Layers

Started by
17 comments, last by decsonic 20 years, 2 months ago
Well ive made a isometric engine, map''s been stored in a 2D array, now i want layers.. so basicly how To store and pull out that data?
Advertisement
Use a 3D array - X,Y and the third dimension are the layers. So [0] is the map, [1] is objects and [2] are enemies.

I prefer to only use a single layer representing the map and a Z-ordered list for all other items.
Do not use a 3D array, only use a 2D array for the static bottom layer of tiles. and put all the other layers in linked lists.

Imagine having a 10000x10000 tiles map (yeah I know, big) and a struct with info for each tile containing mayeb 15 byte per tile.

thats a 1.5 Gig map. now, for each added layer you''ll add another 1.5 GB, but maybe you only have 1000 enemies on the map, so it would be a huge masive unthinkable waste to use an array for them. Look up lined lists, and use a sorted linked list for each layer. That way you waste no memory, and lose nearlyu no speed.

Of course in the massively huge stupid example above, you''d have some culling method, so you only load a small part of the map to RAM. but it still holds true in smaller more real world examples...

(Jeez guys! Imagine building a 10000x10000 map by hand...)

The more I think, the more confused I get.
The best 2D game developer site out there!
JRA GameDev Website//Bad Maniac
I think the tile world in Ultima Online is aproximately 10000 by 10000.
it''s split up into loads of sub maps though, one part of the world handled per server, and it''s stored in some weirdo compressed archives on your PC, byt yeah, the world in total is actually bigger than that. They do not use arrays though

One more point against arrays is, what happens when you want to be able to drop multiple items on each tile? you''d need an n-dimensional array, wich is not viable. So I still say an aray for the base map, split up into zones of some kind, and one or more linked lists for the rest.
JRA GameDev Website//Bad Maniac
i would differentiate between the terrain (dirt, water, grass), static tiles (walls, trees, rocks), and objects (characters, items, enemies).

the terrain might as well be an array, since every space will need one and only one tile. the rest could be in an independent list, or per-tile lists, or whatever.

that''s just how i would do it.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Yep, that''s about the best way of doing it. unless of course you have maps smaller than a few hundred tiles each way, and only one object per tile, in wich case arrays will be enough. depends a bit on the scenario.
JRA GameDev Website//Bad Maniac
If you are a beginner I believe that a 2-deminsional array is not too bad(not knocking linked list!!!). I am a beginner in game programming, but I am extremely good at math and I use formula to determine layers and everythin else. The next game I plan on making I am going to implement linked list. I have grasped most of the concepts of c++ except linked list and vectors. I have just read and played with vectors, good, but I like to have full control. Also I would like to learn how to use linked lists but I have no idea how to implement them in a game.

For example, doesn''t searching through a linked list have the same performance penalty as searching through an array. If anyone can give me a link to to a website that explains how o do tile games with linked list would be greatly appreciated

Robert
The way I did it was to use a two dimensional array of map cells like this:

struct MAP_CELL{    short base_layer;    short fringe_layer;    short object_layer;    short data;};MAP_CELL map[MAP_WIDTH][MAP_HEIGHT]; 


In another game I did something similar to this (yes I know it isn''t about layers but it''s a dynamic map size storage structure):

MAP_CELL *map;void SomeInitFunction(int width, int height){    //create a map in a one-dimensional array    map_width = width;    map_height = height;    map = new MAP_CELL(map_width, map_height);}inline int GetMapCellIndex(int x, int y){    return map_width * y + x;} 
ive found the storage method i use works rather well...

you have a contiguous array of pointers

each pointer points to a tile structure

which contains all the data for each tile, all it's layers and data header.

this gives the enumeration speed of an array

and yet keeps the array considerably smaller since it uses a 32bit pointer to a larger structure, thus making the brunt of the map data not confined to a contiguous block.

example:

struct IsoTile
{
string m_name;
Ground *m_lpbase;
Ground *m_lpoverlay;
Sprite *m_lpitem;
Sprite *m_lpcharacter;
//other stuff...
};

IsoTile **tilearray;

tilearray=new IsoTile*[width*height];


IsoTile* GetTile(long x,long y)
{
//validate dimensions
return tilearray+(y*width+x);
}

Raymond Jacobs,

www.EDIGames.com

www.EtherealDarkness.com



[edited by - EDI on January 9, 2004 4:14:08 PM]

Raymond Jacobs, Owner - Ethereal Darkness Interactive
www.EDIGames.com - EDIGamesCompany - @EDIGames

This topic is closed to new replies.

Advertisement