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

@@ -19,6 +19,7 @@
#include "eStateChangeType.h"
#include "StringifiedEnum.h"
#include "Amf3.h"
#include "ObjectLoadState.h"
ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity, const int32_t componentID) : PhysicsComponent(entity, componentID) {
RegisterMsg(&ControllablePhysicsComponent::OnGetObjectReportInfo);
@@ -460,3 +461,14 @@ bool ControllablePhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObject
immunity.PushDebug<AMFBoolValue>("Immune to Stun Jump") = m_ImmuneToStunJumpCount != 0;
return true;
}
void ControllablePhysicsComponent::Allocator(Entity& entity, ObjectLoadState& state) {
const auto controllablePhysicsComponentID = state.GetComponentID(eReplicaComponentType::CONTROLLABLE_PHYSICS);
if (state.hasModelBehaviors) {
// LWOControllablePhysComponent::Allocator (0x0104e070): left to the model case
if (controllablePhysicsComponentID > 0) state.modelPhysicsComponentID = controllablePhysicsComponentID;
} else if (controllablePhysicsComponentID > 0) {
// The component places it: where the level put an object, where a character's save and the zone put it
entity.AddComponent<ControllablePhysicsComponent>(controllablePhysicsComponentID);
}
}

View File

@@ -10,6 +10,8 @@
#include "dpCollisionChecks.h"
#include "eBubbleType.h"
struct ObjectLoadState;
namespace tinyxml2 {
class XMLDocument;
}
@@ -25,6 +27,9 @@ class ControllablePhysicsComponent : public PhysicsComponent {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::CONTROLLABLE_PHYSICS;
// The client's allocator for this type (ObjectLoader2::DoObjectComponentLoad calls it in load order)
static void Allocator(Entity& entity, ObjectLoadState& state);
ControllablePhysicsComponent(Entity* entity, const int32_t componentID);
void LoadConfigData() override;

View File

@@ -1,6 +1,9 @@
#include "HavokVehiclePhysicsComponent.h"
#include "EntityManager.h"
#include "Amf3.h"
#include "Entity.h"
#include "ObjectLoadState.h"
#include "SimplePhysicsComponent.h"
HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent, const int32_t componentID) : PhysicsComponent(parent, componentID) {
RegisterMsg(&HavokVehiclePhysicsComponent::OnGetObjectReportInfo);
@@ -125,3 +128,15 @@ bool HavokVehiclePhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObject
remoteInputInfo.PushDebug<AMFBoolValue>("Is Modified") = m_RemoteInputInfo.m_IsModified;
return true;
}
void HavokVehiclePhysicsComponent::Allocator(Entity& entity, ObjectLoadState& state) {
const auto havokVehiclePhysicsComponentID = state.GetComponentID(eReplicaComponentType::HAVOK_VEHICLE_PHYSICS);
// The client makes simple physics instead for use_simple_physics, and none for objectWorldState 2
if (havokVehiclePhysicsComponentID > 0 && entity.HasVar(u"use_simple_physics")) {
if (!entity.HasComponent(eReplicaComponentType::SIMPLE_PHYSICS)) entity.AddComponent<SimplePhysicsComponent>(havokVehiclePhysicsComponentID);
} else if (havokVehiclePhysicsComponentID > 0 && !(entity.HasVar(u"objectWorldState") && entity.GetVarAs<int32_t>(u"objectWorldState") == 2)) {
auto* havokVehiclePhysicsComponent = entity.AddComponent<HavokVehiclePhysicsComponent>(havokVehiclePhysicsComponentID);
havokVehiclePhysicsComponent->SetPosition(entity.GetDefaultPosition());
havokVehiclePhysicsComponent->SetRotation(entity.GetDefaultRotation());
}
}

View File

