diff --git a/OpenTESArena/src/Entities/EntityChunkManager.cpp b/OpenTESArena/src/Entities/EntityChunkManager.cpp index 9c118e955..ebd722a29 100644 --- a/OpenTESArena/src/Entities/EntityChunkManager.cpp +++ b/OpenTESArena/src/Entities/EntityChunkManager.cpp @@ -275,6 +275,15 @@ void EntityChunkManager::populateChunkEntities(EntityChunk &entityChunk, const V DebugLogError("Couldn't allocate Jolt physics body for entity."); } + bool hasInventory = (entityDefType == EntityDefinitionType::Enemy) || (entityDefType == EntityDefinitionType::Container); + if (hasInventory) + { + if (!this->itemInventories.tryAlloc(&entityInst.itemInventoryInstID)) + { + DebugCrash("Couldn't allocate EntityItemInventoryInstanceID."); + } + } + entityChunk.entityIDs.emplace_back(entityInstID); } } @@ -697,7 +706,7 @@ const EntityAnimationInstance &EntityChunkManager::getEntityAnimationInstance(En return this->animInsts.get(id); } -const int8_t &EntityChunkManager::getEntityCitizenDirectionIndex(EntityCitizenDirectionIndexID id) const +int8_t EntityChunkManager::getEntityCitizenDirectionIndex(EntityCitizenDirectionIndexID id) const { return this->citizenDirectionIndices.get(id); } @@ -707,6 +716,11 @@ const PaletteIndices &EntityChunkManager::getEntityPaletteIndices(EntityPaletteI return this->paletteIndices.get(id); } +ItemInventory &EntityChunkManager::getEntityItemInventory(EntityItemInventoryInstanceID id) +{ + return this->itemInventories.get(id); +} + int EntityChunkManager::getCountInChunkWithDirection(const ChunkInt2 &chunkPos) const { int count = 0; @@ -1068,6 +1082,11 @@ void EntityChunkManager::cleanUp(JPH::PhysicsSystem &physicsSystem) this->paletteIndices.free(entityInst.paletteIndicesInstID); } + if (entityInst.itemInventoryInstID >= 0) + { + this->itemInventories.free(entityInst.itemInventoryInstID); + } + const JPH::BodyID physicsBodyID = entityInst.physicsBodyID; if (!physicsBodyID.IsInvalid()) { diff --git a/OpenTESArena/src/Entities/EntityChunkManager.h b/OpenTESArena/src/Entities/EntityChunkManager.h index 7bb90e683..58600b631 100644 --- a/OpenTESArena/src/Entities/EntityChunkManager.h +++ b/OpenTESArena/src/Entities/EntityChunkManager.h @@ -11,6 +11,7 @@ #include "EntityGeneration.h" #include "EntityInstance.h" #include "EntityUtils.h" +#include "../Items/ItemInventory.h" #include "../Math/BoundingBox.h" #include "../World/SpecializedChunkManager.h" @@ -43,6 +44,7 @@ class EntityChunkManager final : public SpecializedChunkManager using EntityCreatureSoundPool = RecyclablePool; using EntityCitizenDirectionIndexPool = RecyclablePool; using EntityPaletteIndicesInstancePool = RecyclablePool; + using EntityItemInventoryInstancePool = RecyclablePool; EntityPool entities; EntityPositionPool positions; @@ -57,6 +59,8 @@ class EntityChunkManager final : public SpecializedChunkManager // citizen textures will need to be 8-bit. EntityPaletteIndicesInstancePool paletteIndices; + EntityItemInventoryInstancePool itemInventories; + // Entity definitions for this currently-active level. Their definition IDs CANNOT be assumed // to be zero-based because these are in addition to ones in the entity definition library. // @todo: separate EntityAnimationDefinition from EntityDefinition? @@ -96,8 +100,9 @@ class EntityChunkManager final : public SpecializedChunkManager const VoxelDouble2 &getEntityDirection(EntityDirectionID id) const; EntityAnimationInstance &getEntityAnimationInstance(EntityAnimationInstanceID id); const EntityAnimationInstance &getEntityAnimationInstance(EntityAnimationInstanceID id) const; - const int8_t &getEntityCitizenDirectionIndex(EntityCitizenDirectionIndexID id) const; + int8_t getEntityCitizenDirectionIndex(EntityCitizenDirectionIndexID id) const; const PaletteIndices &getEntityPaletteIndices(EntityPaletteIndicesInstanceID id) const; + ItemInventory &getEntityItemInventory(EntityItemInventoryInstanceID id); // Gets the entities scheduled for destruction this frame. If they're in this list, they should no longer be // simulated or rendered. diff --git a/OpenTESArena/src/Entities/EntityInstance.cpp b/OpenTESArena/src/Entities/EntityInstance.cpp index 85641c3cc..03a73c668 100644 --- a/OpenTESArena/src/Entities/EntityInstance.cpp +++ b/OpenTESArena/src/Entities/EntityInstance.cpp @@ -29,6 +29,11 @@ bool EntityInstance::isCitizen() const return this->citizenDirectionIndexID >= 0; } +bool EntityInstance::hasInventory() const +{ + return this->itemInventoryInstID >= 0; +} + void EntityInstance::clear() { this->instanceID = -1; @@ -40,5 +45,6 @@ void EntityInstance::clear() this->creatureSoundInstID = -1; this->citizenDirectionIndexID = -1; this->paletteIndicesInstID = -1; + this->itemInventoryInstID = -1; this->physicsBodyID = JPH::BodyID(); } diff --git a/OpenTESArena/src/Entities/EntityInstance.h b/OpenTESArena/src/Entities/EntityInstance.h index 068aed14c..4a9f8970e 100644 --- a/OpenTESArena/src/Entities/EntityInstance.h +++ b/OpenTESArena/src/Entities/EntityInstance.h @@ -14,6 +14,7 @@ using EntityAnimationInstanceID = int; using EntityCreatureSoundInstanceID = int; using EntityCitizenDirectionIndexID = int; using EntityPaletteIndicesInstanceID = int; +using EntityItemInventoryInstanceID = int; struct EntityInstance { @@ -26,6 +27,7 @@ struct EntityInstance EntityCreatureSoundInstanceID creatureSoundInstID; EntityCitizenDirectionIndexID citizenDirectionIndexID; EntityPaletteIndicesInstanceID paletteIndicesInstID; + EntityItemInventoryInstanceID itemInventoryInstID; JPH::BodyID physicsBodyID; EntityInstance(); @@ -38,6 +40,8 @@ struct EntityInstance bool isCitizen() const; + bool hasInventory() const; + void clear(); };