Archived

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

Chime_

Object Organisation

Recommended Posts

Hi all, I''ve been reading the forums for a while, and thought I''d take the plunge and ask some questions. I''m in the planning stage for my game at the moment, and am curious about the best way to organise the game objects (People, vehicles, projectiles, etc). All game objects descend from a base class, so a list of base class pointers seems sensible. I''m considering an STL Vector, for the fast "random" [] operator, but as the game is an RTS type, I may also need separate Vectors for the units that are currently selected, and for user defined "teams" of units. Would it be better to declare many STL Vectors, or just loop through the same one, performing if(unit->selected) type tests? Any of you guys had similar design procedures? What do you recommend? I''m more concerned with code readability than speed really, as it''s only my first DirectX effort (2D top-down RTS), but any help/experiences would be helpful. Cheers - Chime. Chime - SNES Mariokart veteran, 10 years on and still red-shelling on a weekly basis.

Share this post


Link to post
Share on other sites
it might be quicker to have each entity to have a pointer which refers to someone else it is selected with. have a global pointer to the first selected entity and operate on them one at a time with no checking ecxept wether there is a next unit.

Share this post


Link to post
Share on other sites
Generally, iterating across a container of a couple of hundred elements (eg. RTS units) takes no time whatsoever, so I might be content just to have an IsSelected() member for each unit and pull out the selected ones that way. But if I needed more speed I would personally keep everything in the main vector, and have an additional std::list for each player of which game objects they currently have selected. I''d use a list here because you will often be adding or removing from it. You could do this for each team, too. But with storing identical pointers in 2 or more places comes a need to ensure that any removals from the main container are propagated to the per-player ones too. You have to design an interface that ensures that when you call DestroyUnit() or whatever, that all the lists are updated accordingly.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

Share this post


Link to post
Share on other sites