summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/character.cpp9
-rw-r--r--editor/character.hpp3
2 files changed, 6 insertions, 6 deletions
diff --git a/editor/character.cpp b/editor/character.cpp
index a971434d..845f8345 100644
--- a/editor/character.cpp
+++ b/editor/character.cpp
@@ -62,10 +62,11 @@ character_wip::~character_wip() = default;
int character_wip::allocate_frame_time(float dt)
{
- delta += dt;
- auto ret = (int)(delta*framerate);
- delta -= ret;
- delta = std::fmax(0.f, delta);
+ int d = int(delta) + int(65535u * dt);
+ constexpr int framerate_ = 65535/framerate;
+ static_assert(framerate_ > 0);
+ auto ret = d / framerate_;
+ delta = (std::uint16_t)std::clamp(d - ret*65535, 0, 65535);
return ret;
}
diff --git a/editor/character.hpp b/editor/character.hpp
index 86f634c5..7172415c 100644
--- a/editor/character.hpp
+++ b/editor/character.hpp
@@ -16,9 +16,8 @@ struct character_wip final
std::shared_ptr<anim_atlas> walk_anim;
global_coords pos;
- std::size_t frame = 0;
- float delta = 0;
Vector2 offset;
+ std::uint16_t delta = 0, frame = 0;
rotation r = rotation::NE;
private: