summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-04-13 21:05:01 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-04-13 21:08:46 +0200
commitb4f0ae962bdd07c01f7193631b6fa502b53351be (patch)
treeedb7a1bc4d0caf8636c5f1a99f05db3c7dcfd432
parentff2a12174c8bd8be75dadeb23c88b6f9a1f0e1da (diff)
split scenery-proto into its own file
-rw-r--r--editor/scenery-editor.hpp2
-rw-r--r--loader/scenery-cell.hpp3
-rw-r--r--serialize/savegame.cpp1
-rw-r--r--src/scenery-proto.cpp60
-rw-r--r--src/scenery-proto.hpp44
-rw-r--r--src/scenery-type.hpp9
-rw-r--r--src/scenery.cpp55
-rw-r--r--src/scenery.hpp49
-rw-r--r--src/world.cpp1
-rw-r--r--test/critter.cpp2
-rw-r--r--test/loader.cpp3
-rw-r--r--test/path-search.cpp2
-rw-r--r--test/save.cpp1
13 files changed, 126 insertions, 106 deletions
diff --git a/editor/scenery-editor.hpp b/editor/scenery-editor.hpp
index 873124a8..678b990f 100644
--- a/editor/scenery-editor.hpp
+++ b/editor/scenery-editor.hpp
@@ -1,5 +1,5 @@
#pragma once
-#include "src/scenery.hpp"
+#include "src/scenery-proto.hpp"
#include <map>
#include <memory>
#include <Corrade/Containers/String.h>
diff --git a/loader/scenery-cell.hpp b/loader/scenery-cell.hpp
index b33f9441..4529d637 100644
--- a/loader/scenery-cell.hpp
+++ b/loader/scenery-cell.hpp
@@ -1,7 +1,6 @@
#pragma once
#include "compat/safe-ptr.hpp"
-#include "src/scenery.hpp"
-#include <memory>
+#include "src/scenery-proto.hpp"
#include <cr/String.h>
#include <cr/Optional.h>
diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp
index 04f9c599..40e6cba4 100644
--- a/serialize/savegame.cpp
+++ b/serialize/savegame.cpp
@@ -9,6 +9,7 @@
#include "src/wall-atlas.hpp"
#include "src/anim-atlas.hpp"
#include "src/scenery.hpp"
+#include "src/scenery-proto.hpp"
#include "src/critter.hpp"
#include "src/light.hpp"
#include "src/world.hpp"
diff --git a/src/scenery-proto.cpp b/src/scenery-proto.cpp
new file mode 100644
index 00000000..6781d84f
--- /dev/null
+++ b/src/scenery-proto.cpp
@@ -0,0 +1,60 @@
+#include "scenery-proto.hpp"
+#include "compat/overloaded.hpp"
+
+namespace floormat {
+
+// ---------- generic_scenery_proto ----------
+
+bool generic_scenery_proto::operator==(const generic_scenery_proto& p) const = default;
+enum scenery_type generic_scenery_proto::scenery_type() { return scenery_type::generic; }
+
+// ---------- door_scenery_proto ----------
+
+bool door_scenery_proto::operator==(const door_scenery_proto& p) const = default;
+enum scenery_type door_scenery_proto::scenery_type() { return scenery_type::door; }
+
+// --- scenery_proto ---
+
+scenery_proto::scenery_proto() noexcept { type = object_type::scenery; }
+scenery_proto::~scenery_proto() noexcept = default;
+scenery_proto::operator bool() const { return atlas != nullptr; }
+
+scenery_proto& scenery_proto::operator=(const scenery_proto&) noexcept = default;
+scenery_proto::scenery_proto(const scenery_proto&) noexcept = default;
+scenery_proto& scenery_proto::operator=(scenery_proto&&) noexcept = default;
+scenery_proto::scenery_proto(scenery_proto&&) noexcept = default;
+
+enum scenery_type scenery_proto::scenery_type() const
+{
+ return std::visit(overloaded {
+ [](std::monostate) { return scenery_type::none; },
+ []<typename T>(const T&) { return T::scenery_type(); },
+ }, subtype
+ );
+}
+
+bool scenery_proto::operator==(const object_proto& e0) const
+{
+ if (type != e0.type)
+ return false;
+
+ if (!object_proto::operator==(e0))
+ return false;
+
+ const auto& sc = static_cast<const scenery_proto&>(e0);
+
+ if (subtype.index() != sc.subtype.index())
+ return false;
+
+ return std::visit(
+ [](const auto& a, const auto& b) -> bool {
+ if constexpr(std::is_same_v<std::decay_t<decltype(a)>, std::decay_t<decltype(b)>>)
+ return a == b;
+ else
+ fm_assert(false);
+ },
+ subtype, sc.subtype
+ );
+}
+
+} // namespace floormat
diff --git a/src/scenery-proto.hpp b/src/scenery-proto.hpp
new file mode 100644
index 00000000..c5889b04
--- /dev/null
+++ b/src/scenery-proto.hpp
@@ -0,0 +1,44 @@
+#pragma once
+#include "scenery-type.hpp"
+#include "object.hpp"
+#include <variant>
+
+namespace floormat {
+
+struct generic_scenery_proto
+{
+ bool active : 1 = false;
+ bool interactive : 1 = false;
+
+ bool operator==(const generic_scenery_proto& p) const;
+ static enum scenery_type scenery_type();
+};
+
+struct door_scenery_proto
+{
+ bool active : 1 = false;
+ bool interactive : 1 = true;
+ bool closing : 1 = false;
+
+ bool operator==(const door_scenery_proto& p) const;
+ static enum scenery_type scenery_type();
+};
+
+using scenery_proto_variants = std::variant<std::monostate, generic_scenery_proto, door_scenery_proto>;
+
+struct scenery_proto : object_proto
+{
+ scenery_proto_variants subtype; // todo! add std::monostate
+
+ scenery_proto() noexcept;
+ ~scenery_proto() noexcept override;
+ explicit operator bool() const;
+ bool operator==(const object_proto& proto) const override;
+ enum scenery_type scenery_type() const;
+ scenery_proto(const scenery_proto&) noexcept;
+ scenery_proto& operator=(const scenery_proto&) noexcept;
+ scenery_proto(scenery_proto&&) noexcept;
+ scenery_proto& operator=(scenery_proto&&) noexcept;
+};
+
+} // namespace floormat
diff --git a/src/scenery-type.hpp b/src/scenery-type.hpp
new file mode 100644
index 00000000..3879e225
--- /dev/null
+++ b/src/scenery-type.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace floormat {
+
+enum class scenery_type : unsigned char {
+ none, generic, door, COUNT,
+};
+
+} // namespace floormat
diff --git a/src/scenery.cpp b/src/scenery.cpp
index e0b62211..442b712c 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -1,70 +1,17 @@
#include "scenery.hpp"
+#include "scenery-proto.hpp"
#include "compat/assert.hpp"
#include "compat/exception.hpp"
-#include "compat/overloaded.hpp"
#include "tile-constants.hpp"
#include "anim-atlas.hpp"
#include "rotation.inl"
-#include "nanosecond.hpp"
#include "world.hpp"
#include "shaders/shader.hpp"
#include <mg/Functions.h>
namespace floormat {
-// ---------- generic_scenery_proto ----------
-bool generic_scenery_proto::operator==(const generic_scenery_proto& p) const = default;
-enum scenery_type generic_scenery_proto::scenery_type() { return scenery_type::generic; }
-
-// ---------- door_scenery_proto ----------
-
-bool door_scenery_proto::operator==(const door_scenery_proto& p) const = default;
-enum scenery_type door_scenery_proto::scenery_type() { return scenery_type::door; }
-
-// --- scenery_proto ---
-
-scenery_proto::scenery_proto() noexcept { type = object_type::scenery; }
-scenery_proto::~scenery_proto() noexcept = default;
-scenery_proto::operator bool() const { return atlas != nullptr; }
-
-scenery_proto& scenery_proto::operator=(const scenery_proto&) noexcept = default;
-scenery_proto::scenery_proto(const scenery_proto&) noexcept = default;
-scenery_proto& scenery_proto::operator=(scenery_proto&&) noexcept = default;
-scenery_proto::scenery_proto(scenery_proto&&) noexcept = default;
-
-enum scenery_type scenery_proto::scenery_type() const
-{
- return std::visit(overloaded {
- [](std::monostate) { return scenery_type::none; },
- []<typename T>(const T&) { return T::scenery_type(); },
- }, subtype
- );
-}
-
-bool scenery_proto::operator==(const object_proto& e0) const
-{
- if (type != e0.type)
- return false;
-
- if (!object_proto::operator==(e0))
- return false;
-
- const auto& sc = static_cast<const scenery_proto&>(e0);
-
- if (subtype.index() != sc.subtype.index())
- return false;
-
- return std::visit(
- [](const auto& a, const auto& b) -> bool {
- if constexpr(std::is_same_v<std::decay_t<decltype(a)>, std::decay_t<decltype(b)>>)
- return a == b;
- else
- fm_assert(false);
- },
- subtype, sc.subtype
- );
-}
// --- scenery ---
diff --git a/src/scenery.hpp b/src/scenery.hpp
index 8db32f91..6699fe2f 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -1,56 +1,15 @@
#pragma once
#include "object.hpp"
-#include <variant>
-#include <Magnum/Math/Vector2.h>
-#include <Magnum/Magnum.h>
+#include "scenery-type.hpp"
namespace floormat {
class chunk;
class anim_atlas;
class world;
-
-enum class scenery_type : unsigned char {
- none, generic, door, COUNT,
-};
-
-struct generic_scenery_proto
-{
- bool active : 1 = false;
- bool interactive : 1 = false;
-
- bool operator==(const generic_scenery_proto& p) const;
- static enum scenery_type scenery_type();
-};
-
-struct door_scenery_proto
-{
- bool active : 1 = false;
- bool interactive : 1 = true;
- bool closing : 1 = false;
-
- bool operator==(const door_scenery_proto& p) const;
- static enum scenery_type scenery_type();
-};
-
-using scenery_proto_variants = std::variant<std::monostate, generic_scenery_proto, door_scenery_proto>;
-
-struct scenery_proto : object_proto
-{
- scenery_proto_variants subtype; // todo! add std::monostate
-
- scenery_proto() noexcept;
- ~scenery_proto() noexcept override;
- explicit operator bool() const;
- bool operator==(const object_proto& proto) const override;
- enum scenery_type scenery_type() const;
- scenery_proto(const scenery_proto&) noexcept;
- scenery_proto& operator=(const scenery_proto&) noexcept;
- scenery_proto(scenery_proto&&) noexcept;
- scenery_proto& operator=(scenery_proto&&) noexcept;
-};
-
-struct scenery;
+struct scenery_proto;
+struct generic_scenery_proto;
+struct door_scenery_proto;
struct scenery : object
{
diff --git a/src/world.cpp b/src/world.cpp
index 821e4c65..1012b303 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -3,6 +3,7 @@
#include "object.hpp"
#include "critter.hpp"
#include "scenery.hpp"
+#include "scenery-proto.hpp"
#include "light.hpp"
#include "compat/shared-ptr-wrapper.hpp"
#include "compat/int-hash.hpp"
diff --git a/test/critter.cpp b/test/critter.cpp
index 72bb58cc..d9f50205 100644
--- a/test/critter.cpp
+++ b/test/critter.cpp
@@ -3,13 +3,13 @@
#include "compat/shared-ptr-wrapper.hpp"
#include "compat/function2.hpp"
#include "src/critter.hpp"
+#include "src/scenery-proto.hpp"
#include "src/world.hpp"
#include "src/wall-atlas.hpp"
#include "src/nanosecond.inl"
#include "src/log.hpp"
#include "src/point.inl"
#include "loader/loader.hpp"
-#include "src/scenery.hpp"
#include <cinttypes>
#include <cstdio>
diff --git a/test/loader.cpp b/test/loader.cpp
index e05508f5..4bd8e4f3 100644
--- a/test/loader.cpp
+++ b/test/loader.cpp
@@ -6,8 +6,7 @@
#include "src/ground-atlas.hpp"
#include "src/wall-atlas.hpp"
#include "src/anim-atlas.hpp"
-#include "src/scenery.hpp"
-#include <mg/Texture.h>
+#include "src/scenery-proto.hpp"
namespace floormat {
diff --git a/test/path-search.cpp b/test/path-search.cpp
index e3c11e28..90accd3a 100644
--- a/test/path-search.cpp
+++ b/test/path-search.cpp
@@ -4,7 +4,7 @@
#include "loader/loader.hpp"
#include "loader/wall-cell.hpp"
#include "src/world.hpp"
-#include "src/scenery.hpp"
+#include "src/scenery-proto.hpp"
#include "src/search-bbox.hpp"
#include "src/search-constants.hpp"
#include <Magnum/Math/Functions.h>
diff --git a/test/save.cpp b/test/save.cpp
index 5f2d8df3..8edb5b4d 100644
--- a/test/save.cpp
+++ b/test/save.cpp
@@ -2,6 +2,7 @@
#include "src/world.hpp"
#include "loader/loader.hpp"
#include "src/scenery.hpp"
+#include "src/scenery-proto.hpp"
#include "src/critter.hpp"
#include "src/light.hpp"
#include "src/ground-atlas.hpp"