Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarEntityMap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/game/StarEntityMap.cpp')
-rw-r--r--source/game/StarEntityMap.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/source/game/StarEntityMap.cpp b/source/game/StarEntityMap.cpp
index 66d09a5..2232099 100644
--- a/source/game/StarEntityMap.cpp
+++ b/source/game/StarEntityMap.cpp
@@ -27,6 +27,25 @@ EntityId EntityMap::reserveEntityId() {
return id;
}
+Maybe<EntityId> EntityMap::maybeReserveEntityId(EntityId entityId) {
+ if (m_spatialMap.size() >= (size_t)(m_endIdSpace - m_beginIdSpace))
+ throw EntityMapException("No more entity id space in EntityMap::reserveEntityId");
+
+ if (m_spatialMap.contains(entityId))
+ return {};
+ else
+ return entityId;
+}
+
+EntityId EntityMap::reserveEntityId(EntityId entityId) {
+ if (auto reserved = maybeReserveEntityId(entityId))
+ return *reserved;
+
+ m_nextId = entityId;
+ return reserveEntityId();
+}
+
+
void EntityMap::addEntity(EntityPtr entity) {
auto position = entity->position();
auto boundBox = entity->metaBoundBox();