From 9be58181320bae8b83cb3bd6b40ca2c16d9619cc Mon Sep 17 00:00:00 2001 From: Gustavo Valiente Date: Thu, 3 Dec 2020 16:29:40 +0100 Subject: [PATCH] butano: h-blank effects optimized (it fixes world_map example flickering) --- butano/hw/include/bn_hw_hblank_effects.h | 10 ++ .../hw/src/bn_hw_hblank_effects.bn_iwram.cpp | 104 ++++++++++++++++-- butano/include/bn_documentation.h | 5 +- butano/src/bn_hblank_effects_manager.cpp | 2 + docs/changelog.html | 4 +- 5 files changed, 113 insertions(+), 12 deletions(-) diff --git a/butano/hw/include/bn_hw_hblank_effects.h b/butano/hw/include/bn_hw_hblank_effects.h index 15bb5d295..e2a1eff9e 100644 --- a/butano/hw/include/bn_hw_hblank_effects.h +++ b/butano/hw/include/bn_hw_hblank_effects.h @@ -17,6 +17,11 @@ namespace bn::hw::hblank_effects public: const uint16_t* src; volatile uint16_t* dest; + + void update(unsigned vcount) + { + *dest = src[vcount]; + } }; class uint32_entry @@ -25,6 +30,11 @@ namespace bn::hw::hblank_effects public: const unsigned* src; volatile unsigned* dest; + + void update(unsigned vcount) + { + *dest = src[vcount]; + } }; class entries diff --git a/butano/hw/src/bn_hw_hblank_effects.bn_iwram.cpp b/butano/hw/src/bn_hw_hblank_effects.bn_iwram.cpp index 20b619169..cb8f8bf65 100644 --- a/butano/hw/src/bn_hw_hblank_effects.bn_iwram.cpp +++ b/butano/hw/src/bn_hw_hblank_effects.bn_iwram.cpp @@ -44,21 +44,109 @@ void _intr() entries* entries_ptr = data.entries_ptr; uint16_entry* uint16_entries = entries_ptr->uint16_entries; - int uint16_entries_count = entries_ptr->uint16_entries_count; - for(int index = 0; index < uint16_entries_count; ++index) + switch(entries_ptr->uint16_entries_count) { - uint16_entry& entry = uint16_entries[index]; - *entry.dest = entry.src[vcount]; + + case 0: + break; + + case 1: + uint16_entries[0].update(vcount); + break; + + case 2: + uint16_entries[0].update(vcount); + uint16_entries[1].update(vcount); + break; + + case 3: + uint16_entries[0].update(vcount); + uint16_entries[1].update(vcount); + uint16_entries[2].update(vcount); + break; + + case 4: + uint16_entries[0].update(vcount); + uint16_entries[1].update(vcount); + uint16_entries[2].update(vcount); + uint16_entries[3].update(vcount); + break; + + case 5: + uint16_entries[0].update(vcount); + uint16_entries[1].update(vcount); + uint16_entries[2].update(vcount); + uint16_entries[3].update(vcount); + uint16_entries[4].update(vcount); + break; + + case 6: + uint16_entries[0].update(vcount); + uint16_entries[1].update(vcount); + uint16_entries[2].update(vcount); + uint16_entries[3].update(vcount); + uint16_entries[4].update(vcount); + uint16_entries[5].update(vcount); + break; + + case 7: + uint16_entries[0].update(vcount); + uint16_entries[1].update(vcount); + uint16_entries[2].update(vcount); + uint16_entries[3].update(vcount); + uint16_entries[4].update(vcount); + uint16_entries[5].update(vcount); + uint16_entries[6].update(vcount); + break; + + case 8: + uint16_entries[0].update(vcount); + uint16_entries[1].update(vcount); + uint16_entries[2].update(vcount); + uint16_entries[3].update(vcount); + uint16_entries[4].update(vcount); + uint16_entries[5].update(vcount); + uint16_entries[6].update(vcount); + uint16_entries[7].update(vcount); + break; + + default: + break; } uint32_entry* uint32_entries = entries_ptr->uint32_entries; - int uint32_entries_count = entries_ptr->uint32_entries_count; - for(int index = 0; index < uint32_entries_count; ++index) + switch(entries_ptr->uint32_entries_count) { - uint32_entry& entry = uint32_entries[index]; - *entry.dest = entry.src[vcount]; + + case 0: + break; + + case 1: + uint32_entries[0].update(vcount); + break; + + case 2: + uint32_entries[0].update(vcount); + uint32_entries[1].update(vcount); + break; + + case 3: + uint32_entries[0].update(vcount); + uint32_entries[1].update(vcount); + uint32_entries[2].update(vcount); + break; + + case 4: + uint32_entries[0].update(vcount); + uint32_entries[1].update(vcount); + uint32_entries[2].update(vcount); + uint32_entries[3].update(vcount); + break; + + default: + break; } } diff --git a/butano/include/bn_documentation.h b/butano/include/bn_documentation.h index 526af03a5..9dc6a7e9c 100644 --- a/butano/include/bn_documentation.h +++ b/butano/include/bn_documentation.h @@ -1041,9 +1041,10 @@ * @tableofcontents * * - * @section changelog_4_0_1 4.0.1 (next release) + * @section changelog_4_1_0 4.1.0 (next release) * - * SRAM code moved from EWRAM to ROM to avoid a No$gba crash. + * * H-Blank effects optimized (it fixes `world_map` example flickering). + * * SRAM code moved from EWRAM to ROM to avoid a No$gba crash. * * * @section changelog_4_0_0 4.0.0 diff --git a/butano/src/bn_hblank_effects_manager.cpp b/butano/src/bn_hblank_effects_manager.cpp index dcb97b4a9..cdaf2a0e3 100644 --- a/butano/src/bn_hblank_effects_manager.cpp +++ b/butano/src/bn_hblank_effects_manager.cpp @@ -1262,6 +1262,8 @@ void update() } } + BN_ASSERT(entries->uint32_entries_count <= 4, "Too much 32 bits entries: ", entries->uint32_entries_count); + external_data.visible_entries = visible_entries; external_data.commit = true; } diff --git a/docs/changelog.html b/docs/changelog.html index de13c37bc..5f06013c1 100644 --- a/docs/changelog.html +++ b/docs/changelog.html @@ -52,7 +52,7 @@

