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

Manages allocation of hardware palette indexes with stack-based checkout semantics. More...

#include <palette_pool.hpp>

Public Member Functions

 PalettePool (std::bitset< pal::num_pals > available_indexes)
 Constructs a PalettePool with the specified available indexes.
 
bool has_available_pal () const
 Checks if there is at least one available pal that can be checked out.
 
bool is_available (std::size_t hardware_index) const
 Checks if a specific index is available for checkout.
 
std::size_t checkout ()
 Checks out the next available hardware palette index.
 
void checkout (std::size_t index)
 Checks out a specific hardware palette index.
 
void checkin ()
 Returns the most recently checked-out hardware palette index index to the pool.
 

Detailed Description

Manages allocation of hardware palette indexes with stack-based checkout semantics.

PalettePool tracks which hardware palette slots (0-15) are available for use and which have been "checked out" by the packing algorithm. The pool is initialized with a bitset indicating which slots are available (on bits). Indexes can be checked out via check_out() and returned via checkin() in LIFO (stack) order.

Invariant
checked_out_ is always a subset of available_indexes_
checkout_stack_.size() == checked_out_.count()

Definition at line 22 of file palette_pool.hpp.

Constructor & Destructor Documentation

◆ PalettePool()

porytiles::PalettePool::PalettePool ( std::bitset< pal::num_pals available_indexes)
explicit

Constructs a PalettePool with the specified available indexes.

The available_indexes bitset determines which hardware palette slots can be used. Only indexes with their corresponding bit set to 1 can be checked out.

Parameters
available_indexesBitset where on-bits indicate available palette slots

Definition at line 7 of file palette_pool.cpp.

Member Function Documentation

◆ checkin()

void porytiles::PalettePool::checkin ( )

Returns the most recently checked-out hardware palette index index to the pool.

Pops the most recent hardware palette index from the internal checkout stack and marks it as no longer checked out. This enables LIFO (stack) semantics for index management.

Precondition
At least one index must have been checked out (checkout_stack_ not empty)
Postcondition
The popped index is available for checkout again

Definition at line 49 of file palette_pool.cpp.

◆ checkout() [1/2]

std::size_t porytiles::PalettePool::checkout ( )

Checks out the next available hardware palette index.

Finds the lowest available hardware palette index that hasn't been checked out, marks it as checked out, and returns it. The index is pushed onto an internal stack to support LIFO checkin behavior.

Precondition
has_available_index() must be true
Returns
The checked-out hardware palette index
Postcondition
The returned index is marked as checked out

Definition at line 20 of file palette_pool.cpp.

◆ checkout() [2/2]

void porytiles::PalettePool::checkout ( std::size_t  index)

Checks out a specific hardware palette index.

Marks the specified hardware palette index as checked out and pushes it onto the checkout stack. Use this when a specific palette index is required (e.g., prefilled palettes).

Parameters
indexThe hardware palette index to check out
Precondition
index must be less than pal::num_pals
is_available(index) must be true
Postcondition
The index is marked as checked out
The index is pushed onto the checkout stack

Definition at line 39 of file palette_pool.cpp.

◆ has_available_pal()

bool porytiles::PalettePool::has_available_pal ( ) const
inline

Checks if there is at least one available pal that can be checked out.

Returns
true if a subsequent check_out() call will succeed, false otherwise

Definition at line 40 of file palette_pool.hpp.

◆ is_available()

bool porytiles::PalettePool::is_available ( std::size_t  hardware_index) const

Checks if a specific index is available for checkout.

Parameters
hardware_indexThe hardware palette index to check
Precondition
index must be less than pal::num_pals
Returns
true if the index is in the pool and not currently checked out

Definition at line 12 of file palette_pool.cpp.


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