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

@@ -184,7 +184,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
character->SetPvpEnabled(!character->GetPvpEnabled());
EntityManager::Instance()->SerializeEntity(entity);
Game::entityManager->SerializeEntity(entity);
std::stringstream message;
message << character->GetName() << " changed their PVP flag to " << std::to_string(character->GetPvpEnabled()) << "!";
@@ -289,7 +289,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
const auto objid = entity->GetObjectID();
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, newZone, 0, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
auto* entity = EntityManager::Instance()->GetEntity(objid);
auto* entity = Game::entityManager->GetEntity(objid);
if (entity == nullptr) {
return;
@@ -372,7 +372,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
ChatPackets::SendSystemMessage(sysAddr, u"Invalid Minifig Item Id ID.");
return;
}
EntityManager::Instance()->DestructEntity(entity, sysAddr);
Game::entityManager->DestructEntity(entity, sysAddr);
auto* charComp = entity->GetComponent<CharacterComponent>();
std::string lowerName = args[0];
if (lowerName.empty()) return;
@@ -399,12 +399,12 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
charComp->m_Character->SetLeftHand(minifigItemId);
charComp->m_Character->SetRightHand(minifigItemId);
} else {
EntityManager::Instance()->ConstructEntity(entity);
Game::entityManager->ConstructEntity(entity);
ChatPackets::SendSystemMessage(sysAddr, u"Invalid Minifig item to change, try one of the following: Eyebrows, Eyes, HairColor, HairStyle, Pants, LeftHand, Mouth, RightHand, Shirt, Hands");
return;
}
EntityManager::Instance()->ConstructEntity(entity);
Game::entityManager->ConstructEntity(entity);
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(lowerName) + u" set to " + (GeneralUtils::to_u16string(minifigItemId)));
GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); // need to retoggle because it gets reenabled on creation of new character
@@ -415,13 +415,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
RenderComponent::PlayAnimation(entity, anim);
auto* possessorComponent = entity->GetComponent<PossessorComponent>();
if (possessorComponent) {
auto* possessedComponent = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
auto* possessedComponent = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
if (possessedComponent) RenderComponent::PlayAnimation(possessedComponent, anim);
}
}
if (chatCommand == "list-spawns" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
for (const auto& pair : EntityManager::Instance()->GetSpawnPointEntities()) {
for (const auto& pair : Game::entityManager->GetSpawnPointEntities()) {
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(pair.first));
}
@@ -450,7 +450,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
auto* user = UserManager::Instance()->GetUser(args[0]);
if (user) {
auto* player = EntityManager::Instance()->GetEntity(user->GetLoggedInChar());
auto* player = Game::entityManager->GetEntity(user->GetLoggedInChar());
player->Smash(entity->GetObjectID());
ChatPackets::SendSystemMessage(sysAddr, u"It has been done, do you feel good about yourself now?");
return;
@@ -478,7 +478,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (possessor) {
auto possessedID = possessor->GetPossessable();
if (possessedID != LWOOBJID_EMPTY) {
auto possessable = EntityManager::Instance()->GetEntity(possessedID);
auto possessable = Game::entityManager->GetEntity(possessedID);
if (possessable) {
auto* possessControllablePhysicsComponent = possessable->GetComponent<ControllablePhysicsComponent>();
if (possessControllablePhysicsComponent) {
@@ -488,7 +488,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
}
EntityManager::Instance()->SerializeEntity(entity);
Game::entityManager->SerializeEntity(entity);
}
if (chatCommand == "freecam" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
@@ -937,13 +937,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
auto* possessorComponent = entity->GetComponent<PossessorComponent>();
if (possessorComponent) {
auto* possassableEntity = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
auto* possassableEntity = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
if (possassableEntity != nullptr) {
auto* vehiclePhysicsComponent = possassableEntity->GetComponent<VehiclePhysicsComponent>();
if (vehiclePhysicsComponent) {
vehiclePhysicsComponent->SetPosition(pos);
EntityManager::Instance()->SerializeEntity(possassableEntity);
Game::entityManager->SerializeEntity(possassableEntity);
} else GameMessages::SendTeleport(possassableEntity->GetObjectID(), pos, NiQuaternion(), sysAddr);
}
}
@@ -952,7 +952,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (chatCommand == "tpall" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
const auto pos = entity->GetPosition();
const auto characters = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::CHARACTER);
const auto characters = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::CHARACTER);
for (auto* character : characters) {
GameMessages::SendTeleport(character->GetObjectID(), pos, NiQuaternion(), character->GetSystemAddress());
@@ -966,7 +966,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (possessorComponent) {
auto possessableId = possessorComponent->GetPossessable();
if (possessableId != LWOOBJID_EMPTY) {
auto* possessableEntity = EntityManager::Instance()->GetEntity(possessableId);
auto* possessableEntity = Game::entityManager->GetEntity(possessableId);
if (possessableEntity) possessorComponent->Dismount(possessableEntity, true);
}
}
@@ -1180,7 +1180,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
dest->SetImagination(999);
dest->SetMaxImagination(999.0f);
}
EntityManager::Instance()->SerializeEntity(entity);
Game::entityManager->SerializeEntity(entity);
}
if (chatCommand == "startcelebration" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER && args.size() == 1) {
@@ -1204,7 +1204,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
dest->SetImagination(9);
dest->SetMaxImagination(9.0f);
}
EntityManager::Instance()->SerializeEntity(entity);
Game::entityManager->SerializeEntity(entity);
}
if (chatCommand == "refillstats" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER) {
@@ -1216,7 +1216,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
dest->SetImagination((int)dest->GetMaxImagination());
}
EntityManager::Instance()->SerializeEntity(entity);
Game::entityManager->SerializeEntity(entity);
}
if (chatCommand == "lookup" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER && args.size() >= 1) {
@@ -1260,14 +1260,14 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
info.spawnerID = entity->GetObjectID();
info.spawnerNodeID = 0;
Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr);
Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr);
if (newEntity == nullptr) {
ChatPackets::SendSystemMessage(sysAddr, u"Failed to spawn entity.");
return;
}
EntityManager::Instance()->ConstructEntity(newEntity);
Game::entityManager->ConstructEntity(newEntity);
}
if (chatCommand == "spawngroup" && entity->GetGMLevel() >= eGameMasterLevel::DEVELOPER && args.size() >= 3) {
@@ -1310,13 +1310,13 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
info.pos = playerPosition + NiPoint3(cos(randomAngle) * randomRadius, 0.0f, sin(randomAngle) * randomRadius);
info.rot = NiQuaternion();
auto newEntity = EntityManager::Instance()->CreateEntity(info);
auto newEntity = Game::entityManager->CreateEntity(info);
if (newEntity == nullptr) {
ChatPackets::SendSystemMessage(sysAddr, u"Failed to spawn entity.");
return;
}
EntityManager::Instance()->ConstructEntity(newEntity);
Game::entityManager->ConstructEntity(newEntity);
numberToSpawn--;
}
}
@@ -1545,7 +1545,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, reqZone, cloneId, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
auto* entity = EntityManager::Instance()->GetEntity(objid);
auto* entity = Game::entityManager->GetEntity(objid);
if (!entity) return;
const auto sysAddr = entity->GetSystemAddress();
@@ -1609,7 +1609,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
return;
}
auto* vehicle = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
auto* vehicle = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
if (vehicle == nullptr) {
return;
@@ -1638,7 +1638,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
auto* possessorComponent = entity->GetComponent<PossessorComponent>();
if (possessorComponent == nullptr) return;
auto* vehicle = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
auto* vehicle = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
if (vehicle == nullptr) return;
GameMessages::SendVehicleRemovePassiveBoostAction(vehicle->GetObjectID(), UNASSIGNED_SYSTEM_ADDRESS);
@@ -1660,7 +1660,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
if (chatCommand == "spawnphysicsverts" && entity->GetGMLevel() >= eGameMasterLevel::JUNIOR_DEVELOPER) {
//Go tell physics to spawn all the vertices:
auto entities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::PHANTOM_PHYSICS);
auto entities = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::PHANTOM_PHYSICS);
for (auto en : entities) {
auto phys = static_cast<PhantomPhysicsComponent*>(en->GetComponent(eReplicaComponentType::PHANTOM_PHYSICS));
if (phys)
@@ -1669,7 +1669,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
}
if (chatCommand == "reportproxphys" && entity->GetGMLevel() >= eGameMasterLevel::JUNIOR_DEVELOPER) {
auto entities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::PROXIMITY_MONITOR);
auto entities = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::PROXIMITY_MONITOR);
for (auto en : entities) {
auto phys = static_cast<ProximityMonitorComponent*>(en->GetComponent(eReplicaComponentType::PROXIMITY_MONITOR));
if (phys) {
@@ -1765,7 +1765,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
Game::config->ReloadConfig();
VanityUtilities::SpawnVanity();
dpWorld::Instance().Reload();
auto entities = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
auto entities = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
for (auto entity : entities) {
auto* scriptedActivityComponent = entity->GetComponent<ScriptedActivityComponent>();
if (!scriptedActivityComponent) continue;
@@ -1862,7 +1862,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
auto closestDistance = 0.0f;
const auto candidates = EntityManager::Instance()->GetEntitiesByComponent(component);
const auto candidates = Game::entityManager->GetEntitiesByComponent(component);
for (auto* candidate : candidates) {
if (candidate->GetLOT() == 1 || candidate->GetLOT() == 8092) {
@@ -1894,7 +1894,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
return;
}
EntityManager::Instance()->SerializeEntity(closest);
Game::entityManager->SerializeEntity(closest);
auto* table = CDClientManager::Instance().GetTable<CDObjectsTable>();
@@ -1934,7 +1934,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
movingPlatformComponent->GotoWaypoint(value);
}
EntityManager::Instance()->SerializeEntity(closest);
Game::entityManager->SerializeEntity(closest);
} else if (args[1] == "-a" && args.size() >= 3) {
RenderComponent::PlayAnimation(closest, args.at(2));
} else if (args[1] == "-s") {

View File

@@ -137,14 +137,14 @@ void VanityUtilities::SpawnVanity() {
info.lot = 8139;
info.pos = { 259.5f, 246.4f, -705.2f };
info.rot = { 0.0f, 0.0f, 1.0f, 0.0f };
info.spawnerID = EntityManager::Instance()->GetZoneControlEntity()->GetObjectID();
info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID();
info.settings = { new LDFData<bool>(u"hasCustomText", true),
new LDFData<std::string>(u"customText", ParseMarkdown((BinaryPathFinder::GetBinaryDir() / "vanity/TESTAMENT.md").string())) };
auto* entity = EntityManager::Instance()->CreateEntity(info);
auto* entity = Game::entityManager->CreateEntity(info);
EntityManager::Instance()->ConstructEntity(entity);
Game::entityManager->ConstructEntity(entity);
}
}
}
@@ -155,10 +155,10 @@ Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoin
info.lot = lot;
info.pos = position;
info.rot = rotation;
info.spawnerID = EntityManager::Instance()->GetZoneControlEntity()->GetObjectID();
info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID();
info.settings = ldf;
auto* entity = EntityManager::Instance()->CreateEntity(info);
auto* entity = Game::entityManager->CreateEntity(info);
entity->SetVar(u"npcName", name);
auto* inventoryComponent = entity->GetComponent<InventoryComponent>();
@@ -175,7 +175,7 @@ Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoin
destroyableComponent->SetHealth(0);
}
EntityManager::Instance()->ConstructEntity(entity);
Game::entityManager->ConstructEntity(entity);
return entity;
}
@@ -535,7 +535,7 @@ void VanityUtilities::NPCTalk(Entity* npc) {
npc->GetObjectID(), u"sendToclient_bubble", 0, 0, npc->GetObjectID(), selected, UNASSIGNED_SYSTEM_ADDRESS);
}
EntityManager::Instance()->SerializeEntity(npc);
Game::entityManager->SerializeEntity(npc);
const float nextTime = GeneralUtils::GenerateRandomNumber<float>(15, 60);