@@ -18,14 +18,11 @@ void LogicEntity::Initialize() {
1818 InitializeNPCSystem ();
1919 InitializeMobSystem ();
2020 InitializeCollisionSystem ();
21-
2221 auto & config = ConfigManager::GetInstance ();
23-
2422 // Initialize loot systems
25- inventorySystem_ = std::make_unique<InventorySystem>();
23+ // inventorySystem_ = std::make_unique<InventorySystem>();
2624 lootTableManager_ = std::make_unique<LootTableManager>();
2725 lootTableManager_->LoadLootTables (" config/loot_tables.json" );
28-
2926 Logger::Info (" LogicEntity initialized" );
3027}
3128
@@ -35,42 +32,35 @@ void LogicEntity::Shutdown() {
3532 npcEntities_.clear ();
3633 activeNPCCount_ = 0 ;
3734 }
38-
3935 npcManager_.reset ();
4036 collisionSystem_.reset ();
41- inventorySystem_.reset ();
37+ // inventorySystem_.reset();
4238 lootTableManager_.reset ();
43-
4439 Logger::Info (" LogicEntity shutdown" );
4540}
4641
4742void LogicEntity::InitializeNPCSystem () {
4843 Logger::Info (" Initializing NPC system..." );
4944 npcManager_ = std::make_unique<NPCManager>();
50-
5145 auto & config = ConfigManager::GetInstance ();
5246 int initialNPCCount = config.GetInt (" npcs.initial_count" , 20 );
53-
5447 std::random_device rd;
5548 std::mt19937 gen (rd ());
5649 std::uniform_real_distribution<float > posDist (-200 .0f , 200 .0f );
5750 std::uniform_int_distribution<int > npcTypeDist (0 , 3 );
58-
5951 for (int i = 0 ; i < initialNPCCount; ++i) {
6052 float x = posDist (gen);
6153 float z = posDist (gen);
6254 float y = 20 .0f ; // Default height
6355 NPCType type = static_cast <NPCType>(npcTypeDist (gen));
6456 SpawnNPC (type, glm::vec3 (x, y, z));
6557 }
66-
6758 Logger::Info (" Spawned {} initial NPCs" , initialNPCCount);
6859}
6960
7061void LogicEntity::InitializeMobSystem () {
7162 Logger::Info (" Initializing mob system..." );
7263 mobSystem_.Initialize ();
73-
7464 auto & config = ConfigManager::GetInstance ();
7565 if (config.HasKey (" mobs" )) {
7666 nlohmann::json mobConfig = config.GetJson (" mobs" );
@@ -85,56 +75,46 @@ void LogicEntity::InitializeCollisionSystem() {
8575
8676uint64_t LogicEntity::SpawnNPC (NPCType type, const glm::vec3& position, uint64_t ownerId) {
8777 std::lock_guard<std::mutex> lock (npcMutex_);
88-
8978 uint64_t npcId = npcManager_->SpawnNPC (type, position, ownerId);
9079 if (npcId == 0 ) {
9180 Logger::Error (" Failed to spawn NPC type {}" , static_cast <int >(type));
9281 return 0 ;
9382 }
94-
9583 NPCEntity* npc = npcManager_->GetNPC (npcId);
9684 if (!npc) {
9785 Logger::Error (" Failed to get spawned NPC" );
9886 return 0 ;
9987 }
100-
10188 npcEntities_[npcId] = std::unique_ptr<NPCEntity>(npc);
10289 activeNPCCount_++;
103-
10490 // Register in collision system
10591 BoundingSphere bounds{position, 1 .0f };
10692 collisionSystem_->RegisterEntity (npcId, bounds, CollisionType::ENTITY );
107-
10893 Logger::Debug (" Spawned NPC {} at [{:.1f}, {:.1f}, {:.1f}]" ,
10994 npcId, position.x , position.y , position.z );
11095 return npcId;
11196}
11297
11398void LogicEntity::DespawnNPC (uint64_t npcId) {
11499 std::lock_guard<std::mutex> lock (npcMutex_);
115-
116100 auto it = npcEntities_.find (npcId);
117101 if (it == npcEntities_.end ()) {
118102 return ;
119103 }
120-
121104 collisionSystem_->UnregisterEntity (npcId);
122105 npcManager_->DespawnNPC (npcId);
123106 npcEntities_.erase (it);
124107 activeNPCCount_--;
125-
126108 Logger::Debug (" Despawned NPC {}" , npcId);
127109}
128110
129111void LogicEntity::UpdateNPCs (float deltaTime) {
130112 std::lock_guard<std::mutex> lock (npcMutex_);
131-
132113 for (auto & [npcId, npc] : npcEntities_) {
133114 if (!npc) continue ;
134115 npc->Update (deltaTime);
135116 collisionSystem_->UpdateEntity (npcId, npc->GetPosition ());
136117 }
137-
138118 mobSystem_.UpdateSpawnZones (deltaTime);
139119 mobSystem_.ProcessRespawns (deltaTime);
140120}
@@ -177,6 +157,5 @@ void LogicEntity::CreateLootEntity(const glm::vec3& position, std::shared_ptr<Lo
177157 uint64_t entityId = entityManager_.CreateEntity (EntityType::ITEM , position);
178158 BoundingSphere bounds{position, 0 .5f };
179159 collisionSystem_->RegisterEntity (entityId, bounds, CollisionType::TRIGGER );
180-
181160 Logger::Debug (" Created loot entity {}: {} x{}" , entityId, item->GetName (), quantity);
182161}
0 commit comments