From 1b84fc144f77c4ebef6fdc0a476410420e0a95b3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 28 Oct 2022 18:31:18 +0200 Subject: refactoring work --- src/local-coords.hpp | 2 +- src/tile-atlas.cpp | 3 +++ src/tile-image.hpp | 24 ++++++++++++++++++++++++ src/tile.hpp | 20 +------------------- 4 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 src/tile-image.hpp (limited to 'src') diff --git a/src/local-coords.hpp b/src/local-coords.hpp index 2d449aae..01101ded 100644 --- a/src/local-coords.hpp +++ b/src/local-coords.hpp @@ -1,7 +1,7 @@ #pragma once #include "compat/assert.hpp" +#include "compat/int-hash.hpp" #include "tile-defs.hpp" -#include #include namespace floormat { diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp index 533cc8e9..e6df942f 100644 --- a/src/tile-atlas.cpp +++ b/src/tile-atlas.cpp @@ -1,5 +1,7 @@ #include "tile-atlas.hpp" #include "compat/assert.hpp" +#include "tile-image.hpp" +#include #include #include #include @@ -11,6 +13,7 @@ tile_atlas::tile_atlas(StringView name, const ImageView2D& image, Vector2ub tile texcoords_{make_texcoords_array(Vector2ui(image.size()), tile_count)}, name_{name}, size_{image.size()}, dims_{tile_count} { + fm_assert(num_tiles() <= std::numeric_limits::max()); fm_assert(dims_[0] > 0 && dims_[1] > 0); fm_assert(size_ % Vector2ui{tile_count} == Vector2ui()); tex_.setWrapping(GL::SamplerWrapping::ClampToEdge) diff --git a/src/tile-image.hpp b/src/tile-image.hpp new file mode 100644 index 00000000..deb04e9a --- /dev/null +++ b/src/tile-image.hpp @@ -0,0 +1,24 @@ +#pragma once +#include "compat/integer-types.hpp" +#include +#include + +namespace floormat { + +struct tile_atlas; + +struct tile_image final +{ + std::shared_ptr atlas; + std::uint8_t variant = (std::uint8_t)-1; + + explicit operator bool() const noexcept { return !!atlas; } + + std::strong_ordering operator<=>(const tile_image& o) const noexcept + { + const auto ret = atlas.get() <=> o.atlas.get(); + return ret != std::strong_ordering::equal ? ret : variant <=> o.variant; + } +}; + +} // namespace floormat diff --git a/src/tile.hpp b/src/tile.hpp index e8bac834..5103479d 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -1,27 +1,9 @@ #pragma once #include "compat/defs.hpp" -#include "compat/integer-types.hpp" -#include "tile-defs.hpp" -#include +#include "tile-image.hpp" namespace floormat { -struct tile_atlas; - -struct tile_image final -{ - std::shared_ptr atlas; - std::size_t variant = (std::size_t)-1; - - explicit operator bool() const noexcept { return !!atlas; } - - std::strong_ordering operator<=>(const tile_image& o) const noexcept - { - const auto ret = atlas.get() <=> o.atlas.get(); - return ret != std::strong_ordering::equal ? ret : variant <=> o.variant; - } -}; - struct tile final { enum pass_mode : std::uint8_t { pass_blocked, pass_ok, pass_shoot_through, }; -- cgit v1.2.3