From cacb9361c7378974bd52146d51e12fc736e67d27 Mon Sep 17 00:00:00 2001 From: nmlgc Date: Thu, 8 Oct 2020 12:55:30 +0200 Subject: [PATCH] [Decompilation] [th01] Skipping past the palette when loading .BOS files At least the upcoming player animation load function was smart enough to do that. Part of P0123, funded by Yanga. --- th01/formats/bos.hpp | 20 +++++++++++++++++--- th01/main/boss/entity_a.cpp | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/th01/formats/bos.hpp b/th01/formats/bos.hpp index f27b46d3..6f3b8828 100644 --- a/th01/formats/bos.hpp +++ b/th01/formats/bos.hpp @@ -29,7 +29,20 @@ struct bos_t { bos_image_t image[BOS_IMAGES_PER_SLOT]; }; -#define bos_header_load(that, plane_size, fn) \ +// Shared loading and freeing subfunctions +// --------------------------------------- + +// Separate function to work around the `Condition is always true/false` and +// `Unreachable code` warnings +inline void bos_header_load_palette(Palette4 &pal, bool load) { + if(load) { + arc_file_get_far(pal); + } else { + arc_file_seek(sizeof(spriteformat_header_t)); + } +} + +#define bos_header_load(that, plane_size, fn, needlessly_load_the_palette) \ union { \ bos_header_t outer; \ Palette4 pal; \ @@ -42,8 +55,8 @@ struct bos_t { that->vram_w = header.outer.vram_w; \ that->h = header.outer.h; \ that->bos_image_count = header.outer.inner.image_count; \ - plane_size = (vram_w * h); \ - arc_file_get_far(header.pal); // yeah, should have been a seek + plane_size = (that->vram_w * that->h); \ + bos_header_load_palette(header.pal, needlessly_load_the_palette); #define bos_image_new(image, plane_size) \ image.alpha = new dots16_t[plane_size / 2]; \ @@ -67,6 +80,7 @@ struct bos_t { bos_image_ptr_free(slot_ptr.image[image].planes.G); \ bos_image_ptr_free(slot_ptr.image[image].planes.E); \ } +// --------------------------------------- /// All functions that operate on this format are implemented redundantly for /// both CBossEntity and CBossAnim, with their own respective entity arrays. diff --git a/th01/main/boss/entity_a.cpp b/th01/main/boss/entity_a.cpp index b0eb79d9..868ba2bd 100644 --- a/th01/main/boss/entity_a.cpp +++ b/th01/main/boss/entity_a.cpp @@ -49,7 +49,7 @@ int CBossEntity::load(const char fn[PF_FN_LEN], int slot) { int plane_size; - bos_header_load(this, plane_size, fn); + bos_header_load(this, plane_size, fn, true); if(!bos_header_only) { bos_entity_free(slot); for(int i = 0; bos_image_count > i; i++) { @@ -612,7 +612,7 @@ int CBossAnim::load(const char fn[PF_FN_LEN], int slot) { int plane_size; - bos_header_load(this, plane_size, fn); + bos_header_load(this, plane_size, fn, true); if(!bos_header_only) { bos_anim_free(slot); for(int i = 0; bos_image_count > i; i++) {