View Single Post
Old 12-02-2012, 11:05 AM   #5
scandum
Senior Member
 
Join Date: Jun 2004
Posts: 315
scandum will become famous soon enough
Re: A huge grid world

I'd suggesting using a grid of pointers to an index table. KaVir uses 2 byte keys which means he can't easily create dynamic content.

Using pointers you have the flexibility to set the pointer to a tile in the lookup table, saving quite a bit of memory doing so, or alternatively to a custom tile that can be altered and modified on the fly.

Using this approach you can also add two pointers for tiles up and down from the tile that is on the 2d grid, allowing the creation of tunnels and towers.

Another problem it solves is that you can maintain a linked list of all players on the tile. With the 2 byte key approach the world is treated as one room, typically resulting in long lists slowing down the system.

So if a player moves from one tile to the next the MUD would check if that tile points to dynamic memory or static memory in the index table. If the tile is in the lookup table the MUD will allocate memory and create a duplicate of the tile in dynamic memory, and adds the player as content of the newly created tile. When the player leaves the tile the dynamic memory is freed and the pointer is set back to point to the index table.

The only downside is that pointers take up 8 bytes on modern systems.
scandum is offline   Reply With Quote