refactor(entity): each component type has an allocator, as the client

DoObjectComponentLoad walks the client's load order and calls the type's
allocator from a table, like ObjectLoader2, instead of one 76-case switch.
Components with rules of their own have a static Allocator (the client's
LWOxComponent::Allocator); the rest share a registry allocator. The load
state moves to ObjectLoadState.h so the allocators can take it.

Construction bytes are identical for all 15,962 LOTs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-02 08:11:58 -05:00
parent 3a79286666
commit 260e6cb1b1
52 changed files with 634 additions and 684 deletions

View File

@@ -38,6 +38,13 @@
#include <ctime>
#include <cmath>
#include <ranges>
#include "Entity.h"
#include "ObjectLoadState.h"
#include "LevelProgressionComponent.h"
#include "MountControlComponent.h"
#include "PetCreatorComponent.h"
#include "PlayerForcedMovementComponent.h"
#include "PossessorComponent.h"
CharacterComponent::CharacterComponent(Entity* parent, const int32_t componentID, Character* character, const SystemAddress& systemAddress) : Component(parent, componentID) {
m_Character = character;
@@ -1076,3 +1083,20 @@ void CharacterComponent::SetUScore(int64_t uscore, uint32_t source) {
if (const auto* character = m_Parent->GetCharacter()) EconomyLedger::RecordUScore(character->GetID(), uscore - m_Uscore, source);
m_Uscore = uscore;
}
void CharacterComponent::Allocator(Entity& entity, ObjectLoadState& state) {
const auto characterID = state.GetComponentID(eReplicaComponentType::CHARACTER);
if (characterID > 0 || entity.GetCharacter()) {
// LWOCharacterComponent::Factory (0x0104db40): possession control, mount control, pet creator, level
// progression and forced movement, then the character, all componentID -1
entity.AddComponent<PossessorComponent>(-1);
entity.AddComponent<MountControlComponent>(-1);
entity.AddComponent<PetCreatorComponent>(-1);
entity.AddComponent<LevelProgressionComponent>(-1);
entity.AddComponent<PlayerForcedMovementComponent>(-1);
auto& systemAddress = entity.GetCharacter()->GetParentUser() ? entity.GetCharacter()->GetParentUser()->GetSystemAddress() : UNASSIGNED_SYSTEM_ADDRESS;
entity.AddComponent<CharacterComponent>(-1, entity.GetCharacter(), systemAddress);
}
}

View File

@@ -17,6 +17,8 @@
#include <optional>
#include <chrono>
struct ObjectLoadState;
enum class eGameActivity : uint32_t;
class Item;
@@ -45,6 +47,9 @@ class CharacterComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::CHARACTER;
// The client's allocator for this type (ObjectLoader2::DoObjectComponentLoad calls it in load order)
static void Allocator(Entity& entity, ObjectLoadState& state);
CharacterComponent(Entity* parent, const int32_t componentID, Character* character, const SystemAddress& systemAddress);
~CharacterComponent() override;

View File

@@ -1,4 +1,6 @@
#include "PlayerForcedMovementComponent.h"
#include "Entity.h"
#include "ObjectLoadState.h"
PlayerForcedMovementComponent::PlayerForcedMovementComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
m_Parent = parent;
@@ -14,3 +16,9 @@ void PlayerForcedMovementComponent::Serialize(RakNet::BitStream& outBitStream, b
}
m_DirtyInfo = false;
}
void PlayerForcedMovementComponent::Allocator(Entity& entity, ObjectLoadState& state) {
// From the registry, as the client makes it (a character got one with its character component)
const auto id = state.GetComponentID(eReplicaComponentType::PLAYER_FORCED_MOVEMENT, -1);
if (id > -1 && !entity.HasComponent(eReplicaComponentType::PLAYER_FORCED_MOVEMENT)) entity.AddComponent<PlayerForcedMovementComponent>(id);
}

View File

@@ -4,6 +4,8 @@
#include "Component.h"
#include "eReplicaComponentType.h"
struct ObjectLoadState;
/**
* Component that handles player forced movement
*
@@ -12,6 +14,9 @@ class PlayerForcedMovementComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PLAYER_FORCED_MOVEMENT;
// The client's allocator for this type (ObjectLoader2::DoObjectComponentLoad calls it in load order)
static void Allocator(Entity& entity, ObjectLoadState& state);
/**
* Constructor for this component
* @param parent parent that contains this component