More organization of header

This commit is contained in:
David Markowitz 2023-06-17 02:39:33 -07:00
parent 68a5cc1d89
commit 1bdec00a61
11 changed files with 61 additions and 59 deletions

View File

@ -746,13 +746,10 @@ void Entity::ResetFlags() {
// Unused // Unused
} }
// std::for_each
void Entity::UpdateXMLDoc(tinyxml2::XMLDocument* doc) { void Entity::UpdateXMLDoc(tinyxml2::XMLDocument* doc) {
DluAssert(doc != nullptr); DluAssert(doc != nullptr);
for (const auto& pair : m_Components) { for (const auto&[componentId, component] : m_Components) {
if (pair.second == nullptr) continue; if (component) component->UpdateXml(doc);
pair.second->UpdateXml(doc);
} }
} }
@ -1121,9 +1118,10 @@ void Entity::RegisterCoinDrop(const uint64_t& coinsDropped) {
} }
void Entity::AddChild(Entity* child) { void Entity::AddChild(Entity* child) {
if (!child) return;
m_IsParentChildDirty = true; m_IsParentChildDirty = true;
if (std::find(m_ChildEntities.begin(), m_ChildEntities.end(), child) != m_ChildEntities.end()) return; if (std::find(m_ChildEntities.begin(), m_ChildEntities.end(), child) == m_ChildEntities.end()) m_ChildEntities.push_back(child);
m_ChildEntities.push_back(child); else Game::logger->Log("Entity", "WARNING: Entity (objid:lot) %llu:%i already has (%llu:%i) as a child", GetObjectID(), GetLOT(), child->GetObjectID(), child->GetLOT());
} }
void Entity::RemoveChild(Entity* child) { void Entity::RemoveChild(Entity* child) {
@ -1138,7 +1136,7 @@ void Entity::RemoveChild(Entity* child) {
void Entity::RemoveParent() { void Entity::RemoveParent() {
if (m_ParentEntity) m_IsParentChildDirty = true; if (m_ParentEntity) m_IsParentChildDirty = true;
else Game::logger->Log("Entity", "WARNING: Attempted to remove parent from(objid:lot) (%llu:%i) when no parent existed", GetObjectID(), GetLOT()); else Game::logger->Log("Entity", "WARNING: Attempted to remove parent from (objid:lot) (%llu:%i) when no parent existed", GetObjectID(), GetLOT());
this->m_ParentEntity = nullptr; this->m_ParentEntity = nullptr;
} }
@ -1363,7 +1361,7 @@ void Entity::Resurrect() {
if (IsPlayer()) GameMessages::SendResurrect(this); if (IsPlayer()) GameMessages::SendResurrect(this);
} }
void Entity::AddToGroups(const std::string& group) { void Entity::AddGroup(const std::string& group) {
if (std::find(m_Groups.begin(), m_Groups.end(), group) == m_Groups.end()) { if (std::find(m_Groups.begin(), m_Groups.end(), group) == m_Groups.end()) {
m_Groups.push_back(group); m_Groups.push_back(group);
} }

View File

@ -98,6 +98,9 @@ public:
Entity* GetOwner() const; Entity* GetOwner() const;
void SetOwnerOverride(const LWOOBJID& value) { m_OwnerOverride = value; }; void SetOwnerOverride(const LWOOBJID& value) { m_OwnerOverride = value; };
Entity* GetScheduledKiller() { return m_ScheduleKiller; }
std::vector<LWOOBJID>& GetTargetsInPhantom();
const std::unordered_map<eReplicaComponentType, ComponentPtr>& GetComponents() { return m_Components; }
// Position related info // Position related info
const NiPoint3& GetDefaultPosition() const { return m_DefaultPosition; }; const NiPoint3& GetDefaultPosition() const { return m_DefaultPosition; };
@ -110,6 +113,9 @@ public:
const NiQuaternion& GetRotation() const; const NiQuaternion& GetRotation() const;
void SetRotation(const NiQuaternion& rotation); void SetRotation(const NiQuaternion& rotation);
virtual NiPoint3 GetRespawnPosition() const { return NiPoint3::ZERO; }
virtual NiQuaternion GetRespawnRotation() const { return NiQuaternion::IDENTITY; }
// Spawner related info // Spawner related info
Spawner* GetSpawner() const { return m_Spawner; } Spawner* GetSpawner() const { return m_Spawner; }
@ -117,6 +123,7 @@ public:
const std::vector<std::string>& GetGroups() { return m_Groups; }; const std::vector<std::string>& GetGroups() { return m_Groups; };
void SetGroups(const std::vector<std::string>& value) { m_Groups = value; } void SetGroups(const std::vector<std::string>& value) { m_Groups = value; }
void AddGroup(const std::string& group);
// LDF related into // LDF related into
const std::vector<LDFBaseData*>& GetSettings() const { return m_Settings; } const std::vector<LDFBaseData*>& GetSettings() const { return m_Settings; }
@ -149,14 +156,12 @@ public:
Character* GetCharacter() const { return m_Character; } Character* GetCharacter() const { return m_Character; }
void SetCharacter(Character* value) { m_Character = value; } void SetCharacter(Character* value) { m_Character = value; }
// End info // End info
bool IsDead() const;
// If you are calling this, then calling GetComponent<T>, just call GetComponent<T> and check for nullptr. // If you are calling this, then calling GetComponent<T>, just call GetComponent<T> and check for nullptr.
bool HasComponent(const eReplicaComponentType componentId) const; bool HasComponent(const eReplicaComponentType componentId) const;
// Event management
/** /**
* Call these when you want to observe events. Observed events should follow the following naming convention * Call these when you want to observe events. Observed events should follow the following naming convention
* in scripts Notify<NotificationName>. For example, if you want to observe the "OnDeath" event, you would call * in scripts Notify<NotificationName>. For example, if you want to observe the "OnDeath" event, you would call
@ -170,6 +175,7 @@ public:
*/ */
void Unsubscribe(CppScripts::Script* scriptToRemove, const std::string& notificationName); void Unsubscribe(CppScripts::Script* scriptToRemove, const std::string& notificationName);
// Proximity radius management
void AddProximityRadius(const float proxRadius, const std::string& name); void AddProximityRadius(const float proxRadius, const std::string& name);
void AddProximityRadius(const BoxDimensions& dimensions, const std::string& name); void AddProximityRadius(const BoxDimensions& dimensions, const std::string& name);
@ -178,9 +184,18 @@ public:
inline void SetProximityRadius(const float proxRadius, const std::string& name) { this->AddProximityRadius(proxRadius, name); } inline void SetProximityRadius(const float proxRadius, const std::string& name) { this->AddProximityRadius(proxRadius, name); }
inline void SetProximityRadius(const BoxDimensions& dimensions, const std::string& name) { this->AddProximityRadius(dimensions, name); } inline void SetProximityRadius(const BoxDimensions& dimensions, const std::string& name) { this->AddProximityRadius(dimensions, name); }
void AddRebuildCompleteCallback(const std::function<void(Entity* user)>& callback) const;
void AddCollisionPhantomCallback(const std::function<void(Entity* target)>& callback) { m_PhantomCollisionCallbacks.push_back(callback); };
void AddDieCallback(const std::function<void()>& callback) { m_DieCallbacks.push_back(callback); };
void TriggerEvent(const eTriggerEventType event, Entity* optionalTarget = nullptr);
void NotifyObject(Entity* sender, const std::u16string& name, const int32_t param1 = 0, const int32_t param2 = 0);
// Parent Child management
void AddChild(Entity* child); void AddChild(Entity* child);
void RemoveChild(Entity* child); void RemoveChild(Entity* child);
void RemoveParent(); void RemoveParent();
// Timer management
void AddTimer(const std::string& name, const float time); void AddTimer(const std::string& name, const float time);
void AddCallbackTimer(const float time, const std::function<void()>& callback); void AddCallbackTimer(const float time, const std::function<void()>& callback);
bool HasTimer(const std::string& name); bool HasTimer(const std::string& name);
@ -188,16 +203,13 @@ public:
void CancelAllTimers(); void CancelAllTimers();
void CancelTimer(const std::string& name); void CancelTimer(const std::string& name);
void AddToGroups(const std::string& group); // Serialization
bool IsPlayer() const;
void WriteBaseReplicaData(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType); void WriteBaseReplicaData(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType);
void WriteComponents(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType); void WriteComponents(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType);
void ResetFlags();
void UpdateXMLDoc(tinyxml2::XMLDocument* doc);
void Update(float deltaTime);
// Events // Scripting
// Get the script attached to this entity. Will never return nullptr.
CppScripts::Script* GetScript() const;
void OnCollisionProximity(const LWOOBJID otherEntity, const std::string& proxName, const std::string& status); void OnCollisionProximity(const LWOOBJID otherEntity, const std::string& proxName, const std::string& status);
void OnCollisionPhantom(const LWOOBJID otherEntity); void OnCollisionPhantom(const LWOOBJID otherEntity);
void OnCollisionLeavePhantom(const LWOOBJID otherEntity); void OnCollisionLeavePhantom(const LWOOBJID otherEntity);
@ -208,7 +220,6 @@ public:
void OnCinematicUpdate(Entity* self, Entity* sender, const eCinematicEvent event, const std::u16string& pathName, void OnCinematicUpdate(Entity* self, Entity* sender, const eCinematicEvent event, const std::u16string& pathName,
const float pathTime, const float totalTime, const int32_t waypoint); const float pathTime, const float totalTime, const int32_t waypoint);
void NotifyObject(Entity* sender, const std::u16string& name, const int32_t param1 = 0, const int32_t param2 = 0);
void OnEmoteReceived(const int32_t emote, Entity* target); void OnEmoteReceived(const int32_t emote, Entity* target);
void OnUse(Entity* originator); void OnUse(Entity* originator);
@ -228,14 +239,19 @@ public:
void OnMessageBoxResponse(Entity* sender, const int32_t button, const std::u16string& identifier, const std::u16string& userData); void OnMessageBoxResponse(Entity* sender, const int32_t button, const std::u16string& identifier, const std::u16string& userData);
void OnChoiceBoxResponse(Entity* sender, const int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier); void OnChoiceBoxResponse(Entity* sender, const int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier);
void RequestActivityExit(Entity* sender, const LWOOBJID& player, const bool canceled); void RequestActivityExit(Entity* sender, const LWOOBJID& player, const bool canceled);
// End scripting
// Cleanup functions
void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u""); void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u"");
// Odds are you do not need to call this. Call Smash instead.
void Kill(Entity* murderer = nullptr); void Kill(Entity* murderer = nullptr);
void AddRebuildCompleteCallback(const std::function<void(Entity* user)>& callback) const;
void AddCollisionPhantomCallback(const std::function<void(Entity* target)>& callback) { m_PhantomCollisionCallbacks.push_back(callback); }; void ScheduleKillAfterUpdate(Entity* murderer = nullptr);
void AddDieCallback(const std::function<void()>& callback) { m_DieCallbacks.push_back(callback); }; void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; }
void Resurrect(); void Resurrect();
// Loot management (should be moved to Player. Not every Entity needs this.)
void AddLootItem(const Loot::Info& info); void AddLootItem(const Loot::Info& info);
void PickupItem(const LWOOBJID& objectID); void PickupItem(const LWOOBJID& objectID);
@ -243,37 +259,29 @@ public:
void PickupCoins(const uint64_t& count); void PickupCoins(const uint64_t& count);
void RegisterCoinDrop(const uint64_t& count); void RegisterCoinDrop(const uint64_t& count);
void ScheduleKillAfterUpdate(Entity* murderer = nullptr); // State checkers
void TriggerEvent(const eTriggerEventType event, Entity* optionalTarget = nullptr);
void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; }
virtual NiPoint3 GetRespawnPosition() const { return NiPoint3::ZERO; }
virtual NiQuaternion GetRespawnRotation() const { return NiQuaternion::IDENTITY; }
CppScripts::Script* GetScript() const;
void Sleep(); void Sleep();
void Wake(); void Wake();
bool IsSleeping() const; bool IsSleeping() const;
bool IsDead() const;
bool IsPlayer() const;
/* // Update
void UpdateXMLDoc(tinyxml2::XMLDocument* doc);
void Update(float deltaTime);
/**
* Utility * Utility
*/ */
//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();
void ResetFlags();
// LDF Setting accessors
bool GetBoolean(const std::u16string& name) const { return GetVar<bool>(name); }; bool GetBoolean(const std::u16string& name) const { return GetVar<bool>(name); };
int32_t GetI32(const std::u16string& name) const { return GetVar<int32_t>(name); }; int32_t GetI32(const std::u16string& name) const { return GetVar<int32_t>(name); };
int64_t GetI64(const std::u16string& name) const { return GetVar<int64_t>(name); }; int64_t GetI64(const std::u16string& name) const { return GetVar<int64_t>(name); };
void SetBoolean(const std::u16string& name, bool value) { SetVar<bool>(name, value); }
void SetI32(const std::u16string& name, int32_t value) { SetVar<int32_t>(name, value); };
void SetI64(const std::u16string& name, int64_t value) { SetVar<int64_t>(name, value); };
bool HasVar(const std::u16string& name) const; bool HasVar(const std::u16string& name) const;
/**
* Get the LDF data.
*/
LDFBaseData* GetVarData(const std::u16string& name) const; LDFBaseData* GetVarData(const std::u16string& name) const;
/** /**
@ -281,14 +289,10 @@ public:
*/ */
std::string GetVarAsString(const std::u16string& name) const; std::string GetVarAsString(const std::u16string& name) const;
/* // LDF Setting assignment shorthands
* Collision void SetBoolean(const std::u16string& name, bool value) { SetVar<bool>(name, value); }
*/ void SetI32(const std::u16string& name, int32_t value) { SetVar<int32_t>(name, value); };
std::vector<LWOOBJID>& GetTargetsInPhantom(); void SetI64(const std::u16string& name, int64_t value) { SetVar<int64_t>(name, value); };
Entity* GetScheduledKiller() { return m_ScheduleKiller; }
const std::unordered_map<eReplicaComponentType, ComponentPtr>& GetComponents() { return m_Components; }
// Template declarations // Template declarations
template<typename T> template<typename T>

