From 3dc6362599e85c9978ec4e9676ebcda3ab52beaf Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 1 Oct 2022 20:04:07 +0200 Subject: a --- chunk.cpp | 10 +++++++--- chunk.hpp | 3 +-- main.cpp | 1 - tile.hpp | 11 ++++------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/chunk.cpp b/chunk.cpp index 87cbe0cf..08009d0e 100644 --- a/chunk.cpp +++ b/chunk.cpp @@ -5,10 +5,12 @@ namespace Magnum::Examples { chunk_sampler_array::chunk_sampler_array() { samplers.reserve(MAX_SAMPLERS); + samplers.push_back(nullptr); } void chunk_sampler_array::ensure_sampler(std::size_t tile_id, const shared_sampler& x) { + CORRADE_INTERNAL_ASSERT(x != nullptr); CORRADE_INTERNAL_ASSERT(tile_id < TILE_COUNT); if (std::size_t id = sampler_map[tile_id]; id != 0) { @@ -26,20 +28,22 @@ void chunk_sampler_array::clear() { Magnum::GL::AbstractTexture::unbindImages(0, samplers.size()); samplers.clear(); + samplers.push_back(nullptr); sampler_map = {}; } void chunk_sampler_array::bind() { Magnum::GL::AbstractTexture::unbindImages(0, MAX_SAMPLERS); - for (std::size_t i = 0; i < samplers.size(); i++) - samplers[i]->texture().bind((int)i + 1); + for (std::size_t i = 1; i < samplers.size(); i++) + samplers[i]->texture().bind((int)i); } std::shared_ptr chunk_sampler_array::operator[](std::size_t tile_id) const { CORRADE_INTERNAL_ASSERT(tile_id < TILE_COUNT); - std::size_t sampler_id = sampler_map[tile_id] - 1; + std::size_t sampler_id = sampler_map[tile_id]; + CORRADE_INTERNAL_ASSERT(sampler_id != 0); CORRADE_INTERNAL_ASSERT(sampler_id < samplers.size()); const auto& sampler = samplers[sampler_id]; CORRADE_INTERNAL_ASSERT(sampler != nullptr); diff --git a/chunk.hpp b/chunk.hpp index 99ad1778..af2e5b13 100644 --- a/chunk.hpp +++ b/chunk.hpp @@ -27,9 +27,8 @@ struct chunk_coords final { struct chunk_sampler_array final { using shared_sampler = std::shared_ptr; - using sampler_tuple = std::pair; + static constexpr inline int MAX_SAMPLERS = 32; - static constexpr inline int MAX_SAMPLERS = 16; std::vector> samplers; std::array sampler_map = {}; diff --git a/main.cpp b/main.cpp index 89afe091..efddc1a4 100644 --- a/main.cpp +++ b/main.cpp @@ -76,7 +76,6 @@ struct app final : Platform::Application chunk c; float get_dt(); - static constexpr Vector3 TILE_SIZE = { 50, 50, 50 }; }; using namespace Math::Literals; diff --git a/tile.hpp b/tile.hpp index 2c23aa9a..7e65b881 100644 --- a/tile.hpp +++ b/tile.hpp @@ -13,7 +13,7 @@ namespace Magnum::Examples { -static constexpr Vector3 TILE_SIZE = { 50, 50, 50 }; +constexpr inline Vector3 TILE_SIZE = { 50, 50, 50 }; struct tile_image final { @@ -25,14 +25,11 @@ struct tile_image final struct tile final { - enum class pass_mode : std::uint8_t { pass_blocked, pass_yes, pass_shoot_through, pass_obscured }; + enum class pass_mode : std::uint8_t { pass_blocked, pass_ok, pass_shoot_through, }; using enum pass_mode; - tile_image ground_image_, wall_west_, wall_north_; - pass_mode passability_ = pass_shoot_through; - - //explicit operator bool() const noexcept { return !!ground_image_.atlas; } + tile_image ground_image, wall_west, wall_north; + pass_mode passability = pass_shoot_through; }; - } //namespace Magnum::Examples -- cgit v1.2.3