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 porytiles {
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(std::size_t row, std::size_t col)
28{
29 rows_[row] |= (1 << (7 - col));
30}
31
32void ShapeMask::unset(std::size_t row, std::size_t col)
33{
34 rows_[row] &= ~(1 << (7 - col));
35}
36
37bool ShapeMask::get(std::size_t row, std::size_t 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 porytiles
Represents which pixels in an 8x8 tile are non-transparent.
bool is_transparent() const
Checks if this entire ShapeMask is transparent.
ShapeMask flip(bool h, bool v) const
Returns a flipped version of this mask.
void unset(std::size_t row, std::size_t col)
Sets the bit at the specified row and column to 0.
bool get(std::size_t row, std::size_t col) const
Gets the bit value at the specified row and column.
void set(std::size_t row, std::size_t col)
Sets the bit at the specified row and column to 1.
constexpr uint8_t reverse_bits(uint8_t b)
Reverses the bits in a byte.