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
23 public:
33 explicit PalettePool(std::bitset<pal::num_pals> available_indexes);
34
40 [[nodiscard]] bool has_available_pal() const
41 {
42 return (available_indexes_ & ~checked_out_).any();
43 }
44
52 [[nodiscard]] bool is_available(std::size_t hardware_index) const;
53
65 [[nodiscard]] std::size_t checkout();
66
80 void checkout(std::size_t index);
81
92 void checkin();
93
94 private:
95 std::bitset<pal::num_pals> available_indexes_;
96 std::bitset<pal::num_pals> checked_out_;
97 std::vector<std::size_t> checkout_stack_;
98};
99
100} // namespace porytiles
Manages allocation of hardware palette indexes with stack-based checkout semantics.
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.
bool has_available_pal() const
Checks if there is at least one available pal that can be checked out.