Porytiles
Loading...
Searching...
No Matches
porytiles::AnimTileMatcher Class Reference

Matches tiles against animation keyframe tiles for compilation. More...

#include <anim_tile_matcher.hpp>

Public Member Functions

void register_animation (const std::string &anim_name, const Animation< Rgba32 > &animation, std::size_t tile_offset, const Rgba32 &extrinsic_transparency, bool is_cross_tileset=false)
 Registers an animation's keyframe tiles for matching.
 
std::optional< AnimTileMatchfind_match (const CanonicalPixelTile< Rgba32 > &tile, const Rgba32 &extrinsic_transparency) const
 Attempts to match a tile against registered animation keyframes.
 
std::size_t total_keyframe_tiles () const
 Returns the total number of keyframe tiles registered across all animations.
 
std::optional< std::size_t > tile_offset_for (const std::string &anim_name) const
 Returns the tile offset for a registered animation.
 
std::optional< std::size_t > tile_count_for (const std::string &anim_name) const
 Returns the tile count for a registered animation.
 
bool is_in_animation_range (std::size_t tile_index) const
 Checks whether a tile index falls within any registered animation range.
 
void clear ()
 Clears all registered animations.
 

Detailed Description

Matches tiles against animation keyframe tiles for compilation.

AnimationTileMatcher is used during tileset compilation to detect when a metatile tile corresponds to an animation keyframe. Instead of inserting the tile normally into TilesPngWorkspace, the compiler should reference the pre-placed animation tile at its reserved offset.

The matcher builds an internal lookup map from canonical tile forms to animation tile info, enabling O(1) matching during the compilation assignment step.

Usage during compilation:

  1. Create matcher and register all animations with their tile offsets
  2. For each tile encountered during metatile processing, call find_match()
  3. If a match is found, use the returned tile index and flip bits instead of normal workspace insertion
AnimationTileMatcher matcher;
matcher.register_animation("flower", flower_animation, 1); // tile_offset = 1
for (each metatile tile) {
auto match = matcher.find_match(tile);
if (match) {
// Use match->tile_index and match->h_flip/v_flip
} else {
// Normal workspace insertion
}
}

Definition at line 60 of file anim_tile_matcher.hpp.

Member Function Documentation

◆ clear()

void porytiles::AnimTileMatcher::clear ( )

Clears all registered animations.

Definition at line 125 of file anim_tile_matcher.cpp.

◆ find_match()

std::optional< AnimTileMatch > porytiles::AnimTileMatcher::find_match ( const CanonicalPixelTile< Rgba32 > &  tile,
const Rgba32 extrinsic_transparency 
) const

Attempts to match a tile against registered animation keyframes.

Searches the lookup map for a tile that matches the given canonical tile (considering all flip orientations). The cross-ET comparator on the map compares each candidate under its own registered extrinsic transparency, so registered entries and the input tile may have been compiled under different ETs and still match when their opaque-pixel patterns coincide.

Parameters
tileThe canonical tile to match.
extrinsic_transparencyThe extrinsic transparency value applied to tile during the cross-ET lookup. Typically this is the ET configured for the tileset whose pixel data tile was derived from.
Returns
Match information if found, std::nullopt otherwise.

Definition at line 72 of file anim_tile_matcher.cpp.

◆ is_in_animation_range()

bool porytiles::AnimTileMatcher::is_in_animation_range ( std::size_t  tile_index) const

Checks whether a tile index falls within any registered animation range.

Iterates over all registered animations and checks if tile_index falls within [tile_offset, tile_offset + tile_count) for any of them.

Parameters
tile_indexThe absolute tile index in tiles.png to check.
Returns
true if tile_index falls within a registered animation range, false otherwise.

Definition at line 118 of file anim_tile_matcher.cpp.

◆ register_animation()

void porytiles::AnimTileMatcher::register_animation ( const std::string &  anim_name,
const Animation< Rgba32 > &  animation,
std::size_t  tile_offset,
const Rgba32 extrinsic_transparency,
bool  is_cross_tileset = false 
)

Registers an animation's keyframe tiles for matching.

Extracts all tiles from the animation's keyframe (frame 0) and registers them in the lookup map. Each tile is stored in canonical form along with metadata about its position and the animation it belongs to.

Parameters
anim_nameName of the animation.
animationThe animation with RGBA tiles.
tile_offsetThe starting tile index in tiles.png for this animation's keyframe.
extrinsic_transparencyThe extrinsic transparent color.
is_cross_tilesetWhether this animation is cross-tileset, i.e. from the paired primary
Precondition
animation must have at least one frame (the keyframe).

Definition at line 11 of file anim_tile_matcher.cpp.

◆ tile_count_for()

std::optional< std::size_t > porytiles::AnimTileMatcher::tile_count_for ( const std::string &  anim_name) const

Returns the tile count for a registered animation.

Parameters
anim_nameName of the animation
Returns
The tile count if the animation is registered, std::nullopt otherwise

Definition at line 109 of file anim_tile_matcher.cpp.

◆ tile_offset_for()

std::optional< std::size_t > porytiles::AnimTileMatcher::tile_offset_for ( const std::string &  anim_name) const

Returns the tile offset for a registered animation.

Parameters
anim_nameName of the animation
Returns
The tile offset if the animation is registered, std::nullopt otherwise

Definition at line 100 of file anim_tile_matcher.cpp.

◆ total_keyframe_tiles()

std::size_t porytiles::AnimTileMatcher::total_keyframe_tiles ( ) const
inline

Returns the total number of keyframe tiles registered across all animations.

Returns
Total tile count for all registered animations

Definition at line 105 of file anim_tile_matcher.hpp.


The documentation for this class was generated from the following files: