mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-19 10:15:27 +00:00
refactor(entity): components load their config and save after all exist, as the client
LWOGameObject::MakeReadyForSerialization runs each component's LoadConfigData and then a character's LoadFromSaveData, in the order the components were made, once DoObjectComponentLoad has made them all; then their Startup. Entity::Initialize now does the same with a component list in creation order (the client's componentList); the walk's own save calls (mission, physics, destroyable, level, character, skill, ghost) and the destroyable's call into the buff go. A model's behaviors load in its LoadConfigData; controllable physics places a non-character at construction, as the client's physics takes the spawn position. A component added later still loads at once. Same bytes for every LOT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <typeinfo>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "NiPoint3.h"
|
||||
@@ -460,6 +461,10 @@ private:
|
||||
|
||||
// Every component has had its Startup (the end of Initialize)
|
||||
bool m_ComponentsStarted = false;
|
||||
// Initialize is making the components (DoObjectComponentLoad); their config and save load after
|
||||
bool m_LoadingComponents = false;
|
||||
// The components in the order they were made (the client's componentList)
|
||||
std::vector<Component*> m_ComponentList;
|
||||
std::vector<EntityTimer> m_Timers;
|
||||
std::vector<EntityTimer> m_PendingTimers;
|
||||
std::vector<EntityCallbackTimer> m_CallbackTimers;
|
||||
@@ -651,8 +656,14 @@ inline ComponentType* Entity::AddComponent(VaArgs... args) {
|
||||
// PrepareConfigData); one added after the object started up starts up at once
|
||||
componentToReturn->LoadDataFromTemplate();
|
||||
componentToReturn->PrepareConfigData();
|
||||
componentToReturn->LoadConfigData();
|
||||
if (m_ComponentsStarted) componentToReturn->Startup();
|
||||
if (m_LoadingComponents) {
|
||||
// While the object loads, its config, save and startup come after every component exists
|
||||
// (LWOGameObject::MakeReadyForSerialization), in the order the components were made
|
||||
if (std::ranges::find(m_ComponentList, componentToReturn) == m_ComponentList.end()) m_ComponentList.push_back(componentToReturn);
|
||||
} else {
|
||||
componentToReturn->LoadConfigData();
|
||||
if (m_ComponentsStarted) componentToReturn->Startup();
|
||||
}
|
||||
|
||||
// Finally return the created or already existing component.
|
||||
// Because of the assert above, this should always be a ComponentType* but I need a way to guarantee the map cannot be modifed outside this function
|
||||
|
||||
Reference in New Issue
Block a user