Skip to content

Instantly share code, notes, and snippets.

@rje
Created August 2, 2016 15:37
Show Gist options
  • Select an option

  • Save rje/2d85f187cf5b2c9b61fe66a77fc27842 to your computer and use it in GitHub Desktop.

Select an option

Save rje/2d85f187cf5b2c9b61fe66a77fc27842 to your computer and use it in GitHub Desktop.
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