MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / addEntity

Method addEntity

source/game/StarEntityMap.cpp:51–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50
51void 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
76EntityPtr EntityMap::removeEntity(EntityId entityId) {
77 if (auto entity = m_spatialMap.remove(entityId)) {

Callers 15

moveBlockMethod · 0.45
placeObjectMethod · 0.45
placeVehicleMethod · 0.45
placePlantMethod · 0.45
placeBiomeItemsMethod · 0.45
addDropMethod · 0.45
spawnNpcMethod · 0.45
spawnStagehandMethod · 0.45
spawnEntityMethod · 0.45
prepareSectorMethod · 0.45
reapplyBiomeMethod · 0.45
breakAtPositionMethod · 0.45

Calls 14

entityIdMethod · 0.80
uniqueIdMethod · 0.80
isNegativeMethod · 0.80
hasLeftValueMethod · 0.80
formatFunction · 0.50
positionMethod · 0.45
metaBoundBoxMethod · 0.45
containsMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
entityTypeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected