summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-22 21:03:49 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-22 21:03:49 +0100
commit2141477c69d379b02ca52e0df9171834b37aadd7 (patch)
tree347f865c403fd86e24ae6f1d2d327554d23f1c33 /src
parent4f458fba80cbcbfecf3fa54284e3004852bbc172 (diff)
scenery work
Diffstat (limited to 'src')
-rw-r--r--src/scenery.cpp53
-rw-r--r--src/scenery.hpp3
2 files changed, 29 insertions, 27 deletions
diff --git a/src/scenery.cpp b/src/scenery.cpp
index cf2c6e98..86561a13 100644
--- a/src/scenery.cpp
+++ b/src/scenery.cpp
@@ -56,6 +56,9 @@ scenery::scenery(float dt, frame_t frame, rotation r, bool passable, scenery_typ
void scenery::update(float dt, const anim_atlas& anim)
{
+ if (!active)
+ return;
+
switch (type)
{
default:
@@ -63,31 +66,31 @@ void scenery::update(float dt, const anim_atlas& anim)
case scenery_type::generic:
break;
case scenery_type::door:
- if (active)
- {
- const auto hz = std::uint8_t(anim.info().fps);
- const auto nframes = (int)anim.info().nframes;
- fm_debug_assert(anim.info().fps > 0 && anim.info().fps <= 0xff);
-
- delta += dt;
- const float frame_time = 1000.f/hz;
- const auto n = int(delta / frame_time);
- delta -= frame_time * n;
- fm_debug_assert(delta >= 0);
- const std::int8_t dir = passable ? 1 : -1;
- const int fr = frame + dir*n;
- active = fr > 0 && fr < nframes-1;
- passable = fr <= 0;
- frame = (frame_t)std::clamp(fr, 0, nframes-1);
- if (!active)
- delta = 0;
- }
+ const auto hz = std::uint8_t(anim.info().fps);
+ const auto nframes = (int)anim.info().nframes;
+ fm_debug_assert(anim.info().fps > 0 && anim.info().fps <= 0xff);
+
+ delta += dt;
+ const float frame_time = 1.f/hz;
+ const auto n = int(delta / frame_time);
+ delta -= frame_time * n;
+ fm_debug_assert(delta >= 0);
+ const std::int8_t dir = closing ? 1 : -1;
+ const int fr = frame + dir*n;
+ active = fr > 0 && fr < nframes-1;
+ passable = fr <= 0;
+ frame = (frame_t)std::clamp(fr, 0, nframes-1);
+ if (!active)
+ delta = 0;
break;
}
}
bool scenery::activate(const anim_atlas& atlas)
{
+ if (active)
+ return false;
+
switch (type)
{
default:
@@ -95,13 +98,11 @@ bool scenery::activate(const anim_atlas& atlas)
case scenery_type::generic:
break;
case scenery_type::door:
- if (!active)
- {
- fm_assert(frame == 0 || frame == atlas.info().nframes-1);
- active = true;
- return true;
- }
- break;
+ fm_assert(frame == 0 || frame == atlas.info().nframes-1);
+ closing = frame == 0;
+ frame += closing ? 1 : -1;
+ active = true;
+ return true;
}
return false;
}
diff --git a/src/scenery.hpp b/src/scenery.hpp
index fadf4da8..68bb084a 100644
--- a/src/scenery.hpp
+++ b/src/scenery.hpp
@@ -34,7 +34,8 @@ struct scenery final
rotation r : 3 = rotation::N;
std::uint8_t passable : 1 = false;
std::uint8_t active : 1 = false;
- scenery_type type : 3 = scenery_type::none;
+ std::uint8_t closing : 1 = true;
+ scenery_type type : 2 = scenery_type::none;
scenery() noexcept;
scenery(none_tag_t) noexcept;