summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-04 21:14:53 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-05 03:24:48 +0200
commitfbc36568af5d9142a45bee57323b8a5457a114f8 (patch)
tree8d838f0ad42823e4816a5ad4cdd66d03434ba6ad
parent78ca913d82a0c30e978b69a8ed2685d92ae9eb36 (diff)
src: remove the tile_iterator class
This is too crufty to bother with.
-rw-r--r--editor/update.cpp5
-rw-r--r--src/chunk.cpp8
-rw-r--r--src/chunk.hpp7
-rw-r--r--src/tile-iterator.cpp26
-rw-r--r--src/tile-iterator.hpp78
-rw-r--r--test/app.hpp1
-rw-r--r--test/json.cpp3
-rw-r--r--test/save.cpp8
-rw-r--r--test/tile-iter.cpp37
9 files changed, 5 insertions, 168 deletions
diff --git a/editor/update.cpp b/editor/update.cpp
index 7fdcd77e..4d1cb3ad 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -11,7 +11,6 @@
#include "floormat/events.hpp"
#include "floormat/main.hpp"
#include "src/critter.hpp"
-#include "src/tile-iterator.hpp"
#include "src/nanosecond.hpp"
#include "src/timer.hpp"
#include "keys.hpp"
@@ -27,8 +26,8 @@ void app::maybe_initialize_chunk_([[maybe_unused]] const chunk_coords_& pos, chu
{
auto floor1 = loader.ground_atlas("floor-tiles");
- for (auto [x, k, pt] : c)
- x.ground() = { floor1, variant_t(k % floor1->num_tiles()) };
+ for (auto k = 0u; k < TILE_COUNT; k++)
+ c[k].ground() = { floor1, variant_t(k % floor1->num_tiles()) };
c.mark_modified();
}
diff --git a/src/chunk.cpp b/src/chunk.cpp
index 9f6fe993..c6967740 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -1,7 +1,6 @@
#include "chunk.hpp"
#include "object.hpp"
#include "world.hpp"
-#include "tile-iterator.hpp"
#include "log.hpp"
#include "RTree.h"
#include <algorithm>
@@ -69,13 +68,6 @@ Optional<tile_ref> chunk::at_offset_(local_coords pos, Vector2i off)
tile_ref chunk::at_offset(tile_ref r, Vector2i off) { return at_offset(local_coords{r.index()}, off); }
Optional<tile_ref> chunk::at_offset_(tile_ref r, Vector2i off) { return at_offset_(local_coords{r.index()}, off); }
-auto chunk::begin() noexcept -> iterator { return iterator { *this, 0 }; }
-auto chunk::end() noexcept -> iterator { return iterator { *this, TILE_COUNT }; }
-auto chunk::cbegin() const noexcept -> const_iterator { return const_iterator { *this, 0 }; }
-auto chunk::cend() const noexcept -> const_iterator { return const_iterator { *this, TILE_COUNT }; }
-auto chunk::begin() const noexcept -> const_iterator { return cbegin(); }
-auto chunk::end() const noexcept -> const_iterator { return cend(); }
-
void chunk::mark_ground_modified() noexcept
{
if (!_ground_modified && is_log_verbose()) [[unlikely]]
diff --git a/src/chunk.hpp b/src/chunk.hpp
index dea7e00b..e5f3cc85 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -42,13 +42,6 @@ public:
using iterator = tile_iterator;
using const_iterator = tile_const_iterator;
- iterator begin() noexcept;
- iterator end() noexcept;
- const_iterator cbegin() const noexcept;
- const_iterator cend() const noexcept;
- const_iterator begin() const noexcept;
- const_iterator end() const noexcept;
-
bool empty(bool force = false) const noexcept;
explicit chunk(class world& w, chunk_coords_ ch) noexcept;
diff --git a/src/tile-iterator.cpp b/src/tile-iterator.cpp
deleted file mode 100644
index ac0fff67..00000000
--- a/src/tile-iterator.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "tile-iterator.hpp"
-#include "tile.hpp"
-
-namespace floormat {
-
-tile_iterator::tile_iterator(chunk& c, 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;
-tile_iterator& tile_iterator::operator++() noexcept { pos++; return *this; }
-tile_iterator tile_iterator::operator++(int) 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); }
-bool operator==(const tile_iterator& a, const tile_iterator& b) noexcept { return a.c == b.c && a.pos == b.pos; }
-tile_iterator_tuple tile_iterator::operator->() noexcept { return { tile_ref{*c, uint8_t(pos)}, pos, local_coords{pos} }; }
-tile_iterator_tuple tile_iterator::operator*() noexcept { return operator->(); }
-
-tile_const_iterator::tile_const_iterator(const chunk& c, size_t pos) noexcept : c{&c}, pos{pos} {}
-tile_const_iterator::tile_const_iterator(const tile_const_iterator& x) noexcept = default;
-tile_const_iterator& tile_const_iterator::operator=(const tile_const_iterator& x) noexcept { if (this != &x) { c = x.c; pos = x.pos; } return *this; }
-tile_const_iterator& tile_const_iterator::operator++() noexcept { pos++; return *this; }
-tile_const_iterator tile_const_iterator::operator++(int) noexcept { auto it = *this; pos++; return it; }
-void tile_const_iterator::swap(tile_const_iterator& other) noexcept { std::swap(c, other.c); std::swap(pos, other.pos); }
-bool operator==(const tile_const_iterator& a, const tile_const_iterator& b) noexcept { return a.c == b.c && a.pos == b.pos; }
-tile_const_iterator_tuple tile_const_iterator::operator->() noexcept { return { tile_proto(tile_ref{*const_cast<chunk*>(c), uint8_t(pos)}), pos, local_coords{pos}, }; }
-tile_const_iterator_tuple tile_const_iterator::operator*() noexcept { return operator->(); }
-
-} // namespace floormat
diff --git a/src/tile-iterator.hpp b/src/tile-iterator.hpp
deleted file mode 100644
index f3b19dfc..00000000
--- a/src/tile-iterator.hpp
+++ /dev/null
@@ -1,78 +0,0 @@
-#pragma once
-
-#include "local-coords.hpp"
-#include "tile.hpp"
-
-#include <iterator>
-
-namespace floormat {
-
-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 x;
- size_t k;
- local_coords pt;
-};
-
-struct tile_const_iterator_tuple final { // NOLINT(cppcoreguidelines-pro-type-member-init)
- const tile_const_iterator_tuple* operator->() const noexcept { return this; }
- tile_const_iterator_tuple* operator->() noexcept { return this; }
-
- tile_proto x;
- size_t k;
- local_coords pt;
-};
-
-class tile_iterator final {
- chunk* c;
- size_t pos;
-
- friend bool operator==(const tile_iterator&, const tile_iterator&) noexcept;
-
-public:
- explicit tile_iterator(chunk& c, size_t pos) noexcept;
- tile_iterator(const tile_iterator&) noexcept;
- tile_iterator& operator=(const tile_iterator&) noexcept;
-
- void swap(tile_iterator& other) noexcept;
-
- tile_iterator& operator++() noexcept;
- tile_iterator operator++(int) noexcept;
- tile_iterator_tuple operator->() noexcept;
- tile_iterator_tuple operator*() noexcept;
-
- using difference_type = ptrdiff_t;
- using value_type = tile_iterator_tuple;
- using pointer = value_type;
- using reference = value_type;
- using iterator_category = std::input_iterator_tag;
-};
-
-class tile_const_iterator final {
- const chunk* c;
- size_t pos;
-
- friend bool operator==(const tile_const_iterator&, const tile_const_iterator&) noexcept;
-
-public:
- explicit tile_const_iterator(const chunk& c, size_t pos) noexcept;
- tile_const_iterator(const tile_const_iterator&) noexcept;
- tile_const_iterator& operator=(const tile_const_iterator&) noexcept;
-
- void swap(tile_const_iterator& other) noexcept;
-
- tile_const_iterator& operator++() noexcept;
- tile_const_iterator operator++(int) noexcept;
- tile_const_iterator_tuple operator->() noexcept;
- tile_const_iterator_tuple operator*() noexcept;
-
- using difference_type = ptrdiff_t;
- using value_type = tile_const_iterator_tuple;
- using pointer = value_type;
- using reference = value_type;
- using iterator_category = std::input_iterator_tag;
-};
-
-} // namespace floormat
diff --git a/test/app.hpp b/test/app.hpp
index b2575433..3aa24b73 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -43,7 +43,6 @@ struct test_app final : private FM_APPLICATION
static void test_save();
static void test_saves();
static void test_script();
- static void test_tile_iter();
static void test_wall_atlas();
static void test_wall_atlas2();
diff --git a/test/json.cpp b/test/json.cpp
index 5733c691..372465b5 100644
--- a/test/json.cpp
+++ b/test/json.cpp
@@ -1,13 +1,10 @@
#include "app.hpp"
-#include "serialize/tile.hpp"
#include "serialize/ground-atlas.hpp"
#include "serialize/wall-atlas.hpp"
#include "serialize/magnum-vector.hpp"
#include "serialize/json-helper.hpp"
#include "compat/assert.hpp"
#include "src/ground-atlas.hpp"
-#include "src/tile.hpp"
-#include "src/tile-iterator.hpp"
#include "src/chunk.hpp"
#include "src/world.hpp"
#include "loader/loader.hpp"
diff --git a/test/save.cpp b/test/save.cpp
index 2df1d296..bc3ed954 100644
--- a/test/save.cpp
+++ b/test/save.cpp
@@ -8,7 +8,6 @@
#include "src/light.hpp"
#include "src/ground-atlas.hpp"
#include "src/anim-atlas.hpp"
-#include "src/tile-iterator.hpp"
#include "src/nanosecond.inl"
#include <Corrade/Utility/Path.h>
@@ -27,11 +26,10 @@ chunk& test_app::make_test_chunk(world& w, chunk_coords_ ch)
auto table = loader.scenery("table1");
auto control_panel = loader.scenery("control panel (wall) 1");
- constexpr auto N = TILE_MAX_DIM;
- for (auto [x, k, pt] : c)
- x.ground() = { tiles, variant_t(k % tiles->num_tiles()) };
+ for (auto k = 0u; k < TILE_COUNT; k++)
+ c[k].ground() = { tiles, variant_t(k % tiles->num_tiles()) };
control_panel.r = rotation::W;
- constexpr auto K = N/2;
+ constexpr auto K = TILE_MAX_DIM/2;
c[{K, K }].wall_north() = { metal2, 0 };
c[{K, K }].wall_west() = { metal2, 0 };
c[{K, K+1}].wall_north() = { metal2, 0 };
diff --git a/test/tile-iter.cpp b/test/tile-iter.cpp
deleted file mode 100644
index 086fd3ce..00000000
--- a/test/tile-iter.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "app.hpp"
-#include "src/chunk.hpp"
-#include "src/world.hpp"
-#include "src/tile-iterator.hpp"
-namespace floormat {
-
-static inline bool always_false()
-{
- volatile bool ret = false;
- return ret;
-}
-
-void test_app::test_tile_iter() // NOLINT(readability-function-size)
-{
- if (always_false())
- {
- world w;
- const chunk c{w, {}};
- for ([[maybe_unused]] const auto& [x, k, pt] : c)
- static_assert(std::is_same_v<decltype(x), const tile_proto>);
- for ([[maybe_unused]] const auto [x, k, pt] : c)
- static_assert(std::is_same_v<decltype(x), const tile_proto>);
- for ([[maybe_unused]] auto [x, k, pt] : c)
- static_assert(std::is_same_v<decltype(x), tile_proto>);
- }
- if (always_false())
- {
- world w;
- chunk c{w, {}};
- for ([[maybe_unused]] auto [x, k, pt] : c)
- static_assert(std::is_same_v<decltype(x), tile_ref>);
- for ([[maybe_unused]] const auto [x, k, pt] : c)
- static_assert(std::is_same_v<decltype(x), const tile_ref>);
- }
-}
-
-} // namespace floormat