diff options
-rw-r--r-- | test/loader.cpp | 36 | ||||
-rw-r--r-- | test/raycast.cpp | 89 |
2 files changed, 117 insertions, 8 deletions
diff --git a/test/loader.cpp b/test/loader.cpp index e6d9f07d..2716d238 100644 --- a/test/loader.cpp +++ b/test/loader.cpp @@ -6,8 +6,44 @@ namespace floormat { +namespace { + +// copied from bench/loader.cpp + +constexpr struct { + const char* name; + Vector2ub size; + pass_mode pass = pass_mode::pass; +} ground_atlases[] = { + { "floor-tiles", {44,4} }, + { "tiles", {8, 5} }, + { "texel", {2, 2}, pass_mode::blocked }, + { "metal1", {2,2} }, +}; + +constexpr const char* wall_atlases[] = { + "concrete1", "empty", "test1", +}; + +constexpr const char* anim_atlases[] = { + "anim/npc-walk", + "anim/test-8x8", + "scenery/door-close", + "scenery/control-panel", + "scenery/table", +}; + +} // namespace + void test_app::test_loader() { + for (const auto& str : anim_atlases) + (void)loader.get_anim_atlas(str); + for (const auto& x : ground_atlases) + (void)loader.get_ground_atlas(x.name, x.size, x.pass); + for (const auto& name : wall_atlases) + (void)loader.get_wall_atlas(name); + for (const auto& x : loader.ground_atlas_list()) (void)loader.ground_atlas(x.name); fm_assert(loader.ground_atlas("texel")->pass_mode() == pass_mode::blocked); diff --git a/test/raycast.cpp b/test/raycast.cpp index ce06dda3..3c8a4ce5 100644 --- a/test/raycast.cpp +++ b/test/raycast.cpp @@ -1,26 +1,99 @@ #include "app.hpp" -#include "src/raycast.hpp" +#include "src/raycast-diag.hpp" #include "src/world.hpp" +#include "loader/loader.hpp" +#include <Magnum/Math/Functions.h> namespace floormat { namespace { -#pragma message("TODO!") +world make_world() +{ + constexpr auto var = (variant_t)-1; + auto wall1_ = loader.wall_atlas("test1"_s); + auto wall2_ = loader.wall_atlas("concrete1"_s); + auto wall1 = wall_image_proto{wall1_, var}; + auto wall2 = wall_image_proto{wall2_, var}; + + auto w = world{}; + w[global_coords{{0, 3, 0}, {15, 0}}].t.wall_north() = wall1; + w[global_coords{{1, 3, 0}, { 0, 0}}].t.wall_north() = wall1; + w[global_coords{{1, 3, 0}, { 0, 0}}].t.wall_north() = wall1; + w[global_coords{{1, 2, 0}, { 1, 15}}].t.wall_west() = wall1; + w[global_coords{{1, 2, 0}, { 1, 14}}].t.wall_west() = wall1; + + w[global_coords{{0, 1, 0}, { 8, 11}}].t.wall_west() = wall2; + w[global_coords{{0, 1, 0}, { 8, 10}}].t.wall_west() = wall2; + w[global_coords{{0, 1, 0}, { 7, 10}}].t.wall_north() = wall2; + w[global_coords{{0, 1, 0}, { 6, 10}}].t.wall_north() = wall2; + + w[global_coords{{0, 1, 0}, { 9, 8}}].t.wall_north() = wall1; + w[global_coords{{0, 1, 0}, {10, 8}}].t.wall_north() = wall1; + w[global_coords{{0, 1, 0}, {11, 8}}].t.wall_west() = wall1; + + w[global_coords{{0, 2, 0}, { 9, 0}}].t.wall_north() = wall1; + w[global_coords{{0, 2, 0}, {10, 0}}].t.wall_north() = wall1; -void test1() + for (int16_t k = -5; k <= -1; k++) + { + auto& ch = w[chunk_coords_{-5, -5, 0}]; + for (unsigned i = 0; i < TILE_MAX_DIM; i++) + { + ch[{(uint8_t)i, 0}].wall_west() = wall1; + ch[{(uint8_t)i, 1}].wall_north() = wall1; + ch[{(uint8_t)i, 2}].wall_north() = wall2; + ch[{(uint8_t)i, 2}].wall_west() = wall2; + } + } + + for (int16_t i = -15; i <= 15; i++) + for (int16_t j = -15; j <= 15; j++) + w[{{i, j}, 0}].mark_modified(); + + return w; +} + +auto run(point from, point to, world& w, bool b, float len) { - // try reproducing the evil bug in src/raycast.cpp:285: - // c = w.at({last_ch + Vector2i{i - 1, j - 1}}); - // was incorrectly: - // c = w.at({last_ch - Vector2i{i - 1, j - 1}}); + constexpr float fuzz = iTILE_SIZE2.x(); + auto diag = rc::raycast_diag_s{}; + auto res = raycast_with_diag(diag, w, from, to, 0); + if (res.success != b) + { + fm_error("success != %s", b ? "true" : "false"); + return false; + } + if (len != 0.f) + { + auto tmin = res.success ? diag.V.length() : diag.tmin; + auto diff = Math::abs(tmin - len); + if (diff > fuzz) + { + fm_error("|tmin=%f - len=%f| > %f", + (double)tmin, (double)len, (double)fuzz); + return false; + } + } + return true; } } // namespace void test_app::test_raycast() { - + auto w = make_world(); + { constexpr auto from = point{{0, 0, 0}, {11,12}, {1,-32}}; + fm_assert(run(from, point{{ 1, 3, 0}, { 0, 1}, {-21, 23}}, w, false, 2288)); + fm_assert(run(from, point{{ 1, 3, 0}, { 8, 10}, {- 9, -13}}, w, true, 3075)); + fm_assert(run(from, point{{ 0, 3, 0}, {14, 4}, { 3, 15}}, w, true, 2614)); + fm_assert(run(from, point{{ 0, 1, 0}, { 8, 12}, {-27, -19}}, w, false, 752)); + fm_assert(run(from, point{{ 2, 33, 0}, {15, 11}, {- 4, 29}}, w, true, 33809)); + fm_assert(run(from, point{{ 0, 1, 0}, { 6, 13}, {- 3, -11}}, w, false, 913)); + } + { fm_assert(run( point{{ 0, 0, 0}, { 1, 0}, {-17, 17}}, + point{{ 0, - 7, 0}, { 1, 15}, {-11, 5}}, w, true, 6220)); + } } } // namespace floormat |