diff options
-rw-r--r-- | bench/dijkstra.cpp | 2 | ||||
-rw-r--r-- | editor/editor.hpp | 2 | ||||
-rw-r--r-- | editor/tile-editor.cpp | 95 | ||||
-rw-r--r-- | editor/wall-editor.cpp | 1 | ||||
-rw-r--r-- | images/wall.json | 30 | ||||
-rw-r--r-- | loader/atlas.cpp | 5 | ||||
-rw-r--r-- | loader/impl.hpp | 4 | ||||
-rw-r--r-- | loader/loader.hpp | 4 | ||||
-rw-r--r-- | loader/wall-atlas.cpp | 7 | ||||
-rw-r--r-- | serialize/tile-atlas.cpp | 17 | ||||
-rw-r--r-- | shaders/lightmap.cpp | 2 | ||||
-rw-r--r-- | src/chunk-collision.cpp | 2 | ||||
-rw-r--r-- | src/tile-atlas.hpp | 2 | ||||
-rw-r--r-- | src/wall-atlas.cpp | 2 | ||||
-rw-r--r-- | src/wall-atlas.hpp | 2 | ||||
-rw-r--r-- | test/dijkstra.cpp | 2 | ||||
-rw-r--r-- | test/loader.cpp | 3 | ||||
-rw-r--r-- | test/main.cpp | 3 | ||||
-rw-r--r-- | test/path-search.cpp | 2 | ||||
-rw-r--r-- | test/serializer.cpp | 4 | ||||
-rw-r--r-- | test/wall-atlas2.cpp | 14 | ||||
-rw-r--r-- | walls/concrete1.json (renamed from walls/concrete-wall1.json) | 2 | ||||
-rw-r--r-- | walls/concrete1.png (renamed from walls/concrete-wall1.png) | bin | 71441 -> 71441 bytes |
23 files changed, 53 insertions, 154 deletions
diff --git a/bench/dijkstra.cpp b/bench/dijkstra.cpp index 66300721..37e562fe 100644 --- a/bench/dijkstra.cpp +++ b/bench/dijkstra.cpp @@ -24,7 +24,7 @@ void Dijkstra(benchmark::State& state) constexpr auto wpos = global_coords{wch, wt}; auto& ch = w[wch]; - auto metal2 = tile_image_proto{loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked), 0}; + auto metal2 = wall_image_proto{loader.wall_atlas("concrete1", false), 0}; for (int16_t j = wcy - 1; j <= wcy + 1; j++) for (int16_t i = wcx - 1; i <= wcx + 1; i++) diff --git a/editor/editor.hpp b/editor/editor.hpp index e84e022f..26f96ec2 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -57,7 +57,7 @@ private: app* _app; - tile_editor _floor{ editor_mode::floor, "floor"_s }; + tile_editor _floor; wall_editor _wall; scenery_editor _scenery; vobj_editor _vobj; diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp index 6bca50f3..e6d98079 100644 --- a/editor/tile-editor.cpp +++ b/editor/tile-editor.cpp @@ -17,16 +17,8 @@ tile_editor::tile_editor() void tile_editor::load_atlases() { - pass_mode default_pass_mode; - switch (_mode) - { - case editor_mode::floor: default_pass_mode = pass_mode::pass; break; - case editor_mode::walls: default_pass_mode = pass_mode::blocked; break; - default: default_pass_mode = pass_mode::see_through; break; - } - const auto filename = _name + ".json"; - for (const auto& atlas : loader.tile_atlases(filename, default_pass_mode)) + for (const auto& atlas : loader.tile_atlases(filename)) { auto& [_, vec] = _permutation; vec.reserve(atlas->num_tiles()); @@ -154,92 +146,23 @@ tile_image_proto tile_editor::get_selected() void tile_editor::place_tile(world& world, global_coords pos, const tile_image_proto& img) { auto [c, t] = world[pos]; - switch (_mode) - { - case editor_mode::none: - break; - case editor_mode::floor: - c.mark_ground_modified(); - t.ground() = img; - break; - case editor_mode::walls: - c.mark_walls_modified(); - switch (_rotation) - { - case editor_wall_rotation::N: - t.wall_north() = img; - break; - case editor_wall_rotation::W: - t.wall_west() = img; - break; - } - break; - default: - fm_warn_once("wrong editor mode '%d' for place_tile()", (int)_mode); - break; - } -} - -void tile_editor::toggle_rotation() -{ - if (_mode != editor_mode::walls) - _rotation = editor_wall_rotation::N; - else if (_rotation == editor_wall_rotation::W) - _rotation = editor_wall_rotation::N; - else - _rotation = editor_wall_rotation::W; -} - -void tile_editor::set_rotation(editor_wall_rotation r) -{ - switch (r) - { - default: - fm_warn_once("invalid rotation '0x%hhx", (char)r); - return; - case editor_wall_rotation::W: - case editor_wall_rotation::N: - if (_mode == editor_mode::walls) - _rotation = r; - else - _rotation = editor_wall_rotation::N; - break; - } + c.mark_ground_modified(); + t.ground() = img; } auto tile_editor::check_snap(int mods) const -> editor_snap_mode { const bool ctrl = mods & kmod_ctrl, shift = mods & kmod_shift; + // todo show on cursor while held if (!(ctrl | shift)) return editor_snap_mode::none; - switch (_mode) - { - default: - case editor_mode::none: - return editor_snap_mode::none; - case editor_mode::walls: - switch (_rotation) - { - case editor_wall_rotation::N: - return editor_snap_mode::horizontal; - case editor_wall_rotation::W: - return editor_snap_mode::vertical; - default: return editor_snap_mode::none; - } - case editor_mode::floor: - if (shift) - return editor_snap_mode::horizontal; - if (ctrl) - return editor_snap_mode::vertical; - return editor_snap_mode::none; - } -} - -bool tile_editor::can_rotate() const -{ - return _mode == editor_mode::walls; + if (shift) + return editor_snap_mode::horizontal; + if (ctrl) + return editor_snap_mode::vertical; + return editor_snap_mode::none; } } // namespace floormat diff --git a/editor/wall-editor.cpp b/editor/wall-editor.cpp index a216c8a6..e1fc96cb 100644 --- a/editor/wall-editor.cpp +++ b/editor/wall-editor.cpp @@ -3,5 +3,4 @@ namespace floormat { - } // namespace floormat diff --git a/images/wall.json b/images/wall.json deleted file mode 100644 index a212b90e..00000000 --- a/images/wall.json +++ /dev/null @@ -1,30 +0,0 @@ -[ - { - "name": "wood2", - "size": "2 x 2" - }, - { - "name": "wood1", - "size": "2 x 2" - }, - { - "name": "teak1", - "size": "2 x 2" - }, - { - "name": "metal2", - "size": "2 x 2" - }, - { - "name": "concrete7", - "size": "4 x 4" - }, - { - "name": "concrete1", - "size": "3 x 1" - }, - { - "name": "wall1", - "size": "4 x 1" - } -] diff --git a/loader/atlas.cpp b/loader/atlas.cpp index de1d8e15..c32ae345 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -42,12 +42,11 @@ bool loader_::check_atlas_name(StringView str) noexcept namespace floormat::loader_detail { -std::shared_ptr<tile_atlas> loader_impl::tile_atlas(StringView name, Vector2ub size, Optional<pass_mode> pass) noexcept(false) +std::shared_ptr<tile_atlas> loader_impl::tile_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) { if (auto it = tile_atlas_map.find(name); it != tile_atlas_map.end()) { - if (pass) - fm_assert(it->second->pass_mode() == pass); + fm_assert(it->second->pass_mode() == pass); return it->second; } diff --git a/loader/impl.hpp b/loader/impl.hpp index c5fe83b2..84022f8d 100644 --- a/loader/impl.hpp +++ b/loader/impl.hpp @@ -51,7 +51,7 @@ struct loader_impl final : loader_ Pointer<wall_info> invalid_wall_atlas; - const wall_info& wall_atlas(StringView name, bool fail_ok = true) override; + std::shared_ptr<class wall_atlas> wall_atlas(StringView name, bool fail_ok = true) override; ArrayView<const wall_info> wall_atlas_list() override; void get_wall_atlas_list(); const wall_info& make_invalid_wall_atlas(); @@ -60,7 +60,7 @@ struct loader_impl final : loader_ // >-----> tile >-----> tsl::robin_map<StringView, std::shared_ptr<class tile_atlas>> tile_atlas_map; - std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, Optional<pass_mode> pass) noexcept(false) override; + std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) override; std::shared_ptr<class tile_atlas> tile_atlas(StringView filename) noexcept(false) override; // >-----> anim >-----> diff --git a/loader/loader.hpp b/loader/loader.hpp index e7824aa5..02c5dc67 100644 --- a/loader/loader.hpp +++ b/loader/loader.hpp @@ -29,11 +29,11 @@ struct loader_ virtual StringView shader(StringView filename) noexcept = 0; virtual Trade::ImageData2D texture(StringView prefix, StringView filename, bool fail_ok = true) noexcept(false) = 0; // todo remove Optional when wall_atlas is fully implemented -sh 20231122 - virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, Optional<pass_mode> pass) noexcept(false) = 0; + virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) = 0; virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename) noexcept(false) = 0; virtual ArrayView<const String> anim_atlas_list() = 0; virtual std::shared_ptr<class anim_atlas> anim_atlas(StringView name, StringView dir = ANIM_PATH) noexcept(false) = 0; - virtual const wall_info& wall_atlas(StringView name, bool fail_ok = true) = 0; + virtual std::shared_ptr<class wall_atlas> wall_atlas(StringView name, bool fail_ok = true) = 0; virtual ArrayView<const wall_info> wall_atlas_list() = 0; static void destroy(); static loader_& default_loader() noexcept; diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp index 9d5c8c2b..026bd6d5 100644 --- a/loader/wall-atlas.cpp +++ b/loader/wall-atlas.cpp @@ -46,6 +46,7 @@ std::shared_ptr<wall_atlas> loader_impl::get_wall_atlas(StringView name, StringV auto tex = texture(""_s, path); fm_soft_assert(name == def.header.name); + fm_soft_assert(!def.frames.empty()); auto atlas = std::make_shared<class wall_atlas>(std::move(def), path, tex); return atlas; } @@ -70,7 +71,7 @@ const wall_info& loader_impl::make_invalid_wall_atlas() return *invalid_wall_atlas; } -const wall_info& loader_impl::wall_atlas(StringView name, bool fail_ok) +std::shared_ptr<class wall_atlas> loader_impl::wall_atlas(StringView name, bool fail_ok) { fm_soft_assert(check_atlas_name(name)); char buf[FILENAME_MAX]; @@ -82,12 +83,12 @@ const wall_info& loader_impl::wall_atlas(StringView name, bool fail_ok) if (!fail_ok) fm_throw("no such wall atlas '{}'"_cf, name); else - return make_invalid_wall_atlas(); + return make_invalid_wall_atlas().atlas; } fm_assert(it->second != nullptr); if (!it->second->atlas) it->second->atlas = get_wall_atlas(it->second->name, path); - return *it->second; + return it->second->atlas; } void loader_impl::get_wall_atlas_list() diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index 8ade10d8..88385339 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -16,7 +16,7 @@ namespace { struct proxy { StringView name; Vector2ub size; - Optional<pass_mode> passability; + pass_mode passability; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy, name, size) @@ -31,11 +31,7 @@ void adl_serializer<std::shared_ptr<tile_atlas>>::to_json(json& j, const std::sh if (!x) j = nullptr; else - { - to_json(j, proxy{x->name(), x->num_tiles2(), NullOpt}); - if (auto p = x->pass_mode()) - j["pass-mode"] = *p; - } + to_json(j, proxy{x->name(), x->num_tiles2(), x->pass_mode()}); } void adl_serializer<std::shared_ptr<tile_atlas>>::from_json(const json& j, std::shared_ptr<tile_atlas>& val) @@ -47,15 +43,14 @@ void adl_serializer<std::shared_ptr<tile_atlas>>::from_json(const json& j, std:: using nlohmann::from_json; proxy x; from_json(j, x); - Optional<pass_mode> p; + pass_mode p = tile_atlas::default_pass_mode; if (j.contains("pass-mode")) - p = {InPlaceInit, j["pass-mode"]}; + p = j["pass-mode"]; val = loader.tile_atlas(x.name, x.size, p); - if (auto p2 = val->pass_mode(); p && p2 != p) + if (auto p2 = val->pass_mode(); p2 != p) { - int m = p2 ? int(*p2) : -1; const auto name = val->name(); - fm_throw("atlas {} wrong pass mode {} should be {}"_cf, name, m, uint8_t(*p)); + fm_throw("atlas {} wrong pass mode {} should be {}"_cf, name, uint8_t(p2), uint8_t(p)); } } } diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp index d0e32453..fcb32619 100644 --- a/shaders/lightmap.cpp +++ b/shaders/lightmap.cpp @@ -367,7 +367,7 @@ void lightmap_shader::add_geometry(Vector2 neighbor_offset, chunk& c) { auto t = c[i]; if (auto atlas = t.ground_atlas()) - if (atlas->pass_mode(pass_mode::pass) == pass_mode::blocked) + if (atlas->pass_mode() == pass_mode::blocked) { auto [min, max] = whole_tile(i); constexpr auto fuzz = Vector2(fuzz_pixels, fuzz_pixels), fuzz2 = fuzz*2; diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index 611754bc..ed6a23d2 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -44,7 +44,7 @@ void chunk::ensure_passability() noexcept if (const auto* atlas = ground_atlas_at(i)) { auto [min, max] = whole_tile(i); - auto id = make_id(collision_type::geometry, atlas->pass_mode(pass_mode::pass), i+1); + auto id = make_id(collision_type::geometry, atlas->pass_mode(), i+1); _rtree.Insert(min.data(), max.data(), id); } } diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp index 347da166..4f837cf1 100644 --- a/src/tile-atlas.hpp +++ b/src/tile-atlas.hpp @@ -37,6 +37,8 @@ public: GL::Texture2D& texture() { return tex_; } StringView name() const { return name_; } enum pass_mode pass_mode() const; + + static constexpr enum pass_mode default_pass_mode = pass_mode::pass; }; diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp index 8e6bd13c..3ee14f1e 100644 --- a/src/wall-atlas.cpp +++ b/src/wall-atlas.cpp @@ -58,7 +58,7 @@ wall_atlas::wall_atlas(wall_atlas_def def, String path, const ImageView2D& img) _image_size{get_image_size(img)}, _direction_map{def.direction_map} { - fm_soft_assert(!def.frames.empty()); + fm_soft_assert(!_frame_array.empty()); { bool found = false; diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp index b73704fe..c2da82f9 100644 --- a/src/wall-atlas.hpp +++ b/src/wall-atlas.hpp @@ -114,7 +114,7 @@ class wall_atlas final Info _info; String _path; Vector2ui _image_size; - GL::Texture2D _texture{NoCreate}; + GL::Texture2D _texture; std::array<DirArrayIndex, Wall::Direction_COUNT> _direction_map; Direction* get_Direction(Direction_ num) const; diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp index 58a38afb..f3c47288 100644 --- a/test/dijkstra.cpp +++ b/test/dijkstra.cpp @@ -19,7 +19,7 @@ void test_app::test_dijkstra() constexpr auto wpos = global_coords{wch, wt}; auto& ch = w[wch]; - auto metal2 = tile_image_proto{loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked), 0}; + auto metal2 = wall_image_proto{loader.wall_atlas("concrete1", false), 0}; for (int16_t j = wcy - 1; j <= wcy + 1; j++) for (int16_t i = wcx - 1; i <= wcx + 1; i++) diff --git a/test/loader.cpp b/test/loader.cpp index 1ef5dac8..b45d4f0e 100644 --- a/test/loader.cpp +++ b/test/loader.cpp @@ -8,8 +8,7 @@ namespace floormat { void test_app::test_loader() { - (void)loader.tile_atlases("wall.json", pass_mode::blocked); - (void)loader.tile_atlases("floor.json", pass_mode::pass); + (void)loader.tile_atlases("floor.json"); fm_assert(loader.tile_atlas("texel")->pass_mode() == pass_mode::blocked); fm_assert(loader.tile_atlas("metal1")->pass_mode() == pass_mode::pass); loader.sceneries(); diff --git a/test/main.cpp b/test/main.cpp index a5a96c54..973609f6 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -33,9 +33,8 @@ int test_app::exec() test_math(); test_hash(); test_wall_atlas(); - test_wall_atlas2(); - test_scenery(); + test_wall_atlas2(); test_path_search_node_pool(); test_path_search(); test_dijkstra(); diff --git a/test/path-search.cpp b/test/path-search.cpp index e42364e7..00203035 100644 --- a/test/path-search.cpp +++ b/test/path-search.cpp @@ -170,7 +170,7 @@ void test_bbox() return neighbor_tiles(w, { ch, pos }, {}, (object_id)-1, path_search::never_continue()); }; - const auto metal2 = loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked); + const auto metal2 = loader.wall_atlas("concrete1", false); const auto table = loader.scenery("table1"); { diff --git a/test/serializer.cpp b/test/serializer.cpp index 5fd55b3e..9ef3b021 100644 --- a/test/serializer.cpp +++ b/test/serializer.cpp @@ -17,8 +17,8 @@ chunk& test_app::make_test_chunk(world& w, chunk_coords_ ch) { chunk& c = w[ch]; c.mark_modified(); - auto metal2 = loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked), - tiles = loader.tile_atlas("tiles", {8, 5}, pass_mode::pass); + auto metal2 = loader.wall_atlas("concrete1", false); + auto tiles = loader.tile_atlas("tiles", {8, 5}, pass_mode::pass); constexpr auto N = TILE_MAX_DIM; for (auto [x, k, pt] : c) x.ground() = { tiles, variant_t(k % tiles->num_tiles()) }; diff --git a/test/wall-atlas2.cpp b/test/wall-atlas2.cpp index 778b5b0b..23f5a1b8 100644 --- a/test/wall-atlas2.cpp +++ b/test/wall-atlas2.cpp @@ -1,7 +1,19 @@ #include "app.hpp" +#include "compat/assert.hpp" +#include "src/wall-atlas.hpp" +#include "loader/loader.hpp" +#include "loader/wall-info.hpp" namespace floormat { -//void test_app::test_wall_atlas2() {} +void test_app::test_wall_atlas2() +{ + Debug{} << "test_wall2: start"; + static constexpr auto name = "concrete1"_s; + auto& a = *loader.wall_atlas(name, false); + fm_assert(a.name() == name); + fm_assert(a.info().depth == 20); + Debug{} << "test_wall2: end"; +} } // namespace floormat diff --git a/walls/concrete-wall1.json b/walls/concrete1.json index a2a8bbdd..1f3911ce 100644 --- a/walls/concrete-wall1.json +++ b/walls/concrete1.json @@ -45,5 +45,5 @@ "pixel-size": "64 x 192"
}
},
- "name": "concrete-wall1"
+ "name": "concrete1"
}
diff --git a/walls/concrete-wall1.png b/walls/concrete1.png Binary files differindex 137f3295..137f3295 100644 --- a/walls/concrete-wall1.png +++ b/walls/concrete1.png |