Skip to content

Commit 37dda8a

Browse files
Finish xJSP as Equivalent (#666)
1 parent 8d15cf6 commit 37dda8a

File tree

5 files changed

+196
-38
lines changed

5 files changed

+196
-38
lines changed

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def MatchingFor(*versions):
575575
Object(NonMatching, "SB/Core/x/xClumpColl.cpp"),
576576
Object(NonMatching, "SB/Core/x/xEntBoulder.cpp"),
577577
Object(NonMatching, "SB/Core/x/xGrid.cpp"),
578-
Object(NonMatching, "SB/Core/x/xJSP.cpp"),
578+
Object(Equivalent, "SB/Core/x/xJSP.cpp"),
579579
Object(Matching, "SB/Core/x/xLightKit.cpp"),
580580
Object(Matching, "SB/Game/zCamMarker.cpp"),
581581
Object(NonMatching, "SB/Game/zGoo.cpp"),

include/rwsdk/rwplcore.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,12 @@ enum RwStreamAccessType
531531
rwSTREAMACCESSTYPEFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
532532
};
533533

534+
struct RwMemory
535+
{
536+
RwUInt8* start;
537+
RwUInt32 length;
538+
};
539+
534540
struct RwStreamMemory
535541
{
536542
RwUInt32 position;

src/SB/Core/x/xJSP.cpp

Lines changed: 176 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,208 @@
11
#include "xJSP.h"
2+
#include "zGlobals.h"
23

34
#include <types.h>
45
#include <string.h>
56

6-
#include "xClumpColl.h"
7+
static RwV3d* sCurrVert;
8+
static S32 sAtomicStartCount;
9+
static RwV3d** sAtomicStartVert;
710

8-
extern S32 sAtomicStartCount; // not exactly sure of the type
9-
extern RwV3d* sCurrVert; // not sure if correct type. not sure what this is.
10-
extern RwV3d* sAtomicStartVert; // I'm just going based on matt's assumption
1111

12-
extern RwGlobals* RwEngineInstance;
13-
14-
// No dwarf info
15-
// ghidra said return type and type of param_2 was void
16-
// but changing it to return atomic matches.
17-
RpAtomic* CountAtomicCB(RpAtomic* atomic, U32* param_2)
12+
static RpAtomic* CountAtomicCB(RpAtomic* atomic, void* data)
1813
{
1914
sAtomicStartCount++;
20-
*param_2 += atomic->geometry->mesh->totalIndicesInMesh;
15+
*(U32*)data += atomic->geometry->mesh->totalIndicesInMesh;
2116
return atomic;
2217
}
2318

24-
static RpMesh* AddMeshCB(RpMesh* mesh, RpMeshHeader* header, void* param_3)
19+
static RpMesh* AddMeshCB(RpMesh* mesh, RpMeshHeader*, void* pData)
2520
{
26-
for (int i = 0; i < mesh->numIndices; i++)
27-
{
28-
**(RwV3d**)(param_3) = sCurrVert[mesh->indices[i]];
29-
*((S32*)(param_3)) += sizeof(RwV3d);
21+
RwV3d** stripVert = (RwV3d**)pData;
22+
for (U32 i = 0; i < mesh->numIndices; i++) {
23+
**stripVert = sCurrVert[mesh->indices[i]];
24+
(*stripVert)++;
3025
}
31-
3226
return mesh;
3327
}
3428

35-
RpAtomic* AddAtomicCB(RpAtomic* atomic, void* data)
29+
static RpAtomic* AddAtomicCB(RpAtomic* atomic, void* data)
3630
{
3731
// The dwarf defines this variable but it looks like it isnt used
3832
// TempAtomicList** tmpList;
39-
sAtomicStartCount--;
40-
sAtomicStartVert[sAtomicStartCount] = *(RwV3d*)data;
33+
sAtomicStartVert[--sAtomicStartCount] = *(RwV3d**)data;
4134
sCurrVert = atomic->geometry->morphTarget->verts;
4235
_rpMeshHeaderForAllMeshes(atomic->geometry->mesh, (RpMeshCallBack)&AddMeshCB, data);
4336
return atomic;
4437
}
4538

46-
RpAtomic* AddAtomicPrecalcedVertCB(RpAtomic* atomic, void* data)
39+
static RpAtomic* AddAtomicPrecalcedVertCB(RpAtomic* atomic, void* data)
4740
{
48-
sAtomicStartCount--;
49-
sAtomicStartVert[sAtomicStartCount] = *(RwV3d*)data;
50-
data = &data + atomic->geometry->mesh->totalIndicesInMesh * 0xc;
51-
41+
sAtomicStartVert[--sAtomicStartCount] = *(RwV3d**)data;
42+
*(RwV3d**)data += atomic->geometry->mesh->totalIndicesInMesh;
5243
return atomic;
5344
}
5445

55-
RpAtomic* ListAtomicCB(RpAtomic* atomic, void* data)
46+
static RpAtomic* ListAtomicCB(RpAtomic* atomic, void* data)
5647
{
57-
// RpAtomic*** aList; <- declared in dwarf data
58-
// ¯\_(ツ)_/¯ idk what's going on
59-
**(RpAtomic***)data = atomic;
60-
*(S32*)data += 4;
48+
RpAtomic*** aList = (RpAtomic***)data;
49+
**aList = atomic;
50+
(*aList)++;
6151
return atomic;
6252
}
53+
54+
void xJSP_MultiStreamRead(void* data, U32 size, xJSPHeader** jsp)
55+
{
56+
U32 i;
57+
RpClump* clump;
58+
xClumpCollBSPTree* colltree;
59+
60+
if (!*jsp)
61+
{
62+
*jsp = (xJSPHeaderGC*)RwMalloc(sizeof(xJSPHeaderGC));
63+
memset(*jsp, 0, sizeof(xJSPHeaderGC));
64+
}
65+
66+
xJSPHeaderGC* hdr = (xJSPHeaderGC*)*jsp;
67+
68+
__rwMark mark;
69+
__rwMark* mp = (__rwMark*)data;
70+
memmove(&mark, mp, sizeof(__rwMark));
71+
RwMemNative32(&mark, sizeof(__rwMark));
72+
73+
if (mark.type == 0xBEEF01)
74+
{
75+
data = mp + 1;
76+
colltree = xClumpColl_StaticBufferInit(data, mark.length);
77+
78+
size -= mark.length + sizeof(__rwMark);
79+
data = (U8*)data + mark.length;
80+
81+
mp = (__rwMark*)data;
82+
memmove(&mark, mp, sizeof(__rwMark));
83+
RwMemNative32(&mark, sizeof(__rwMark));
84+
85+
data = mp + 1;
86+
87+
xJSPHeader* tmphdr = (xJSPHeader*)data;
88+
strncpy(hdr->idtag, tmphdr->idtag, sizeof(hdr->idtag));
89+
hdr->version = tmphdr->version;
90+
hdr->jspNodeCount = tmphdr->jspNodeCount;
91+
hdr->colltree = colltree;
92+
hdr->jspNodeList = (xJSPNodeInfo*)(tmphdr + 1);
93+
94+
size -= mark.length + sizeof(__rwMark);
95+
96+
for (i = 0; i < colltree->numTriangles; i++)
97+
{
98+
colltree->triangles[i].matIndex =
99+
hdr->jspNodeList[hdr->jspNodeCount - 1 - colltree->triangles[i].v.i.atomIndex]
100+
.originalMatIndex;
101+
}
102+
103+
if (size >= sizeof(__rwMark))
104+
{
105+
mp = (__rwMark*)((U8*)data + mark.length);
106+
memmove(&mark, mp, sizeof(__rwMark));
107+
RwMemNative32(&mark, sizeof(__rwMark));
108+
109+
data = mp + 1;
110+
111+
if (mark.type == 0xBEEF03)
112+
{
113+
hdr->stripVecCount = *(U32*)data;
114+
data = (U32*)data + 1;
115+
hdr->stripVecList = (RwV3d*)data;
116+
117+
sAtomicStartCount = RpClumpGetNumAtomics(hdr->clump);
118+
sAtomicStartVert = (RwV3d**)RwMalloc(sAtomicStartCount * sizeof(RwV3d*));
119+
120+
RwV3d* currVec = hdr->stripVecList;
121+
RpClumpForAllAtomics(hdr->clump, AddAtomicPrecalcedVertCB, &currVec);
122+
}
123+
}
124+
125+
if (hdr->stripVecCount == 0)
126+
{
127+
hdr->stripVecCount = 0;
128+
sAtomicStartCount = 0;
129+
130+
RpClumpForAllAtomics(hdr->clump, CountAtomicCB, &hdr->stripVecCount);
131+
132+
hdr->stripVecList = (RwV3d*)RwMalloc(hdr->stripVecCount * sizeof(RwV3d));
133+
sAtomicStartVert = (RwV3d**)RwMalloc(sAtomicStartCount * sizeof(RwV3d**));
134+
135+
RwV3d* currVec = hdr->stripVecList;
136+
RpClumpForAllAtomics(hdr->clump, AddAtomicCB, &currVec);
137+
}
138+
139+
for (i = 0; i < colltree->numTriangles; i++)
140+
{
141+
colltree->triangles[i].v.p = sAtomicStartVert[colltree->triangles[i].v.i.atomIndex] +
142+
colltree->triangles[i].v.i.meshVertIndex;
143+
}
144+
145+
RwFree(sAtomicStartVert);
146+
}
147+
else
148+
{
149+
RwMemory rwmem;
150+
rwmem.start = (RwUInt8*)data;
151+
rwmem.length = size;
152+
153+
RwStream* stream = RwStreamOpen(rwSTREAMMEMORY, rwSTREAMREAD, &rwmem);
154+
RwStreamFindChunk(stream, rwID_CLUMP, NULL, NULL);
155+
clump = RpClumpStreamRead(stream);
156+
RwStreamClose(stream, NULL);
157+
158+
if (!hdr->clump)
159+
{
160+
hdr->clump = clump;
161+
}
162+
else
163+
{
164+
S32 i, atomCount;
165+
166+
atomCount = RpClumpGetNumAtomics(clump);
167+
if (atomCount)
168+
{
169+
RpAtomic** atomList = (RpAtomic**)RwMalloc(atomCount * sizeof(RpAtomic*));
170+
RpAtomic** atomCurr = atomList;
171+
RpClumpForAllAtomics(clump, ListAtomicCB, &atomCurr);
172+
173+
for (i = atomCount - 1; i >= 0; i--)
174+
{
175+
RpClumpRemoveAtomic(clump, atomList[i]);
176+
RpClumpAddAtomic(hdr->clump, atomList[i]);
177+
RpAtomicSetFrame(atomList[i], RpClumpGetFrame(hdr->clump));
178+
}
179+
180+
RwFree(atomList);
181+
}
182+
183+
RpClumpDestroy(clump);
184+
}
185+
}
186+
}
187+
188+
void xJSP_Destroy(xJSPHeader* jsp)
189+
{
190+
if (globals.sceneCur->env->geom->jsp == jsp && globals.sceneCur->env->geom->world)
191+
{
192+
RpWorldDestroy(globals.sceneCur->env->geom->world);
193+
globals.sceneCur->env->geom->world = NULL;
194+
}
195+
196+
RpClumpDestroy(jsp->clump);
197+
RwFree(jsp->colltree);
198+
199+
U32* tp = (U32*)((xJSPHeaderGC*)jsp)->stripVecList;
200+
U32 test = *(tp - sizeof(U32));
201+
RwMemNative32(&test, sizeof(U32));
202+
if (test != 0xBEEF03)
203+
{
204+
RwFree(((xJSPHeaderGC*)jsp)->stripVecList);
205+
}
206+
207+
RwFree(jsp);
208+
}

src/SB/Core/x/xJSP.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
#include <rpworld.h>
77
#include "xClumpColl.h"
88

9+
struct __rwMark
10+
{
11+
U32 type;
12+
U32 length;
13+
U32 libraryID;
14+
};
15+
916
struct xJSPNodeInfo
1017
{
1118
S32 originalMatIndex;
@@ -22,7 +29,12 @@ struct xJSPHeader
2229
xJSPNodeInfo* jspNodeList;
2330
};
2431

25-
RpMesh* AddMeshCB(RpMesh* mesh, RpMeshHeader* header, RwV3d** param_3);
32+
struct xJSPHeaderGC : xJSPHeader
33+
{
34+
U32 stripVecCount;
35+
RwV3d* stripVecList;
36+
};
37+
2638
void xJSP_MultiStreamRead(void* data, U32 size, xJSPHeader** jsp);
2739
void xJSP_Destroy(xJSPHeader* jsp);
2840

src/SB/Game/zAssetTypes.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
#include "zNPCTypeTest.h"
2828
#include "zNPCTypeTiki.h"
2929

30-
struct RwMemory
31-
{
32-
U8* start;
33-
U32 length;
34-
};
35-
3630
class HackModelRadius
3731
{
3832
public:

0 commit comments

Comments
 (0)