Added remove_entity
This commit is contained in:
parent
ac463f0669
commit
0feb020be8
|
@ -57,6 +57,7 @@ namespace ecs::lua {
|
|||
// @todo Allow to construct with given uuid
|
||||
return thiz->create_entity();
|
||||
},
|
||||
"remove_entity", &Manager::remove_entity,
|
||||
"has_entity", [] (Manager* thiz, std::string uuid) {
|
||||
// @todo Check if valid
|
||||
return thiz->has_entity(uuids::uuid::from_string(uuid).value());
|
||||
|
|
|
@ -198,6 +198,8 @@ namespace ecs {
|
|||
Entity* create_entity(uuids::uuid uuid);
|
||||
Entity* create_entity();
|
||||
|
||||
void remove_entity(ecs::Entity* entity);
|
||||
|
||||
bool has_entity(uuids::uuid uuid) {
|
||||
// @todo c++20 has .contains()
|
||||
return _entities.count(uuid);
|
||||
|
|
|
@ -77,6 +77,16 @@ namespace ecs {
|
|||
return create_entity(uuid);
|
||||
}
|
||||
|
||||
void Manager::remove_entity(ecs::Entity* entity) {
|
||||
auto it = _entities.find(entity->uuid);
|
||||
if (it == _entities.end()) {
|
||||
throw std::runtime_error("Entity with uuid does not exists");
|
||||
}
|
||||
|
||||
delete it->second;
|
||||
_entities.erase(it);
|
||||
}
|
||||
|
||||
Entity* Manager::create_entity(uuids::uuid uuid) {
|
||||
Entity* entity = new Entity(uuid);
|
||||
_entities.insert({uuid, entity});
|
||||
|
|
Loading…
Reference in New Issue
Block a user