View File

@ -17,7 +17,7 @@ void WaveBossApe::OnStartup(Entity* self) {
combatAIComponent->SetStunImmune(true); combatAIComponent->SetStunImmune(true);
} }
self->AddToGroups("boss"); self->AddGroup("boss");
BaseEnemyApe::OnStartup(self); BaseEnemyApe::OnStartup(self);
} }

View File

@ -11,7 +11,7 @@ void WaveBossHammerling::OnStartup(Entity* self) {
combatAIComponent->SetStunImmune(true); combatAIComponent->SetStunImmune(true);
} }
self->AddToGroups("boss"); self->AddGroup("boss");
} }
void WaveBossHammerling::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, void WaveBossHammerling::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1,

View File

@ -11,7 +11,7 @@ void WaveBossHorsemen::OnStartup(Entity* self) {
combatAIComponent->SetStunImmune(true); combatAIComponent->SetStunImmune(true);
} }
self->AddToGroups("boss"); self->AddGroup("boss");
} }
void void

View File

@ -11,7 +11,7 @@ void WaveBossSpiderling::OnStartup(Entity* self) {
combatAIComponent->SetStunImmune(true); combatAIComponent->SetStunImmune(true);
} }
self->AddToGroups("boss"); self->AddGroup("boss");
} }
void WaveBossSpiderling::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, void WaveBossSpiderling::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1,

