Porytiles
Loading...
Searching...
No Matches
prefilled_palette.cpp
Go to the documentation of this file.
2
4
5namespace porytiles {
6
7PrefilledPalette::PrefilledPalette(
8 std::size_t hardware_index, ColorSet fixed_colors, std::size_t available_capacity, std::size_t occupied_slots)
9 : hardware_index_{hardware_index}, fixed_colors_{std::move(fixed_colors)}, available_capacity_{available_capacity},
10 occupied_slots_{occupied_slots}
11{
12}
13
14PrefilledPalette
15PrefilledPalette::fully_locked(std::size_t hardware_index, ColorSet color_set, std::size_t occupied_slots)
16{
17 return PrefilledPalette{hardware_index, std::move(color_set), 0, occupied_slots};
18}
19
20PrefilledPalette PrefilledPalette::partially_locked(
21 std::size_t hardware_index, ColorSet fixed_colors, std::size_t occupied_slots, std::size_t total_capacity)
22{
23 if (occupied_slots > total_capacity) {
24 panic("PrefilledPalette::partially_locked occupied_slots > total_capacity");
25 }
26 const std::size_t available = total_capacity - occupied_slots;
27 return PrefilledPalette{hardware_index, std::move(fixed_colors), available, occupied_slots};
28}
29
30std::size_t PrefilledPalette::fixed_color_count() const
31{
32 return color_set_count(fixed_colors_);
33}
34
35bool PrefilledPalette::can_accommodate(const ColorSet &tile_colors) const
36{
37 // If tile colors are a subset of fixed colors, always OK
38 if (is_subset(tile_colors, fixed_colors_)) {
39 return true;
40 }
41
42 // Otherwise, check if new colors fit in available capacity
43 // New colors = union size - fixed count
44 const ColorSet combined = color_set_union(tile_colors, fixed_colors_);
45 const std::size_t combined_count = color_set_count(combined);
46 const std::size_t fixed_count = color_set_count(fixed_colors_);
47 const std::size_t new_colors_needed = combined_count - fixed_count;
48
49 return new_colors_needed <= available_capacity_;
50}
51
52} // namespace porytiles
A set of colors represented as a bitset.
Definition color_set.hpp:26
Pre-assigned palette with wildcard support for palette packing.
bool is_subset(const ColorSet &a, const ColorSet &b)
Checks if one ColorSet is a subset of another.
Definition color_set.cpp:49
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
ColorSet color_set_union(const ColorSet &a, const ColorSet &b)
Computes the union of two ColorSets.
Definition color_set.cpp:20
std::size_t color_set_count(const ColorSet &set)
Counts the number of colors in a ColorSet.
Definition color_set.cpp:44