@@ -6,6 +6,8 @@
#include "eReplicaComponentType.h"
#include "PositionUpdate.h"
struct ObjectLoadState;
/**
* Physics component for vehicles.
*/
@@ -13,6 +15,9 @@ class HavokVehiclePhysicsComponent : public PhysicsComponent {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::HAVOK_VEHICLE_PHYSICS;
// The client's allocator for this type (ObjectLoader2::DoObjectComponentLoad calls it in load order)
static void Allocator(Entity& entity, ObjectLoadState& state);
HavokVehiclePhysicsComponent(Entity* parentEntity, const int32_t componentID);
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;

View File

@@ -28,6 +28,7 @@
#include "dpEntity.h"
#include "dpShapeBox.h"
#include "dpShapeSphere.h"
#include "ObjectLoadState.h"
PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent, const int32_t componentID) : PhysicsComponent(parent, componentID) {
RegisterMsg(&PhantomPhysicsComponent::OnGetObjectReportInfo);
@@ -293,3 +294,13 @@ bool PhantomPhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectRepor
return true;
}
void PhantomPhysicsComponent::Allocator(Entity& entity, ObjectLoadState& state) {
const auto phantomPhysicsComponentID = state.GetComponentID(eReplicaComponentType::PHANTOM_PHYSICS);
if (state.hasModelBehaviors) {
// LWOPhantomPhysicsComponent::Allocator (0x010383b0): left to the model case
if (phantomPhysicsComponentID > 0) state.modelPhysicsComponentID = phantomPhysicsComponentID;
} else if (phantomPhysicsComponentID > 0 && !entity.HasComponent(eReplicaComponentType::PHANTOM_PHYSICS)) {
entity.AddComponent<PhantomPhysicsComponent>(phantomPhysicsComponentID)->SetPhysicsEffectActive(false);
}
}

View File

@@ -12,6 +12,8 @@
#include "eReplicaComponentType.h"
#include "PhysicsComponent.h"
struct ObjectLoadState;
class Entity;
class dpEntity;
enum class ePhysicsEffectType : uint32_t ;
@@ -27,6 +29,9 @@ class PhantomPhysicsComponent final : public PhysicsComponent {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PHANTOM_PHYSICS;
// The client's allocator for this type (ObjectLoader2::DoObjectComponentLoad calls it in load order)
static void Allocator(Entity& entity, ObjectLoadState& state);
PhantomPhysicsComponent(Entity* parent, const int32_t componentID);
void LoadConfigData() override;

View File

@@ -14,6 +14,8 @@
#include "Entity.h"
#include "StringifiedEnum.h"
#include "Amf3.h"
#include "ObjectLoadState.h"
#include "PhantomPhysicsComponent.h"
SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, const int32_t componentID) : PhysicsComponent(parent, componentID) {
RegisterMsg(&SimplePhysicsComponent::OnGetObjectReportInfo);
@@ -97,3 +99,15 @@ bool SimplePhysicsComponent::OnGetObjectReportInfo(GameMessages::GetObjectReport
info.PushDebug<AMFStringValue>("Climbable Type") = StringifiedEnum::ToString(m_ClimbableType).data();
return true;
}
void SimplePhysicsComponent::Allocator(Entity& entity, ObjectLoadState& state) {
const auto simplePhysicsComponentID = state.GetComponentID(eReplicaComponentType::SIMPLE_PHYSICS);
if (state.hasModelBehaviors) {
// LWOSimplePhysicsComponent::Allocator (0x0104ded0): left to the model case
if (simplePhysicsComponentID > 0) state.modelPhysicsComponentID = simplePhysicsComponentID;
} else if (simplePhysicsComponentID > 0) {
// state.markedAsPhantom makes its simple physics phantom physics (with the simple physics row)
if (state.markedAsPhantom) entity.AddComponent<PhantomPhysicsComponent>(simplePhysicsComponentID)->SetPhysicsEffectActive(false);
else entity.AddComponent<SimplePhysicsComponent>(simplePhysicsComponentID);
}
}

View File

@@ -13,6 +13,8 @@
#include "PhysicsComponent.h"
#include "eReplicaComponentType.h"
struct ObjectLoadState;
class Entity;
enum class eClimbableType : int32_t {
@@ -30,6 +32,9 @@ class SimplePhysicsComponent : public PhysicsComponent {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SIMPLE_PHYSICS;
// The client's allocator for this type (ObjectLoader2::DoObjectComponentLoad calls it in load order)
static void Allocator(Entity& entity, ObjectLoadState& state);
// Havok motion types the client reads as the physics motion state
static constexpr uint32_t MOTION_TYPE_DYNAMIC = 1;
static constexpr uint32_t MOTION_TYPE_KEYFRAMED = 4;