Porytiles
Loading...
Searching...
No Matches
porytiles::details Namespace Reference

Functions

template<SupportsTransparency ColorType, typename TransparencyPredicate , std::size_t N = 0>
PaletteMatchResult< ColorType > match_tile_to_palette_impl (const PixelTile< ColorType > &tile, const Palette< ColorType, N > &palette, TransparencyPredicate is_transparent_pred)
 Helper function implementing the core palette matching logic.
 
template<SupportsTransparency PixelType, typename TransparencyPredicate >
ShapeTile< ColorIndexfrom_pixel_tile_impl (const PixelTile< PixelType > &pixel_tile, const ColorIndexMap< PixelType > &color_index_map, TransparencyPredicate is_transparent_pred)
 Helper function implementing the core PixelTile to ShapeTile conversion logic.
 
template<SupportsTransparency ColorType, std::size_t N = 0, typename TransparencyPredicate >
PixelTile< IndexPixelindex_tile_from_color_tile_impl (const PixelTile< ColorType > &tile, const Palette< ColorType, N > &palette, TransparencyPredicate is_transparent_pred)
 Helper function implementing the core color-to-index tile conversion logic.
 
template<SupportsTransparency ColorType, std::size_t N = 0>
PixelTile< ColorType > color_tile_from_index_tile_impl (const PixelTile< IndexPixel > &index_tile, const Palette< ColorType, N > &palette, const ColorType &transparent_color)
 Helper function implementing the core index-to-color tile conversion logic.
 
void report_validation_error_in_metatile (const TilesetCompileValidatorServices &services, const Metatile< Rgba32 > &metatile, std::size_t metatile_index, std::size_t internal_tile_index, std::size_t row, std::size_t col, const std::string &diagnostic_code, const std::string &error_message, const Rgba32 &extrinsic_transparency)
 Reports a validation error at a specific pixel location within a metatile.
 
void report_validation_error_in_anim (const TilesetCompileValidatorServices &services, const PixelTile< Rgba32 > &tile, const std::string &anim_name, const std::string &frame_name, std::size_t internal_tile_index, std::size_t row, std::size_t col, const std::string &diagnostic_code, const std::string &error_message, const Rgba32 &extrinsic_transparency)
 Reports a validation error at a specific pixel location within an animation frame tile.
 
void report_validation_error_in_anim_tile (const TilesetCompileValidatorServices &services, const PixelTile< Rgba32 > &tile, const std::string &anim_name, const std::string &frame_name, std::size_t internal_tile_index, const std::string &diagnostic_code, const std::string &error_message, const Rgba32 &extrinsic_transparency)
 Reports a validation error for an entire animation frame tile.
 
void report_color_counts (const std::string &tag, const TilesetCompileValidatorServices &services, const std::map< Rgba32, unsigned int > &color_counts)
 Emits a diagnostic note displaying the count of each unique color.
 
template<typename T , typename ConfigInterface , typename FetchFunc , typename Comparator >
ChainableResult< ConfigValue< T > > compare_values (const ConfigValue< T > &val, const ConfigInterface &config, ConfigScopeType type, const std::string &scope, const std::string &other_field_name, FetchFunc fetch_other, Comparator comp, std::string_view error_message)
 Generic comparison validator that compares the current value against another config value.
 

Function Documentation

◆ color_tile_from_index_tile_impl()

template<SupportsTransparency ColorType, std::size_t N = 0>
PixelTile< ColorType > porytiles::details::color_tile_from_index_tile_impl ( const PixelTile< IndexPixel > &  index_tile,
const Palette< ColorType, N > &  palette,
const ColorType &  transparent_color 
)

Helper function implementing the core index-to-color tile conversion logic.

This private helper converts a PixelTile<IndexPixel> to a PixelTile<ColorType> by mapping each pixel's index to its corresponding color in the provided palette. It accepts a transparent_color parameter that determines what color to use for index 0 pixels, allowing the same implementation to work with both intrinsic and extrinsic transparency.

The algorithm:

  1. For each pixel in the tile:
    • If index is 0, maps to transparent_color
    • Otherwise, looks up the color in the palette's index-to-color map
    • If not found, panics (indicates invalid index)
Template Parameters
ColorTypeThe color type of the palette and output tile
Parameters
index_tileThe PixelTile containing IndexPixel values to convert
paletteThe Palette containing the colors to look up
transparent_colorThe color to use for index 0 (transparent) pixels
Precondition
palette is not empty
All non-zero indices in index_tile are within the bounds of the palette [1, palette.size())
Returns
A PixelTile<ColorType> where each pixel is the palette color corresponding to the index

Definition at line 168 of file tile_converters.hpp.

◆ compare_values()

template<typename T , typename ConfigInterface , typename FetchFunc , typename Comparator >
ChainableResult< ConfigValue< T > > porytiles::details::compare_values ( const ConfigValue< T > &  val,
const ConfigInterface &  config,
ConfigScopeType  type,
const std::string &  scope,
const std::string &  other_field_name,
FetchFunc  fetch_other,
Comparator  comp,
std::string_view  error_message 
)

