From 573f8f2bcbfd86119e00a13fedc5abf2bf7deafb Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 23 Jan 2024 13:26:25 +0100 Subject: w --- src/scenery.hpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 5 deletions(-) (limited to 'src/scenery.hpp') diff --git a/src/scenery.hpp b/src/scenery.hpp index 61345ab6..2c28d936 100644 --- a/src/scenery.hpp +++ b/src/scenery.hpp @@ -4,6 +4,8 @@ #include "rotation.hpp" #include "object.hpp" #include +#include +#include #include #include @@ -18,13 +20,29 @@ enum class scenery_type : unsigned char { door, // todo remove it }; -struct scenery_proto : object_proto +struct generic_scenery_proto { - scenery_type sc_type = scenery_type::none; unsigned char active : 1 = false; - unsigned char closing : 1 = false; unsigned char interactive : 1 = false; + bool operator==(const generic_scenery_proto& p) const; +}; + +struct door_scenery_proto +{ + unsigned char active : 1 = false; + unsigned char interactive : 1 = false; + unsigned char closing : 1 = false; + + bool operator==(const door_scenery_proto& p) const; +}; + +using scenery_proto_variants = std::variant; + +struct scenery_proto : object_proto +{ + scenery_proto_variants subtype; + scenery_proto(); scenery_proto(const scenery_proto&); ~scenery_proto() noexcept override; @@ -33,13 +51,49 @@ struct scenery_proto : object_proto explicit operator bool() const; }; -struct scenery final : object +struct scenery; + +struct generic_scenery { - scenery_type sc_type : 3 = scenery_type::none; unsigned char active : 1 = false; + unsigned char interactive : 1 = false; + + void update(scenery& sc, size_t i, float 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); + + object_type type() const noexcept; + enum scenery_type scenery_type() const; + explicit operator generic_scenery_proto() const; + + generic_scenery(object_id id, struct chunk& c, const generic_scenery_proto& p); +}; + +struct door_scenery +{ unsigned char closing : 1 = false; + unsigned char active : 1 = false; unsigned char interactive : 1 = false; + void update(scenery& sc, size_t i, float 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); + + object_type type() const noexcept; + enum scenery_type scenery_type() const; + explicit operator door_scenery_proto() const; + + door_scenery(object_id id, struct chunk& c, const door_scenery_proto& p); +}; + +using scenery_variants = std::variant; + +struct scenery final : object +{ + scenery_variants subtype; + void update(size_t i, float dt) override; Vector2 ordinal_offset(Vector2b offset) const override; float depth_offset() const override; @@ -48,6 +102,10 @@ struct scenery final : object 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, struct chunk& c, + const scenery_proto_variants& variants); private: friend class world; -- cgit v1.2.3