Skip to content

Commit

Permalink
butano: color-related H-Blank effects update fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
GValiente committed Oct 3, 2023
1 parent 2e4faf4 commit cbe04da
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 97 deletions.
1 change: 1 addition & 0 deletions butano/include/bn_documentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,7 @@
*
* * bn::display::size added.
* * Standard abort implemented.
* * Color-related H-Blank effects update fixed.
*
*
* @section changelog_15_5_0 15.5.0
Expand Down
9 changes: 8 additions & 1 deletion butano/src/bn_bg_palette_color_hbe_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ class bg_palette_color_hbe_handler

[[nodiscard]] static bool target_updated(intptr_t target_id, void*)
{
palettes_bank::commit_data commit_data = palettes_manager::bg_palettes_bank().retrieve_commit_data();
const palettes_bank& bg_palettes_bank = palettes_manager::bg_palettes_bank();

if(bg_palettes_bank.global_effects_updated())
{
return true;
}

palettes_bank::commit_data commit_data = bg_palettes_bank.retrieve_commit_data();

if(int count = commit_data.count)
{
Expand Down
9 changes: 8 additions & 1 deletion butano/src/bn_bg_palettes_transparent_color_hbe_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ class bg_palettes_transparent_color_hbe_handler

[[nodiscard]] static bool target_updated(intptr_t, void*)
{
palettes_bank::commit_data commit_data = palettes_manager::bg_palettes_bank().retrieve_commit_data();
const palettes_bank& bg_palettes_bank = palettes_manager::bg_palettes_bank();

if(bg_palettes_bank.global_effects_updated())
{
return true;
}

palettes_bank::commit_data commit_data = bg_palettes_bank.retrieve_commit_data();

if(commit_data.colors_ptr)
{
Expand Down
110 changes: 18 additions & 92 deletions butano/src/bn_palettes_bank.cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,7 @@ void palettes_bank::set_brightness(fixed brightness)

if(update)
{
_update = true;
_update_global_effects = true;

if(output_brightness.data())
{
_global_effects_enabled = true;
}
else
{
_check_global_effects_enabled();
}
_on_global_effect_updated(output_brightness.data());
}
}

Expand All @@ -490,17 +480,7 @@ void palettes_bank::set_contrast(fixed contrast)

if(update)
{
_update = true;
_update_global_effects = true;

if(output_contrast.data())
{
_global_effects_enabled = true;
}
else
{
_check_global_effects_enabled();
}
_on_global_effect_updated(output_contrast.data());
}
}

Expand All @@ -514,17 +494,7 @@ void palettes_bank::set_intensity(fixed intensity)

if(update)
{
_update = true;
_update_global_effects = true;

if(output_intensity.data())
{
_global_effects_enabled = true;
}
else
{
_check_global_effects_enabled();
}
_on_global_effect_updated(output_intensity.data());
}
}

Expand All @@ -535,17 +505,7 @@ void palettes_bank::set_inverted(bool inverted)

if(update)
{
_update = true;
_update_global_effects = true;

if(inverted)
{
_global_effects_enabled = true;
}
else
{
_check_global_effects_enabled();
}
_on_global_effect_updated(inverted);
}
}

Expand All @@ -559,17 +519,7 @@ void palettes_bank::set_grayscale_intensity(fixed intensity)

if(update)
{
_update = true;
_update_global_effects = true;

if(output_intensity.data())
{
_global_effects_enabled = true;
}
else
{
_check_global_effects_enabled();
}
_on_global_effect_updated(output_intensity.data());
}
}

Expand All @@ -583,17 +533,7 @@ void palettes_bank::set_hue_shift_intensity(fixed intensity)

if(update)
{
_update = true;
_update_global_effects = true;

if(output_intensity.data())
{
_global_effects_enabled = true;
}
else
{
_check_global_effects_enabled();
}
_on_global_effect_updated(output_intensity.data());
}
}

Expand All @@ -619,17 +559,7 @@ void palettes_bank::set_fade_intensity(fixed intensity)

