Last active
March 15, 2017 03:08
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
#pragma once | |
#include <string> | |
#include <unordered_set> | |
#include "entityx/Entity.h" | |
#include "entityx/Event.h" | |
class Groups : public entityx::Receiver<Groups> { | |
public: | |
Groups(entityx::EventManager &events) { | |
events.subscribe<entityx::EntityDestroyedEvent>(*this); | |
} | |
void add(const std::string &group, entityx::Entity entity) { | |
groups_[group].insert(entity); | |
} | |
void remove(const std::string &group, entityx::Entity entity) { | |
groups_[group].erase(entity); | |
} | |
const std::unordered_set<entityx::Entity> &group(const std::string &name) { | |
return groups_[name]; | |
} | |
void receive(const entityx::EntityDestroyedEvent &event) { | |
for (auto it : groups_) { | |
auto f = it.second.find(event.entity); | |
if (f != it.second.end()) { | |
it.second.erase(f); | |
} | |
} | |
} | |
private: | |
std::unordered_map<std::string, std::unordered_set<entityx::Entity>> groups_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment