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

@@ -263,7 +263,7 @@ void Entity::Initialize() {
NiQuaternion rot;
const auto& targetSceneName = m_Character->GetTargetScene();
auto* targetScene = EntityManager::Instance()->GetSpawnPointEntity(targetSceneName);
auto* targetScene = Game::entityManager->GetSpawnPointEntity(targetSceneName);
if (m_Character->HasBeenToWorld(mapID) && targetSceneName.empty()) {
pos = m_Character->GetRespawnPoint(mapID);
@@ -735,7 +735,7 @@ void Entity::Initialize() {
}
});
if (!m_Character && EntityManager::Instance()->GetGhostingEnabled()) {
if (!m_Character && Game::entityManager->GetGhostingEnabled()) {
// Don't ghost what is likely large scene elements
if (HasComponent(eReplicaComponentType::SIMPLE_PHYSICS) && HasComponent(eReplicaComponentType::RENDER) && (m_Components.size() == 2 || (HasComponent(eReplicaComponentType::TRIGGER) && m_Components.size() == 3))) {
goto no_ghosting;
@@ -1284,12 +1284,12 @@ void Entity::Update(const float deltaTime) {
}
if (m_ShouldDestroyAfterUpdate) {
EntityManager::Instance()->DestroyEntity(this->GetObjectID());
Game::entityManager->DestroyEntity(this->GetObjectID());
}
}
void Entity::OnCollisionProximity(LWOOBJID otherEntity, const std::string& proxName, const std::string& status) {
Entity* other = EntityManager::Instance()->GetEntity(otherEntity);
Entity* other = Game::entityManager->GetEntity(otherEntity);
if (!other) return;
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
@@ -1303,7 +1303,7 @@ void Entity::OnCollisionProximity(LWOOBJID otherEntity, const std::string& proxN
}
void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
auto* other = EntityManager::Instance()->GetEntity(otherEntity);
auto* other = Game::entityManager->GetEntity(otherEntity);
if (!other) return;
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
@@ -1350,7 +1350,7 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
}
void Entity::OnCollisionLeavePhantom(const LWOOBJID otherEntity) {
auto* other = EntityManager::Instance()->GetEntity(otherEntity);
auto* other = Game::entityManager->GetEntity(otherEntity);
if (!other) return;
for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) {
@@ -1504,13 +1504,13 @@ void Entity::Smash(const LWOOBJID source, const eKillType killType, const std::u
auto* destroyableComponent = GetComponent<DestroyableComponent>();
if (destroyableComponent == nullptr) {
Kill(EntityManager::Instance()->GetEntity(source));
Kill(Game::entityManager->GetEntity(source));
return;
}
auto* possessorComponent = GetComponent<PossessorComponent>();
if (possessorComponent) {
if (possessorComponent->GetPossessable() != LWOOBJID_EMPTY) {
auto* mount = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
auto* mount = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
if (mount) possessorComponent->Dismount(mount, true);
}
}
@@ -1538,7 +1538,7 @@ void Entity::Kill(Entity* murderer) {
}
if (!IsPlayer()) {
EntityManager::Instance()->DestroyEntity(this);
Game::entityManager->DestroyEntity(this);
}
const auto& grpNameQBShowBricks = GetVar<std::string>(u"grpNameQBShowBricks");
@@ -1719,7 +1719,7 @@ void Entity::CancelCallbackTimers() {
void Entity::ScheduleKillAfterUpdate(Entity* murderer) {
//if (m_Info.spawner) m_Info.spawner->ScheduleKill(this);
EntityManager::Instance()->ScheduleForKill(this);
Game::entityManager->ScheduleForKill(this);
if (murderer) m_ScheduleKiller = murderer;
}
@@ -1763,7 +1763,7 @@ void Entity::TriggerEvent(eTriggerEventType event, Entity* optionalTarget) {
Entity* Entity::GetOwner() const {
if (m_OwnerOverride != LWOOBJID_EMPTY) {
auto* other = EntityManager::Instance()->GetEntity(m_OwnerOverride);
auto* other = Game::entityManager->GetEntity(m_OwnerOverride);
if (other != nullptr) {
return other->GetOwner();
@@ -1907,7 +1907,7 @@ void Entity::SetPosition(NiPoint3 position) {
vehicel->SetPosition(position);
}
EntityManager::Instance()->SerializeEntity(this);
Game::entityManager->SerializeEntity(this);
}
void Entity::SetRotation(NiQuaternion rotation) {
@@ -1935,7 +1935,7 @@ void Entity::SetRotation(NiQuaternion rotation) {
vehicel->SetRotation(rotation);
}
EntityManager::Instance()->SerializeEntity(this);
Game::entityManager->SerializeEntity(this);
}
bool Entity::GetBoolean(const std::u16string& name) const {
@@ -1987,7 +1987,7 @@ std::vector<LWOOBJID>& Entity::GetTargetsInPhantom() {
for (auto i = 0u; i < m_TargetsInPhantom.size(); ++i) {
const auto id = m_TargetsInPhantom.at(i);
auto* entity = EntityManager::Instance()->GetEntity(id);
auto* entity = Game::entityManager->GetEntity(id);
if (entity == nullptr) {
continue;