mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-06-26 14:49:53 +00:00
optimizations (#1829)
This commit is contained in:
parent
f63a9a6bea
commit
0f0d0a6dee
528
dGame/Entity.cpp
528
dGame/Entity.cpp
File diff suppressed because it is too large
Load Diff
@ -34,7 +34,6 @@ namespace tinyxml2 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
class EntityInfo;
|
|
||||||
class User;
|
class User;
|
||||||
class Spawner;
|
class Spawner;
|
||||||
class ScriptComponent;
|
class ScriptComponent;
|
||||||
@ -45,6 +44,7 @@ class Item;
|
|||||||
class Character;
|
class Character;
|
||||||
class EntityCallbackTimer;
|
class EntityCallbackTimer;
|
||||||
class PositionUpdate;
|
class PositionUpdate;
|
||||||
|
struct EntityInfo;
|
||||||
enum class eTriggerEventType;
|
enum class eTriggerEventType;
|
||||||
enum class eGameMasterLevel : uint8_t;
|
enum class eGameMasterLevel : uint8_t;
|
||||||
enum class eReplicaComponentType : uint32_t;
|
enum class eReplicaComponentType : uint32_t;
|
||||||
@ -60,7 +60,7 @@ namespace CppScripts {
|
|||||||
*/
|
*/
|
||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
explicit Entity(const LWOOBJID& objectID, EntityInfo info, User* parentUser = nullptr, Entity* parentEntity = nullptr);
|
Entity(const LWOOBJID& objectID, const EntityInfo& info, User* parentUser = nullptr, Entity* parentEntity = nullptr);
|
||||||
~Entity();
|
~Entity();
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
@ -113,7 +113,7 @@ public:
|
|||||||
|
|
||||||
float GetDefaultScale() const;
|
float GetDefaultScale() const;
|
||||||
|
|
||||||
const NiPoint3& GetPosition() const;
|
NiPoint3 GetPosition() const;
|
||||||
|
|
||||||
const NiQuaternion& GetRotation() const;
|
const NiQuaternion& GetRotation() const;
|
||||||
|
|
||||||
@ -146,9 +146,9 @@ public:
|
|||||||
|
|
||||||
void SetRotation(const NiQuaternion& rotation);
|
void SetRotation(const NiQuaternion& rotation);
|
||||||
|
|
||||||
void SetRespawnPos(const NiPoint3& position);
|
void SetRespawnPos(const NiPoint3& position) const;
|
||||||
|
|
||||||
void SetRespawnRot(const NiQuaternion& rotation);
|
void SetRespawnRot(const NiQuaternion& rotation) const;
|
||||||
|
|
||||||
void SetVelocity(const NiPoint3& velocity);
|
void SetVelocity(const NiPoint3& velocity);
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ public:
|
|||||||
void AddComponent(eReplicaComponentType componentId, Component* component);
|
void AddComponent(eReplicaComponentType componentId, Component* component);
|
||||||
|
|
||||||
// This is expceted to never return nullptr, an assert checks this.
|
// This is expceted to never return nullptr, an assert checks this.
|
||||||
CppScripts::Script* const GetScript();
|
CppScripts::Script* const GetScript() const;
|
||||||
|
|
||||||
void Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName);
|
void Subscribe(LWOOBJID scriptObjId, CppScripts::Script* scriptToAdd, const std::string& notificationName);
|
||||||
void Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationName);
|
void Unsubscribe(LWOOBJID scriptObjId, const std::string& notificationName);
|
||||||
@ -182,8 +182,8 @@ public:
|
|||||||
void RemoveParent();
|
void RemoveParent();
|
||||||
|
|
||||||
// Adds a timer to start next frame with the given name and time.
|
// Adds a timer to start next frame with the given name and time.
|
||||||
void AddTimer(std::string name, float time);
|
void AddTimer(const std::string& name, float time);
|
||||||
void AddCallbackTimer(float time, std::function<void()> callback);
|
void AddCallbackTimer(float time, const std::function<void()> callback);
|
||||||
bool HasTimer(const std::string& name);
|
bool HasTimer(const std::string& name);
|
||||||
void CancelCallbackTimers();
|
void CancelCallbackTimers();
|
||||||
void CancelAllTimers();
|
void CancelAllTimers();
|
||||||
@ -195,7 +195,7 @@ public:
|
|||||||
std::unordered_map<eReplicaComponentType, Component*>& GetComponents() { return m_Components; } // TODO: Remove
|
std::unordered_map<eReplicaComponentType, Component*>& GetComponents() { return m_Components; } // TODO: Remove
|
||||||
|
|
||||||
void WriteBaseReplicaData(RakNet::BitStream& outBitStream, eReplicaPacketType packetType);
|
void WriteBaseReplicaData(RakNet::BitStream& outBitStream, eReplicaPacketType packetType);
|
||||||
void WriteComponents(RakNet::BitStream& outBitStream, eReplicaPacketType packetType);
|
void WriteComponents(RakNet::BitStream& outBitStream, eReplicaPacketType packetType) const;
|
||||||
void UpdateXMLDoc(tinyxml2::XMLDocument& doc);
|
void UpdateXMLDoc(tinyxml2::XMLDocument& doc);
|
||||||
void Update(float deltaTime);
|
void Update(float deltaTime);
|
||||||
|
|
||||||
@ -242,21 +242,21 @@ public:
|
|||||||
void AddDieCallback(const std::function<void()>& callback);
|
void AddDieCallback(const std::function<void()>& callback);
|
||||||
void Resurrect();
|
void Resurrect();
|
||||||
|
|
||||||
void AddLootItem(const Loot::Info& info);
|
void AddLootItem(const Loot::Info& info) const;
|
||||||
void PickupItem(const LWOOBJID& objectID);
|
void PickupItem(const LWOOBJID& objectID) const;
|
||||||
|
|
||||||
bool CanPickupCoins(uint64_t count);
|
bool PickupCoins(uint64_t count) const;
|
||||||
void RegisterCoinDrop(uint64_t count);
|
void RegisterCoinDrop(uint64_t count) const;
|
||||||
|
|
||||||
void ScheduleKillAfterUpdate(Entity* murderer = nullptr);
|
void ScheduleKillAfterUpdate(Entity* murderer = nullptr);
|
||||||
void TriggerEvent(eTriggerEventType event, Entity* optionalTarget = nullptr);
|
void TriggerEvent(eTriggerEventType event, Entity* optionalTarget = nullptr) const;
|
||||||
void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; }
|
void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; }
|
||||||
|
|
||||||
const NiPoint3& GetRespawnPosition() const;
|
const NiPoint3& GetRespawnPosition() const;
|
||||||
const NiQuaternion& GetRespawnRotation() const;
|
const NiQuaternion& GetRespawnRotation() const;
|
||||||
|
|
||||||
void Sleep();
|
void Sleep() const;
|
||||||
void Wake();
|
void Wake() const;
|
||||||
bool IsSleeping() const;
|
bool IsSleeping() const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -266,7 +266,7 @@ public:
|
|||||||
* Retroactively corrects the model vault size due to incorrect initialization in a previous patch.
|
* Retroactively corrects the model vault size due to incorrect initialization in a previous patch.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void RetroactiveVaultSize();
|
void RetroactiveVaultSize() const;
|
||||||
bool GetBoolean(const std::u16string& name) const;
|
bool GetBoolean(const std::u16string& name) const;
|
||||||
int32_t GetI32(const std::u16string& name) const;
|
int32_t GetI32(const std::u16string& name) const;
|
||||||
int64_t GetI64(const std::u16string& name) const;
|
int64_t GetI64(const std::u16string& name) const;
|
||||||
@ -334,7 +334,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
static Observable<Entity*, const PositionUpdate&> OnPlayerPositionUpdate;
|
static Observable<Entity*, const PositionUpdate&> OnPlayerPositionUpdate;
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
|
void WriteLDFData(const std::vector<LDFBaseData*>& ldf, RakNet::BitStream& outBitStream) const;
|
||||||
LWOOBJID m_ObjectID;
|
LWOOBJID m_ObjectID;
|
||||||
|
|
||||||
LOT m_TemplateID;
|
LOT m_TemplateID;
|
||||||
@ -357,7 +358,6 @@ protected:
|
|||||||
Entity* m_ParentEntity; //For spawners and the like
|
Entity* m_ParentEntity; //For spawners and the like
|
||||||
std::vector<Entity*> m_ChildEntities;
|
std::vector<Entity*> m_ChildEntities;
|
||||||
eGameMasterLevel m_GMLevel;
|
eGameMasterLevel m_GMLevel;
|
||||||
uint16_t m_CollectibleID;
|
|
||||||
std::vector<std::string> m_Groups;
|
std::vector<std::string> m_Groups;
|
||||||
uint16_t m_NetworkID;
|
uint16_t m_NetworkID;
|
||||||
std::vector<std::function<void()>> m_DieCallbacks;
|
std::vector<std::function<void()>> m_DieCallbacks;
|
||||||
@ -383,6 +383,8 @@ protected:
|
|||||||
|
|
||||||
bool m_IsParentChildDirty = true;
|
bool m_IsParentChildDirty = true;
|
||||||
|
|
||||||
|
bool m_IsSleeping = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Collision
|
* Collision
|
||||||
*/
|
*/
|
||||||
@ -391,7 +393,7 @@ protected:
|
|||||||
// objectID of receiver and map of notification name to script
|
// objectID of receiver and map of notification name to script
|
||||||
std::map<LWOOBJID, std::map<std::string, CppScripts::Script*>> m_Subscriptions;
|
std::map<LWOOBJID, std::map<std::string, CppScripts::Script*>> m_Subscriptions;
|
||||||
|
|
||||||
std::multimap<MessageType::Game, std::function<bool(GameMessages::GameMsg&)>> m_MsgHandlers;
|
std::unordered_multimap<MessageType::Game, std::function<bool(GameMessages::GameMsg&)>> m_MsgHandlers;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,13 @@ PhysicsComponent::PhysicsComponent(Entity* parent, int32_t componentId) : Compon
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_Parent->HasVar(u"CollisionGroupID")) m_CollisionGroup = m_Parent->GetVar<int32_t>(u"CollisionGroupID");
|
if (m_Parent->HasVar(u"CollisionGroupID")) m_CollisionGroup = m_Parent->GetVar<int32_t>(u"CollisionGroupID");
|
||||||
|
|
||||||
|
RegisterMsg(MessageType::Game::GET_POSITION, this, &PhysicsComponent::OnGetPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PhysicsComponent::OnGetPosition(GameMessages::GameMsg& msg) {
|
||||||
|
static_cast<GameMessages::GetPosition&>(msg).pos = GetPosition();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
void PhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||||
|
|
||||||
const NiPoint3& GetPosition() const { return m_Position; }
|
const NiPoint3& GetPosition() const noexcept { return m_Position; }
|
||||||
virtual void SetPosition(const NiPoint3& pos) { if (m_Position == pos) return; m_Position = pos; m_DirtyPosition = true; }
|
virtual void SetPosition(const NiPoint3& pos) { if (m_Position == pos) return; m_Position = pos; m_DirtyPosition = true; }
|
||||||
|
|
||||||
const NiQuaternion& GetRotation() const { return m_Rotation; }
|
const NiQuaternion& GetRotation() const { return m_Rotation; }
|
||||||
@ -35,6 +35,8 @@ protected:
|
|||||||
|
|
||||||
void SpawnVertices(dpEntity* entity) const;
|
void SpawnVertices(dpEntity* entity) const;
|
||||||
|
|
||||||
|
bool OnGetPosition(GameMessages::GameMsg& msg);
|
||||||
|
|
||||||
NiPoint3 m_Position;
|
NiPoint3 m_Position;
|
||||||
|
|
||||||
NiQuaternion m_Rotation;
|
NiQuaternion m_Rotation;
|
||||||
|
@ -5207,7 +5207,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream& inStream, Entity* ent
|
|||||||
if (currency == 0) return;
|
if (currency == 0) return;
|
||||||
|
|
||||||
auto* ch = entity->GetCharacter();
|
auto* ch = entity->GetCharacter();
|
||||||
if (ch && entity->CanPickupCoins(currency)) {
|
if (ch && entity->PickupCoins(currency)) {
|
||||||
ch->SetCoins(ch->GetCoins() + currency, eLootSourceType::PICKUP);
|
ch->SetCoins(ch->GetCoins() + currency, eLootSourceType::PICKUP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -843,5 +843,10 @@ namespace GameMessages {
|
|||||||
LWOOBJID targetID;
|
LWOOBJID targetID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct GetPosition : public GameMsg {
|
||||||
|
GetPosition() : GameMsg(MessageType::Game::GET_POSITION) {}
|
||||||
|
|
||||||
|
NiPoint3 pos{};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
#endif // GAMEMESSAGES_H
|
#endif // GAMEMESSAGES_H
|
||||||
|
@ -24,9 +24,8 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Loot::CacheMatrix(uint32_t matrixIndex) {
|
void Loot::CacheMatrix(uint32_t matrixIndex) {
|
||||||
if (CachedMatrices.find(matrixIndex) != CachedMatrices.end()) {
|
if (CachedMatrices.contains(matrixIndex)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
CachedMatrices.insert(matrixIndex);
|
CachedMatrices.insert(matrixIndex);
|
||||||
CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
CDComponentsRegistryTable* componentsRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
||||||
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user