diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-11 21:31:35 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-04-11 21:49:45 +0200 |
commit | 2c042d30d96827941e5052d4eca0cc03965cacc8 (patch) | |
tree | 21ad2b6e71890f41fec48ceafde8de22ae8fd6ba /src/scenery.hpp | |
parent | c362121f04ffe72eed17126affc9129bbb354c49 (diff) |
w
Diffstat (limited to 'src/scenery.hpp')
-rw-r--r-- | src/scenery.hpp | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/src/scenery.hpp b/src/scenery.hpp index 6729e462..32ba3742 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -1,6 +1,5 @@ #pragma once #include "object.hpp" -#include <type_traits> #include <variant> #include <Magnum/Math/Vector2.h> #include <Magnum/Magnum.h> @@ -17,21 +16,21 @@ enum class scenery_type : unsigned char { struct generic_scenery_proto { - unsigned char active : 1 = false; - unsigned char interactive : 1 = false; + bool active : 1 = false; + bool interactive : 1 = false; bool operator==(const generic_scenery_proto& p) const; - enum scenery_type scenery_type() const; + static enum scenery_type scenery_type(); }; struct door_scenery_proto { - unsigned char active : 1 = false; - unsigned char interactive : 1 = true; - unsigned char closing : 1 = false; + bool active : 1 = false; + bool interactive : 1 = true; + bool closing : 1 = false; bool operator==(const door_scenery_proto& p) const; - enum scenery_type scenery_type() const; + static enum scenery_type scenery_type(); }; using scenery_proto_variants = std::variant<generic_scenery_proto, door_scenery_proto>; @@ -51,63 +50,59 @@ struct scenery_proto : object_proto struct scenery; -struct generic_scenery +struct scenery : object { - unsigned char active : 1 = false; - unsigned char interactive : 1 = false; - - void update(scenery& sc, size_t& i, Ns dt); - Vector2 ordinal_offset(const scenery& sc, Vector2b offset) const; - bool can_activate(const scenery& sc, size_t i) const; - bool activate(scenery& sc, size_t i); - - enum scenery_type scenery_type() const; - explicit operator generic_scenery_proto() const; + float depth_offset() const override; + enum object_type type() const noexcept override; + virtual enum scenery_type scenery_type() const = 0; - generic_scenery(object_id id, class chunk& c, const generic_scenery_proto& p); +protected: + virtual explicit operator scenery_proto() const; + scenery(object_id id, class chunk& c, const scenery_proto& proto); }; -struct door_scenery +struct generic_scenery final : scenery { - unsigned char closing : 1 = false; - unsigned char active : 1 = false; - unsigned char interactive : 1 = false; + bool active : 1 = false; + bool interactive : 1 = false; - void update(scenery& sc, size_t& i, Ns dt); - Vector2 ordinal_offset(const scenery& sc, Vector2b offset) const; - bool can_activate(const scenery& sc, size_t i) const; - bool activate(scenery& sc, size_t i); + void update(size_t& i, const Ns& dt) override; + Vector2 ordinal_offset(Vector2b offset) const override; + bool can_activate(size_t i) const override; + bool activate(size_t i) override; - enum scenery_type scenery_type() const; - explicit operator door_scenery_proto() const; + enum scenery_type scenery_type() const override; + explicit operator scenery_proto() const override; + explicit operator generic_scenery_proto() const; - door_scenery(object_id id, class chunk& c, const door_scenery_proto& p); +private: + friend class world; + generic_scenery(object_id id, class chunk& c, const generic_scenery_proto& p, const scenery_proto& p0); }; -using scenery_variants = std::variant<generic_scenery, door_scenery>; - -struct scenery final : object +struct door_scenery final : scenery { - scenery_variants subtype; + bool closing : 1 = false; + bool active : 1 = false; + bool interactive : 1 = false; void update(size_t& i, const Ns& dt) override; Vector2 ordinal_offset(Vector2b offset) const override; - float depth_offset() const override; bool can_activate(size_t i) const override; bool activate(size_t i) override; - object_type type() const noexcept override; - explicit operator scenery_proto() const; - enum scenery_type scenery_type() const; - - static scenery_variants subtype_from_proto(object_id id, class chunk& c, const scenery_proto_variants& variants); + enum scenery_type scenery_type() const override; + explicit operator scenery_proto() const override; + explicit operator door_scenery_proto() const; private: friend class world; - scenery(object_id id, class chunk& c, const scenery_proto& proto); + door_scenery(object_id id, class chunk& c, const door_scenery_proto& p, const scenery_proto& p0); }; template<> struct object_type_<scenery> : std::integral_constant<object_type, object_type::scenery> {}; +template<> struct object_type_<generic_scenery> : std::integral_constant<object_type, object_type::scenery> {}; +template<> struct object_type_<door_scenery> : std::integral_constant<object_type, object_type::scenery> {}; template<> struct object_type_<scenery_proto> : std::integral_constant<object_type, object_type::scenery> {}; } // namespace floormat |