Skip to content

Commit 594ab60

Browse files
author
Niko
committed
Start of animation decompression
1 parent 7e82aed commit 594ab60

File tree

6 files changed

+127
-18
lines changed

6 files changed

+127
-18
lines changed

decompile/General/AltMods/Mods6.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
#ifdef USE_FASTANIM
3+
void FastAnim_Start(struct GameTracker* gGT)
4+
{
5+
for(int i = 0; i < gGT->numPlyrCurrGame; i++)
6+
{
7+
struct Driver* d = gGT->drivers[i];
8+
9+
if(d == 0)
10+
continue;
11+
12+
struct Instance* inst = d->instSelf;
13+
struct Model* m = inst->model;
14+
15+
for(int j = 0; j < m->numHeaders; j++)
16+
{
17+
struct ModelHeader* h = &m->headers[j];
18+
19+
for(int k = 0; k < h->numAnimations; k++)
20+
{
21+
struct ModelAnim* ma = h->ptrAnimations[k];
22+
23+
void FastAnim_Decompress(struct ModelAnim* ma);
24+
FastAnim_Decompress(ma);
25+
}
26+
}
27+
}
28+
}
29+
#endif

decompile/General/AltMods/ModsA.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
#ifdef USE_FASTANIM
3+
void FastAnim_Decompress(struct ModelAnim* ma)
4+
{
5+
6+
}
7+
#endif
8+
9+
#if 0
10+
11+
// animation
12+
ma = m->headers[0].ptrAnimations[curr->animIndex];
13+
14+
// temporary solution, plays animations
15+
// at 30fps while rest of the game is 60fps
16+
int frameIndex = FPS_HALF(curr->animFrame);
17+
18+
// cast
19+
char* maByte = (char*)ma;
20+
maByte = MODELANIM_GETFRAME(maByte);
21+
maByte = &maByte[ma->frameSize * frameIndex];
22+
23+
// frame data
24+
mf = maByte;
25+
26+
char* vertData = (char*)&mf[0] + mf->vertexOffset;
27+
28+
Decompressed
29+
30+
//copy from vertex buffer to stack index
31+
stack[stackIndex].X = ptrVerts[vertexIndex].X;
32+
stack[stackIndex].Y = ptrVerts[vertexIndex].Y;
33+
stack[stackIndex].Z = ptrVerts[vertexIndex].Z;
34+
35+
Compressed
36+
37+
//store temporal vertex packed uint
38+
u_int temporal = ma->ptrDeltaArray[vertexIndex];
39+
40+
//printf("temporal: %08x\n", temporal);
41+
42+
//extract data from packed uint
43+
//deltaArray bits: 0bXXXXXXXZZZZZZZZYYYYYYYYAAABBBCCC
44+
45+
u_char XBits = (temporal >> 6) & 7;
46+
u_char YBits = (temporal >> 3) & 7;
47+
u_char ZBits = (temporal) & 7;
48+
49+
u_char bx = (temporal >> 0x19) << 1;
50+
u_char by = (temporal << 7) >> 0x18;
51+
u_char bz = (temporal << 0xf) >> 0x18;
52+
53+
// If reading a full 8 bits (7+1)
54+
// reset accumulator, this is an
55+
// uncompressed 1-byte number
56+
if (XBits == 7) x_alu = 0;
57+
if (YBits == 7) y_alu = 0;
58+
if (ZBits == 7) z_alu = 0;
59+
60+
// Read NumBits+1, where the first
61+
// extra (+1) bit, determines negative
62+
63+
// convert XZY frame data
64+
int newX = GetSignedBits(vertData, XBits + 1);
65+
int newY = GetSignedBits(vertData, YBits + 1);
66+
int newZ = GetSignedBits(vertData, ZBits + 1);
67+
68+
//calculate decompressed coord value
69+
x_alu = (x_alu + (int)newX + bx);
70+
y_alu = (y_alu + (int)newY + by);
71+
z_alu = (z_alu + (int)newZ + bz);
72+
73+
//store values to stack index, axis swap is important
74+
stack[stackIndex].X = x_alu;
75+
stack[stackIndex].Y = z_alu;
76+
stack[stackIndex].Z = y_alu;
77+
78+
#endif

