summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/main.cpp4
-rw-r--r--compat/safe-ptr.hpp61
-rw-r--r--compat/shared-ptr-wrapper.hpp12
-rw-r--r--editor/app.cpp39
-rw-r--r--editor/app.hpp17
-rw-r--r--editor/ctor.cpp3
-rw-r--r--editor/imgui.cpp10
-rw-r--r--editor/tests.cpp5
-rw-r--r--editor/tests.hpp4
-rw-r--r--editor/tests/path-test.cpp3
m---------external/corrade0
-rw-r--r--floormat/main.hpp1
-rw-r--r--loader/impl.hpp2
-rw-r--r--loader/loader.cpp33
-rw-r--r--loader/loader.hpp8
-rw-r--r--main/main-impl.cpp7
-rw-r--r--src/RTree-fwd.h5
-rw-r--r--src/RTree.h18
-rw-r--r--src/RTree.hpp27
-rw-r--r--src/chunk-collision.cpp16
-rw-r--r--src/chunk.cpp8
-rw-r--r--src/chunk.hpp4
-rw-r--r--test/main.cpp2
-rw-r--r--userconfig-sthalik@Windows-GNU.cmake1
24 files changed, 200 insertions, 90 deletions
diff --git a/bench/main.cpp b/bench/main.cpp
index 7410bf8d..5fccf3e4 100644
--- a/bench/main.cpp
+++ b/bench/main.cpp
@@ -22,7 +22,7 @@ struct bench_app final : private FM_APPLICATION
int argc;
char** argv;
};
-bench_app::~bench_app() { loader_::destroy(); }
+bench_app::~bench_app() { loader.destroy(); }
int argc_ = 0; // NOLINT
@@ -52,6 +52,6 @@ int main(int argc, char** argv)
{ auto app = bench_app{argc, argv};
status = app.exec();
}
- loader_::destroy();
+ loader.destroy();
return status;
}
diff --git a/compat/safe-ptr.hpp b/compat/safe-ptr.hpp
new file mode 100644
index 00000000..f6b0b260
--- /dev/null
+++ b/compat/safe-ptr.hpp
@@ -0,0 +1,61 @@
+#pragma once
+#include "compat/assert.hpp"
+#include "compat/defs.hpp"
+#include <type_traits>
+#include <Corrade/Tags.h>
+#include <Corrade/Utility/Move.h>
+
+namespace floormat {
+
+template<typename T>
+class safe_ptr final
+{
+ T* ptr;
+
+public:
+ template<typename... Ts>
+ requires requires (Ts&&... xs) {
+ new T{Utility::forward<Ts>(xs)...};
+ }
+ safe_ptr(InPlaceInitT, Ts&&... args) noexcept:
+ ptr{new T{Utility::forward<Ts>(args)...}}
+ {}
+
+ explicit safe_ptr(T*&& ptr) noexcept: ptr{ptr}
+ {
+ fm_assert(ptr != nullptr);
+ }
+
+ ~safe_ptr() noexcept
+ {
+ if (ptr)
+ delete ptr;
+ ptr = (T*)-0xbadbabe;
+ }
+
+ explicit safe_ptr(safe_ptr&& other) noexcept: ptr{other.ptr}
+ {
+ other.ptr = nullptr;
+ }
+
+ safe_ptr& operator=(safe_ptr&& other) noexcept
+ {
+ fm_assert(this != &other);
+ if (ptr)
+ delete ptr;
+ ptr = other.ptr;
+ other.ptr = nullptr;
+ return *this;
+ }
+
+ fm_DECLARE_DELETED_COPY_ASSIGNMENT(safe_ptr);
+
+ //explicit operator bool() const noexcept { return ptr != nullptr; }
+
+ const T& operator*() const noexcept { return *ptr; }
+ T& operator*() noexcept { return *ptr; }
+ const T* operator->() const noexcept { return ptr; }
+ T* operator->() noexcept { return ptr; }
+};
+
+} // namespace floormat
diff --git a/compat/shared-ptr-wrapper.hpp b/compat/shared-ptr-wrapper.hpp
new file mode 100644
index 00000000..8315d674
--- /dev/null
+++ b/compat/shared-ptr-wrapper.hpp
@@ -0,0 +1,12 @@
+#pragma once
+#include <memory>
+
+namespace floormat {
+
+template<typename T>
+struct shared_ptr_wrapper final
+{
+ std::shared_ptr<T> ptr;
+};
+
+} // namespace floormat
diff --git a/editor/app.cpp b/editor/app.cpp
index 44df5c5e..766d96c8 100644
--- a/editor/app.cpp
+++ b/editor/app.cpp
@@ -1,6 +1,7 @@
#include "app.hpp"
#include "compat/assert.hpp"
#include "compat/sysexits.hpp"
+#include "compat/shared-ptr-wrapper.hpp"
#include "editor.hpp"
#include "src/anim-atlas.hpp"
#include "src/critter.hpp"
@@ -28,16 +29,22 @@ floormat_main& app::main() { return *M; }
const cursor_state& app::cursor_state() { return cursor; }
-std::shared_ptr<critter> app::ensure_player_character(world& w)
+shared_ptr_wrapper<critter> app::ensure_player_character(world& w)
{
if (_character_id)
+ {
+ std::shared_ptr<critter> tmp;
if (auto C = w.find_object(_character_id); C && C->type() == object_type::critter)
- return std::static_pointer_cast<critter>(C);
+ {
+ auto ptr = std::static_pointer_cast<critter>(C);
+ return {ptr};
+ }
+ }
_character_id = 0;
auto id = (object_id)-1;
- std::shared_ptr<critter> ret;
+ shared_ptr_wrapper<critter> ret;
for (const auto& [coord, c] : w.chunks())
{
@@ -50,7 +57,7 @@ std::shared_ptr<critter> app::ensure_player_character(world& w)
if (C.playable)
{
id = std::min(id, C.id);
- ret = std::static_pointer_cast<critter>(e_);
+ ret.ptr = std::static_pointer_cast<critter>(e_);
}
}
}
@@ -63,11 +70,11 @@ std::shared_ptr<critter> app::ensure_player_character(world& w)
critter_proto cproto;
cproto.name = "Player"_s;
cproto.playable = true;
- ret = w.make_object<critter>(w.make_id(), global_coords{}, cproto);
- _character_id = ret->id;
+ ret.ptr = w.make_object<critter>(w.make_id(), global_coords{}, cproto);
+ _character_id = ret.ptr->id;
}
- fm_debug_assert(ret);
- return ret;
+ fm_debug_assert(ret.ptr);
+ return shared_ptr_wrapper<critter>{ret};
}
void app::reset_world(class world&& w_)
@@ -176,15 +183,13 @@ int app::run_from_argv(const int argc, const char* const* const argv)
opts.argv = argv;
opts.argc = argc;
- Pointer<struct floormat_main> main;
- Pointer<struct app> app_ptr{new app{Utility::move(opts)}};
- auto& app = *app_ptr;
- {
- ret = app.exec();
- main = Utility::move(app.M);
- (void)main;
- }
- loader_::destroy();
+ struct app* A = new app{Utility::move(opts)};
+ floormat_main* M = A->M;
+ fm_assert(M != nullptr);
+ ret = A->exec();
+ loader.destroy();
+ delete A;
+ delete M;
return ret;
}
diff --git a/editor/app.hpp b/editor/app.hpp
index b869f2b4..fd24e495 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -1,13 +1,13 @@
#pragma once
#include "compat/defs.hpp"
#include "compat/enum-bitset-fwd.hpp"
+#include "compat/safe-ptr.hpp"
#include "floormat/app.hpp"
#include "keys.hpp"
#include "src/global-coords.hpp"
#include "src/object-id.hpp"
#include "editor-enums.hpp"
#include "tests.hpp"
-#include <memory>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/Pointer.h>
@@ -37,6 +37,7 @@ class anim_atlas;
struct critter;
struct point;
class editor;
+template<typename T> struct shared_ptr_wrapper;
struct cursor_state final
{
@@ -78,7 +79,7 @@ struct app final : floormat_app
floormat_main& main();
const struct cursor_state& cursor_state();
clickable* find_clickable_scenery(const Optional<Vector2i>& pixel);
- std::shared_ptr<critter> ensure_player_character(world& w);
+ shared_ptr_wrapper<critter> ensure_player_character(world& w);
private:
app(fm_settings&& opts);
@@ -176,12 +177,12 @@ private:
void erase_inspector(size_t index, ptrdiff_t count = 1);
void kill_inspectors();
- Pointer<floormat_main> M;
- Pointer<ImGuiIntegration::Context> _imgui;
- Pointer<floormat::wireframe::meshes> _wireframe;
- Pointer<tests_data_> _tests;
- Pointer<editor> _editor;
- Pointer<key_set> keys_;
+ floormat_main* M;
+ safe_ptr<ImGuiIntegration::Context> _imgui;
+ safe_ptr<floormat::wireframe::meshes> _wireframe;
+ safe_ptr<tests_data_> _tests;
+ safe_ptr<editor> _editor;
+ safe_ptr<key_set> keys_;
StaticArray<key_COUNT, int> key_modifiers{ValueInit};
Array<popup_target> inspectors;
object_id _character_id = 0;
diff --git a/editor/ctor.cpp b/editor/ctor.cpp
index ccda3060..9c1f64fc 100644
--- a/editor/ctor.cpp
+++ b/editor/ctor.cpp
@@ -10,10 +10,11 @@ namespace floormat {
app::app(fm_settings&& opts) :
M{floormat_main::create(*this, Utility::move(opts))},
+ _imgui{InPlaceInit, NoCreate},
_wireframe{InPlaceInit},
_tests{tests_data_::make()},
_editor{InPlaceInit, this},
- keys_{InPlaceInit, 0}
+ keys_{InPlaceInit, 0u}
{
reset_world();
auto& w = M->world();
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 3465f27a..02e3abc1 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -21,9 +21,9 @@ bool popup_target::operator==(const popup_target&) const = default;
void app::init_imgui(Vector2i size)
{
- if (!_imgui) [[unlikely]]
+ if (!_imgui->context()) [[unlikely]]
{
- _imgui = Pointer<ImGuiIntegration::Context>{InPlaceInit, NoCreate};
+ _imgui = safe_ptr<ImGuiIntegration::Context>{InPlaceInit, NoCreate};
*_imgui = ImGuiIntegration::Context{Vector2{size}, size, size};
fm_assert(_imgui->context());
}
@@ -392,7 +392,7 @@ void app::do_popup_menu()
void app::kill_popups(bool hard)
{
- const bool imgui = _imgui != nullptr;
+ const bool imgui = _imgui->context() != nullptr;
if (imgui)
fm_assert(_imgui->context());
@@ -403,13 +403,13 @@ void app::kill_popups(bool hard)
if (hard)
tested_light_chunk = {};
- if (_imgui)
+ if (_imgui->context())
ImGui::CloseCurrentPopup();
if (hard)
kill_inspectors();
- if (_imgui)
+ if (_imgui->context())
ImGui::FocusWindow(nullptr);
}
diff --git a/editor/tests.cpp b/editor/tests.cpp
index ee108d01..41d39cd2 100644
--- a/editor/tests.cpp
+++ b/editor/tests.cpp
@@ -1,4 +1,5 @@
#include "tests-private.hpp"
+#include "compat/safe-ptr.hpp"
#include "app.hpp"
#include "floormat/events.hpp"
#include "imgui-raii.hpp"
@@ -31,9 +32,9 @@ void tests_data::switch_to(size_t i)
}
}
-Pointer<tests_data_> tests_data_::make()
+safe_ptr<tests_data_> tests_data_::make()
{
- return Pointer<tests_data>{InPlaceInit};
+ return safe_ptr<tests_data_>{new tests_data};
}
void app::tests_pre_update()
diff --git a/editor/tests.hpp b/editor/tests.hpp
index 06762127..b4ee5289 100644
--- a/editor/tests.hpp
+++ b/editor/tests.hpp
@@ -3,6 +3,8 @@
namespace floormat {
+template<typename T> class safe_ptr;
+
struct tests_data;
struct tests_data_
@@ -10,7 +12,7 @@ struct tests_data_
fm_DECLARE_DELETED_COPY_ASSIGNMENT(tests_data_);
virtual ~tests_data_() noexcept;
- static Pointer<tests_data_> make();
+ [[nodiscard]] static safe_ptr<tests_data_> make();
protected:
tests_data_();
diff --git a/editor/tests/path-test.cpp b/editor/tests/path-test.cpp
index 2bc40717..c21c13c9 100644
--- a/editor/tests/path-test.cpp
+++ b/editor/tests/path-test.cpp
@@ -1,5 +1,6 @@
#include "../tests-private.hpp"
#include "../app.hpp"
+#include "compat/shared-ptr-wrapper.hpp"
#include "floormat/main.hpp"
#include "src/path-search.hpp"
#include "src/critter.hpp"
@@ -26,7 +27,7 @@ bool path_test::handle_mouse_click(app& a, const mouse_button_event& e, bool is_
case mouse_button_left: {
auto& M = a.main();
auto& w = M.world();
- auto C = a.ensure_player_character(w);
+ auto C = a.ensure_player_character(w).ptr;
if (auto pt = a.cursor_state().point())
{
constexpr auto chunk_size = iTILE_SIZE2 * TILE_MAX_DIM;
diff --git a/external/corrade b/external/corrade
-Subproject 2b33a728ec170ff4a134ab5094ef07c9d3a3d5c
+Subproject 86e15c4db2715cb0527cbd1094df6f48e3f5731
diff --git a/floormat/main.hpp b/floormat/main.hpp
index ead48a8d..cfb41f1d 100644
--- a/floormat/main.hpp
+++ b/floormat/main.hpp
@@ -9,6 +9,7 @@ namespace Magnum::Platform { class Sdl2Application; }
namespace floormat {
+template<typename T> class safe_ptr;
struct fm_settings;
struct floormat_app;
struct tile_shader;
diff --git a/loader/impl.hpp b/loader/impl.hpp
index 5f1a8ff0..a4a33747 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -22,13 +22,13 @@ struct loader_impl final : loader_
{
explicit loader_impl();
~loader_impl() override;
-
// >-----> system >----->
String original_working_directory;
void set_application_working_directory();
StringView startup_directory() noexcept override;
static void system_init();
+ void destroy() override;
static bool chdir(StringView pathname);
// >-----> plugins >----->
diff --git a/loader/loader.cpp b/loader/loader.cpp
index df712f39..af7b053f 100644
--- a/loader/loader.cpp
+++ b/loader/loader.cpp
@@ -1,15 +1,36 @@
#include "impl.hpp"
+#include "ground-info.hpp"
+#include "wall-info.hpp"
+#include "scenery.hpp"
-namespace floormat {
-
-using loader_detail::loader_impl;
+namespace floormat::loader_detail {
-void loader_::destroy()
+void loader_impl::destroy()
{
- loader.~loader_();
- new (&loader) loader_impl();
+ wall_atlas_map.clear();
+ wall_atlas_array.clear();
+ invalid_wall_atlas = nullptr;
+ missing_wall_atlases.clear();
+
+ ground_atlas_map.clear();
+ ground_atlas_array.clear();
+ invalid_ground_atlas = nullptr;
+ missing_ground_atlases.clear();
+
+ anim_atlas_map.clear();
+ anim_atlases.clear();
+ sceneries_map.clear();
+ sceneries_array.clear();
+ vobj_atlas_map.clear();
+ vobjs.clear();
}
+} // namespace floormat::loader_detail
+
+namespace floormat {
+
+using loader_detail::loader_impl;
+
loader_& loader_::default_loader() noexcept
{
static loader_impl loader_singleton{};
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 477a5dd0..51a15b14 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include "compat/defs.hpp"
#include "src/pass-mode.hpp"
#include <stdio.h>
#include <memory>
@@ -37,7 +38,7 @@ struct loader_
virtual std::shared_ptr<class anim_atlas> anim_atlas(StringView name, StringView dir = ANIM_PATH) noexcept(false) = 0;
virtual std::shared_ptr<class wall_atlas> wall_atlas(StringView name, bool fail_ok = false) noexcept(false) = 0;
virtual ArrayView<const wall_info> wall_atlas_list() = 0;
- static void destroy();
+ virtual void destroy() = 0;
static loader_& default_loader() noexcept;
virtual ArrayView<const ground_info> ground_atlas_list() noexcept(false) = 0;
virtual ArrayView<const serialized_scenery> sceneries() = 0;
@@ -49,10 +50,9 @@ struct loader_
static StringView make_atlas_path(char(&buf)[FILENAME_MAX], StringView dir, StringView name);
[[nodiscard]] static bool check_atlas_name(StringView name) noexcept;
- loader_(const loader_&) = delete;
- loader_& operator=(const loader_&) = delete;
-
virtual ~loader_() noexcept;
+ fm_DECLARE_DELETED_COPY_ASSIGNMENT(loader_);
+ fm_DECLARE_DELETED_MOVE_ASSIGNMENT(loader_);
static const StringView INVALID;
static const StringView IMAGE_PATH_;
diff --git a/main/main-impl.cpp b/main/main-impl.cpp
index ae074a49..cb74de85 100644
--- a/main/main-impl.cpp
+++ b/main/main-impl.cpp
@@ -1,7 +1,5 @@
#include "main-impl.hpp"
-#include "compat/assert.hpp"
-#include <cstdlib>
-#include <cstdio>
+#include <Corrade/Utility/Move.h>
#include <Magnum/Platform/Sdl2Application.h>
namespace floormat {
@@ -37,8 +35,7 @@ int main_impl::exec()
floormat_main* floormat_main::create(floormat_app& app, fm_settings&& options)
{
- auto* ret = new main_impl(app, std::move(options), options.argc, const_cast<char**>(options.argv));
- fm_assert(ret);
+ auto* ret = new main_impl(app, Utility::move(options), options.argc, const_cast<char**>(options.argv));
return ret;
}
diff --git a/src/RTree-fwd.h b/src/RTree-fwd.h
new file mode 100644
index 00000000..a93ec168
--- /dev/null
+++ b/src/RTree-fwd.h
@@ -0,0 +1,5 @@
+#pragma once
+
+template<class DATATYPE, class ELEMTYPE, int NUMDIMS,
+ class ELEMTYPEREAL = ELEMTYPE, int TMAXNODES = 8, int TMINNODES = TMAXNODES / 2>
+class RTree;
diff --git a/src/RTree.h b/src/RTree.h
index 95784409..7b8eeb7c 100644
--- a/src/RTree.h
+++ b/src/RTree.h
@@ -1,6 +1,5 @@
-#ifndef RTREE_H
-#define RTREE_H
-
+#pragma once
+#include "RTree-fwd.h"
// NOTE This file compiles under MSVC 6 SP5 and MSVC .Net 2003 it may not work on other compilers without modification.
// NOTE These next few lines may be win32 specific, you may need to modify them to compile on other platform
@@ -11,8 +10,6 @@
#include <stdio.h>
#endif
-#include <vector>
-
//
// RTree.h
//
@@ -71,10 +68,9 @@ private:
/// array similar to MFC CArray or STL Vector for returning search query result.
///
template<class DATATYPE, class ELEMTYPE, int NUMDIMS,
- class ELEMTYPEREAL = ELEMTYPE, int TMAXNODES = 8, int TMINNODES = TMAXNODES / 2>
+ class ELEMTYPEREAL, int TMAXNODES, int TMINNODES>
class RTree final
{
-
public:
struct Node; // Fwd decl. Used by other internal structs and iterator
@@ -88,8 +84,6 @@ public:
MINNODES = TMINNODES, ///< Min elements in node
};
-public:
-
RTree();
RTree(const RTree& other);
~RTree() noexcept;
@@ -302,9 +296,11 @@ protected:
Node* m_root; ///< Root of tree
ELEMTYPEREAL m_unitSphereVolume; ///< Unit sphere constant for required number of dimensions
+ template<typename T> using Array = ::Corrade::Containers::Array<T>;
+
public:
// return all the AABBs that form the RTree
- void ListTree(std::vector<Rect>& vec, std::vector<Node*>& temp) const;
+ void ListTree(Array<Rect>& vec, Array<Node*>& temp) const;
};
@@ -315,5 +311,3 @@ extern template class RTree<floormat::uint64_t, float, 2, float>;
#endif
//#undef RTREE_TEMPLATE
//#undef RTREE_QUAL
-
-#endif //RTREE_H
diff --git a/src/RTree.hpp b/src/RTree.hpp
index 01ce9b5b..18ae3b77 100644
--- a/src/RTree.hpp
+++ b/src/RTree.hpp
@@ -6,6 +6,7 @@
#include <cmath>
#include <cstddef>
#include <algorithm>
+#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Utility/Math.h>
#ifdef __GNUG__
@@ -1247,29 +1248,31 @@ void RTREE_QUAL::ReInsert(Node* a_node, ListNode** a_listNode)
RTREE_TEMPLATE
-void RTREE_QUAL::ListTree(std::vector<Rect>& treeList, std::vector<Node*>& toVisit) const
+void RTREE_QUAL::ListTree(Array<Rect>& treeList, Array<Node*>& toVisit) const
{
fm_assert(m_root);
fm_assert(m_root->m_level >= 0);
+ using namespace ::Corrade::Containers;
+
std::size_t count = (std::size_t)Count();
- treeList.clear();
- treeList.reserve(count);
- toVisit.clear();
- toVisit.reserve(count);
+ arrayResize(treeList, 0);
+ arrayResize(toVisit, 0);
+ arrayReserve(treeList, count);
+ arrayReserve(toVisit, count);
- toVisit.push_back(m_root);
+ arrayAppend(toVisit, m_root);
- while (!toVisit.empty()) {
+ while (!toVisit.isEmpty()) {
Node* a_node = toVisit.back();
- toVisit.pop_back();
+ arrayRemove(toVisit, toVisit.size()-1);
if(a_node->IsInternalNode())
{
// This is an internal node in the tree
for(int index=0; index < a_node->m_count; ++index)
{
- treeList.push_back(a_node->m_branch[index].m_rect);
- toVisit.push_back(a_node->m_branch[index].m_child);
+ arrayAppend(treeList, a_node->m_branch[index].m_rect);
+ arrayAppend(toVisit, a_node->m_branch[index].m_child);
}
}
else
@@ -1277,12 +1280,12 @@ void RTREE_QUAL::ListTree(std::vector<Rect>& treeList, std::vector<Node*>& toVis
// This is a leaf node
for(int index=0; index < a_node->m_count; ++index)
{
- treeList.push_back(a_node->m_branch[index].m_rect);
+ arrayAppend(treeList, a_node->m_branch[index].m_rect);
}
}
}
- toVisit.clear();
+ arrayResize(toVisit, 0);
}
RTREE_TEMPLATE
diff --git a/src/chunk-collision.cpp b/src/chunk-collision.cpp
index a6fd379d..5ffbf0ec 100644
--- a/src/chunk-collision.cpp
+++ b/src/chunk-collision.cpp
@@ -11,7 +11,7 @@
namespace floormat {
-chunk::RTree* chunk::rtree() noexcept { ensure_passability(); return &_rtree; }
+chunk::RTree* chunk::rtree() noexcept { ensure_passability(); return &*_rtree; }
namespace {
@@ -30,7 +30,7 @@ void chunk::ensure_passability() noexcept
return;
_pass_modified = false;
- _rtree.RemoveAll();
+ _rtree->RemoveAll();
for (const std::shared_ptr<object>& s : objects())
{
@@ -45,7 +45,7 @@ void chunk::ensure_passability() noexcept
{
auto [min, max] = whole_tile(i);
auto id = make_id(collision_type::geometry, atlas->pass_mode(), i+1);
- _rtree.Insert(min.data(), max.data(), id);
+ _rtree->Insert(min.data(), max.data(), id);
}
}
for (auto i = 0uz; i < TILE_COUNT; i++)
@@ -55,13 +55,13 @@ void chunk::ensure_passability() noexcept
{
auto [min, max] = wall_north(i, atlas->info().depth);
auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT+i+1);
- _rtree.Insert(min.data(), max.data(), id);
+ _rtree->Insert(min.data(), max.data(), id);
}
if (const auto* atlas = tile.wall_west_atlas().get())
{
auto [min, max] = wall_west(i, atlas->info().depth);
auto id = make_id(collision_type::geometry, atlas->info().passability, TILE_COUNT*2+i+1);
- _rtree.Insert(min.data(), max.data(), id);
+ _rtree->Insert(min.data(), max.data(), id);
}
}
}
@@ -82,13 +82,13 @@ bool chunk::_bbox_for_scenery(const object& s, bbox& value) noexcept
void chunk::_remove_bbox(const bbox& x)
{
auto start = Vector2(x.start), end = Vector2(x.end);
- _rtree.Remove(start.data(), end.data(), x.id);
+ _rtree->Remove(start.data(), end.data(), x.id);
}
void chunk::_add_bbox(const bbox& x)
{
auto start = Vector2(x.start), end = Vector2(x.end);
- _rtree.Insert(start.data(), end.data(), x.id);
+ _rtree->Insert(start.data(), end.data(), x.id);
}
void chunk::_replace_bbox(const bbox& x0, const bbox& x1, bool b0, bool b1)
@@ -144,7 +144,7 @@ bool chunk::can_place_object(const object_proto& proto, local_coords pos)
const auto center = Vector2(pos)*TILE_SIZE2 + Vector2(proto.offset) + Vector2(proto.bbox_offset),
min = center - Vector2(bbox_size)*.5f, max = min + Vector2(bbox_size);
bool ret = true;
- _rtree.Search(min.data(), max.data(), [&](uint64_t data, const auto&) {
+ _rtree->Search(min.data(), max.data(), [&](uint64_t data, const auto&) {
[[maybe_unused]] auto x = std::bit_cast<collision_data>(data);
if (x.pass == (uint64_t)pass_mode::pass || x.pass == (uint64_t)pass_mode::shoot_through)
return true;
diff --git a/src/chunk.cpp b/src/chunk.cpp
index a819de6c..19d79b3a 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -2,6 +2,7 @@
#include "object.hpp"
#include "world.hpp"
#include "tile-iterator.hpp"
+#include "RTree.h"
#include <algorithm>
#include <Corrade/Containers/GrowableArray.h>
#include <Magnum/GL/Context.h>
@@ -120,7 +121,10 @@ void chunk::mark_modified() noexcept
mark_passability_modified();
}
-chunk::chunk(class world& w, chunk_coords_ ch) noexcept : _world{&w}, _coord{ch}
+chunk::chunk(class world& w, chunk_coords_ ch) noexcept :
+ _world{&w},
+ _rtree{InPlaceInit},
+ _coord{ch}
{
}
@@ -129,7 +133,7 @@ chunk::~chunk() noexcept
_teardown = true;
arrayResize(_objects, 0);
arrayShrink(_objects);
- _rtree.RemoveAll();
+ _rtree->RemoveAll();
}
chunk::chunk(chunk&&) noexcept = default;
diff --git a/src/chunk.hpp b/src/chunk.hpp
index 56afb6a5..064a16e7 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -2,7 +2,7 @@
#include "object-id.hpp"
#include "tile.hpp"
#include "local-coords.hpp"
-#include "src/RTree.h"
+#include "src/RTree-fwd.h"
#include "global-coords.hpp"
#include "wall-defs.hpp"
#include <type_traits>
@@ -150,7 +150,7 @@ private:
Array<std::shared_ptr<object>> _objects;
class world* _world;
GL::Mesh ground_mesh{NoCreate}, wall_mesh{NoCreate}, scenery_mesh{NoCreate};
- RTree _rtree;
+ Pointer<RTree> _rtree;
chunk_coords_ _coord;
mutable bool _maybe_empty : 1 = true,
diff --git a/test/main.cpp b/test/main.cpp
index 93652102..dfe37c2c 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -16,7 +16,7 @@ test_app::test_app(const Arguments& arguments):
test_app::~test_app()
{
- loader_::destroy();
+ loader.destroy();
}
int test_app::exec()
diff --git a/userconfig-sthalik@Windows-GNU.cmake b/userconfig-sthalik@Windows-GNU.cmake
index 84de67b2..0a7d7cc1 100644
--- a/userconfig-sthalik@Windows-GNU.cmake
+++ b/userconfig-sthalik@Windows-GNU.cmake
@@ -13,6 +13,7 @@ sets(STRING
list(APPEND CMAKE_IGNORE_PATH "c:/msys64" "c:/msys64/clang64")
list(APPEND CMAKE_IGNORE_PREFIX_PATH "c:/msys64" "c:/msys64/clang64")
+add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fconcepts-diagnostics-depth=3>)
add_compile_options(-fdiagnostics-color=always)
set(OpenCV_DIR "f:/dev/opentrack-depends/opencv/build-gcc/install" CACHE PATH "" FORCE)