summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-09-07 09:05:18 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-09-07 09:05:18 +0200
commit100f35c5129b28c12aa776b5664a9e29f1f551bf (patch)
treefff276ba524144835edb48f4e58da5094b3cf15c
parent259219f76c49e6dee0ea7fa0ca09731354fc847f (diff)
chunk: add hack to prevent character feet clipping
-rw-r--r--src/chunk-render.cpp4
-rw-r--r--src/chunk.cpp2
-rw-r--r--src/chunk.hpp6
-rw-r--r--src/world.cpp2
-rw-r--r--test/json.cpp2
-rw-r--r--test/tile-iter.cpp4
6 files changed, 11 insertions, 9 deletions
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index 281d7207..c163fd4d 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -48,6 +48,8 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
return _ground->_ground_atlases[a] < _ground->_ground_atlases[b];
});
+ float hack_offset = _coord.z == 0 ? -1 : 0;
+
std::array<std::array<vertex, 4>, TILE_COUNT> vertexes;
for (auto k = 0uz; k < count; k++)
{
@@ -56,7 +58,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
const local_coords pos{i};
const auto quad = atlas->floor_quad(Vector3(pos) * TILE_SIZE, TILE_SIZE2);
const auto texcoords = atlas->texcoords_for_id(_ground->_ground_variants[i]);
- const float depth = tile_shader::depth_value(pos, tile_shader::ground_depth_offset);
+ const float depth = tile_shader::depth_value(pos, tile_shader::ground_depth_offset + hack_offset);
auto& v = vertexes[k];
for (auto j = 0uz; j < 4; j++)
v[j] = { quad[j], texcoords[j], depth };
diff --git a/src/chunk.cpp b/src/chunk.cpp
index f8b823a8..52321aa1 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -91,7 +91,7 @@ void chunk::mark_modified() noexcept
mark_passability_modified();
}
-chunk::chunk(struct world& w) noexcept : _world{&w}
+chunk::chunk(struct world& w, chunk_coords_ ch) noexcept : _world{&w}, _coord{ch}
{
}
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 6a7e3fc9..2f537f84 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -3,6 +3,7 @@
#include "tile.hpp"
#include "local-coords.hpp"
#include "src/RTree.h"
+#include "global-coords.hpp"
#include <type_traits>
#include <array>
#include <Corrade/Containers/Pointer.h>
@@ -55,7 +56,7 @@ struct chunk final
bool empty(bool force = false) const noexcept;
- explicit chunk(struct world& w) noexcept;
+ explicit chunk(struct world& w, chunk_coords_ ch) noexcept;
~chunk() noexcept;
chunk(const chunk&) = delete;
chunk& operator=(const chunk&) = delete;
@@ -132,11 +133,10 @@ private:
Pointer<ground_stuff> _ground;
Pointer<wall_stuff> _walls;
std::vector<std::shared_ptr<object>> _objects;
-
struct world* _world;
GL::Mesh ground_mesh{NoCreate}, wall_mesh{NoCreate}, scenery_mesh{NoCreate};
-
RTree _rtree;
+ chunk_coords_ _coord;
mutable bool _maybe_empty : 1 = true,
_ground_modified : 1 = true,
diff --git a/src/world.cpp b/src/world.cpp
index 97cc4702..46a65f64 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -91,7 +91,7 @@ chunk& world::operator[](chunk_coords_ coord) noexcept
fm_debug_assert(coord.z >= chunk_z_min && coord.z <= chunk_z_max);
auto& [c, coord2] = _last_chunk;
if (coord != coord2)
- c = &_chunks.try_emplace(coord, *this).first->second;
+ c = &_chunks.try_emplace(coord, *this, coord).first->second;
coord2 = coord;
return *c;
}
diff --git a/test/json.cpp b/test/json.cpp
index d9498e49..9c638530 100644
--- a/test/json.cpp
+++ b/test/json.cpp
@@ -23,7 +23,7 @@ static chunk make_test_chunk()
tiles = loader.tile_atlas("tiles", {8, 5}, pass_mode::pass);
constexpr auto N = TILE_MAX_DIM;
world w;
- chunk c{w};
+ chunk c{w, {}};
for (auto [x, k, pt] : c) {
x.ground() = { tiles, variant_t(k % tiles->num_tiles()) };
}
diff --git a/test/tile-iter.cpp b/test/tile-iter.cpp
index 85ad8797..5248f7ce 100644
--- a/test/tile-iter.cpp
+++ b/test/tile-iter.cpp
@@ -15,7 +15,7 @@ void test_app::test_tile_iter() // NOLINT(readability-function-size)
if (always_false())
{
world w;
- const chunk c{w};
+ const chunk c{w, {}};
for ([[maybe_unused]] const auto& [x, k, pt] : c)
static_assert(std::is_same_v<decltype(x), const tile_proto>);
for ([[maybe_unused]] const auto [x, k, pt] : c)
@@ -26,7 +26,7 @@ void test_app::test_tile_iter() // NOLINT(readability-function-size)
if (always_false())
{
world w;
- chunk c{w};
+ chunk c{w, {}};
for ([[maybe_unused]] auto [x, k, pt] : c)
static_assert(std::is_same_v<decltype(x), tile_ref>);
for ([[maybe_unused]] const auto [x, k, pt] : c)