|
Porytiles
|
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< AnimTileMatch > | find_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. | |
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:
find_match()Definition at line 60 of file anim_tile_matcher.hpp.
| void porytiles::AnimTileMatcher::clear | ( | ) |
Clears all registered animations.
Definition at line 125 of file anim_tile_matcher.cpp.
| 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.
| tile | The canonical tile to match. |
| extrinsic_transparency | The 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. |
std::nullopt otherwise. Definition at line 72 of file anim_tile_matcher.cpp.
| 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.
| tile_index | The absolute tile index in tiles.png to check. |
true if tile_index falls within a registered animation range, false otherwise. Definition at line 118 of file anim_tile_matcher.cpp.
| 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.
| anim_name | Name of the animation. |
| animation | The animation with RGBA tiles. |
| tile_offset | The starting tile index in tiles.png for this animation's keyframe. |
| extrinsic_transparency | The extrinsic transparent color. |
| is_cross_tileset | Whether this animation is cross-tileset, i.e. from the paired primary |
animation must have at least one frame (the keyframe). Definition at line 11 of file anim_tile_matcher.cpp.
| std::optional< std::size_t > porytiles::AnimTileMatcher::tile_count_for | ( | const std::string & | anim_name | ) | const |
Returns the tile count for a registered animation.
| anim_name | Name of the animation |
Definition at line 109 of file anim_tile_matcher.cpp.
| std::optional< std::size_t > porytiles::AnimTileMatcher::tile_offset_for | ( | const std::string & | anim_name | ) | const |
Returns the tile offset for a registered animation.
| anim_name | Name of the animation |
Definition at line 100 of file anim_tile_matcher.cpp.
|
inline |
Returns the total number of keyframe tiles registered across all animations.
Definition at line 105 of file anim_tile_matcher.hpp.