From fbc36568af5d9142a45bee57323b8a5457a114f8 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 4 May 2024 21:14:53 +0200 Subject: src: remove the tile_iterator class This is too crufty to bother with. --- editor/update.cpp | 5 ++-- src/chunk.cpp | 8 ------ src/chunk.hpp | 7 ----- src/tile-iterator.cpp | 26 ----------------- src/tile-iterator.hpp | 78 --------------------------------------------------- test/app.hpp | 1 - test/json.cpp | 3 -- test/save.cpp | 8 ++---- test/tile-iter.cpp | 37 ------------------------ 9 files changed, 5 insertions(+), 168 deletions(-) delete mode 100644 src/tile-iterator.cpp delete mode 100644 src/tile-iterator.hpp delete mode 100644 test/tile-iter.cpp 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 @@ -69,13 +68,6 @@ Optional 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 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(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 - -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 @@ -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); - for ([[maybe_unused]] const auto [x, k, pt] : c) - static_assert(std::is_same_v); - for ([[maybe_unused]] auto [x, k, pt] : c) - static_assert(std::is_same_v); - } - if (always_false()) - { - world w; - chunk c{w, {}}; - for ([[maybe_unused]] auto [x, k, pt] : c) - static_assert(std::is_same_v); - for ([[maybe_unused]] const auto [x, k, pt] : c) - static_assert(std::is_same_v); - } -} - -} // namespace floormat -- cgit v1.2.3