Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6 Game Actors and Component Arch... > Defining Actors and Components

DEFINING ACTORS AND COMPONENTS

Now that you have an understanding of how actors get into the game, it’s time to show you what an actor really looks like. Here’s the Actor class:

class Actor
{
  friend class ActorFactory;

  typedef std::map<ComponentId, StrongActorComponentPtr> ActorComponents;

  ActorId m_id;                  // unique id for the actor
  ActorComponents m_components; // all components this actor has

public:
  explicit Actor(ActorId id);
  ~Actor(void);

  bool Init(TiXmlElement* pData);
  void PostInit(void);
  void Destroy(void);
  void Update(int deltaMs);

  // accessors
  ActorId GetId(void) const { return m_id; }

  // template function for retrieving components
  template <class ComponentType>
  weak_ptr<ComponentType> GetComponent(ComponentId id)
  {
    ActorComponents::iterator findIt = m_components.find(id);
    if (findIt != m_components.end())
    {
      StrongActorComponentPtr pB....

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint