Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Manager
- {
- private:
- std::vector<std::unique_ptr<Entity>> entities; //list of entities
- std::array<std::vector<Entity *>, maxGroups> groupedEntities; //group of entities
- public:
- void update()
- {
- for(auto &e : entities) e->update();
- }
- void draw()
- {
- for(auto &e : entities) e->draw();
- }
- void refresh()
- {
- for(auto i(0u); i < maxGroups; i++)
- {
- auto &v(groupedEntities[i]);
- v.erase(
- std::remove_if(std::begin(v), std::end(v), [i](Entity *mEntity)
- {
- return !mEntity->isActive() || !mEntity->hasGroup(i);
- }), std::end(v));
- }
- entities.erase(std::remove_if(std::begin(entities), std::end(entities),
- [](const std::unique_ptr<Entity> &mEntity)
- {
- return !mEntity->isActive();
- }),
- std::end(entities));
- }
- //Adding entities to groups
- void AddToGroup(Entity *mEntity, Group mGroup)
- {
- groupedEntities[mGroup].emplace_back(mEntity);
- }
- //fetching entity group
- std::vector<Entity *> &getGroup(Group mGroup)
- {
- return groupedEntities[mGroup];
- }
- //Adding an entity
- Entity &addentity()
- {
- Entity *e = new Entity(*this);
- std::unique_ptr<Entity> uPtr{ e };
- entities.emplace_back(std::move(uPtr));
- return *e;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement