Last active
December 20, 2015 16:33
-
-
Save yashihei/ef809b03d8328e7cc4b4 to your computer and use it in GitHub Desktop.
This file contains 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 Actor { | |
public: | |
Actor() = default; | |
virtual ~Actor() = default; | |
virtual void update() = 0; | |
virtual void draw() = 0; | |
void kill() { enable = false; } | |
bool isEnabled() const { return enable; } | |
private: | |
bool enable = true; | |
}; | |
template<typename Type> | |
class ActorManager { | |
public: | |
ActorManager() = default; | |
virtual ~ActorManager() = default; | |
void add(std::shared_ptr<Type> actor) { | |
actors.push_back(actor); | |
} | |
void clear() { | |
actors.clear(); | |
} | |
int size() { | |
return actors.size(); | |
} | |
virtual void update(Game* game) { | |
for (auto& actor : actors) { | |
actor->update(game); | |
} | |
Erase_if(actors, [](std::shared_ptr<Type> actor) { return !actor->isEnabled(); }); | |
} | |
virtual void draw(Game* game) { | |
for (auto& actor : actors) { | |
actor->draw(game); | |
} | |
} | |
typename std::list<std::shared_ptr<Type>>::const_iterator begin() { return actors.begin(); } | |
typename std::list<std::shared_ptr<Type>>::const_iterator end() { return actors.end(); } | |
private: | |
std::list<std::shared_ptr<Type>> actors; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment