Kelsidavis-WoWee/include/game/transport_clock_sync.hpp
Pavel Okhlopkov 39719cac82 refactor: decompose TransportManager and upgrade Entity to CatmullRom splines
TransportManager decomposition:
- Extract TransportClockSync: server clock offset, yaw flip detection,
  velocity bootstrap, client/server mode switching
- Extract TransportAnimator: spline evaluation, Z clamping, orientation
  from server yaw or spline tangent
- Slim TransportManager to thin orchestrator delegating to ClockSync and
  Animator; add pushTransform() helper to deduplicate WMO/M2 renderer calls
- Remove legacy orientationFromSplineTangent (now uses
  CatmullRomSpline::orientationFromTangent)

Entity path following upgrade:
- Replace pathPoints_/pathSegDists_ linear lerp with
  std::optional<CatmullRomSpline> activeSpline_
- startMoveAlongPath builds SplineKeys with distance-proportional timing
- updateMovement evaluates CatmullRomSpline for smooth Catmull-Rom
  interpolation matching server-side creature movement
- Reset activeSpline_ on setPosition/startMoveTo to prevent stale state

Tests:
- Add test_transport_components (9 cases): ClockSync client/server/reverse
  modes, yaw flip detection, Animator position eval, server yaw, Z clamping
- Link spline.cpp into test_entity for CatmullRomSpline dependency

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
2026-04-11 09:50:38 +03:00

49 lines
1.6 KiB
C++

// include/game/transport_clock_sync.hpp
// Clock synchronization and yaw correction for transports.
// Extracted from TransportManager (Phase 3a of spline refactoring).
#pragma once
#include <glm/glm.hpp>
#include <cstdint>
namespace wowee::math { class CatmullRomSpline; }
namespace wowee::game {
struct ActiveTransport;
struct PathEntry;
/// Manages clock sync, server-yaw correction, and velocity bootstrap for a single transport.
class TransportClockSync {
public:
/// Compute pathTimeMs for a transport given current elapsed time and deltaTime.
/// Returns false if the transport should use raw server position (no interpolation).
[[nodiscard]] bool computePathTime(
ActiveTransport& transport,
const math::CatmullRomSpline& spline,
double elapsedTime,
float deltaTime,
uint32_t& outPathTimeMs) const;
/// Process a server position update: update clock offset, detect yaw flips,
/// bootstrap velocity, and switch between client/server driven modes.
void processServerUpdate(
ActiveTransport& transport,
const PathEntry* pathEntry,
const glm::vec3& position,
float orientation,
double elapsedTime);
private:
/// Detect and apply 180-degree yaw correction based on movement vs heading alignment.
void updateYawAlignment(
ActiveTransport& transport,
const glm::vec3& velocity) const;
/// Bootstrap velocity from nearest DBC path segment on first authoritative sample.
void bootstrapVelocityFromPath(
ActiveTransport& transport,
const PathEntry& pathEntry) const;
};
} // namespace wowee::game