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

summaryrefslogtreecommitdiff
path: root/source/game/StarEntityMap.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-07-22 22:31:04 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-07-22 22:31:04 +1000
commitcb19eef701b5c9e27d0464795fffcf8a4d795a21 (patch)
tree5cfbdf49ebd7ac9539891eea850e244887d4c355 /source/game/StarEntityMap.cpp
parent4fbd67daccfa69df6988bdf17c67ee3d5f3049c5 (diff)
Add character swapping (no GUI yet)
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();