diff options
-rw-r--r-- | editor/camera.cpp | 29 | ||||
-rw-r--r-- | editor/imgui.cpp | 25 | ||||
-rw-r--r-- | editor/update.cpp | 6 | ||||
-rw-r--r-- | main/events.cpp | 1 | ||||
-rw-r--r-- | main/main.hpp | 2 |
5 files changed, 37 insertions, 26 deletions
diff --git a/editor/camera.cpp b/editor/camera.cpp index 0ae5a26d..e37bd84d 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -6,42 +6,45 @@ namespace floormat { -void app::do_camera(flota dt) +void app::do_camera(float dt) { - if (keys[key::camera_reset]) + if (_keys[key::camera_reset]) reset_camera_offset(); else { Vector2d dir{}; - if (keys[key::camera_up]) + if (_keys[key::camera_up]) dir += Vector2d{0, -1}; - else if (keys[key::camera_down]) + else if (_keys[key::camera_down]) dir += Vector2d{0, 1}; - if (keys[key::camera_left]) + if (_keys[key::camera_left]) dir += Vector2d{-1, 0}; - else if (keys[key::camera_right]) + else if (_keys[key::camera_right]) dir += Vector2d{1, 0}; if (dir != Vector2d{}) { - constexpr double screens_per_second = 1; - const auto pixels_per_second = windowSize().length() / screens_per_second; - auto camera_offset = _shader.camera_offset(); - const auto max_camera_offset = Vector2d(windowSize() * 10); + auto& shader = M->shader(); + const auto sz = M->window_size(); + constexpr double screens_per_second = 0.75; - camera_offset -= dir.normalized() * dt * pixels_per_second; + const double pixels_per_second = sz.length() / screens_per_second; + auto camera_offset = shader.camera_offset(); + const auto max_camera_offset = Vector2d(sz * 10); + + camera_offset -= dir.normalized() * (double)dt * pixels_per_second; camera_offset[0] = std::clamp(camera_offset[0], -max_camera_offset[0], max_camera_offset[0]); camera_offset[1] = std::clamp(camera_offset[1], -max_camera_offset[1], max_camera_offset[1]); - _shader.set_camera_offset(camera_offset); + shader.set_camera_offset(camera_offset); } else return; } recalc_cursor_tile(); if (cursor.tile) - do_mouse_move(*_cursor_tile); + do_mouse_move(*cursor.tile); } void app::reset_camera_offset() diff --git a/editor/imgui.cpp b/editor/imgui.cpp index a64330e4..f6a3db1e 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -1,4 +1,5 @@ #include "app.hpp" +#include "main/floormat-main.hpp" #include <Magnum/GL/Renderer.h> #include "imgui-raii.hpp" #include <Magnum/ImGuiIntegration/Context.h> @@ -64,12 +65,14 @@ void app::draw_ui() const float main_menu_height = draw_main_menu(); draw_editor_pane(_editor.floor(), main_menu_height); draw_fps(); - draw_cursor_coord(); + draw_cursor_tile(); ImGui::EndFrame(); } -void app::draw_editor_pane(tile_type& type, float main_menu_height) +void app::draw_editor_pane(tile_editor& type, float main_menu_height) { + const auto window_size = M->window_size(); + constexpr Color4 color_perm_selected{1, 1, 1, .7f}, color_selected{1, 0.843f, 0, .8f}, @@ -89,13 +92,13 @@ void app::draw_editor_pane(tile_type& type, float main_menu_height) }; const auto& style = ImGui::GetStyle(); - tile_type* const ed = _editor.current(); + tile_editor* const ed = _editor.current(); if (main_menu_height > 0) { ImGui::SetNextWindowPos({0, main_menu_height+style.WindowPadding.y}); ImGui::SetNextFrameWantCaptureKeyboard(false); - ImGui::SetNextWindowSize({420, windowSize()[1] - main_menu_height - style.WindowPadding.y}); + ImGui::SetNextWindowSize({420, window_size[1] - main_menu_height - style.WindowPadding.y}); if (const auto flags = ImGuiWindowFlags_(ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings); auto b = begin_window({}, flags)) { @@ -192,12 +195,13 @@ void app::draw_fps() auto c5 = push_style_var(ImGuiStyleVar_ScrollbarSize, 0); auto c6 = push_style_color(ImGuiCol_Text, {0, 1, 0, 1}); + const auto frame_time = M->smoothed_dt(); char buf[16]; - const double hz = _frame_time > 1e-6f ? (int)std::round(10./(double)_frame_time + .05) * .1 : 9999; + const double hz = frame_time > 1e-6f ? (int)std::round(10./(double)frame_time + .05) * .1 : 9999; snprintf(buf, sizeof(buf), "%.1f FPS", hz); const ImVec2 size = ImGui::CalcTextSize(buf); - ImGui::SetNextWindowPos({windowSize()[0] - size.x - 4, 3}); + ImGui::SetNextWindowPos({M->window_size()[0] - size.x - 4, 3}); ImGui::SetNextWindowSize(size); if (auto flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs | @@ -208,9 +212,9 @@ void app::draw_fps() } } -void app::draw_cursor_coord() +void app::draw_cursor_tile() { - if (!_cursor_tile) + if (!cursor.tile) return; auto c1 = push_style_var(ImGuiStyleVar_FramePadding, {0, 0}); @@ -221,13 +225,14 @@ void app::draw_cursor_coord() auto c6 = push_style_color(ImGuiCol_Text, {.9f, .9f, .9f, 1}); char buf[64]; - const auto coord = *_cursor_tile; + const auto coord = *cursor.tile; const auto chunk = coord.chunk(); const auto local = coord.local(); snprintf(buf, sizeof(buf), "%hd:%hd - %hhu:%hhu", chunk.x, chunk.y, local.x, local.y); const auto size = ImGui::CalcTextSize(buf); + const auto window_size = M->window_size(); - ImGui::SetNextWindowPos({windowSize()[0]/2 - size.x/2, 3}); + ImGui::SetNextWindowPos({window_size[0]/2 - size.x/2, 3}); ImGui::SetNextWindowSize(size); if (auto flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground; diff --git a/editor/update.cpp b/editor/update.cpp index 579d640e..affcff57 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -1,6 +1,8 @@ #include "app.hpp" #include "src/chunk.hpp" #include "src/tile-atlas.hpp" +#include "main/floormat-events.hpp" +#include "main/floormat-main.hpp" namespace floormat { @@ -29,8 +31,8 @@ void app::make_test_chunk(chunk& c) void app::do_mouse_click(const global_coords pos, int button) { - if (button == mouse_button_event) - _editor.on_click(_world, pos); + if (button == mouse_button_left) + _editor.on_click(M->world(), pos); else _editor.on_release(); } diff --git a/main/events.cpp b/main/events.cpp index 8ab3d997..ef1d4ead 100644 --- a/main/events.cpp +++ b/main/events.cpp @@ -1,4 +1,3 @@ -#pragma once #include "floormat-main.hpp" #include <cstdio> #include <SDL_events.h> diff --git a/main/main.hpp b/main/main.hpp index e11c15f7..aa7671e6 100644 --- a/main/main.hpp +++ b/main/main.hpp @@ -1,5 +1,6 @@ #pragma once +#if 0 #include "floormat.hpp" #include "tile-atlas.hpp" @@ -142,3 +143,4 @@ private: }; } // namespace floormat +#endif |