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:
David Markowitz
2023-07-15 13:56:33 -07:00
committed by GitHub
parent 9375c36c7b
commit 455f9470a5
200 changed files with 861 additions and 862 deletions

View File

@@ -19,7 +19,7 @@ void CatapultBaseServer::OnNotifyObject(Entity* self, Entity* sender, const std:
void CatapultBaseServer::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "PlatAnim") {
// get the arm asset
const auto arm = EntityManager::Instance()->GetEntitiesInGroup(self->GetVarAsString(u"ArmGroup"));
const auto arm = Game::entityManager->GetEntitiesInGroup(self->GetVarAsString(u"ArmGroup"));
// tell the arm to the play the platform animation, which is just the arm laying there but with bouncer
for (auto* obj : arm) {
@@ -34,7 +34,7 @@ void CatapultBaseServer::OnTimerDone(Entity* self, std::string timerName) {
self->AddTimer("bounce", 3);
} else if (timerName == "launchAnim") {
// get the arm asset
auto* arm = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Arm"));
auto* arm = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Arm"));
if (arm == nullptr) return;
// tell the arm to player the launcher animation
@@ -42,7 +42,7 @@ void CatapultBaseServer::OnTimerDone(Entity* self, std::string timerName) {
self->AddTimer("resetArm", animTime);
RenderComponent::PlayAnimation(arm, u"launch");
} else if (timerName == "bounce") {
auto* bouncer = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Bouncer"));
auto* bouncer = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Bouncer"));
if (bouncer == nullptr) return;
// bounce all players
@@ -50,13 +50,13 @@ void CatapultBaseServer::OnTimerDone(Entity* self, std::string timerName) {
// add a delay to play the animation
self->AddTimer("launchAnim", .3);
} else if (timerName == "resetArm") {
auto* arm = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Arm"));
auto* arm = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Arm"));
if (arm == nullptr) return;
// set the arm back to natural state
RenderComponent::PlayAnimation(arm, u"idle");
auto* bouncer = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Bouncer"));
auto* bouncer = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Bouncer"));
if (bouncer == nullptr) return;
// kill the bouncer

View File

@@ -7,7 +7,7 @@ void CatapultBouncerServer::OnRebuildComplete(Entity* self, Entity* target) {
self->SetNetworkVar<bool>(u"Built", true);
const auto base = EntityManager::Instance()->GetEntitiesInGroup(self->GetVarAsString(u"BaseGroup"));
const auto base = Game::entityManager->GetEntitiesInGroup(self->GetVarAsString(u"BaseGroup"));
for (auto* obj : base) {
obj->NotifyObject(self, "BouncerBuilt");

View File

@@ -36,13 +36,13 @@ void CavePrisonCage::Setup(Entity* self, Spawner* spawner) {
info.spawnerID = self->GetObjectID();
// Spawn the villager inside the jail
auto* entity = EntityManager::Instance()->CreateEntity(info);
auto* entity = Game::entityManager->CreateEntity(info);
// Save the villeger ID
self->SetVar<LWOOBJID>(u"villager", entity->GetObjectID());
// Construct the entity
EntityManager::Instance()->ConstructEntity(entity);
Game::entityManager->ConstructEntity(entity);
}
void CavePrisonCage::OnRebuildNotifyState(Entity* self, eRebuildState state) {
@@ -77,7 +77,7 @@ void CavePrisonCage::SpawnCounterweight(Entity* self, Spawner* spawner) {
rebuildComponent->AddRebuildCompleteCallback([this, self](Entity* user) {
// The counterweight is a simple mover, which is not implemented, so we'll just set it's position
auto* counterweight = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
auto* counterweight = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
if (counterweight == nullptr) {
return;
@@ -87,7 +87,7 @@ void CavePrisonCage::SpawnCounterweight(Entity* self, Spawner* spawner) {
counterweight->SetPosition(counterweight->GetPosition() + NiPoint3(0, -2, 0));
// Serialize the counterweight
EntityManager::Instance()->SerializeEntity(counterweight);
Game::entityManager->SerializeEntity(counterweight);
// notifyPlatformAtLastWaypoint
@@ -95,7 +95,7 @@ void CavePrisonCage::SpawnCounterweight(Entity* self, Spawner* spawner) {
self->SetVar<LWOOBJID>(u"Builder", user->GetObjectID());
// Get the button and make sure it still exists
auto* button = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
auto* button = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
if (button == nullptr) {
return;
@@ -117,7 +117,7 @@ void CavePrisonCage::SpawnCounterweight(Entity* self, Spawner* spawner) {
}
void CavePrisonCage::GetButton(Entity* self) {
const auto buttons = EntityManager::Instance()->GetEntitiesInGroup("PrisonButton_0" + std::to_string(self->GetVarAs<int32_t>(u"myNumber")));
const auto buttons = Game::entityManager->GetEntitiesInGroup("PrisonButton_0" + std::to_string(self->GetVarAs<int32_t>(u"myNumber")));
if (buttons.size() == 0) {
// Try again in 0.5 seconds
@@ -146,7 +146,7 @@ void CavePrisonCage::OnTimerDone(Entity* self, std::string timerName) {
RenderComponent::PlayAnimation(self, u"idle-up");
// Get the villeger
auto* villager = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
auto* villager = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
if (villager == nullptr) {
return;
@@ -155,7 +155,7 @@ void CavePrisonCage::OnTimerDone(Entity* self, std::string timerName) {
GameMessages::SendNotifyClientObject(villager->GetObjectID(), u"TimeToChat", 0, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS);
// Get the builder and make sure it still exists
auto* builder = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Builder"));
auto* builder = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Builder"));
if (builder == nullptr) {
return;
@@ -170,7 +170,7 @@ void CavePrisonCage::OnTimerDone(Entity* self, std::string timerName) {
self->AddTimer("VillagerEscape", 5.0f);
} else if (timerName == "VillagerEscape") {
// Get the villeger and make sure it still exists
auto* villager = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
auto* villager = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
if (villager == nullptr) {
return;
@@ -183,7 +183,7 @@ void CavePrisonCage::OnTimerDone(Entity* self, std::string timerName) {
self->AddTimer("SmashCounterweight", 2.0f);
} else if (timerName == "SmashCounterweight") {
// Get the counterweight and make sure it still exists
auto* counterweight = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
auto* counterweight = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
if (counterweight == nullptr) {
return;
@@ -193,7 +193,7 @@ void CavePrisonCage::OnTimerDone(Entity* self, std::string timerName) {
counterweight->Smash();
// Get the button and make sure it still exists
auto* button = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
auto* button = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
if (button == nullptr) {
return;

View File

@@ -28,13 +28,13 @@ void EnemySkeletonSpawner::OnTimerDone(Entity* self, std::string timerName) {
info.rot = self->GetRotation();
info.spawnerID = self->GetObjectID();
auto* spawnedEntity = EntityManager::Instance()->CreateEntity(info);
auto* spawnedEntity = Game::entityManager->CreateEntity(info);
if (spawnedEntity == nullptr) {
return;
}
EntityManager::Instance()->ConstructEntity(spawnedEntity);
Game::entityManager->ConstructEntity(spawnedEntity);
spawnedEntity->AddCallbackTimer(60, [spawnedEntity]() {
spawnedEntity->Smash(spawnedEntity->GetObjectID());

View File

@@ -9,7 +9,7 @@ void MonCoreSmashableDoors::OnDie(Entity* self, Entity* killer) {
auto triggerGroup = "CoreNookTrig0" + myNum;
// Get the trigger
auto triggers = EntityManager::Instance()->GetEntitiesInGroup(triggerGroup);
auto triggers = Game::entityManager->GetEntitiesInGroup(triggerGroup);
if (triggers.empty()) {
return;

View File

@@ -12,7 +12,7 @@ void NjNPCMissionSpinjitzuServer::OnMissionDialogueOK(Entity* self, Entity* targ
// Wait for an animation to complete and flag that the player has learned spinjitzu
self->AddCallbackTimer(5.0f, [targetID, element]() {
auto* target = EntityManager::Instance()->GetEntity(targetID);
auto* target = Game::entityManager->GetEntity(targetID);
if (target != nullptr) {
auto* character = target->GetCharacter();
if (character != nullptr) {

View File

@@ -28,7 +28,7 @@ void NjWuNPC::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, e
character->SetPlayerFlag(ePlayerFlag::NJ_WU_SHOW_DAILY_CHEST, false);
// Hide the chest
for (auto* chest : EntityManager::Instance()->GetEntitiesInGroup(m_DragonChestGroup)) {
for (auto* chest : Game::entityManager->GetEntitiesInGroup(m_DragonChestGroup)) {
GameMessages::SendNotifyClientObject(chest->GetObjectID(), m_ShowChestNotification, 0, -1,
target->GetObjectID(), "", target->GetSystemAddress());
}
@@ -41,19 +41,19 @@ void NjWuNPC::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, e
character->SetPlayerFlag(ePlayerFlag::NJ_WU_SHOW_DAILY_CHEST, true);
// Show the chest
for (auto* chest : EntityManager::Instance()->GetEntitiesInGroup(m_DragonChestGroup)) {
for (auto* chest : Game::entityManager->GetEntitiesInGroup(m_DragonChestGroup)) {
GameMessages::SendNotifyClientObject(chest->GetObjectID(), m_ShowChestNotification, 1, -1,
target->GetObjectID(), "", target->GetSystemAddress());
}
auto playerID = target->GetObjectID();
self->AddCallbackTimer(5.0f, [this, playerID]() {
auto* player = EntityManager::Instance()->GetEntity(playerID);
auto* player = Game::entityManager->GetEntity(playerID);
if (player == nullptr)
return;
// Stop the dragon effects
for (auto* dragon : EntityManager::Instance()->GetEntitiesInGroup(m_DragonStatueGroup)) {
for (auto* dragon : Game::entityManager->GetEntitiesInGroup(m_DragonStatueGroup)) {
GameMessages::SendStopFXEffect(dragon, true, "on");
}
});

View File

@@ -18,9 +18,9 @@ void RainOfArrows::OnRebuildComplete(Entity* self, Entity* target) {
info.rot = myRot;
info.spawnerID = self->GetObjectID();
auto* entity = EntityManager::Instance()->CreateEntity(info);
auto* entity = Game::entityManager->CreateEntity(info);
EntityManager::Instance()->ConstructEntity(entity);
Game::entityManager->ConstructEntity(entity);
self->SetVar<LWOOBJID>(u"ChildFX", entity->GetObjectID());
self->SetVar<LWOOBJID>(u"playerID", target->GetObjectID());
@@ -30,11 +30,11 @@ void RainOfArrows::OnRebuildComplete(Entity* self, Entity* target) {
}
void RainOfArrows::OnTimerDone(Entity* self, std::string timerName) {
auto* child = EntityManager::Instance()->GetEntity(
auto* child = Game::entityManager->GetEntity(
self->GetVar<LWOOBJID>(u"ChildFX")
);
auto* player = EntityManager::Instance()->GetEntity(
auto* player = Game::entityManager->GetEntity(
self->GetVar<LWOOBJID>(u"playerID")
);

View File

@@ -122,7 +122,7 @@ void NjMonastryBossInstance::OnActivityTimerDone(Entity* self, const std::string
if (timerName == WaitingForPlayersTimer) {
StartFight(self);
} else if (timerName == SpawnNextWaveTimer) {
auto* frakjaw = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(LedgeFrakjawVariable));
auto* frakjaw = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(LedgeFrakjawVariable));
if (frakjaw != nullptr) {
SummonWave(self, frakjaw);
}
@@ -145,7 +145,7 @@ void NjMonastryBossInstance::OnActivityTimerDone(Entity* self, const std::string
}
}
} else if (timerName + TimerSplitChar == UnstunTimer) {
auto* entity = EntityManager::Instance()->GetEntity(objectID);
auto* entity = Game::entityManager->GetEntity(objectID);
if (entity != nullptr) {
auto* combatAI = entity->GetComponent<BaseCombatAIComponent>();
if (combatAI != nullptr) {
@@ -164,7 +164,7 @@ void NjMonastryBossInstance::OnActivityTimerDone(Entity* self, const std::string
}
} else if (timerName == LowerFrakjawCamTimer) {
// Destroy the frakjaw on the ledge
auto* ledgeFrakjaw = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(LedgeFrakjawVariable));
auto* ledgeFrakjaw = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(LedgeFrakjawVariable));
if (ledgeFrakjaw != nullptr) {
ledgeFrakjaw->Kill();
}
@@ -188,7 +188,7 @@ void NjMonastryBossInstance::OnActivityTimerDone(Entity* self, const std::string
spawner->Activate();
}
} else if (timerName + TimerSplitChar == FrakjawSpawnInTimer) {
auto* lowerFrakjaw = EntityManager::Instance()->GetEntity(objectID);
auto* lowerFrakjaw = Game::entityManager->GetEntity(objectID);
if (lowerFrakjaw != nullptr) {
LowerFrakjawSummon(self, lowerFrakjaw);
}
@@ -250,7 +250,7 @@ void NjMonastryBossInstance::HandleCounterWeightSpawned(Entity* self, Entity* co
counterWeight->Kill();
}
auto* frakjaw = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(LedgeFrakjawVariable));
auto* frakjaw = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(LedgeFrakjawVariable));
if (frakjaw == nullptr) {
GameMessages::SendNotifyClientObject(self->GetObjectID(), u"LedgeFrakjawDead", 0,
0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS);
@@ -342,7 +342,7 @@ void NjMonastryBossInstance::HandleLowerFrakjawHit(Entity* self, Entity* lowerFr
std::vector<LWOOBJID> newTrashMobs = {};
for (const auto& trashMobID : trashMobsAlive) {
auto* trashMob = EntityManager::Instance()->GetEntity(trashMobID);
auto* trashMob = Game::entityManager->GetEntity(trashMobID);
if (trashMob != nullptr) {
newTrashMobs.push_back(trashMobID);
@@ -393,7 +393,7 @@ void NjMonastryBossInstance::HandleWaveEnemyDied(Entity* self, Entity* waveEnemy
}
void NjMonastryBossInstance::TeleportPlayer(Entity* player, uint32_t position) {
for (const auto* spawnPoint : EntityManager::Instance()->GetEntitiesInGroup("SpawnPoint" + std::to_string(position))) {
for (const auto* spawnPoint : Game::entityManager->GetEntitiesInGroup("SpawnPoint" + std::to_string(position))) {
GameMessages::SendTeleport(player->GetObjectID(), spawnPoint->GetPosition(), spawnPoint->GetRotation(),
player->GetSystemAddress(), true);
}
@@ -433,7 +433,7 @@ void NjMonastryBossInstance::RemovePoison(Entity* self) {
const auto& totalPlayer = self->GetVar<std::vector<LWOOBJID>>(TotalPlayersLoadedVariable);
for (const auto& playerID : totalPlayer) {
auto* player = EntityManager::Instance()->GetEntity(playerID);
auto* player = Game::entityManager->GetEntity(playerID);
if (player != nullptr) {
auto* buffComponent = player->GetComponent<BuffComponent>();
@@ -505,7 +505,7 @@ void NjMonastryBossInstance::FightOver(Entity* self) {
GameMessages::SendNotifyClientObject(self->GetObjectID(), PlayCinematicNotification, 0, 0,
LWOOBJID_EMPTY, TreasureChestSpawning, UNASSIGNED_SYSTEM_ADDRESS);
auto treasureChests = EntityManager::Instance()->GetEntitiesInGroup(ChestSpawnpointGroup);
auto treasureChests = Game::entityManager->GetEntitiesInGroup(ChestSpawnpointGroup);
for (auto* treasureChest : treasureChests) {
auto info = EntityInfo{};
@@ -518,7 +518,7 @@ void NjMonastryBossInstance::FightOver(Entity* self) {
};
// Finally spawn a treasure chest at the correct spawn point
auto* chestObject = EntityManager::Instance()->CreateEntity(info);
EntityManager::Instance()->ConstructEntity(chestObject);
auto* chestObject = Game::entityManager->CreateEntity(info);
Game::entityManager->ConstructEntity(chestObject);
}
}