Advertisement

Storing "unit" information

Started by December 11, 1999 10:51 PM
2 comments, last by TUna 25 years ago
One alternative would be to store a pointer to a unit structure in each tile and a bool to whether theres a unit there. If you are going to do that I would also keep a linked list of units on the map since it would probably be easier to work with a linked list for ai and stuff.
I personally would have each map point have a linked list off of it that consists of all the objects/units over that particular point. So generally what the map point struct would look like is as follows:

struct MapObjUDT{    cMapObj *MapObj;      //Pointer to a generic map object base class    cMapObjUDT *NextNode; //Pointer to the next node}struct MapPtUDT{     MapObjUDT *ObjList;  //Pointer to the list head     long Flags;          //Various flags for this spot};

With my map engine, everything is a map object (Tiles, static objects like trees, and entities). Most of the time the very first object is the tile. What this whole system allows you to order any of the objects anywhere so you could actually have multiple levels over any given point and people walking between them.

There are a few things that need to handle that are a bit out of the ordinary, but nothing serious that anyone who has ever dealt with linked lists can't handle.

Good Luck and I hope this helps!

PS: HI TANSTAAFL!

------------------
Dino M. Gambone
http://www.xyphus.com/users/dino

Good judgement is gained through experience. Experience, however, is gained through bad judgement.

Dino M. Gambone
Good judgment is gained through experience. Experience, however, is gained through bad judgment.

Currently working on Rise of Praxis MUD: http://www.riseofpraxis.net/

Advertisement
Hi

I'm designing a simple tile based game, and was wondering what the best method to store "unit" information was? An array or linked-list would do, but wouldn't that be a big slow down having to search through ALL the "units" just to find the ones on the current screen? Are there any better ways of doing this?

Thanks a lot
Lloyd

An alternative to the linked list method for units is storing the units in an array, then storing unit array indices in the map cells. Special values (e.g. -1) may be used to indicate no unit here. If you must have multiple units in a cell you can have a -1 terminated string of object references in your map cell.

An advantage to arrays over link lists is knowledge of worse case memory requirements as well as increased locality of references. It also makes your life a lot easier if you happen to be using a transparent garbage collection library.

This topic is closed to new replies.

Advertisement