diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-04-08 12:01:42 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-04-08 12:21:26 +0200 |
commit | 0cd263af59f256da2d2f3a77be264d5e64c1ec5d (patch) | |
tree | f89935707693657ac804aef27c6b188ed66f4d30 | |
parent | d1984938e4f0cbc24b7b8cc6e219fa873d39418a (diff) |
mplement z levels
-rw-r--r-- | draw/anim.cpp | 2 | ||||
-rw-r--r-- | editor/app.cpp | 1 | ||||
-rw-r--r-- | editor/draw.cpp | 29 | ||||
-rw-r--r-- | editor/events.cpp | 1 | ||||
-rw-r--r-- | editor/imgui.cpp | 4 | ||||
-rw-r--r-- | editor/keys.hpp | 2 | ||||
-rw-r--r-- | editor/update.cpp | 2 | ||||
-rw-r--r-- | main/draw.cpp | 27 | ||||
-rw-r--r-- | test/save/quicksave - Copy (0020).dat | bin | 0 -> 1523 bytes | |||
-rw-r--r-- | test/serializer.cpp | 4 |
10 files changed, 41 insertions, 31 deletions
diff --git a/draw/anim.cpp b/draw/anim.cpp index 119bd6c6..2612c110 100644 --- a/draw/anim.cpp +++ b/draw/anim.cpp @@ -44,7 +44,7 @@ void anim_mesh::add_clickable(tile_shader& shader, const Vector2i& win_size, .dest = { offset, offset + Vector2i(f.size) }, .bitmask = a.bitmask(), .e = s_, - .depth = s.ordinal(), + .depth = s.ordinal() + (float)s.coord.z() * TILE_COUNT, .slope = data.slope, .bb_min = data.bb_min, .bb_max = data.bb_max, .stride = a.info().pixel_size[0], diff --git a/editor/app.cpp b/editor/app.cpp index 4293708d..e2632f32 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -90,6 +90,7 @@ void app::reset_world(struct world&& w_) const auto pixel = cursor.pixel; cursor = {}; _character_id = 0; + _render_all_z_levels = true; auto& w = M->reset_world(std::move(w_)); w.collect(true); diff --git a/editor/draw.cpp b/editor/draw.cpp index adbc7b60..c01c149d 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -72,12 +72,13 @@ void app::draw_collision_boxes() auto& world = M->world(); auto& shader = M->shader(); - shader.set_tint({0, .5f, 1, 1}); - using rtree_type = std::decay_t<decltype(*world[chunk_coords{}].rtree())>; using rect_type = typename rtree_type::Rect; for (int8_t z = z_min; z <= z_max; z++) + { + shader.set_tint({0, .5f, 1, 1}); + for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) { @@ -103,19 +104,18 @@ void app::draw_collision_boxes() } } - shader.set_tint({1, 0, 1, 1}); + shader.set_tint({1, 0, 1, 1}); - if (cursor.tile) - { - constexpr auto eps = 1e-6f; - constexpr auto m = TILE_SIZE2 * Vector2(1- eps, 1- eps); - const auto tile_ = Vector2(M->pixel_to_tile_(Vector2d(*cursor.pixel))); - const auto tile = *cursor.tile; - const auto curchunk = Vector2(tile.chunk()), curtile = Vector2(tile.local()); - const auto subpixel_ = Vector2(std::fmod(tile_[0], 1.f), std::fmod(tile_[1], 1.f)); - const auto subpixel = m * Vector2(curchunk[0] < 0 ? 1 + subpixel_[0] : subpixel_[0], - curchunk[1] < 0 ? 1 + subpixel_[1] : subpixel_[1]); - for (int8_t z = z_min; z <= z_max; z++) + if (cursor.tile) + { + constexpr auto eps = 1e-6f; + constexpr auto m = TILE_SIZE2 * Vector2(1- eps, 1- eps); + const auto tile_ = Vector2(M->pixel_to_tile_(Vector2d(*cursor.pixel))); + const auto tile = *cursor.tile; + const auto curchunk = Vector2(tile.chunk()), curtile = Vector2(tile.local()); + const auto subpixel_ = Vector2(std::fmod(tile_[0], 1.f), std::fmod(tile_[1], 1.f)); + const auto subpixel = m * Vector2(curchunk[0] < 0 ? 1 + subpixel_[0] : subpixel_[0], + curchunk[1] < 0 ? 1 + subpixel_[1] : subpixel_[1]); for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) { @@ -144,6 +144,7 @@ void app::draw_collision_boxes() }); } } + } } shader.set_tint({1, 1, 1, 1}); diff --git a/editor/events.cpp b/editor/events.cpp index 275ddf57..18e3a8f6 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -136,6 +136,7 @@ auto app::resolve_keybinding(int k_, int mods_) -> std::tuple<key, int> case SDLK_4: return { key_mode_scenery, mods }; case SDLK_c | ALT: return { key_render_collision_boxes, mods }; case SDLK_l | ALT: return { key_render_clickables, mods }; + case SDLK_t: return { key_render_all_z_levels, mods }; case SDLK_F5: return { key_quicksave, mods }; case SDLK_F9: return { key_quickload, mods }; case SDLK_q | CTRL: return { key_quit, mods }; diff --git a/editor/imgui.cpp b/editor/imgui.cpp index b3863f06..32b85cb8 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -55,7 +55,7 @@ float app::draw_main_menu() const auto* ed_w = _editor.current_tile_editor(); bool b_none = mode == m::none, b_floor = mode == m::floor, b_walls = mode == m::walls, b_scenery = mode == m::scenery, b_collisions = _render_bboxes, - b_clickables = _render_clickables; + b_clickables = _render_clickables, b_all_z_levels = _render_all_z_levels; const bool b_rotate = ed_sc && ed_sc->is_anything_selected() || mode == editor_mode::walls && ed_w && ed_w->is_anything_selected(); ImGui::SeparatorText("Mode"); @@ -75,6 +75,8 @@ float app::draw_main_menu() do_key(key_render_collision_boxes); if (ImGui::MenuItem("Show clickables", "Alt+L", b_clickables)) do_key(key_render_clickables); + if (ImGui::MenuItem("Show all Z levels", "T", b_all_z_levels)) + do_key(key_render_all_z_levels); } main_menu_height = ImGui::GetContentRegionMax().y; diff --git a/editor/keys.hpp b/editor/keys.hpp index 902b6c95..56f4e59e 100644 --- a/editor/keys.hpp +++ b/editor/keys.hpp @@ -18,7 +18,7 @@ enum key : unsigned { key_NO_REPEAT, key_rotate_tile, key_mode_none, key_mode_floor, key_mode_walls, key_mode_scenery, - key_render_collision_boxes, key_render_clickables, + key_render_collision_boxes, key_render_clickables, key_render_all_z_levels, key_GLOBAL, key_new_file, key_quit, diff --git a/editor/update.cpp b/editor/update.cpp index f36b2905..2ab34ccb 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -160,6 +160,8 @@ void app::do_key(key k, int mods) return void(_render_bboxes = !_render_bboxes); case key_render_clickables: return void(_render_clickables = !_render_clickables); + case key_render_all_z_levels: + return void(_render_all_z_levels = !_render_all_z_levels); case key_quicksave: return do_quicksave(); case key_quickload: diff --git a/main/draw.cpp b/main/draw.cpp index 97d12579..44785f61 100644 --- a/main/draw.cpp +++ b/main/draw.cpp @@ -119,7 +119,17 @@ void main_impl::draw_world() noexcept const auto [minx, maxx, miny, maxy] = get_draw_bounds(); const auto sz = window_size(); + _clickable_scenery.clear(); +#ifdef FM_USE_DEPTH32 + framebuffer.fb.clearDepth(0); +#else + GL::defaultFramebuffer.clearDepth(0); +#endif + for (int8_t z = z_min; z <= z_max; z++) + { + GL::Renderer::setDepthMask(false); + for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) { @@ -135,13 +145,9 @@ void main_impl::draw_world() noexcept _floor_mesh.draw(_shader, c); } - GL::Renderer::enable(GL::Renderer::Feature::DepthTest); -#ifdef FM_USE_DEPTH32 - framebuffer.fb.clearDepth(0); -#else - GL::defaultFramebuffer.clearDepth(0); -#endif - for (int8_t z = z_min; z <= z_max; z++) + GL::Renderer::setDepthMask(true); + GL::Renderer::enable(GL::Renderer::Feature::DepthTest); + for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) { @@ -155,11 +161,8 @@ void main_impl::draw_world() noexcept _wall_mesh.draw(_shader, c); } - _clickable_scenery.clear(); - - GL::Renderer::setDepthMask(false); + GL::Renderer::setDepthMask(false); - for (int8_t z = z_min; z <= z_max; z++) for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) { @@ -172,6 +175,7 @@ void main_impl::draw_world() noexcept if (check_chunk_visible(_shader.camera_offset(), sz)) _anim_mesh.draw(_shader, sz, c, _clickable_scenery); } + } GL::Renderer::setDepthMask(true); @@ -224,7 +228,6 @@ void main_impl::drawEvent() _shader.set_tint({1, 1, 1, 1}); { - _shader.set_tint({1, 1, 1, 1}); const auto clear_color = 0x222222ff_rgbaf; #ifdef FM_USE_DEPTH32 framebuffer.fb.clearColor(0, clear_color); diff --git a/test/save/quicksave - Copy (0020).dat b/test/save/quicksave - Copy (0020).dat Binary files differnew file mode 100644 index 00000000..119df03d --- /dev/null +++ b/test/save/quicksave - Copy (0020).dat diff --git a/test/serializer.cpp b/test/serializer.cpp index 8107ad68..02e6fdcc 100644 --- a/test/serializer.cpp +++ b/test/serializer.cpp @@ -14,7 +14,7 @@ namespace Path = Corrade::Utility::Path; namespace { -chunk& make_test_chunk(world& w, chunk_coords ch) +chunk& make_test_chunk(world& w, chunk_coords_ ch) { chunk& c = w[ch]; c.mark_modified(); @@ -87,7 +87,7 @@ void test_serializer(StringView input, StringView tmp) { if (Path::exists(tmp)) Path::remove(tmp); - chunk_coords coord{}; + chunk_coords_ coord{}; world w; if (input) w = world::deserialize(input); |