diff --git a/src/game/protos/object.c b/src/game/protos/object.c index 0ba20f3c4..f2c8e6787 100644 --- a/src/game/protos/object.c +++ b/src/game/protos/object.c @@ -460,7 +460,7 @@ void object_palette_transform(object *obj) { } if(obj->sprite_state.pal_tricks_off) { // BPO tag is on - vga_state_enable_palette_transform(object_palette_copy_transform, obj); + vga_state_enable_palette_transform_sticky(object_palette_copy_transform, obj); } else if(obj->sprite_state.pal_entry_count > 0 && obj->sprite_state.duration > 0) { // BPO tag is off vga_state_enable_palette_transform(object_scenewide_palette_transform, obj); } diff --git a/src/video/vga_state.c b/src/video/vga_state.c index 13f642517..8f0cfae3f 100644 --- a/src/video/vga_state.c +++ b/src/video/vga_state.c @@ -11,6 +11,7 @@ typedef struct palette_transformer { vga_palette_transform callback; void *userdata; + bool sticky; } palette_transformer; typedef struct vga_state { @@ -69,7 +70,8 @@ void vga_state_render(void) { // Run transformers on top. These may modify the current palette and change dirtiness state. for(unsigned int i = 0; i < state.transformer_count; i++) { - state.transformers[i].callback(&state.dmg_transform, &state.current, state.transformers[i].userdata); + damage_tracker *dmg = state.transformers[i].sticky ? &state.dmg_current : &state.dmg_transform; + state.transformers[i].callback(dmg, &state.current, state.transformers[i].userdata); } damage_combine(&state.dmg_current, &state.dmg_transform); damage_copy(&state.dmg_previous, &state.dmg_current); @@ -161,7 +163,8 @@ void vga_state_copy_base_palette_range(vga_index dst, vga_index src, vga_index c damage_set_range(&state.dmg_base, dst, dst + count); } -void vga_state_enable_palette_transform(vga_palette_transform transform_callback, void *userdata) { +static void vga_state_enable_palette_transform_impl(vga_palette_transform transform_callback, void *userdata, + bool sticky) { #ifndef NDEBUG for(unsigned int i = 0; i < state.transformer_count; i++) { if(state.transformers[i].callback == transform_callback && state.transformers[i].userdata == userdata) { @@ -173,9 +176,18 @@ void vga_state_enable_palette_transform(vga_palette_transform transform_callback assert(state.transformer_count < MAX_TRANSFORMER_COUNT - 1); state.transformers[state.transformer_count].callback = transform_callback; state.transformers[state.transformer_count].userdata = userdata; + state.transformers[state.transformer_count].sticky = sticky; state.transformer_count++; } +void vga_state_enable_palette_transform(vga_palette_transform transform_callback, void *userdata) { + vga_state_enable_palette_transform_impl(transform_callback, userdata, false); +} + +void vga_state_enable_palette_transform_sticky(vga_palette_transform transform_callback, void *userdata) { + vga_state_enable_palette_transform_impl(transform_callback, userdata, true); +} + /** * For debug use only! */ diff --git a/src/video/vga_state.h b/src/video/vga_state.h index 6bed17d30..181c82b5f 100644 --- a/src/video/vga_state.h +++ b/src/video/vga_state.h @@ -39,6 +39,7 @@ void vga_state_set_base_palette_range(vga_index start, vga_index count, vga_colo void vga_state_copy_base_palette_range(vga_index dst, vga_index src, vga_index count); void vga_state_enable_palette_transform(vga_palette_transform transform_callback, void *userdata); +void vga_state_enable_palette_transform_sticky(vga_palette_transform transform_callback, void *userdata); // Take debug snapshot of the current palette state. void vga_state_debug_screenshot(const char *filename);