mirror of https://github.com/nmlgc/ReC98.git
[Decompilation] Move palette loops to common macros
You'd really want to overload `operator =` for those. Part of P0165, funded by Ember2528.
This commit is contained in:
parent
629bf7b08e
commit
7cc0189439
19
pc98.h
19
pc98.h
|
@ -117,6 +117,25 @@ typedef int8_t uint4_t;
|
|||
|
||||
typedef RGB<uint4_t, 16> RGB4;
|
||||
typedef Palette<RGB4> Palette4;
|
||||
|
||||
#define palette_foreach(tmp_col, tmp_comp, func) { \
|
||||
for(tmp_col = 0; tmp_col < COLOR_COUNT; tmp_col++) { \
|
||||
for(tmp_comp = 0; tmp_comp < COMPONENT_COUNT; tmp_comp++) { \
|
||||
func \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
// Sets all components of all colors to the given grayscale [value].
|
||||
#define palette_set_grayscale(dst, value, tmp_col, tmp_comp) \
|
||||
palette_foreach(tmp_col, tmp_comp, { \
|
||||
dst[tmp_col].v[tmp_comp] = value; \
|
||||
})
|
||||
|
||||
#define palette_copy(dst, src, tmp_col, tmp_comp) \
|
||||
palette_foreach(tmp_col, tmp_comp, { \
|
||||
dst[col].v[comp] = src[col].v[comp]; \
|
||||
})
|
||||
#endif
|
||||
/// --------
|
||||
|
||||
|
|
|
@ -58,11 +58,9 @@ int getkanji(FILE *fp)
|
|||
|
||||
void grp_palette_set_all(const Palette4& pal)
|
||||
{
|
||||
for(int col = 0; col < COLOR_COUNT; col++) {
|
||||
for(int comp = 0; comp < COMPONENT_COUNT; comp++) {
|
||||
grp_palette[col].v[comp] = pal[col].v[comp];
|
||||
}
|
||||
}
|
||||
int col;
|
||||
int comp;
|
||||
palette_copy(grp_palette, pal, col, comp);
|
||||
}
|
||||
|
||||
int grp_put_palette_show(const char *fn)
|
||||
|
|
|
@ -44,19 +44,16 @@ void z_palette_white_in(void);
|
|||
void z_palette_black_out(void);
|
||||
void z_palette_white_out(void);
|
||||
|
||||
#define z_Palettes_set_func_and_show(tmp_col, tmp_comp, func) \
|
||||
for(tmp_col = 0; tmp_col < COLOR_COUNT; tmp_col++) { \
|
||||
for(tmp_comp = 0; tmp_comp < COMPONENT_COUNT; tmp_comp++) { \
|
||||
func \
|
||||
} \
|
||||
} \
|
||||
z_palette_set_all_show(z_Palettes);
|
||||
#define z_Palettes_set_func_and_show(tmp_col, tmp_comp, func) { \
|
||||
palette_foreach(tmp_col, tmp_comp, func); \
|
||||
z_palette_set_all_show(z_Palettes); \
|
||||
}
|
||||
|
||||
// Sets all colors in both the hardware palette and z_Palettes to #000.
|
||||
#define z_palette_set_black(tmp_col, tmp_comp) \
|
||||
z_Palettes_set_func_and_show(tmp_col, tmp_comp, { \
|
||||
z_Palettes[tmp_col].v[tmp_comp] = 0; \
|
||||
})
|
||||
#define z_palette_set_black(tmp_col, tmp_comp) { \
|
||||
palette_set_grayscale(z_Palettes, 0, tmp_col, tmp_comp); \
|
||||
z_palette_set_all_show(z_Palettes); \
|
||||
}
|
||||
|
||||
// Performs a single black-out step.
|
||||
#define z_palette_black_out_step(tmp_col, tmp_comp) \
|
||||
|
|
|
@ -75,17 +75,15 @@ void pagetrans_diagonal_8x8_with_palette(
|
|||
: (tip_top + INTERLEAVE_H);
|
||||
|
||||
if((frame % (FRAME_COUNT / COLOR_COUNT)) == 0) {
|
||||
for(col = 0; col < COLOR_COUNT; col++) {
|
||||
// Not identical to the ramping loop in z_palette_fade_from()!
|
||||
for(comp = 0; comp < COMPONENT_COUNT; comp++) {
|
||||
palette_foreach(col, comp, {
|
||||
if(pal_cur[col].v[comp] != pal_target[col].v[comp]) {
|
||||
pal_cur.colors[col].v[comp] +=
|
||||
(pal_cur[col].v[comp] > pal_target[col].v[comp])
|
||||
? -1
|
||||
: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
z_palette_set_all_show(pal_cur);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
// The intended palette for a boss, with no effects applied.
|
||||
extern Palette4 boss_palette;
|
||||
|
||||
#define boss_palette_snap_inlined() \
|
||||
for(int col = 0; col < COLOR_COUNT; col++) { \
|
||||
for(int comp = 0; comp < COMPONENT_COUNT; comp++) { \
|
||||
boss_palette[col].v[comp] = z_Palettes[col].v[comp]; \
|
||||
} \
|
||||
}
|
||||
#define boss_palette_snap_inlined() { \
|
||||
int col; \
|
||||
int comp; \
|
||||
palette_copy(boss_palette, z_Palettes, col, comp); \
|
||||
}
|
||||
|
||||
// Overwrites [boss_palette] with [z_Palettes].
|
||||
void boss_palette_snap(void);
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
void stage_palette_set(const Palette4 &pal)
|
||||
{
|
||||
for(int col = 0; col < COLOR_COUNT; col++) {
|
||||
for(int comp = 0; comp < COMPONENT_COUNT; comp++) {
|
||||
stage_palette[col].v[comp] = pal[col].v[comp];
|
||||
}
|
||||
}
|
||||
int col;
|
||||
int comp;
|
||||
palette_copy(stage_palette, pal, col, comp);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue