Implement LegoLOD::Read and related (#634)

* WIP

* Fix

* Remove bogus

* Fix

* Match

* Fix

* Remove TODO
This commit is contained in:
Christian Semmler
2024-03-07 14:57:17 -05:00
committed by GitHub
parent a12146f52f
commit 53e2353f78
16 changed files with 652 additions and 126 deletions

View File

@@ -0,0 +1,91 @@
#include "legomesh.h"
#include "misc/legostorage.h"
DECOMP_SIZE_ASSERT(LegoMeshUnkComponent, 0x1c)
DECOMP_SIZE_ASSERT(LegoMesh, 0x24)
// FUNCTION: LEGO1 0x100d3810
LegoMesh::LegoMesh()
{
m_alpha = 0.0F;
m_shading = e_flat;
m_unk0x14 = 0;
m_textureName = NULL;
m_unk0x0d = 0;
m_unk0x10 = NULL;
m_unk0x20 = 0;
m_unk0x21 = FALSE;
m_materialName = NULL;
}
// FUNCTION: LEGO1 0x100d3860
LegoMesh::~LegoMesh()
{
if (m_textureName != NULL) {
delete[] m_textureName;
}
if (m_materialName != NULL) {
delete[] m_materialName;
}
if (m_unk0x10 != NULL) {
delete m_unk0x10;
}
}
// FUNCTION: LEGO1 0x100d38f0
LegoResult LegoMesh::Read(LegoStorage* p_storage)
{
LegoResult result;
LegoU32 textureLength, materialLength;
if ((result = m_color.Read(p_storage)) != SUCCESS) {
return result;
}
if ((result = p_storage->Read(&m_alpha, sizeof(m_alpha))) != SUCCESS) {
return result;
}
if ((result = p_storage->Read(&m_shading, sizeof(m_shading))) != SUCCESS) {
return result;
}
if ((result = p_storage->Read(&m_unk0x0d, sizeof(m_unk0x0d))) != SUCCESS) {
return result;
}
if ((result = p_storage->Read(&m_unk0x20, sizeof(m_unk0x20))) != SUCCESS) {
return result;
}
if ((result = p_storage->Read(&m_unk0x21, sizeof(m_unk0x21))) != SUCCESS) {
return result;
}
if ((result = p_storage->Read(&textureLength, sizeof(textureLength))) != SUCCESS) {
return result;
}
if (textureLength) {
m_textureName = new LegoChar[textureLength + 1];
if ((result = p_storage->Read(m_textureName, textureLength)) != SUCCESS) {
return result;
}
m_textureName[textureLength] = '\0';
strlwr(m_textureName);
}
if ((result = p_storage->Read(&materialLength, sizeof(materialLength))) != SUCCESS) {
return result;
}
if (materialLength) {
m_materialName = new LegoChar[materialLength + 1];
if ((result = p_storage->Read(m_materialName, materialLength)) != SUCCESS) {
return result;
}
m_materialName[materialLength] = '\0';
strlwr(m_materialName);
}
return SUCCESS;
}

View File

@@ -0,0 +1,78 @@
#ifndef __LEGOMESH_H
#define __LEGOMESH_H
#include "decomp.h"
#include "misc/legocolor.h"
#include "misc/legotypes.h"
class LegoStorage;
// SIZE 0x1c
struct LegoMeshUnkComponent {
~LegoMeshUnkComponent()
{
if (m_unk0x08) {
delete m_unk0x08;
}
if (m_unk0x0c) {
delete m_unk0x0c;
}
if (m_unk0x10) {
delete m_unk0x10;
}
if (m_unk0x14) {
delete m_unk0x14;
}
if (m_unk0x18) {
delete m_unk0x18;
}
}
undefined m_unk0x00[8]; // 0x00
undefined* m_unk0x08; // 0x08
undefined* m_unk0x0c; // 0x0c
undefined* m_unk0x10; // 0x10
undefined* m_unk0x14; // 0x14
undefined* m_unk0x18; // 0x18
};
// VTABLE: LEGO1 0x100dd228
// SIZE 0x24
class LegoMesh {
public:
enum {
e_flat,
e_gouraud,
e_wireframe
};
LegoMesh();
virtual ~LegoMesh();
LegoColor GetColor() { return m_color; }
void SetColor(LegoColor p_color) { m_color = p_color; }
LegoFloat GetAlpha() { return m_alpha; }
LegoU8 GetShading() { return m_shading; }
void SetShading(LegoU8 p_shading) { m_shading = p_shading; }
LegoU8 GetUnknown0x0d() { return m_unk0x0d; }
const LegoChar* GetTextureName() { return m_textureName; }
const LegoChar* GetMaterialName() { return m_materialName; }
LegoBool GetUnknown0x21() { return m_unk0x21; }
LegoResult Read(LegoStorage* p_storage);
// SYNTHETIC: LEGO1 0x100d3840
// LegoMesh::`scalar deleting destructor'
protected:
LegoColor m_color; // 0x04
LegoFloat m_alpha; // 0x08
LegoU8 m_shading; // 0x0c
LegoU8 m_unk0x0d; // 0x0d
LegoMeshUnkComponent* m_unk0x10; // 0x10 - unused, except in destructor
undefined4 m_unk0x14; // 0x14 - unused
LegoChar* m_textureName; // 0x18
LegoChar* m_materialName; // 0x1c
undefined m_unk0x20; // 0x20 - unused
LegoBool m_unk0x21; // 0x21
};
#endif // __LEGOMESH_H