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
20 std::string anim_name;
21 std::size_t tile_index;
22 std::size_t keyframe_tile_idx;
23 bool h_flip;
24 bool v_flip;
25 bool is_cross_tileset{false};
26};
27
57 public:
71 const std::string &anim_name,
72 const Animation<Rgba32> &animation,
73 std::size_t tile_offset,
74 const Rgba32 &extrinsic_transparency,
75 bool is_cross_tileset = false);
76
89 [[nodiscard]] std::optional<AnimTileMatch>
90 find_match(const CanonicalPixelTile<Rgba32> &tile, const Rgba32 &extrinsic_transparency) const;
91
100 [[nodiscard]] std::size_t total_keyframe_tiles() const
101 {
102 return total_tiles_;
103 }
104
109 [[nodiscard]] std::optional<std::size_t> tile_offset_for(const std::string &anim_name) const;
110
115 [[nodiscard]] std::optional<std::size_t> tile_count_for(const std::string &anim_name) const;
116
125 [[nodiscard]] bool is_in_animation_range(std::size_t tile_index) const;
126
128 void clear();
129
130 private:
132 struct KeyframeTileInfo {
133 std::string anim_name;
134 std::size_t tile_index; // Absolute index in tiles.png
135 std::size_t keyframe_tile_idx; // Index within keyframe
136 bool h_flip; // Flip applied to reach canonical form
137 bool v_flip;
138 bool is_cross_tileset;
139 };
140
142 struct AnimRegistration {
143 std::size_t tile_offset;
144 std::size_t tile_count;
145 };
146
153 struct KeyframeKey {
154 PixelTile<Rgba32> tile;
155 Rgba32 extrinsic_transparency;
156 };
157
165 struct KeyframeKeyCompare {
166 using is_transparent = void;
167
168 bool operator()(const KeyframeKey &a, const KeyframeKey &b) const
169 {
171 a.tile, a.extrinsic_transparency, b.tile, b.extrinsic_transparency) < 0;
172 }
173 };
174
175 // Map from canonical tile form (with its source ET) to keyframe info
176 std::map<KeyframeKey, KeyframeTileInfo, KeyframeKeyCompare> lookup_map_;
177 std::size_t total_tiles_{0};
178 std::map<std::string, AnimRegistration> animation_registrations_;
179};
180
181} // 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:89
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:21
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, ...)