if(update)
{
_update = true;
_update_global_effects = true;

if(output_intensity.data())
{
_global_effects_enabled = true;
}
else
{
_check_global_effects_enabled();
}
_on_global_effect_updated(output_intensity.data());
}
}

Expand All @@ -644,17 +574,7 @@ void palettes_bank::set_fade(color color, fixed intensity)

if(update)
{
_update = true;
_update_global_effects = true;

if(output_intensity.data())
{
_global_effects_enabled = true;
}
else
{
_check_global_effects_enabled();
}
_on_global_effect_updated(output_intensity.data());
}
}

Expand All @@ -667,6 +587,7 @@ void palettes_bank::update()
{
bool update_global_effects = _update_global_effects || _global_effects_enabled;
_update = false;
_global_effects_updated = _update_global_effects;
_update_global_effects = false;

if(update_global_effects)
Expand Down Expand Up @@ -748,6 +669,7 @@ void palettes_bank::reset_commit_data()
{
_first_index_to_commit = numeric_limits<int>::max();
_last_index_to_commit = 0;
_global_effects_updated = false;
}

void palettes_bank::fill_hblank_effect_colors(int id, const color* source_colors_ptr, uint16_t* dest_ptr) const
Expand Down Expand Up @@ -822,11 +744,15 @@ int palettes_bank::_first_bpp_4_palette_index() const
return hw::palettes::count();
}

void palettes_bank::_check_global_effects_enabled()
void palettes_bank::_on_global_effect_updated(bool active)
{
_global_effects_enabled = _inverted || fixed_t<5>(_brightness).data() || fixed_t<5>(_contrast).data() ||
fixed_t<5>(_intensity).data() || fixed_t<5>(_grayscale_intensity).data() ||
fixed_t<5>(_hue_shift_intensity).data() || fixed_t<5>(_fade_intensity).data();
_update = true;
_update_global_effects = true;

_global_effects_enabled = active || _inverted || fixed_t<5>(_brightness).data() ||
fixed_t<5>(_contrast).data() || fixed_t<5>(_intensity).data() ||
fixed_t<5>(_grayscale_intensity).data() || fixed_t<5>(_hue_shift_intensity).data() ||
fixed_t<5>(_fade_intensity).data();
}

void palettes_bank::_set_colors_bpp_impl(int id, const span<const color>& colors)
Expand Down
8 changes: 7 additions & 1 deletion butano/src/bn_palettes_bank.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ class palettes_bank

[[nodiscard]] commit_data retrieve_commit_data() const;

[[nodiscard]] bool global_effects_updated() const
{
return _global_effects_updated;
}

void reset_commit_data();

void fill_hblank_effect_colors(int id, const color* source_colors_ptr, uint16_t* dest_ptr) const;
Expand Down Expand Up @@ -245,14 +250,15 @@ class palettes_bank
bool _update = false;
bool _update_global_effects = false;
bool _global_effects_enabled = false;
bool _global_effects_updated = false;

[[nodiscard]] bool _same_colors(const span<const color>& colors, int id) const;

[[nodiscard]] int _bpp_8_slots_count() const;

[[nodiscard]] int _first_bpp_4_palette_index() const;

void _check_global_effects_enabled();
void _on_global_effect_updated(bool active);

void _set_colors_bpp_impl(int id, const span<const color>& colors);

Expand Down
9 changes: 8 additions & 1 deletion butano/src/bn_sprite_palette_color_hbe_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ class sprite_palette_color_hbe_handler

[[nodiscard]] static bool target_updated(intptr_t target_id, void*)
{
palettes_bank::commit_data commit_data = palettes_manager::sprite_palettes_bank().retrieve_commit_data();
const palettes_bank& sprite_palettes_bank = palettes_manager::sprite_palettes_bank();

if(sprite_palettes_bank.global_effects_updated())
{
return true;
}

palettes_bank::commit_data commit_data = sprite_palettes_bank.retrieve_commit_data();

if(int count = commit_data.count)
{
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.html

Large diffs are not rendered by default.

0 comments on commit cbe04da

Please sign in to comment.