Skip to content

Commit ac72338

Browse files
author
Niko
committed
AnimTex variable rework
1 parent d2bfb88 commit ac72338

6 files changed

Lines changed: 64 additions & 49 deletions

File tree

decompile/General/CTR/CTR_04_CycleTex_LEV.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@
22

33
void DECOMP_CTR_CycleTex_LEV(struct AnimTex* animtex, int timer)
44
{
5-
int frameIndex;
5+
int frameCurr;
66
struct AnimTex* curAnimTex = animtex;
77

88
#ifdef USE_NEWLEV
99
if(animtex == 0) return;
1010
#endif
1111

12-
// iterate over All AnimTex's in a row,
13-
// last one loops back to the beginning, could've also just been a null terminator
14-
while (*(int*)curAnimTex != (int)animtex)// I feel like this should just be a do/while with `(int)curAnimText != (int)animtex`, but idk
12+
// Termination is determined by pointer to First AnimTex
13+
while (*(int*)curAnimTex != (int)animtex)
1514
{
16-
frameIndex = FPS_HALF(timer) + curAnimTex->frameDuration >>
17-
((int)curAnimTex->shiftFactor & 0x1fU);
18-
19-
frameIndex = frameIndex % curAnimTex->numFrames;
20-
curAnimTex->frameIndex = frameIndex;
15+
// which texture to draw this frame
16+
frameCurr = FPS_HALF(timer) + curAnimTex->frameOffset;
17+
18+
// allow frames to skip updating (like 60fps hacks)
19+
frameCurr = frameCurr >> curAnimTex->frameSkip;
20+
21+
// loop back to index[0] after finished cycle
22+
frameCurr = frameCurr % curAnimTex->numFrames;
23+
24+
// save result
25+
curAnimTex->frameCurr = frameCurr;
2126

2227
struct IconGroup4** ptrArray = ANIMTEX_GETARRAY(curAnimTex);
2328

2429
// Save new frame
25-
curAnimTex->ptrActiveTex = (int*)ptrArray[frameIndex]; //why is this line slightly different than CTR_CycleTex_Model.c?
30+
// For levels, this is just a pointer
31+
curAnimTex->ptrActiveTex = (int*)ptrArray[frameCurr];
2632

2733
// Go to next AnimTex, which comes after this AnimTex's ptrarray
2834
curAnimTex = (struct AnimTex*)&ptrArray[curAnimTex->numFrames];

decompile/General/CTR/CTR_05_CycleTex_Model.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,33 @@
22

33
void DECOMP_CTR_CycleTex_Model(struct AnimTex* animtex, int timer)
44
{
5-
int frameIndex;
5+
int frameCurr;
66
struct AnimTex* curAnimTex = animtex;
7-
8-
// iterate over All AnimTex's in a row,
9-
// last one loops back to the beginning, could've also just been a null terminator
10-
while (*(int*)curAnimTex != (int)animtex)// I feel like this should just be a do/while with `(int)curAnimText != (int)animtex`, but idk
7+
8+
#ifdef USE_NEWLEV
9+
if(animtex == 0) return;
10+
#endif
11+
12+
// Termination is determined by pointer to First AnimTex
13+
while (*(int*)curAnimTex != (int)animtex)
1114
{
12-
frameIndex = FPS_HALF(timer) + curAnimTex->frameDuration >>
13-
((int)curAnimTex->shiftFactor & 0x1fU);
14-
15-
frameIndex = frameIndex % curAnimTex->numFrames;
16-
curAnimTex->frameIndex = frameIndex;
15+
// which texture to draw this frame
16+
frameCurr = FPS_HALF(timer) + curAnimTex->frameOffset;
17+
18+
// allow frames to skip updating (like 60fps hacks)
19+
frameCurr = frameCurr >> curAnimTex->frameSkip;
20+
21+
// loop back to index[0] after finished cycle
22+
frameCurr = frameCurr % curAnimTex->numFrames;
23+
24+
// save result
25+
curAnimTex->frameCurr = frameCurr;
1726

1827
struct IconGroup4** ptrArray = ANIMTEX_GETARRAY(curAnimTex);
1928

2029
// Save new frame
21-
*curAnimTex->ptrActiveTex = (int)ptrArray[frameIndex]; //why is this line slightly different than CTR_CycleTex_LEV.c?
30+
// For Model, this is a pointer to a pointer
31+
*curAnimTex->ptrActiveTex = (int)ptrArray[frameCurr];
2232

2333
// Go to next AnimTex, which comes after this AnimTex's ptrarray
2434
curAnimTex = (struct AnimTex*)&ptrArray[curAnimTex->numFrames];

include/namespace_Level.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ struct AnimTex
129129
short numFrames;
130130

131131
// 0x6
132-
short frameDuration;
132+
short frameOffset;
133133

134134
// 0x8
135-
short shiftFactor;
135+
short frameSkip;
136136

137137
// 0xA
138-
u_short frameIndex;
138+
short frameCurr;
139139

140140
// 0xC
141141
// size = numFrames

mods/Levels/Legacy/RoadToRainbow/src/Lev221.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ struct LevelFile file =
159159
{
160160
.ptrActiveTex = LEV_OFFSETOF(turbo_pad[0]),
161161
.numFrames = 10,
162-
.frameDuration = 0,
163-
.shiftFactor = 0,
164-
.frameIndex = 0,
165162
},
166163

167164
.TPA_ptrarray =

mods/Levels/Legacy/TileTrauma/src/Lev221.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,6 @@ struct LevelFile file =
279279
{
280280
.ptrActiveTex = LEV_OFFSETOF(turbo_pad[0]),
281281
.numFrames = 10,
282-
.frameDuration = 0,
283-
.shiftFactor = 0,
284-
.frameIndex = 0,
285282
},
286283

287284
.TPA_ptrarray =
@@ -302,9 +299,6 @@ struct LevelFile file =
302299
{
303300
.ptrActiveTex = LEV_OFFSETOF(super_turbo_pad[0]),
304301
.numFrames = 10,
305-
.frameDuration = 0,
306-
.shiftFactor = 0,
307-
.frameIndex = 0,
308302
},
309303

310304
.STPA_ptrarray =

mods/Levels/PS1_TrackROM/src/cycle_tex.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,34 @@
22

33
void CTR_CycleTex_LEV(struct AnimTex* animtex, int timer)
44
{
5-
int frameIndex;
5+
int frameCurr;
66
struct AnimTex* curAnimTex = animtex;
7-
8-
if(animtex == NULL) { return; }
9-
10-
// iterate over All AnimTex's in a row,
11-
// last one loops back to the beginning, could've also just been a null terminator
12-
while (*(int*)curAnimTex != (int)animtex)// I feel like this should just be a do/while with `(int)curAnimText != (int)animtex`, but idk
7+
8+
#ifdef USE_NEWLEV
9+
if(animtex == 0) return;
10+
#endif
11+
12+
// Termination is determined by pointer to First AnimTex
13+
while (*(int*)curAnimTex != (int)animtex)
1314
{
14-
frameIndex = FPS_HALF(timer) + curAnimTex->frameDuration >>
15-
((int)curAnimTex->shiftFactor & 0x1fU);
16-
17-
frameIndex = frameIndex % curAnimTex->numFrames;
18-
curAnimTex->frameIndex = frameIndex;
19-
15+
// which texture to draw this frame
16+
frameCurr = FPS_HALF(timer) + curAnimTex->frameOffset;
17+
18+
// allow frames to skip updating (like 60fps hacks)
19+
frameCurr = frameCurr >> curAnimTex->frameSkip;
20+
21+
// loop back to index[0] after finished cycle
22+
frameCurr = frameCurr % curAnimTex->numFrames;
23+
24+
// save result
25+
curAnimTex->frameCurr = frameCurr;
26+
2027
struct IconGroup4** ptrArray = ANIMTEX_GETARRAY(curAnimTex);
21-
28+
2229
// Save new frame
23-
curAnimTex->ptrActiveTex = (int*)ptrArray[frameIndex]; //why is this line slightly different than CTR_CycleTex_Model.c?
24-
30+
// For levels, this is just a pointer
31+
curAnimTex->ptrActiveTex = (int*)ptrArray[frameCurr];
32+
2533
// Go to next AnimTex, which comes after this AnimTex's ptrarray
2634
curAnimTex = (struct AnimTex*)&ptrArray[curAnimTex->numFrames];
2735
}

0 commit comments

Comments
 (0)