summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-10 18:02:29 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-10 18:02:29 +0100
commit29bdd5f2170b9d46a8b3b0973c4c0845d6a2b61e (patch)
treede0e6f19b1c6fc12326afa092e8f13c011d8f8eb
parentb17c955193cbcc0bc774cdf09022b40abf80f768 (diff)
editor: reduce struct character size
-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: