Fix endianness & 64-bit in 3D asset loading code

Combination of plumbing BE(T) through everything, making BE<T> have template specializations, and inverting at load time where more practical.
This commit is contained in:
PJB3005
2026-02-25 20:20:45 +01:00
parent 31149794f1
commit e7861f1ee3
32 changed files with 830 additions and 553 deletions
+3 -2
View File
@@ -5,6 +5,7 @@
#include "JSystem/J3DAssert.h"
#include "JSystem/J3DGraphBase/J3DFifo.h"
#include <dolphin/mtx.h>
#include "dusk/endian_gx.hpp"
class J3DShapeMtx;
@@ -184,7 +185,7 @@ public:
bool getNBTFlag() const { return mHasNBT; }
u32 getBumpMtxOffset() const { return mBumpMtxOffset; }
void setBumpMtxOffset(u32 offset) { mBumpMtxOffset = offset; }
GXVtxDescList* getVtxDesc() { return mVtxDesc; }
BE(GXVtxDescList)* getVtxDesc() { return mVtxDesc; }
J3DMaterial* getMaterial() const { return mMaterial; }
u16 getIndex() const { return mIndex; }
@@ -212,7 +213,7 @@ private:
/* 0x14 */ Vec mMin;
/* 0x20 */ Vec mMax;
/* 0x2C */ u8* mVcdVatCmd;
/* 0x30 */ GXVtxDescList* mVtxDesc;
/* 0x30 */ BE(GXVtxDescList)* mVtxDesc;
/* 0x34 */ bool mHasNBT;
/* 0x38 */ J3DShapeMtx** mShapeMtx;
/* 0x3C */ J3DShapeDraw** mShapeDraw;
+5 -4
View File
@@ -4,6 +4,7 @@
#include "JSystem/J3DGraphBase/J3DShape.h"
#include "JSystem/J3DAssert.h"
#include <dolphin/mtx.h>
#include "dusk/endian.h"
class J3DTexMtx;
class J3DTexGenBlock;
@@ -34,7 +35,7 @@ typedef void (J3DShapeMtxConcatView::*J3DShapeMtxConcatView_LoadFunc)(int, u16)
*/
class J3DShapeMtxMulti : public J3DShapeMtx {
public:
J3DShapeMtxMulti(u16 useMtxIndex, u16 useMtxNum, u16* useMtxIndexTable)
J3DShapeMtxMulti(u16 useMtxIndex, u16 useMtxNum, BE(u16)* useMtxIndexTable)
: J3DShapeMtx(useMtxIndex)
, mUseMtxNum(useMtxNum)
, mUseMtxIndexTable(useMtxIndexTable)
@@ -49,7 +50,7 @@ public:
private:
/* 0x8 */ u16 mUseMtxNum;
/* 0xC */ u16* mUseMtxIndexTable;
/* 0xC */ BE(u16)* mUseMtxIndexTable;
};
/**
@@ -85,7 +86,7 @@ public:
*/
class J3DShapeMtxMultiConcatView : public J3DShapeMtxConcatView {
public:
J3DShapeMtxMultiConcatView(u16 useMtxIndex, u16 useMtxNum, u16* useMtxIndexTable)
J3DShapeMtxMultiConcatView(u16 useMtxIndex, u16 useMtxNum, BE(u16)* useMtxIndexTable)
: J3DShapeMtxConcatView(useMtxIndex)
, mUseMtxNum(useMtxNum)
, mUseMtxIndexTable(useMtxIndexTable)
@@ -101,7 +102,7 @@ public:
private:
/* 0x8 */ u16 mUseMtxNum;
/* 0xC */ u16* mUseMtxIndexTable;
/* 0xC */ BE(u16)* mUseMtxIndexTable;
};
/**
+11 -2
View File
@@ -7,6 +7,8 @@
#include "global.h"
#include "JSystem/JMath/JMath.h"
#include "dusk/endian.h"
/**
* @ingroup jsystem-j3d
*
@@ -15,6 +17,8 @@ struct J3DLightInfo {
bool operator==(J3DLightInfo& other) const;
J3DLightInfo& operator=(J3DLightInfo const&);
// NOTE: Values big endian, need fixup at load
// Actually, this class doesn't seem used?
/* 0x00 */ Vec mLightPosition;
/* 0x0C */ Vec mLightDirection;
/* 0x18 */ GXColor mColor;
@@ -27,6 +31,7 @@ struct J3DLightInfo {
*
*/
struct J3DTextureSRTInfo {
// NOTE: Big endian when loaded from file!
/* 0x00 */ f32 mScaleX;
/* 0x04 */ f32 mScaleY;
/* 0x08 */ s16 mRotation;
@@ -85,9 +90,10 @@ struct J3DTexMtxInfo {
/* 0x01 */ u8 mInfo;
/* 0x02 */ u8 field_0x2;
/* 0x03 */ u8 field_0x3;
// NOTE: big endian when loaded from file!
/* 0x04 */ Vec mCenter;
/* 0x10 */ J3DTextureSRTInfo mSRT;
/* 0x24 */ Mtx44 mEffectMtx;
/* 0x24 */ Mtx44 mEffectMtx;
}; // Size: 0x64
/**
@@ -108,6 +114,9 @@ struct J3DFogInfo {
bool operator==(J3DFogInfo&) const;
J3DFogInfo& operator=(const J3DFogInfo&);
// TODO: Fog data should be converted from big endian (probably?)
// Not sure TP uses it.
/* 0x00 */ u8 mType;
/* 0x01 */ u8 mAdjEnable;
/* 0x02 */ u16 mCenter;
@@ -128,7 +137,7 @@ struct J3DNBTScaleInfo {
J3DNBTScaleInfo& operator=(const J3DNBTScaleInfo&);
/* 0x0 */ u8 mbHasScale;
/* 0x4 */ Vec mScale;
/* 0x4 */ BE(Vec) mScale;
}; // Size: 0x10
/**
+5 -3
View File
@@ -3,8 +3,10 @@
#include <dolphin/gx.h>
#include <dolphin/mtx.h>
#include "JSystem/J3DAssert.h"
#include "JSystem/JMath/JMath.h"
#include "dusk/endian.h"
enum J3DSysDrawBuf {
/* 0x0 */ J3DSysDrawBuf_Opa,
@@ -63,7 +65,7 @@ struct J3DSys {
/* 0x10C */ void* mVtxPos;
/* 0x110 */ void* mVtxNrm;
/* 0x114 */ GXColor* mVtxCol;
/* 0x118 */ Vec* mNBTScale;
/* 0x118 */ BE(Vec)* mNBTScale;
J3DSys();
void loadPosMtxIndx(int, u16) const;
@@ -131,8 +133,8 @@ struct J3DSys {
}
J3DTexture* getTexture() { return mTexture; }
void setNBTScale(Vec* scale) { mNBTScale = scale; }
Vec* getNBTScale() { return mNBTScale; }
void setNBTScale(BE(Vec)* scale) { mNBTScale = scale; }
BE(Vec)* getNBTScale() { return mNBTScale; }
void onFlag(u32 flag) { mFlags |= flag; }
+1 -1
View File
@@ -282,7 +282,7 @@ struct J3DNBTScale : public J3DNBTScaleInfo {
mScale.z = info.mScale.z;
}
Vec* getScale() { return &mScale; }
BE(Vec)* getScale() { return &mScale; }
};
extern const GXColor j3dDefaultColInfo;
+3 -2
View File
@@ -3,6 +3,7 @@
#include <dolphin/gx.h>
#include <dolphin/mtx.h>
#include "dusk/endian_gx.hpp"
typedef struct _GXColor GXColor;
class J3DModel;
@@ -41,7 +42,7 @@ public:
u32 getNrmNum() const { return mNrmNum; }
u32 getVtxNum() const { return mVtxNum; }
u32 getColNum() const { return mColNum; }
GXVtxAttrFmtList* getVtxAttrFmtList() const { return mVtxAttrFmtList; }
BE(GXVtxAttrFmtList)* getVtxAttrFmtList() const { return mVtxAttrFmtList; }
u8 getVtxPosFrac() const { return mVtxPosFrac; }
u8 getVtxNrmFrac() const { return mVtxNrmFrac; }
int getVtxPosType() const { return mVtxPosType; }
@@ -60,7 +61,7 @@ private:
/* 0x08 */ u32 mColNum;
/* 0x0C */ u32 mTexCoordNum;
/* 0x10 */ u32 mPacketNum;
/* 0x14 */ GXVtxAttrFmtList* mVtxAttrFmtList;
/* 0x14 */ BE(GXVtxAttrFmtList)* mVtxAttrFmtList;
/* 0x18 */ void* mVtxPosArray;
/* 0x1C */ void* mVtxNrmArray;
/* 0x20 */ void* mVtxNBTArray;