|
@@ -26,6 +26,26 @@ void Entity::kill()
|
|
|
this->registry->killEntity(*this);
|
|
|
}
|
|
|
|
|
|
+void Entity::tag(const std::string &tag)
|
|
|
+{
|
|
|
+ this->registry->tagEntity(*this, tag);
|
|
|
+}
|
|
|
+
|
|
|
+bool Entity::hasTag(const std::string &tag) const
|
|
|
+{
|
|
|
+ return this->registry->entityHasTag(*this, tag);
|
|
|
+}
|
|
|
+
|
|
|
+void Entity::group(const std::string &groupName)
|
|
|
+{
|
|
|
+ this->registry->groupEntity(*this, groupName);
|
|
|
+}
|
|
|
+
|
|
|
+bool Entity::belongToGroup(const std::string &groupName) const
|
|
|
+{
|
|
|
+ return this->registry->entityBelongsToGroup(*this, groupName);
|
|
|
+}
|
|
|
+
|
|
|
/* System */
|
|
|
void System::addEntity(Entity entity)
|
|
|
{
|
|
@@ -50,7 +70,6 @@ const Signature& System::getComponentSignature() const
|
|
|
return this->componentSignature;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
Entity Registry::createEntity()
|
|
|
{
|
|
|
uint32_t entityId;
|
|
@@ -129,6 +148,78 @@ void Registry::update()
|
|
|
this->entityComponentSignatures[entity.getId()].reset();
|
|
|
|
|
|
this->freeIds.push_back(entity.getId());
|
|
|
+
|
|
|
+ this->removeEntityTag(entity);
|
|
|
+ this->removeEntityGroup(entity);
|
|
|
}
|
|
|
this->entitiesToBeKilled.clear();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+void Registry::tagEntity(Entity entity, const std::string &tag)
|
|
|
+{
|
|
|
+ this->entityPerTag.emplace(tag, entity);
|
|
|
+ this->tagPerEntity.emplace(entity.getId(), tag);
|
|
|
+}
|
|
|
+
|
|
|
+bool Registry::entityHasTag(Entity entity, const std::string &tag) const
|
|
|
+{
|
|
|
+ if (this->tagPerEntity.find(entity.getId()) == this->tagPerEntity.end())
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return this->entityPerTag.find(tag)->second == entity;
|
|
|
+}
|
|
|
+
|
|
|
+Entity Registry::getEntityByTag(const std::string &tag) const
|
|
|
+{
|
|
|
+ return this->entityPerTag.at(tag);
|
|
|
+}
|
|
|
+
|
|
|
+void Registry::removeEntityTag(Entity entity)
|
|
|
+{
|
|
|
+ auto taggedEntity = this->tagPerEntity.find(entity.getId());
|
|
|
+ if (taggedEntity != this->tagPerEntity.end())
|
|
|
+ {
|
|
|
+ auto tag = taggedEntity->second;
|
|
|
+ this->entityPerTag.erase(tag);
|
|
|
+ this->tagPerEntity.erase(taggedEntity);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Registry::groupEntity(Entity entity, const std::string &groupName)
|
|
|
+{
|
|
|
+ this->entitiesPerGroup.emplace(groupName, std::set<Entity>());
|
|
|
+ this->entitiesPerGroup[groupName].emplace(entity);
|
|
|
+ this->groupPerEntity.emplace(entity.getId(), groupName);
|
|
|
+}
|
|
|
+
|
|
|
+bool Registry::entityBelongsToGroup(Entity entity, const std::string &groupName) const
|
|
|
+{
|
|
|
+ auto groupEntities = this->entitiesPerGroup.at(groupName);
|
|
|
+ return groupEntities.find(entity) != groupEntities.end();
|
|
|
+}
|
|
|
+
|
|
|
+std::vector<Entity> Registry::getEntitiesByGroup(const std::string &groupName) const
|
|
|
+{
|
|
|
+ auto &setOfEntities = this->entitiesPerGroup.at(groupName);
|
|
|
+ return std::vector<Entity>(setOfEntities.begin(), setOfEntities.end());
|
|
|
+}
|
|
|
+
|
|
|
+void Registry::removeEntityGroup(Entity entity)
|
|
|
+{
|
|
|
+ auto groupedEntity = this->groupPerEntity.find(entity.getId());
|
|
|
+ if (groupedEntity != this->groupPerEntity.end())
|
|
|
+ {
|
|
|
+ auto group = this->entitiesPerGroup.find(groupedEntity->second);
|
|
|
+ if (group != this->entitiesPerGroup.end())
|
|
|
+ {
|
|
|
+ auto entityInGroup = group->second.find(entity);
|
|
|
+ if (entityInGroup != group->second.end())
|
|
|
+ {
|
|
|
+ group->second.erase(entityInGroup);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ groupPerEntity.erase(groupedEntity);
|
|
|
+ }
|
|
|
+}
|