Skip to content

Commit

Permalink
uberobject
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Jensen committed Mar 7, 2024
1 parent 3533b09 commit 9ce5251
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cdcAnim/AnimComponentV2.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#pragma once

namespace cdc { class IAnimGraphNode; }
namespace cdc {

class IAnimGraphNode;

class AnimComponentV2 {
public:
cdc::IAnimGraphNode *firstNode = nullptr; // 54
};

}
3 changes: 2 additions & 1 deletion cdcObjects/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target_sources(dxhr PRIVATE
ObjectComponent.cpp
ObjectManager.cpp)
ObjectManager.cpp
UberObject.cpp)
5 changes: 5 additions & 0 deletions cdcObjects/ObjectComponent.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "game/objects/UberObject_DX3.h"
#include "ObjectComponent.h"
#include "ObjectManager.h"
#include "cdcWorld/GameTracker.h"
Expand All @@ -22,6 +23,10 @@ bool ObjectComponent::InstanceInit(bool unknown) {
}
g_objectManager->preInit(m_instance, &gameTrackerX); // calls GameAdditionalPreInit
G2Instance_SetTransformsToIdentity(m_instance);
// TODO: call the object family's init function
// right now I'm just hardcoding the init for UberObjects (family 2) though
if (m_familyId == 2)
UBEROBJECT_DX3_Init(m_instance, &gameTrackerX);
// TODO
g_objectManager->postInit(m_instance, &gameTrackerX);// calls GameAdditionalPostInit
// TODO
Expand Down
6 changes: 6 additions & 0 deletions cdcObjects/Objects.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include "cdcWorld/UserDataComponent.h"

class ObjState : public InstanceUserData {

};
88 changes: 88 additions & 0 deletions cdcObjects/UberObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include "cdcAnim/AnimComponentV2.h"
#include "cdcWorld/Object.h"
#include "cdcWorld/Instance.h"
#include "cdcWorld/InstanceManager.h"
#include "cdcWorld/InstncG2.h"
#include "cdc/dtp/objectbasedata.h"
#include "UberObject.h"

Instance *UBEROBJECT_BirthSectionInstance(Instance *parent, uint32_t modelIndex, uint32_t id) {
// TODO
Instance *instance = InstanceManager::CreateInstance2();
instance->DefaultInit(
parent->object,
modelIndex,
id,
parent->intro,
parent->introData,
&parent->position,
&parent->rotation,
/*pDerivedObject=*/ nullptr,
/*flags=*/ 0);

instance->position = parent->position; // but DefaultInit just did that
instance->rotation = parent->rotation; // but DefaultInit just did that

// TODO

instance->objectComponent.SetInstance(instance);

// TODO

dtp::ObjectBaseData *dtpData = instance->object->dtpData;
if (dtpData->hasAnimGraph || dtpData->numHostedAnimGraphs) {
dtp::Model *model = instance->GetModels()[modelIndex];
// instance->animComponentV2 = new cdc::AnimComponentV2(instance);
// instance->animComponentV2->Init(model);
}

return instance;
}

UberObjectComposite::UberObjectComposite(Instance *instance, bool deferSectionInit) {
auto *prop = (dtp::UberObjectProp*) instance->object->data; // actually reads a cached version thereof
UserDataComponent::CreateIfNeeded(instance)->userData = this;
// TODO
this->instance = instance;
// TODO

numSections = prop->numSections;
sectionList = new int32_t[numSections];
for (uint32_t i=0; i<numSections; i++)
sectionList[i] = 0x7FFFFFFF;

if (!deferSectionInit)
CreateSections(instance);
}

uint32_t CurrentBirthID = 0x1000000; // how is this initialized

void UberObjectComposite::CreateSections(Instance *instance) {
if (!createdSections) {
createdSections = true;
auto *prop = (dtp::UberObjectProp*) instance->object->data; // actually reads a cached version thereof
if (sectionsIntroUniqueID == ~0u) {
sectionsIntroUniqueID = CurrentBirthID;
CurrentBirthID += prop->numSections;
}

for (uint32_t i=0; i<numSections; i++) {
Instance *child = CreateSectionInstance(instance, &prop->sectionList[i], i);
sectionList[i] = child ? child->introUniqueID : 0x7FFFFFFF;
}
}
}

