mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-27 07:57:21 +00:00
Utilize set
instead of vector in player observed list.
This commit is contained in:
parent
e6227562b0
commit
ea59cc10c0
@ -29,9 +29,7 @@ Player::Player(const LWOOBJID& objectID, const EntityInfo info, User* user, Enti
|
|||||||
m_GhostReferencePoint = NiPoint3::ZERO;
|
m_GhostReferencePoint = NiPoint3::ZERO;
|
||||||
m_GhostOverridePoint = NiPoint3::ZERO;
|
m_GhostOverridePoint = NiPoint3::ZERO;
|
||||||
m_GhostOverride = false;
|
m_GhostOverride = false;
|
||||||
m_ObservedEntitiesLength = 256;
|
m_ObservedEntities.reserve(256);
|
||||||
m_ObservedEntitiesUsed = 0;
|
|
||||||
m_ObservedEntities.resize(m_ObservedEntitiesLength);
|
|
||||||
|
|
||||||
m_Character->SetEntity(this);
|
m_Character->SetEntity(this);
|
||||||
|
|
||||||
@ -122,26 +120,12 @@ void Player::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId)
|
|||||||
|
|
||||||
void Player::AddLimboConstruction(LWOOBJID objectId)
|
void Player::AddLimboConstruction(LWOOBJID objectId)
|
||||||
{
|
{
|
||||||
const auto& iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId);
|
m_LimboConstructions.insert(objectId);
|
||||||
|
|
||||||
if (iter != m_LimboConstructions.end())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_LimboConstructions.push_back(objectId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::RemoveLimboConstruction(LWOOBJID objectId)
|
void Player::RemoveLimboConstruction(LWOOBJID objectId)
|
||||||
{
|
{
|
||||||
const auto& iter = std::find(m_LimboConstructions.begin(), m_LimboConstructions.end(), objectId);
|
m_LimboConstructions.erase(objectId);
|
||||||
|
|
||||||
if (iter == m_LimboConstructions.end())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_LimboConstructions.erase(iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::ConstructLimboEntities()
|
void Player::ConstructLimboEntities()
|
||||||
@ -203,50 +187,17 @@ bool Player::GetGhostOverride() const
|
|||||||
|
|
||||||
void Player::ObserveEntity(int32_t id)
|
void Player::ObserveEntity(int32_t id)
|
||||||
{
|
{
|
||||||
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++)
|
m_ObservedEntities.insert(id);
|
||||||
{
|
|
||||||
if (m_ObservedEntities[i] == 0 || m_ObservedEntities[i] == id)
|
|
||||||
{
|
|
||||||
m_ObservedEntities[i] = id;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto index = m_ObservedEntitiesUsed++;
|
|
||||||
|
|
||||||
if (m_ObservedEntitiesUsed > m_ObservedEntitiesLength)
|
|
||||||
{
|
|
||||||
m_ObservedEntities.resize(m_ObservedEntitiesLength + m_ObservedEntitiesLength);
|
|
||||||
|
|
||||||
m_ObservedEntitiesLength = m_ObservedEntitiesLength + m_ObservedEntitiesLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_ObservedEntities[index] = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Player::IsObserved(int32_t id)
|
bool Player::IsObserved(int32_t id)
|
||||||
{
|
{
|
||||||
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++)
|
return m_ObservedEntities.find(id) != m_ObservedEntities.end();
|
||||||
{
|
|
||||||
if (m_ObservedEntities[i] == id)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::GhostEntity(int32_t id)
|
void Player::GhostEntity(int32_t id)
|
||||||
{
|
{
|
||||||
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++)
|
m_ObservedEntities.erase(id);
|
||||||
{
|
|
||||||
if (m_ObservedEntities[i] == id)
|
|
||||||
{
|
|
||||||
m_ObservedEntities[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Player* Player::GetPlayer(const SystemAddress& sysAddr)
|
Player* Player::GetPlayer(const SystemAddress& sysAddr)
|
||||||
@ -303,15 +254,8 @@ Player::~Player()
|
|||||||
{
|
{
|
||||||
Game::logger->Log("Player", "Deleted player\n");
|
Game::logger->Log("Player", "Deleted player\n");
|
||||||
|
|
||||||
for (int32_t i = 0; i < m_ObservedEntitiesUsed; i++)
|
for (const auto id : m_ObservedEntities)
|
||||||
{
|
{
|
||||||
const auto id = m_ObservedEntities[i];
|
|
||||||
|
|
||||||
if (id == 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* entity = EntityManager::Instance()->GetGhostCandidate(id);
|
auto* entity = EntityManager::Instance()->GetGhostCandidate(id);
|
||||||
|
|
||||||
if (entity != nullptr)
|
if (entity != nullptr)
|
||||||
@ -320,6 +264,8 @@ Player::~Player()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_ObservedEntities.clear();
|
||||||
|
|
||||||
m_LimboConstructions.clear();
|
m_LimboConstructions.clear();
|
||||||
|
|
||||||
const auto& iter = std::find(m_Players.begin(), m_Players.end(), this);
|
const auto& iter = std::find(m_Players.begin(), m_Players.end(), this);
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include "Entity.h"
|
#include "Entity.h"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extended Entity for player data and behavior.
|
* Extended Entity for player data and behavior.
|
||||||
*
|
*
|
||||||
@ -120,13 +123,9 @@ private:
|
|||||||
|
|
||||||
bool m_GhostOverride;
|
bool m_GhostOverride;
|
||||||
|
|
||||||
std::vector<int32_t> m_ObservedEntities;
|
std::unordered_set<int32_t> m_ObservedEntities;
|
||||||
|
|
||||||
int32_t m_ObservedEntitiesLength;
|
std::set<LWOOBJID> m_LimboConstructions;
|
||||||
|
|
||||||
int32_t m_ObservedEntitiesUsed;
|
|
||||||
|
|
||||||
std::vector<LWOOBJID> m_LimboConstructions;
|
|
||||||
|
|
||||||
std::map<LWOOBJID, Loot::Info> m_DroppedLoot;
|
std::map<LWOOBJID, Loot::Info> m_DroppedLoot;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user