Skip to main content
gamedev.net
🔒 Locked

Entity Class

Started by F-Kop Jan 23, 2008 at 10:33 PM 3 replies 1k views
Original Post
F-Kop
F-Kop
I can't think of a good structure for the entity class. "Entity" is the name I used in my code for an object that "thinks" once each time the game loop goes around. This is what I have right now:

class EntityList
{
public:
	friend class Entity;
	
	void Think( double time );

private:
	System::List m_list;
};

class Entity
{
public:
	friend class EntityList;
	
	Entity( EntityList * entity_list );
	~Entity( );
	
	virtual void Think( double time ) = 0;

private:
	System::List * m_entity_list;
	System::Node * m_entity_node;
};


I've rewritten this a few different ways, and I am still not happy with it. Any suggestions?
---------------------------------Upon thine ass shall I bust but a single cap.
bulgurmayo
bulgurmayo
How about something like :

class Entity{public:	friend class EntityList;		Entity( EntityList * entity_list );	~Entity( );		virtual void Think( double time ) = 0;	virtual void ThinkHarder( double time ) = 0;	virtual void ThinkHigher (Drug boost) = 0;	virtual void MassageNeurones (MassageStyle massage) = 0;	virtual void DayDream () = 0;private:	System::List * m_entity_list;	System::Node * m_entity_node;        boost::vector_ptr< Neurone >   m_neurones;};
Peter5897
Peter5897
class Entity{public:	Entity( );	~Entity( );		void RunAI( double time );  // run all attached brains or "thinkers"private:        std::list< Thinker >  Brains;};class Thinker{public: virtual void Think( double time, Entity& owner ) = 0;};


You're more component based in this way. During a RunAI call you'll go through all your attached Brains and call Think on them passing in the owner ( I assume later you will have information such as position that you'd like to get at ).

In this way you don't need to rewrite code for "Attack" when you make multiple enemy types. You just attach the Attack thinker to both entities whereas they're other behavioral Thinkers might be different.

Hope that made sense.

*EDIT*

I noticed that every entity has a list of entities and nodes. I'm assuming that the same node list and entity list won't show up in every entity right?
F-Kop
F-Kop
The entity has a pointer to the list inside of the EntityList class and a node, so that the destructor can call list->Remove( node ) to quickly remove the node from the list. For now I'm going to change it so that the time will be stored in a global variable, rather than passing it through every Think function call.
---------------------------------Upon thine ass shall I bust but a single cap.
Zahlman
Zahlman
Quote:
Original post by F-Kop
I can't think of a good structure for the entity class. "Entity" is the name I used in my code for an object that "thinks" once each time the game loop goes around. This is what I have right now:

*** Source Snippet Removed ***

I've rewritten this a few different ways, and I am still not happy with it. Any suggestions?


What aren't you happy about, exactly?

And why not use standard library containers?

Topic Locked

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

Sign in to reply to this topic.