Skip to content

Commit ba2d2ea

Browse files
author
Niko
committed
RaceFlag_DrawSelf progress
1 parent ac090fe commit ba2d2ea

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

decompile/General/RaceFlag/RaceFlag_13_DrawSelf.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,36 @@ force_inline char RaceFlag_CalculateBrightness(u_int sine, u_char darkTile)
1313
return((sine * -125 + 0x1fe000) >> 0xD);
1414
}
1515

16+
// inline Sine operation
17+
// drops clock from ~130 to
18+
force_inline
19+
int MathSinInline(u_int param_1)
20+
{
21+
u_int iVar1;
22+
23+
// approximate trigonometry
24+
iVar1 = *(u_int*)&data.trigApprox[param_1 & 0x3ff];
25+
26+
// if (0 < angle < 90) or (180 < angle < 270)
27+
if ((param_1 & 0x400) == 0)
28+
{
29+
// shift bottom 2-byte to become top 2-byte
30+
iVar1 = iVar1 << 0x10;
31+
}
32+
33+
// move top 2-byte to bottom 2-byte,
34+
// and make top 2-byte zero
35+
iVar1 = iVar1 >> 0x10;
36+
37+
// if (angle > 180)
38+
if ((param_1 & 0x800) != 0)
39+
{
40+
// make negative
41+
iVar1 = -iVar1;
42+
}
43+
return iVar1;
44+
}
45+
1646
void DECOMP_RaceFlag_DrawSelf()
1747
{
1848
char i, j;
@@ -96,7 +126,7 @@ void DECOMP_RaceFlag_DrawSelf()
96126

97127
// === First Loop Iteration ===
98128
// Remove 36*10 branching instructions,
99-
// Reduces clock from ~150 to ~120
129+
// Reduces clock from ~150 to ~130
100130
{
101131
#ifdef REBUILD_PC
102132
posL = &scratchpadBuf[(toggle * 0x78 / 4) - 1];
@@ -123,22 +153,22 @@ void DECOMP_RaceFlag_DrawSelf()
123153
local0 += 0x200;
124154
local2 += 200;
125155

126-
int sin0 = DECOMP_MATH_Sin(local0) + 0xfff;
127-
int sin2 = DECOMP_MATH_Sin(local2) + 0xfff;
156+
int sin0 = MathSinInline(local0) + 0xfff;
157+
int sin2 = MathSinInline(local2) + 0xfff;
128158

129159
// reset based on trig
130160
local1 = (sin0 * 0x20 >> 0xd) + 0x96;
131161
local3 = (sin2 * 0x40 >> 0xd) + 0xb4;
132162
}
133163

134164
// === Step 3 ===
135-
approx[0] = DECOMP_MATH_Sin(angle[0]) + 0xfff;
165+
approx[0] = MathSinInline(angle[0]) + 0xfff;
136166
approx[0] = approx[0] * local1;
137167
approx[0] = (approx[0] >> 0xd) + 0x280;
138168

139169
// === Step 4 ===
140170
angle[0] += 0xc80;
141-
lightL = DECOMP_MATH_Sin(angle[0]) + 0xfff;
171+
lightL = MathSinInline(angle[0]) + 0xfff;
142172

143173
// === Step 5 ===
144174
pos[0].vy = 0xfc72;
@@ -171,7 +201,7 @@ void DECOMP_RaceFlag_DrawSelf()
171201
j++, vect++)
172202
{
173203
// Range: [1.0, 2.0]
174-
approx[1] = DECOMP_MATH_Sin(angle[0]) + 0xfff;
204+
approx[1] = MathSinInline(angle[0]) + 0xfff;
175205
angle[0] += 300;
176206

177207
// change all vector posZ
@@ -220,22 +250,22 @@ void DECOMP_RaceFlag_DrawSelf()
220250
local0 += 0x200;
221251
local2 += 200;
222252

223-
int sin0 = DECOMP_MATH_Sin(local0) + 0xfff;
224-
int sin2 = DECOMP_MATH_Sin(local2) + 0xfff;
253+
int sin0 = MathSinInline(local0) + 0xfff;
254+
int sin2 = MathSinInline(local2) + 0xfff;
225255

226256
// reset based on trig
227257
local1 = (sin0 * 0x20 >> 0xd) + 0x96;
228258
local3 = (sin2 * 0x40 >> 0xd) + 0xb4;
229259
}
230260

231261
// === Step 3 ===
232-
approx[0] = DECOMP_MATH_Sin(angle[0]) + 0xfff;
262+
approx[0] = MathSinInline(angle[0]) + 0xfff;
233263
approx[0] = approx[0] * local1;
234264
approx[0] = (approx[0] >> 0xd) + 0x280;
235265

236266
// === Step 4 ===
237267
angle[0] += 0xc80;
238-
lightL = DECOMP_MATH_Sin(angle[0]) + 0xfff;
268+
lightL = MathSinInline(angle[0]) + 0xfff;
239269

240270
// === Step 5 ===
241271
pos[0].vy = 0xfc72;
@@ -260,7 +290,7 @@ void DECOMP_RaceFlag_DrawSelf()
260290
j++, vect++)
261291
{
262292
// Range: [1.0, 2.0]
263-
approx[1] = DECOMP_MATH_Sin(angle[0]) + 0xfff;
293+
approx[1] = MathSinInline(angle[0]) + 0xfff;
264294
angle[0] += 300;
265295

266296
// change all vector posZ

0 commit comments

Comments
 (0)