Porytiles
Loading...
Searching...
No Matches
shape_mask.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <cstdint>
5
7
8namespace porytiles2 {
9
10ShapeMask ShapeMask::flip(bool h, bool v) const
11{
12 if (!h && !v) {
13 return *this;
14 }
15
16 ShapeMask result;
17 const int8_t v_inc = v ? -1 : 1;
18 const int8_t v_start = v ? 7 : 0;
19
20 for (int y = 0; y < 8; ++y) {
21 const int ry = y * v_inc + v_start;
22 result.rows_[y] = h ? reverse_bits(rows_[ry]) : rows_[ry];
23 }
24 return result;
25}
26
27void ShapeMask::set(int row, int col)
28{
29 rows_[row] |= (1 << (7 - col));
30}
31
32void ShapeMask::unset(int row, int col)
33{
34 rows_[row] &= ~(1 << (7 - col));
35}
36
37bool ShapeMask::get(int row, int col) const
38{
39 return (rows_[row] & (1 << (7 - col))) != 0;
40}
41
43{
44 return std::ranges::all_of(rows_, [](uint8_t byte) { return byte == 0; });
45}
46
47} // namespace porytiles2
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.
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.
constexpr uint8_t reverse_bits(uint8_t b)
Reverses the bits in a byte.