Bootstrap LegoLOD, implement/match ViewManager::FUN_100a66a0 (#625)

* Bootstrap LegoLOD, implement/match ViewManager::FUN_100a66a0

* Fixes

* Try fix

* Try this

* Fix
This commit is contained in:
Christian Semmler 2024-03-04 16:57:35 -05:00 committed by GitHub
parent b8aa16ff80
commit c9210c02fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 169 additions and 41 deletions

View file

@ -117,6 +117,7 @@ target_include_directories(realtime PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1" "${CMAKE
target_link_libraries(realtime PRIVATE Vec::Vec) target_link_libraries(realtime PRIVATE Vec::Vec)
add_library(viewmanager STATIC add_library(viewmanager STATIC
LEGO1/viewmanager/viewlod.cpp
LEGO1/viewmanager/viewlodlist.cpp LEGO1/viewmanager/viewlodlist.cpp
LEGO1/viewmanager/viewmanager.cpp LEGO1/viewmanager/viewmanager.cpp
LEGO1/viewmanager/viewroi.cpp LEGO1/viewmanager/viewroi.cpp
@ -141,7 +142,7 @@ add_library(roi STATIC
register_lego1_target(roi) register_lego1_target(roi)
set_property(TARGET roi PROPERTY ARCHIVE_OUTPUT_NAME "roi$<$<CONFIG:Debug>:d>") set_property(TARGET roi PROPERTY ARCHIVE_OUTPUT_NAME "roi$<$<CONFIG:Debug>:d>")
target_include_directories(roi PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1" "${CMAKE_SOURCE_DIR}/LEGO1/lego/sources" "${CMAKE_SOURCE_DIR}/util") target_include_directories(roi PRIVATE "${CMAKE_SOURCE_DIR}/LEGO1" "${CMAKE_SOURCE_DIR}/LEGO1/lego/sources" "${CMAKE_SOURCE_DIR}/util")
target_link_libraries(roi PRIVATE) target_link_libraries(roi PRIVATE viewmanager)
add_library(anim STATIC add_library(anim STATIC
LEGO1/lego/sources/anim/legoanim.cpp LEGO1/lego/sources/anim/legoanim.cpp

View file

@ -331,11 +331,11 @@ MxResult LegoWorldPresenter::FUN_10067360(ModelDbPart& p_part, FILE* p_wdbFile)
chunk.SetLength(p_part.m_partDataLength); chunk.SetLength(p_part.m_partDataLength);
chunk.SetData(buff); chunk.SetData(buff);
LegoPartPresenter part; LegoPartPresenter partPresenter;
result = part.Read(chunk); result = partPresenter.Read(chunk);
if (result == SUCCESS) { if (result == SUCCESS) {
part.FUN_1007df20(); partPresenter.FUN_1007df20();
} }
delete[] buff; delete[] buff;

View file

@ -1,9 +1,16 @@
#include "legoroi.h" #include "legoroi.h"
#include "tgl/d3drm/impl.h"
#include <string.h> #include <string.h>
DECOMP_SIZE_ASSERT(LegoROI, 0x108) DECOMP_SIZE_ASSERT(LegoROI, 0x108)
DECOMP_SIZE_ASSERT(TimeROI, 0x10c) DECOMP_SIZE_ASSERT(TimeROI, 0x10c)
DECOMP_SIZE_ASSERT(LODObject, 0x04)
DECOMP_SIZE_ASSERT(ViewLOD, 0x0c)
DECOMP_SIZE_ASSERT(LegoLOD, 0x20)
inline IDirect3DRM2* GetD3DRM(Tgl::Renderer* pRenderer);
// SIZE 0x14 // SIZE 0x14
typedef struct { typedef struct {
@ -38,6 +45,9 @@ int g_roiConfig = 100;
// GLOBAL: LEGO1 0x101013ac // GLOBAL: LEGO1 0x101013ac
ROIHandler g_someHandlerFunction = NULL; ROIHandler g_someHandlerFunction = NULL;
// GLOBAL: LEGO1 0x101013d4
LPDIRECT3DRMMATERIAL g_unk0x101013d4 = NULL;
// FUNCTION: LEGO1 0x100a81c0 // FUNCTION: LEGO1 0x100a81c0
void LegoROI::configureLegoROI(int p_roiConfig) void LegoROI::configureLegoROI(int p_roiConfig)
{ {
@ -99,7 +109,7 @@ LegoResult LegoROI::SetFrame(LegoAnim* p_anim, LegoTime p_time)
} }
// FUNCTION: LEGO1 0x100a9a50 // FUNCTION: LEGO1 0x100a9a50
TimeROI::TimeROI(Tgl::Renderer* p_renderer, ViewLODList* p_lodList, int p_time) : LegoROI(p_renderer, p_lodList) TimeROI::TimeROI(Tgl::Renderer* p_renderer, ViewLODList* p_lodList, LegoTime p_time) : LegoROI(p_renderer, p_lodList)
{ {
m_time = p_time; m_time = p_time;
} }
@ -171,3 +181,28 @@ void LegoROI::UpdateWorldBoundingVolumes()
{ {
// TODO // TODO
} }
// FUNCTION: LEGO1 0x100aa380
LegoLOD::LegoLOD(Tgl::Renderer* p_renderer) : ViewLOD(p_renderer)
{
if (g_unk0x101013d4 == NULL) {
GetD3DRM(p_renderer)->CreateMaterial(10.0, &g_unk0x101013d4);
}
m_unk0x0c = 0;
m_unk0x10 = 0;
m_unk0x14 = 0;
m_numPolys = 0;
m_unk0x1c = 0;
}
// STUB: LEGO1 0x100aa450
LegoLOD::~LegoLOD()
{
// TODO
}
inline IDirect3DRM2* GetD3DRM(Tgl::Renderer* pRenderer)
{
return ((TglImpl::RendererImpl*) pRenderer)->ImplementationData();
}

View file

@ -2,6 +2,7 @@
#define LEGOROI_H #define LEGOROI_H
#include "misc/legotypes.h" #include "misc/legotypes.h"
#include "viewmanager/viewlod.h"
#include "viewmanager/viewroi.h" #include "viewmanager/viewroi.h"
typedef unsigned char (*ROIHandler)(char*, char*, unsigned int); typedef unsigned char (*ROIHandler)(char*, char*, unsigned int);
@ -11,6 +12,31 @@ class LegoTextureContainer;
class LegoStorage; class LegoStorage;
class LegoAnim; class LegoAnim;
// VTABLE: LEGO1 0x100dbf10
// SIZE 0x20
class LegoLOD : public ViewLOD {
public:
LegoLOD(Tgl::Renderer*);
~LegoLOD() override;
// FUNCTION: LEGO1 0x100aae70
int NumPolys() const override { return m_numPolys; } // vtable+0x0c
// FUNCTION: LEGO1 0x100aae80
float VTable0x10() override { return 0.0; } // vtable+0x10
// SYNTHETIC: LEGO1 0x100aa430
// LegoLOD::`scalar deleting destructor'
protected:
// TODO: Review 1996 version
undefined4 m_unk0x0c; // 0x0c
undefined4 m_unk0x10; // 0x10
undefined4 m_unk0x14; // 0x14
LegoU32 m_numPolys; // 0x18
undefined4 m_unk0x1c; // 0x1c
};
// VTABLE: LEGO1 0x100dbe38 // VTABLE: LEGO1 0x100dbe38
// SIZE 0x108 // SIZE 0x108
class LegoROI : public ViewROI { class LegoROI : public ViewROI {
@ -44,7 +70,7 @@ class LegoROI : public ViewROI {
); );
static unsigned char ColorAliasLookup(char* p_param, float& p_red, float& p_green, float& p_blue, float& p_other); static unsigned char ColorAliasLookup(char* p_param, float& p_red, float& p_green, float& p_blue, float& p_other);
inline const char* GetName() const { return m_name; } inline const LegoChar* GetName() const { return m_name; }
inline LegoEntity* GetUnknown0x104() { return m_unk0x104; } inline LegoEntity* GetUnknown0x104() { return m_unk0x104; }
inline void SetUnknown0x104(LegoEntity* p_unk0x104) { m_unk0x104 = p_unk0x104; } inline void SetUnknown0x104(LegoEntity* p_unk0x104) { m_unk0x104 = p_unk0x104; }
@ -63,13 +89,13 @@ class LegoROI : public ViewROI {
// SIZE 0x10c // SIZE 0x10c
class TimeROI : public LegoROI { class TimeROI : public LegoROI {
public: public:
TimeROI(Tgl::Renderer* p_renderer, ViewLODList* p_lodList, int p_time); TimeROI(Tgl::Renderer* p_renderer, ViewLODList* p_lodList, LegoTime p_time);
// SYNTHETIC: LEGO1 0x100a9ad0 // SYNTHETIC: LEGO1 0x100a9ad0
// TimeROI::`scalar deleting destructor' // TimeROI::`scalar deleting destructor'
private: private:
int m_time; // 0x108 LegoTime m_time; // 0x108
}; };
#endif // LEGOROI_H #endif // LEGOROI_H

View file

@ -45,13 +45,22 @@ class BoundingSphere {
* Abstract base class representing a single LOD version of * Abstract base class representing a single LOD version of
* a geometric object. * a geometric object.
*/ */
// VTABLE: LEGO1 0x100dbd90
// SIZE 0x04
class LODObject { class LODObject {
public: public:
// LODObject(); // LODObject();
// FUNCTION: LEGO1 0x100a6f00
virtual ~LODObject() {} virtual ~LODObject() {}
virtual float Cost(float pixels_covered) const = 0; // vtable+0x04
virtual float AveragePolyArea() const = 0; // vtable+0x08 virtual double AveragePolyArea() const = 0; // vtable+0x04
virtual int NVerts() const = 0; // vtable+0x0c virtual int NVerts() const = 0; // vtable+0x08
virtual int NumPolys() const = 0; // vtable+0x0c
virtual float VTable0x10() = 0; // vtable+0x10
// SYNTHETIC: LEGO1 0x100a6f10
// LODObject::`scalar deleting destructor'
}; };
/* /*

View file

@ -79,33 +79,35 @@ Result GroupImpl::SetMaterialMode(MaterialMode mode)
} }
// FUNCTION: LEGO1 0x100a3410 // FUNCTION: LEGO1 0x100a3410
Result GroupImpl::Add(const Mesh* pMesh)
{
const MeshImpl* pMeshImpl = static_cast<const MeshImpl*>(pMesh);
return ResultVal(m_data->AddVisual(pMeshImpl->ImplementationData()->groupMesh));
}
// FUNCTION: LEGO1 0x100a3430
Result GroupImpl::Add(const Group* pGroup) Result GroupImpl::Add(const Group* pGroup)
{ {
const GroupImpl* pGroupImpl = static_cast<const GroupImpl*>(pGroup); const GroupImpl* pGroupImpl = static_cast<const GroupImpl*>(pGroup);
return ResultVal(m_data->AddVisual(pGroupImpl->m_data)); return ResultVal(m_data->AddVisual(pGroupImpl->m_data));
} }
// FUNCTION: LEGO1 0x100a3430
Result GroupImpl::Add(const Mesh* pMesh)
{
const MeshImpl* pMeshImpl = static_cast<const MeshImpl*>(pMesh);
// TODO: Incorrect structure
return ResultVal(m_data->AddVisual((IDirect3DRMMesh*) pMeshImpl->ImplementationData()));
}
// FUNCTION: LEGO1 0x100a3450 // FUNCTION: LEGO1 0x100a3450
Result GroupImpl::Remove(const Mesh* pMesh)
{
const MeshImpl* pMeshImpl = static_cast<const MeshImpl*>(pMesh);
// TODO: Incorrect structure
return ResultVal(m_data->DeleteVisual((IDirect3DRMMesh*) pMeshImpl->ImplementationData()));
}
// FUNCTION: LEGO1 0x100a3480
Result GroupImpl::Remove(const Group* pGroup) Result GroupImpl::Remove(const Group* pGroup)
{ {
const GroupImpl* pGroupImpl = static_cast<const GroupImpl*>(pGroup); const GroupImpl* pGroupImpl = static_cast<const GroupImpl*>(pGroup);
return ResultVal(m_data->DeleteVisual(pGroupImpl->m_data)); return ResultVal(m_data->DeleteVisual(pGroupImpl->m_data));
} }
// FUNCTION: LEGO1 0x100a3480
Result GroupImpl::Remove(const Mesh* pMesh)
{
const MeshImpl* pMeshImpl = static_cast<const MeshImpl*>(pMesh);
return ResultVal(m_data->DeleteVisual(pMeshImpl->ImplementationData()->groupMesh));
}
// STUB: LEGO1 0x100a34b0 // STUB: LEGO1 0x100a34b0
Result GroupImpl::RemoveAll() Result GroupImpl::RemoveAll()
{ {

View file

@ -315,12 +315,12 @@ class GroupImpl : public Group {
Result SetTexture(const Texture*) override; Result SetTexture(const Texture*) override;
Result GetTexture(Texture*&) override; Result GetTexture(Texture*&) override;
Result SetMaterialMode(MaterialMode) override; Result SetMaterialMode(MaterialMode) override;
Result Add(const Mesh*) override; Result Add(const Group*) override;
// vtable+0x20 // vtable+0x20
Result Add(const Group*) override; Result Add(const Mesh*) override;
Result Remove(const Mesh*) override;
Result Remove(const Group*) override; Result Remove(const Group*) override;
Result Remove(const Mesh*) override;
Result RemoveAll() override; Result RemoveAll() override;
// vtable+0x30 // vtable+0x30

View file

@ -294,10 +294,10 @@ class Group : public Object {
virtual Result SetTexture(const Texture*) = 0; virtual Result SetTexture(const Texture*) = 0;
virtual Result GetTexture(Texture*&) = 0; virtual Result GetTexture(Texture*&) = 0;
virtual Result SetMaterialMode(MaterialMode) = 0; virtual Result SetMaterialMode(MaterialMode) = 0;
virtual Result Add(const Mesh*) = 0;
virtual Result Add(const Group*) = 0; virtual Result Add(const Group*) = 0;
virtual Result Remove(const Mesh*) = 0; virtual Result Add(const Mesh*) = 0;
virtual Result Remove(const Group*) = 0; virtual Result Remove(const Group*) = 0;
virtual Result Remove(const Mesh*) = 0;
virtual Result RemoveAll() = 0; virtual Result RemoveAll() = 0;
// This is TransformLocalToWorld in the leak, however it seems // This is TransformLocalToWorld in the leak, however it seems

View file

@ -0,0 +1,7 @@
#include "viewlod.h"
// FUNCTION: LEGO1 0x100a5e40
ViewLOD::~ViewLOD()
{
delete m_meshGroup;
}

View file

@ -0,0 +1,32 @@
#include "decomp.h"
#include "realtime/roi.h"
#include "tgl/tgl.h"
//////////////////////////////////////////////////////////////////////////////
// ViewLOD
//
// VTABLE: LEGO1 0x100dbd70
// SIZE 0x0c
class ViewLOD : public LODObject {
public:
ViewLOD(Tgl::Renderer* pRenderer) : m_meshGroup(NULL), m_unk0x08(3) {}
~ViewLOD() override;
// FUNCTION: LEGO1 0x100a6f30
double AveragePolyArea() const override { return 2 * 3.14159 * 10.0 / NumPolys(); } // vtable+0x04
// FUNCTION: LEGO1 0x100a6f50
int NVerts() const override { return NumPolys() * 2; } // vtable+0x08
Tgl::Group* GetGeometry() { return m_meshGroup; }
const Tgl::Group* GetGeometry() const { return m_meshGroup; }
// SYNTHETIC: LEGO1 0x100a6f60
// ViewLOD::`scalar deleting destructor'
protected:
// TODO: m_meshGroup unconfirmed (based on 1996)
Tgl::Group* m_meshGroup; // 0x04
undefined4 m_unk0x08; // 0x08
};

View file

@ -1,11 +1,12 @@
#include "viewmanager.h" #include "viewmanager.h"
#include "tgl/d3drm/impl.h" #include "tgl/d3drm/impl.h"
#include "viewlod.h"
DECOMP_SIZE_ASSERT(ViewManager, 0x1bc) DECOMP_SIZE_ASSERT(ViewManager, 0x1bc)
inline undefined4 SetD3DRM(IDirect3DRM2*& d3drm, Tgl::Renderer* pRenderer); inline undefined4 GetD3DRM(IDirect3DRM2*& d3drm, Tgl::Renderer* pRenderer);
inline undefined4 SetFrame(IDirect3DRMFrame2*& frame, Tgl::Group* scene); inline undefined4 GetFrame(IDirect3DRMFrame2*& frame, Tgl::Group* scene);
// FUNCTION: LEGO1 0x100a5eb0 // FUNCTION: LEGO1 0x100a5eb0
ViewManager::ViewManager(Tgl::Renderer* pRenderer, Tgl::Group* scene, const OrientableROI* point_of_view) ViewManager::ViewManager(Tgl::Renderer* pRenderer, Tgl::Group* scene, const OrientableROI* point_of_view)
@ -13,8 +14,8 @@ ViewManager::ViewManager(Tgl::Renderer* pRenderer, Tgl::Group* scene, const Orie
{ {
SetPOVSource(point_of_view); SetPOVSource(point_of_view);
unk0x28 = 0.09; unk0x28 = 0.09;
SetD3DRM(d3drm, pRenderer); GetD3DRM(d3drm, pRenderer);
SetFrame(frame, scene); GetFrame(frame, scene);
width = 0.0; width = 0.0;
height = 0.0; height = 0.0;
view_angle = 0.0; view_angle = 0.0;
@ -86,10 +87,25 @@ void ViewManager::RemoveAll(ViewROI* p_roi)
} }
} }
// STUB: LEGO1 0x100a66a0 // FUNCTION: LEGO1 0x100a66a0
void ViewManager::FUN_100a66a0(ViewROI* p_roi) void ViewManager::FUN_100a66a0(ViewROI* p_roi)
{ {
// TODO const ViewLOD* lod = (const ViewLOD*) p_roi->GetLOD(p_roi->GetUnknown0xe0());
if (lod != NULL) {
const Tgl::Mesh* meshGroup = NULL;
Tgl::Group* roiGeometry = p_roi->GetGeometry();
meshGroup = (const Tgl::Mesh*) lod->GetGeometry();
if (meshGroup != NULL) {
roiGeometry->Remove(meshGroup);
}
scene->Remove(roiGeometry);
}
p_roi->SetUnknown0xe0(-1);
} }
// STUB: LEGO1 0x100a6930 // STUB: LEGO1 0x100a6930
@ -131,13 +147,13 @@ ViewROI* ViewManager::Pick(Tgl::View* p_view, unsigned long x, unsigned long y)
return NULL; return NULL;
} }
inline undefined4 SetD3DRM(IDirect3DRM2*& d3drm, Tgl::Renderer* pRenderer) inline undefined4 GetD3DRM(IDirect3DRM2*& d3drm, Tgl::Renderer* pRenderer)
{ {
d3drm = ((TglImpl::RendererImpl*) pRenderer)->ImplementationData(); d3drm = ((TglImpl::RendererImpl*) pRenderer)->ImplementationData();
return 0; return 0;
} }
inline undefined4 SetFrame(IDirect3DRMFrame2*& frame, Tgl::Group* scene) inline undefined4 GetFrame(IDirect3DRMFrame2*& frame, Tgl::Group* scene)
{ {
frame = ((TglImpl::GroupImpl*) scene)->ImplementationData(); frame = ((TglImpl::GroupImpl*) scene)->ImplementationData();
return 0; return 0;

View file

@ -16,13 +16,13 @@ float ViewROI::IntrinsicImportance() const
} // for now } // for now
// FUNCTION: LEGO1 0x100a9ec0 // FUNCTION: LEGO1 0x100a9ec0
const Tgl::Group* ViewROI::GetGeometry() const Tgl::Group* ViewROI::GetGeometry()
{ {
return geometry; return geometry;
} }
// FUNCTION: LEGO1 0x100a9ed0 // FUNCTION: LEGO1 0x100a9ed0
Tgl::Group* ViewROI::GetGeometry() const Tgl::Group* ViewROI::GetGeometry() const
{ {
return geometry; return geometry;
} }

View file

@ -53,8 +53,8 @@ class ViewROI : public OrientableROI {
void VTable0x1c() override; // vtable+0x1c void VTable0x1c() override; // vtable+0x1c
void SetLocalTransform(const Matrix4& p_transform) override; // vtable+0x20 void SetLocalTransform(const Matrix4& p_transform) override; // vtable+0x20
void VTable0x24(const Matrix4& p_transform) override; // vtable+0x24 void VTable0x24(const Matrix4& p_transform) override; // vtable+0x24
virtual const Tgl::Group* GetGeometry() const; // vtable+0x34
virtual Tgl::Group* GetGeometry(); // vtable+0x30 virtual Tgl::Group* GetGeometry(); // vtable+0x30
virtual const Tgl::Group* GetGeometry() const; // vtable+0x34
inline int GetUnknown0xe0() { return m_unk0xe0; } inline int GetUnknown0xe0() { return m_unk0xe0; }
inline void SetUnknown0xe0(int p_unk0xe0) { m_unk0xe0 = p_unk0xe0; } inline void SetUnknown0xe0(int p_unk0xe0) { m_unk0xe0 = p_unk0xe0; }