diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-07 23:38:31 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-08 08:43:49 +0100 |
commit | a6514d1a95d0f84f0935866215463ef6aed23e19 (patch) | |
tree | 639075646b1ea42a3cd4a76ae59af7dda0c4b14a /src | |
parent | 4575194adb4615deeca174044a872093c3664ad4 (diff) |
loader: work toward removing duplicate atlas code
Diffstat (limited to 'src')
-rw-r--r-- | src/ground-atlas.cpp | 27 | ||||
-rw-r--r-- | src/ground-atlas.hpp | 33 | ||||
-rw-r--r-- | src/ground-def.hpp | 15 | ||||
-rw-r--r-- | src/world.cpp | 2 |
4 files changed, 46 insertions, 31 deletions
diff --git a/src/ground-atlas.cpp b/src/ground-atlas.cpp index f918f940..ea513d44 100644 --- a/src/ground-atlas.cpp +++ b/src/ground-atlas.cpp @@ -3,6 +3,7 @@ #include "compat/assert.hpp" #include "tile-image.hpp" #include "compat/exception.hpp" +#include "loader/loader.hpp" #include <limits> #include <Magnum/Math/Color.h> #include <Magnum/ImageView.h> @@ -12,15 +13,16 @@ namespace floormat { using namespace floormat::Quads; -ground_atlas::ground_atlas(ground_def info, String path, const ImageView2D& image) : - texcoords_{make_texcoords_array(Vector2ui(image.size()), info.size)}, - path_{std::move(path)}, name_{std::move(info.name)}, size_{image.size()}, dims_{info.size}, passability{info.pass} +ground_atlas::ground_atlas(ground_def info, const ImageView2D& image) : + _def{std::move(info)}, _path{make_path(_def.name)}, + _texcoords{make_texcoords_array(Vector2ui(image.size()), _def.size)}, + _pixel_size{image.size()} { constexpr auto variant_max = std::numeric_limits<variant_t>::max(); fm_soft_assert(num_tiles() <= variant_max); - fm_soft_assert(dims_[0] > 0 && dims_[1] > 0); - fm_soft_assert(size_ % Vector2ui{info.size} == Vector2ui()); - tex_.setLabel(path_) + fm_soft_assert(_def.size.x() > 0 && _def.size.y() > 0); + fm_soft_assert(_pixel_size % Vector2ui{_def.size} == Vector2ui()); + _tex.setLabel(_path) .setWrapping(GL::SamplerWrapping::ClampToEdge) .setMagnificationFilter(GL::SamplerFilter::Nearest) .setMinificationFilter(GL::SamplerFilter::Linear) @@ -33,7 +35,7 @@ ground_atlas::ground_atlas(ground_def info, String path, const ImageView2D& imag std::array<Vector2, 4> ground_atlas::texcoords_for_id(size_t i) const { fm_assert(i < num_tiles()); - return texcoords_[i]; + return _texcoords[i]; } auto ground_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i) -> texcoords @@ -53,7 +55,14 @@ auto ground_atlas::make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_cou return ptr; } -size_t ground_atlas::num_tiles() const { return Vector2ui{dims_}.product(); } -enum pass_mode ground_atlas::pass_mode() const { return passability; } +size_t ground_atlas::num_tiles() const { return Vector2ui{_def.size}.product(); } +enum pass_mode ground_atlas::pass_mode() const { return _def.pass; } + +String ground_atlas::make_path(StringView name) +{ + char buf[fm_FILENAME_MAX]; + auto sv = loader.make_atlas_path(buf, loader.GROUND_TILESET_PATH, name); + return String{sv}; +} } // namespace floormat diff --git a/src/ground-atlas.hpp b/src/ground-atlas.hpp index 38832f9b..e13c0012 100644 --- a/src/ground-atlas.hpp +++ b/src/ground-atlas.hpp @@ -1,7 +1,7 @@ #pragma once #include "src/pass-mode.hpp" #include "src/quads.hpp" -#include "loader/ground-info.hpp" +#include "loader/ground-cell.hpp" #include <array> #include <memory> #include <Corrade/Containers/Optional.h> @@ -12,13 +12,6 @@ namespace floormat { -struct ground_def -{ - String name; - Vector2ub size; - pass_mode pass = pass_mode::pass; -}; - class ground_atlas; class ground_atlas final @@ -28,25 +21,23 @@ class ground_atlas final static std::unique_ptr<const texcoords[]> make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count); static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i); + static String make_path(StringView name); - std::unique_ptr<const texcoords[]> texcoords_; - GL::Texture2D tex_; - String path_, name_; - Vector2ui size_; - Vector2ub dims_; - enum pass_mode passability; + ground_def _def; + String _path; + std::unique_ptr<const texcoords[]> _texcoords; + GL::Texture2D _tex; + Vector2ui _pixel_size; public: - ground_atlas(ground_def info, String path, const ImageView2D& img); + ground_atlas(ground_def info, const ImageView2D& img); texcoords texcoords_for_id(size_t id) const; - [[maybe_unused]] Vector2ui pixel_size() const { return size_; } + [[maybe_unused]] Vector2ui pixel_size() const { return _pixel_size; } size_t num_tiles() const; - Vector2ub num_tiles2() const { return dims_; } - GL::Texture2D& texture() { return tex_; } - StringView name() const { return name_; } + Vector2ub num_tiles2() const { return _def.size; } + GL::Texture2D& texture() { return _tex; } + StringView name() const { return _def.name; } enum pass_mode pass_mode() const; - - static constexpr enum pass_mode default_pass_mode = pass_mode::pass; }; } // namespace floormat diff --git a/src/ground-def.hpp b/src/ground-def.hpp new file mode 100644 index 00000000..9b3825ff --- /dev/null +++ b/src/ground-def.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "pass-mode.hpp" +#include <Corrade/Containers/String.h> +#include <Magnum/Math/Vector2.h> + +namespace floormat { + +struct ground_def +{ + String name; + Vector2ub size; + pass_mode pass = pass_mode::pass; +}; + +} // namespace floormat diff --git a/src/world.cpp b/src/world.cpp index 59ea8d3d..759b9060 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -44,7 +44,7 @@ world& world::operator=(world&& w) noexcept _last_chunk = {}; _chunks = std::move(w._chunks); _objects = std::move(w._objects); - w._objects = safe_ptr<robin_map_wrapper>{}; + w._objects = {}; _unique_id = std::move(w._unique_id); fm_debug_assert(_unique_id); fm_debug_assert(w._unique_id == nullptr); |