summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-01 14:54:30 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-01 14:54:30 +0100
commit7ff1f0911e0b0c314d6e639887b705d6fc0d78aa (patch)
treecf3f11ce4e60a4a98a9bcff6510d39a692859441
parent60eea789335743855f380249b8bbaf544fea3887 (diff)
wip
-rw-r--r--compat/int-hash.hpp2
-rw-r--r--src/chunk.hpp8
-rw-r--r--src/local-coords.hpp1
-rw-r--r--src/random.hpp3
-rw-r--r--src/tile-iterator.cpp18
-rw-r--r--src/tile-iterator.hpp33
6 files changed, 28 insertions, 37 deletions
diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp
index 43b92605..ee2dbf16 100644
--- a/compat/int-hash.hpp
+++ b/compat/int-hash.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include <cstddef>
+#include "integer-types.hpp"
namespace floormat {
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 5ffc1680..6031b913 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -7,11 +7,6 @@
namespace floormat {
-template<typename T> class basic_tile_iterator;
-
-struct tile_ref;
-struct pass_mode_ref;
-
struct chunk final
{
friend struct tile_ref;
@@ -26,8 +21,7 @@ struct chunk final
auto& tiles() noexcept { return _tiles; }
#endif
- using iterator = basic_tile_iterator<tile>;
- using const_iterator = basic_tile_iterator<const tile>;
+ using iterator = tile_iterator;
#if 0
iterator begin() noexcept { return iterator{_tiles.data(), 0}; }
diff --git a/src/local-coords.hpp b/src/local-coords.hpp
index 01101ded..e0aea1d6 100644
--- a/src/local-coords.hpp
+++ b/src/local-coords.hpp
@@ -1,6 +1,5 @@
#pragma once
#include "compat/assert.hpp"
-#include "compat/int-hash.hpp"
#include "tile-defs.hpp"
#include <concepts>
diff --git a/src/random.hpp b/src/random.hpp
index 84d8ca2a..7ac51c7b 100644
--- a/src/random.hpp
+++ b/src/random.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <cstddef>
-#include <concepts>
+#include "compat/integer-types.hpp"
#include <type_traits>
namespace floormat {
diff --git a/src/tile-iterator.cpp b/src/tile-iterator.cpp
index b454576a..943bbaf8 100644
--- a/src/tile-iterator.cpp
+++ b/src/tile-iterator.cpp
@@ -3,15 +3,17 @@
namespace floormat {
-basic_tile_iterator::basic_tile_iterator(chunk& c, std::size_t pos) noexcept :
- c{&c}, pos{pos}
-{
-}
+tile_iterator::tile_iterator(chunk& c, std::size_t pos) noexcept : c{&c}, pos{pos} {}
+tile_iterator::tile_iterator(const tile_iterator&) noexcept = default;
+tile_iterator& tile_iterator::operator=(const tile_iterator&) noexcept = default;
-basic_tile_iterator::basic_tile_iterator(const basic_tile_iterator&) noexcept = default;
-basic_tile_iterator& basic_tile_iterator::operator=(const basic_tile_iterator&) noexcept = default;
-std::strong_ordering basic_tile_iterator::operator<=>(const basic_tile_iterator&) const noexcept = default;
-void basic_tile_iterator::swap(basic_tile_iterator& other) { std::swap(c, other.c); std::swap(pos, other.pos); }
+tile_iterator& tile_iterator::operator++() noexcept { pos++; return *this; }
+tile_iterator tile_iterator::operator++() noexcept { auto it = *this; pos++; return it; }
+void tile_iterator::swap(tile_iterator& other) noexcept { std::swap(c, other.c); std::swap(pos, other.pos); }
+std::strong_ordering tile_iterator::operator<=>(const tile_iterator&) const noexcept = default;
+
+tile_iterator_tuple tile_iterator::operator->() { return { tile_ref{*c, i}, i, local_coords{i} }; }
+tile_iterator_tuple tile_iterator::operator*() { return { tile_ref{*c, i}, i, local_coords{i} }; }
} // namespace floormat
diff --git a/src/tile-iterator.hpp b/src/tile-iterator.hpp
index 91d85cad..2f860380 100644
--- a/src/tile-iterator.hpp
+++ b/src/tile-iterator.hpp
@@ -1,40 +1,37 @@
#pragma once
+#include "compat/integer-types.hpp"
#include "local-coords.hpp"
#include "tile.hpp"
-#include <iterator>
-#include <tuple>
-#include <utility>
-#include <type_traits>
+#include <compare>
namespace floormat {
-struct tile_tuple final {
- const tile_tuple* operator->() const noexcept { return this; }
- tile_tuple* operator->() noexcept { return this; }
+struct tile_iterator_tuple final { // NOLINT(cppcoreguidelines-pro-type-member-init)
+ const tile_iterator_tuple* operator->() const noexcept { return this; }
+ tile_iterator_tuple* operator->() noexcept { return this; }
tile_ref tile;
std::size_t i;
local_coords pos;
};
-class basic_tile_iterator final {
+class tile_iterator final {
chunk* c;
std::size_t pos;
public:
- explicit basic_tile_iterator(chunk& c, std::size_t pos) noexcept;
- basic_tile_iterator(const basic_tile_iterator&) noexcept;
- basic_tile_iterator& operator=(const basic_tile_iterator&) noexcept;
+ explicit tile_iterator(chunk& c, std::size_t pos) noexcept;
+ tile_iterator(const tile_iterator&) noexcept;
+ tile_iterator& operator=(const tile_iterator&) noexcept;
- std::strong_ordering operator<=>(const basic_tile_iterator&) const noexcept;
- void swap(basic_tile_iterator& other);
+ std::strong_ordering operator<=>(const tile_iterator&) const noexcept;
+ void swap(tile_iterator& other) noexcept;
- basic_tile_iterator& operator++();
- basic_tile_iterator operator++(int);
- tile_tuple operator->();
- tile_tuple operator*();
+ tile_iterator& operator++() noexcept;
+ tile_iterator operator++(int) noexcept;
+ tile_iterator_tuple operator->() noexcept;
+ tile_iterator_tuple operator*() noexcept;
};
} // namespace floormat
-