Skip to content

Commit

Permalink
butano: regular_bg_map_item::decompress and affine_bg_map_item::decom…
Browse files Browse the repository at this point in the history
…press fixed
  • Loading branch information
GValiente committed Jul 18, 2023
1 parent b471cfc commit d98a545
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 80 deletions.
10 changes: 9 additions & 1 deletion butano/include/bn_affine_bg_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ class affine_bg_item
* @param decompressed_tiles_ref Destination of the decompressed tiles.
* @param decompressed_colors_ref Destination of the decompressed colors.
* @param decompressed_cells_ref Destination of the decompressed map cells.
* @param decompressed_dimensions Size in map cells of the destination data.
* @return An affine_bg_item pointing to the decompressed tiles, colors and map cells.
*/
[[nodiscard]] affine_bg_item decompress(
span<tile> decompressed_tiles_ref, span<color> decompressed_colors_ref,
span<affine_bg_map_cell> decompressed_cells_ref) const;

/// @cond DO_NOT_DOCUMENT

[[deprecated("Call the other decompress() method instead")]]
[[nodiscard]] affine_bg_item decompress(
span<tile> decompressed_tiles_ref, span<color> decompressed_colors_ref,
affine_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const;

/// @endcond

/**
* @brief Creates an affine_bg_ptr using the information contained in this item.
* @param x Horizontal position of the affine background.
Expand Down
21 changes: 18 additions & 3 deletions butano/include/bn_affine_bg_map_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "bn_size.h"
#include "bn_point.h"
#include "bn_optional.h"
#include "bn_span_fwd.h"
#include "bn_compression_type.h"
#include "bn_affine_bg_map_cell.h"

Expand Down Expand Up @@ -190,6 +191,14 @@ class affine_bg_map_item
return _maps_count;
}

/**
* @brief Returns the number of referenced map cells.
*/
[[nodiscard]] constexpr int cells_count() const
{
return _dimensions.width() * _dimensions.height() * _maps_count;
}

/**
* @brief Returns the compression type.
*/
Expand Down Expand Up @@ -301,11 +310,17 @@ class affine_bg_map_item
* If the source and destination map cells overlap, the behavior is undefined.
*
* @param decompressed_cells_ref Destination of the decompressed map cells.
* @param decompressed_dimensions Size in map cells of the destination data.
* @return An affine_bg_map_item pointing to the decompressed map cells.
*/
[[nodiscard]] affine_bg_map_item decompress(affine_bg_map_cell& decompressed_cells_ref,
const size& decompressed_dimensions) const;
[[nodiscard]] affine_bg_map_item decompress(span<affine_bg_map_cell> decompressed_cells_ref) const;

/// @cond DO_NOT_DOCUMENT

[[deprecated("Call the other decompress() method instead")]]
[[nodiscard]] affine_bg_map_item decompress(
affine_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const;

/// @endcond

/**
* @brief Searches for an affine_bg_map_ptr which references the information provided by this item.
Expand Down
6 changes: 6 additions & 0 deletions butano/include/bn_documentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,12 @@
* @tableofcontents
*
*
* @section changelog_14_1_0 14.1.0 (next release)
*
* * bn::regular_bg_map_item::cells_count and bn::affine_bg_map_item::cells_count added.
* * bn::regular_bg_map_item::decompress and bn::affine_bg_map_item::decompress fixed.
*
*
* @section changelog_14_0_0 14.0.0
*
* * bn::regular_bg_map_item and bn::affine_bg_map_item can reference multiple maps per item.
Expand Down
10 changes: 9 additions & 1 deletion butano/include/bn_regular_bg_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ class regular_bg_item
* @param decompressed_tiles_ref Destination of the decompressed tiles.
* @param decompressed_colors_ref Destination of the decompressed colors.
* @param decompressed_cells_ref Destination of the decompressed map cells.
* @param decompressed_dimensions Size in map cells of the destination data.
* @return A regular_bg_item pointing to the decompressed tiles, colors and map cells.
*/
[[nodiscard]] regular_bg_item decompress(
span<tile> decompressed_tiles_ref, span<color> decompressed_colors_ref,
span<regular_bg_map_cell> decompressed_cells_ref) const;

/// @cond DO_NOT_DOCUMENT

[[deprecated("Call the other decompress() method instead")]]
[[nodiscard]] regular_bg_item decompress(
span<tile> decompressed_tiles_ref, span<color> decompressed_colors_ref,
regular_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const;

/// @endcond

/**
* @brief Creates a regular_bg_ptr using the information contained in this item.
* @param x Horizontal position of the regular background.
Expand Down
21 changes: 18 additions & 3 deletions butano/include/bn_regular_bg_map_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "bn_size.h"
#include "bn_point.h"
#include "bn_optional.h"
#include "bn_span_fwd.h"
#include "bn_compression_type.h"
#include "bn_regular_bg_map_cell.h"

Expand Down Expand Up @@ -185,6 +186,14 @@ class regular_bg_map_item
return _maps_count;
}

/**
* @brief Returns the number of referenced map cells.
*/
[[nodiscard]] constexpr int cells_count() const
{
return _dimensions.width() * _dimensions.height() * _maps_count;
}

/**
* @brief Returns the compression type.
*/
Expand Down Expand Up @@ -306,11 +315,17 @@ class regular_bg_map_item
* If the source and destination map cells overlap, the behavior is undefined.
*
* @param decompressed_cells_ref Destination of the decompressed map cells.
* @param decompressed_dimensions Size in map cells of the destination data.
* @return A regular_bg_map_item pointing to the decompressed map cells.
*/
[[nodiscard]] regular_bg_map_item decompress(regular_bg_map_cell& decompressed_cells_ref,
const size& decompressed_dimensions) const;
[[nodiscard]] regular_bg_map_item decompress(span<regular_bg_map_cell> decompressed_cells_ref) const;

/// @cond DO_NOT_DOCUMENT

[[deprecated("Call the other decompress() method instead")]]
[[nodiscard]] regular_bg_map_item decompress(
regular_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const;

/// @endcond

/**
* @brief Searches for a regular_bg_map_ptr which references the information provided by this item.
Expand Down
13 changes: 11 additions & 2 deletions butano/src/bn_affine_bg_item.cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ namespace bn

affine_bg_item affine_bg_item::decompress(
span<tile> decompressed_tiles_ref, span<color> decompressed_colors_ref,
affine_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const
span<affine_bg_map_cell> decompressed_cells_ref) const
{
affine_bg_item result = *this;
result._tiles_item = _tiles_item.decompress(decompressed_tiles_ref);
result._palette_item = _palette_item.decompress(decompressed_colors_ref);
result._map_item = _map_item.decompress(decompressed_cells_ref, decompressed_dimensions);
result._map_item = _map_item.decompress(decompressed_cells_ref);
return result;
}

affine_bg_item affine_bg_item::decompress(
span<tile> decompressed_tiles_ref, span<color> decompressed_colors_ref,
affine_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const
{
span<affine_bg_map_cell> decompressed_cells_span(
&decompressed_cells_ref, decompressed_dimensions.width() * decompressed_dimensions.height());
return decompress(decompressed_tiles_ref, decompressed_colors_ref, decompressed_cells_span);
}

affine_bg_ptr affine_bg_item::create_bg(fixed x, fixed y) const
{
return affine_bg_ptr::create(x, y, *this);
Expand Down
32 changes: 19 additions & 13 deletions butano/src/bn_affine_bg_map_item.cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
namespace bn
{

affine_bg_map_item affine_bg_map_item::decompress(affine_bg_map_cell& decompressed_cells_ref,
[[maybe_unused]] const size& decompressed_dimensions) const
affine_bg_map_item affine_bg_map_item::decompress(span<affine_bg_map_cell> decompressed_cells_ref) const
{
BN_ASSERT(decompressed_dimensions.width() >= _dimensions.width() &&
decompressed_dimensions.height() >= _dimensions.height(),
BN_ASSERT(decompressed_cells_ref.size() >= cells_count(),
"There's not enough space to store the decompressed data: ",
decompressed_dimensions.width(), " - ", _dimensions.width(), " - ",
decompressed_dimensions.height(), " - ", _dimensions.height());
decompressed_cells_ref.size(), " - ", cells_count());

BN_ASSERT(aligned<4>(&decompressed_cells_ref), "Destination map cells are not aligned");
affine_bg_map_cell* decompressed_cells_ptr = decompressed_cells_ref.data();
BN_ASSERT(aligned<4>(decompressed_cells_ptr), "Destination map cells are not aligned");

affine_bg_map_item result = *this;

Expand All @@ -33,20 +31,20 @@ affine_bg_map_item affine_bg_map_item::decompress(affine_bg_map_cell& decompress
break;

case compression_type::LZ77:
hw::decompress::lz77_wram(_cells_ptr, &decompressed_cells_ref);
result._cells_ptr = &decompressed_cells_ref;
hw::decompress::lz77_wram(_cells_ptr, decompressed_cells_ptr);
result._cells_ptr = decompressed_cells_ptr;
result._compression = compression_type::NONE;
break;

case compression_type::RUN_LENGTH:
hw::decompress::rl_wram(_cells_ptr, &decompressed_cells_ref);
result._cells_ptr = &decompressed_cells_ref;
hw::decompress::rl_wram(_cells_ptr, decompressed_cells_ptr);
result._cells_ptr = decompressed_cells_ptr;
result._compression = compression_type::NONE;
break;

case compression_type::HUFFMAN:
hw::decompress::huff(_cells_ptr, &decompressed_cells_ref);
result._cells_ptr = &decompressed_cells_ref;
hw::decompress::huff(_cells_ptr, decompressed_cells_ptr);
result._cells_ptr = decompressed_cells_ptr;
result._compression = compression_type::NONE;
break;

Expand All @@ -58,6 +56,14 @@ affine_bg_map_item affine_bg_map_item::decompress(affine_bg_map_cell& decompress
return result;
}

affine_bg_map_item affine_bg_map_item::decompress(
affine_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const
{
span<affine_bg_map_cell> decompressed_cells_span(
&decompressed_cells_ref, decompressed_dimensions.width() * decompressed_dimensions.height());
return decompress(decompressed_cells_span);
}

optional<affine_bg_map_ptr> affine_bg_map_item::find_map(
const affine_bg_tiles_ptr& tiles, const bg_palette_ptr& palette) const
{
Expand Down
13 changes: 11 additions & 2 deletions butano/src/bn_regular_bg_item.cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@ namespace bn

regular_bg_item regular_bg_item::decompress(
span<tile> decompressed_tiles_ref, span<color> decompressed_colors_ref,
regular_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const
span<regular_bg_map_cell> decompressed_cells_ref) const
{
regular_bg_item result = *this;
result._tiles_item = _tiles_item.decompress(decompressed_tiles_ref);
result._palette_item = _palette_item.decompress(decompressed_colors_ref);
result._map_item = _map_item.decompress(decompressed_cells_ref, decompressed_dimensions);
result._map_item = _map_item.decompress(decompressed_cells_ref);
return result;
}

regular_bg_item regular_bg_item::decompress(
span<tile> decompressed_tiles_ref, span<color> decompressed_colors_ref,
regular_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const
{
span<regular_bg_map_cell> decompressed_cells_span(
&decompressed_cells_ref, decompressed_dimensions.width() * decompressed_dimensions.height());
return decompress(decompressed_tiles_ref, decompressed_colors_ref, decompressed_cells_span);
}

regular_bg_ptr regular_bg_item::create_bg(fixed x, fixed y) const
{
return regular_bg_ptr::create(x, y, *this);
Expand Down
32 changes: 19 additions & 13 deletions butano/src/bn_regular_bg_map_item.cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
namespace bn
{

regular_bg_map_item regular_bg_map_item::decompress(regular_bg_map_cell& decompressed_cells_ref,
[[maybe_unused]] const size& decompressed_dimensions) const
regular_bg_map_item regular_bg_map_item::decompress(span<regular_bg_map_cell> decompressed_cells_ref) const
{
BN_ASSERT(decompressed_dimensions.width() >= _dimensions.width() &&
decompressed_dimensions.height() >= _dimensions.height(),
BN_ASSERT(decompressed_cells_ref.size() >= cells_count(),
"There's not enough space to store the decompressed data: ",
decompressed_dimensions.width(), " - ", _dimensions.width(), " - ",
decompressed_dimensions.height(), " - ", _dimensions.height());
decompressed_cells_ref.size(), " - ", cells_count());

BN_ASSERT(aligned<4>(&decompressed_cells_ref), "Destination map cells are not aligned");
regular_bg_map_cell* decompressed_cells_ptr = decompressed_cells_ref.data();
BN_ASSERT(aligned<4>(decompressed_cells_ptr), "Destination map cells are not aligned");

regular_bg_map_item result = *this;

Expand All @@ -33,20 +31,20 @@ regular_bg_map_item regular_bg_map_item::decompress(regular_bg_map_cell& decompr
break;

case compression_type::LZ77:
hw::decompress::lz77_wram(_cells_ptr, &decompressed_cells_ref);
result._cells_ptr = &decompressed_cells_ref;
hw::decompress::lz77_wram(_cells_ptr, decompressed_cells_ptr);
result._cells_ptr = decompressed_cells_ptr;
result._compression = compression_type::NONE;
break;

case compression_type::RUN_LENGTH:
hw::decompress::rl_wram(_cells_ptr, &decompressed_cells_ref);
result._cells_ptr = &decompressed_cells_ref;
hw::decompress::rl_wram(_cells_ptr, decompressed_cells_ptr);
result._cells_ptr = decompressed_cells_ptr;
result._compression = compression_type::NONE;
break;

case compression_type::HUFFMAN:
hw::decompress::huff(_cells_ptr, &decompressed_cells_ref);
result._cells_ptr = &decompressed_cells_ref;
hw::decompress::huff(_cells_ptr, decompressed_cells_ptr);
result._cells_ptr = decompressed_cells_ptr;
result._compression = compression_type::NONE;
break;

Expand All @@ -58,6 +56,14 @@ regular_bg_map_item regular_bg_map_item::decompress(regular_bg_map_cell& decompr
return result;
}

regular_bg_map_item regular_bg_map_item::decompress(
regular_bg_map_cell& decompressed_cells_ref, const size& decompressed_dimensions) const
{
span<regular_bg_map_cell> decompressed_cells_span(
&decompressed_cells_ref, decompressed_dimensions.width() * decompressed_dimensions.height());
return decompress(decompressed_cells_span);
}

optional<regular_bg_map_ptr> regular_bg_map_item::find_map(
const regular_bg_tiles_ptr& tiles, const bg_palette_ptr& palette) const
{
Expand Down
3 changes: 2 additions & 1 deletion docs/changelog.html

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions docs/classbn_1_1affine__bg__item.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ <h2><a href="#pub-methods">Public functions</a></h2>
</dt>
<dd>Indicates if backgrounds generated with this item are big or not.</dd>
<dt>
<span class="m-doc-wrap-bumper">auto <a href="#a0177591595125edaa7d07b0af0f30c34" class="m-doc">decompress</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1span.html" class="m-doc">span</a>&lt;<a href="classbn_1_1tile.html" class="m-doc">tile</a>&gt; decompressed_tiles_ref,
<span class="m-doc-wrap-bumper">auto <a href="#a3734d93bc14699962f2f08d5cf2789cd" class="m-doc">decompress</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1span.html" class="m-doc">span</a>&lt;<a href="classbn_1_1tile.html" class="m-doc">tile</a>&gt; decompressed_tiles_ref,
<a href="classbn_1_1span.html" class="m-doc">span</a>&lt;<a href="classbn_1_1color.html" class="m-doc">color</a>&gt; decompressed_colors_ref,
<a href="namespacebn.html#a840f0a4392c5ec4f3b82f1066f811066" class="m-doc">affine_<wbr />bg_<wbr />map_<wbr />cell</a>&amp; decompressed_cells_ref,
const <a href="classbn_1_1size.html" class="m-doc">size</a>&amp; decompressed_dimensions) const -&gt; <a href="classbn_1_1affine__bg__item.html" class="m-doc">affine_<wbr />bg_<wbr />item</a></span>
<a href="classbn_1_1span.html" class="m-doc">span</a>&lt;<a href="namespacebn.html#a840f0a4392c5ec4f3b82f1066f811066" class="m-doc">affine_<wbr />bg_<wbr />map_<wbr />cell</a>&gt; decompressed_cells_ref) const -&gt; <a href="classbn_1_1affine__bg__item.html" class="m-doc">affine_<wbr />bg_<wbr />item</a></span>
</dt>
<dd>Decompresses the stored data in the tiles referenced by decompressed_tiles_ref, the colors referenced by decompressed_colors_ref and the map cells referenced by decompressed_cells_ref.</dd>
<dt>
Expand Down Expand Up @@ -270,12 +269,11 @@ <h3>
<p>Indicates if backgrounds generated with this item are big or not.</p>
<p>Big backgrounds are slower CPU wise and don&#x27;t support wrapping (they can&#x27;t be moved beyond their boundaries), but can have any width or height multiple of 256 pixels.</p>
</div></section>
<section class="m-doc-details" id="a0177591595125edaa7d07b0af0f30c34"><div>
<section class="m-doc-details" id="a3734d93bc14699962f2f08d5cf2789cd"><div>
<h3>
<span class="m-doc-wrap-bumper"><a href="classbn_1_1affine__bg__item.html" class="m-doc">affine_<wbr />bg_<wbr />item</a> bn::<wbr />affine_bg_item::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a0177591595125edaa7d07b0af0f30c34" class="m-doc-self">decompress</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1span.html" class="m-doc">span</a>&lt;<a href="classbn_1_1tile.html" class="m-doc">tile</a>&gt; decompressed_tiles_ref,
<span class="m-doc-wrap-bumper"><a href="classbn_1_1affine__bg__item.html" class="m-doc">affine_<wbr />bg_<wbr />item</a> bn::<wbr />affine_bg_item::<wbr /></span><span class="m-doc-wrap"><span class="m-doc-wrap-bumper"><a href="#a3734d93bc14699962f2f08d5cf2789cd" class="m-doc-self">decompress</a>(</span><span class="m-doc-wrap"><a href="classbn_1_1span.html" class="m-doc">span</a>&lt;<a href="classbn_1_1tile.html" class="m-doc">tile</a>&gt; decompressed_tiles_ref,
<a href="classbn_1_1span.html" class="m-doc">span</a>&lt;<a href="classbn_1_1color.html" class="m-doc">color</a>&gt; decompressed_colors_ref,
<a href="namespacebn.html#a840f0a4392c5ec4f3b82f1066f811066" class="m-doc">affine_<wbr />bg_<wbr />map_<wbr />cell</a>&amp; decompressed_cells_ref,
const <a href="classbn_1_1size.html" class="m-doc">size</a>&amp; decompressed_dimensions) const</span></span>
<a href="classbn_1_1span.html" class="m-doc">span</a>&lt;<a href="namespacebn.html#a840f0a4392c5ec4f3b82f1066f811066" class="m-doc">affine_<wbr />bg_<wbr />map_<wbr />cell</a>&gt; decompressed_cells_ref) const</span></span>
</h3>
<p>Decompresses the stored data in the tiles referenced by decompressed_tiles_ref, the colors referenced by decompressed_colors_ref and the map cells referenced by decompressed_cells_ref.</p>
<table class="m-table m-fullwidth m-flat">
Expand All @@ -295,10 +293,6 @@ <h3>
<td>decompressed_cells_ref</td>
<td>Destination of the decompressed map cells.</td>
</tr>
<tr>
<td>decompressed_dimensions</td>
<td>Size in map cells of the destination data.</td>
</tr>
</tbody>
<tfoot>
<tr>
Expand Down
Loading

0 comments on commit d98a545

Please sign in to comment.