diff options
Diffstat (limited to 'src/game/client')
| -rw-r--r-- | src/game/client/entity/camera.cc | 6 | ||||
| -rw-r--r-- | src/game/client/entity/factory.cc | 5 | ||||
| -rw-r--r-- | src/game/client/entity/interpolation.cc | 13 | ||||
| -rw-r--r-- | src/game/client/entity/player_move.cc | 1 |
4 files changed, 22 insertions, 3 deletions
diff --git a/src/game/client/entity/camera.cc b/src/game/client/entity/camera.cc index 2009066..27603cf 100644 --- a/src/game/client/entity/camera.cc +++ b/src/game/client/entity/camera.cc @@ -8,6 +8,7 @@ #include "core/math/angles.hh" +#include "shared/entity/grounded.hh" #include "shared/entity/head.hh" #include "shared/entity/transform.hh" #include "shared/entity/velocity.hh" @@ -87,7 +88,7 @@ void camera::update(void) const auto& head = globals::dimension->entities.get<client::HeadIntr>(globals::player); const auto& transform = globals::dimension->entities.get<client::TransformIntr>(globals::player); - const auto& velocity = globals::dimension->entities.get<Velocity>(globals::player); + const auto& velocity = globals::dimension->entities.get<client::VelocityIntr>(globals::player); camera::angles = transform.angles + head.angles; camera::position_chunk = transform.chunk; @@ -98,8 +99,7 @@ void camera::update(void) auto client_angles = camera::angles; - if(!toggles::get(TOGGLE_PM_FLIGHT)) { - // Apply the quake-like view rolling + if(!toggles::get(TOGGLE_PM_FLIGHT) && globals::dimension->entities.try_get<Grounded>(globals::player)) { client_angles[2] = math::radians(-camera::roll_angle.get_value() * glm::dot(velocity.value / PMOVE_MAX_SPEED_GROUND, right_vector)); } diff --git a/src/game/client/entity/factory.cc b/src/game/client/entity/factory.cc index f4724c5..94a9698 100644 --- a/src/game/client/entity/factory.cc +++ b/src/game/client/entity/factory.cc @@ -5,6 +5,7 @@ #include "shared/entity/factory.hh" #include "shared/entity/head.hh" #include "shared/entity/transform.hh" +#include "shared/entity/velocity.hh" #include "shared/world/dimension.hh" @@ -24,6 +25,10 @@ void client::create_player(Dimension* dimension, entt::entity entity) dimension->entities.emplace_or_replace<client::TransformIntr>(entity, transform); dimension->entities.emplace_or_replace<client::TransformPrev>(entity, transform); + const auto& velocity = dimension->entities.get<Velocity>(entity); + dimension->entities.emplace_or_replace<client::VelocityIntr>(entity, velocity); + dimension->entities.emplace_or_replace<client::VelocityPrev>(entity, velocity); + if(globals::sound_ctx) { dimension->entities.emplace_or_replace<SoundEmitter>(entity); } diff --git a/src/game/client/entity/interpolation.cc b/src/game/client/entity/interpolation.cc index 69fd487..86af971 100644 --- a/src/game/client/entity/interpolation.cc +++ b/src/game/client/entity/interpolation.cc @@ -6,6 +6,7 @@ #include "shared/entity/head.hh" #include "shared/entity/transform.hh" +#include "shared/entity/velocity.hh" #include "shared/world/dimension.hh" @@ -53,11 +54,23 @@ static void head_interpolate(float alpha) } } +static void velocity_interpolate(float alpha) +{ + auto group = globals::dimension->entities.group<client::VelocityIntr>(entt::get<Velocity, client::VelocityPrev>); + + for(auto [entity, interp, current, previous] : group.each()) { + interp.value[0] = glm::mix(previous.value[0], current.value[0], alpha); + interp.value[1] = glm::mix(previous.value[1], current.value[1], alpha); + interp.value[2] = glm::mix(previous.value[2], current.value[2], alpha); + } +} + void interpolation::update(void) { if(globals::dimension) { auto alpha = static_cast<float>(globals::fixed_accumulator) / static_cast<float>(globals::fixed_frametime_us); transform_interpolate(alpha); head_interpolate(alpha); + velocity_interpolate(alpha); } }
\ No newline at end of file diff --git a/src/game/client/entity/player_move.cc b/src/game/client/entity/player_move.cc index 14d64cc..edf9150 100644 --- a/src/game/client/entity/player_move.cc +++ b/src/game/client/entity/player_move.cc @@ -161,6 +161,7 @@ void player_move::fixed_update(void) // Interpolation - preserve current component states globals::dimension->entities.emplace_or_replace<client::TransformPrev>(globals::player, transform); + globals::dimension->entities.emplace_or_replace<client::VelocityPrev>(globals::player, velocity); glm::fvec3 forward, right; math::vectors(glm::fvec3(0.0f, head.angles[1], 0.0f), &forward, &right, nullptr); |
