Porytiles
Loading...
Searching...
No Matches
anim_tile_matcher.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <optional>
5#include <string>
6#include <vector>
7
11
12namespace porytiles {
13
22 std::string anim_name;
23 std::size_t tile_index;
24 std::size_t keyframe_tile_idx;
25 bool h_flip;
26 bool v_flip;
27 bool is_cross_tileset{false};
28};
29
61 public:
77 const std::string &anim_name,
78 const Animation<Rgba32> &animation,
79 std::size_t tile_offset,
80 const Rgba32 &extrinsic_transparency,
81 bool is_cross_tileset = false);
82
97 [[nodiscard]] std::optional<AnimTileMatch>
98 find_match(const CanonicalPixelTile<Rgba32> &tile, const Rgba32 &extrinsic_transparency) const;
99
105 [[nodiscard]] std::size_t total_keyframe_tiles() const
106 {
107 return total_tiles_;
108 }
109
116 [[nodiscard]] std::optional<std::size_t> tile_offset_for(const std::string &anim_name) const;
117
124 [[nodiscard]] std::optional<std::size_t> tile_count_for(const std::string &anim_name) const;
125
136 [[nodiscard]] bool is_in_animation_range(std::size_t tile_index) const;
137
141 void clear();
142
143 private:
147 struct KeyframeTileInfo {
148 std::string anim_name;
149 std::size_t tile_index; // Absolute index in tiles.png
150 std::size_t keyframe_tile_idx; // Index within keyframe
151 bool h_flip; // Flip applied to reach canonical form
152 bool v_flip;
153 bool is_cross_tileset;
154 };
155
159 struct AnimRegistration {
160 std::size_t tile_offset;
161 std::size_t tile_count;
162 };
163
172 struct KeyframeKey {
173 PixelTile<Rgba32> tile;
174 Rgba32 extrinsic_transparency;
175 };
176
186 struct KeyframeKeyCompare {
187 using is_transparent = void;
188
189 bool operator()(const KeyframeKey &a, const KeyframeKey &b) const
190 {
192 a.tile, a.extrinsic_transparency, b.tile, b.extrinsic_transparency) < 0;
193 }
194 };
195
196 // Map from canonical tile form (with its source ET) to keyframe info
197 std::map<KeyframeKey, KeyframeTileInfo, KeyframeKeyCompare> lookup_map_;
198 std::size_t total_tiles_{0};
199 std::map<std::string, AnimRegistration> animation_registrations_;
200};
201
202} // namespace porytiles
Matches tiles against animation keyframe tiles for compilation.
std::size_t total_keyframe_tiles() const
Returns the total number of keyframe tiles registered across all animations.
void clear()
Clears all registered animations.
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 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::optional< std::size_t > tile_offset_for(const std::string &anim_name) const
Returns the tile offset for a registered animation.
A complete tileset animation with name, configuration, and frame data.
Definition animation.hpp:78
A PixelTile representation that stores the canonical (lexicographically minimal) orientation among al...
static std::weak_ordering cross_et_compare(const PixelTile &a, const PixelType &a_et, const PixelTile &b, const PixelType &b_et)
Strict weak ordering that treats transparent pixels under each side's own ET as equivalent.
Represents a 32-bit RGBA color.
Definition rgba32.hpp:23
Result of matching a tile against animation keyframes.
bool v_flip
Vertical flip required to match.
std::size_t tile_index
Absolute tile index in tiles.png.
std::string anim_name
Name of the animation this keyframe belongs to.
bool h_flip
Horizontal flip required to match.
bool is_cross_tileset
True if this match is against a primary animation (cross-tileset linking)
std::size_t keyframe_tile_idx
Index within the keyframe (0, 1, 2, ...)