Porytiles
Loading...
Searching...
No Matches
packing_initializer.cpp
Go to the documentation of this file.
2
4
5namespace porytiles {
6
7std::vector<PackedPalette> initialize_packed_palettes(
8 const std::set<PrefilledPalette> &prefilled_pals, PalettePool &pal_pool, std::size_t pal_capacity)
9{
10 std::vector<PackedPalette> palettes;
11
12 for (const auto &prefilled_pal : prefilled_pals) {
13 // Only set up prefilled palettes for slots that were requested via PalettePool
14 if (pal_pool.is_available(prefilled_pal.hardware_index())) {
15 pal_pool.checkout(prefilled_pal.hardware_index());
16
17 // Calculate effective capacity accounting for "wasted" slots from duplicate colors.
18 // If a prefilled palette has 15 occupied slots but only 14 unique colors, there's 1 wasted slot.
19 const ColorSet fixed_colors = prefilled_pal.fixed_colors();
20 const std::size_t unique_color_count = color_set_count(fixed_colors);
21 const std::size_t occupied_slot_count = prefilled_pal.occupied_slots();
22 const std::size_t wasted_slot_count = occupied_slot_count - unique_color_count;
23 const std::size_t effective_capacity = pal_capacity - wasted_slot_count;
24
25 PackedPalette pal{prefilled_pal.hardware_index(), effective_capacity};
26 if (unique_color_count > 0) {
27 // Pre-populate with fixed colors using a "system" tile whose id matches the prefilled's hw index
28 PackableTile system_tile{
29 PackableTile::PrefilledPaletteId{prefilled_pal.hardware_index()}, fixed_colors};
30 pal.add_tile(system_tile);
31 }
32 palettes.push_back(std::move(pal));
33 }
34 }
35
36 return palettes;
37}
38
39} // namespace porytiles
A set of colors represented as a bitset.
Definition color_set.hpp:26
Identifies a tile created from a prefilled palette.
Wraps a ColorSet with a tile ID for tracking during palette packing.
Represents a hardware palette after packing with accumulated colors and assigned tiles.
std::size_t hardware_index() const
Manages allocation of hardware palette indexes with stack-based checkout semantics.
std::size_t checkout()
Checks out the next available hardware palette index.
bool is_available(std::size_t hardware_index) const
Checks if a specific index is available for checkout.
std::size_t color_set_count(const ColorSet &set)
Counts the number of colors in a ColorSet.
Definition color_set.cpp:44
std::vector< PackedPalette > initialize_packed_palettes(const std::set< PrefilledPalette > &prefilled_pals, PalettePool &pal_pool, std::size_t pal_capacity)
Initializes packed palettes from prefilled palettes.