Game Development Reference
In-Depth Information
protected:
StrongActorPtr m_pOwner;
public:
virtual
˜
ActorComponent(void) { }
// These functions are meant to be overridden by the implementation
// classes of the components.
virtual bool VInit(TiXmlElement* pData) = 0;
virtual void VPostInit(void) { }
virtual void VUpdate(int deltaMs) { }
// This function should be overridden by the interface class.
virtual ComponentId VGetComponentId(void) const = 0;
private:
void SetOwner(StrongActorPtr pOwner) { m_pOwner = pOwner; }
};
This is the interface for all components. The m_pOwner member is the link back to
the actor, which is necessary to allow components to communicate with each other.
Other than that, there are no member variables. The rest of the class serves as an
interface for individual components to override and implement.
You already saw the VInit() and VPostInit() functions in the factory
'
s Create-
Component() method. The VUpdate() function is called by the actor
s Update()
function. The VGetComponentId() function is overridden by the component inter-
face classes that derive from this class. Every component interface has a unique ID,
and this accessor is used to retrieve it. A component must have an ID, which is why
this is a pure virtual function.
'
Storing and Accessing Actors
There are a number of ways to store actors and even components. The method used
in this topic is an STL map where the key is the actor ID.
typedef std::map<ActorId, StrongActorPtr> ActorMap;
ActorMap m_actors;
Maps allow for relatively fast lookups, insertions, and removals (which, for the mathemat-
ically inclined, are all O(log n)) . All actors live in this map on the BaseGameLogic
class, which has a public API for retrieving actors.
virtual weak_ptr<Actor> VGetActor(const ActorId id);
 
 
Search WWH ::




Custom Search