Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 5th, 2013  |  syntax: C++  |  size: 0.96 KB  |  views: 404  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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
clone this paste RAW Paste Data