Porytiles
Loading...
Searching...
No Matches
porytiles::PackedPalette Class Reference

Represents a hardware palette after packing with accumulated colors and assigned tiles. More...

#include <packed_palette.hpp>

Public Member Functions

 PackedPalette (std::size_t hardware_index, std::size_t capacity=pal::max_size - 1)
 Constructs a PackedPalette with a given index and capacity.
 
bool operator== (const PackedPalette &other) const
 
std::strong_ordering operator<=> (const PackedPalette &other) const
 
std::size_t hardware_index () const
 
const ColorSetcolor_set () const
 
const std::vector< PackableTile::Id > & assigned_tile_ids () const
 
std::size_t color_count () const
 
std::size_t color_multiplicity (std::size_t color_idx) const
 
const std::array< std::size_t, num_colors > & color_counts () const
 
std::size_t remaining_capacity () const
 
bool can_fit (const ColorSet &tile_colors) const
 Checks if a tile's colors can fit in this palette.
 
std::size_t union_size (const ColorSet &tile_colors) const
 Computes the size of the union of this palette's colors with the given colors.
 
void add_tile (const PackableTile &tile)
 Adds a tile to this palette.
 
void remove_tile (const PackableTile &tile)
 Removes a tile from this palette and recalculates the color set.
 
void remove_tile (const PackableTile::Id &tile_id)
 Removes a tile (by ID) from this palette and recalculates the color set.
 

Detailed Description

Represents a hardware palette after packing with accumulated colors and assigned tiles.

PackedPalette tracks the colors that have been assigned to a single hardware palette during the packing process. It maintains both the accumulated color set and the list of tile IDs that have been assigned to use this palette.

GBA hardware palettes have 16 slots, but slot 0 is always transparency, leaving 15 usable color slots (the default capacity).

Definition at line 24 of file packed_palette.hpp.

Constructor & Destructor Documentation

◆ PackedPalette()

porytiles::PackedPalette::PackedPalette ( std::size_t  hardware_index,
std::size_t  capacity = pal::max_size - 1 
)
explicit

Constructs a PackedPalette with a given index and capacity.

Parameters
hardware_indexThe hardware palette index (0-5 for primary, etc.)
capacityMaximum number of colors this palette can hold (default pal::max_size - 1, i.e. 15)

Definition at line 10 of file packed_palette.cpp.

Member Function Documentation

◆ add_tile()

void porytiles::PackedPalette::add_tile ( const PackableTile tile)

Adds a tile to this palette.

Adds the tile's ID to the assigned list and unions the tile's colors with this palette's color set.

Parameters
tileThe tile to add
Precondition
can_fit(tile.color_set()) must be true

Definition at line 38 of file packed_palette.cpp.

◆ assigned_tile_ids()

const std::vector< PackableTile::Id > & porytiles::PackedPalette::assigned_tile_ids ( ) const
inline

Definition at line 54 of file packed_palette.hpp.

◆ can_fit()

bool porytiles::PackedPalette::can_fit ( const ColorSet tile_colors) const

Checks if a tile's colors can fit in this palette.

Returns true if adding the tile's colors would not exceed the palette's capacity. Takes into account colors that are already in the palette (overlap).

Parameters
tile_colorsThe colors to check
Returns
true if the colors can fit, false otherwise

Definition at line 27 of file packed_palette.cpp.

◆ color_count()

std::size_t porytiles::PackedPalette::color_count ( ) const

Definition at line 16 of file packed_palette.cpp.

◆ color_counts()

const std::array< std::size_t, num_colors > & porytiles::PackedPalette::color_counts ( ) const
inline

Definition at line 66 of file packed_palette.hpp.

◆ color_multiplicity()

std::size_t porytiles::PackedPalette::color_multiplicity ( std::size_t  color_idx) const
inline

Definition at line 61 of file packed_palette.hpp.

◆ color_set()

const ColorSet & porytiles::PackedPalette::color_set ( ) const
inline

Definition at line 49 of file packed_palette.hpp.

◆ hardware_index()

std::size_t porytiles::PackedPalette::hardware_index ( ) const
inline

Definition at line 44 of file packed_palette.hpp.

◆ operator<=>()

std::strong_ordering porytiles::PackedPalette::operator<=> ( const PackedPalette other) const
inline

Definition at line 39 of file packed_palette.hpp.

◆ operator==()

bool porytiles::PackedPalette::operator== ( const PackedPalette other) const
inline

Definition at line 34 of file packed_palette.hpp.

◆ remaining_capacity()

std::size_t porytiles::PackedPalette::remaining_capacity ( ) const

Definition at line 21 of file packed_palette.cpp.

◆ remove_tile() [1/2]

void porytiles::PackedPalette::remove_tile ( const PackableTile tile)

Removes a tile from this palette and recalculates the color set.

Removes the tile's ID from the assigned list and rebuilds the color set from the remaining tiles. Colors that were unique to the removed tile will no longer be in the palette's color set.

Parameters
tileThe tile to remove

Definition at line 48 of file packed_palette.cpp.

◆ remove_tile() [2/2]

void porytiles::PackedPalette::remove_tile ( const PackableTile::Id tile_id)

Removes a tile (by ID) from this palette and recalculates the color set.

Removes the tile's ID from the assigned list and rebuilds the color set from the remaining tiles. Colors that were unique to the removed tile will no longer be in the palette's color set.

Parameters
tile_idThe ID of the tile to remove

Definition at line 53 of file packed_palette.cpp.

◆ union_size()

std::size_t porytiles::PackedPalette::union_size ( const ColorSet tile_colors) const

Computes the size of the union of this palette's colors with the given colors.

Returns the total number of unique colors that would result from adding the given colors to this palette.

Parameters
tile_colorsThe colors to compute union with
Returns
The number of colors in the union

Definition at line 32 of file packed_palette.cpp.


The documentation for this class was generated from the following files: