@@ -92,9 +92,11 @@ void DECOMP_RaceFlag_DrawSelf()
9292 local3 = data .checkerFlagVariables [3 ];
9393 local4 = data .checkerFlagVariables [4 ];
9494
95- // vertical strips
9695 toggle = 0 ;
97- for (column = 0 ; column < 36 ; column ++ )
96+
97+ // === First Loop Iteration ===
98+ // Remove 36*10 branching instructions,
99+ // Reduces clock from ~150 to ~120
98100 {
99101#ifdef REBUILD_PC
100102 posL = & scratchpadBuf [(toggle * 0x78 / 4 ) - 1 ];
@@ -107,10 +109,7 @@ void DECOMP_RaceFlag_DrawSelf()
107109#endif
108110
109111 // === Step 1 ===
110- int stepRate = 0x40 ;
111- if (column == 0 )
112- stepRate = gGT -> elapsedTimeMS ;
113-
112+ int stepRate = gGT -> elapsedTimeMS ;
114113 local4 += local3 * stepRate ;
115114 angle [0 ] = (int )local4 >> 5 ;
116115
@@ -147,36 +146,112 @@ void DECOMP_RaceFlag_DrawSelf()
147146 pos [2 ].vy = 0xfd2e ;
148147
149148 // === Step 6 ===
150- if (column == 0 )
149+ data .checkerFlagVariables [0 ] = local0 ;
150+ data .checkerFlagVariables [1 ] = local1 ;
151+ data .checkerFlagVariables [2 ] = local2 ;
152+ data .checkerFlagVariables [3 ] = local3 ;
153+ data .checkerFlagVariables [4 ] = local4 ;
154+
155+ time = sdata -> RaceFlag_ElapsedTime >> 5 ;
156+ angle [0 ] = time ;
157+
158+ flagPos = sdata -> RaceFlag_Position ;
159+ flagPos = -0xbbe - flagPos ;
160+ pos [0 ].vx = flagPos ;
161+ pos [1 ].vx = flagPos ;
162+ pos [2 ].vx = flagPos ;
163+
164+ i = 0 ;
165+ // === Step 7 ===
166+ for (row = 0 ; row < 10 ; row ++ )
151167 {
152- data .checkerFlagVariables [0 ] = local0 ;
153- data .checkerFlagVariables [1 ] = local1 ;
154- data .checkerFlagVariables [2 ] = local2 ;
155- data .checkerFlagVariables [3 ] = local3 ;
156- data .checkerFlagVariables [4 ] = local4 ;
168+ for (
169+ j = 0 , vect = & pos [0 ];
170+ j < 3 ;
171+ j ++ , vect ++ )
172+ {
173+ // Range: [1.0, 2.0]
174+ approx [1 ] = DECOMP_MATH_Sin (angle [0 ]) + 0xfff ;
175+ angle [0 ] += 300 ;
176+
177+ // change all vector posZ
178+ vect -> vz = (short )approx [0 ] + (short )(approx [1 ] * 0x20 >> 0xd );
179+ }
180+
181+ gte_ldv3 (& pos [0 ], & pos [1 ], & pos [2 ]);
182+ gte_rtpt ();
183+
184+ pos [0 ].vy += 0x11a ;
185+ pos [1 ].vy += 0x11a ;
186+ pos [2 ].vy += 0x11a ;
157187
158- time = sdata -> RaceFlag_ElapsedTime >> 5 ;
159- angle [0 ] = time ;
160-
161- flagPos = sdata -> RaceFlag_Position ;
162- flagPos = -0xbbe - flagPos ;
163- pos [0 ].vx = flagPos ;
164- pos [1 ].vx = flagPos ;
165- pos [2 ].vx = flagPos ;
188+ gte_stsxy3 ((long * )(posL + 1 ), (long * )(posL + 2 ), (long * )(posL + 3 ));
189+ posL += 3 ;
166190 }
191+ }
192+
193+
194+ // === Rest of Iterations ===
195+ // Now executing without branching
196+ for (column = 1 ; column < 36 ; column ++ )
197+ {
198+ #ifdef REBUILD_PC
199+ posL = & scratchpadBuf [(toggle * 0x78 / 4 ) - 1 ];
200+ toggle = toggle ^ 1 ;
201+ posR = & scratchpadBuf [(toggle * 0x78 / 4 )];
202+ #else
203+ posL = (u_int * )((0x1f800000 + toggle * 0x78 ) - 4 );
204+ toggle = toggle ^ 1 ;
205+ posR = (u_int * )(0x1f800000 + toggle * 0x78 );
206+ #endif
207+
208+ // === Step 1 ===
209+ int stepRate = 0x40 ;
210+ local4 += local3 * stepRate ;
211+ angle [0 ] = (int )local4 >> 5 ;
167212
168- else
213+ // === Step 2 ===
214+ if (0xfff < angle [0 ])
169215 {
170- time += 0x100 ;
171- angle [0 ] = time ;
216+ // reset counter
217+ local4 &= 0x1ffff ;
218+ angle [0 ] = (int )local4 >> 5 ;
172219
173- pos [0 ].vx += 100 ;
174- pos [1 ].vx += 100 ;
175- pos [2 ].vx += 100 ;
220+ local0 += 0x200 ;
221+ local2 += 200 ;
222+
223+ int sin0 = DECOMP_MATH_Sin (local0 ) + 0xfff ;
224+ int sin2 = DECOMP_MATH_Sin (local2 ) + 0xfff ;
225+
226+ // reset based on trig
227+ local1 = (sin0 * 0x20 >> 0xd ) + 0x96 ;
228+ local3 = (sin2 * 0x40 >> 0xd ) + 0xb4 ;
176229 }
177230
231+ // === Step 3 ===
232+ approx [0 ] = DECOMP_MATH_Sin (angle [0 ]) + 0xfff ;
233+ approx [0 ] = approx [0 ] * local1 ;
234+ approx [0 ] = (approx [0 ] >> 0xd ) + 0x280 ;
235+
236+ // === Step 4 ===
237+ angle [0 ] += 0xc80 ;
238+ lightL = DECOMP_MATH_Sin (angle [0 ]) + 0xfff ;
239+
240+ // === Step 5 ===
241+ pos [0 ].vy = 0xfc72 ;
242+ pos [1 ].vy = 0xfcd0 ;
243+ pos [2 ].vy = 0xfd2e ;
244+
245+ // === Step 6 ===
246+ time += 0x100 ;
247+ angle [0 ] = time ;
248+
249+ pos [0 ].vx += 100 ;
250+ pos [1 ].vx += 100 ;
251+ pos [2 ].vx += 100 ;
252+
178253 i = 0 ;
179- // === Step 8 ===
254+ // === Step 7 ===
180255 for (row = 0 ; row < 10 ; row ++ )
181256 {
182257 for (
@@ -201,12 +276,6 @@ void DECOMP_RaceFlag_DrawSelf()
201276
202277 gte_stsxy3 ((long * )(posL + 1 ), (long * )(posL + 2 ), (long * )(posL + 3 ));
203278
204- if (column == 0 )
205- {
206- posL += 3 ;
207- continue ;
208- }
209-
210279 // ============================
211280
212281 j = 0 ;
@@ -232,14 +301,12 @@ void DECOMP_RaceFlag_DrawSelf()
232301 }
233302
234303 u_char colorR = RaceFlag_CalculateBrightness (lightR , boolDark );
235- u_int rgbR = (colorR ) | (colorR << 8 ) | (colorR << 16 );
236- * (int * )& p -> r0 = rgbR ;
237- * (int * )& p -> r2 = rgbR ;
304+ setRGB0 (p , colorR , colorR , colorR );
305+ * (int * )& p -> r2 = * (int * )& p -> r0 ;
238306
239307 u_char colorL = RaceFlag_CalculateBrightness (lightL , boolDark );
240- u_int rgbL = (colorL ) | (colorL << 8 ) | (colorL << 16 );
241- * (int * )& p -> r1 = rgbL ;
242- * (int * )& p -> r3 = rgbL ;
308+ setRGB1 (p , colorL , colorL , colorL );
309+ * (int * )& p -> r3 = * (int * )& p -> r1 ;
243310
244311 // positions
245312 * (int * )& p -> x0 = posR [0 ];
0 commit comments