Porytiles
Loading...
Searching...
No Matches
shape_mask.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5
7
8namespace porytiles2 {
9
31class ShapeMask {
32 public:
33 ShapeMask() = default;
34
44 explicit ShapeMask(const std::array<uint8_t, tile::side_length_pix> &rows) : rows_{rows} {}
45
46 // (lexicographic on rows array)
47 auto operator<=>(const ShapeMask &) const = default;
48
61 [[nodiscard]] ShapeMask flip(bool h, bool v) const;
62
73 void set(int row, int col);
74
85 void unset(int row, int col);
86
98 [[nodiscard]] bool get(int row, int col) const;
99
108 [[nodiscard]] bool is_transparent() const;
109
118 [[nodiscard]] const std::array<uint8_t, 8> &rows() const
119 {
120 return rows_;
121 }
122
123 private:
124 std::array<uint8_t, tile::side_length_pix> rows_{};
125};
126
127} // namespace porytiles2
128
136template <>
137struct std::hash<porytiles2::ShapeMask> {
138 size_t operator()(const porytiles2::ShapeMask &tm) const noexcept
139 {
140 // Simple hash combining all 8 bytes
141 size_t h = 0;
142 for (const uint8_t byte : tm.rows()) {
143 h = h * 31 + byte;
144 }
145 return h;
146 }
147};
Represents which pixels in an 8x8 tile are non-transparent.
void unset(int row, int col)
Sets the bit at the specified row and column to 0.
const std::array< uint8_t, 8 > & rows() const
Returns the raw row data.
auto operator<=>(const ShapeMask &) const =default
ShapeMask flip(bool h, bool v) const
Returns a flipped version of this mask.
bool get(int row, int col) const
Gets the bit value at the specified row and column.
void set(int row, int col)
Sets the bit at the specified row and column to 1.
bool is_transparent() const
Checks if this entire ShapeMask is transparent.
ShapeMask(const std::array< uint8_t, tile::side_length_pix > &rows)
Constructs a ShapeMask from an array of row data.
size_t operator()(const porytiles2::ShapeMask &tm) const noexcept