Instance *UberObjectComposite::CreateSectionInstance(Instance *instance, dtp::UberObjectProp::SectionProp *info, uint32_t index) {
Instance *child = UBEROBJECT_BirthSectionInstance(instance, info->modelIndex, sectionsIntroUniqueID + index);
// TODO
if (child) {
// TODO
cdc::G2Instance_SetTransformsToIdentity(child);
}
return child;
}

UberObjectSection::UberObjectSection(Instance *instance, UberObjectComposite *composite, dtp::UberObjectProp::SectionProp *info, uint32_t index) {
// TODO
}
28 changes: 28 additions & 0 deletions cdcObjects/UberObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <cstdint>
#include "cdcObjects/Objects.h"
#include "cdc/dtp/objecttypes/uberobject.h"

// There is a string .\game\Objects\UberObject.cpp in DXHRDC.exe suggesting this file should go there,
// but Tomb Raider later moved it to cdcObjects/ which makes more sense IMO.

class Instance;

Instance *UBEROBJECT_BirthSectionInstance(Instance *parent, uint32_t modelIndex, uint32_t id);

class UberObjectComposite : public ObjState {
Instance *instance; // 54
bool createdSections = false; // 5D
uint32_t sectionsIntroUniqueID = ~0u; // 60
int32_t *sectionList = nullptr; // 64
uint32_t numSections = 0; // 68
public:
UberObjectComposite(Instance *instance, bool deferSectionInit);
void CreateSections(Instance *instance);
Instance *CreateSectionInstance(Instance *instance, dtp::UberObjectProp::SectionProp *info, uint32_t index);
};

class UberObjectSection : public ObjState {
public:
UberObjectSection(Instance *instance, UberObjectComposite *composite, dtp::UberObjectProp::SectionProp *info, uint32_t index);
};
3 changes: 2 additions & 1 deletion cdcWorld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ target_sources(dxhr PRIVATE
RMIDrawableBase.cpp
SceneLayer.cpp
stream.cpp
StreamUnit.cpp)
StreamUnit.cpp
UserDataComponent.cpp)

