Rough outline for LightTextureManager

This commit is contained in:
robojumper
2025-03-16 15:37:19 +01:00
parent f622030c71
commit 4eba49d9f8
8 changed files with 215 additions and 25 deletions
+1
View File
@@ -2256,6 +2256,7 @@ egg/gfx/eggLightTexture.cpp:
egg/gfx/eggLightTextureMgr.cpp:
.text start:0x804AD450 end:0x804AE644
.data start:0x8056F0F0 end:0x8056F110
egg/gfx/eggModelEx.cpp:
.text start:0x804AE650 end:0x804AEC20
+5 -5
View File
@@ -26665,8 +26665,8 @@ __sinit_\eggLightTexture_cpp = .text:0x804AD3C0; // type:function size:0x44 scop
__ct__Q23EGG19LightTextureManagerFPCQ23EGG12LightManager = .text:0x804AD450; // type:function size:0x1AC
__dt__Q23EGG19LightTextureManagerFv = .text:0x804AD600; // type:function size:0x90
createTexture__Q23EGG19LightTextureManagerFPCc = .text:0x804AD690; // type:function size:0x110
EGG__LightTextureManager__createTextureFromBin = .text:0x804AD7A0; // type:function size:0x5C
EGG__LightTextureManager__createTexturesFromBin = .text:0x804AD800; // type:function size:0x6C
createTextureFromBin__Q23EGG19LightTextureManagerFPCv = .text:0x804AD7A0; // type:function size:0x5C
createTexturesFromBin__Q23EGG19LightTextureManagerFPCv = .text:0x804AD800; // type:function size:0x6C
deleteTexture__Q23EGG19LightTextureManagerFi = .text:0x804AD870; // type:function size:0x84
replaceModelTextures__Q23EGG19LightTextureManagerCFQ34nw4r3g3d6ResMdl = .text:0x804AD900; // type:function size:0x84
replaceModelTexture__Q23EGG19LightTextureManagerCFiQ34nw4r3g3d6ResMdl = .text:0x804AD990; // type:function size:0x104
@@ -26677,7 +26677,7 @@ frameReset__Q23EGG19LightTextureManagerFv = .text:0x804ADC40; // type:function s
drawAndCaptureTexture__Q23EGG19LightTextureManagerFffff = .text:0x804ADC80; // type:function size:0x4C8
SetBinaryInner__Q23EGG19LightTextureManagerFRCQ33EGG36IBinary<Q23EGG19LightTextureManager>3Bin = .text:0x804AE150; // type:function size:0x80
GetBinaryInner__Q23EGG19LightTextureManagerCFPQ33EGG36IBinary<Q23EGG19LightTextureManager>3Bin = .text:0x804AE1D0; // type:function size:0x90
getLTEXfromLMAP = .text:0x804AE260; // type:function size:0xDC
getLtexFromLmap__Q23EGG19LightTextureManagerFPCvUs = .text:0x804AE260; // type:function size:0xDC
FUN_804ae340 = .text:0x804AE340; // type:function size:0xBC
GetBinarySize__Q23EGG19LightTextureManagerCFv = .text:0x804AE400; // type:function size:0x8
SetBinaryInner__Q23EGG36IBinary<Q23EGG19LightTextureManager>FRCQ33EGG36IBinary<Q23EGG19LightTextureManager>3BinRCQ33EGG36IBinary<Q23EGG19LightTextureManager>3Binf = .text:0x804AE410; // type:function size:0x4
@@ -37372,7 +37372,7 @@ __vt__Q23EGG8IScnProc = .data:0x8056F058; // type:object size:0x10
EGG__LightManager__vtable = .data:0x8056F068; // type:object size:0x30
EGG__LightObject__vtable = .data:0x8056F098; // type:object size:0x20
__vt__Q23EGG12LightTexture = .data:0x8056F0B8; // type:object size:0x38
EGG__LightTextureManager__vtable = .data:0x8056F0F0; // type:object size:0x20
__vt__Q23EGG19LightTextureManager = .data:0x8056F0F0; // type:object size:0x1C
lbl_8056F110 = .data:0x8056F110; // type:object size:0x10
jumptable_8056F120 = .data:0x8056F120; // type:object size:0x30 scope:local
__vt__Q23EGG14PostEffectBase = .data:0x8056F150; // type:object size:0x1C
@@ -41185,7 +41185,7 @@ lbl_805768A2 = .sbss:0x805768A2; // type:object size:0x2 data:2byte
lbl_805768A4 = .sbss:0x805768A4; // type:object size:0x4 data:4byte
lbl_805768A8 = .sbss:0x805768A8; // type:object size:0x4 data:4byte
lbl_805768AC = .sbss:0x805768AC; // type:object size:0x1 data:byte
lbl_805768B0 = .sbss:0x805768B0; // type:object size:0x2 data:2byte
s_flag__Q23EGG7StateGX = .sbss:0x805768B0; // type:object size:0x2 data:2byte
s_commandFlag__Q23EGG7StateGX = .sbss:0x805768B2; // type:object size:0x6 data:2byte
lbl_805768B8 = .sbss:0x805768B8; // type:object size:0x4 data:4byte
lbl_805768BC = .sbss:0x805768BC; // type:object size:0x4 data:4byte
+14 -8
View File
@@ -12,13 +12,14 @@ class LightTextureManager;
class LightTexture : public CapTexture, public IBinary<LightTexture> {
public:
#pragma pack(push, 1)
struct SubData {
/* 0x00 */ f32 mIntensity;
/* 0x04 */ u8 mGradientUsed;
/* 0x05 */ u8 field_0x05;
/* 0x06 */ u8 _0x06[2];
};
// Implicit +0x10 from BinHeader
struct BinData {
/* 0x00 */ u16 mNumEntries;
@@ -26,29 +27,34 @@ public:
/* 0x03 */ u8 field_0x03;
/* 0x04 */ char mName[32];
/* 0x24 */ u8 mType;
/* 0x25 */ u8 _0x25[7];
/* 0x25 */ u16 field_0x25;
/* 0x27 */ u8 field_0x27;
/* 0x28 */ u8 _0x28[4];
/* 0x2C */ f32 field_0x2C;
/* 0x30 */ u8 _0x30[4];
/* 0x34 */ char mName2[32];
/* 0x54 */ f32 field_0x54;
u8 _0x00[0x1D];
u8 _0x00[0x20];
SubData mSubData[1];
};
#pragma pack(pop)
LightTexture(const char *name, const LightTextureManager *mgr);
virtual ~LightTexture();
virtual void configure() override; // at 0xC
virtual void SetBinaryInner(const Bin &) override;
virtual void GetBinaryInner(Bin *) const override;
virtual size_t GetBinarySize() const override;
static void initialize(u16 textureSize, Heap *pHeap);
private:
const char *getName() const {
return mName1;
}
private:
f32 getFloat(u16 idx) const {
return mpFloatData[idx];
}
+31 -3
View File
@@ -1,29 +1,57 @@
#ifndef EGG_LIGHT_TEXTURE_MGR_H
#define EGG_LIGHT_TEXTURE_MGR_H
#include "egg/gfx/eggLightTexture.h"
#include "egg/prim/eggBinary.h"
#include "nw4r/g3d/res/g3d_resmdl.h"
namespace EGG {
class LightManager;
class LightObject;
class LightTextureManager : public IBinary<LightTextureManager> {
public:
struct BinData {};
struct BinData {
u16 mDataCount;
u8 _0x02[14];
BinHeader mSubData[1];
};
LightTextureManager(const LightManager *lightMgr);
virtual ~LightTextureManager();
virtual void SetBinaryInner(const Bin &) override;
virtual void GetBinaryInner(Bin *) const override;
virtual size_t GetBinarySize() const override;
void replaceModelTextures(nw4r::g3d::ResMdl) const;
u16 createTexture(const char *name);
bool setBinaryToTexture(const void *data);
bool deleteTexture(int idx);
void replaceModelTextures(nw4r::g3d::ResMdl) const;
void drawAndCaptureTexture(f32, f32, f32, f32);
// Inofficial
static const void *getLtexFromLmap(const void *lmap, u16 index);
int createTexturesFromBin(const void *bin);
u16 createTextureFromBin(const void *bin);
u16 getMaxNumLightTextures() const {
return mMaxNumTextures;
}
u16 getNumLightTextures() const {
return mTextureCount;
}
private:
/* 0x04 */ u8 field_0x04;
/* 0x06 */ u16 mTextureCount;
/* 0x08 */ LightTexture **mpTextures;
/* 0x0C */ const LightManager *mpLightMgr;
/* 0x10 */ u32 field_0x10;
/* 0x14 */ u16 mMaxNumTextures;
/* 0x16 */ u8 field_0x16;
/* 0x18 */ LightObject **mpObjects;
};
} // namespace EGG
+1
View File
@@ -92,6 +92,7 @@ public:
static u16 s_commandFlag;
static u16 s_flag;
};
} // namespace EGG
+7 -7
View File
@@ -53,11 +53,17 @@ public:
// These functions below are automatically provided, you should not need to
// touch them to implement de-/serialization for your type. They will parse
// the binary header and then invoke the above virtual functions.
void GetBinary(void *pData) const;
void SetBinary(const void *);
void GetBinary(void *pData) const;
void SetBinaryBlend(const void *a, const void *b, f32 blend);
};
template <typename T>
void IBinary<T>::SetBinary(const void *a) {
const Bin *pBinA = reinterpret_cast<const Bin *>(a);
SetBinaryInner(*pBinA);
}
template <typename T>
void IBinary<T>::GetBinary(void *pData) const {
Bin *pBin = reinterpret_cast<Bin *>(pData);
@@ -74,12 +80,6 @@ void IBinary<T>::GetBinary(void *pData) const {
GetBinaryInner(pBin);
}
template <typename T>
void IBinary<T>::SetBinary(const void *a) {
const Bin *pBinA = reinterpret_cast<const Bin *>(a);
SetBinaryInner(*pBinA);
}
template <typename T>
void IBinary<T>::SetBinaryBlend(const void *a, const void *b, f32 blend) {
const Bin *pBinA = reinterpret_cast<const Bin *>(a);
+1 -1
View File
@@ -19,7 +19,7 @@ static const int sCpuTexGradientOp[NUM_CPU_TEX] = {0, 0, 0, 1, 2, 3, 4, 0, 5, 5,
static nw4r::math::MTX34 sMtx(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
u16 LightTexture::sTextureSize;
u16 LightTexture::sTextureSize = 0x20;
CpuTexture *LightTexture::spNormalEnvironment;
static s8 lbl_80574F3A = 0xFE;
+155 -1
View File
@@ -1,3 +1,157 @@
#include "egg/gfx/eggLightTextureMgr.h"
namespace EGG {} // namespace EGG
#include "common.h"
#include "egg/gfx/eggLightTexture.h"
#include "egg/gfx/eggStateGX.h"
#include <cstring>
namespace EGG {
LightTextureManager::LightTextureManager(const LightManager *lightMgr) {
field_0x04 = 0x78;
mTextureCount = 0;
mpTextures = nullptr;
mpLightMgr = lightMgr;
field_0x10 = 0;
mMaxNumTextures = 0x80;
field_0x16 = 1;
mpObjects = nullptr;
mpTextures = new LightTexture *[0x80];
for (int i = 0; i < 0x80; i++) {
mpTextures[i] = nullptr;
}
mpObjects = new LightObject *[mMaxNumTextures];
for (int i = 0; i < mMaxNumTextures; i++) {
mpObjects[i] = nullptr;
}
if ((StateGX::s_flag & 0x40) != 0) {
field_0x04 |= 0x80;
field_0x04 &= ~0x40;
field_0x16 = 3;
}
}
LightTextureManager::~LightTextureManager() {
for (int i = 0; i < 0x80; i++) {
deleteTexture(i);
}
delete[] mpTextures;
delete[] mpObjects;
}
u16 LightTextureManager::createTexture(const char *name) {
// Check if one already exists with the same name
for (int i = 0; i < getNumLightTextures(); i++) {
if (mpTextures[i] != nullptr && !strcmp(name, mpTextures[i]->getName())) {
return i;
}
}
// Find a hole to fill
int targetPosition = getNumLightTextures();
for (int i = 0; i < getNumLightTextures(); i++) {
if (mpTextures[i] == nullptr) {
targetPosition = i;
}
}
if (targetPosition == getNumLightTextures()) {
mTextureCount++;
}
LightTexture *tex = new LightTexture(name, this);
mpTextures[targetPosition] = tex;
tex->configure();
return targetPosition;
}
u16 LightTextureManager::createTextureFromBin(const void *bin) {
const LightTexture::Bin *data = reinterpret_cast<const LightTexture::Bin *>(bin);
u16 idx = createTexture(data->mData.mName);
mpTextures[idx]->SetBinary(data);
return idx;
}
int LightTextureManager::createTexturesFromBin(const void *bin) {
const LightTextureManager::Bin *data = reinterpret_cast<const LightTextureManager::Bin *>(bin);
// Moderate inefficiency here - this algorithm has quadratic runtime
// since we always search from the beginning
for (int i = 0; i < data->mData.mDataCount; i++) {
const void *subData = getLtexFromLmap(data, (u16)i);
createTextureFromBin(subData);
}
return data->mData.mDataCount;
}
bool LightTextureManager::deleteTexture(int idx) {
if (0 <= idx && idx < 0x80) {
if (mpTextures[idx] != nullptr) {
delete mpTextures[idx];
mpTextures[idx] = nullptr;
return true;
}
}
return false;
}
bool LightTextureManager::setBinaryToTexture(const void *data) {
const LightTexture::Bin *bin = reinterpret_cast<const LightTexture::Bin *>(data);
for (int i = 0; i < getNumLightTextures(); i++) {
if (!std::strcmp(bin->mData.mName, mpTextures[i]->getName())) {
mpTextures[i]->SetBinary(bin);
return true;
}
}
return false;
}
void LightTextureManager::SetBinaryInner(const Bin &bin) {
if (bin.mHeader.mVersion != 0) {
return;
}
const char *buf = reinterpret_cast<const char *>(bin.mData.mSubData);
for (int i = 0; i < bin.mData.mDataCount; i++) {
const BinHeader *hdr = reinterpret_cast<const BinHeader *>(buf);
setBinaryToTexture(buf);
buf += hdr->mSize;
}
}
void LightTextureManager::GetBinaryInner(Bin *pOutBin) const {
int count = 0;
char *buf = reinterpret_cast<char *>(pOutBin->mData.mSubData);
for (int i = 0; i < getNumLightTextures(); i++) {
mpTextures[i]->GetBinary(buf);
BinHeader *hdr = reinterpret_cast<BinHeader *>(buf);
// This is where the actually written size is added to the whole object
pOutBin->mHeader.mSize += hdr->mSize;
buf += hdr->mSize;
count++;
}
pOutBin->mData.mDataCount = count;
}
// Performs a linear search through the data to find the offset for the given index
const void *LightTextureManager::getLtexFromLmap(const void *lmap, u16 index) {
// A bit awkward but it matches
const BinHeader *buf = nullptr;
const Bin *bin = reinterpret_cast<const Bin *>(lmap);
if (bin->mHeader.mVersion == 0 && index < bin->mData.mDataCount) {
buf = bin->mData.mSubData;
for (int i = 0; i < index; i++) {
buf = reinterpret_cast<const BinHeader *>(reinterpret_cast<const char *>(buf) + buf->mSize);
}
}
return buf;
}
size_t LightTextureManager::GetBinarySize() const {
// Contrary to the other dynamically-sized Bins, this only
// returns the fixed size. GetBinaryInner will add the dynamic
// parts when writing.
return sizeof(Bin) - sizeof(BinHeader);
}
} // namespace EGG