Contents

-

4.0.1 (next release)

SRAM code moved from EWRAM to ROM to avoid a No$gba crash.

4.0.0

3.3.0

  • HDMA properly supported (now it works at less than 60fps). See bn::hdma and the hdma_polygons example for more.
  • gba-link-connection remote timeout detection fixed.

3.2.1

bn::optional build fix.

3.2.0

bn::optional is now constexpr.

3.1.0

3.0.0

Thanks to the awesome gba-link-connection, multiplayer support has been implemented! See bn::link and the link example for more.

2.0.0

  • By removing some method overloads, lots of runtime asserts when creating resources have been removed.
  • bn::palette_bpp_mode has been renamed to bn::bpp_mode and bpp_mode() methods have been renamed to bpp().
  • 8 bits per pixel background tiles allocation fixed.

1.0.0

0.4.0

  • btn renamed to bn. No more API breaks will be made between minor releases after 1.0.0, promise.
  • Background tiles manager status can be printed in the log with bn::bg_tiles::log_status(). This is done automatically when a non-optional background tiles allocation fails too.
  • Background regular maps manager status can be printed in the log with bn::bg_maps::log_status(). This is done automatically when a non-optional regular background map allocation fails too.
  • Sprite tiles manager status can be printed in the log with bn::sprite_tiles::log_status(). This is done automatically when a non-optional sprite tiles allocation fails too.
  • Color palettes managers status can be printed in the log with bn::bg_palettes::log_status() and bn::sprite_palettes::log_status(). This is done automatically when a non-optional color palette allocation fails too.
  • Sprites destruction optimized.
  • Setters with an optional parameter added to some classes.
  • Optional components documentation fixed.
  • Other documentation improvements.

0.3.0

  • Sprites update performance improved up to 30% in Butano Fighter thanks to avoid rebuilding sprites list as much as possible.
  • Profiler can show the maximum measured ticks per entry.
  • Assets tools print output binaries size.

0.2.0

  • Performance improved up to 12% in Butano Fighter without -flto thanks to using less build translation units.
  • Documentation improved.

0.1.0

First release.

+

4.1.0 (next release)

  • H-Blank effects optimized (it fixes world_map example flickering).
  • SRAM code moved from EWRAM to ROM to avoid a No$gba crash.

4.0.0

3.3.0

  • HDMA properly supported (now it works at less than 60fps). See bn::hdma and the hdma_polygons example for more.
  • gba-link-connection remote timeout detection fixed.

3.2.1

bn::optional build fix.

3.2.0

bn::optional is now constexpr.

3.1.0

3.0.0

Thanks to the awesome gba-link-connection, multiplayer support has been implemented! See bn::link and the link example for more.

2.0.0

  • By removing some method overloads, lots of runtime asserts when creating resources have been removed.
  • bn::palette_bpp_mode has been renamed to bn::bpp_mode and bpp_mode() methods have been renamed to bpp().
  • 8 bits per pixel background tiles allocation fixed.

1.0.0

0.4.0

  • btn renamed to bn. No more API breaks will be made between minor releases after 1.0.0, promise.
  • Background tiles manager status can be printed in the log with bn::bg_tiles::log_status(). This is done automatically when a non-optional background tiles allocation fails too.
  • Background regular maps manager status can be printed in the log with bn::bg_maps::log_status(). This is done automatically when a non-optional regular background map allocation fails too.
  • Sprite tiles manager status can be printed in the log with bn::sprite_tiles::log_status(). This is done automatically when a non-optional sprite tiles allocation fails too.
  • Color palettes managers status can be printed in the log with bn::bg_palettes::log_status() and bn::sprite_palettes::log_status(). This is done automatically when a non-optional color palette allocation fails too.
  • Sprites destruction optimized.
  • Setters with an optional parameter added to some classes.
  • Optional components documentation fixed.
  • Other documentation improvements.

0.3.0

  • Sprites update performance improved up to 30% in Butano Fighter thanks to avoid rebuilding sprites list as much as possible.
  • Profiler can show the maximum measured ticks per entry.
  • Assets tools print output binaries size.

0.2.0

  • Performance improved up to 12% in Butano Fighter without -flto thanks to using less build translation units.
  • Documentation improved.

0.1.0

First release.