2021-12-05 17:54:36 +00:00
|
|
|
#ifndef ENTITYMANAGER_H
|
|
|
|
#define ENTITYMANAGER_H
|
|
|
|
|
|
|
|
#include "dCommonVars.h"
|
|
|
|
#include <map>
|
|
|
|
#include <stack>
|
|
|
|
#include <vector>
|
2023-01-07 05:17:05 +00:00
|
|
|
#include <unordered_map>
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-01-07 05:17:05 +00:00
|
|
|
class Entity;
|
|
|
|
class EntityInfo;
|
|
|
|
class Player;
|
2021-12-05 17:54:36 +00:00
|
|
|
class User;
|
2023-03-04 07:16:37 +00:00
|
|
|
enum class eReplicaComponentType : uint32_t;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-01-07 05:17:05 +00:00
|
|
|
struct SystemAddress;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
class EntityManager {
|
|
|
|
public:
|
2022-07-28 13:39:57 +00:00
|
|
|
static EntityManager* Instance() {
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!m_Address) {
|
|
|
|
m_Address = new EntityManager();
|
|
|
|
m_Address->Initialize();
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return m_Address;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
void Initialize();
|
|
|
|
|
|
|
|
~EntityManager();
|
|
|
|
|
|
|
|
void UpdateEntities(float deltaTime);
|
|
|
|
Entity* CreateEntity(EntityInfo info, User* user = nullptr, Entity* parentEntity = nullptr, bool controller = false, LWOOBJID explicitId = LWOOBJID_EMPTY);
|
|
|
|
void DestroyEntity(const LWOOBJID& objectID);
|
2021-12-05 17:54:36 +00:00
|
|
|
void DestroyEntity(Entity* entity);
|
2022-07-28 13:39:57 +00:00
|
|
|
Entity* GetEntity(const LWOOBJID& objectId) const;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<Entity*> GetEntitiesInGroup(const std::string& group);
|
2023-03-04 07:16:37 +00:00
|
|
|
std::vector<Entity*> GetEntitiesByComponent(eReplicaComponentType componentType) const;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<Entity*> GetEntitiesByLOT(const LOT& lot) const;
|
|
|
|
Entity* GetZoneControlEntity() const;
|
|
|
|
|
|
|
|
// Get spawn point entity by spawn name
|
|
|
|
Entity* GetSpawnPointEntity(const std::string& spawnName) const;
|
|
|
|
|
|
|
|
// Get spawn points
|
|
|
|
const std::unordered_map<std::string, LWOOBJID>& GetSpawnPointEntities() const;
|
|
|
|
|
|
|
|
//To make it obvious this SHOULD NOT be used outside of debug:
|
|
|
|
#ifdef _DEBUG
|
|
|
|
const std::unordered_map<LWOOBJID, Entity*> GetAllEntities() const { return m_Entities; }
|
|
|
|
#endif
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void ConstructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS, bool skipChecks = false);
|
|
|
|
void DestructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
|
2021-12-05 17:54:36 +00:00
|
|
|
void SerializeEntity(Entity* entity);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
void ConstructAllEntities(const SystemAddress& sysAddr);
|
|
|
|
void DestructAllEntities(const SystemAddress& sysAddr);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void SetGhostDistanceMax(float value);
|
|
|
|
float GetGhostDistanceMax() const;
|
|
|
|
void SetGhostDistanceMin(float value);
|
|
|
|
float GetGhostDistanceMin() const;
|
|
|
|
void QueueGhostUpdate(LWOOBJID playerID);
|
|
|
|
void UpdateGhosting();
|
|
|
|
void UpdateGhosting(Player* player);
|
|
|
|
void CheckGhosting(Entity* entity);
|
|
|
|
Entity* GetGhostCandidate(int32_t id);
|
|
|
|
bool GetGhostingEnabled() const;
|
|
|
|
|
|
|
|
void ResetFlags();
|
|
|
|
|
|
|
|
void ScheduleForKill(Entity* entity);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
void ScheduleForDeletion(LWOOBJID entity);
|
|
|
|
|
|
|
|
void FireEventServerSide(Entity* origin, std::string args);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
static bool IsExcludedFromGhosting(LOT lot);
|
|
|
|
|
2023-01-12 19:16:24 +00:00
|
|
|
const bool GetHardcoreMode() { return m_HardcoreMode; };
|
|
|
|
const uint32_t GetHardcoreLoseUscoreOnDeathPercent() { return m_HardcoreLoseUscoreOnDeathPercent; };
|
|
|
|
const bool GetHardcoreDropinventoryOnDeath() { return m_HardcoreDropinventoryOnDeath; };
|
|
|
|
const uint32_t GetHardcoreUscoreEnemiesMultiplier() { return m_HardcoreUscoreEnemiesMultiplier; };
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
private:
|
2023-05-06 06:31:30 +00:00
|
|
|
void SerializeEntities();
|
|
|
|
void KillEntities();
|
|
|
|
void DeleteEntities();
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
static EntityManager* m_Address; //For singleton method
|
2021-12-05 17:54:36 +00:00
|
|
|
static std::vector<LWOMAPID> m_GhostingExcludedZones;
|
|
|
|
static std::vector<LOT> m_GhostingExcludedLOTs;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
std::unordered_map<LWOOBJID, Entity*> m_Entities;
|
2021-12-05 17:54:36 +00:00
|
|
|
std::vector<LWOOBJID> m_EntitiesToKill;
|
|
|
|
std::vector<LWOOBJID> m_EntitiesToDelete;
|
|
|
|
std::vector<LWOOBJID> m_EntitiesToSerialize;
|
|
|
|
std::vector<Entity*> m_EntitiesToGhost;
|
|
|
|
std::vector<LWOOBJID> m_PlayersToUpdateGhosting;
|
|
|
|
Entity* m_ZoneControlEntity;
|
|
|
|
|
|
|
|
uint16_t m_NetworkIdCounter;
|
|
|
|
uint64_t m_SerializationCounter = 0;
|
|
|
|
|
|
|
|
float m_GhostDistanceMinSqaured = 100 * 100;
|
|
|
|
float m_GhostDistanceMaxSquared = 150 * 150;
|
|
|
|
bool m_GhostingEnabled = true;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
std::stack<uint16_t> m_LostNetworkIds;
|
|
|
|
|
|
|
|
// Map of spawnname to entity object ID
|
|
|
|
std::unordered_map<std::string, LWOOBJID> m_SpawnPoints;
|
2023-01-12 19:16:24 +00:00
|
|
|
|
|
|
|
// hardcore mode vars
|
|
|
|
bool m_HardcoreMode;
|
|
|
|
uint32_t m_HardcoreLoseUscoreOnDeathPercent;
|
|
|
|
bool m_HardcoreDropinventoryOnDeath;
|
|
|
|
uint32_t m_HardcoreUscoreEnemiesMultiplier;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ENTITYMANAGER_H
|