summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/scenery.cpp50
-rw-r--r--src/scenery.hpp29
2 files changed, 35 insertions, 44 deletions
diff --git a/src/scenery.cpp b/src/scenery.cpp
index 03adc39e..dfb72b65 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -5,22 +5,13 @@
namespace floormat {
-scenery_proto::scenery_proto() noexcept : scenery_proto{scenery::none} {}
-scenery_proto::scenery_proto(scenery::none_tag_t) noexcept : frame{scenery::none} {}
-scenery_proto::scenery_proto(const std::shared_ptr<anim_atlas>& atlas, const scenery& frame) :
+scenery_proto::scenery_proto() noexcept = default;
+scenery_proto::scenery_proto(const std::shared_ptr<anim_atlas>& atlas, const scenery& frame) noexcept :
atlas{atlas}, frame{frame}
{}
-scenery_proto::scenery_proto(scenery::generic_tag_t, rotation r, const std::shared_ptr<anim_atlas>& atlas, bool passable, scenery::frame_t frame) :
- atlas{atlas}, frame{scenery::generic, r, *atlas, frame, passable}
-{}
-
-scenery_proto::scenery_proto(scenery::door_tag_t, rotation r, const std::shared_ptr<anim_atlas>& atlas, bool is_open) :
- atlas{atlas}, frame{scenery::door, r, *atlas, is_open}
-{}
-
scenery_proto& scenery_proto::operator=(const scenery_proto&) noexcept = default;
-
+scenery_proto::scenery_proto(const scenery_proto&) noexcept = default;
scenery_proto::operator bool() const noexcept { return atlas != nullptr; }
scenery_ref::scenery_ref(std::shared_ptr<anim_atlas>& atlas, scenery& frame) noexcept : atlas{atlas}, frame{frame} {}
@@ -39,36 +30,27 @@ scenery_ref::operator bool() const noexcept { return atlas != nullptr; }
scenery::scenery() noexcept : scenery{none_tag_t{}} {}
scenery::scenery(none_tag_t) noexcept : passable{true} {}
-scenery::scenery(generic_tag_t, rotation r, const anim_atlas& atlas, frame_t frame,
- bool passable, bool blocks_view, bool animated, bool active) :
- frame{frame}, r{r}, passable{passable},
- blocks_view{blocks_view}, active{active}, animated{animated},
- type{scenery_type::generic}
+scenery::scenery(generic_tag_t, const anim_atlas& atlas, rotation r, frame_t frame,
+ bool passable, bool blocks_view, bool animated, bool active, bool interactive) :
+ frame{frame}, r{r}, type{scenery_type::generic},
+ passable{passable}, blocks_view{blocks_view}, active{active}, animated{animated},
+ interactive{interactive}
{
+ fm_assert(r < rotation_COUNT);
fm_assert(frame < atlas.group(r).frames.size());
}
-scenery::scenery(door_tag_t, rotation r, const anim_atlas& atlas, bool is_open) :
+scenery::scenery(door_tag_t, const anim_atlas& atlas, rotation r, bool is_open) :
frame{frame_t(is_open ? 0 : atlas.group(r).frames.size()-1)},
- r{r},
- passable{is_open}, blocks_view{!is_open}, type{scenery_type::door}
-{}
+ r{r}, type{scenery_type::door},
+ passable{is_open}, blocks_view{!is_open}, interactive{true}
+{
+ fm_assert(r < rotation_COUNT);
+}
bool scenery::can_activate() const noexcept
{
-#if 0
- return true;
-#else
- switch (type)
- {
- default:
- return false;
- case scenery_type::object:
- return true;
- case scenery_type::door:
- return !active;
- }
-#endif
+ return interactive;
}
void scenery::update(float dt, const anim_atlas& anim)
diff --git a/src/scenery.hpp b/src/scenery.hpp
index c1e2b5ea..d34067d9 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <cstdint>
#include <memory>
+#include <type_traits>
namespace floormat {
@@ -13,7 +14,7 @@ enum class rotation : std::uint8_t {
constexpr inline rotation rotation_COUNT = rotation{8};
enum class scenery_type : std::uint8_t {
- none, generic, door, object,
+ none, generic, door,
};
struct scenery final
@@ -22,7 +23,6 @@ struct scenery final
struct generic_tag_t final {};
struct door_tag_t final {};
- static constexpr auto NO_FRAME = (std::uint16_t)-1;
static constexpr inline auto none = none_tag_t{};
static constexpr inline auto generic = generic_tag_t{};
static constexpr inline auto door = door_tag_t{};
@@ -30,19 +30,20 @@ struct scenery final
using frame_t = std::uint16_t;
float delta = 0;
- frame_t frame = NO_FRAME;
+ frame_t frame = 0;
rotation r : 3 = rotation::N;
+ scenery_type type : 3 = scenery_type::none;
std::uint8_t passable : 1 = false;
std::uint8_t blocks_view : 1 = false; // todo
std::uint8_t active : 1 = false;
std::uint8_t closing : 1 = false;
std::uint8_t animated : 1 = false; // todo
- scenery_type type : 3 = scenery_type::none;
+ std::uint8_t interactive : 1 = false;
scenery() noexcept;
scenery(none_tag_t) noexcept;
- scenery(generic_tag_t, rotation r, const anim_atlas& atlas, frame_t frame = 0, bool passable = false, bool blocks_view = false, bool animated = false, bool active = false);
- scenery(door_tag_t, rotation r, const anim_atlas& atlas, bool is_open = false);
+ scenery(generic_tag_t, const anim_atlas& atlas, rotation r, frame_t frame = 0, bool passable = false, bool blocks_view = false, bool animated = false, bool active = false, bool interactive = false);
+ scenery(door_tag_t, const anim_atlas& atlas, rotation r, bool is_open = false);
bool can_activate() const noexcept;
bool activate(const anim_atlas& atlas);
@@ -54,11 +55,19 @@ struct scenery_proto final {
scenery frame;
scenery_proto() noexcept;
- explicit scenery_proto(scenery::none_tag_t) noexcept;
- scenery_proto(const std::shared_ptr<anim_atlas>& atlas, const scenery& frame);
- scenery_proto(scenery::generic_tag_t, rotation r, const std::shared_ptr<anim_atlas>& atlas, bool passable = false, scenery::frame_t frame = 0);
- scenery_proto(scenery::door_tag_t, rotation r, const std::shared_ptr<anim_atlas>& atlas, bool is_open = false);
+ scenery_proto(const std::shared_ptr<anim_atlas>& atlas, const scenery& frame) noexcept;
scenery_proto& operator=(const scenery_proto&) noexcept;
+ scenery_proto(const scenery_proto&) noexcept;
+
+ template<typename... Ts>
+ scenery_proto(scenery::generic_tag_t, const std::shared_ptr<anim_atlas>& atlas, Ts&&... args) :
+ atlas{atlas}, frame{scenery::generic, *atlas, std::forward<Ts>(args)...}
+ {}
+
+ template<typename... Ts>
+ scenery_proto(scenery::door_tag_t, const std::shared_ptr<anim_atlas>& atlas, Ts&&... args) :
+ atlas{atlas}, frame{scenery::door, *atlas, std::forward<Ts>(args)...}
+ {}
operator bool() const noexcept;
};