if (ENABLE_IMGUI)
target_sources(dxhr PRIVATE
Expand Down
21 changes: 21 additions & 0 deletions cdcWorld/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ void Instance::InitCommonComponents(bool initEffects, bool unknown) { // line 28
// this runs after DefaultInit

// TODO

if (objectFamilyId != /*UberObject*/ 2) {
// UberObjects create their own components in
// ObjectComponent::InstanceInit (called below)
// UBEROBJECT_DX3_Init
// UberObjectComposite_DX3
// CreateSections
// CreateSectionInstance
// UBEROBJECT_BirthSectionInstance

if (object->numAnims + object->numPatterns > 0) {
dtp::ObjectBaseData *dtpData = object->dtpData;
if (dtpData->hasAnimGraph || dtpData->numHostedAnimGraphs) {
// animComponentV2 = new AnimComponentV2(this);
// animComponentV2->Init(meshComponent.GetBaseModel());
}
}
}

// TODO

if (unknown)
objectComponent.SetProcessFunctions();
objectComponent.SetInstance(this);
Expand Down
3 changes: 3 additions & 0 deletions cdcWorld/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "cdcMath/Math.h"
#include "cdcObjects/ObjectComponent.h"
#include "cdcWorld/InstanceDrawable.h" // for MeshComponent
#include "cdcWorld/UserDataComponent.h"

namespace cdc {
class IDrawable;
Expand All @@ -26,6 +27,7 @@ class Instance {
Instance *next; // 0
Instance *prev; // 4
cdc::Object *object; // 8
int32_t introUniqueID; // C

uint16_t objectFamilyId; // 14
uint8_t flags = 0; // 18
Expand All @@ -51,6 +53,7 @@ class Instance {
cdc::MeshComponent meshComponent {this}; // 218

cdc::IDrawable *instanceDrawable = nullptr; // 23C
UserDataComponent *userDataComponent = nullptr; // 2E0

bool enableOverridePose = true; // HACK
std::vector<cdc::Matrix> overridePose; // HACK
Expand Down
10 changes: 10 additions & 0 deletions cdcWorld/UserDataComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "UserDataComponent.h"
#include "cdcWorld/Instance.h"

UserDataComponent *UserDataComponent::CreateIfNeeded(Instance *instance) {
if (!instance->userDataComponent) {
auto *udc = new UserDataComponent(instance);
instance->userDataComponent = udc;
}
return instance->userDataComponent;
}
17 changes: 17 additions & 0 deletions cdcWorld/UserDataComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "cdcWorld/InstanceComponent.h"

// namespaced as cdc::InstanceUserData in Tomb Raider
struct InstanceUserData {
// empty
};

// namespaced as cdc::UserDataComponent in Tomb Raider
class UserDataComponent : public InstanceComponent {
public:
Instance *instance;
InstanceUserData *userData;

UserDataComponent(Instance *i) : instance(i), userData(nullptr) {}
static UserDataComponent *CreateIfNeeded(Instance*);
};
12 changes: 7 additions & 5 deletions eventually_generated/cdc/dtp/objectbasedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

namespace cdc {

class AnimGraphRequest;
class ObjectBlobAnim;

}

namespace dtp {

struct AnimGraphRootRef;
struct AnimStateGraph;
struct Model;
struct SoundPlex;

Expand All @@ -25,6 +26,7 @@ struct ObjectBaseData {
uint32_t dword0;
// 20000000 see MeshComponent::SetModel
uint32_t dword4;
// 00004000 has bones
uint32_t dword8;
uint32_t dwordC;
float float10_lod1_distance_maybe;
Expand All @@ -45,10 +47,10 @@ struct ObjectBaseData {
uint16_t word40;
uint16_t word42;
uint32_t dword44;
uint32_t dword48;
cdc::AnimGraphRequest **pAnimGraphReq4C;
uint32_t numAnimGraphs54;
struct { cdc::AnimGraphRequest *req; uint32_t unk4; } *animgraphs54;
uint32_t hasAnimGraph; // 48
dtp::AnimGraphRootRef *pAnimGraph; // 4C
uint32_t numHostedAnimGraphs;
dtp::AnimGraphRootRef *pHostedAnimGraphs;
uint32_t dword58;
uint32_t dword5C;
uint32_t dword60;
Expand Down
22 changes: 22 additions & 0 deletions eventually_generated/cdc/dtp/objecttypes/uberobject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <cstdint>

namespace dtp {

struct UberObjectProp {
struct SectionProp {
uint8_t pad[0x28];
uint8_t modelIndex; // 28
uint8_t pad29[0x2F0-0x29];
};
uint16_t version; // 0
uint16_t family; // 2
uint16_t id; // 4
uint16_t type; // 6
uint32_t numSections; // 8
SectionProp *sectionList; // C
};

static_assert(sizeof(UberObjectProp::SectionProp) == 0x2F0);

}
3 changes: 2 additions & 1 deletion game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ target_sources(dxhr PRIVATE
LensFlareAndCoronaID.cpp
Main.cpp
PackedVector.cpp
objects/objects.cpp)
objects/objects.cpp
objects/UberObject_DX3.cpp)

add_subdirectory(script/game)
add_subdirectory(ui)
13 changes: 13 additions & 0 deletions game/objects/UberObject_DX3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "UberObject_DX3.h"

void UBEROBJECT_DX3_Init(Instance *instance, GameTracker*) {
// TODO
new UberObjectComposite_DX3(instance);
}

UberObjectComposite_DX3::UberObjectComposite_DX3(Instance *instance) :
UberObjectComposite(instance, /*deferSectionInit=*/ true)
{
CreateSections(instance);
}

15 changes: 15 additions & 0 deletions game/objects/UberObject_DX3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include "cdcObjects/UberObject.h"

struct GameTracker;

void UBEROBJECT_DX3_Init(Instance*, GameTracker*);

class UberObjectComposite_DX3 : public UberObjectComposite {
public:
UberObjectComposite_DX3(Instance *instance);
};

class UberObjectSection_DX3 : public UberObjectSection {

};

0 comments on commit 9ce5251

Please sign in to comment.