summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--draw/quad-floor.hpp2
-rw-r--r--draw/quad-wall-n.hpp2
-rw-r--r--draw/quad-wall-w.hpp2
-rw-r--r--draw/quad.hpp2
-rw-r--r--draw/wireframe-meshes.cpp15
-rw-r--r--draw/wireframe-meshes.hpp29
-rw-r--r--draw/wireframe.cpp1
-rw-r--r--draw/wireframe.hpp31
-rw-r--r--editor/app.cpp11
-rw-r--r--editor/app.hpp39
-rw-r--r--editor/imgui.cpp6
11 files changed, 88 insertions, 52 deletions
diff --git a/draw/quad-floor.hpp b/draw/quad-floor.hpp
index f44bf7af..b289ab84 100644
--- a/draw/quad-floor.hpp
+++ b/draw/quad-floor.hpp
@@ -4,7 +4,7 @@
#include <Magnum/Math/Vector2.h>
#include <Magnum/Math/Vector3.h>
#include <Magnum/GL/Mesh.h>
-#include <Corrade/Containers/ArrayView.h>
+#include <Corrade/Containers/ArrayViewStl.h>
namespace floormat::wireframe {
diff --git a/draw/quad-wall-n.hpp b/draw/quad-wall-n.hpp
index 6993b08a..d607ffe3 100644
--- a/draw/quad-wall-n.hpp
+++ b/draw/quad-wall-n.hpp
@@ -3,7 +3,7 @@
#include <array>
#include <Magnum/Math/Vector3.h>
#include <Magnum/GL/Mesh.h>
-#include <Corrade/Containers/ArrayView.h>
+#include <Corrade/Containers/ArrayViewStl.h>
namespace floormat::wireframe {
diff --git a/draw/quad-wall-w.hpp b/draw/quad-wall-w.hpp
index b7e402a4..a96e8d83 100644
--- a/draw/quad-wall-w.hpp
+++ b/draw/quad-wall-w.hpp
@@ -3,7 +3,7 @@
#include <array>
#include <Magnum/Math/Vector3.h>
#include <Magnum/GL/Mesh.h>
-#include <Corrade/Containers/ArrayView.h>
+#include <Corrade/Containers/ArrayViewStl.h>
namespace floormat::wireframe {
diff --git a/draw/quad.hpp b/draw/quad.hpp
index 466299f7..c9345f64 100644
--- a/draw/quad.hpp
+++ b/draw/quad.hpp
@@ -1,6 +1,6 @@
#pragma once
#include <array>
-#include <Corrade/Containers/ArrayView.h>
+#include <Corrade/Containers/ArrayViewStl.h>
#include <Magnum/Math/Vector3.h>
#include <Magnum/GL/Mesh.h>
diff --git a/draw/wireframe-meshes.cpp b/draw/wireframe-meshes.cpp
new file mode 100644
index 00000000..7baeddf7
--- /dev/null
+++ b/draw/wireframe-meshes.cpp
@@ -0,0 +1,15 @@
+#include "wireframe-meshes.hpp"
+
+namespace floormat::wireframe {
+
+meshes::meshes() :
+ _wireframe_texture{make_constant_texture()},
+ _wireframe_quad {_wireframe_texture},
+ _wireframe_wall_n {_wireframe_texture},
+ _wireframe_wall_w {_wireframe_texture},
+ _wireframe_box {_wireframe_texture},
+ _wireframe_rect {_wireframe_texture}
+{
+}
+
+} // namespace floormat::wireframe
diff --git a/draw/wireframe-meshes.hpp b/draw/wireframe-meshes.hpp
new file mode 100644
index 00000000..be9b6b79
--- /dev/null
+++ b/draw/wireframe-meshes.hpp
@@ -0,0 +1,29 @@
+#pragma once
+#include "wireframe.hpp"
+#include "compat/defs.hpp"
+#include "box.hpp"
+#include "quad-floor.hpp"
+#include "quad-wall-n.hpp"
+#include "quad-wall-w.hpp"
+#include "quad.hpp"
+#include <Corrade/Containers/ArrayViewStl.h>
+#include <Magnum/GL/Texture.h>
+
+namespace floormat::wireframe {
+
+struct meshes final
+{
+ fm_DECLARE_DELETED_COPY_ASSIGNMENT(meshes);
+ fm_DECLARE_DELETED_MOVE_ASSIGNMENT(meshes);
+
+ meshes();
+
+ GL::Texture2D _wireframe_texture;
+ wireframe_mesh<wireframe::quad_floor> _wireframe_quad {_wireframe_texture};
+ wireframe_mesh<wireframe::quad_wall_n> _wireframe_wall_n {_wireframe_texture};
+ wireframe_mesh<wireframe::quad_wall_w> _wireframe_wall_w {_wireframe_texture};
+ wireframe_mesh<wireframe::box> _wireframe_box {_wireframe_texture};
+ wireframe_mesh<wireframe::quad> _wireframe_rect {_wireframe_texture};
+};
+
+} // namespace floormat::wireframe
diff --git a/draw/wireframe.cpp b/draw/wireframe.cpp
index 5d041991..2ece4117 100644
--- a/draw/wireframe.cpp
+++ b/draw/wireframe.cpp
@@ -1,4 +1,3 @@
-#include "compat/defs.hpp"
#include "wireframe.hpp"
#include "shaders/shader.hpp"
#include <Corrade/Containers/Array.h>
diff --git a/draw/wireframe.hpp b/draw/wireframe.hpp
index ba42bac3..7b33a7fc 100644
--- a/draw/wireframe.hpp
+++ b/draw/wireframe.hpp
@@ -1,29 +1,18 @@
#pragma once
-
#include "src/tile-defs.hpp"
+#include <Corrade/Containers/ArrayView.h>
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/Mesh.h>
#include "Magnum/GL/Texture.h"
-namespace floormat {
-
-struct tile_shader;
-
-namespace wireframe {
+namespace floormat { struct tile_shader; }
-template<typename T>
-concept traits = requires (const T& x) {
- {T::num_vertices} -> std::convertible_to<size_t>;
- {T::num_indexes} -> std::convertible_to<size_t>;
- {x.primitive} -> std::convertible_to<GL::MeshPrimitive>;
- {x.make_vertex_array() } -> std::convertible_to<ArrayView<const void>>;
- {T::make_index_array() } -> std::convertible_to<ArrayView<const void>>;
- {x.on_draw()} -> std::same_as<void>;
-};
+namespace floormat::wireframe {
GL::Texture2D make_constant_texture();
-struct mesh_base {
+struct mesh_base
+{
static void set_line_width(float width);
protected:
@@ -37,22 +26,20 @@ protected:
void set_subdata(ArrayView<const void> array);
};
-} // namespace wireframe
-
-template<wireframe::traits T>
+template<typename T>
struct wireframe_mesh final : private wireframe::mesh_base
{
wireframe_mesh(GL::Texture2D& constant_texture);
void draw(tile_shader& shader, T traits);
};
-template<wireframe::traits T>
+template<typename T>
wireframe_mesh<T>::wireframe_mesh(GL::Texture2D& constant_texture) :
wireframe::mesh_base{T::primitive, T::make_index_array(), T::num_vertices, T::num_indexes, &constant_texture}
{
}
-template <wireframe::traits T> void wireframe_mesh<T>::draw(tile_shader& shader, T x)
+template <typename T> void wireframe_mesh<T>::draw(tile_shader& shader, T x)
{
//_texcoord_buffer.setData({nullptr, sizeof(Vector3) * T::num_vertices}, GL::BufferUsage::DynamicDraw); // orphan the buffer
set_subdata(x.make_vertex_array());
@@ -60,4 +47,4 @@ template <wireframe::traits T> void wireframe_mesh<T>::draw(tile_shader& shader,
mesh_base::draw(shader);
}
-} // namespace floormat
+} // namespace floormat::wireframe
diff --git a/editor/app.cpp b/editor/app.cpp
index 7505ff84..c6c298b3 100644
--- a/editor/app.cpp
+++ b/editor/app.cpp
@@ -1,19 +1,20 @@
#include "app.hpp"
#include "compat/assert.hpp"
#include "compat/sysexits.hpp"
-#include "floormat/main.hpp"
-#include "floormat/settings.hpp"
-#include "loader/loader.hpp"
#include "src/world.hpp"
#include "src/anim-atlas.hpp"
#include "src/critter.hpp"
-#include <cerrno>
+#include "floormat/main.hpp"
+#include "floormat/settings.hpp"
+#include "loader/loader.hpp"
+#include "draw/wireframe-meshes.hpp"
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <Corrade/Containers/StringIterable.h>
#include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/Move.h>
+#include <Magnum/ImGuiIntegration/Context.h>
namespace floormat {
@@ -30,6 +31,7 @@ const cursor_state& app::cursor_state() { return cursor; }
app::app(fm_settings&& opts) :
M{floormat_main::create(*this, Utility::move(opts))},
+ _wireframe{InPlaceInit},
_tests{tests_data_::make()}
{
reset_world();
@@ -43,7 +45,6 @@ app::app(fm_settings&& opts) :
app::~app()
{
-
}
void app::reset_world()
diff --git a/editor/app.hpp b/editor/app.hpp
index 09198c36..e0dc36e0 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -2,20 +2,26 @@
#include "compat/defs.hpp"
#include "compat/enum-bitset.hpp"
#include "editor.hpp"
-#include "draw/wireframe.hpp"
-#include "draw/quad-floor.hpp"
-#include "draw/quad-wall-n.hpp"
-#include "draw/quad-wall-w.hpp"
-#include "draw/quad.hpp"
-#include "draw/box.hpp"
#include "floormat/app.hpp"
#include "keys.hpp"
#include "src/object-id.hpp"
#include "tests.hpp"
#include <memory>
+#include <array>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/Optional.h>
-#include <Magnum/ImGuiIntegration/Context.h>
+
+namespace Magnum::GL {
+template<UnsignedInt dimensions> class Texture;
+typedef Texture<2> Texture2D;
+} // namespace Magnum::GL
+
+namespace Magnum::ImGuiIntegration { class Context; }
+
+namespace floormat::wireframe {
+GL::Texture2D make_constant_texture();
+struct meshes;
+} // namespace floormat::wireframe
namespace floormat {
@@ -69,8 +75,6 @@ struct app final : floormat_app
std::shared_ptr<critter> ensure_player_character(world& w);
private:
- using key_set = enum_bitset<key, key_COUNT>;
-
app(fm_settings&& opts);
fm_DECLARE_DELETED_COPY_ASSIGNMENT(app);
@@ -109,9 +113,6 @@ private:
void do_mouse_up_down(uint8_t button, bool is_down, int modifiers);
void do_mouse_scroll(int offset);
- void do_camera(float dt, const key_set& cmds, int mods);
- void reset_camera_offset();
-
void do_quicksave();
void do_quickload();
void do_new_file();
@@ -139,6 +140,7 @@ private:
void kill_popups(bool hard);
void render_menu();
+ using key_set = enum_bitset<key, key_COUNT>;
void do_key(key k, int mods);
void do_key(key k);
void do_set_mode(editor_mode mode);
@@ -150,6 +152,9 @@ private:
void clear_non_global_keys();
void clear_non_repeated_keys();
+ void do_camera(float dt, const key_set& cmds, int mods);
+ void reset_camera_offset();
+
[[nodiscard]] bool tests_handle_key(const key_event& e, bool is_down);
[[nodiscard]] bool tests_handle_mouse_click(const mouse_button_event& e, bool is_down);
[[nodiscard]] bool tests_handle_mouse_move(const mouse_move_event& e);
@@ -161,14 +166,10 @@ private:
tests_data& tests();
Pointer<floormat_main> M;
+ Pointer<floormat::wireframe::meshes> _wireframe;
+ Pointer<ImGuiIntegration::Context> _imgui;
Pointer<tests_data_> _tests;
- ImGuiIntegration::Context _imgui{NoCreate};
- GL::Texture2D _wireframe_texture = wireframe::make_constant_texture();
- wireframe_mesh<wireframe::quad_floor> _wireframe_quad {_wireframe_texture};
- wireframe_mesh<wireframe::quad_wall_n> _wireframe_wall_n {_wireframe_texture};
- wireframe_mesh<wireframe::quad_wall_w> _wireframe_wall_w {_wireframe_texture};
- wireframe_mesh<wireframe::box> _wireframe_box {_wireframe_texture};
- wireframe_mesh<wireframe::quad> _wireframe_rect {_wireframe_texture};
+
editor _editor{this};
key_set keys;
std::array<int, key_set::COUNT> key_modifiers = {};
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 440c9928..1e9dfc89 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -9,6 +9,7 @@
#include "imgui-raii.hpp"
#include "src/light.hpp"
#include <Magnum/GL/Renderer.h>
+#include <Magnum/ImGuiIntegration/Context.h>
#include <imgui.h>
namespace floormat {
@@ -19,8 +20,11 @@ bool popup_target::operator==(const popup_target&) const = default;
void app::init_imgui(Vector2i size)
{
- if (!_imgui.context())
+ if (!_imgui) [[unlikely]]
+ {
_imgui = ImGuiIntegration::Context(Vector2{size}, size, size);
+ fm_assert(_imgui.context());
+ }
else
_imgui.relayout(Vector2{size}, size, size);
}