From 7867213a01fcabb1f05b1836c2ca59dc3bb2132f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 11 Jan 2024 13:54:53 +0100 Subject: rename tile_atlas -> ground_atlas --- draw/floor.cpp | 7 +- editor/app.hpp | 2 +- editor/editor.cpp | 6 +- editor/editor.hpp | 10 +-- editor/ground-editor.cpp | 166 +++++++++++++++++++++++++++++++++++++++++++++ editor/ground-editor.hpp | 56 +++++++++++++++ editor/imgui-editors.cpp | 4 +- editor/tile-editor.cpp | 166 --------------------------------------------- editor/tile-editor.hpp | 56 --------------- editor/update.cpp | 10 +-- loader/atlas.cpp | 18 ++--- loader/impl.hpp | 10 +-- loader/json.cpp | 16 ++--- loader/loader.hpp | 8 +-- serialize/ground-atlas.cpp | 58 ++++++++++++++++ serialize/ground-atlas.hpp | 14 ++++ serialize/tile-atlas.cpp | 58 ---------------- serialize/tile-atlas.hpp | 14 ---- serialize/tile.cpp | 4 +- serialize/world-reader.cpp | 8 +-- serialize/world-writer.cpp | 2 +- shaders/lightmap.cpp | 2 +- src/chunk-collision.cpp | 2 +- src/chunk-render.cpp | 2 +- src/chunk.cpp | 2 +- src/chunk.hpp | 4 +- src/ground-atlas.cpp | 59 ++++++++++++++++ src/ground-atlas.hpp | 46 +++++++++++++ src/tile-atlas.cpp | 59 ---------------- src/tile-atlas.hpp | 46 ------------- src/tile-image.cpp | 4 +- src/tile-image.hpp | 6 +- src/tile.cpp | 12 ++-- src/tile.hpp | 14 ++-- test/json.cpp | 12 ++-- test/loader.cpp | 8 +-- test/serializer.cpp | 4 +- 37 files changed, 488 insertions(+), 487 deletions(-) create mode 100644 editor/ground-editor.cpp create mode 100644 editor/ground-editor.hpp delete mode 100644 editor/tile-editor.cpp delete mode 100644 editor/tile-editor.hpp create mode 100644 serialize/ground-atlas.cpp create mode 100644 serialize/ground-atlas.hpp delete mode 100644 serialize/tile-atlas.cpp delete mode 100644 serialize/tile-atlas.hpp create mode 100644 src/ground-atlas.cpp create mode 100644 src/ground-atlas.hpp delete mode 100644 src/tile-atlas.cpp delete mode 100644 src/tile-atlas.hpp diff --git a/draw/floor.cpp b/draw/floor.cpp index 31626f1c..a073f39f 100644 --- a/draw/floor.cpp +++ b/draw/floor.cpp @@ -1,7 +1,7 @@ #include "floor.hpp" #include "shaders/shader.hpp" #include "src/chunk.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "compat/assert.hpp" #include @@ -13,13 +13,14 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) { constexpr int quad_index_count = 6; const auto [mesh_, ids, size] = c.ensure_ground_mesh(); - struct { tile_atlas* atlas = nullptr; size_t pos = 0; } last; + struct { + ground_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, ground_atlas* atlas, uint32_t max_index) { if (atlas == last.atlas) return; if (auto len = i - last.pos; last.atlas && len > 0) diff --git a/editor/app.hpp b/editor/app.hpp index 45735400..09198c36 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -21,7 +21,7 @@ namespace floormat { struct chunk; struct floormat_main; -class tile_atlas; +class ground_atlas; struct fm_settings; class anim_atlas; struct critter; diff --git a/editor/editor.cpp b/editor/editor.cpp index de2e690e..86a180b5 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -191,7 +191,7 @@ void editor::set_mode(editor_mode mode) on_release(); } -const tile_editor* editor::current_ground_editor() const noexcept +const ground_editor* editor::current_ground_editor() const noexcept { switch (_mode) { @@ -229,9 +229,9 @@ const vobj_editor* editor::current_vobj_editor() const noexcept return nullptr; } -tile_editor* editor::current_ground_editor() noexcept +ground_editor* editor::current_ground_editor() noexcept { - return const_cast(static_cast(*this).current_ground_editor()); + return const_cast(static_cast(*this).current_ground_editor()); } wall_editor* editor::current_wall_editor() noexcept diff --git a/editor/editor.hpp b/editor/editor.hpp index dc897bc3..fae85c2f 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -4,7 +4,7 @@ #include "src/tile-image.hpp" #include "src/scenery.hpp" #include "editor-enums.hpp" -#include "tile-editor.hpp" +#include "ground-editor.hpp" #include "wall-editor.hpp" #include "scenery-editor.hpp" #include "vobj-editor.hpp" @@ -16,7 +16,7 @@ namespace floormat { struct world; class anim_atlas; -class tile_atlas; +class ground_atlas; struct app; struct editor final @@ -26,8 +26,8 @@ struct editor final [[nodiscard]] editor_mode mode() const noexcept { return _mode; } void set_mode(editor_mode mode); - tile_editor* current_ground_editor() noexcept; - const tile_editor* current_ground_editor() const noexcept; + ground_editor* current_ground_editor() noexcept; + const ground_editor* current_ground_editor() const noexcept; wall_editor* current_wall_editor() noexcept; const wall_editor* current_wall_editor() const noexcept; scenery_editor* current_scenery_editor() noexcept; @@ -57,7 +57,7 @@ private: app* _app; - tile_editor _floor; + ground_editor _floor; wall_editor _wall; scenery_editor _scenery; vobj_editor _vobj; diff --git a/editor/ground-editor.cpp b/editor/ground-editor.cpp new file mode 100644 index 00000000..0f67853e --- /dev/null +++ b/editor/ground-editor.cpp @@ -0,0 +1,166 @@ +#include "ground-editor.hpp" +#include "src/ground-atlas.hpp" +#include "src/world.hpp" +#include "src/random.hpp" +#include "keys.hpp" +#include "loader/loader.hpp" +#include "compat/exception.hpp" +#include +#include + +namespace floormat { + +ground_editor::ground_editor() +{ + load_atlases(); +} + +void ground_editor::load_atlases() +{ + for (const auto& atlas : loader.ground_atlases("floor.json"_s)) + { + auto& [_, vec] = _permutation; + vec.reserve(atlas->num_tiles()); + _atlases[atlas->name()] = atlas; + } +} + +std::shared_ptr ground_editor::maybe_atlas(StringView str) +{ + if (auto it = _atlases.find(str); it != _atlases.end()) + return it->second; + else + return nullptr; +} + +std::shared_ptr ground_editor::atlas(StringView str) +{ + if (auto ptr = maybe_atlas(str)) + return ptr; + else + fm_throw("no such atlas: {}"_cf, str); +} + +StringView ground_editor::name() const noexcept { return "floor"_s; } + +void ground_editor::clear_selection() +{ + _selected_tile = {}; + _permutation = {}; + _selection_mode = sel_none; +} + +void ground_editor::select_tile(const std::shared_ptr& atlas, size_t variant) +{ + fm_assert(atlas); + clear_selection(); + _selection_mode = sel_tile; + _selected_tile = { atlas, variant_t(variant % atlas->num_tiles()) }; +} + +void ground_editor::select_tile_permutation(const std::shared_ptr& atlas) +{ + fm_assert(atlas); + clear_selection(); + _selection_mode = sel_perm; + _permutation = { atlas, {} }; +} + +bool ground_editor::is_tile_selected(const std::shared_ptr& atlas, size_t variant) const +{ + return atlas && _selection_mode == sel_tile && _selected_tile && + atlas == _selected_tile.atlas && variant == _selected_tile.variant; +} + +bool ground_editor::is_permutation_selected(const std::shared_ptr& atlas) const +{ + const auto& [perm, _] = _permutation; + return atlas && _selection_mode == sel_perm && perm == atlas; +} + +bool ground_editor::is_atlas_selected(const std::shared_ptr& atlas) const +{ + switch (_selection_mode) + { + default: + case sel_none: + return false; + case sel_perm: + return is_permutation_selected(atlas); + case sel_tile: + return atlas && _selected_tile && atlas == _selected_tile.atlas; + } +} + +bool ground_editor::is_anything_selected() const +{ + return _selection_mode != sel_none; +} + +template +void fisher_yates(T begin, T end) +{ + const auto N = std::distance(begin, end); + for (auto i = N-1; i >= 1; i--) + { + const auto j = random(i+1); + using std::swap; + swap(begin[i], begin[j]); + } +} + +tile_image_proto ground_editor::get_selected_perm() +{ + auto& [atlas, vec] = _permutation; + const auto N = (variant_t)atlas->num_tiles(); + if (N == 0) + return {}; + if (vec.empty()) + { + for (variant_t i = 0; i < N; i++) + vec.push_back(i); + fisher_yates(vec.begin(), vec.end()); + } + const auto idx = vec.back(); + vec.pop_back(); + return {atlas, idx}; +} + +tile_image_proto ground_editor::get_selected() +{ + switch (_selection_mode) + { + default: + fm_warn_once("invalid editor mode '%u'", (unsigned)_selection_mode); + [[fallthrough]]; + case sel_none: + return {}; + case sel_tile: + return _selected_tile; + case sel_perm: + return get_selected_perm(); + } +} + +void ground_editor::place_tile(world& world, global_coords pos, const tile_image_proto& img) +{ + auto [c, t] = world[pos]; + c.mark_ground_modified(); + t.ground() = img; +} + +auto ground_editor::check_snap(int mods) const -> editor_snap_mode +{ + const bool ctrl = mods & kmod_ctrl, shift = mods & kmod_shift; + + if (!(ctrl | shift)) + return editor_snap_mode::none; + + 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/ground-editor.hpp b/editor/ground-editor.hpp new file mode 100644 index 00000000..46c9dc3a --- /dev/null +++ b/editor/ground-editor.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include "editor-enums.hpp" +#include "src/tile-image.hpp" +#include "src/global-coords.hpp" +#include +#include +#include +#include + +namespace floormat { + +struct world; + +class ground_editor final +{ + enum selection_mode : unsigned char { + sel_none, sel_tile, sel_perm, + }; + + struct tuple final { + std::shared_ptr atlas; + std::vector variant; + }; + + std::map> _atlases; + tile_image_proto _selected_tile; + tuple _permutation; + selection_mode _selection_mode = sel_none; + + void load_atlases(); + tile_image_proto get_selected_perm(); + +public: + ground_editor(); + std::shared_ptr maybe_atlas(StringView str); + std::shared_ptr atlas(StringView str); + auto cbegin() const noexcept { return _atlases.cbegin(); } + auto cend() const noexcept { return _atlases.cend(); } + auto begin() const noexcept { return _atlases.cbegin(); } + auto end() const noexcept { return _atlases.cend(); } + StringView name() const noexcept; + + void clear_selection(); + void select_tile(const std::shared_ptr& atlas, size_t variant); + void select_tile_permutation(const std::shared_ptr& atlas); + bool is_tile_selected(const std::shared_ptr& atlas, size_t variant) const; + bool is_permutation_selected(const std::shared_ptr& atlas) const; + bool is_atlas_selected(const std::shared_ptr& atlas) const; + bool is_anything_selected() const; + tile_image_proto get_selected(); + void place_tile(world& world, global_coords pos, const tile_image_proto& img); + editor_snap_mode check_snap(int mods) const; +}; + +} // namespace floormat diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp index 4ffb74ba..2e585d6b 100644 --- a/editor/imgui-editors.cpp +++ b/editor/imgui-editors.cpp @@ -2,7 +2,7 @@ #include "compat/format.hpp" #include "imgui-raii.hpp" #include "src/anim-atlas.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/wall-atlas.hpp" #include "loader/loader.hpp" #include "floormat/main.hpp" @@ -51,7 +51,7 @@ void select_tile(wall_editor& wa, const wall_info* sc) { wa.select_atlas(sc->atl auto get_texcoords(const auto&, anim_atlas& atlas) { return atlas.texcoords_for_frame(atlas.first_rotation(), 0, !atlas.group(atlas.first_rotation()).mirror_from.isEmpty()); } auto get_texcoords(const wall_info* w, wall_atlas& atlas) { auto sz = get_size(w, atlas); return Quads::texcoords_at({}, sz, atlas.image_size()); }; -void draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const std::shared_ptr& atlas, Vector2 dpi) +void draw_editor_tile_pane_atlas(ground_editor& ed, StringView name, const std::shared_ptr& atlas, Vector2 dpi) { const auto b = push_id("tile-pane"); diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp deleted file mode 100644 index 1b766208..00000000 --- a/editor/tile-editor.cpp +++ /dev/null @@ -1,166 +0,0 @@ -#include "tile-editor.hpp" -#include "src/tile-atlas.hpp" -#include "src/world.hpp" -#include "src/random.hpp" -#include "keys.hpp" -#include "loader/loader.hpp" -#include "compat/exception.hpp" -#include -#include - -namespace floormat { - -tile_editor::tile_editor() -{ - load_atlases(); -} - -void tile_editor::load_atlases() -{ - for (const auto& atlas : loader.tile_atlases("floor.json"_s)) - { - auto& [_, vec] = _permutation; - vec.reserve(atlas->num_tiles()); - _atlases[atlas->name()] = atlas; - } -} - -std::shared_ptr tile_editor::maybe_atlas(StringView str) -{ - if (auto it = _atlases.find(str); it != _atlases.end()) - return it->second; - else - return nullptr; -} - -std::shared_ptr tile_editor::atlas(StringView str) -{ - if (auto ptr = maybe_atlas(str)) - return ptr; - else - fm_throw("no such atlas: {}"_cf, str); -} - -StringView tile_editor::name() const noexcept { return "floor"_s; } - -void tile_editor::clear_selection() -{ - _selected_tile = {}; - _permutation = {}; - _selection_mode = sel_none; -} - -void tile_editor::select_tile(const std::shared_ptr& atlas, size_t variant) -{ - fm_assert(atlas); - clear_selection(); - _selection_mode = sel_tile; - _selected_tile = { atlas, variant_t(variant % atlas->num_tiles()) }; -} - -void tile_editor::select_tile_permutation(const std::shared_ptr& atlas) -{ - fm_assert(atlas); - clear_selection(); - _selection_mode = sel_perm; - _permutation = { atlas, {} }; -} - -bool tile_editor::is_tile_selected(const std::shared_ptr& atlas, size_t variant) const -{ - return atlas && _selection_mode == sel_tile && _selected_tile && - atlas == _selected_tile.atlas && variant == _selected_tile.variant; -} - -bool tile_editor::is_permutation_selected(const std::shared_ptr& atlas) const -{ - const auto& [perm, _] = _permutation; - return atlas && _selection_mode == sel_perm && perm == atlas; -} - -bool tile_editor::is_atlas_selected(const std::shared_ptr& atlas) const -{ - switch (_selection_mode) - { - default: - case sel_none: - return false; - case sel_perm: - return is_permutation_selected(atlas); - case sel_tile: - return atlas && _selected_tile && atlas == _selected_tile.atlas; - } -} - -bool tile_editor::is_anything_selected() const -{ - return _selection_mode != sel_none; -} - -template -void fisher_yates(T begin, T end) -{ - const auto N = std::distance(begin, end); - for (auto i = N-1; i >= 1; i--) - { - const auto j = random(i+1); - using std::swap; - swap(begin[i], begin[j]); - } -} - -tile_image_proto tile_editor::get_selected_perm() -{ - auto& [atlas, vec] = _permutation; - const auto N = (variant_t)atlas->num_tiles(); - if (N == 0) - return {}; - if (vec.empty()) - { - for (variant_t i = 0; i < N; i++) - vec.push_back(i); - fisher_yates(vec.begin(), vec.end()); - } - const auto idx = vec.back(); - vec.pop_back(); - return {atlas, idx}; -} - -tile_image_proto tile_editor::get_selected() -{ - switch (_selection_mode) - { - default: - fm_warn_once("invalid editor mode '%u'", (unsigned)_selection_mode); - [[fallthrough]]; - case sel_none: - return {}; - case sel_tile: - return _selected_tile; - case sel_perm: - return get_selected_perm(); - } -} - -void tile_editor::place_tile(world& world, global_coords pos, const tile_image_proto& img) -{ - auto [c, t] = world[pos]; - 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; - - if (!(ctrl | shift)) - return editor_snap_mode::none; - - 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/tile-editor.hpp b/editor/tile-editor.hpp deleted file mode 100644 index a33ed848..00000000 --- a/editor/tile-editor.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include "editor-enums.hpp" -#include "src/tile-image.hpp" -#include "src/global-coords.hpp" -#include -#include -#include -#include - -namespace floormat { - -struct world; - -class tile_editor final -{ - enum selection_mode : unsigned char { - sel_none, sel_tile, sel_perm, - }; - - struct tuple final { - std::shared_ptr atlas; - std::vector variant; - }; - - std::map> _atlases; - tile_image_proto _selected_tile; - tuple _permutation; - selection_mode _selection_mode = sel_none; - - void load_atlases(); - tile_image_proto get_selected_perm(); - -public: - tile_editor(); - std::shared_ptr maybe_atlas(StringView str); - std::shared_ptr atlas(StringView str); - auto cbegin() const noexcept { return _atlases.cbegin(); } - auto cend() const noexcept { return _atlases.cend(); } - auto begin() const noexcept { return _atlases.cbegin(); } - auto end() const noexcept { return _atlases.cend(); } - StringView name() const noexcept; - - void clear_selection(); - void select_tile(const std::shared_ptr& atlas, size_t variant); - void select_tile_permutation(const std::shared_ptr& atlas); - bool is_tile_selected(const std::shared_ptr& atlas, size_t variant) const; - bool is_permutation_selected(const std::shared_ptr& atlas) const; - bool is_atlas_selected(const std::shared_ptr& atlas) const; - bool is_anything_selected() const; - tile_image_proto get_selected(); - void place_tile(world& world, global_coords pos, const tile_image_proto& img); - editor_snap_mode check_snap(int mods) const; -}; - -} // namespace floormat diff --git a/editor/update.cpp b/editor/update.cpp index e80a5318..1140ad47 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -1,6 +1,6 @@ #include "app.hpp" #include "src/world.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/anim-atlas.hpp" #include "main/clickable.hpp" #include "floormat/events.hpp" @@ -17,10 +17,10 @@ namespace floormat { void app::maybe_initialize_chunk_(const chunk_coords_& pos, chunk& c) { - auto floor1 = loader.tile_atlas("floor-tiles", {44, 4}, pass_mode::pass); - auto floor2 = loader.tile_atlas("metal1", {2, 2}, pass_mode::pass); - auto wall1 = loader.tile_atlas("wood2", {2, 1}, pass_mode::blocked); - auto wall2 = loader.tile_atlas("wood1", {2, 1}, pass_mode::blocked); + auto floor1 = loader.ground_atlas("floor-tiles", { 44, 4 }, pass_mode::pass); + auto floor2 = loader.ground_atlas("metal1", { 2, 2 }, pass_mode::pass); + auto wall1 = loader.ground_atlas("wood2", { 2, 1 }, pass_mode::blocked); + auto wall2 = loader.ground_atlas("wood1", { 2, 1 }, pass_mode::blocked); auto door = loader.anim_atlas("door-close", loader.SCENERY_PATH); auto table = loader.anim_atlas("table", loader.SCENERY_PATH); auto control_panel = loader.anim_atlas("control-panel", loader.SCENERY_PATH); diff --git a/loader/atlas.cpp b/loader/atlas.cpp index e2ecb956..c7bfbdbf 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -2,7 +2,7 @@ #include "compat/assert.hpp" #include "compat/exception.hpp" #include "src/emplacer.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/anim-atlas.hpp" #include #include @@ -45,9 +45,9 @@ bool loader_::check_atlas_name(StringView str) noexcept namespace floormat::loader_detail { -std::shared_ptr loader_impl::tile_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) +std::shared_ptr loader_impl::ground_atlas(StringView name, Vector2ub size, pass_mode pass) noexcept(false) { - if (auto it = tile_atlas_map.find(name); it != tile_atlas_map.end()) + if (auto it = ground_atlas_map.find(name); it != ground_atlas_map.end()) { fm_assert(it->second->pass_mode() == pass); return it->second; @@ -58,16 +58,16 @@ std::shared_ptr loader_impl::tile_atlas(StringView name, Vector2ub s char buf[FILENAME_MAX]; auto path = make_atlas_path(buf, IMAGE_PATH, name); - auto atlas = std::make_shared(path, name, texture(""_s, path), size, pass); - tile_atlas_map[atlas->name()] = atlas; + auto atlas = std::make_shared(path, name, texture(""_s, path), size, pass); + ground_atlas_map[atlas->name()] = atlas; return atlas; } -std::shared_ptr loader_impl::tile_atlas(StringView filename) noexcept(false) +std::shared_ptr loader_impl::ground_atlas(StringView filename) noexcept(false) { - fm_assert(!tile_atlas_map.empty()); - auto it = tile_atlas_map.find(filename); - if (it == tile_atlas_map.end()) + fm_assert(!ground_atlas_map.empty()); + auto it = ground_atlas_map.find(filename); + if (it == ground_atlas_map.end()) fm_throw("no such tile atlas '{}'"_cf, filename); return it->second; } diff --git a/loader/impl.hpp b/loader/impl.hpp index d88174ba..165b7c2f 100644 --- a/loader/impl.hpp +++ b/loader/impl.hpp @@ -59,12 +59,12 @@ struct loader_impl final : loader_ std::shared_ptr get_wall_atlas(StringView name, StringView path); // >-----> tile >-----> - tsl::robin_map> tile_atlas_map; - std::vector> tile_atlas_array; + tsl::robin_map> ground_atlas_map; + std::vector> ground_atlas_array; - ArrayView> tile_atlases(StringView filename) noexcept(false) override; - std::shared_ptr tile_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) override; - std::shared_ptr tile_atlas(StringView filename) noexcept(false) override; + ArrayView> ground_atlases(StringView filename) noexcept(false) override; + std::shared_ptr ground_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) override; + std::shared_ptr ground_atlas(StringView filename) noexcept(false) override; // >-----> anim >-----> tsl::robin_map> anim_atlas_map; diff --git a/loader/json.cpp b/loader/json.cpp index 7cf24015..8e2f329f 100644 --- a/loader/json.cpp +++ b/loader/json.cpp @@ -1,10 +1,10 @@ #include "impl.hpp" #include "compat/assert.hpp" #include "compat/exception.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "serialize/json-helper.hpp" #include "serialize/anim.hpp" -#include "serialize/tile-atlas.hpp" +#include "serialize/ground-atlas.hpp" #include "serialize/scenery.hpp" #include "loader/scenery.hpp" #include @@ -53,14 +53,14 @@ const scenery_proto& loader_impl::scenery(StringView name) noexcept(false) return it->second->proto; } -ArrayView> loader_impl::tile_atlases(StringView filename) +ArrayView> loader_impl::ground_atlases(StringView filename) noexcept(false) { - if (!tile_atlas_array.empty()) [[likely]] - return tile_atlas_array; - tile_atlas_array = json_helper::from_json>>( + if (!ground_atlas_array.empty()) [[likely]] + return ground_atlas_array; + ground_atlas_array = json_helper::from_json>>( Path::join(loader_::IMAGE_PATH, filename)); - fm_assert(!tile_atlas_array.empty()); - return tile_atlas_array; + fm_assert(!ground_atlas_array.empty()); + return ground_atlas_array; } } // namespace floormat::loader_detail diff --git a/loader/loader.hpp b/loader/loader.hpp index f93e6967..63b5ea5c 100644 --- a/loader/loader.hpp +++ b/loader/loader.hpp @@ -13,7 +13,7 @@ using ImageData2D = ImageData<2>; namespace floormat { -class tile_atlas; +class ground_atlas; class anim_atlas; class wall_atlas; struct scenery_proto; @@ -24,15 +24,15 @@ struct loader_ { virtual StringView shader(StringView filename) noexcept = 0; virtual Trade::ImageData2D texture(StringView prefix, StringView filename, bool fail_ok = true) noexcept(false) = 0; - virtual std::shared_ptr tile_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) = 0; - virtual std::shared_ptr tile_atlas(StringView filename) noexcept(false) = 0; + virtual std::shared_ptr ground_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) = 0; + virtual std::shared_ptr ground_atlas(StringView filename) noexcept(false) = 0; virtual ArrayView anim_atlas_list() = 0; virtual std::shared_ptr anim_atlas(StringView name, StringView dir = ANIM_PATH) noexcept(false) = 0; virtual std::shared_ptr wall_atlas(StringView name, bool fail_ok = true) noexcept(false) = 0; virtual ArrayView wall_atlas_list() = 0; static void destroy(); static loader_& default_loader() noexcept; - virtual ArrayView> tile_atlases(StringView filename) noexcept(false) = 0; + virtual ArrayView> ground_atlases(StringView filename) noexcept(false) = 0; virtual ArrayView sceneries() = 0; virtual const scenery_proto& scenery(StringView name) noexcept(false) = 0; virtual StringView startup_directory() noexcept = 0; diff --git a/serialize/ground-atlas.cpp b/serialize/ground-atlas.cpp new file mode 100644 index 00000000..76c8686e --- /dev/null +++ b/serialize/ground-atlas.cpp @@ -0,0 +1,58 @@ +#include "src/ground-atlas.hpp" +#include "serialize/ground-atlas.hpp" +#include "serialize/corrade-string.hpp" +#include "serialize/magnum-vector.hpp" +#include "loader/loader.hpp" +#include "serialize/pass-mode.hpp" +#include "compat/exception.hpp" +#include +#include +#include + +using namespace floormat; + +namespace { + +struct proxy { + StringView name; + Vector2ub size; + pass_mode passability; +}; + +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy, name, size) + +} // namespace + +namespace nlohmann { + +void adl_serializer>::to_json(json& j, const std::shared_ptr& x) +{ + using nlohmann::to_json; + if (!x) + j = nullptr; + else + to_json(j, proxy{x->name(), x->num_tiles2(), x->pass_mode()}); +} + +void adl_serializer>::from_json(const json& j, std::shared_ptr& val) +{ + if (j.is_null()) + val = nullptr; + else + { + using nlohmann::from_json; + proxy x; + from_json(j, x); + pass_mode p = ground_atlas::default_pass_mode; + if (j.contains("pass-mode")) + p = j["pass-mode"]; + val = loader.ground_atlas(x.name, x.size, p); + if (auto p2 = val->pass_mode(); p2 != p) + { + const auto name = val->name(); + fm_throw("atlas {} wrong pass mode {} should be {}"_cf, name, uint8_t(p2), uint8_t(p)); + } + } +} + +} // namespace nlohmann diff --git a/serialize/ground-atlas.hpp b/serialize/ground-atlas.hpp new file mode 100644 index 00000000..344e8714 --- /dev/null +++ b/serialize/ground-atlas.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "src/ground-atlas.hpp" +#include +#include + +namespace nlohmann { + +template<> +struct adl_serializer> final { + static void to_json(json& j, const std::shared_ptr& x); + static void from_json(const json& j, std::shared_ptr& x); +}; + +} // namespace nlohmann diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp deleted file mode 100644 index 88385339..00000000 --- a/serialize/tile-atlas.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "src/tile-atlas.hpp" -#include "serialize/tile-atlas.hpp" -#include "serialize/corrade-string.hpp" -#include "serialize/magnum-vector.hpp" -#include "loader/loader.hpp" -#include "serialize/pass-mode.hpp" -#include "compat/exception.hpp" -#include -#include -#include - -using namespace floormat; - -namespace { - -struct proxy { - StringView name; - Vector2ub size; - pass_mode passability; -}; - -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy, name, size) - -} // namespace - -namespace nlohmann { - -void adl_serializer>::to_json(json& j, const std::shared_ptr& x) -{ - using nlohmann::to_json; - if (!x) - j = nullptr; - else - to_json(j, proxy{x->name(), x->num_tiles2(), x->pass_mode()}); -} - -void adl_serializer>::from_json(const json& j, std::shared_ptr& val) -{ - if (j.is_null()) - val = nullptr; - else - { - using nlohmann::from_json; - proxy x; - from_json(j, x); - pass_mode p = tile_atlas::default_pass_mode; - if (j.contains("pass-mode")) - p = j["pass-mode"]; - val = loader.tile_atlas(x.name, x.size, p); - if (auto p2 = val->pass_mode(); p2 != p) - { - const auto name = val->name(); - fm_throw("atlas {} wrong pass mode {} should be {}"_cf, name, uint8_t(p2), uint8_t(p)); - } - } -} - -} // namespace nlohmann diff --git a/serialize/tile-atlas.hpp b/serialize/tile-atlas.hpp deleted file mode 100644 index 0c65c55e..00000000 --- a/serialize/tile-atlas.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "src/tile-atlas.hpp" -#include -#include - -namespace nlohmann { - -template<> -struct adl_serializer> final { - static void to_json(json& j, const std::shared_ptr& x); - static void from_json(const json& j, std::shared_ptr& x); -}; - -} // namespace nlohmann diff --git a/serialize/tile.cpp b/serialize/tile.cpp index 69cec8a2..cd9064a8 100644 --- a/serialize/tile.cpp +++ b/serialize/tile.cpp @@ -1,8 +1,8 @@ #include "serialize/tile.hpp" #include "src/tile.hpp" #include "src/global-coords.hpp" -#include "serialize/tile-atlas.hpp" -#include "src/tile-atlas.hpp" +#include "serialize/ground-atlas.hpp" +#include "src/ground-atlas.hpp" #include #include diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index 05b880b8..5e66616b 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -7,7 +7,7 @@ #include "src/light.hpp" #include "loader/loader.hpp" #include "loader/scenery.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/anim-atlas.hpp" #include "src/chunk-scenery.hpp" #include "compat/strerror.hpp" @@ -215,9 +215,9 @@ void reader_state::read_chunks(reader_t& s) ? s.read() : uint8_t(s.read()); auto name = lookup_atlas(id); - if constexpr(std::is_same_v) + if constexpr(std::is_same_v) { - auto atlas = loader.tile_atlas(name); + auto atlas = loader.ground_atlas(name); fm_soft_assert(v < atlas->num_tiles()); return { atlas, v }; } @@ -232,7 +232,7 @@ void reader_state::read_chunks(reader_t& s) SET_CHUNK_SIZE(); //t.passability() = pass_mode(flags & pass_mask); if (flags & meta_ground) - t.ground() = make_atlas.operator()(); + t.ground() = make_atlas.operator()(); if (flags & meta_wall_n) t.wall_north() = make_atlas.operator()(); if (flags & meta_wall_w) diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index a89f039a..e32d3cdf 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -1,6 +1,6 @@ #define FM_SERIALIZE_WORLD_IMPL #include "world-impl.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/wall-atlas.hpp" #include "binary-writer.inl" #include "src/global-coords.hpp" diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp index 1be58131..f1d0e088 100644 --- a/shaders/lightmap.cpp +++ b/shaders/lightmap.cpp @@ -3,7 +3,7 @@ #include "src/tile-defs.hpp" #include "src/chunk.hpp" #include "src/tile-bbox.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/wall-atlas.hpp" #include "src/quads.hpp" #include "src/object.hpp" diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp index 4f94df6b..a6fd379d 100644 --- a/src/chunk-collision.cpp +++ b/src/chunk-collision.cpp @@ -1,5 +1,5 @@ #include "chunk.hpp" -#include "tile-atlas.hpp" +#include "ground-atlas.hpp" #include "object.hpp" #include "src/RTree-search.hpp" #include "src/chunk-scenery.hpp" diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp index d019a948..ffaa33ec 100644 --- a/src/chunk-render.cpp +++ b/src/chunk-render.cpp @@ -1,5 +1,5 @@ #include "chunk.hpp" -#include "tile-atlas.hpp" +#include "ground-atlas.hpp" #include "quads.hpp" #include "shaders/shader.hpp" #include "compat/defs.hpp" diff --git a/src/chunk.cpp b/src/chunk.cpp index a49669c5..eaeb06e1 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -36,7 +36,7 @@ bool chunk::empty(bool force) const noexcept return true; } -tile_atlas* chunk::ground_atlas_at(size_t i) const noexcept { return _ground ? _ground->atlases[i].get() : nullptr; } +ground_atlas* chunk::ground_atlas_at(size_t i) const noexcept { return _ground ? _ground->atlases[i].get() : nullptr; } tile_ref chunk::operator[](size_t idx) noexcept { return { *this, uint8_t(idx) }; } tile_proto chunk::operator[](size_t idx) const noexcept { return tile_proto(tile_ref { *const_cast(this), uint8_t(idx) }); } diff --git a/src/chunk.hpp b/src/chunk.hpp index 3005475c..1f144ca7 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -103,7 +103,7 @@ struct chunk final void ensure_alloc_ground(); void ensure_alloc_walls(); ground_mesh_tuple ensure_ground_mesh() noexcept; - tile_atlas* ground_atlas_at(size_t i) const noexcept; + ground_atlas* ground_atlas_at(size_t i) const noexcept; wall_atlas* wall_atlas_at(size_t i) const noexcept; wall_mesh_tuple ensure_wall_mesh() noexcept; @@ -129,7 +129,7 @@ struct chunk final private: struct ground_stuff { - std::array, TILE_COUNT> atlases; + std::array, TILE_COUNT> atlases; std::array indexes = {}; std::array variants = {}; }; diff --git a/src/ground-atlas.cpp b/src/ground-atlas.cpp new file mode 100644 index 00000000..a64264ff --- /dev/null +++ b/src/ground-atlas.cpp @@ -0,0 +1,59 @@ +#include "ground-atlas.hpp" +#include "quads.hpp" +#include "compat/assert.hpp" +#include "tile-image.hpp" +#include "compat/exception.hpp" +#include +#include +#include +#include + +namespace floormat { + +using namespace floormat::Quads; + +ground_atlas::ground_atlas(StringView path, StringView name, const ImageView2D& image, Vector2ub tile_count, enum pass_mode p) : + texcoords_{make_texcoords_array(Vector2ui(image.size()), tile_count)}, + path_{path}, name_{name}, size_{image.size()}, dims_{tile_count}, passability{p} +{ + constexpr auto variant_max = std::numeric_limits::max(); + fm_soft_assert(num_tiles() <= variant_max); + fm_soft_assert(dims_[0] > 0 && dims_[1] > 0); + fm_soft_assert(size_ % Vector2ui{tile_count} == Vector2ui()); + tex_.setLabel(path_) + .setWrapping(GL::SamplerWrapping::ClampToEdge) + .setMagnificationFilter(GL::SamplerFilter::Nearest) + .setMinificationFilter(GL::SamplerFilter::Linear) + .setMaxAnisotropy(1) + .setBorderColor(Color4{1, 0, 0, 1}) + .setStorage(1, GL::textureFormat(image.format()), image.size()) + .setSubImage(0, {}, image); +} + +std::array ground_atlas::texcoords_for_id(size_t i) const +{ + fm_assert(i < num_tiles()); + return texcoords_[i]; +} + +auto ground_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i) -> texcoords +{ + const auto sz = pixel_size/Vector2ui{tile_count}; + const auto id = Vector2ui{ uint32_t(i % tile_count[0]), uint32_t(i / tile_count[0]) }; + const auto p0 = id * sz; + return texcoords_at(p0, sz, pixel_size); +} + +auto ground_atlas::make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count) -> std::unique_ptr +{ + const size_t N = Vector2ui{tile_count}.product(); + auto ptr = std::make_unique[]>(N); + for (auto i = 0uz; i < N; i++) + ptr[i] = make_texcoords(pixel_size, tile_count, i); + return ptr; +} + +size_t ground_atlas::num_tiles() const { return Vector2ui{dims_}.product(); } +enum pass_mode ground_atlas::pass_mode() const { return passability; } + +} // namespace floormat diff --git a/src/ground-atlas.hpp b/src/ground-atlas.hpp new file mode 100644 index 00000000..e6e2d5ba --- /dev/null +++ b/src/ground-atlas.hpp @@ -0,0 +1,46 @@ +#pragma once +#include "src/pass-mode.hpp" +#include "src/quads.hpp" +#include +#include +#include +#include +#include +#include +#include + +namespace floormat { + +class ground_atlas final +{ + using quad = Quads::quad; + using texcoords = std::array; + + static std::unique_ptr make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count); + static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i); + + std::unique_ptr texcoords_; + GL::Texture2D tex_; + String path_, name_; + Vector2ui size_; + Vector2ub dims_; + enum pass_mode passability; + +public: + ground_atlas(StringView path, StringView name, const ImageView2D& img, Vector2ub tile_count, enum pass_mode pass_mode); + + texcoords texcoords_for_id(size_t id) const; + + [[maybe_unused]] Vector2ui pixel_size() const { return size_; } + size_t num_tiles() const; + Vector2ub num_tiles2() const { return dims_; } + 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; +}; + + + +} // namespace floormat diff --git a/src/tile-atlas.cpp b/src/tile-atlas.cpp deleted file mode 100644 index 53156a84..00000000 --- a/src/tile-atlas.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "tile-atlas.hpp" -#include "quads.hpp" -#include "compat/assert.hpp" -#include "tile-image.hpp" -#include "compat/exception.hpp" -#include -#include -#include -#include - -namespace floormat { - -using namespace floormat::Quads; - -tile_atlas::tile_atlas(StringView path, StringView name, const ImageView2D& image, Vector2ub tile_count, enum pass_mode p) : - texcoords_{make_texcoords_array(Vector2ui(image.size()), tile_count)}, - path_{path}, name_{name}, size_{image.size()}, dims_{tile_count}, passability{p} -{ - constexpr auto variant_max = std::numeric_limits::max(); - fm_soft_assert(num_tiles() <= variant_max); - fm_soft_assert(dims_[0] > 0 && dims_[1] > 0); - fm_soft_assert(size_ % Vector2ui{tile_count} == Vector2ui()); - tex_.setLabel(path_) - .setWrapping(GL::SamplerWrapping::ClampToEdge) - .setMagnificationFilter(GL::SamplerFilter::Nearest) - .setMinificationFilter(GL::SamplerFilter::Linear) - .setMaxAnisotropy(1) - .setBorderColor(Color4{1, 0, 0, 1}) - .setStorage(1, GL::textureFormat(image.format()), image.size()) - .setSubImage(0, {}, image); -} - -std::array tile_atlas::texcoords_for_id(size_t i) const -{ - fm_assert(i < num_tiles()); - return texcoords_[i]; -} - -auto tile_atlas::make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i) -> texcoords -{ - const auto sz = pixel_size/Vector2ui{tile_count}; - const auto id = Vector2ui{ uint32_t(i % tile_count[0]), uint32_t(i / tile_count[0]) }; - const auto p0 = id * sz; - return texcoords_at(p0, sz, pixel_size); -} - -auto tile_atlas::make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count) -> std::unique_ptr -{ - const size_t N = Vector2ui{tile_count}.product(); - auto ptr = std::make_unique[]>(N); - for (auto i = 0uz; i < N; i++) - ptr[i] = make_texcoords(pixel_size, tile_count, i); - return ptr; -} - -size_t tile_atlas::num_tiles() const { return Vector2ui{dims_}.product(); } -enum pass_mode tile_atlas::pass_mode() const { return passability; } - -} // namespace floormat diff --git a/src/tile-atlas.hpp b/src/tile-atlas.hpp deleted file mode 100644 index a4334b1a..00000000 --- a/src/tile-atlas.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once -#include "src/pass-mode.hpp" -#include "src/quads.hpp" -#include -#include -#include -#include -#include -#include -#include - -namespace floormat { - -class tile_atlas final -{ - using quad = Quads::quad; - using texcoords = std::array; - - static std::unique_ptr make_texcoords_array(Vector2ui pixel_size, Vector2ub tile_count); - static texcoords make_texcoords(Vector2ui pixel_size, Vector2ub tile_count, size_t i); - - std::unique_ptr texcoords_; - GL::Texture2D tex_; - String path_, name_; - Vector2ui size_; - Vector2ub dims_; - enum pass_mode passability; - -public: - tile_atlas(StringView path, StringView name, const ImageView2D& img, Vector2ub tile_count, enum pass_mode pass_mode); - - texcoords texcoords_for_id(size_t id) const; - - [[maybe_unused]] Vector2ui pixel_size() const { return size_; } - size_t num_tiles() const; - Vector2ub num_tiles2() const { return dims_; } - 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; -}; - - - -} // namespace floormat diff --git a/src/tile-image.cpp b/src/tile-image.cpp index 7bfea375..e2d84461 100644 --- a/src/tile-image.cpp +++ b/src/tile-image.cpp @@ -35,8 +35,8 @@ image_ref_& image_ref_::operator=(const Proto& proto return *this; } -template struct image_proto_; -template struct image_ref_; +template struct image_proto_; +template struct image_ref_; template struct image_proto_; template struct image_ref_; diff --git a/src/tile-image.hpp b/src/tile-image.hpp index facf9945..7292c5f0 100644 --- a/src/tile-image.hpp +++ b/src/tile-image.hpp @@ -4,7 +4,7 @@ namespace floormat { -class tile_atlas; +class ground_atlas; class wall_atlas; template @@ -30,8 +30,8 @@ struct image_ref_ final explicit operator bool() const noexcept; }; -using tile_image_proto = image_proto_; -using tile_image_ref = image_ref_; +using tile_image_proto = image_proto_; +using tile_image_ref = image_ref_; using wall_image_proto = image_proto_; using wall_image_ref = image_ref_; diff --git a/src/tile.cpp b/src/tile.cpp index ce21d506..c5eda401 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -18,13 +18,13 @@ wall_image_proto tile_proto::wall_west() const noexcept { return { wall_west_at tile_ref::tile_ref(struct chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {} -std::shared_ptr tile_ref::ground_atlas() noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; } -std::shared_ptr tile_ref::wall_north_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; } -std::shared_ptr tile_ref::wall_west_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+1] : nullptr; } +std::shared_ptr tile_ref::ground_atlas() noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; } +std::shared_ptr tile_ref::wall_north_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; } +std::shared_ptr tile_ref::wall_west_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+1] : nullptr; } -std::shared_ptr tile_ref::ground_atlas() const noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; } -std::shared_ptr tile_ref::wall_north_atlas() const noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; } -std::shared_ptr tile_ref::wall_west_atlas() const noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+1] : nullptr; } +std::shared_ptr tile_ref::ground_atlas() const noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; } +std::shared_ptr tile_ref::wall_north_atlas() const noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; } +std::shared_ptr tile_ref::wall_west_atlas() const noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+1] : nullptr; } tile_image_ref tile_ref::ground() noexcept { _chunk->ensure_alloc_ground(); return {_chunk->_ground->atlases[i], _chunk->_ground->variants[i] }; } wall_image_ref tile_ref::wall_north() noexcept { _chunk->ensure_alloc_walls(); return {_chunk->_walls->atlases[i*2+0], _chunk->_walls->variants[i*2+0] }; } diff --git a/src/tile.hpp b/src/tile.hpp index efdd331b..a195eec4 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -8,7 +8,7 @@ class anim_atlas; struct tile_proto final { - std::shared_ptr ground_atlas; + std::shared_ptr ground_atlas; std::shared_ptr wall_north_atlas, wall_west_atlas; variant_t ground_variant = 0, wall_north_variant = 0, wall_west_variant = 0; @@ -31,13 +31,13 @@ struct tile_ref final wall_image_proto wall_north() const noexcept; wall_image_proto wall_west() const noexcept; - std::shared_ptr ground_atlas() noexcept; - std::shared_ptr wall_north_atlas() noexcept; - std::shared_ptr wall_west_atlas() noexcept; + std::shared_ptr ground_atlas() noexcept; + std::shared_ptr wall_north_atlas() noexcept; + std::shared_ptr wall_west_atlas() noexcept; - std::shared_ptr ground_atlas() const noexcept; - std::shared_ptr wall_north_atlas() const noexcept; - std::shared_ptr wall_west_atlas() const noexcept; + std::shared_ptr ground_atlas() const noexcept; + std::shared_ptr wall_north_atlas() const noexcept; + std::shared_ptr wall_west_atlas() const noexcept; explicit operator tile_proto() const noexcept; diff --git a/test/json.cpp b/test/json.cpp index b0ab9f0f..3d7a5f0f 100644 --- a/test/json.cpp +++ b/test/json.cpp @@ -1,10 +1,10 @@ #include "app.hpp" #include "serialize/tile.hpp" -#include "serialize/tile-atlas.hpp" +#include "serialize/ground-atlas.hpp" #include "serialize/magnum-vector.hpp" #include "serialize/json-helper.hpp" #include "compat/assert.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/tile.hpp" #include "src/tile-iterator.hpp" #include "src/chunk.hpp" @@ -18,9 +18,9 @@ namespace floormat { #if 0 static chunk make_test_chunk() { - auto metal1 = loader.tile_atlas("metal1", {2, 2}, pass_mode::pass), - metal2 = loader.tile_atlas("metal2", {2, 2}, pass_mode::blocked), - tiles = loader.tile_atlas("tiles", {8, 5}, pass_mode::pass); + auto metal1 = loader.ground_atlas("metal1", {2, 2}, pass_mode::pass), + metal2 = loader.ground_atlas("metal2", {2, 2}, pass_mode::blocked), + tiles = loader.ground_atlas("tiles", {8, 5}, pass_mode::pass); constexpr auto N = TILE_MAX_DIM; world w; chunk c{w, {}}; @@ -41,7 +41,7 @@ void test_app::test_json() // NOLINT(readability-convert-member-functions-to-sta fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt"))); const auto output_dir = Path::join(loader.TEMP_PATH, "test/."_s); { - auto atlas = loader.tile_atlas("metal1", {2, 2}, pass_mode::pass); + auto atlas = loader.ground_atlas("metal1", { 2, 2 }, pass_mode::pass); json_helper::to_json(atlas, Path::join(output_dir, "atlas.json")); } { diff --git a/test/loader.cpp b/test/loader.cpp index b45d4f0e..88fa2b32 100644 --- a/test/loader.cpp +++ b/test/loader.cpp @@ -1,16 +1,16 @@ #include "app.hpp" #include "compat/assert.hpp" #include "loader/loader.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "loader/wall-info.hpp" namespace floormat { void test_app::test_loader() { - (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); + (void)loader.ground_atlases("floor.json"); + fm_assert(loader.ground_atlas("texel")->pass_mode() == pass_mode::blocked); + fm_assert(loader.ground_atlas("metal1")->pass_mode() == pass_mode::pass); loader.sceneries(); for (StringView name : loader.anim_atlas_list()) loader.anim_atlas(name); diff --git a/test/serializer.cpp b/test/serializer.cpp index bf31e7f5..c768023e 100644 --- a/test/serializer.cpp +++ b/test/serializer.cpp @@ -4,7 +4,7 @@ #include "src/scenery.hpp" #include "src/critter.hpp" #include "src/light.hpp" -#include "src/tile-atlas.hpp" +#include "src/ground-atlas.hpp" #include "src/anim-atlas.hpp" #include "src/tile-iterator.hpp" #include @@ -18,7 +18,7 @@ chunk& test_app::make_test_chunk(world& w, chunk_coords_ ch) chunk& c = w[ch]; c.mark_modified(); auto metal2 = loader.wall_atlas("empty", false); - auto tiles = loader.tile_atlas("tiles", {8, 5}, pass_mode::pass); + auto tiles = loader.ground_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()) }; -- cgit v1.2.3