Generic comparison validator that compares the current value against another config value.

This is the generic implementation for all cross-field comparison validators. It fetches another config value using the provided lambda and performs a comparison using the provided comparator. If the comparison fails, returns a detailed error message showing both values and their sources. This function is used internally by the public comparison validator functions.

Template Parameters
TThe type of the config values being compared (must support the comparator's operation)
ConfigInterfaceThe config interface type (DomainConfig, AppConfig, or InfraConfig)
FetchFuncCallable type that fetches the other config value
ComparatorCallable type that performs the comparison (e.g., std::greater<>, std::less<>)
Parameters
valThe config value being validated
configThe config interface to fetch other values from
typeThe config scope type (tileset or layout)
scopeThe scope name (tileset or layout name)
other_field_nameThe name of the other field to compare against
fetch_otherCallable that fetches the other config value
compComparator that performs the comparison operation
error_messageThe error message to display if validation fails (e.g., "must be greater than")
Returns
ChainableResult containing either the original value or an error

Definition at line 176 of file xcut_config_validators.hpp.

◆ from_pixel_tile_impl()

template<SupportsTransparency PixelType, typename TransparencyPredicate >
ShapeTile< ColorIndex > porytiles::details::from_pixel_tile_impl ( const PixelTile< PixelType > &  pixel_tile,
const ColorIndexMap< PixelType > &  color_index_map,
TransparencyPredicate  is_transparent_pred 
)

Helper function implementing the core PixelTile to ShapeTile conversion logic.

This private helper contains the common conversion logic shared by both from_pixel_tile() overloads. It accepts a transparency predicate (function/lambda) that determines whether a pixel is transparent, allowing the same implementation to work with both intrinsic and extrinsic transparency checking.

Template Parameters
PixelTypeThe pixel type of the input tile
TransparencyPredicateA callable type that takes a PixelType and returns bool
Parameters
pixel_tileThe PixelTile to convert
color_index_mapThe ColorIndexMap providing color-to-index mappings
is_transparent_predA predicate function that returns true if a pixel is transparent
Precondition
All non-transparent pixels in pixel_tile must be present in color_index_map
Returns
A ShapeTile<ColorIndex> with ShapeMasks mapped to color indices

Definition at line 35 of file tile_converters.hpp.

◆ index_tile_from_color_tile_impl()

template<SupportsTransparency ColorType, std::size_t N = 0, typename TransparencyPredicate >
PixelTile< IndexPixel > porytiles::details::index_tile_from_color_tile_impl ( const PixelTile< ColorType > &  tile,
const Palette< ColorType, N > &  palette,
TransparencyPredicate  is_transparent_pred 
)

Helper function implementing the core color-to-index tile conversion logic.

This private helper converts a PixelTile<ColorType> to a PixelTile<IndexPixel> by mapping each pixel's color to its corresponding index in the provided palette. It accepts a transparency predicate that determines whether a pixel is transparent, allowing the same implementation to work with both intrinsic and extrinsic transparency checking.

The algorithm:

  1. Builds a color-to-index map from the palette for O(log n) lookup
  2. For each pixel in the tile:
    • If transparent (per predicate), maps to index 0
    • If not transparent, looks up the color in the palette and uses that index
    • If not found, panics (caller should use match_tile_to_palette first to verify coverage)
Template Parameters
ColorTypeThe color type of the palette and tile
TransparencyPredicateA callable type that takes a ColorType and returns bool
Parameters
tileThe PixelTile to convert to indexed form
paletteThe Palette containing the color-to-index mapping
is_transparent_predA predicate function that returns true if a color is transparent
Precondition
All non-transparent colors in the tile must exist in the palette's non-0 slots
If tile contains non-transparent pixels, palette may not be empty
Returns
A PixelTile<IndexPixel> where each pixel is the palette index corresponding to the color

Definition at line 105 of file tile_converters.hpp.

◆ match_tile_to_palette_impl()

template<SupportsTransparency ColorType, typename TransparencyPredicate , std::size_t N = 0>
PaletteMatchResult< ColorType > porytiles::details::match_tile_to_palette_impl ( const PixelTile< ColorType > &  tile,
const Palette< ColorType, N > &  palette,
TransparencyPredicate  is_transparent_pred 
)

Helper function implementing the core palette matching logic.

This private helper contains the common matching logic shared by both match_tile_to_palette() overloads. It accepts a transparency predicate (function/lambda) that determines whether a pixel is transparent, allowing the same implementation to work with both intrinsic and extrinsic transparency checking.

The algorithm:

  1. Extracts all unique non-transparent colors from the tile
  2. For each color, checks if it exists in the palette
  3. Categorizes colors as either "covered" (found in palette) or "missing" (not in palette)
  4. Sets is_covered to true if no colors are missing
Template Parameters
ColorTypeThe color type of the palette and tile
TransparencyPredicateA callable type that takes a ColorType and returns bool
NThe palette size (0 for dynamic, non-zero for fixed-size)
Parameters
tileThe PixelTile to match against the palette
paletteThe Palette to check for color coverage
is_transparent_predA predicate function that returns true if a color is transparent
Returns
A PaletteMatchResult indicating coverage status and color sets

Definition at line 81 of file palette_matchers.hpp.

◆ report_color_counts()

void porytiles::details::report_color_counts ( const std::string &  tag,
const TilesetCompileValidatorServices services,
const std::map< Rgba32, unsigned int > &  color_counts 
)
inline

Emits a diagnostic note displaying the count of each unique color.

Formats and prints a color count summary as a note diagnostic. This is typically used as a follow-up to a color count violation error to help users understand which colors are present in the problematic tile or metatile.

Parameters
tagDiagnostic code to associate with this note.
servicesCommon services for formatting and diagnostic output.
color_countsMap of colors to their occurrence counts.

Definition at line 183 of file tileset_compile_validators.hpp.

◆ report_validation_error_in_anim()

void porytiles::details::report_validation_error_in_anim ( const TilesetCompileValidatorServices services,
const PixelTile< Rgba32 > &  tile,
const std::string &  anim_name,
const std::string &  frame_name,
std::size_t  internal_tile_index,
std::size_t  row,
std::size_t  col,
const std::string &  diagnostic_code,
const std::string &  error_message,
const Rgba32 extrinsic_transparency 
)
inline

Reports a validation error at a specific pixel location within an animation frame tile.

Emits a formatted error diagnostic that includes the animation name, frame name, tile index, and the specific pixel coordinates where the error occurred. The diagnostic includes a visual highlight of the problematic pixel within the tile context.

Parameters
servicesCommon services for formatting and diagnostic output.
tileThe pixel tile containing the validation error.
anim_nameName of the animation containing the error.
frame_nameName of the frame within the animation.
internal_tile_indexIndex of the tile within the frame's tile array.
rowRow position of the pixel within the tile (0-7).
colColumn position of the pixel within the tile (0-7).
diagnostic_codeUnique identifier for this type of diagnostic.
error_messageHuman-readable description of the validation error.
extrinsic_transparencyThe transparency color used for rendering the highlight.

Definition at line 112 of file tileset_compile_validators.hpp.

◆ report_validation_error_in_anim_tile()

void porytiles::details::report_validation_error_in_anim_tile ( const TilesetCompileValidatorServices services,
const PixelTile< Rgba32 > &  tile,
const std::string &  anim_name,
const std::string &  frame_name,
std::size_t  internal_tile_index,
const std::string &  diagnostic_code,
const std::string &  error_message,
const Rgba32 extrinsic_transparency 
)
inline

Reports a validation error for an entire animation frame tile.

Emits a formatted error diagnostic that includes the animation name, frame name, and tile index. Unlike report_validation_error_in_anim which highlights a specific pixel, this function displays the entire tile visual. Use this for tile-level errors like transparency violations or color count violations.

Parameters
servicesCommon services for formatting and diagnostic output.
tileThe pixel tile containing the validation error.
anim_nameName of the animation containing the error.
frame_nameName of the frame within the animation.
internal_tile_indexIndex of the tile within the frame's tile array.
diagnostic_codeUnique identifier for this type of diagnostic.
error_messageHuman-readable description of the validation error.
extrinsic_transparencyThe transparency color used for rendering.

Definition at line 152 of file tileset_compile_validators.hpp.

◆ report_validation_error_in_metatile()

void porytiles::details::report_validation_error_in_metatile ( const TilesetCompileValidatorServices services,
const Metatile< Rgba32 > &  metatile,
std::size_t  metatile_index,
std::size_t  internal_tile_index,
std::size_t  row,
std::size_t  col,
const std::string &  diagnostic_code,
const std::string &  error_message,
const Rgba32 extrinsic_transparency 
)
inline

Reports a validation error at a specific pixel location within a metatile.

Emits a formatted error diagnostic that includes the metatile location, layer, subtile position, and the specific pixel coordinates where the error occurred. The diagnostic includes a visual highlight of the problematic pixel within the metatile context.

Parameters
servicesCommon services for formatting and diagnostic output.
metatileThe metatile containing the validation error.
metatile_indexZero-based index of the metatile in the input sequence.
internal_tile_indexIndex of the tile within the decomposed metatile (0-11 for triple layer).
rowRow position of the pixel within the tile (0-7).
colColumn position of the pixel within the tile (0-7).
diagnostic_codeUnique identifier for this type of diagnostic.
error_messageHuman-readable description of the validation error.
extrinsic_transparencyThe transparency color used for rendering the highlight.

Definition at line 70 of file tileset_compile_validators.hpp.