More CModel RE

This commit is contained in:
Phillip Stephens 2022-02-01 01:18:42 -08:00
parent 3ba2c4bfff
commit 05f841a5ce
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
2 changed files with 105 additions and 22 deletions

View File

@ -3,6 +3,9 @@
#include "CGraphics.hpp"
namespace metaforce {
#pragma region CModel
u32 CModel::sTotalMemory = 0;
u32 CModel::sFrameCounter = 0;
bool CModel::sIsTextureTimeoutEnabled = true;
CModel* CModel::sThisFrameList = nullptr;
@ -20,9 +23,12 @@ static const u8* MemoryFromPartData(const u8*& dataCur, const u32*& secSizeCur)
}
CModel::CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store)
: x0_data(std::move(in)), x4_dataLen(dataLen), x34_next(sThisFrameList), x38_lastFrame(CGraphics::GetFrameCounter() - 2) {
: x0_data(std::move(in))
, x4_dataLen(dataLen)
, x34_next(sThisFrameList)
, x38_lastFrame(CGraphics::GetFrameCounter() - 2) {
const u8* data = reinterpret_cast<const u8*>(x0_data.get());
u32 uVar1 = *reinterpret_cast<const u32*>(data + 8);
u32 flags = *reinterpret_cast<const u32*>(data + 8);
u32 sectionSizeStart = 0x2c;
if (hecl::SBig(*reinterpret_cast<const u32*>(data + 4)) == 1) {
sectionSizeStart = 0x28;
@ -32,29 +38,60 @@ CModel::CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store)
if (hecl::SBig(*reinterpret_cast<const u32*>(data + 4)) > 1) {
numMatSets = hecl::SBig(*reinterpret_cast<const s32*>(data + 0x28));
}
const auto* dataCur = data + ROUND_UP_32(sectionSizeStart + hecl::SBig(*reinterpret_cast<const s32*>(data + 0x24)) * 4);
const u8* dataCur = data + ROUND_UP_32(sectionSizeStart + hecl::SBig(*reinterpret_cast<const s32*>(data + 0x24)) * 4);
x18_matSets.reserve(numMatSets);
for (s32 i = 0; i < numMatSets; ++i) {
x18_matSets.emplace_back(static_cast<const u8*>(MemoryFromPartData(dataCur, secSizeCur)));
auto shader = x18_matSets.back();
CCubeModel::MakeTexturesFromMats(shader.x10_data, shader.x0_textures, true);
x4_dataLen += shader.x0_textures.size() * sizeof(TCachedToken<CTexture>);
}
const u8* positions = MemoryFromPartData(dataCur, secSizeCur);
const u8* normals = MemoryFromPartData(dataCur, secSizeCur);
const u8* vtxColors = MemoryFromPartData(dataCur, secSizeCur);
const u8* floatUVs = MemoryFromPartData(dataCur, secSizeCur);
const u8* shortUVs = nullptr;
if (((flags >> 2) & 1) != 0) {
shortUVs = MemoryFromPartData(dataCur, secSizeCur);
}
const u8* surfaceInfo = MemoryFromPartData(dataCur, secSizeCur);
u32 surfaceCount = hecl::SBig(*reinterpret_cast<const u32*>(surfaceInfo));
x8_surfaces.reserve(surfaceCount);
for (u32 i = 0; i < surfaceCount; ++i) {
// Implement CCubeSurface loading taking into account endian
}
// TODO: need to endian swap the values
const auto* aabox = reinterpret_cast<const zeus::CAABox*>(data + 12);
x28_modelInst =
std::make_unique<CCubeModel>(&x8_surfaces, &x18_matSets[0].x0_textures, x18_matSets[0].x10_data, positions,
normals, vtxColors, floatUVs, shortUVs, aabox, flags, true, -1);
sThisFrameList = this;
if (x34_next != nullptr) {
x34_next->x30_prev = this;
}
x4_dataLen += x8_surfaces.size() * 4;
sTotalMemory += x4_dataLen;
// DCFlushRange(x0_data, dataLen);
}
void CModel::UpdateLastFrame() { x38_lastFrame = CGraphics::GetFrameCounter(); }
void CModel::MoveToThisFrameList() {
UpdateLastFrame();
CModel* ptr = sThisFrameList;
if (sThisFrameList != this) {
RemoveFromList();
if (sThisFrameList == this) {
return;
}
if (sThisFrameList != nullptr) {
x34_next = sThisFrameList;
x34_next->x30_prev = this;
}
ptr = this;
}
sThisFrameList = ptr;
sThisFrameList = this;
}
void CModel::RemoveFromList() {
@ -101,4 +138,14 @@ void CModel::FrameDone() {
void CModel::EnableTextureTimeout() { sIsTextureTimeoutEnabled = true; }
void CModel::DisableTextureTimeout() { sIsTextureTimeoutEnabled = false; }
#pragma endregion
#pragma region CCubeModel
void CCubeModel::UnlockTextures() {}
void CCubeModel::MakeTexturesFromMats(const u8* ptr, std::vector<TCachedToken<CTexture>>& texture, bool b1) {}
#pragma endregion
} // namespace metaforce

View File

@ -10,25 +10,22 @@
namespace metaforce {
class CCubeSurface;
class CCubeModel {
public:
void UnlockTextures() {}
static void MakeTexturesFromMats(const u8* ptr, std::vector<TCachedToken<CTexture>>& texture, bool b1) {}
};
class CCubeModel;
#pragma region CModel
class CModel {
public:
struct SShader {
std::vector<TCachedToken<CTexture>> x0_textures;
const u8* x10_data;
SShader(const u8* data) : x10_data(data) {}
explicit SShader(const u8* data) : x10_data(data) {}
void UnlockTextures(){};
};
private:
static u32 sTotalMemory;
static u32 sFrameCounter;
static bool sIsTextureTimeoutEnabled;
static CModel* sThisFrameList;
@ -39,7 +36,7 @@ private:
u32 x4_dataLen;
std::vector<CCubeSurface*> x8_surfaces;
std::vector<SShader> x18_matSets;
CCubeModel* x28_modelInst = nullptr;
std::unique_ptr<CCubeModel> x28_modelInst = nullptr;
u16 x2c_ = 0;
u16 x2e_ = 0;
CModel* x30_prev = nullptr;
@ -57,4 +54,43 @@ public:
static void EnableTextureTimeout();
static void DisableTextureTimeout();
};
#pragma endregion
#pragma region CCubeModel
class CCubeModel {
public:
CCubeModel(const std::vector<CCubeSurface*>* surfaces, const std::vector<TCachedToken<CTexture>>* textures,
const u8* materialData, const u8* positions, const u8* normals, const u8* vtxColors, const u8* floatUvs,
const u8* shortUVs, const zeus::CAABox* aabox, u8 flags, bool b1, u32 w1) {}
void UnlockTextures();
static void MakeTexturesFromMats(const u8* ptr, std::vector<TCachedToken<CTexture>>& texture, bool b1);
};
#pragma endregion
#pragma region CCubeSurface
class CCubeSurface {
public:
enum class ECookie {
};
public:
bool IsValid() const;
static CCubeSurface* FromCookieValue(u32);
void GetCookie(ECookie cookie);
void SetCookie(ECookie cookie, u32 value);
u32 GetCookieValue() const;
s32 GetMaterialIndex() const;
s32 GetDisplayListSize() const;
u8* GetDisplayList() const;
u32 GetSurfaceHeaderSize() const;
zeus::CVector3f GetCenter() const;
u32 GetNormalHint() const;
zeus::CAABox GetBounds() const;
};
#pragma endregion
} // namespace metaforce