isle-portable/LEGO1/tgl/d3drm/group.cpp
Mark Langen 260772e374
Bootstrap decomp of Tgl rendering library (#293)
* Bootstrap decomp of D3DRM rendering code

* This PR kicks off work on decompiling the D3D Retained Mode (D3DRM)
  rendering part of the codebase.

* High level overview:

* There is a base IMxDirect3DRMObject class which all of the D3DRM
  rendering objects inherit from. Its only virtual method is one to get
  the underlying object handle.

* A hierarchy of abstract classes inherits from this base class, which
  I've called "IMxDirect3DRM<class>". These classes only have pure
  virtual methods on them and don't contain any data.

* Each one of the abstract classes has exactly one concrete
  implementation, which I've called "MxDirect3DRM<class>". These classes
  have exactly one piece of data, which is a pointer to the underlying
  D3D Retained Mode object.

* If the classes need to store additional data, they store it in a
  userdata blob which is attached to the D3DRM object rather than the
  additional data being stored in the class itself.

* I've worked out about twice this many classes related to D3DRM
  rendering so far but the PR was getting large enough as is, so I'm
  cutting it here for now.

* I decomped sufficiently many methods of these classe to convince
  myself that the above observations are correct. About 60% of the
  decomped methods here are perfect matches, including at least one
  non-trivial method per class.

* Formatting

* Restructure changes using Tgl naming / details

* Restructure the changes to use the naming that we know from Tgl.

* Fill in some parts of the implementation I couldn't initially figure
  out using the details from Tgl (got more 100% matches).

* Move d3drm link requirement

* Fixups FloatMatrix -> FloatMatrix4

* Fix order

* Full fix for ordering problems

* Put back accidentally removed include.

* Fix call which should have been Release

* Use new and delete for DeepClone

* Missing Tgl:: on CreateRenderer

* Revert change to bool return value.

* Rename Something -> Unk

* Return paramter naming convention to what Tgl used

* Add scalar ddtor to verify inline destructor

* Fix order

* Change malloc/free -> new/delete in Tgl

* Remove duplicate destructor.

* Check all inline destructors

* Fix dtor comments

* Third time's the charm

* Alphabetical sort

* Decomp adjustments

* Add d3drm files to clang-format

---------

Co-authored-by: Christian Semmler <mail@csemmler.com>
2023-12-07 13:10:42 +01:00

122 lines
3.3 KiB
C++

#include "impl.h"
using namespace TglImpl;
// SYNTHETIC: LEGO1 0x100a2480
// TglImpl::GroupImpl::`scalar deleting destructor'
// FUNCTION: LEGO1 0x100a31d0
void* GroupImpl::ImplementationDataPtr()
{
return reinterpret_cast<void*>(&m_data);
}
// FUNCTION: LEGO1 0x100a31e0
Result GroupImpl::SetTransformation(const FloatMatrix4& matrix)
{
D3DRMMATRIX4D helper;
D3DRMMATRIX4D* d3dMatrix = Translate(matrix, helper);
return ResultVal(m_data->AddTransform(D3DRMCOMBINE_REPLACE, *d3dMatrix));
}
// FUNCTION: LEGO1 0x100a3240
Result GroupImpl::SetColor(float r, float g, float b, float a)
{
// The first instruction makes no sense here:
// cmp dword ptr [esp + 0x10], 0
// This compares a, which we know is a float because it immediately
// gets passed into D3DRMCreateColorRGBA, but does the comparison
// as though it's an int??
if (*reinterpret_cast<int*>(&a) > 0) {
D3DCOLOR color = D3DRMCreateColorRGBA(r, g, b, a);
return ResultVal(m_data->SetColor(color));
}
else {
return ResultVal(m_data->SetColorRGB(r, a, b));
}
}
// FUNCTION: LEGO1 0x100a32b0
Result GroupImpl::SetTexture(const Texture* pTexture)
{
IDirect3DRMTexture* pD3DTexture = pTexture ? static_cast<const TextureImpl*>(pTexture)->ImplementationData() : NULL;
return ResultVal(m_data->SetTexture(pD3DTexture));
}
// FUNCTION: LEGO1 0x100a32e0
Result GroupImpl::GetTexture(Texture*& pTexture)
{
IDirect3DRMTexture* pD3DTexture;
TextureImpl* holder = new TextureImpl();
Result result = ResultVal(m_data->GetTexture(&pD3DTexture));
if (result) {
// Seems to actually call the first virtual method of holder here
// but that doesn't make any sense since it passes three arguments
// to the method (self + string constant? + an offset?).
// This line makes the start of the function match and is what I
// would expect to see there but it clearly isn't what's actually
// there.
holder->SetImplementation(pD3DTexture);
}
pTexture = holder;
return Success;
}
// FUNCTION: LEGO1 0x100a33c0
Result GroupImpl::SetMaterialMode(MaterialMode mode)
{
D3DRMMATERIALMODE d3dMode;
switch (mode) {
case FromParent:
d3dMode = D3DRMMATERIAL_FROMPARENT;
break;
case FromFrame:
d3dMode = D3DRMMATERIAL_FROMFRAME;
break;
case FromMesh:
d3dMode = D3DRMMATERIAL_FROMMESH;
break;
}
return ResultVal(m_data->SetMaterialMode(d3dMode));
}
// 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)
{
const GroupImpl* pGroupImpl = static_cast<const GroupImpl*>(pGroup);
return ResultVal(m_data->AddVisual(pGroupImpl->m_data));
}
// FUNCTION: LEGO1 0x100a3450
Result GroupImpl::Remove(const Group* pGroup)
{
const GroupImpl* pGroupImpl = static_cast<const GroupImpl*>(pGroup);
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));
}
// FUNCTION: LEGO1 0x100a34b0 STUB
Result GroupImpl::RemoveAll()
{
return Error;
}
// FUNCTION: LEGO1 0x100a34c0 STUB
Result GroupImpl::Unknown()
{
return Error;
}