Porytiles
Loading...
Searching...
No Matches
palette_pool.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <bitset>
4#include <cstddef>
5#include <vector>
6
8
9namespace porytiles {
10
21 public:
29 explicit PalettePool(std::bitset<palette::num_palettes> available_indexes);
30
34 [[nodiscard]] bool has_available_palette() const
35 {
36 return (available_indexes_ & ~checked_out_).any();
37 }
38
44 [[nodiscard]] bool is_available(std::size_t hardware_index) const;
45
55 [[nodiscard]] std::size_t checkout();
56
68 void checkout(std::size_t index);
69
78 void checkin();
79
80 private:
81 std::bitset<palette::num_palettes> available_indexes_;
82 std::bitset<palette::num_palettes> checked_out_;
83 std::vector<std::size_t> checkout_stack_;
84};
85
86} // namespace porytiles
Manages allocation of hardware palette indexes with stack-based checkout semantics.
bool has_available_palette() const
Checks if there is at least one available palette that can be checked out.
std::size_t checkout()
Checks out the next available hardware palette index.
void checkin()
Returns the most recently checked-out hardware palette index index to the pool.
bool is_available(std::size_t hardware_index) const
Checks if a specific index is available for checkout.