Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Using pointers and id for referencing game objects?

$
0
0
Hi Im making a city builder/simulation game where a building can house up to 15 units. Units and buildings are located in a list (std::list <unit> unitList). They need to keep track of eachother (the building: which units live here, how many free slots do I have) (unit: where do I live, where do i work, is workplace full of resources, is food missing at home etc). Pointers between these is quicker but seems unreliable. Also, when I load/save the game i need to do same special handling of the pointers. The other idea is to just save the IDs of the building/units. IDs are unique so a ID relates to a single unit/building. But then each time I need to find the units inside a building or whatever i need to getUnitFromID(myID) and use that function to loop through the entire list of objects and return the correct one. Might be slow with hundreds of objects looking for other object all the time. Or a combination? Or something completely else? Thanks! Erik

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>