Archived

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

dopeflow

RTS : handling a high number of game actors(units/structures) question

Recommended Posts

dopeflow    124
I have come to a point where I need to manage my actors properly. Since in RTS games you can have multiple instances of the same object kind, for example a team of 12 marines, I was thinking it would be good to have some sort of ActorFactory where I could obtain a copy of an object when I need to, instead of loading it all over again from a xml file. For example, you finish building a soldier : CGameActor soldier= new CUnit(); soldier= ActorFactory::Clone(SOLDIER); m_world->AddActor(soldier); Conceptually, I have one "brand new" copy of each actor type in memory so that i can always duplicate them fast then add the copy to the world actor list. But my problem is this, my "game actors" are made out from a class hierarchy containing pointers to other class, a big number of member variables, some private, protected etc.... and when the time comes to duplicate an object, it just doesnt work. CEntity(base class) CGameActor(derives from CEntity) CUnit and CStructure (derives from CGameActor) Just interesting in hearing someone''s opinion on that problem or perhaps other ways to deal with it. Thanks!

Share this post


Link to post
Share on other sites
RenderTarget    398
Make a virtual Clone method in the Actor base class, with a custom implementation for each actor type. The actor will manage making a new clone of itself. This is nice too because an actor can do refcounting on resources (like VBs and such), and do very little actual copying in the clone.

I like pie.

Share this post


Link to post
Share on other sites
Tommyboy    122
Generally, yes.


two-cents worth
---------------
Personally, I would setup all the units using the Flyweight pattern (maybe you are already).

Then use a Factory pattern to generate instance specific Actors. The Actor would hold the isolated instance data and a pointer to the Flyweight unit.



Tommyboy

Share this post


Link to post
Share on other sites
dopeflow    124
I fixed the problem already. I have opted for a ActorFactory singleton class from which I can easily get new object instances.

The ActorFactory loads from xml a "template" for each actor type, works great.

Share this post


Link to post
Share on other sites