mirror of https://github.com/nmlgc/ReC98.git
[Maintenance] [th01] Boss entrance rings: Move main code into a macro
Part of P0198, funded by Lmocinemod and Ember2528.
This commit is contained in:
parent
c3572c62a9
commit
dd8461e0bc
|
@ -36,12 +36,44 @@ inline long entrance_ring_radius(pixel_t base, unsigned int square_i) {
|
|||
for( \
|
||||
square_i = (1 * ENTRANCE_RING_SQUARES); \
|
||||
square_i < ((1 + ENTRANCE_RING_STACK) * ENTRANCE_RING_SQUARES); \
|
||||
i++ \
|
||||
square_i++ \
|
||||
) { \
|
||||
invert_lhs entrance_ring_invert(square_i, radius_base); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define entrance_rings_done(squares_offscreen) \
|
||||
(squares_offscreen >= (ENTRANCE_RING_STACK * ENTRANCE_RING_SQUARES))
|
||||
// Well, well, we'd *really* like call sites to use this macro within an `if`
|
||||
// statement. That makes it looks as if this macro is actually a function that
|
||||
// returns whether the animation is done or not. Unfortunately, the completion
|
||||
// condition is itself nested within a conditional branch. This only leaves
|
||||
// ugly workarounds:
|
||||
//
|
||||
// 1) Forcing calling sites to close a block they didn't open
|
||||
// 2) A fake lambda function in another macro parameter
|
||||
// 3) Using `goto` and jumping to a label (`entrance_rings_still_active`) that
|
||||
// we force the call site to define
|
||||
//
|
||||
// Option 3) doesn't introduce weird syntax and thus feels like the most
|
||||
// natural choice.
|
||||
#define entrance_rings_update_and_render( \
|
||||
radius_base, i, squares_offscreen, frame, radius_base_initial, frame_first \
|
||||
) \
|
||||
frame == frame_first) { \
|
||||
radius_base = radius_base_initial; \
|
||||
goto entrance_rings_still_active; \
|
||||
} else if(frame == (frame_first + 1)) { \
|
||||
entrance_rings_invert(i, {}, radius_base); \
|
||||
goto entrance_rings_still_active; \
|
||||
} else if((frame > (frame_first + 1)) && ((frame % 4) == 0)) { \
|
||||
/* "Un-invert" the previous frame */ \
|
||||
entrance_rings_invert(i, {}, radius_base); \
|
||||
\
|
||||
radius_base += 16; \
|
||||
squares_offscreen = 0; \
|
||||
\
|
||||
entrance_rings_invert(i, squares_offscreen +=, radius_base); \
|
||||
} else { \
|
||||
goto entrance_rings_still_active; \
|
||||
} \
|
||||
if(squares_offscreen >= (ENTRANCE_RING_STACK * ENTRANCE_RING_SQUARES)
|
||||
/// ------------------------------------------------
|
||||
|
|
|
@ -2648,22 +2648,14 @@ void sariel_main(void)
|
|||
random_seed = frame_rand;
|
||||
|
||||
while(1) {
|
||||
boss_phase_frame++;
|
||||
if(boss_phase_frame == 1) {
|
||||
entrance_ring_radius_base = 16;
|
||||
} else if(boss_phase_frame == 2) {
|
||||
entrance_rings_invert(i, {}, entrance_ring_radius_base);
|
||||
} else if((boss_phase_frame > 2) && ((boss_phase_frame % 4) == 0)) {
|
||||
// "Un-invert" the previous frame
|
||||
entrance_rings_invert(i, {}, entrance_ring_radius_base);
|
||||
#define frame_half boss_phase_frame
|
||||
|
||||
entrance_ring_radius_base += 16;
|
||||
unsigned int squares_offscreen = 0;
|
||||
unsigned int tmp;
|
||||
|
||||
entrance_rings_invert(
|
||||
i, squares_offscreen +=, entrance_ring_radius_base
|
||||
);
|
||||
if(entrance_rings_done(squares_offscreen)) {
|
||||
frame_half++;
|
||||
if(entrance_rings_update_and_render(
|
||||
entrance_ring_radius_base, i, tmp, frame_half, 16, 1
|
||||
)) {
|
||||
boss_phase = 1;
|
||||
phase.pattern_cur = 0;
|
||||
phase.ax.patterns_done = 0;
|
||||
|
@ -2675,12 +2667,13 @@ void sariel_main(void)
|
|||
wand_lowered_snap();
|
||||
wand_render_raise_both(true);
|
||||
birds_reset();
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(boss_phase_frame % 2) {
|
||||
entrance_rings_still_active:
|
||||
if(frame_half % 2) { // That's why we've renamed the variable
|
||||
frame_delay(1);
|
||||
}
|
||||
#undef frame_half
|
||||
}
|
||||
} else if(boss_phase == 1) {
|
||||
hud_hp_increment_render(initial_hp_rendered, boss_hp, boss_phase_frame);
|
||||
|
|
Loading…
Reference in New Issue