format codebase

This commit is contained in:
aronwk-aaron
2022-07-28 08:39:57 -05:00
parent 4f7aa11067
commit 19e77a38d8
881 changed files with 34700 additions and 38689 deletions

View File

@@ -65,7 +65,7 @@ EntityManager::~EntityManager() {
Entity* EntityManager::CreateEntity(EntityInfo info, User* user, Entity* parentEntity, const bool controller, const LWOOBJID explicitId) {
// Determine the objectID for the new entity
LWOOBJID id;
LWOOBJID id;
// If an explicit ID was provided, use it
if (explicitId != LWOOBJID_EMPTY) {
@@ -76,17 +76,17 @@ Entity* EntityManager::CreateEntity(EntityInfo info, User* user, Entity* parentE
else if (user == nullptr || info.lot != 1) {
// Entities with no ID already set, often spawned entities, we'll generate a new sequencial ID
if (info.id == 0) {
if (info.id == 0) {
id = ObjectIDManager::Instance()->GenerateObjectID();
}
// Entities with an ID already set, often level entities, we'll use that ID as a base
else {
else {
id = info.id;
}
// Exclude the zone control object from any flags
if(!controller && info.lot != 14) {
if (!controller && info.lot != 14) {
// The client flags means the client should render the entity
id = GeneralUtils::SetBit(id, OBJECT_BIT_CLIENT);
@@ -96,22 +96,21 @@ Entity* EntityManager::CreateEntity(EntityInfo info, User* user, Entity* parentE
id = GeneralUtils::SetBit(id, OBJECT_BIT_SPAWNED);
}
}
}
}
// For players, we'll use the persistent ID for that character
else {
id = user->GetLastUsedChar()->GetObjectID();
}
info.id = id;
info.id = id;
Entity* entity;
// Check if the entitty if a player, in case use the extended player entity class
if (user != nullptr) {
entity = new Player(id, info, user, parentEntity);
}
else {
} else {
entity = new Entity(id, info, parentEntity);
}
@@ -133,7 +132,7 @@ Entity* EntityManager::CreateEntity(EntityInfo info, User* user, Entity* parentE
m_SpawnPoints.insert_or_assign(GeneralUtils::UTF16ToWTF8(spawnName), entity->GetObjectID());
}
return entity;
return entity;
}
void EntityManager::DestroyEntity(const LWOOBJID& objectID) {
@@ -229,11 +228,10 @@ void EntityManager::UpdateEntities(const float deltaTime) {
m_EntitiesToDelete.clear();
}
Entity * EntityManager::GetEntity(const LWOOBJID& objectId) const {
Entity* EntityManager::GetEntity(const LWOOBJID& objectId) const {
const auto& index = m_Entities.find(objectId);
if (index == m_Entities.end())
{
if (index == m_Entities.end()) {
return nullptr;
}
@@ -263,29 +261,26 @@ std::vector<Entity*> EntityManager::GetEntitiesByComponent(const int componentTy
return withComp;
}
std::vector<Entity *> EntityManager::GetEntitiesByLOT(const LOT &lot) const {
std::vector<Entity*> entities;
std::vector<Entity*> EntityManager::GetEntitiesByLOT(const LOT& lot) const {
std::vector<Entity*> entities;
for (const auto& entity : m_Entities) {
if (entity.second->GetLOT() == lot)
entities.push_back(entity.second);
}
for (const auto& entity : m_Entities) {
if (entity.second->GetLOT() == lot)
entities.push_back(entity.second);
}
return entities;
return entities;
}
Entity* EntityManager::GetZoneControlEntity() const
{
Entity* EntityManager::GetZoneControlEntity() const {
return m_ZoneControlEntity;
}
Entity* EntityManager::GetSpawnPointEntity(const std::string& spawnName) const
{
Entity* EntityManager::GetSpawnPointEntity(const std::string& spawnName) const {
// Lookup the spawn point entity in the map
const auto& spawnPoint = m_SpawnPoints.find(spawnName);
if (spawnPoint == m_SpawnPoints.end())
{
if (spawnPoint == m_SpawnPoints.end()) {
return nullptr;
}
@@ -293,23 +288,18 @@ Entity* EntityManager::GetSpawnPointEntity(const std::string& spawnName) const
return GetEntity(spawnPoint->second);
}
const std::unordered_map<std::string, LWOOBJID>& EntityManager::GetSpawnPointEntities() const
{
const std::unordered_map<std::string, LWOOBJID>& EntityManager::GetSpawnPointEntities() const {
return m_SpawnPoints;
}
void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr, const bool skipChecks) {
if (entity->GetNetworkId() == 0)
{
if (entity->GetNetworkId() == 0) {
uint16_t networkId;
if (!m_LostNetworkIds.empty())
{
if (!m_LostNetworkIds.empty()) {
networkId = m_LostNetworkIds.top();
m_LostNetworkIds.pop();
}
else
{
} else {
networkId = ++m_NetworkIdCounter;
}
@@ -318,18 +308,15 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr
const auto checkGhosting = entity->GetIsGhostingCandidate();
if (checkGhosting)
{
if (checkGhosting) {
const auto& iter = std::find(m_EntitiesToGhost.begin(), m_EntitiesToGhost.end(), entity);
if (iter == m_EntitiesToGhost.end())
{
if (iter == m_EntitiesToGhost.end()) {
m_EntitiesToGhost.push_back(entity);
}
}
if (checkGhosting && sysAddr == UNASSIGNED_SYSTEM_ADDRESS)
{
if (checkGhosting && sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
CheckGhosting(entity);
return;
@@ -346,38 +333,26 @@ void EntityManager::ConstructEntity(Entity* entity, const SystemAddress& sysAddr
entity->WriteBaseReplicaData(&stream, PACKET_TYPE_CONSTRUCTION);
entity->WriteComponents(&stream, PACKET_TYPE_CONSTRUCTION);
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS)
{
if (skipChecks)
{
if (sysAddr == UNASSIGNED_SYSTEM_ADDRESS) {
if (skipChecks) {
Game::server->Send(&stream, UNASSIGNED_SYSTEM_ADDRESS, true);
}
else
{
for (auto* player : Player::GetAllPlayers())
{
if (player->GetPlayerReadyForUpdates())
{
} else {
for (auto* player : Player::GetAllPlayers()) {
if (player->GetPlayerReadyForUpdates()) {
Game::server->Send(&stream, player->GetSystemAddress(), false);
}
else
{
} else {
player->AddLimboConstruction(entity->GetObjectID());
}
}
}
}
else
{
} else {
Game::server->Send(&stream, sysAddr, false);
}
// PacketUtils::SavePacket("[24]_"+std::to_string(entity->GetObjectID()) + "_" + std::to_string(m_SerializationCounter) + ".bin", (char*)stream.GetData(), stream.GetNumberOfBytesUsed());
if (entity->IsPlayer())
{
if (entity->GetGMLevel() > GAME_MASTER_LEVEL_CIVILIAN)
{
if (entity->IsPlayer()) {
if (entity->GetGMLevel() > GAME_MASTER_LEVEL_CIVILIAN) {
GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, sysAddr);
}
}
@@ -387,18 +362,17 @@ void EntityManager::ConstructAllEntities(const SystemAddress& sysAddr) {
//ZoneControl is special:
ConstructEntity(m_ZoneControlEntity, sysAddr);
for (const auto& e : m_Entities) {
for (const auto& e : m_Entities) {
if (e.second && (e.second->GetSpawnerID() != 0 || e.second->GetLOT() == 1) && !e.second->GetIsGhostingCandidate()) {
ConstructEntity(e.second, sysAddr);
}
}
}
UpdateGhosting(Player::GetPlayer(sysAddr));
}
void EntityManager::DestructEntity(Entity* entity, const SystemAddress& sysAddr) {
if (entity->GetNetworkId() == 0)
{
if (entity->GetNetworkId() == 0) {
return;
}
@@ -409,23 +383,19 @@ void EntityManager::DestructEntity(Entity* entity, const SystemAddress& sysAddr)
Game::server->Send(&stream, sysAddr, sysAddr == UNASSIGNED_SYSTEM_ADDRESS);
for (auto* player : Player::GetAllPlayers())
{
if (!player->GetPlayerReadyForUpdates())
{
for (auto* player : Player::GetAllPlayers()) {
if (!player->GetPlayerReadyForUpdates()) {
player->RemoveLimboConstruction(entity->GetObjectID());
}
}
}
void EntityManager::SerializeEntity(Entity* entity) {
if (entity->GetNetworkId() == 0)
{
if (entity->GetNetworkId() == 0) {
return;
}
if (std::find(m_EntitiesToSerialize.begin(), m_EntitiesToSerialize.end(), entity->GetObjectID()) == m_EntitiesToSerialize.end())
{
if (std::find(m_EntitiesToSerialize.begin(), m_EntitiesToSerialize.end(), entity->GetObjectID()) == m_EntitiesToSerialize.end()) {
m_EntitiesToSerialize.push_back(entity->GetObjectID());
}
@@ -433,49 +403,40 @@ void EntityManager::SerializeEntity(Entity* entity) {
}
void EntityManager::DestructAllEntities(const SystemAddress& sysAddr) {
for (const auto& e : m_Entities) {
for (const auto& e : m_Entities) {
DestructEntity(e.second, sysAddr);
}
}
}
void EntityManager::SetGhostDistanceMax(float value)
{
void EntityManager::SetGhostDistanceMax(float value) {
m_GhostDistanceMaxSquared = value * value;
}
float EntityManager::GetGhostDistanceMax() const
{
float EntityManager::GetGhostDistanceMax() const {
return std::sqrt(m_GhostDistanceMaxSquared);
}
void EntityManager::SetGhostDistanceMin(float value)
{
void EntityManager::SetGhostDistanceMin(float value) {
m_GhostDistanceMinSqaured = value * value;
}
float EntityManager::GetGhostDistanceMin() const
{
float EntityManager::GetGhostDistanceMin() const {
return std::sqrt(m_GhostDistanceMinSqaured);
}
void EntityManager::QueueGhostUpdate(LWOOBJID playerID)
{
void EntityManager::QueueGhostUpdate(LWOOBJID playerID) {
const auto& iter = std::find(m_PlayersToUpdateGhosting.begin(), m_PlayersToUpdateGhosting.end(), playerID);
if (iter == m_PlayersToUpdateGhosting.end())
{
if (iter == m_PlayersToUpdateGhosting.end()) {
m_PlayersToUpdateGhosting.push_back(playerID);
}
}
void EntityManager::UpdateGhosting()
{
for (const auto playerID : m_PlayersToUpdateGhosting)
{
void EntityManager::UpdateGhosting() {
for (const auto playerID : m_PlayersToUpdateGhosting) {
auto* player = Player::GetPlayer(playerID);
if (player == nullptr)
{
if (player == nullptr) {
continue;
}
@@ -485,25 +446,21 @@ void EntityManager::UpdateGhosting()
m_PlayersToUpdateGhosting.clear();
}
void EntityManager::UpdateGhosting(Player* player)
{
if (player == nullptr)
{
void EntityManager::UpdateGhosting(Player* player) {
if (player == nullptr) {
return;
}
auto* missionComponent = player->GetComponent<MissionComponent>();
if (missionComponent == nullptr)
{
if (missionComponent == nullptr) {
return;
}
const auto& referencePoint = player->GetGhostReferencePoint();
const auto isOverride = player->GetGhostOverride();
for (auto* entity : m_EntitiesToGhost)
{
for (auto* entity : m_EntitiesToGhost) {
const auto isAudioEmitter = entity->GetLOT() == 6368;
const auto& entityPoint = entity->GetPosition();
@@ -517,30 +474,24 @@ void EntityManager::UpdateGhosting(Player* player)
auto ghostingDistanceMax = m_GhostDistanceMaxSquared;
auto ghostingDistanceMin = m_GhostDistanceMinSqaured;
if (isAudioEmitter)
{
if (isAudioEmitter) {
ghostingDistanceMax = ghostingDistanceMin;
}
if (observed && distance > ghostingDistanceMax && !isOverride)
{
if (observed && distance > ghostingDistanceMax && !isOverride) {
player->GhostEntity(id);
DestructEntity(entity, player->GetSystemAddress());
entity->SetObservers(entity->GetObservers() - 1);
}
else if (!observed && ghostingDistanceMin > distance)
{
} else if (!observed && ghostingDistanceMin > distance) {
// Check collectables, don't construct if it has been collected
uint32_t collectionId = entity->GetCollectibleID();
if (collectionId != 0)
{
if (collectionId != 0) {
collectionId = static_cast<uint32_t>(collectionId) + static_cast<uint32_t>(Game::server->GetZoneID() << 8);
if (missionComponent->HasCollectible(collectionId))
{
if (missionComponent->HasCollectible(collectionId)) {
continue;
}
}
@@ -554,10 +505,8 @@ void EntityManager::UpdateGhosting(Player* player)
}
}
void EntityManager::CheckGhosting(Entity* entity)
{
if (entity == nullptr)
{
void EntityManager::CheckGhosting(Entity* entity) {
if (entity == nullptr) {
return;
}
@@ -568,8 +517,7 @@ void EntityManager::CheckGhosting(Entity* entity)
const auto isAudioEmitter = entity->GetLOT() == 6368;
for (auto* player : Player::GetAllPlayers())
{
for (auto* player : Player::GetAllPlayers()) {
const auto& entityPoint = player->GetGhostReferencePoint();
const int32_t id = entity->GetObjectID();
@@ -578,16 +526,13 @@ void EntityManager::CheckGhosting(Entity* entity)
const auto distance = NiPoint3::DistanceSquared(referencePoint, entityPoint);
if (observed && distance > ghostingDistanceMax)
{
if (observed && distance > ghostingDistanceMax) {
player->GhostEntity(id);
DestructEntity(entity, player->GetSystemAddress());
entity->SetObservers(entity->GetObservers() - 1);
}
else if (!observed && ghostingDistanceMin > distance)
{
} else if (!observed && ghostingDistanceMin > distance) {
player->ObserveEntity(id);
ConstructEntity(entity, player->GetSystemAddress());
@@ -597,12 +542,9 @@ void EntityManager::CheckGhosting(Entity* entity)
}
}
Entity* EntityManager::GetGhostCandidate(int32_t id)
{
for (auto* entity : m_EntitiesToGhost)
{
if (entity->GetObjectID() == id)
{
Entity* EntityManager::GetGhostCandidate(int32_t id) {
for (auto* entity : m_EntitiesToGhost) {
if (entity->GetObjectID() == id) {
return entity;
}
}
@@ -610,8 +552,7 @@ Entity* EntityManager::GetGhostCandidate(int32_t id)
return nullptr;
}
bool EntityManager::GetGhostingEnabled() const
{
bool EntityManager::GetGhostingEnabled() const {
return m_GhostingEnabled;
}
@@ -633,18 +574,15 @@ void EntityManager::ScheduleForKill(Entity* entity) {
const auto objectId = entity->GetObjectID();
if (std::count(m_EntitiesToKill.begin(), m_EntitiesToKill.end(), objectId))
{
if (std::count(m_EntitiesToKill.begin(), m_EntitiesToKill.end(), objectId)) {
return;
}
m_EntitiesToKill.push_back(objectId);
}
void EntityManager::ScheduleForDeletion(LWOOBJID entity)
{
if (std::count(m_EntitiesToDelete.begin(), m_EntitiesToDelete.end(), entity))
{
void EntityManager::ScheduleForDeletion(LWOOBJID entity) {
if (std::count(m_EntitiesToDelete.begin(), m_EntitiesToDelete.end(), entity)) {
return;
}
@@ -660,7 +598,6 @@ void EntityManager::FireEventServerSide(Entity* origin, std::string args) {
}
}
bool EntityManager::IsExcludedFromGhosting(LOT lot)
{
bool EntityManager::IsExcludedFromGhosting(LOT lot) {
return std::find(m_GhostingExcludedLOTs.begin(), m_GhostingExcludedLOTs.end(), lot) != m_GhostingExcludedLOTs.end();
}