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:
@@ -71,6 +71,7 @@
|
||||
#include "eMasterMessageType.h"
|
||||
#include "eGameMessageType.h"
|
||||
#include "ZCompression.h"
|
||||
#include "EntityManager.h"
|
||||
|
||||
namespace Game {
|
||||
dLogger* logger = nullptr;
|
||||
@@ -83,6 +84,7 @@ namespace Game {
|
||||
std::mt19937 randomEngine;
|
||||
SystemAddress chatSysAddr;
|
||||
bool shouldShutdown = false;
|
||||
EntityManager* entityManager = nullptr;
|
||||
} // namespace Game
|
||||
|
||||
bool chatDisabled = false;
|
||||
@@ -251,6 +253,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
PerformanceManager::SelectProfile(zoneID);
|
||||
|
||||
Game::entityManager = new EntityManager();
|
||||
//Load our level:
|
||||
if (zoneID != 0) {
|
||||
dpWorld::Instance().Initialize(zoneID);
|
||||
@@ -297,6 +300,8 @@ int main(int argc, char** argv) {
|
||||
|
||||
Game::logger->Log("WorldServer", "FDB Checksum calculated as: %s", databaseChecksum.c_str());
|
||||
}
|
||||
} else {
|
||||
Game::entityManager->Initialize();
|
||||
}
|
||||
|
||||
uint32_t currentFrameDelta = highFrameDelta;
|
||||
@@ -383,12 +388,12 @@ int main(int argc, char** argv) {
|
||||
Metrics::EndMeasurement(MetricVariable::Physics);
|
||||
|
||||
Metrics::StartMeasurement(MetricVariable::UpdateEntities);
|
||||
EntityManager::Instance()->UpdateEntities(deltaTime);
|
||||
Game::entityManager->UpdateEntities(deltaTime);
|
||||
Metrics::EndMeasurement(MetricVariable::UpdateEntities);
|
||||
|
||||
Metrics::StartMeasurement(MetricVariable::Ghosting);
|
||||
if (std::chrono::duration<float>(currentTime - ghostingLastTime).count() >= 1.0f) {
|
||||
EntityManager::Instance()->UpdateGhosting();
|
||||
Game::entityManager->UpdateGhosting();
|
||||
ghostingLastTime = currentTime;
|
||||
}
|
||||
Metrics::EndMeasurement(MetricVariable::Ghosting);
|
||||
@@ -558,7 +563,7 @@ void HandlePacketChat(Packet* packet) {
|
||||
LWOOBJID playerID;
|
||||
inStream.Read(playerID);
|
||||
|
||||
auto player = EntityManager::Instance()->GetEntity(playerID);
|
||||
auto player = Game::entityManager->GetEntity(playerID);
|
||||
if (!player) return;
|
||||
|
||||
auto sysAddr = player->GetSystemAddress();
|
||||
@@ -614,7 +619,7 @@ void HandlePacketChat(Packet* packet) {
|
||||
inStream.Read(playerId);
|
||||
inStream.Read(expire);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(playerId);
|
||||
auto* entity = Game::entityManager->GetEntity(playerId);
|
||||
|
||||
if (entity != nullptr) {
|
||||
entity->GetParentUser()->SetMuteExpire(expire);
|
||||
@@ -678,7 +683,7 @@ void HandlePacket(Packet* packet) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(c->GetObjectID());
|
||||
auto* entity = Game::entityManager->GetEntity(c->GetObjectID());
|
||||
|
||||
if (!entity) {
|
||||
entity = Player::GetPlayer(packet->systemAddress);
|
||||
@@ -695,7 +700,7 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
Game::logger->Log("WorldServer", "Deleting player %llu", entity->GetObjectID());
|
||||
|
||||
EntityManager::Instance()->DestroyEntity(entity);
|
||||
Game::entityManager->DestroyEntity(entity);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -917,7 +922,7 @@ void HandlePacket(Packet* packet) {
|
||||
if (Game::server->GetZoneID() != 0) {
|
||||
auto user = UserManager::Instance()->GetUser(packet->systemAddress);
|
||||
if (!user) return;
|
||||
EntityManager::Instance()->DestroyEntity(user->GetLastUsedChar()->GetEntity());
|
||||
Game::entityManager->DestroyEntity(user->GetLastUsedChar()->GetEntity());
|
||||
}
|
||||
|
||||
//This loops prevents users who aren't authenticated to double-request the char list, which
|
||||
@@ -1005,20 +1010,20 @@ void HandlePacket(Packet* packet) {
|
||||
|
||||
EntityInfo info{};
|
||||
info.lot = 1;
|
||||
Entity* player = EntityManager::Instance()->CreateEntity(info, UserManager::Instance()->GetUser(packet->systemAddress));
|
||||
Entity* player = Game::entityManager->CreateEntity(info, UserManager::Instance()->GetUser(packet->systemAddress));
|
||||
|
||||
WorldPackets::SendCreateCharacter(packet->systemAddress, player, c->GetXMLData(), username, c->GetGMLevel());
|
||||
WorldPackets::SendServerState(packet->systemAddress);
|
||||
|
||||
const auto respawnPoint = player->GetCharacter()->GetRespawnPoint(dZoneManager::Instance()->GetZone()->GetWorldID());
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(player, UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||
Game::entityManager->ConstructEntity(player, UNASSIGNED_SYSTEM_ADDRESS, true);
|
||||
|
||||
if (respawnPoint != NiPoint3::ZERO) {
|
||||
GameMessages::SendPlayerReachedRespawnCheckpoint(player, respawnPoint, NiQuaternion::IDENTITY);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->ConstructAllEntities(packet->systemAddress);
|
||||
Game::entityManager->ConstructAllEntities(packet->systemAddress);
|
||||
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) {
|
||||
@@ -1330,6 +1335,7 @@ void FinalizeShutdown() {
|
||||
if (Game::server) delete Game::server;
|
||||
if (Game::logger) delete Game::logger;
|
||||
if (Game::config) delete Game::config;
|
||||
if (Game::entityManager) delete Game::entityManager;
|
||||
|
||||
worldShutdownSequenceComplete = true;
|
||||
|
||||
|
Reference in New Issue
Block a user