Creating an Entity Hierarchy

Started by
15 comments, last by Darkor 20 years, 4 months ago
quote:Original post by Darkor
Also, you didn''t say if using static functions like Ravyne suggested was a good solution. I imagine, that it would be quite obscure to other programmers who''ll read the code.


static member variables the functions couldn''t be static or you''d have no access to them outside the class file. Just clearing that up. I don''t think it would appear obscure to anyone, in fact I find it more straight forward.

but again; evaluate the options and choose what seems best.

Ravyne, NYN Interactive Entertainment
[My Site][My School][My Group]

throw table_exception("(? ???)? ? ???");

Advertisement
darkor: i have actually implemented a complex entity system, and that is what I personally used, and it worked. do whatever you want, but remember you want to be spending all of your time defining entity behavior, not deciding the perfect hierarchy system (because ultimately there isn''t any).

Why don't alcoholics make good calculus teachers?Because they don't know their limits!Oh come on, Newton wasn't THAT smart...
shadow12345: Haha, I didn''t say it would work, but you see I have other programmers on the team and they would be doing the implmentations, not me. So I have to make the hierarchy do as much as possible in order not to erm let them screw it up. Though I concede the fact that this is impossible because anyone who would want to screw things up could do so.

But that''s not the point, I simply want to make it such accidents don''t happen. =p

Ravyne: Yes, I''ve discussed it with the other programmers and though they find no reason not to use static stuff, they say that it''s not really a good design. I disagree, since this way makes classes more closely knit.

What I mentioned about it being obscure is that, you don''t really know what the class is. It can be an instance and thus the actual entity or it could be used for the static members as a Flyweight.

I guess I still have some sorting out to do. I have other things to code in the meantime so don''t worry, I''m not wasting my time just doing thinking. =p
the only advice I can give is play around and see what works. Personally, for me, I have a higher success rate when I keep things as simple as I possibly can. Your hierarchy should make things easier for you, not harder.

Why don't alcoholics make good calculus teachers?Because they don't know their limits!Oh come on, Newton wasn't THAT smart...
Hmm well I''ve thought about it and the only reason to use Flyweights in this case is to allow designers to create variations of the same entity to exist at the same time.

Imagine if static variables were used, you can only have one type of entity per class. If say you had a manager for loading and unloading flyweights, a designer can take an existing entity and change it and both would exist and use only one class.

My game could probably use that kind of functionality, so I''ll use flyweights.

shadow12345: Yeah keeping it simple is great, but as I mentioned, making it simpler in the long run is worth the trouble now.
I found this article Smash TV 3D Design quite informative.

It pretty much describes what you want to achieve and also flattens deep inheritance hierarchies and replaces them with a containment / systems approach.

I guess it's up to you if you go the 1 class / 2 classes approach. I went with 2 - Actor and ActorData, with Actor having pointers to the data which is stored in a std::map.

I limited my inheritance to 3 levels...
e.g.

Actor::Alien::LanderActor::Alien::MutantActor::Bullet::MissileActor::Bullet::LaserActor::Ship::StandardActor::Ship::FastetcCDataStore < ActorClassEnum, ActorData >CDataStore < ActorClassEnum, AlienData >CDataStore < ActorClassEnum, LanderData >< ACTOR_CLASS_LANDER, CLander >< ACTOR_CLASS_MUTANT, CMutant > 


When creating the Entity I'd set the pointer to the relevant data...

this->actor_data = CDataStore < ActorClassEnum, CActorData > ::getData(ACTOR_CLASS_LANDER);this->alien_data = CDataStore < ActorClassEnum, CAlienData > ::getData(ACTOR_CLASS_LANDER);this->grunt_data = CDataStore < ActorClassEnum, CLanderData > ::getData(ACTOR_CLASS_LANDER);Seems to work quite well for my needs.Cheers,Paul Cunningham    


EDIT - fixed the greater / less than signs

[edited by - PaulCunningham on December 1, 2003 8:19:00 AM]
Cheers,Paul CunninghamPumpkin Games
Ah just when I''ve thought of almost the same solution, you posted that! =p It was a good read, thanks.

Well already we are implementing such a system in the Flyweight. However, that is not the problem. I realise that I can avoid having two classes for each type of entity, by putting as much functionality into the Flyweight instead of the Exported state.

That being said, all entities in the game are treated the same way, but the Flyweight controls its behaviour. I will have an implementation up soon.

Also if certain entities require more than the default processing, we don''t have to subclass it to create distinct behaviour, instead the Decorator pattern uses object composition to change behaviour. But I''m not sure if this is needed yet.

This topic is closed to new replies.

Advertisement