Porytiles
Loading...
Searching...
No Matches
sharing_metrics.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
5namespace porytiles {
6
8 const PackableTile::Id &tile_id, const PackedPalette &palette, const ShapeGroupMetadata &metadata)
9{
10 auto it = metadata.tile_id_to_group.find(tile_id);
11 if (it == metadata.tile_id_to_group.end()) {
12 return false;
13 }
14
15 std::size_t group_index = it->second;
16 const auto &members = metadata.group_members[group_index];
17
18 for (const auto &assigned_id : palette.assigned_tile_ids()) {
19 if (assigned_id == tile_id) {
20 continue;
21 }
22 if (std::ranges::find(members, assigned_id) != members.end()) {
23 return true;
24 }
25 }
26
27 return false;
28}
29
31 const PackableTile &tile, const PackedPalette &palette, const ShapeGroupMetadata &metadata, double sharing_weight)
32{
33 if (!palette_contains_sibling(tile.id(), palette, metadata)) {
34 return 0.0;
35 }
36 return sharing_weight * static_cast<double>(tile.color_count());
37}
38
39} // namespace porytiles
Wraps a ColorSet with a tile ID for tracking during palette packing.
std::size_t color_count() const
const Id & id() const
std::variant< HintId, PrefilledPaletteId, RegularId, AnimId, PrimaryTileId > Id
Variant type for tile identification.
Represents a hardware palette after packing with accumulated colors and assigned tiles.
const std::vector< PackableTile::Id > & assigned_tile_ids() const
bool palette_contains_sibling(const PackableTile::Id &tile_id, const PackedPalette &palette, const ShapeGroupMetadata &metadata)
Checks whether a palette already contains a sibling of the given tile (same shape group,...
double compute_sharing_penalty(const PackableTile &tile, const PackedPalette &palette, const ShapeGroupMetadata &metadata, double sharing_weight=0.5)
Computes the sharing penalty for placing a tile in a palette.
Metadata that maps PackableTile IDs to shape group membership for sharing-aware packing.
std::map< PackableTile::Id, std::size_t > tile_id_to_group
Maps PackableTile::Id to its shape group index.
std::vector< std::vector< PackableTile::Id > > group_members
For each group, the list of PackableTile::Ids that belong to it.