From 4f63210c8a7102138eb3c1a5ee46cd232efc8ef9 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Sun, 30 Jan 2022 00:30:33 +0100 Subject: [PATCH] [Maintenance] [th01] Move boss entity loading calls next to their freeing calls With loading and freeing code physically close together, it almost looks like C++ classes. Part of P0174, funded by Ember2528. --- th01/main/boss/b10j.cpp | 26 +++++++++++++++++--------- th01/main/boss/b15m.cpp | 38 +++++++++++++++++++++++--------------- th01/main/boss/b20j.cpp | 14 +++++++++----- th01/main/boss/b20m.cpp | 37 ++++++++++++++++++++----------------- 4 files changed, 69 insertions(+), 46 deletions(-) diff --git a/th01/main/boss/b10j.cpp b/th01/main/boss/b10j.cpp index 173759cd..65ef0995 100644 --- a/th01/main/boss/b10j.cpp +++ b/th01/main/boss/b10j.cpp @@ -57,6 +57,15 @@ extern uint8_t spreadin_interval; // Sprite pixels to spread in per frame, in one half of Mima's sprite extern uint8_t spreadin_speed; +// File names +// ---------- + +extern const char boss3_1_bos[]; +extern const char boss3_2_bos[]; +extern const char boss3_grp_0[]; +extern const char boss5_gr_grc[]; +// ---------- + // Entities // -------- @@ -71,7 +80,12 @@ enum anim_cel_t { #define ent_still boss_entities[0] #define ent_anim boss_entities[1] -static inline void ent_free(void) { +inline void mima_ent_load(void) { + ent_still.load(boss3_1_bos, 0); + ent_anim.load(boss3_2_bos, 1); +} + +inline void mima_ent_free(void) { bos_entity_free(0); bos_entity_free(1); } @@ -89,16 +103,10 @@ static const int BG_ENT_OFFSET = 3; void mima_load(void) { - extern const char boss3_1_bos[]; - extern const char boss3_2_bos[]; - extern const char boss3_grp_0[]; - extern const char boss5_gr_grc[]; - int col; int comp; - ent_still.load(boss3_1_bos, 0); - ent_anim.load(boss3_2_bos, 1); + mima_ent_load(); grp_palette_load_show(boss3_grp_0); palette_copy(boss_post_defeat_palette, z_Palettes, col, comp); void mima_setup(void); @@ -310,7 +318,7 @@ void mima_setup(void) void mima_free(void) { - ent_free(); + mima_ent_free(); ptn_free(PTN_SLOT_BG_ENT); ptn_free(PTN_SLOT_MISSILE); } diff --git a/th01/main/boss/b15m.cpp b/th01/main/boss/b15m.cpp index 22ba5a1f..0be5d1da 100644 --- a/th01/main/boss/b15m.cpp +++ b/th01/main/boss/b15m.cpp @@ -57,6 +57,15 @@ extern bool16 invincible; extern bool16 wave_teleport_done; extern bool initial_hp_rendered; +// File names +// ---------- + +extern const char boss5_bos[]; +extern const char boss5_2_bos[]; +extern const char boss5_3_bos[]; +extern const char boss5_gr_grc[]; +// ---------- + // Entities // -------- @@ -74,17 +83,23 @@ enum still_or_wave_cel_t { #define ent_bat boss_entities[2] +inline void elis_ent_load(void) { + ent_still_or_wave.load(boss5_bos, 0); + ent_attack.load(boss5_2_bos, 1); + ent_bat.load(boss5_3_bos, 2); +} + +inline void elis_ent_free(void) { + bos_entity_free(0); + bos_entity_free(1); + bos_entity_free(2); +} + inline void ent_attack_sync_with_still_or_wave(void) { ent_attack.pos_cur_set( ent_still_or_wave.cur_left, ent_still_or_wave.cur_top ); } - -static inline void ent_free(void) { - bos_entity_free(0); - bos_entity_free(1); - bos_entity_free(2); -} // -------- // .PTN @@ -137,16 +152,9 @@ void girl_bg_put(int unncessary_parameter_that_still_needs_to_be_1_or_2) void elis_load(void) { - extern const char boss5_bos[]; - extern const char boss5_2_bos[]; - extern const char boss5_3_bos[]; - extern const char boss5_gr_grc[]; - pellet_interlace = true; Pellets.unknown_seven = 7; - ent_still_or_wave.load(boss5_bos, 0); - ent_attack.load(boss5_2_bos, 1); - ent_bat.load(boss5_3_bos, 2); + elis_ent_load(); grc_load(GRC_SLOT_BOSS_1, boss5_gr_grc); ptn_new(PTN_SLOT_BG_ENT, ((GIRL_W / PTN_W) * (GIRL_H / PTN_H))); Missiles.load(PTN_SLOT_MISSILE); @@ -197,7 +205,7 @@ void elis_setup(void) void elis_free(void) { - ent_free(); + elis_ent_free(); grc_free(GRC_SLOT_BOSS_1); ptn_free(PTN_SLOT_BG_ENT); ptn_free(PTN_SLOT_MISSILE); diff --git a/th01/main/boss/b20j.cpp b/th01/main/boss/b20j.cpp index 43ad86cc..26713c98 100644 --- a/th01/main/boss/b20j.cpp +++ b/th01/main/boss/b20j.cpp @@ -142,7 +142,13 @@ static bool16 face_direction_can_change = true; #define ent_face_closed_or_glare boss_entities[1] #define ent_face_aim boss_entities[2] -static inline void ent_free(void) { +inline void konngara_ent_load(void) { + ent_head.load("boss8_1.bos", 0); + ent_face_closed_or_glare.load("boss8_e1.bos", 1); + ent_face_aim.load("boss8_e2.bos", 2); +} + +inline void konngara_ent_free(void) { bos_entity_free(0); bos_entity_free(1); bos_entity_free(2); @@ -367,9 +373,7 @@ void konngara_load_and_entrance(int8_t) z_palette_set_black(j, i); text_fillca(' ', TX_WHITE); - ent_head.load("boss8_1.bos", 0); - ent_face_closed_or_glare.load("boss8_e1.bos", 1); - ent_face_aim.load("boss8_e2.bos", 2); + konngara_ent_load(); // Decelerating scroll // ------------------- @@ -506,7 +510,7 @@ void konngara_setup(void) // Happens to be entirely protected to double frees. Yes, this matters. void konngara_free(void) { - ent_free(); + konngara_ent_free(); for(int i = 0; i < 7; i++) { grx_free(i); } diff --git a/th01/main/boss/b20m.cpp b/th01/main/boss/b20m.cpp index 39dc2b6d..24f7c0ba 100644 --- a/th01/main/boss/b20m.cpp +++ b/th01/main/boss/b20m.cpp @@ -54,20 +54,6 @@ extern bool16 invincible; extern int invincibility_frame; extern bool initial_hp_rendered; -// Entities (and animations) -// -------- - -#define ent_shield boss_entities[0] -#define anm_dress boss_anims[0] -#define anm_wand boss_anims[1] -// -------- - -// .PTN -// ---- - -static const main_ptn_slot_t PTN_SLOT_BG_ENT = PTN_SLOT_BOSS_1; -// ---- - // File names // ---------- @@ -86,6 +72,25 @@ extern const char boss6gr3_grc[]; extern const char boss6gr4_grc[]; // ---------- +// Entities (and animations) +// -------- + +#define ent_shield boss_entities[0] +#define anm_dress boss_anims[0] +#define anm_wand boss_anims[1] + +inline void sariel_ent_load(void) { + ent_shield.load(boss6_1_bos, 0); + anm_wand.load(boss6_2_bos, 0); + anm_dress.load(boss6_3_bos, 1); +} +// -------- + +// .PTN +// ---- + +static const main_ptn_slot_t PTN_SLOT_BG_ENT = PTN_SLOT_BOSS_1; +// ---- #define select_for_rank sariel_select_for_rank #include "th01/main/select_r.cpp" @@ -128,9 +133,7 @@ void sariel_entrance(int8_t) void sariel_load_and_init(void) { - ent_shield.load(boss6_1_bos, 0); - anm_wand.load(boss6_2_bos, 0); - anm_dress.load(boss6_3_bos, 1); + sariel_ent_load(); grc_load(GRC_SLOT_BOSS_1, boss6gr1_grc); grc_load(GRC_SLOT_BOSS_2, boss6gr2_grc); grc_load(GRC_SLOT_BOSS_3, boss6gr3_grc);