[Debloating] [th01] .GRP: Replace flag globals with a parameter

Might be a bit controversial, but *having* to specify a flag also makes
it clearer where the hardware palette is *not* mutated.

Part of P0229, funded by Ember2528.
This commit is contained in:
nmlgc 2023-01-29 01:56:42 +01:00
parent 65a9276180
commit 18398a3293
11 changed files with 44 additions and 59 deletions

View File

@ -521,7 +521,7 @@ void verdict_animate_and_regist(void)
grp_palette_black_out(10);
graph_accesspage_func(1);
grp_put_palette_show(REGIST_BG_CLEARED);
grp_put(REGIST_BG_CLEARED, GPF_PALETTE_SHOW);
graph_copy_accessed_page_to_other();
graph_accesspage_func(0);

View File

@ -5,7 +5,7 @@
void pascal end_pics_load_palette_show(const char *fn)
{
graph_accesspage_func(1);
grp_put_palette_show(fn);
grp_put(fn, GPF_PALETTE_SHOW);
}
// Avoid symbol duplication...

View File

@ -14,9 +14,6 @@
// *Not* offsetof(PiHeader, palette)!
#define PI_PALETTE_OFFSET 0x12
extern bool16 flag_palette_show;
extern bool flag_grp_colorkey;
bool grp_palette_load(const char *fn)
{
if(!file_ropen(fn)) {
@ -41,18 +38,18 @@ bool grp_palette_load_show(const char *fn)
return false;
}
int grp_put_palette_show(const char *fn)
int grp_put(const char *fn, grp_put_flag_t flag)
{
extern int8_t* grp_buf;
int option = 0;
char ret;
grp_buf = new int8_t[GRP_BUFFER_SIZE];
if(flag_grp_colorkey == true) {
if(flag & GPF_COLORKEY) {
option = PILOAD_OPT_COLORKEY(15);
}
ret = PiLoad(fn, grp_buf, GRP_BUFFER_SIZE, 0, 0, 100, option);
if(flag_palette_show == true) {
if(flag & GPF_PALETTE_SHOW) {
grp_palette_load_show(fn);
} else {
grp_palette_load(fn);
@ -61,21 +58,3 @@ int grp_put_palette_show(const char *fn)
delete[] grp_buf;
return ret;
}
int grp_put(const char *fn)
{
flag_palette_show = false;
int ret = grp_put_palette_show(fn);
flag_palette_show = true;
return ret;
}
int grp_put_colorkey(const char *fn)
{
flag_grp_colorkey = true;
flag_palette_show = false;
int ret = grp_put_palette_show(fn);
flag_palette_show = true;
flag_grp_colorkey = false;
return ret;
}

View File

@ -16,6 +16,21 @@
///
/// More info on the original format: https://mooncore.eu/bunny/txt/pi-pic.htm
// Flags
// -----
typedef uint8_t grp_put_flag_t;
// Keeps the current hardware palette. Still updates [grp_palette] though!
static const grp_put_flag_t GPF_PALETTE_KEEP = (0 << 0);
// Sets the hardware palette to the one from the header of the displayed .GRP.
static const grp_put_flag_t GPF_PALETTE_SHOW = (1 << 0);
// Treats color #15 as transparent.
static const grp_put_flag_t GPF_COLORKEY = (1 << 1);
// -----
// Always updated by any of the .GRP loading or blitting functions.
extern Palette4 grp_palette;
@ -25,15 +40,8 @@ extern Palette4 grp_palette;
bool grp_palette_load_show(const char *fn);
// Displays the .GRP image loaded from [fn] on the currently accessed VRAM
// page, using the current hardware palette. Returns the return value from
// PiLoad.
int grp_put(const char *fn);
// Like grp_put(), but sets the hardware palette to the one in [fn]'s header.
int grp_put_palette_show(const char *fn);
// Like grp_put(), but treats color #15 as transparent.
int grp_put_colorkey(const char *fn);
// page, applying the given flags. Returns the return value from PiLoad.
int grp_put(const char *fn, grp_put_flag_t flag);
#if (BINARY == 'E')
extern int grp_palette_tone;

View File

@ -20,7 +20,6 @@
// ----
Palette4 grp_palette;
bool16 flag_palette_show = true;
// ----
// .PTN
@ -47,7 +46,6 @@ uint8_t planar_stream_count[GRX_COUNT];
#if (BINARY == 'E')
int grp_palette_tone = 100;
#endif
bool flag_grp_colorkey = false;
int8_t* grp_buf;
// ----------

View File

@ -253,7 +253,7 @@ void pascal near totle_pagetrans_animate(int)
void near totle_load_and_pagetrans_animate(void)
{
graph_accesspage_func(1);
grp_put("CLEAR3.grp");
grp_put("CLEAR3.grp", GPF_PALETTE_KEEP);
ptn_load(PTN_SLOT_NUMB, "numb.ptn");
graph_accesspage_func(0);
totle_pagetrans_animate(0);

View File

@ -352,7 +352,7 @@ void konngara_load_and_entrance(int8_t)
text_fillca(' ', (TX_BLACK | TX_REVERSE));
// graph_accesspage_func(0);
grp_put_palette_show(SCROLL_BG_FN);
grp_put(SCROLL_BG_FN, GPF_PALETTE_SHOW);
// ZUN bug: On its own, this call at this position in the code would just
// be redundant as the stage palette is never used here. After all, you
@ -368,7 +368,7 @@ void konngara_load_and_entrance(int8_t)
stageobjs_init_and_render(BOSS_STAGE);
graph_accesspage_func(1);
grp_put_palette_show("boss8_a1.grp");
grp_put("boss8_a1.grp", GPF_PALETTE_SHOW);
// The stage_palette_set() call should have been here.
graph_accesspage_func(0);
@ -481,10 +481,10 @@ void konngara_load_and_entrance(int8_t)
// -------------------------------
siddham_col_white();
grp_put_colorkey("boss8_d1.grp");
grp_put_colorkey("boss8_d2.grp");
grp_put_colorkey("boss8_d3.grp");
grp_put_colorkey("boss8_d4.grp");
grp_put("boss8_d1.grp", GPF_COLORKEY);
grp_put("boss8_d2.grp", GPF_COLORKEY);
grp_put("boss8_d3.grp", GPF_COLORKEY);
grp_put("boss8_d4.grp", GPF_COLORKEY);
for(j = 0; j < RGB4::Range; j++) {
siddham_col_white_in_step();
@ -1787,7 +1787,7 @@ void konngara_main(void)
printf("\x1B)3"); // Enter graph mode
text_fill_black(j, i);
grp_put_palette_show(SCROLL_BG_FN);
grp_put(SCROLL_BG_FN, GPF_PALETTE_SHOW);
z_palette_set_black(j, i);
printf("\x1B)0"); // Back to regular kanji mode

View File

@ -313,8 +313,8 @@ void sariel_entrance(int8_t)
text_fillca(' ', (TX_BLACK | TX_REVERSE));
/* graph_accesspage_func(0); */ grp_put_palette_show("boss6_l.grp");
/**/graph_accesspage_func(1)/**/; grp_put_palette_show("boss6_h.grp");
/* graph_accesspage_func(0); */ grp_put("boss6_l.grp", GPF_PALETTE_SHOW);
/**/graph_accesspage_func(1)/**/; grp_put("boss6_h.grp", GPF_PALETTE_SHOW);
graph_accesspage_func(0);
stageobjs_init_and_render(BOSS_STAGE);
@ -336,7 +336,7 @@ void sariel_entrance(int8_t)
// ------
graph_accesspage_func(1);
grp_put_palette_show(BG_IMAGES[0]);
grp_put(BG_IMAGES[0], GPF_PALETTE_SHOW);
graph_accesspage_func(0);
pagetrans_diagonal_8x8(40);
@ -1277,7 +1277,7 @@ void pascal near bg_transition(int image_id_new)
z_vsync_wait_and_scrollup(0);
graph_accesspage_func(1);
grp_put_palette_show(BG_IMAGES[image_id_new]);
grp_put(BG_IMAGES[image_id_new], GPF_PALETTE_SHOW);
graph_copy_accessed_page_to_other();
stage_palette_set(z_Palettes);
@ -2775,13 +2775,13 @@ entrance_rings_still_active:
// boss6.grp is not part of the game? Might have been a defeat graphic.
graph_accesspage_func(1);
grp_put_palette_show("boss6.grp");
grp_put("boss6.grp", GPF_PALETTE_SHOW);
z_palette_set_show(0xF, 0x0, 0x0, 0x0);
boss_palette_snap();
graph_copy_accessed_page_to_other();
graph_accesspage_func(1);
grp_put("boss6_a5.grp");
grp_put("boss6_a5.grp", GPF_PALETTE_KEEP);
graph_accesspage_func(0);
while(1) {
@ -2814,7 +2814,7 @@ entrance_rings_still_active:
graph_accesspage_func(1);
mdrv2_bgm_load("syugen.MDT");
mdrv2_bgm_play();
grp_put_palette_show("boss6_a6.grp");
grp_put("boss6_a6.grp", GPF_PALETTE_SHOW);
z_palette_set_show(COL_FORM2_PULSE, 0x0, 0x0, 0x0);
graph_copy_accessed_page_to_other();
hud_rerender();
@ -2929,7 +2929,7 @@ entrance_rings_still_active:
}
} else if(boss_phase == PHASE_FORM2_DEFEATED) {
graph_accesspage_func(1);
grp_put_palette_show("boss6_a6.grp");
grp_put("boss6_a6.grp", GPF_PALETTE_SHOW);
// Actually a different color inside the .GRP! Would have been nicer to
// reuse the previous state of the color from above.

View File

@ -348,7 +348,7 @@ void stage_entrance(int stage_id, const char* bg_fn, bool16 clear_vram_page_0)
text_color_reset();
if(strcmp(bg_fn, "empty.grf")) {
grp_put_palette_show(bg_fn);
grp_put(bg_fn, GPF_PALETTE_SHOW);
}
stage_palette_set(z_Palettes);

View File

@ -87,9 +87,9 @@ void pascal near str_from_swapped_kanji(
graph_accesspage_func(1); \
\
if(stage_num_or_scoredat_constant < SCOREDAT_NOT_CLEARED) { \
grp_put_palette_show("game_o.grp"); \
grp_put("game_o.grp", GPF_PALETTE_SHOW); \
} else { \
grp_put(REGIST_BG_CLEARED); \
grp_put(REGIST_BG_CLEARED, GPF_PALETTE_KEEP); \
} \
graph_copy_accessed_page_to_other(); \
z_palette_black_in(); \

View File

@ -312,10 +312,10 @@ void title_init(void)
mdrv2_bgm_load("reimu.mdt");
mdrv2_bgm_play();
graph_accesspage_func(1);
grp_put_palette_show("REIIDEN2.grp");
grp_put("REIIDEN2.grp", GPF_PALETTE_SHOW);
z_palette_black();
graph_copy_accessed_page_to_other();
grp_put("REIIDEN3.grp");
grp_put("REIIDEN3.grp", GPF_PALETTE_KEEP);
graph_accesspage_func(0);
z_palette_black_in();
frame_delay(100);
@ -328,7 +328,7 @@ void title_window_put(void)
graph_accesspage_func(1);
graph_copy_accessed_page_to_other();
graph_accesspage_func(0);
grp_put_colorkey("op_win.grp");
grp_put("op_win.grp", GPF_COLORKEY);
graph_copy_accessed_page_to_other();
}