#1 - ClientWorldController refactoring

This commit is contained in:
Martin Slachta
2026-08-03 23:30:18 +02:00
parent f4174eb0c7
commit a097f4d4b0
35 changed files with 899 additions and 1010 deletions
@@ -9,19 +9,16 @@
namespace tw::net {
EntityPositionInterpolator::EntityPositionInterpolator(
entt::registry* registry, entt::entity player_entity, size_t bufferingIntervalInMillis
entt::registry* registry, size_t bufferingIntervalInMillis
) : m_registry(registry),
m_player_entity(player_entity),
m_bufferingIntervalInMillis(bufferingIntervalInMillis)
{
}
{ }
void EntityPositionInterpolator::register_entity(entt::entity entity) {
m_registry->emplace<EntityPositionInterpolation>(entity, glm::vec3());
}
void EntityPositionInterpolator::add_position_for_entity(entt::entity entity, glm::vec3 position) {
void EntityPositionInterpolator::set_position(Clock::time_point time_point, entt::entity entity, glm::vec3 position) {
auto* interpolation = m_registry->try_get<EntityPositionInterpolation>(entity);
if(interpolation == nullptr) {
spdlog::warn("Attempt to add position for non-registered entity {}", (uint32_t)entity);
@@ -31,7 +28,7 @@ void EntityPositionInterpolator::add_position_for_entity(entt::entity entity, gl
interpolation->push(Clock::now(), position);
}
glm::vec3 EntityPositionInterpolator::get_position_for_entity(entt::entity entity) {
glm::vec3 EntityPositionInterpolator::get_position(Clock::time_point time_point, entt::entity entity) {
auto* interpolation = m_registry->try_get<EntityPositionInterpolation>(entity);
if(interpolation == nullptr) {
spdlog::warn("Attempt to get position for non-registered entity {}", (uint32_t)entity);
@@ -44,12 +41,10 @@ glm::vec3 EntityPositionInterpolator::get_position_for_entity(entt::entity entit
return glm::mix(from, to, value);
}
void EntityPositionInterpolator::update() {
void EntityPositionInterpolator::interpolate_smoothed_entities(Clock::time_point time_point) {
m_registry->view<EntityPositionInterpolation, Transform>()
.each([&](const auto entity, const EntityPositionInterpolation& interpolation, Transform& ts) {
auto now = Clock::now() - std::chrono::milliseconds(m_bufferingIntervalInMillis);
auto [from, to, value] = interpolation.get_values_around(now);
auto [from, to, value] = interpolation.get_values_around(time_point);
ts.set_position(glm::mix(from, to, value));
});
}