View File

@ -123,7 +123,7 @@ void NtCombatChallengeServer::OnChildLoaded(Entity* self, Entity* child) {
EntityManager::Instance()->SerializeEntity(child); EntityManager::Instance()->SerializeEntity(child);
child->AddToGroups("targets_" + std::to_string(self->GetObjectID())); child->AddGroup("targets_" + std::to_string(self->GetObjectID()));
} }
void NtCombatChallengeServer::ResetGame(Entity* self) { void NtCombatChallengeServer::ResetGame(Entity* self) {

View File

@ -51,7 +51,7 @@ void EnemySpiderSpawner::OnTimerDone(Entity* self, std::string timerName) {
Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr); Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr);
if (newEntity) { if (newEntity) {
EntityManager::Instance()->ConstructEntity(newEntity); EntityManager::Instance()->ConstructEntity(newEntity);
newEntity->AddToGroups("BabySpider"); newEntity->AddGroup("BabySpider");
/* /*
auto* movementAi = newEntity->GetComponent<MovementAIComponent>(); auto* movementAi = newEntity->GetComponent<MovementAIComponent>();

View File

@ -18,7 +18,7 @@ void ActMine::OnRebuildNotifyState(Entity* self, eRebuildState state) {
self->SetVar(u"RebuildComplete", true); self->SetVar(u"RebuildComplete", true);
self->SetVar(u"NumWarnings", 0); self->SetVar(u"NumWarnings", 0);
self->AddToGroups("reset"); self->AddGroup("reset");
} }
} }

View File

@ -2,7 +2,7 @@
#include "Entity.h" #include "Entity.h"
void WildNinjaBricks::OnStartup(Entity* self) { void WildNinjaBricks::OnStartup(Entity* self) {
self->AddToGroups("Ninjastuff"); self->AddGroup("Ninjastuff");
} }
void WildNinjaBricks::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { void WildNinjaBricks::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) {

View File

@ -3,7 +3,7 @@
#include "Entity.h" #include "Entity.h"
void WildNinjaStudent::OnStartup(Entity* self) { void WildNinjaStudent::OnStartup(Entity* self) {
self->AddToGroups("Ninjastuff"); self->AddGroup("Ninjastuff");
GameMessages::SendPlayAnimation(self, u"bow"); GameMessages::SendPlayAnimation(self, u"bow");
} }