diff options
-rw-r--r-- | draw/wall.cpp | 10 | ||||
-rw-r--r-- | loader/wall-atlas.cpp | 4 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 3 | ||||
-rw-r--r-- | serialize/world-writer.cpp | 14 | ||||
-rw-r--r-- | shaders/lightmap.cpp | 5 | ||||
-rw-r--r-- | src/chunk-collision.cpp | 5 | ||||
-rw-r--r-- | src/chunk-walls.cpp | 19 | ||||
-rw-r--r-- | src/chunk.hpp | 4 | ||||
-rw-r--r-- | src/wall-atlas.cpp | 1 | ||||
-rw-r--r-- | src/wall-atlas.hpp | 2 |
10 files changed, 44 insertions, 23 deletions
diff --git a/draw/wall.cpp b/draw/wall.cpp index 0a0a0b5a..870cf9b9 100644 --- a/draw/wall.cpp +++ b/draw/wall.cpp @@ -1,9 +1,9 @@ #include "wall.hpp" -#include "src/tile-atlas.hpp" +#include "src/wall-atlas.hpp" #include "shaders/shader.hpp" #include "src/chunk.hpp" -#include "src/tile-image.hpp" -#include "src/anim-atlas.hpp" +//#include "src/tile-image.hpp" +//#include "src/anim-atlas.hpp" #include <Magnum/GL/Texture.h> #include <Magnum/GL/MeshView.h> @@ -16,12 +16,12 @@ wall_mesh::wall_mesh() = default; void wall_mesh::draw(tile_shader& shader, chunk& c) { const auto [mesh_, ids, size] = c.ensure_wall_mesh(); - struct { tile_atlas* atlas = nullptr; size_t pos = 0; } last; + struct { wall_atlas* atlas = nullptr; size_t pos = 0; } last; GL::MeshView mesh{mesh_}; [[maybe_unused]] size_t draw_count = 0; fm_debug_assert(size_t(mesh_.count()) == size*quad_index_count); - const auto do_draw = [&](size_t i, tile_atlas* atlas, uint32_t max_index) { + const auto do_draw = [&](size_t i, wall_atlas* atlas, uint32_t max_index) { if (atlas == last.atlas) return; if (auto len = i - last.pos; last.atlas && len > 0) diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp index 30afe3d9..745c5eb8 100644 --- a/loader/wall-atlas.cpp +++ b/loader/wall-atlas.cpp @@ -62,11 +62,11 @@ const wall_info& loader_impl::make_invalid_wall_atlas() wall_atlas_def { Wall::Info{.name = name, .depth = 8}, {{ {}, frame_size}, }, - {{ {.index = 0, .count = 1, .pixel_size = frame_size, } }}, + {{ {.index = 0, .count = 1, .pixel_size = frame_size, } } }, {{ {.val = 0}, {}, }}, {1u}, }, name, make_error_texture()); - invalid_wall_atlas = Pointer<wall_info>{InPlaceInit, wall_info{ .name = name, .atlas = a } }; + invalid_wall_atlas = Pointer<wall_info>{InPlaceInit, wall_info{ .name = name, .atlas = std::move(a) } }; return *invalid_wall_atlas; } diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index ec8b733a..d3954b09 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -223,10 +223,13 @@ void reader_state::read_chunks(reader_t& s) //t.passability() = pass_mode(flags & pass_mask); if (flags & meta_ground) t.ground() = make_atlas(); + // todo! +#if 0 if (flags & meta_wall_n) t.wall_north() = make_atlas(); if (flags & meta_wall_w) t.wall_west() = make_atlas(); +#endif if (PROTO >= 3 && PROTO < 8) [[unlikely]] if (flags & meta_scenery_) read_old_scenery(s, ch, i); diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index c41fa89d..90fcf3b4 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -458,14 +458,17 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords_ coord) for (auto i = 0uz; i < TILE_COUNT; i++) { const tile_proto x = c[i]; - const auto ground = x.ground(), wall_north = x.wall_north(), wall_west = x.wall_west(); + const auto ground = x.ground(); + const auto wall_north = x.wall_north(), wall_west = x.wall_west(); //const auto scenery = x.scenery_frame; fm_debug_assert(s.bytes_written() + tile_size <= chunkbuf_size); auto img_g = maybe_intern_atlas(ground); - auto img_n = maybe_intern_atlas(wall_north); - auto img_w = maybe_intern_atlas(wall_west); + //auto img_n = maybe_intern_atlas(wall_north); + //auto img_w = maybe_intern_atlas(wall_west); + // todo! + auto img_n = null_atlas, img_w = null_atlas; if (img_g == null_atlas && img_n == null_atlas && img_w == null_atlas) { @@ -495,8 +498,9 @@ void writer_state::serialize_chunk(const chunk& c, chunk_coords_ coord) fm_assert(!x.atlas || x.variant < x.atlas->num_tiles()); }; check_atlas(ground); - check_atlas(wall_north); - check_atlas(wall_west); + // todo! + //check_atlas(wall_north); + //check_atlas(wall_west); if (img_g != null_atlas) { diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp index c56fbaa6..d0e32453 100644 --- a/shaders/lightmap.cpp +++ b/shaders/lightmap.cpp @@ -4,6 +4,7 @@ #include "src/chunk.hpp" #include "src/tile-bbox.hpp" #include "src/tile-atlas.hpp" +#include "src/wall-atlas.hpp" #include "src/quads.hpp" #include "src/object.hpp" #include "loader/loader.hpp" @@ -373,7 +374,7 @@ void lightmap_shader::add_geometry(Vector2 neighbor_offset, chunk& c) add_rect(neighbor_offset, {min-fuzz, max+fuzz2}); } if (auto atlas = t.wall_north_atlas()) - if (atlas->pass_mode(pass_mode::blocked) == pass_mode::blocked) + if (atlas->info().passability == pass_mode::blocked) { auto start = tile_start(i); auto min = start - Vector2(0, shadow_wall_depth), @@ -382,7 +383,7 @@ void lightmap_shader::add_geometry(Vector2 neighbor_offset, chunk& c) add_rect(neighbor_offset, {min-fuzz, max+fuzz2}); } if (auto atlas = t.wall_west_atlas()) - if (atlas->pass_mode(pass_mode::blocked) == pass_mode::blocked) + if (atlas->info().passability == pass_mode::blocked) { auto start = tile_start(i); auto min = start - Vector2(shadow_wall_depth, 0), diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index 8b27fd83..611754bc 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -4,6 +4,7 @@ #include "src/RTree-search.hpp" #include "src/chunk-scenery.hpp" #include "src/tile-bbox.hpp" +#include "src/wall-atlas.hpp" #include <bit> #include <Corrade/Containers/StructuredBindings.h> #include <Corrade/Containers/Pair.h> @@ -53,13 +54,13 @@ void chunk::ensure_passability() noexcept if (const auto* atlas = tile.wall_north_atlas().get()) { auto [min, max] = wall_north(i); - auto id = make_id(collision_type::geometry, atlas->pass_mode(pass_mode::blocked), TILE_COUNT+i+1); + auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT+i+1); _rtree.Insert(min.data(), max.data(), id); } if (const auto* atlas = tile.wall_west_atlas().get()) { auto [min, max] = wall_west(i); - auto id = make_id(collision_type::geometry, atlas->pass_mode(pass_mode::blocked), TILE_COUNT*2+i+1); + auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT*2+i+1); _rtree.Insert(min.data(), max.data(), id); } } diff --git a/src/chunk-walls.cpp b/src/chunk-walls.cpp index 01cc39b6..6e9fd51b 100644 --- a/src/chunk-walls.cpp +++ b/src/chunk-walls.cpp @@ -190,9 +190,19 @@ GL::Mesh chunk::make_wall_mesh() { CORRADE_ASSUME(G < Group_::COUNT); - if (G == Group_::corner_L && D != Direction_::N || - G == Group_::corner_R && D != Direction_::W) [[unlikely]] - continue; + switch (G) + { + case Wall::Group_::corner_L: + if (D != Direction_::N || !_walls->atlases[k+1]) + continue; + break; + case Wall::Group_::corner_R: + if (D != Direction_::W || !_walls->atlases[k-1]) + continue; + break; + default: + break; + } const auto& group = dir.*member; if (!group.is_defined) @@ -225,7 +235,8 @@ GL::Mesh chunk::make_wall_mesh() auto index_view = make_indexes(N); GL::Mesh mesh{GL::MeshPrimitive::Triangles}; - mesh.addVertexBuffer(GL::Buffer{vertex_view}, 0, tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{}) + mesh.addVertexBuffer(GL::Buffer{vertex_view}, 0, + tile_shader::Position{}, tile_shader::TextureCoordinates{}, tile_shader::Depth{}) .setIndexBuffer(GL::Buffer{index_view}, 0, GL::MeshIndexType::UnsignedShort) .setCount(int32_t(6 * N)); fm_debug_assert((size_t)mesh.count() == N*6); diff --git a/src/chunk.hpp b/src/chunk.hpp index d9daf436..2331bef8 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -79,7 +79,7 @@ struct chunk final }; struct wall_mesh_tuple final { GL::Mesh& mesh; - const ArrayView<const uint16_t> ids; + const ArrayView<const uint_fast16_t> indexes; const size_t size; }; struct topo_sort_data; @@ -134,7 +134,7 @@ private: { std::array<std::shared_ptr<wall_atlas>, 2*TILE_COUNT> atlases; std::array<variant_t, 2*TILE_COUNT> variants; - std::array<uint16_t, max_wall_quad_count> mesh_indexes; + std::array<uint_fast16_t, max_wall_quad_count> mesh_indexes; }; Pointer<ground_stuff> _ground; diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp index 3b2ff9d7..8e6bd13c 100644 --- a/src/wall-atlas.cpp +++ b/src/wall-atlas.cpp @@ -65,6 +65,7 @@ wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img) for (auto [dir_name, dir] : wall_atlas::directions) { const auto* D = direction((size_t)dir); + fm_soft_assert(def.direction_mask[(size_t)dir] == !!D); if (!D) continue; for (auto [group_name, gmemb, gr] : Direction::groups) diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp index 6ace0f7c..b73704fe 100644 --- a/src/wall-atlas.hpp +++ b/src/wall-atlas.hpp @@ -120,7 +120,7 @@ class wall_atlas final Direction* get_Direction(Direction_ num) const; public: - fm_DECLARE_DELETED_MOVE_ASSIGNMENT(wall_atlas); + fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT_(wall_atlas); wall_atlas() noexcept; ~wall_atlas() noexcept; wall_atlas(wall_atlas_def def, String path, const ImageView2D& img); |