summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-01-16 04:46:41 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-01-16 04:46:41 +0100
commit371f3ba371355ef204bf26bfe8aac962cebc1e4c (patch)
tree09a081d0ec9b322b832e3dfea35a442a72b72a75
parentc8c86c776483a60b988b18257573009b9897fd6c (diff)
b
-rw-r--r--compat/safe-ptr.hpp6
-rw-r--r--editor/draw.cpp4
-rw-r--r--editor/editor.cpp17
-rw-r--r--editor/editor.hpp24
-rw-r--r--editor/imgui-editors.cpp6
-rw-r--r--editor/imgui.cpp7
-rw-r--r--editor/update.cpp6
-rw-r--r--editor/vobj-editor.hpp12
-rw-r--r--src/chunk.cpp2
9 files changed, 51 insertions, 33 deletions
diff --git a/compat/safe-ptr.hpp b/compat/safe-ptr.hpp
index ec4a8e02..0882f3be 100644
--- a/compat/safe-ptr.hpp
+++ b/compat/safe-ptr.hpp
@@ -31,7 +31,7 @@ public:
{
if (ptr) [[likely]]
delete ptr;
- ptr = (T*)-0xbadbabe;
+ ptr = (T*)0xbadcafedeadbabe;
}
explicit safe_ptr(safe_ptr&& other) noexcept: ptr{other.ptr}
@@ -39,6 +39,10 @@ public:
other.ptr = nullptr;
}
+ explicit safe_ptr() noexcept:
+ ptr{new T{}}
+ {}
+
safe_ptr& operator=(safe_ptr&& other) noexcept
{
fm_assert(this != &other);
diff --git a/editor/draw.cpp b/editor/draw.cpp
index 039492ac..bd77f37d 100644
--- a/editor/draw.cpp
+++ b/editor/draw.cpp
@@ -4,6 +4,10 @@
#include "shaders/shader.hpp"
#include "main/clickable.hpp"
#include "editor.hpp"
+#include "ground-editor.hpp"
+#include "wall-editor.hpp"
+#include "scenery-editor.hpp"
+#include "vobj-editor.hpp"
#include "src/anim-atlas.hpp"
#include "draw/anim.hpp"
#include "draw/wireframe-meshes.hpp"
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 53776ebe..c84c376a 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -1,8 +1,10 @@
#include "editor.hpp"
#include "loader/loader.hpp"
#include "src/world.hpp"
-#include "keys.hpp"
-
+#include "ground-editor.hpp"
+#include "wall-editor.hpp"
+#include "scenery-editor.hpp"
+#include "vobj-editor.hpp"
#include <algorithm>
#include <Corrade/Containers/StringView.h>
@@ -183,6 +185,9 @@ void editor::on_click(world& world, global_coords pos, int mods, button b)
}
editor::editor(app* a) : _app{a} {}
+editor::editor(editor&&) noexcept = default;
+editor& editor::operator=(editor&&) noexcept = default;
+editor::~editor() noexcept = default;
void editor::set_mode(editor_mode mode)
{
@@ -195,7 +200,7 @@ const ground_editor* editor::current_ground_editor() const noexcept
switch (_mode)
{
case editor_mode::floor:
- return &_floor;
+ return &*_floor;
default:
return nullptr;
}
@@ -206,7 +211,7 @@ const wall_editor* editor::current_wall_editor() const noexcept
switch (_mode)
{
case editor_mode::walls:
- return &_wall;
+ return &*_wall;
default:
return nullptr;
}
@@ -215,7 +220,7 @@ const wall_editor* editor::current_wall_editor() const noexcept
const scenery_editor* editor::current_scenery_editor() const noexcept
{
if (_mode == editor_mode::scenery)
- return &_scenery;
+ return &*_scenery;
else
return nullptr;
}
@@ -223,7 +228,7 @@ const scenery_editor* editor::current_scenery_editor() const noexcept
const vobj_editor* editor::current_vobj_editor() const noexcept
{
if (_mode == editor_mode::vobj)
- return &_vobj;
+ return &*_vobj;
else
return nullptr;
}
diff --git a/editor/editor.hpp b/editor/editor.hpp
index b4e4ff8e..22cd48da 100644
--- a/editor/editor.hpp
+++ b/editor/editor.hpp
@@ -1,14 +1,10 @@
#pragma once
#include "compat/defs.hpp"
+#include "compat/safe-ptr.hpp"
#include "src/global-coords.hpp"
#include "src/tile-image.hpp"
#include "src/scenery.hpp"
#include "editor-enums.hpp"
-#include "ground-editor.hpp"
-#include "wall-editor.hpp"
-#include "scenery-editor.hpp"
-#include "vobj-editor.hpp"
-
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/StringView.h>
@@ -19,6 +15,11 @@ class anim_atlas;
class ground_atlas;
struct app;
+class ground_editor;
+class wall_editor;
+class scenery_editor;
+class vobj_editor;
+
class editor final
{
editor_snap_mode get_snap_value(editor_snap_mode snap, int mods) const;
@@ -26,10 +27,10 @@ class editor final
app* _app;
- ground_editor _floor;
- wall_editor _wall;
- scenery_editor _scenery;
- vobj_editor _vobj;
+ safe_ptr<ground_editor> _floor{};
+ safe_ptr<wall_editor> _wall{};
+ safe_ptr<scenery_editor> _scenery{};
+ safe_ptr<vobj_editor> _vobj{};
struct drag_pos final {
global_coords coord, draw_coord;
@@ -43,8 +44,9 @@ class editor final
public:
fm_DECLARE_DELETED_COPY_ASSIGNMENT(editor);
editor(app* a);
- editor(editor&&) noexcept = default;
- editor& operator=(editor&&) noexcept = default;
+ editor(editor&&) noexcept;
+ editor& operator=(editor&&) noexcept;
+ ~editor() noexcept;
[[nodiscard]] bool dirty() const noexcept { return _dirty; }
void set_dirty(bool value) noexcept { _dirty = value; }
diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp
index 0e098ae1..358cd200 100644
--- a/editor/imgui-editors.cpp
+++ b/editor/imgui-editors.cpp
@@ -1,6 +1,10 @@
#include "app.hpp"
#include "compat/format.hpp"
#include "imgui-raii.hpp"
+#include "ground-editor.hpp"
+#include "wall-editor.hpp"
+#include "scenery-editor.hpp"
+#include "vobj-editor.hpp"
#include "src/anim-atlas.hpp"
#include "src/ground-atlas.hpp"
#include "src/wall-atlas.hpp"
@@ -50,7 +54,7 @@ void select_tile(scenery_editor& ed, const scenery_& sc) { ed.select_tile(sc); }
void select_tile(vobj_editor& vo, const vobj_& sc) { vo.select_tile(sc); }
void select_tile(wall_editor& wa, const wall_info* sc) { wa.select_atlas(sc->atlas); }
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()); };
+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(ground_editor& ed, StringView name, const std::shared_ptr<ground_atlas>& atlas, Vector2 dpi)
{
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 02e3abc1..f974ec6b 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -1,11 +1,14 @@
#include "app.hpp"
-#include "floormat/main.hpp"
#include "compat/format.hpp"
+#include "editor.hpp"
+#include "ground-editor.hpp"
+#include "wall-editor.hpp"
+#include "scenery-editor.hpp"
+#include "floormat/main.hpp"
#include "src/world.hpp"
#include "src/anim-atlas.hpp"
#include "shaders/shader.hpp"
#include "shaders/lightmap.hpp"
-#include "editor.hpp"
#include "main/clickable.hpp"
#include "imgui-raii.hpp"
#include "src/light.hpp"
diff --git a/editor/update.cpp b/editor/update.cpp
index be686567..62f0e5d3 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -1,9 +1,13 @@
#include "app.hpp"
+#include "editor.hpp"
+#include "ground-editor.hpp"
+#include "wall-editor.hpp"
+#include "scenery-editor.hpp"
+#include "vobj-editor.hpp"
#include "src/world.hpp"
#include "src/ground-atlas.hpp"
#include "src/anim-atlas.hpp"
#include "main/clickable.hpp"
-#include "editor.hpp"
#include "floormat/events.hpp"
#include "floormat/main.hpp"
#include "src/critter.hpp"
diff --git a/editor/vobj-editor.hpp b/editor/vobj-editor.hpp
index d5af27ba..962212c7 100644
--- a/editor/vobj-editor.hpp
+++ b/editor/vobj-editor.hpp
@@ -14,11 +14,6 @@ class anim_atlas;
struct vobj_info;
struct app;
-#if defined __clang__ || defined __CLION_IDE__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wweak-vtables"
-#endif
-
struct vobj_factory
{
vobj_factory();
@@ -32,12 +27,9 @@ struct vobj_factory
std::shared_ptr<anim_atlas> atlas() const;
};
-#if defined __clang__ || defined __CLION_IDE__
-#pragma clang diagnostic pop
-#endif
-
-struct vobj_editor final
+class vobj_editor final
{
+public:
struct vobj_ final {
StringView name, descr;
std::unique_ptr<vobj_factory> factory;
diff --git a/src/chunk.cpp b/src/chunk.cpp
index 19d79b3a..8674eb9f 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -181,7 +181,7 @@ void chunk::remove_object(size_t i)
fm_assert(_objects_sorted);
auto& es = _objects;
fm_debug_assert(i < es.size());
- const auto& e = es[i];
+ const auto e = es[i];
if (!e->is_dynamic())
mark_scenery_modified();
if (bbox bb; _bbox_for_scenery(*e, bb))