Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maintenance] [th02] Score: Consolidate rendering functions
Part of P0278, funded by Yanga.
- Loading branch information
Showing
4 changed files
with
104 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// ZUN bloat: The divisor can never be 0. This separate function is just meant | ||
// to work around the resulting `Condition is always true/false` and | ||
// `Unreachable code` warnings. | ||
#ifndef gaiji_score_put | ||
inline score_t gaiji_score_divide( | ||
const score_t& score, const score_t& divisor, bool check_divisor | ||
) { | ||
if(check_divisor) { | ||
return (divisor ? ((score / divisor) % 10) : (score % 10)); | ||
} else { | ||
return ((score / divisor) % 10); | ||
} | ||
} | ||
#endif | ||
|
||
#define gaiji_score_put_update( \ | ||
gaiji, past_leading_zeroes, divisor, digit, score, check_divisor \ | ||
) { \ | ||
digit = gaiji_score_divide(score, divisor, check_divisor); \ | ||
divisor /= 10; \ | ||
gaiji = (gb_0_ + digit); \ | ||
if(digit) { \ | ||
past_leading_zeroes = true; \ | ||
} \ | ||
} | ||
|
||
#define gaiji_score_put(score, on_digit, check_divisor) { \ | ||
/* ZUN bloat: Initialized inside the loop. */ \ | ||
int gaiji = gb_0_; /* ACTUAL TYPE: gaiji_th02_t */ \ | ||
\ | ||
score_t divisor = 10000000; /* Must match SCORE_DIGITS! */ \ | ||
score_t digit; \ | ||
bool past_leading_zeroes = false; \ | ||
for(int i = 0; i < SCORE_DIGITS; i++) { \ | ||
gaiji_score_put_update( \ | ||
gaiji, past_leading_zeroes, divisor, digit, score, check_divisor \ | ||
); \ | ||
if(past_leading_zeroes) { \ | ||
on_digit(i, gaiji); \ | ||
} \ | ||
} \ | ||
} | ||
|
||
// ZUN bloat: Could have been merged into the function above. | ||
#define gaiji_score_put_digits(score, digits, on_digit) { \ | ||
int i; \ | ||
\ | ||
/* ZUN bloat: Initialized inside the loop. */ \ | ||
int gaiji = gb_0_; /* ACTUAL TYPE: gaiji_th02_t */ \ | ||
\ | ||
score_t divisor = 10000000; /* Must match SCORE_DIGITS! */ \ | ||
score_t digit; \ | ||
bool past_leading_zeroes = false; \ | ||
\ | ||
for(i = SCORE_DIGITS; i > digits; i--) { \ | ||
divisor /= 10; \ | ||
} \ | ||
for(i = 0; i < digits; i++) { \ | ||
gaiji_score_put_update( \ | ||
gaiji, past_leading_zeroes, divisor, digit, score, false \ | ||
); \ | ||
if(i == (digits - 1)) { \ | ||
past_leading_zeroes = true; \ | ||
} \ | ||
if(past_leading_zeroes) { \ | ||
on_digit(i, gaiji); \ | ||
} \ | ||
} \ | ||
} | ||
|
||
// ZUN bloat: Also equivalent to the first function. | ||
#define gaiji_score_put_to(left, score, on_digit_at) { \ | ||
int gaiji; /* ACTUAL TYPE: gaiji_th02_t */ \ | ||
score_t divisor = 10000000; /* Must match SCORE_DIGITS! */ \ | ||
score_t digit; \ | ||
bool past_leading_zeroes = false; \ | ||
tram_x_t x = left; \ | ||
while(x < (left + (SCORE_DIGITS * GAIJI_TRAM_W))) { \ | ||
gaiji_score_put_update( \ | ||
gaiji, past_leading_zeroes, divisor, digit, score, false \ | ||
); \ | ||
if(past_leading_zeroes) { \ | ||
on_digit_at(x, gaiji); \ | ||
} \ | ||
x += GAIJI_TRAM_W; \ | ||
} \ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters