Skip to main content
gamedev.net
🔒 Locked

Entity System

Started by InFerN0 3 replies 250+ views
Original Post
InFerN0
InFerN0
Hey, I am trying to work out an entity system for my engine. I created a base class CEntity which all other entities would be derived from.
//Base entity class
class CEntity
{
public:

        char *name;//entities name 
	virtual void UpdateEntState();// This will usually be overridden by the derived class
	void LoadModel(char *modelname);//load the model
	bool drawable;//entity can be drawn to screen
	vec3_t position;
	vec3_t facing;
	
	CEntity *next;//next entity
	//model
	

private:

};
 
I figured the best way to store them was in a linked list so I could just go throught the list updating as necessary. My questions are should the linked list be made from CEntity and if I do will I be able to call UpdateEntState() in the derived class. Thanks. InFerN0 Not all who wander are lost...
InFerN0Not all who wander are lost...
SH
SH
Hi InFerN0. I''m not sure if this helps, but here goes anyway.

Making a linked list directly from the entity has the advantage of being just slightly marginally quicker, but I think using a template is much more convinient, and worth the tiny performance hit. This way, you have a general list of pointers to entity objects. As to calling and accessing the derived functions, this isn''t a problem if you make a list of POINTERS to entities (which is where the performance hit comes in), but I don''t think you can do it if you place the entity itself in the list.

Hope this helps-- SH
-- SH
Zipster
Zipster
Take a look at the HL source code. They have a nice class system set up.
revolver
revolver
IMHO, that can get pretty messy (linked list inside the entity class). Best option is to have a linked list of entities OUTSIDE of the class itself (via STL, or custom code), perhaps in a CEntityManager class...

Another thing which you might consider is seperating entity type from entity instance. This would allow you to just have the model data (and other data) loaded just once, and shared among every instance of the entity. Basically you have (no it doesn't work, it's just on the spot stuff):

    
CEntityClass {
ModelData* Model;
std::string Name;
void LoadModel(std::string filename);
void Draw();
void ProcessAI(SituationalData* SD);
};


CEntity {
CEntity(CEntityClass* UseEC) {
EC = UseEC;
}
CEntityClass* EC;
void Render() {
ApplyTransforms();
ED->ProcessAI(SituationalData);
ED->Draw();
}
};


CEntityManager {
void Create(std::string name, std::string ModelFile) {
EC = new CEntityClass;
ED->Name = name;
EC->LoadModel(ModelFile)
}
void Spawn(std::string name) {
CEntity* Ent = new(FindClass(name)) CEntity;
AddEntityToList(Ent);
}
};


void main() {
EntManager->Create("HiigaranShip", "mdls/hiigaranship.mdl");
for (int i = 0; i < 11; i++) {
EntManager->Spawn("HiigaranShip");
}
};


The late Seumas discussed in pretty easy to understand terms how Treadmark's entity system works over here:

http://www.longbowdigitalarts.com/ubb/Forum3/HTML/000018.html

Edited by - revolver on October 26, 2000 12:20:06 AM
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat
InFerN0
InFerN0
I have a quick question. How do I make a Linked List with derived classes? When I use the base class as the type the derived classes have base class functionality. Thanks

InFerN0

Not all who wander are lost...
InFerN0Not all who wander are lost...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.