mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-12 13:35:35 -04:00
1eb018ea26
- Fix <string> -> <cstring> across all source files (upstream fix) - Add <cstring> to JASGadget.h, <cstdarg> to JUTDbPrint.cpp - Fix <string> -> <cstring> in JUTFont.h, d_save.h, f_ap_game.h - Fix std::isnan usage in c_cc_d.cpp - Fix cCcD_Src types: s32 -> u32 for bitmask fields (upstream fix) - Fix AT_TYPE_WOLF_ATTACK/AT_TYPE_UNK unsigned literals (upstream fix) - Remove (s32) casts on hex literals in collision data (upstream fix) - Fix 0xFFFFFFFF literal in d_a_obj_wood_statue.cpp (upstream fix) - Add braces to case 0 in d_a_e_gb.cpp to fix jump-over-init - Fix Z2AudioCS.h include path (Z2AudioLib -> Z2AudioCS) - Forward-declare Z2AudioCS in stubs.cpp to avoid revolution conflicts - Guard JASGlobalInstance specializations with __MWERKS__ in m_Do_main - Remove duplicate inline functions from d_com_inf_game.h - Mark dummy() functions as static (upstream fix) - Add JAUSectionHeap.h include to m_Do_main.cpp
83 lines
2.3 KiB
C++
83 lines
2.3 KiB
C++
#include "JSystem/JSystem.h" // IWYU pragma: keep
|
|
|
|
#include "JSystem/J3DGraphBase/J3DShapeDraw.h"
|
|
#include "JSystem/JKernel/JKRHeap.h"
|
|
#include <cstring>
|
|
#include <stdint.h>
|
|
#include <dolphin/gx.h>
|
|
|
|
u32 J3DShapeDraw::countVertex(u32 stride) {
|
|
u32 count = 0;
|
|
u8* dlStart = (u8*)getDisplayList();
|
|
|
|
for (u8* dl = dlStart; (dl - dlStart) < getDisplayListSize();) {
|
|
u8 cmd = *(u8*)dl;
|
|
dl++;
|
|
if (cmd != GX_TRIANGLEFAN && cmd != GX_TRIANGLESTRIP)
|
|
break;
|
|
int vtxNum = *((u16*)(dl));
|
|
dl += 2;
|
|
count += vtxNum;
|
|
dl = (u8*)dl + stride * vtxNum;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
void J3DShapeDraw::addTexMtxIndexInDL(u32 stride, u32 attrOffs, u32 valueBase) {
|
|
u32 byteNum = countVertex(stride);
|
|
u32 oldSize = mDisplayListSize;
|
|
u32 newSize = ALIGN_NEXT(oldSize + byteNum, 0x20);
|
|
u8* newDLStart = new (0x20) u8[newSize];
|
|
u8* oldDLStart = (u8*)mDisplayList;
|
|
u8* oldDL = oldDLStart;
|
|
u8* newDL = newDLStart;
|
|
|
|
for (; (oldDL - oldDLStart) < mDisplayListSize;) {
|
|
// Copy command
|
|
u8 cmd = *(u8*)oldDL;
|
|
oldDL++;
|
|
*newDL++ = cmd;
|
|
|
|
if (cmd != GX_TRIANGLEFAN && cmd != GX_TRIANGLESTRIP)
|
|
break;
|
|
|
|
// Copy count
|
|
int vtxNum = *(u16*)oldDL;
|
|
oldDL += 2;
|
|
*(u16*)newDL = vtxNum;
|
|
newDL += 2;
|
|
|
|
for (int i = 0; i < vtxNum; i++) {
|
|
u8* oldDLVtx = &oldDL[stride * i];
|
|
u8 pnmtxidx = *oldDLVtx;
|
|
memcpy(newDL, oldDLVtx, (int)attrOffs);
|
|
newDL += attrOffs;
|
|
*newDL++ = valueBase + pnmtxidx;
|
|
memcpy(newDL, oldDLVtx + attrOffs, stride - attrOffs);
|
|
newDL += (stride - attrOffs);
|
|
}
|
|
|
|
oldDL = (u8*)oldDL + stride * vtxNum;
|
|
}
|
|
|
|
u32 realSize = ALIGN_NEXT((uintptr_t)newDL - (uintptr_t)newDLStart, 0x20);
|
|
for (; (newDL - newDLStart) < newSize; newDL++)
|
|
*newDL = 0;
|
|
|
|
mDisplayListSize = realSize;
|
|
mDisplayList = newDLStart;
|
|
DCStoreRange(newDLStart, mDisplayListSize);
|
|
}
|
|
|
|
J3DShapeDraw::J3DShapeDraw(const u8* displayList, u32 displayListSize) {
|
|
mDisplayList = (void*)displayList;
|
|
mDisplayListSize = displayListSize;
|
|
}
|
|
|
|
void J3DShapeDraw::draw() const {
|
|
GXCallDisplayList(mDisplayList, mDisplayListSize);
|
|
}
|
|
|
|
J3DShapeDraw::~J3DShapeDraw() {}
|