diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-12 05:52:55 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-09-12 05:52:55 +0200 |
commit | aae112ae02b415483ac03c59629dc9290bd833cf (patch) | |
tree | a4763c87cdb7fd00109255a618177c30d1f0fa73 | |
parent | 7c56df7eed83af63e018be1be5507c1ca8cf1b99 (diff) |
a
-rw-r--r-- | shaders/lightmap.cpp | 16 | ||||
-rw-r--r-- | src/camera-offset.cpp | 2 | ||||
-rw-r--r-- | src/path-search.cpp | 7 | ||||
-rw-r--r-- | test/path-search.cpp | 12 |
4 files changed, 13 insertions, 24 deletions
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp index 47a7a5e0..52471b6b 100644 --- a/shaders/lightmap.cpp +++ b/shaders/lightmap.cpp @@ -1,11 +1,12 @@ #include "shaders/lightmap.hpp" #include "compat/assert.hpp" +#include "compat/math.hpp" #include "src/tile-defs.hpp" -#include "loader/loader.hpp" #include "src/chunk.hpp" #include "src/tile-bbox.hpp" #include "src/tile-atlas.hpp" #include "src/object.hpp" +#include "loader/loader.hpp" #include <utility> #include <Corrade/Containers/PairStl.h> #include <Corrade/Containers/Iterable.h> @@ -25,23 +26,12 @@ namespace floormat { namespace { -template<typename T> -constexpr T poor_mans_ceil(T x) -{ - static_assert(std::is_floating_point_v<T>); - const auto x0 = (int64_t)x; - if (x > x0) - return T(x0 + (int64_t)1); - else - return T(x0); -} - constexpr auto neighbor_count = 4; constexpr float fuzz_pixels = 16; constexpr float shadow_wall_depth = 8; constexpr float real_image_size = 1024; -constexpr auto half_neighbors = (int)poor_mans_ceil(neighbor_count/2.f); +constexpr auto half_neighbors = (int)math::ceil(neighbor_count/2.f); constexpr auto image_size = TILE_SIZE2 * TILE_MAX_DIM * neighbor_count; constexpr auto chunk_size = TILE_SIZE2 * TILE_MAX_DIM; diff --git a/src/camera-offset.cpp b/src/camera-offset.cpp index a5213397..25b0a3bb 100644 --- a/src/camera-offset.cpp +++ b/src/camera-offset.cpp @@ -16,7 +16,7 @@ with_shifted_camera_offset::with_shifted_camera_offset(tile_shader& shader, chun auto pos = chunk_coords(c_) - first_; constexpr auto depth_start = -1 + 1.111e-16f; - int depth = TILE_MAX_DIM*2 * pos.sum(); + int depth = (int)TILE_MAX_DIM*2 * pos.sum(); #if 0 printf("c=(%2hd %2hd %2hhd) pos=(%2d %2d) len=(%d %d) --> %d\n", c_.x, c_.y, c_.z, pos.x(), pos.y(), len.x(), len.y(), depth); diff --git a/src/path-search.cpp b/src/path-search.cpp index 1f9b5bf9..8a4c52f0 100644 --- a/src/path-search.cpp +++ b/src/path-search.cpp @@ -94,11 +94,10 @@ bool search::sample_rtree(world& w, global_coords coord, Vector2b offset, Vector auto search::make_neighbor_tile_bbox(Vector2i coord, Vector2ub own_size, rotation r) -> bbox { - constexpr auto full_tile = Vector2ui(iTILE_SIZE2*3/4); - constexpr auto tx = full_tile.x()*2u, ty = full_tile.y()*2u; + constexpr auto tx = iTILE_SIZE2.x()/2, ty = iTILE_SIZE2.y()/2; - const auto s = Math::max(Vector2ui(own_size), full_tile); - const auto sx = s[0], sy = s[1]; + const auto s = Math::max(Vector2ui(own_size), Vector2ui(iTILE_SIZE2)); + const auto sx = s.x(), sy = s.y(); Vector2i off; Vector2ui size; diff --git a/test/path-search.cpp b/test/path-search.cpp index 8e91d763..3a78489f 100644 --- a/test/path-search.cpp +++ b/test/path-search.cpp @@ -30,19 +30,19 @@ void test_bbox() { using enum rotation; auto w = world(); - auto& c12 = w[chunk_coords_{1, 2, 0}]; + [[maybe_unused]] auto& c12 = w[chunk_coords_{1, 2, 0}]; [[maybe_unused]] auto& c11 = w[chunk_coords_{1, 1, 0}]; c12[{0, 0}].wall_north() = {metal2, 0}; - fm_assert( !sample(c12, bbox({0, 0}, N)) ); - fm_assert( sample(c12, bbox({0, 0}, E)) ); - fm_assert( sample(c12, bbox({0, 0}, S)) ); - fm_assert( sample(c12, bbox({0, 0}, W)) ); - fm_assert( sample2(w, chunk_coords_{1, 1, 0}, bbox({0, TILE_MAX_DIM-1}, W)) ); fm_assert( sample2(w, chunk_coords_{1, 1, 0}, bbox({0, TILE_MAX_DIM-1}, E)) ); fm_assert( sample2(w, chunk_coords_{1, 1, 0}, bbox({0, TILE_MAX_DIM-1}, N)) ); fm_assert( !sample2(w, chunk_coords_{1, 1, 0}, bbox({0, TILE_MAX_DIM-1}, S)) ); + + fm_assert( !sample(c12, bbox({0, 0}, N)) ); + fm_assert( sample(c12, bbox({0, 0}, E)) ); + fm_assert( sample(c12, bbox({0, 0}, S)) ); + fm_assert( sample(c12, bbox({0, 0}, W)) ); } // todo use test chunk } |