summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-23 17:31:31 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-23 17:31:31 +0200
commitcce1f768e7399b838a2b865511915bdd576dbbf4 (patch)
tree4c6a8f2dc9112394fd329d56c0f628ce66b16467
parent6b875a0919b9932eca9ed877552c34ecb220b7d8 (diff)
a
-rw-r--r--CMakeLists.txt1
-rw-r--r--compat/defs.hpp8
-rw-r--r--draw/wireframe-mesh.cpp4
-rw-r--r--draw/wireframe-mesh.hpp3
-rw-r--r--editor/CMakeLists.txt14
-rw-r--r--editor/app.cpp0
-rw-r--r--editor/app.hpp0
-rw-r--r--editor/camera.cpp (renamed from main/camera.cpp)0
-rw-r--r--editor/editor.cpp (renamed from main/editor.cpp)0
-rw-r--r--editor/editor.hpp (renamed from main/editor.hpp)0
-rw-r--r--editor/imgui-raii.hpp (renamed from main/imgui-raii.hpp)0
-rw-r--r--editor/imgui.cpp (renamed from main/imgui.cpp)0
-rw-r--r--editor/keyboard.cpp (renamed from main/keyboard.cpp)0
-rw-r--r--editor/update.cpp (renamed from main/update.cpp)0
-rw-r--r--loader/loader-impl.cpp (renamed from main/loader-impl.cpp)4
-rw-r--r--main/CMakeLists.txt16
-rw-r--r--main/debug.cpp10
-rw-r--r--main/draw.cpp14
-rw-r--r--main/events.cpp35
-rw-r--r--main/floormat-app.cpp8
-rw-r--r--main/floormat-app.hpp44
-rw-r--r--main/floormat-events.cpp100
-rw-r--r--main/floormat-main-impl.cpp106
-rw-r--r--main/floormat-main-impl.hpp66
-rw-r--r--main/floormat-main.hpp35
-rw-r--r--main/floormat.hpp30
-rw-r--r--main/main.cpp (renamed from main/app.cpp)14
-rw-r--r--main/main.hpp (renamed from main/app.hpp)14
-rw-r--r--src/CMakeLists.txt10
-rw-r--r--test/CMakeLists.txt4
-rw-r--r--test/app.hpp6
-rw-r--r--test/const-math.cpp4
-rw-r--r--test/json.cpp2
-rw-r--r--test/main.cpp8
-rw-r--r--test/tile-iter.cpp2
35 files changed, 478 insertions, 84 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fc6fa890..e510ceb5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -136,6 +136,7 @@ include_directories(SYSTEM
add_subdirectory(src)
add_subdirectory(main)
+add_subdirectory(editor)
add_subdirectory(anim-crop-tool)
add_subdirectory(test)
diff --git a/compat/defs.hpp b/compat/defs.hpp
index de922df2..e4b92260 100644
--- a/compat/defs.hpp
+++ b/compat/defs.hpp
@@ -25,8 +25,12 @@
type& operator=(const type&) = delete
#define fm_DECLARE_DELETED_MOVE_ASSIGNMENT(type) \
- [[deprecated]] type(type&&) = delete; \
- [[deprecated]] type& operator=(type&&) = delete
+ type(type&&) = delete; \
+ type& operator=(type&&) = delete
+
+#define fm_DECLARE_DEPRECATED_MOVE_ASSIGNMENT(type) \
+ [[deprecated]] type(type&&) = default; \
+ [[deprecated]] type& operator=(type&&) = default
#define fm_DECLARE_DEFAULT_MOVE_ASSIGNMENT(type) \
constexpr type(type&&) noexcept = default; \
diff --git a/draw/wireframe-mesh.cpp b/draw/wireframe-mesh.cpp
index b0ba7676..3fc53c6c 100644
--- a/draw/wireframe-mesh.cpp
+++ b/draw/wireframe-mesh.cpp
@@ -46,5 +46,9 @@ void mesh_base::draw(tile_shader& shader)
shader.draw(_mesh);
}
+void mesh_base::set_subdata(Containers::ArrayView<const void> array)
+{
+ _vertex_buffer.setSubData(0, array);
+}
} // namespace floormat::wireframe
diff --git a/draw/wireframe-mesh.hpp b/draw/wireframe-mesh.hpp
index 67b35ecd..9a8e90c7 100644
--- a/draw/wireframe-mesh.hpp
+++ b/draw/wireframe-mesh.hpp
@@ -36,6 +36,7 @@ struct mesh_base
mesh_base(GL::MeshPrimitive primitive, Containers::ArrayView<const void> index_data,
std::size_t num_vertices, std::size_t num_indexes);
void draw(tile_shader& shader);
+ void set_subdata(Containers::ArrayView<const void> array);
};
} // namespace wireframe
@@ -56,7 +57,7 @@ wireframe_mesh<T>::wireframe_mesh() :
template <wireframe::traits T> void wireframe_mesh<T>::draw(tile_shader& shader, T x)
{
//_vertex_buffer.setData({nullptr, sizeof(Vector3) * T::num_vertices}, GL::BufferUsage::DynamicDraw); // orphan the buffer
- _vertex_buffer.setSubData(0, x.make_vertex_array());
+ set_subdata(x.make_vertex_array());
x.on_draw();
mesh_base::draw(shader);
}
diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt
new file mode 100644
index 00000000..8d3a0bf5
--- /dev/null
+++ b/editor/CMakeLists.txt
@@ -0,0 +1,14 @@
+set(self ${PROJECT_NAME}-editor)
+
+corrade_add_resource(res ../resources.conf)
+
+if(MSVC)
+ set_property(SOURCE "${res}" APPEND PROPERTY COMPILE_OPTIONS "-W0")
+else()
+ set_property(SOURCE "${res}" APPEND PROPERTY COMPILE_OPTIONS "-w")
+endif()
+
+add_executable(${self} "${res}" "../loader/loader-impl.cpp")
+target_link_libraries(${self} ${PROJECT_NAME}-main)
+
+install(TARGETS ${self} RUNTIME DESTINATION bin)
diff --git a/editor/app.cpp b/editor/app.cpp
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/editor/app.cpp
diff --git a/editor/app.hpp b/editor/app.hpp
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/editor/app.hpp
diff --git a/main/camera.cpp b/editor/camera.cpp
index 7af77211..7af77211 100644
--- a/main/camera.cpp
+++ b/editor/camera.cpp
diff --git a/main/editor.cpp b/editor/editor.cpp
index f3c8b157..f3c8b157 100644
--- a/main/editor.cpp
+++ b/editor/editor.cpp
diff --git a/main/editor.hpp b/editor/editor.hpp
index 28ba153c..28ba153c 100644
--- a/main/editor.hpp
+++ b/editor/editor.hpp
diff --git a/main/imgui-raii.hpp b/editor/imgui-raii.hpp
index afae29d6..afae29d6 100644
--- a/main/imgui-raii.hpp
+++ b/editor/imgui-raii.hpp
diff --git a/main/imgui.cpp b/editor/imgui.cpp
index b0777d5d..b0777d5d 100644
--- a/main/imgui.cpp
+++ b/editor/imgui.cpp
diff --git a/main/keyboard.cpp b/editor/keyboard.cpp
index a700d0f4..a700d0f4 100644
--- a/main/keyboard.cpp
+++ b/editor/keyboard.cpp
diff --git a/main/update.cpp b/editor/update.cpp
index ebd1881b..ebd1881b 100644
--- a/main/update.cpp
+++ b/editor/update.cpp
diff --git a/main/loader-impl.cpp b/loader/loader-impl.cpp
index 5cbe1759..def67c1b 100644
--- a/main/loader-impl.cpp
+++ b/loader/loader-impl.cpp
@@ -1,5 +1,5 @@
-#include "loader.hpp"
-#include "tile-atlas.hpp"
+#include "src/loader.hpp"
+#include "src/tile-atlas.hpp"
#include "compat/assert.hpp"
#include "compat/alloca.hpp"
#include <filesystem>
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index e567dee2..81a67fee 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -1,22 +1,12 @@
-set(self "${PROJECT_NAME}-main")
file(GLOB sources "*.cpp" CONFIGURE_ARGS)
link_libraries(${PROJECT_NAME})
link_libraries(Magnum::Sdl2Application Magnum::Trade)
link_libraries(MagnumIntegration::ImGui)
-corrade_add_resource(res ../resources.conf)
-if(MSVC)
- set_property(SOURCE "${res}" APPEND PROPERTY COMPILE_OPTIONS "-W0")
-else()
- set_property(SOURCE "${res}" APPEND PROPERTY COMPILE_OPTIONS "-w")
-endif()
-add_library(${self}-lib STATIC "${sources}")
-add_executable(${self} "${res}")
-target_link_libraries(${self} ${self}-lib)
-set_property(TARGET ${self} PROPERTY OUTPUT_NAME "${PROJECT_NAME}")
-install(TARGETS ${self} RUNTIME DESTINATION bin)
+add_library(${PROJECT_NAME}-main STATIC "${sources}")
if(FLOORMAT_PRECOMPILED-HEADERS)
- target_precompile_headers(${self} PRIVATE precomp.hpp)
+ target_precompile_headers(${PROJECT_NAME}-main PRIVATE precomp.hpp)
endif()
+
diff --git a/main/debug.cpp b/main/debug.cpp
index 3383948b..4ce4a3b0 100644
--- a/main/debug.cpp
+++ b/main/debug.cpp
@@ -1,4 +1,4 @@
-#include "app.hpp"
+#include "main.hpp"
#include <chrono>
#include <Magnum/GL/Renderer.h>
@@ -12,7 +12,7 @@ using GL::Renderer;
using GL::DebugOutput;
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
-void app::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
+void floormat::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
Severity severity, const std::string& str) const
{
static thread_local auto clock = std::chrono::steady_clock{};
@@ -58,13 +58,13 @@ void app::debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type
std::fputs("", stdout); // put breakpoint here
}
-void app::_debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
+void floormat::_debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
GL::DebugOutput::Severity severity, const std::string& str, const void* self)
{
- static_cast<const app*>(self)->debug_callback(src, type, id, severity, str);
+ static_cast<const floormat*>(self)->debug_callback(src, type, id, severity, str);
}
-void* app::register_debug_callback()
+void* floormat::register_debug_callback()
{
GL::DebugOutput::setCallback(_debug_callback, this);
diff --git a/main/draw.cpp b/main/draw.cpp
index b2e0a637..cc9e85d3 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -1,4 +1,4 @@
-#include "app.hpp"
+#include "main.hpp"
#include "tile-defs.hpp"
#include "camera-offset.hpp"
#include <Magnum/GL/DefaultFramebuffer.h>
@@ -8,7 +8,7 @@
namespace floormat {
-void app::drawEvent()
+void floormat::drawEvent()
{
if (const float dt = timeline.previousFrameDuration(); dt > 0)
{
@@ -50,14 +50,14 @@ void app::drawEvent()
timeline.nextFrame();
}
-void app::draw_msaa()
+void floormat::draw_msaa()
{
const with_shifted_camera_offset o{_shader, BASE_X, BASE_Y};
draw_world();
draw_cursor_tile();
}
-void app::draw_world()
+void floormat::draw_world()
{
auto foo = get_draw_bounds();
auto [minx, maxx, miny, maxy] = foo;
@@ -83,7 +83,7 @@ void app::draw_world()
}
}
-void app::draw_wireframe_quad(global_coords pos)
+void floormat::draw_wireframe_quad(global_coords pos)
{
constexpr float LINE_WIDTH = 2;
const auto pt = pos.to_signed();
@@ -96,7 +96,7 @@ void app::draw_wireframe_quad(global_coords pos)
}
}
-void app::draw_wireframe_box(local_coords pt)
+void floormat::draw_wireframe_box(local_coords pt)
{
constexpr float LINE_WIDTH = 1.5;
@@ -107,7 +107,7 @@ void app::draw_wireframe_box(local_coords pt)
_wireframe_box.draw(_shader, {center1, size, LINE_WIDTH});
}
-void app::draw_cursor_tile()
+void floormat::draw_cursor_tile()
{
if (_cursor_tile && !_cursor_in_imgui)
draw_wireframe_quad(*_cursor_tile);
diff --git a/main/events.cpp b/main/events.cpp
index 83362bfe..989406ba 100644
--- a/main/events.cpp
+++ b/main/events.cpp
@@ -1,20 +1,18 @@
#pragma once
-#include "app.hpp"
-#include <Magnum/ImGuiIntegration/Context.hpp>
-
+#include "floormat-main.hpp"
#include <cstdio>
#include <SDL_events.h>
#include <SDL_video.h>
namespace floormat {
-void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
+void main_impl::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
{
fm_assert(event.framebufferSize() == event.windowSize());
recalc_viewport(event.windowSize());
}
-void app::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)
+void main_impl::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)
{
if (_imgui.handleMousePressEvent(event))
return event.setAccepted();
@@ -25,14 +23,14 @@ void app::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)
}
}
-void app::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event)
+void main_impl::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event)
{
if (_imgui.handleMouseReleaseEvent(event))
return event.setAccepted();
do_mouse_release((int)event.button());
}
-void app::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event)
+void main_impl::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event)
{
_cursor_in_imgui = _imgui.handleMouseMoveEvent(event);
if (_cursor_in_imgui)
@@ -44,13 +42,13 @@ void app::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event)
do_mouse_move(*_cursor_tile);
}
-void app::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event)
+void main_impl::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event)
{
if (_imgui.handleMouseScrollEvent(event))
return event.setAccepted();
}
-void app::textInputEvent(Platform::Sdl2Application::TextInputEvent& event)
+void main_impl::textInputEvent(Platform::Sdl2Application::TextInputEvent& event)
{
if (_imgui.handleTextInputEvent(event))
{
@@ -59,7 +57,7 @@ void app::textInputEvent(Platform::Sdl2Application::TextInputEvent& event)
}
}
-void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
+void main_impl::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
{
if (_imgui.handleKeyPressEvent(event))
{
@@ -69,7 +67,7 @@ void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
do_key(event.key(), event.modifiers(), true, event.isRepeated());
}
-void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
+void main_impl::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
{
if (_imgui.handleKeyReleaseEvent(event))
{
@@ -79,7 +77,7 @@ void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
do_key(event.key(), event.modifiers(), false, false);
}
-void app::anyEvent(SDL_Event& event)
+void main_impl::anyEvent(SDL_Event& event)
{
if (event.type == SDL_WINDOWEVENT)
switch (event.window.event)
@@ -97,25 +95,16 @@ void app::anyEvent(SDL_Event& event)
}
}
-void app::event_focus_out()
+void main_impl::event_focus_out() // TODO move to app
{
_cursor_pixel = std::nullopt;
recalc_cursor_tile();
}
-void app::event_focus_in()
-{
-}
-
-void app::event_mouse_leave()
+void main_impl::event_mouse_leave() // TODO move to app
{
_cursor_pixel = std::nullopt;
recalc_cursor_tile();
}
-void app::event_mouse_enter()
-{
-}
-
-
} // namespace floormat
diff --git a/main/floormat-app.cpp b/main/floormat-app.cpp
new file mode 100644
index 00000000..c16bbf4b
--- /dev/null
+++ b/main/floormat-app.cpp
@@ -0,0 +1,8 @@
+#include "floormat-app.hpp"
+
+namespace floormat {
+
+floormat_app::floormat_app() noexcept = default;
+floormat_app::~floormat_app() noexcept = default;
+
+} // namespace floormat
diff --git a/main/floormat-app.hpp b/main/floormat-app.hpp
new file mode 100644
index 00000000..f5e57c6e
--- /dev/null
+++ b/main/floormat-app.hpp
@@ -0,0 +1,44 @@
+#pragma once
+#include "compat/defs.hpp"
+
+namespace Magnum::Math { template<typename T> class Vector2; }
+
+namespace floormat {
+
+struct mouse_move_event;
+struct mouse_button_event;
+struct mouse_scroll_event;
+struct key_event;
+struct text_input_event;
+struct any_event;
+
+struct floormat_app
+{
+ floormat_app() noexcept;
+ virtual ~floormat_app() noexcept;
+
+ fm_DECLARE_DELETED_COPY_ASSIGNMENT(floormat_app);
+ fm_DECLARE_DEPRECATED_MOVE_ASSIGNMENT(floormat_app);
+
+ virtual void update(double dt) = 0;
+ virtual void draw_msaa();
+ virtual void draw() = 0;
+
+ virtual bool on_mouse_move(const mouse_move_event& event) noexcept = 0;
+ virtual bool on_mouse_down(const mouse_button_event& event) noexcept = 0;
+ virtual bool on_mouse_up(const mouse_button_event& event) noexcept = 0;
+ virtual bool on_mouse_scroll(const mouse_scroll_event& event) noexcept = 0;
+ virtual bool on_key_down(const key_event& event) noexcept = 0;
+ virtual bool on_key_up(const key_event& event) noexcept = 0;
+ virtual bool on_text_input_event(const text_input_event& event) noexcept = 0;
+ virtual void on_viewport_event(const Magnum::Math::Vector2<int>& size) noexcept = 0;
+ virtual bool on_any_event(const any_event& event) noexcept = 0;
+ virtual void on_focus_in() noexcept = 0;
+ virtual void on_focus_out() noexcept = 0;
+ virtual void on_mouse_leave() noexcept = 0;
+ virtual void on_mouse_enter() noexcept = 0;
+};
+
+inline void floormat_app::draw_msaa() {}
+
+} // namespace floormat
diff --git a/main/floormat-events.cpp b/main/floormat-events.cpp
new file mode 100644
index 00000000..55fb7a91
--- /dev/null
+++ b/main/floormat-events.cpp
@@ -0,0 +1,100 @@
+#pragma once
+#include "floormat-main.hpp"
+#include "compat/assert.hpp"
+#include <SDL_events.h>
+#include <SDL_video.h>
+
+namespace floormat {
+
+void main_impl::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
+{
+ fm_assert(event.framebufferSize() == event.windowSize());
+ recalc_viewport(event.windowSize());
+ app.viewport_event(event.windowSize());
+}
+
+void main_impl::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)
+{
+ if (app.)
+ if (_imgui.handleMousePressEvent(event))
+ return event.setAccepted();
+ else if (_cursor_tile)
+ {
+ const auto& tile = *_cursor_tile;
+ do_mouse_click(tile, (int)event.button());
+ }
+}
+
+void main_impl::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event)
+{
+ if (_imgui.handleMouseReleaseEvent(event))
+ return event.setAccepted();
+ do_mouse_release((int)event.button());
+}
+
+void main_impl::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event)
+{
+ _cursor_in_imgui = _imgui.handleMouseMoveEvent(event);
+ if (_cursor_in_imgui)
+ _cursor_pixel = std::nullopt;
+ else
+ _cursor_pixel = event.position();
+ recalc_cursor_tile();
+ if (_cursor_tile)
+ do_mouse_move(*_cursor_tile);
+}
+
+void main_impl::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event)
+{
+ if (_imgui.handleMouseScrollEvent(event))
+ return event.setAccepted();
+}
+
+void main_impl::textInputEvent(Platform::Sdl2Application::TextInputEvent& event)
+{
+ if (_imgui.handleTextInputEvent(event))
+ {
+ keys = {};
+ event.setAccepted();
+ }
+}
+
+void main_impl::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
+{
+ if (_imgui.handleKeyPressEvent(event))
+ {
+ keys = {};
+ return event.setAccepted();
+ }
+ do_key(event.key(), event.modifiers(), true, event.isRepeated());
+}
+
+void main_impl::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
+{
+ if (_imgui.handleKeyReleaseEvent(event))
+ {
+ keys = {};
+ return event.setAccepted();
+ }
+ do_key(event.key(), event.modifiers(), false, false);
+}
+
+void main_impl::anyEvent(SDL_Event& event)
+{
+ if (event.type == SDL_WINDOWEVENT)
+ switch (event.window.event)
+ {
+ case SDL_WINDOWEVENT_FOCUS_LOST:
+ return app.event_focus_out();
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
+ return app.event_focus_in();
+ case SDL_WINDOWEVENT_LEAVE:
+ return app.event_mouse_leave();
+ case SDL_WINDOWEVENT_ENTER:
+ return app.event_mouse_enter();
+ default:
+ std::fputs("", stdout); break; // put breakpoint here
+ }
+}
+} // namespace floormat
+
diff --git a/main/floormat-main-impl.cpp b/main/floormat-main-impl.cpp
new file mode 100644
index 00000000..56c19882
--- /dev/null
+++ b/main/floormat-main-impl.cpp
@@ -0,0 +1,106 @@
+#include "floormat-main-impl.hpp"
+#include "floormat.hpp"
+#include "floormat-app.hpp"
+#include "compat/assert.hpp"
+#include "compat/fpu.hpp"
+
+namespace floormat {
+
+floormat_main::floormat_main() noexcept = default;
+floormat_main::~floormat_main() noexcept = default;
+
+static const char* const fm_fake_argv[] = { "floormat", nullptr };
+
+auto main_impl::make_window_flags(const fm_options& s) -> Configuration::WindowFlags
+{
+ using flag = Configuration::WindowFlag;
+ Configuration::WindowFlags flags{};
+ if (s.resizable)
+ flags |= flag::Resizable;
+ if (s.fullscreen)
+ flags |= flag::Fullscreen;
+ if (s.fullscreen_desktop)
+ flags |= flag::FullscreenDesktop;
+ if (s.borderless)
+ flags |= flag::Borderless;
+ if (s.maximized)
+ flags |= flag::Maximized;
+ return flags;
+}
+
+void main_impl::recalc_viewport(Vector2i size)
+{
+ GL::defaultFramebuffer.setViewport({{}, size });
+#ifdef FM_MSAA
+ _msaa_framebuffer.detach(GL::Framebuffer::ColorAttachment{0});
+ _msaa_renderbuffer = Magnum::GL::Renderbuffer{};
+ _msaa_renderbuffer.setStorageMultisample(s.msaa_samples, GL::RenderbufferFormat::RGBA8, size);
+ _msaa_framebuffer.setViewport({{}, size });
+ _msaa_framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, _msaa_renderbuffer);
+#endif
+ _shader.set_scale(Vector2(size));
+ app.on_viewport_event(size);
+ setMinimalLoopPeriod(5);
+}
+
+auto main_impl::make_conf(const fm_options& s) -> Configuration
+{
+ return Configuration{}
+ .setTitle(s.title)
+ .setSize(s.resolution)
+ .setWindowFlags(make_window_flags(s));
+}
+
+main_impl::main_impl(floormat_app& app, const fm_options& s) :
+ Platform::Sdl2Application{Arguments{fake_argc, fm_fake_argv},
+ make_conf(s), make_gl_conf(s)},
+ app{app}, s{s}
+{
+ switch (s.vsync)
+ {
+ case fm_tristate::on:
+ (void)setSwapInterval(1);
+ if (const auto list = GL::Context::current().extensionStrings();
+ std::find(list.cbegin(), list.cend(), "EXT_swap_control_tear") != list.cbegin())
+ (void)setSwapInterval(-1);
+ break;
+ case fm_tristate::off:
+ setSwapInterval(0);
+ break;
+ default: break;
+ }
+ set_fp_mask();
+ fm_assert(framebufferSize() == windowSize());
+ recalc_viewport(windowSize());
+ timeline.start();
+}
+
+main_impl::~main_impl() = default;
+
+void main_impl::drawEvent()
+{
+ if (const float dt = timeline.previousFrameDuration(); dt > 0)
+ {
+ constexpr float RC = 0.1f;
+ const float alpha = dt/(dt + RC);
+
+ _frame_time = _frame_time*(1-alpha) + alpha*dt;
+ }
+ else
+ swapBuffers();
+ timeline.nextFrame();
+
+ const auto dt = std::clamp((double)timeline.previousFrameDuration(), 1e-6, 1e-1);
+ app.update(dt);
+
+ _shader.set_tint({1, 1, 1, 1});
+}
+
+floormat_main* floormat_main::create(floormat_app& app, const fm_options& options)
+{
+ auto* ret = new main_impl(app, options);
+ fm_assert(ret);
+ return ret;
+}
+
+} // namespace floormat
diff --git a/main/floormat-main-impl.hpp b/main/floormat-main-impl.hpp
new file mode 100644
index 00000000..e0cb0747
--- /dev/null
+++ b/main/floormat-main-impl.hpp
@@ -0,0 +1,66 @@
+#pragma once
+#include "floormat.hpp"
+#include "floormat-main.hpp"
+#include "shaders/tile-shader.hpp"
+#include <Corrade/Containers/String.h>
+#include <Magnum/GL/RenderbufferFormat.h>
+#include <Magnum/Platform/Sdl2Application.h>
+
+#define FM_MSAA
+
+namespace floormat {
+
+struct floormat_app;
+
+struct main_impl final : Platform::Sdl2Application, floormat_main
+{
+ main_impl(floormat_app& app, const fm_options& opts);
+ ~main_impl() override;
+
+ void quit(int status) override;
+
+ Magnum::Math::Vector2<int> window_size() const noexcept override;
+ tile_shader& shader() noexcept override;
+ void register_debug_callback() noexcept override;
+
+ struct world& world() noexcept override;
+ SDL_Window* window() noexcept override;
+ float smoothed_dt() const noexcept override;
+
+ [[maybe_unused]] void viewportEvent(ViewportEvent& event) override;
+ [[maybe_unused]] void mousePressEvent(MouseEvent& event) override;
+ [[maybe_unused]] void mouseReleaseEvent(MouseEvent& event) override;
+ [[maybe_unused]] void mouseMoveEvent(MouseMoveEvent& event) override;
+ [[maybe_unused]] void mouseScrollEvent(MouseScrollEvent& event) override;
+ [[maybe_unused]] void textInputEvent(TextInputEvent& event) override;
+ [[maybe_unused]] void keyPressEvent(KeyEvent& event) override;
+ [[maybe_unused]] void keyReleaseEvent(KeyEvent& event) override;
+ [[maybe_unused]] void anyEvent(SDL_Event& event) override;
+ void drawEvent() override;
+
+private:
+ float _frame_time = 0;
+ floormat_app& app;
+ fm_options s;
+ tile_shader _shader;
+ Magnum::Timeline timeline;
+ int fake_argc = 1;
+
+#ifdef FM_MSAA
+ GL::Framebuffer _msaa_framebuffer{{{}, windowSize()}};
+ GL::Renderbuffer _msaa_renderbuffer{};
+#endif
+
+ void recalc_viewport(Vector2i size);
+
+ void debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
+ GL::DebugOutput::Severity severity, const std::string& str) const;
+ static void _debug_callback(GL::DebugOutput::Source src, GL::DebugOutput::Type type, UnsignedInt id,
+ GL::DebugOutput::Severity severity, const std::string& str, const void* self);
+
+ static Configuration make_conf(const fm_options& s);
+ static GLConfiguration make_gl_conf(const fm_options& s);
+ static Configuration::WindowFlags make_window_flags(const fm_options& s);
+};
+
+} // namespace floormat
diff --git a/main/floormat-main.hpp b/main/floormat-main.hpp
new file mode 100644
index 00000000..5f0635cc
--- /dev/null
+++ b/main/floormat-main.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "floormat.hpp"
+#include <Magnum/Math/Vector2.h>
+
+struct SDL_Window;
+
+namespace floormat {
+
+struct floormat_app;
+struct tile_shader;
+struct world;
+
+struct floormat_main
+{
+ floormat_main() noexcept;
+ virtual ~floormat_main() noexcept;
+
+ fm_DECLARE_DELETED_COPY_ASSIGNMENT(floormat_main);
+ fm_DECLARE_DEPRECATED_MOVE_ASSIGNMENT(floormat_main);
+
+ virtual void quit(int status) = 0;
+
+ virtual Magnum::Math::Vector2<int> window_size() const noexcept = 0;
+ virtual float smoothed_dt() const noexcept = 0;
+ virtual tile_shader& shader() noexcept = 0;
+ virtual void register_debug_callback() noexcept = 0;
+
+ virtual world& world() noexcept = 0;
+ virtual SDL_Window* window() noexcept = 0;
+
+ static floormat_main* create(floormat_app& app, const fm_options& options);
+};
+
+} // namespace floormat
diff --git a/main/floormat.hpp b/main/floormat.hpp
new file mode 100644
index 00000000..49b7ec76
--- /dev/null
+++ b/main/floormat.hpp
@@ -0,0 +1,30 @@
+#pragma once
+#include <cstdint>
+#include <Corrade/Containers/String.h>
+#include <Magnum/Math/Vector2.h>
+
+namespace floormat {
+
+enum class fm_gpu_debug : char { no_error = -1, on, off };
+enum class fm_tristate : char { maybe = -1, on, off };
+enum class fm_log_level : unsigned char { quiet, normal, verbose, };
+
+struct fm_options final
+{
+ Magnum::Math::Vector2<int> resolution{1024, 768};
+ Containers::String title{"Test"};
+ Containers::String disabled_extensions; // TODO
+ std::uint8_t msaa_samples = 4;
+ fm_tristate vsync = fm_tristate::maybe;
+ fm_gpu_debug gpu_debug = fm_gpu_debug::on; // TODO
+ fm_log_level log_level = fm_log_level::normal; // TODO
+ std::uint8_t resizable : 1 = true,
+ fullscreen : 1 = false,
+ fullscreen_desktop : 1 = false,
+ borderless : 1 = false,
+ maximized : 1 = false,
+ msaa : 1 = true; // TODO
+};
+
+} // namespace floormat
+
diff --git a/main/app.cpp b/main/main.cpp
index d6593227..37e7164b 100644
--- a/main/app.cpp
+++ b/main/main.cpp
@@ -1,6 +1,6 @@
#include <cstddef>
#include "compat/sysexits.hpp"
-#include "app.hpp"
+#include "main.hpp"
#include "compat/fpu.hpp"
#include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/DebugStl.h>
@@ -12,7 +12,7 @@
namespace floormat {
-int app::run_from_argv(int argc, char** argv)
+int floormat::run_from_argv(int argc, char** argv)
{
Corrade::Utility::Arguments args{};
app_settings opts;
@@ -20,17 +20,17 @@ int app::run_from_argv(int argc, char** argv)
.addOption("vsync", opts.vsync ? "1" : "0")
.parse(argc, argv);
opts.vsync = args.value<bool>("vsync");
- app x{{argc, argv}, std::move(opts)}; // NOLINT(performance-move-const-arg)
+ floormat x{{argc, argv}, std::move(opts)}; // NOLINT(performance-move-const-arg)
return x.exec();
}
-void app::usage(const Utility::Arguments& args)
+void floormat::usage(const Utility::Arguments& args)
{
Error{Error::Flag::NoNewlineAtTheEnd} << args.usage();
std::exit(EX_USAGE); // NOLINT(concurrency-mt-unsafe)
}
-app::app(const Arguments& arguments, app_settings opts):
+floormat::floormat(const Arguments& arguments, app_settings opts):
Platform::Sdl2Application{
arguments,
Configuration{}
@@ -67,7 +67,7 @@ app::app(const Arguments& arguments, app_settings opts):
timeline.start();
}
-void app::recalc_viewport(Vector2i size)
+void floormat::recalc_viewport(Vector2i size)
{
_shader.set_scale(Vector2(size));
init_imgui(size);
@@ -88,7 +88,7 @@ void app::recalc_viewport(Vector2i size)
int main(int argc, char** argv)
{
- return floormat::app::run_from_argv(argc, argv);
+ return floormat::floormat::run_from_argv(argc, argv);
}
#ifdef _MSC_VER
diff --git a/main/app.hpp b/main/main.hpp
index 8970aa15..98552a7c 100644
--- a/main/app.hpp
+++ b/main/main.hpp
@@ -1,6 +1,9 @@
#pragma once
+
+#include "floormat.hpp"
+
#include "tile-atlas.hpp"
-#include "chunk.hpp"
+#include "src/chunk.hpp"
#include "shaders/tile-shader.hpp"
#include "src/loader.hpp"
#include "draw/floor-mesh.hpp"
@@ -9,8 +12,7 @@
#include "draw/wireframe-quad.hpp"
#include "draw/wireframe-box.hpp"
#include "compat/enum-bitset.hpp"
-#include "editor.hpp"
-#include "world.hpp"
+#include "src/world.hpp"
#include <Magnum/Timeline.h>
#include <Magnum/GL/DebugOutput.h>
#include <Magnum/Platform/Sdl2Application.h>
@@ -26,16 +28,16 @@
namespace floormat {
-struct app final : private Platform::Sdl2Application
+struct floormat final : private Platform::Sdl2Application
{
static int run_from_argv(int argc, char** argv);
- virtual ~app();
+ virtual ~floormat();
private:
struct app_settings;
[[maybe_unused]] [[noreturn]] static void usage(const Utility::Arguments& args);
- explicit app(const Arguments& arguments, app_settings opts);
+ explicit floormat(const Arguments& arguments, app_settings opts);
using dpi_policy = Platform::Implementation::Sdl2DpiScalingPolicy;
using tile_atlas_ = std::shared_ptr<tile_atlas>;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fa5112aa..413290b5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -2,11 +2,11 @@ set(self ${PROJECT_NAME})
file(GLOB sources "*.cpp" "../shaders/*.cpp" "../serialize/*.cpp" "../draw/*.cpp" CONFIGURE_ARGS)
add_library(${self} STATIC "${sources}")
target_link_libraries(
- ${self} PUBLIC
- Magnum::GL
- Magnum::Magnum
- Magnum::Shaders
- nlohmann_json::nlohmann_json
+ ${self} PUBLIC
+ Magnum::GL
+ Magnum::Magnum
+ Magnum::Shaders
+ nlohmann_json::nlohmann_json
)
if(FLOORMAT_PRECOMPILED-HEADERS)
target_precompile_headers(${self} PRIVATE precomp.hpp)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 981a99a2..ea0009f8 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -6,6 +6,6 @@ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/test")
link_libraries(${PROJECT_NAME})
link_libraries(Magnum::WindowlessWglApplication Magnum::Trade)
-#add_executable(${self} "${sources}" "../main/loader-impl.cpp")
-add_library(${self} STATIC "${sources}" "../main/loader-impl.cpp")
+#add_executable(${self} "${sources}" "../loader/loader-impl.cpp")
+add_library(${self} STATIC "${sources}" "../loader/loader-impl.cpp")
install(TARGETS ${self} RUNTIME DESTINATION bin)
diff --git a/test/app.hpp b/test/app.hpp
index 4647001e..943e53a3 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -2,10 +2,10 @@
#include <Magnum/Magnum.h>
#include <Magnum/Platform/WindowlessWglApplication.h>
namespace floormat {
-struct app final : Platform::WindowlessWglApplication // NOLINT(cppcoreguidelines-virtual-class-destructor)
+struct floormat final : Platform::WindowlessWglApplication // NOLINT(cppcoreguidelines-virtual-class-destructor)
{
- explicit app(const Arguments& arguments);
- ~app();
+ explicit floormat(const Arguments& arguments);
+ ~floormat();
int exec() override;
static bool test_json();
static bool test_tile_iter();
diff --git a/test/const-math.cpp b/test/const-math.cpp
index 63baff4d..1ea4c2f0 100644
--- a/test/const-math.cpp
+++ b/test/const-math.cpp
@@ -61,7 +61,7 @@ static constexpr void* compile_tests()
namespace floormat {
-bool app::test_const_math()
+bool floormat::test_const_math()
{
static_assert(compile_tests() == nullptr);
return true;
@@ -73,5 +73,5 @@ bool app::test_const_math()
# pragma GCC diagnostic pop
#endif
#else
-namespace floormat { bool app::test_const_math() { return true; } }
+namespace floormat { bool floormat::test_const_math() { return true; } }
#endif
diff --git a/test/json.cpp b/test/json.cpp
index 6684f404..198f2d48 100644
--- a/test/json.cpp
+++ b/test/json.cpp
@@ -29,7 +29,7 @@ static chunk make_test_chunk()
return c;
}
-bool app::test_json() // NOLINT(readability-convert-member-functions-to-static)
+bool floormat::test_json() // NOLINT(readability-convert-member-functions-to-static)
{
const std::filesystem::path output_dir = "../test/.";
{
diff --git a/test/main.cpp b/test/main.cpp
index 8e053d23..75e2950f 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -9,7 +9,7 @@
namespace floormat {
-app::app(const Arguments& arguments):
+floormat::floormat(const Arguments& arguments):
Platform::WindowlessWglApplication{
arguments,
Configuration{}
@@ -17,12 +17,12 @@ app::app(const Arguments& arguments):
{
}
-app::~app()
+floormat::~floormat()
{
loader_::destroy();
}
-int app::exec()
+int floormat::exec()
{
bool ret = true;
ret &= test_json();
@@ -35,7 +35,7 @@ int app::exec()
int main(int argc, char** argv)
{
- floormat::app application{{argc, argv}};
+ floormat::floormat application{{argc, argv}};
return application.exec();
}
diff --git a/test/tile-iter.cpp b/test/tile-iter.cpp
index 3aeb3ba2..9303a764 100644
--- a/test/tile-iter.cpp
+++ b/test/tile-iter.cpp
@@ -8,7 +8,7 @@ static inline bool always_false()
return ret;
}
-bool app::test_tile_iter() // NOLINT(readability-function-size)
+bool floormat::test_tile_iter() // NOLINT(readability-function-size)
{
if (always_false())
{