summaryrefslogtreecommitdiffhomepage
path: root/src/tile.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-07 16:05:34 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-07 16:05:34 +0200
commit38440873ac8bf0862de7ba225657df09c5aee9e4 (patch)
tree45d06046aedac4111610a40c6f020f2f7feceef6 /src/tile.hpp
parent2caeb3de2a3b6c79d6c3bce6898eaee07249836f (diff)
a
Diffstat (limited to 'src/tile.hpp')
-rw-r--r--src/tile.hpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/tile.hpp b/src/tile.hpp
index 169c941b..f559ce79 100644
--- a/src/tile.hpp
+++ b/src/tile.hpp
@@ -36,12 +36,19 @@ struct tile final
struct local_coords final {
std::uint8_t x = 0, y = 0;
+ explicit constexpr local_coords(std::size_t idx);
constexpr local_coords() = default;
constexpr local_coords(std::size_t x, std::size_t y);
constexpr local_coords(std::uint8_t x, std::uint8_t y) : x{x}, y{y} {}
constexpr std::size_t to_index() const { return y*TILE_MAX_DIM + x; }
};
+constexpr local_coords::local_coords(std::size_t index) :
+ x{(std::uint8_t)(index % TILE_MAX_DIM)},
+ y{(std::uint8_t)(index / TILE_MAX_DIM)}
+{
+}
+
constexpr local_coords::local_coords(std::size_t x, std::size_t y)
: x{(std::uint8_t)x}, y{(std::uint8_t)y}
{