Skip to content

Commit

Permalink
Make object_palette_copy_transform sticky
Browse files Browse the repository at this point in the history
This fixes the same credits flicker that PR 762
does, while still ensuring other transformers do
not get stuck on (which PR 756 set out to solve)
  • Loading branch information
Nopey committed Nov 9, 2024
1 parent 81bd510 commit fb56f35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/game/protos/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 14 additions & 2 deletions src/video/vga_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
typedef struct palette_transformer {
vga_palette_transform callback;
void *userdata;
bool sticky;
} palette_transformer;

typedef struct vga_state {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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!
*/
Expand Down
1 change: 1 addition & 0 deletions src/video/vga_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fb56f35

Please sign in to comment.