decompile/General/LOAD/LOAD_44_TenStages.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,6 @@ int DECOMP_LOAD_TenStages(struct GameTracker* gGT, int loadingStage, struct BigH
675675
// Stage 7: Fill remaining heap
676676
DECOMP_MainInit_PrimMem(gGT, 0);
677677
#endif
678-
679-
#ifdef USE_FASTANIM
680-
#endif
681678

682679
if ((gGT->gameMode2 & LEV_SWAP) == 0)
683680
break;

decompile/General/MAIN/MainInit_07_FinalizeInit.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ void DECOMP_MainInit_FinalizeInit(struct GameTracker *gGT)
194194
OnlineInit_Drivers(gGT);
195195
#endif
196196

197+
#ifdef USE_FASTANIM
198+
#ifndef REBUILD_PC
199+
void FastAnim_Start(struct GameTracker* gGT);
200+
FastAnim_Start(gGT);
201+
#endif
202+
#endif
203+
197204
// assume 1P fov
198205
numPlyr = 1;
199206

include/common.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ enum HotReloadSteps
115115
// Not PC
116116
#ifndef REBUILD_PC
117117
#include <gccHeaders.h>
118+
#include <ctr_gte.h>
119+
#endif
120+
121+
// PC-only, always use this
122+
#ifdef REBUILD_PC
123+
#define USE_MOREPRIM
118124
#endif
119125

120126
#include <macros.h>
121127
#include <ctr_math.h>
122128

123-
124-
// PC Only
125-
#ifndef REBUILD_PC
126-
#include <ctr_gte.h>
127-
#endif
128-
129129
#include <prim.h>
130130

131131
// =============================

rebuild_PS1/TEST_DrawInstances.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,12 @@ void DrawOneInst(struct Instance* curr)
239239
// at 30fps while rest of the game is 60fps
240240
int frameIndex = FPS_HALF(curr->animFrame);
241241

242-
// cast
243-
char* maByte = (char*)ma;
244-
maByte = MODELANIM_GETFRAME(maByte);
245-
maByte = &maByte[ma->frameSize * frameIndex];
246-
247-
// frame data
248-
mf = maByte;
242+
// Get first frame, then current frame
243+
char* firstFrame = MODELANIM_GETFRAME(ma);
244+
mf = &firstFrame[ma->frameSize * frameIndex];
249245
}
250246

247+
// may be compressed vertData, or uncompresed
251248
char* vertData = (char*)&mf[0] + mf->vertexOffset;
252249

253250
// 3FF is background, 0x0 is minimum depth
@@ -268,7 +265,6 @@ void DrawOneInst(struct Instance* curr)
268265
int vertexIndex = 0;
269266
//current strip length
270267
int stripLength = 0;
271-
CompVertex* ptrVerts = (CompVertex*)vertData;
272268
u_int* pCmd = mh->ptrCommandList;
273269

274270
//a "shifting window", here we update the vertices and read triangle once it's ready
@@ -367,7 +363,9 @@ void DrawOneInst(struct Instance* curr)
367363
}
368364
else
369365
{
370-
//copy from vertex buffer to stack index
366+
// Copy uncompressed vertices to scratchpad
367+
CompVertex* ptrVerts = (CompVertex*)vertData;
368+
371369
stack[stackIndex].X = ptrVerts[vertexIndex].X;
372370
stack[stackIndex].Y = ptrVerts[vertexIndex].Y;
373371
stack[stackIndex].Z = ptrVerts[vertexIndex].Z;

0 commit comments

Comments
 (0)