Advertisement
Guest User

Untitled

a guest
May 5th, 2013
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. class Component
  2. {
  3. public:
  4.   void Init( void ) = 0;
  5.   void Update( float dt ) = 0;
  6.   void ShutDown( void ) = 0;
  7.   void SendMSG( MSG *msg ) = 0;
  8.  
  9. protected:
  10.   CID id; // Component id
  11.   GameObject *m_owner;
  12.   bool m_active; // delayed destruction
  13. }
  14.  
  15. class GameObject
  16. {
  17. public:
  18.   void SendMSG( MSG *msg ); // forward msgs to all components;
  19.   Component *GetComponent( CID id ); // Can do binary search with std::map on CID
  20.   void Update( float dt ); // Run update on all components
  21.   void AddComponent( Component *comp );
  22.  
  23. private:
  24.   std::map<Component *, CID> m_componentMap;
  25. };
  26.  
  27. // Adding components, all default constructed with initial values
  28. GameObject *obj = Factory->CreateObject( );
  29. obj->AddComponent( Factory->CreateComponent( "Tansform" );
  30. obj->AddComponent( Factory->CreateComponent( "Sprite" );
  31. obj->AddComponent( Factory->CreateComponent( "RigidBody" );
  32.  
  33. Component *sprite = obj->GetComponent( Spriteid );
  34. sprite->Update( ); // render an object
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement