Created
August 2, 2016 15:37
-
-
Save rje/2d85f187cf5b2c9b61fe66a77fc27842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Entity | |
| { | |
| public: | |
| Entity(string name); | |
| ~Entity(); | |
| void SetParent(Entity* newParent); | |
| bool HasTag(string toFind); | |
| void AddTag(string toAdd); | |
| void Tick(uint32 millis); | |
| template<class T> | |
| T* GetComponent() | |
| { | |
| for(auto c : Components) | |
| { | |
| auto cast = dynamic_cast<T*>(c); | |
| if(cast != nullptr) | |
| { | |
| return cast; | |
| } | |
| } | |
| return nullptr; | |
| } | |
| template <class T> | |
| T* AddComponent() | |
| { | |
| auto toReturn = new T(this); | |
| Components.push_back(toReturn); | |
| return toReturn; | |
| } | |
| string Name; | |
| Vec3i Position; | |
| protected: | |
| Entity* Parent; | |
| vector<Entity*> Children; | |
| vector<Component*> Components; | |
| list<string> Tags; | |
| private: | |
| Entity() = delete; | |
| void RemoveChild(Entity* toRemove); | |
| void AddChild(Entity* toAdd); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment