From 458e0005690ea9d579588a0a12368fc2c2c9a93a Mon Sep 17 00:00:00 2001 From: untodesu Date: Tue, 1 Jul 2025 03:08:39 +0500 Subject: I hyper-focued on refactoring again - I put a cool-sounding "we are number one" remix on repeat and straight up grinded the entire repository to a better state until 03:09 AM. I guess I have something wrong in my brain that makes me do this shit --- game/client/entity/interpolation.cc | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 game/client/entity/interpolation.cc (limited to 'game/client/entity/interpolation.cc') diff --git a/game/client/entity/interpolation.cc b/game/client/entity/interpolation.cc new file mode 100644 index 0000000..6eb9e65 --- /dev/null +++ b/game/client/entity/interpolation.cc @@ -0,0 +1,63 @@ +#include "client/pch.hh" + +#include "client/entity/interpolation.hh" + +#include "core/math/constexpr.hh" + +#include "shared/entity/head.hh" +#include "shared/entity/transform.hh" +#include "shared/world/dimension.hh" + +#include "shared/coord.hh" + +#include "client/globals.hh" + +static void transform_interpolate(float alpha) +{ + auto group = globals::dimension->entities.group( + entt::get); + + for(auto [entity, interp, current, previous] : group.each()) { + interp.angles[0] = math::lerp(previous.angles[0], current.angles[0], alpha); + interp.angles[1] = math::lerp(previous.angles[1], current.angles[1], alpha); + interp.angles[2] = math::lerp(previous.angles[2], current.angles[2], alpha); + + // Figure out previous chunk-local floating-point coordinates transformed + // to the current WorldCoord's chunk domain coordinates; we're interpolating + // against these instead of using previous.position.local to prevent jittering + auto previous_shift = coord::to_relative(current.chunk, current.local, previous.chunk, previous.local); + auto previous_local = current.local + previous_shift; + + interp.chunk.x = current.chunk.x; + interp.chunk.y = current.chunk.y; + interp.chunk.z = current.chunk.z; + + interp.local.x = math::lerp(previous_local.x, current.local.x, alpha); + interp.local.y = math::lerp(previous_local.y, current.local.y, alpha); + interp.local.z = math::lerp(previous_local.z, current.local.z, alpha); + } +} + +static void head_interpolate(float alpha) +{ + auto group = globals::dimension->entities.group(entt::get); + + for(auto [entity, interp, current, previous] : group.each()) { + interp.angles[0] = math::lerp(previous.angles[0], current.angles[0], alpha); + interp.angles[1] = math::lerp(previous.angles[1], current.angles[1], alpha); + interp.angles[2] = math::lerp(previous.angles[2], current.angles[2], alpha); + + interp.offset.x = math::lerp(previous.offset.x, current.offset.x, alpha); + interp.offset.y = math::lerp(previous.offset.y, current.offset.y, alpha); + interp.offset.z = math::lerp(previous.offset.z, current.offset.z, alpha); + } +} + +void entity::interpolation::update(void) +{ + if(globals::dimension) { + auto alpha = static_cast(globals::fixed_accumulator) / static_cast(globals::fixed_frametime_us); + transform_interpolate(alpha); + head_interpolate(alpha); + } +} \ No newline at end of file -- cgit