Whoa. First take a chill pill quzah.
You don't have to look up anything in my method, except maybe to find the objects that are in that room and even that can be optimized quite a bit.
The map is just an array that holds values. The values correspond to room ID numbers. The room ID numbers are really just the index of the room in the master list of rooms. So really the map is just a big array of indexes into the master list.
So if you are at 5,5 and the number there is 10 you would use the number 10 to access the room, exit info, etc. Since the room list is going to be a class of type Room then this information is all contained in the class.
You can do objects by using pointers in the room class. When the user drops an item in a room you simply do Room[ID].AddObject(ObjectToBeDropped());
I don't think I'm too far off here because a lot of editors that I've used, use this same method. A lot of the old AGI games (Kings Quest 1,2,3 etc) used this for rooms and information. They also use this same method for responding to the user about what they typed in - everything is based on ID numbers.
Modern 3D editors like Novalogic's NILE for Joint Ops also uses ID numbers but they call them SSN's. The whole engine revolves around SSNs. I suspect they either keep an STL map of SSN to object relations or it is an array with the SSN being the index into the array. Either way would be pretty simple. And I suspect there is more info than just the SSN inside of the engine.
With the pointer method it's not easy to say transport a person from one room to the next or move to an arbitrary location in the map for say a spawn point for monsters or what have you. Array index methods allow for simple placement of objects, monsters, descriptions etc.
Code:
int column=rand () % mapsizex;
int row=rand() % mapsizey;
DWORD RoomID=TheMap[column][row];
Monster.SetLocation(RoomID);
Here might be a sample setup code for monsters.
Code:
int iMonsters=rand () % somevalue;
Monster *MonsterArrray=new Monster[iMonsters];
bool bMonsterPlaced=false;
for (int i=0;i<iMonsters;i++)
{
do
{
int x=rand() % mapsizex;
int y=rand() % mapsizey;
//Get RoomID - index value into master array of rooms
DWORD RoomID=TheMap[x][y];
if (!Room[ID].OccupiedByMonster())
{
...Set random monster traits
Monster[i].SetLocation(RoomID);
bMonsterPlaced=true;
}
} while (bMonsterPlaced==false);
bMonsterPlaced=false;
}
I don't use iteration to find the room. With this you directly index into the array based on the value in the map.
It's the same concept for a tile engine. You assign IDs to the tiles - preferably the ID is the index into the array of tiles. The map is simply a bunch of ID's or indexes into the array of tiles. So the render system simply iterates through the map based on scroll position, extracts the TileID or index, sets the texture based on the ID, and renders.
Here is a simple sample from my asteroids project. This is just a really simple texture manager class. It uses a vector instead of an array, but could be changed to use an array. The ID of the texture is simply it's position in the vector.
Code:
#ifndef CTEXTUREMANAGER
#define CTEXTUREMANAGER
#include <d3dx9.h>
#include <vector>
#include "CTexture.h"
class CTextureManager
{
protected:
IDirect3DDevice9 *m_pDevice;
public:
std::vector<IDirect3DTexture9 * > m_pTextures;
CTextureManager(void) {}
virtual ~CTextureManager(void)
{
m_pTextures.clear();
}
void Create(IDirect3DDevice9 *Device)
{
m_pDevice=Device;
}
unsigned int Add(std::string File)
{
IDirect3DTexture9 *Texture=NULL;
D3DXCreateTextureFromFile(m_pDevice,File.c_str(),&Texture);
m_pTextures.push_back(Texture);
return m_pTextures.size()-1;
}
IDirect3DTexture9 *GetTexture(unsigned int ID)
{
return m_pTextures[ID];
}
};
#endif
So to set a texture just becomes this:
Code:
Device->SetTexture(TextureSystem->m_pTextures[ClassTextureID]);
I didn't mean to make anyone mad and I'm sorry if I did. I've just found that using ID numbers as indexes into arrays works quite well for a lot of games. The advantage to using an array based approach is the same as the benefits of an array over a linked list.
Essentially using pointers is making one huge linked list of rooms.
Very hard to iterate through quickly.