mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-28 08:51:42 +00:00
The client keeps the scene under the player loaded, the scenes the zone file's transitions connect to it, and the global scene (the client's scene streaming and terrain scene lookup the client's terrain scene lookup and connected scenes; transitions naming a missing scene dropped as the client does). - ZoneScenes (dCommon): the terrain's scene map lookup and the scene graph, shared by the world server and the dashboard. - Objects remember the scene they were placed in (spawners pass theirs on). - ghosting_scenes=1 (world config, off by default): players get the objects of their loaded scenes instead of the ones within the ghosting distances; objects from no scene go by the scene under them. Zones without a scene map keep distance ghosting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
137 lines
4.8 KiB
C++
137 lines
4.8 KiB
C++
#ifndef ENTITYMANAGER_H
|
|
#define ENTITYMANAGER_H
|
|
|
|
#include <map>
|
|
#include <stack>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
#include "dCommonVars.h"
|
|
|
|
class Entity;
|
|
struct EntityInfo;
|
|
class Player;
|
|
class User;
|
|
enum class eReplicaComponentType : uint32_t;
|
|
|
|
namespace GameMessages {
|
|
struct GameMsg;
|
|
}
|
|
|
|
struct SystemAddress;
|
|
|
|
class EntityManager {
|
|
public:
|
|
void Initialize();
|
|
|
|
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);
|
|
void DestroyEntity(Entity* entity);
|
|
Entity* GetEntity(const LWOOBJID& objectId) const;
|
|
std::vector<Entity*> GetEntitiesInGroup(const std::string& group);
|
|
std::vector<Entity*> GetEntitiesByComponent(eReplicaComponentType componentType) const;
|
|
std::vector<Entity*> GetEntitiesByLOT(const LOT& lot) const;
|
|
std::vector<Entity*> GetEntitiesByProximity(NiPoint3 reference, float radius) 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
|
|
|
|
void ConstructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
|
|
void DestructEntity(Entity* entity, const SystemAddress& sysAddr = UNASSIGNED_SYSTEM_ADDRESS);
|
|
void SerializeEntity(Entity* entity);
|
|
void SerializeEntity(const Entity& entity);
|
|
|
|
void ConstructAllEntities(const SystemAddress& sysAddr);
|
|
void DestructAllEntities(const SystemAddress& sysAddr);
|
|
|
|
void SetGhostDistanceMax(float value);
|
|
void SetGhostDistanceMin(float value);
|
|
void QueueGhostUpdate(LWOOBJID playerID);
|
|
void UpdateGhosting();
|
|
void UpdateGhosting(Entity* player);
|
|
void CheckGhosting(Entity* entity);
|
|
Entity* GetGhostCandidate(LWOOBJID id) const;
|
|
bool GetGhostingEnabled() const;
|
|
bool GetSceneGhosting() const { return m_SceneGhosting; }
|
|
|
|
void ScheduleForKill(Entity* entity);
|
|
|
|
void ScheduleForDeletion(LWOOBJID entity);
|
|
|
|
void FireEventServerSide(Entity* origin, std::string args);
|
|
|
|
static bool IsExcludedFromGhosting(LOT lot);
|
|
|
|
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; };
|
|
const std::set<LOT>& GetHardcoreExcludedItemDrops() { return m_HardcoreExcludedItemDrops; };
|
|
const float& GetHardcoreUscoreReduction() const { return m_HardcoreUscoreReduction; };
|
|
bool GetHardcoreUscoreReduced() const { return m_HardcoreUscoreReduced; };
|
|
const std::set<LOT>& GetHardcoreUscoreReducedLots() const { return m_HardcoreUscoreReducedLots; };
|
|
const std::set<LOT>& GetHardcoreUscoreExcludedEnemies() const { return m_HardcoreUscoreExcludedEnemies; };
|
|
const std::set<LWOMAPID>& GetHardcoreDisabledWorlds() const { return m_HardcoreDisabledWorlds; };
|
|
float GetHardcoreCoinKeep() const { return m_HardcoreCoinKeep; }
|
|
|
|
// Messaging
|
|
bool SendMessage(GameMessages::GameMsg& msg) const;
|
|
|
|
private:
|
|
void ReloadConfig();
|
|
void SerializeEntities();
|
|
void KillEntities();
|
|
void DeleteEntities();
|
|
|
|
static std::vector<LWOMAPID> m_GhostingExcludedZones;
|
|
static std::vector<LOT> m_GhostingExcludedLOTs;
|
|
|
|
std::unordered_map<LWOOBJID, Entity*> m_Entities;
|
|
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;
|
|
// ghosting_scenes: players get the objects of the scenes their client keeps loaded (ZoneScenes) instead of the
|
|
// ones within the ghosting distances
|
|
bool m_SceneGhosting = false;
|
|
|
|
std::stack<uint16_t> m_LostNetworkIds;
|
|
|
|
// Map of spawnname to entity object ID
|
|
std::unordered_map<std::string, LWOOBJID> m_SpawnPoints;
|
|
|
|
// hardcore mode vars
|
|
bool m_HardcoreMode;
|
|
uint32_t m_HardcoreLoseUscoreOnDeathPercent;
|
|
bool m_HardcoreDropinventoryOnDeath;
|
|
uint32_t m_HardcoreUscoreEnemiesMultiplier;
|
|
std::set<LOT> m_HardcoreExcludedItemDrops;
|
|
float m_HardcoreUscoreReduction{};
|
|
bool m_HardcoreUscoreReduced{};
|
|
std::set<LOT> m_HardcoreUscoreReducedLots{};
|
|
std::set<LOT> m_HardcoreUscoreExcludedEnemies{};
|
|
std::set<LWOMAPID> m_HardcoreDisabledWorlds{};
|
|
float m_HardcoreCoinKeep{};
|
|
};
|
|
|
|
#endif // ENTITYMANAGER_H
|