CBaseEntity Help!!!

Started by
11 comments, last by dmail 16 years, 9 months ago
Say in a game you have a base entity class. What sort of variables and functions would be in it?
Advertisement
ToString(), HashCode, uid perhaps. There's not much that's usefully required by everything.
Depends. What's an entity?
In my game i want all my objects like for eg the map every model etc... to derive from CBaseEntity and register with a manager for things like collision detection etc. Is this a good way to do it?
Quote:Original post by hahaha
In my game i want all my objects like for eg the map every model etc... to derive from CBaseEntity and register with a manager for things like collision detection etc. Is this a good way to do it?


An extension on model-view-controller might be more adapted. You use a controller object which sets up a model (a collision detection client object or a physics engine client object for instance) and a view (a model, a sprite).
Ask: What sort of things do every entitity have in common?
What actions do each entitity have in common?
A couple pointers for an intrusive double linked list.
Quote:Original post by Nohup
A couple pointers for an intrusive double linked list.


What is an intrusive double linked list?
Quote:Original post by hahaha
Quote:Original post by Nohup
A couple pointers for an intrusive double linked list.


What is an intrusive double linked list?


It's a violation of the single responsibility principle, which adds the responsibility of being part of a list to the responsibility of being an object.

This approach is generally shunned in all languages which have access to a standard library of containers (in practice, everything except C and assembly), because standard library containers are faster and lighter by default, provide more features and take less development time to use, in addition to respecting the single responsibility principle. The main reason is that you want to be free to make your entities part of zero, one or more containers, and you don't want to be forced to make your entities par of exactly one container (and to make that container a doubly linked list).
Why have a base entity at all?

Why not define a single entity class, that uses component oriented design to specialize contents?

Or, if going for networked gameplay, an entity that is convenient to use with serialization (has UID, possible persistence ID) and is capable of serializing itself.

Or, have the class design mimic different types of entities, and have fields that reflect the functionality.

Or, not have the objects, and simply use arrays of structs to encapsulate functionality.

This question is akin to:"Suppose I want to drive. What kind of SUV would I use?" Well, not only is SUV not the best solution, but driving involves everything from unicycle, pogo stick, motor bike, tanks, airplanes, and, in some cases, SUVs.

In this case, the question is wrong. A better one would be describing the type of game design you want, what interactions you want, and implementation specific quirks, and then, the design of entity forms by itself.

Class design solves the problem - designing classes without context simply creates a solution looking for an answer. In this case, answering 42 would be perfectly valid. But you'd be stuck trying to figure out what the question is.

This topic is closed to new replies.

Advertisement