| 49 | |
| 50 | |
| 51 | void EntityMap::addEntity(EntityPtr entity) { |
| 52 | auto position = entity->position(); |
| 53 | auto boundBox = entity->metaBoundBox(); |
| 54 | auto entityId = entity->entityId(); |
| 55 | auto uniqueId = entity->uniqueId(); |
| 56 | |
| 57 | if (m_spatialMap.contains(entityId)) |
| 58 | throw EntityMapException::format("Duplicate entity id '{}' in EntityMap::addEntity", entityId); |
| 59 | |
| 60 | if (boundBox.isNegative() || boundBox.width() > MaximumEntityBoundBox || boundBox.height() > MaximumEntityBoundBox) { |
| 61 | throw EntityMapException::format("Entity id: {} type: {} bound box is negative or beyond the maximum entity bound box size in EntityMap::addEntity", |
| 62 | entity->entityId(), (int)entity->entityType()); |
| 63 | } |
| 64 | |
| 65 | if (entityId == NullEntityId) |
| 66 | throw EntityMapException::format("Null entity id in EntityMap::addEntity"); |
| 67 | |
| 68 | if (uniqueId && m_uniqueMap.hasLeftValue(*uniqueId)) |
| 69 | throw EntityMapException::format("Duplicate entity unique id ({}) on entity id ({}) in EntityMap::addEntity", *uniqueId, entityId); |
| 70 | |
| 71 | m_spatialMap.set(entityId, m_geometry.splitRect(boundBox, position), std::move(entity)); |
| 72 | if (uniqueId) |
| 73 | m_uniqueMap.add(*uniqueId, entityId); |
| 74 | } |
| 75 | |
| 76 | EntityPtr EntityMap::removeEntity(EntityId entityId) { |
| 77 | if (auto entity = m_spatialMap.remove(entityId)) { |
no test coverage detected