mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
Move EntityManager to Game namespace (#1140)
* Move EntityManager to Game namespace * move initialization to later Need to wait for dZoneManager to be initialized. * Fix bugs - Cannot delete from a RandomAccessIterator while in a range based for loop. Touchup zone manager initialize replace magic numbers with better named constants replace magic zonecontrol id with a more readable hex alternative condense stack variables move initializers closer to their use initialize entity manager with zone control change initialize timings If zone is not zero we expect to initialize the entity manager during zone manager initialization Add constexpr for zone control LOT * Add proper error handling * revert vanity changes * Update WorldServer.cpp * Update dZoneManager.cpp
This commit is contained in:
@@ -332,7 +332,7 @@ void Level::ReadSceneObjectDataChunk(std::istream& file, Header& header) {
|
||||
if (zoneControlObject != nullptr && info.lot == zoneControlObject->GetLOT())
|
||||
goto deleteSettings;
|
||||
|
||||
EntityManager::Instance()->CreateEntity(info, nullptr);
|
||||
Game::entityManager->CreateEntity(info, nullptr);
|
||||
} else {
|
||||
deleteSettings:
|
||||
|
||||
|
@@ -46,7 +46,7 @@ Spawner::Spawner(const SpawnerInfo info) {
|
||||
}
|
||||
|
||||
if (m_Info.spawnOnSmashGroupName != "") {
|
||||
std::vector<Entity*> spawnSmashEntities = EntityManager::Instance()->GetEntitiesInGroup(m_Info.spawnOnSmashGroupName);
|
||||
std::vector<Entity*> spawnSmashEntities = Game::entityManager->GetEntitiesInGroup(m_Info.spawnOnSmashGroupName);
|
||||
std::vector<Spawner*> spawnSmashSpawners = dZoneManager::Instance()->GetSpawnersInGroup(m_Info.spawnOnSmashGroupName);
|
||||
std::vector<Spawner*> spawnSmashSpawnersN = dZoneManager::Instance()->GetSpawnersByName(m_Info.spawnOnSmashGroupName);
|
||||
for (Entity* ssEntity : spawnSmashEntities) {
|
||||
@@ -102,11 +102,11 @@ Entity* Spawner::Spawn(std::vector<SpawnerNode*> freeNodes, const bool force) {
|
||||
m_EntityInfo.spawnerID = m_Info.spawnerID;
|
||||
}
|
||||
|
||||
Entity* rezdE = EntityManager::Instance()->CreateEntity(m_EntityInfo, nullptr);
|
||||
Entity* rezdE = Game::entityManager->CreateEntity(m_EntityInfo, nullptr);
|
||||
|
||||
rezdE->GetGroups() = m_Info.groups;
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(rezdE);
|
||||
Game::entityManager->ConstructEntity(rezdE);
|
||||
|
||||
m_Entities.insert({ rezdE->GetObjectID(), spawnNode });
|
||||
spawnNode->entities.push_back(rezdE->GetObjectID());
|
||||
@@ -143,7 +143,7 @@ void Spawner::Reset() {
|
||||
void Spawner::DestroyAllEntities(){
|
||||
for (auto* node : m_Info.nodes) {
|
||||
for (const auto& element : node->entities) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(element);
|
||||
auto* entity = Game::entityManager->GetEntity(element);
|
||||
if (entity == nullptr) continue;
|
||||
entity->Kill();
|
||||
}
|
||||
|
@@ -39,8 +39,8 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
|
||||
zoneControlTemplate = zone->zoneControlTemplate != -1 ? zone->zoneControlTemplate : 2365;
|
||||
const auto min = zone->ghostdistance_min != -1.0f ? zone->ghostdistance_min : 100;
|
||||
const auto max = zone->ghostdistance != -1.0f ? zone->ghostdistance : 100;
|
||||
EntityManager::Instance()->SetGhostDistanceMax(max + min);
|
||||
EntityManager::Instance()->SetGhostDistanceMin(max);
|
||||
Game::entityManager->SetGhostDistanceMax(max + min);
|
||||
Game::entityManager->SetGhostDistanceMin(max);
|
||||
m_PlayerLoseCoinsOnDeath = zone->PlayerLoseCoinsOnDeath;
|
||||
}
|
||||
}
|
||||
@@ -48,10 +48,15 @@ void dZoneManager::Initialize(const LWOZONEID& zoneID) {
|
||||
Game::logger->Log("dZoneManager", "Creating zone control object %i", zoneControlTemplate);
|
||||
|
||||
// Create ZoneControl object
|
||||
if (!Game::entityManager) {
|
||||
Game::logger->Log("dZoneManager", "ERROR: No entity manager loaded. Cannot proceed.");
|
||||
throw std::invalid_argument("No entity manager loaded. Cannot proceed.");
|
||||
}
|
||||
Game::entityManager->Initialize();
|
||||
EntityInfo info;
|
||||
info.lot = zoneControlTemplate;
|
||||
info.id = 70368744177662;
|
||||
Entity* zoneControl = EntityManager::Instance()->CreateEntity(info, nullptr, nullptr, true);
|
||||
Entity* zoneControl = Game::entityManager->CreateEntity(info, nullptr, nullptr, true);
|
||||
m_ZoneControlObject = zoneControl;
|
||||
|
||||
m_pZone->Initalize();
|
||||
@@ -148,9 +153,9 @@ LWOOBJID dZoneManager::MakeSpawner(SpawnerInfo info) {
|
||||
entityInfo.id = objectId;
|
||||
entityInfo.lot = 176;
|
||||
|
||||
auto* entity = EntityManager::Instance()->CreateEntity(entityInfo, nullptr, nullptr, false, objectId);
|
||||
auto* entity = Game::entityManager->CreateEntity(entityInfo, nullptr, nullptr, false, objectId);
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(entity);
|
||||
Game::entityManager->ConstructEntity(entity);
|
||||
|
||||
AddSpawner(objectId, spawner);
|
||||
|
||||
@@ -175,7 +180,7 @@ void dZoneManager::RemoveSpawner(const LWOOBJID id) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(id);
|
||||
auto* entity = Game::entityManager->GetEntity(id);
|
||||
|
||||
if (entity != nullptr) {
|
||||
entity->Kill();
|
||||
|
Reference in New Issue
Block a user