Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Storing "unit" information

This topic is 6945 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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!


Dino M. Gambone

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!