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

@@ -18,5 +18,5 @@ void ForceVolumeServer::OnStartup(Entity* self) {
phantomPhysicsComponent->SetDirection({ forceX, forceY, forceZ });
phantomPhysicsComponent->SetPhysicsEffectActive(true);
EntityManager::Instance()->SerializeEntity(self);
Game::entityManager->SerializeEntity(self);
}

View File

@@ -10,13 +10,13 @@ void NjIceRailActivator::OnPlayerRailArrived(Entity* self, Entity* sender, const
if (breakPoint == waypoint) {
const auto& blockGroup = self->GetVar<std::u16string>(BlockGroupVariable);
for (auto* block : EntityManager::Instance()->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(blockGroup))) {
for (auto* block : Game::entityManager->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(blockGroup))) {
RenderComponent::PlayAnimation(block, u"explode");
const auto blockID = block->GetObjectID();
self->AddCallbackTimer(1.0f, [self, blockID]() {
auto* block = EntityManager::Instance()->GetEntity(blockID);
auto* block = Game::entityManager->GetEntity(blockID);
if (block != nullptr) {
block->Kill(self);

View File

@@ -42,7 +42,7 @@ void NjRailPostServer::OnRebuildNotifyState(Entity* self, eRebuildState state) {
Entity* NjRailPostServer::GetRelatedRail(Entity* self) {
const auto& railGroup = self->GetVar<std::u16string>(RailGroupVariable);
if (!railGroup.empty()) {
for (auto* entity : EntityManager::Instance()->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(railGroup))) {
for (auto* entity : Game::entityManager->GetEntitiesInGroup(GeneralUtils::UTF16ToWTF8(railGroup))) {
return entity;
}
}

View File

@@ -95,7 +95,7 @@ void PetDigServer::OnDie(Entity* self, Entity* killer) {
// TODO: Reset other pets
// Handles smashing leftovers (edge case for the AG X)
auto* xObject = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"X"));
auto* xObject = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"X"));
if (xObject != nullptr) {
xObject->Smash(xObject->GetObjectID(), eKillType::VIOLENT);
}
@@ -106,7 +106,7 @@ void PetDigServer::HandleXBuildDig(const Entity* self, Entity* owner, Entity* pe
if (playerID == LWOOBJID_EMPTY || playerID != owner->GetObjectID())
return;
auto* playerEntity = EntityManager::Instance()->GetEntity(playerID);
auto* playerEntity = Game::entityManager->GetEntity(playerID);
if (!playerEntity || !playerEntity->GetParentUser() || !playerEntity->GetParentUser()->GetLastUsedChar())
return;
@@ -134,7 +134,7 @@ void PetDigServer::HandleXBuildDig(const Entity* self, Entity* owner, Entity* pe
player->SetPlayerFlag(playerFlag, true);
}
auto* xObject = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"X"));
auto* xObject = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"X"));
if (xObject != nullptr) {
xObject->Smash(xObject->GetObjectID(), eKillType::VIOLENT);
}
@@ -211,8 +211,8 @@ void PetDigServer::SpawnPet(Entity* self, const Entity* owner, const DigInfo dig
new LDFData<float>(u"spawnTimer", 1.0)
};
auto* spawnedPet = EntityManager::Instance()->CreateEntity(info);
EntityManager::Instance()->ConstructEntity(spawnedPet);
auto* spawnedPet = Game::entityManager->CreateEntity(info);
Game::entityManager->ConstructEntity(spawnedPet);
}
Entity* PetDigServer::GetClosestTresure(NiPoint3 position) {
@@ -220,7 +220,7 @@ Entity* PetDigServer::GetClosestTresure(NiPoint3 position) {
Entity* closest = nullptr;
for (const auto tresureId : treasures) {
auto* tresure = EntityManager::Instance()->GetEntity(tresureId);
auto* tresure = Game::entityManager->GetEntity(tresureId);
if (tresure == nullptr) continue;

View File

@@ -5,7 +5,7 @@
#include "eMissionState.h"
void PropertyDevice::OnStartup(Entity* self) {
auto* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
auto* zoneControl = Game::entityManager->GetZoneControlEntity();
if (zoneControl != nullptr) {
zoneControl->OnFireEventServerSide(self, "CheckForPropertyOwner");
}

View File

@@ -41,7 +41,7 @@ void QbSpawner::OnTimerDone(Entity* self, std::string timerName) {
auto gateObjID = self->GetVar<LWOOBJID>(u"gateObj");
if (!gateObjID) return;
auto* gate = EntityManager::Instance()->GetEntity(gateObjID);
auto* gate = Game::entityManager->GetEntity(gateObjID);
if (!gate) return;
auto oPos = gate->GetPosition();
@@ -75,12 +75,12 @@ void QbSpawner::OnTimerDone(Entity* self, std::string timerName) {
new LDFData<int>(u"mobTableLoc", i)
};
auto* child = EntityManager::Instance()->CreateEntity(info, nullptr, self);
EntityManager::Instance()->ConstructEntity(child);
auto* child = Game::entityManager->CreateEntity(info, nullptr, self);
Game::entityManager->ConstructEntity(child);
OnChildLoaded(self, child);
} else {
auto* mob = EntityManager::Instance()->GetEntity(mobTable[i]);
auto* mob = Game::entityManager->GetEntity(mobTable[i]);
AggroTargetObject(self, mob);
}
}
@@ -100,7 +100,7 @@ void QbSpawner::OnChildLoaded(Entity* self, Entity* child) {
const auto selfID = self->GetObjectID();
child->AddDieCallback([this, selfID, child]() {
auto* self = EntityManager::Instance()->GetEntity(selfID);
auto* self = Game::entityManager->GetEntity(selfID);
OnChildRemoved(self, child);
}
);
@@ -120,7 +120,7 @@ void QbSpawner::AggroTargetObject(Entity* self, Entity* enemy) {
auto gateObjID = self->GetVar<LWOOBJID>(u"gateObj");
if (gateObjID) {
auto* gate = EntityManager::Instance()->GetEntity(gateObjID);
auto* gate = Game::entityManager->GetEntity(gateObjID);
if (gate) {
auto* movementAIComponent = enemy->GetComponent<MovementAIComponent>();
if (movementAIComponent) movementAIComponent->SetDestination(gate->GetPosition());

View File

@@ -33,7 +33,7 @@ void WishingWellServer::OnUse(Entity* self, Entity* user) {
const auto userID = user->GetObjectID();
self->AddCallbackTimer(10, [self, userID]() {
auto* user = EntityManager::Instance()->GetEntity(userID);
auto* user = Game::entityManager->GetEntity(userID);
if (user == nullptr) return;