2026-02-10 21:29:10 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
refactor: extract spline math, consolidate packet parsing, decompose TransportManager
Extract CatmullRomSpline (include/math/spline.hpp, src/math/spline.cpp) as a
standalone, immutable, thread-safe spline module with O(log n) binary segment
search and fused position+tangent evaluation — replacing the duplicated O(n)
evalTimedCatmullRom/orientationFromTangent pair in TransportManager.
Consolidate 7 copies of spline packet parsing into shared functions in
game/spline_packet.{hpp,cpp}: parseMonsterMoveSplineBody (WotLK/TBC),
parseMonsterMoveSplineBodyVanilla, parseClassicMoveUpdateSpline,
parseWotlkMoveUpdateSpline, and decodePackedDelta. Named SplineFlag constants
replace magic hex literals throughout.
Extract TransportPathRepository (game/transport_path_repository.{hpp,cpp}) from
TransportManager — owns path data, DBC loading, and path inference. Paths stored
as PathEntry wrapping CatmullRomSpline + metadata (zOnly, fromDBC, worldCoords).
TransportManager reduced from ~1200 to ~500 lines, focused on transport lifecycle
and server sync.
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
2026-04-11 08:30:28 +03:00
|
|
|
#include "game/transport_path_repository.hpp"
|
2026-02-10 21:29:10 -08:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <unordered_map>
|
2026-02-11 00:54:38 -08:00
|
|
|
#include <string>
|
2026-02-10 21:29:10 -08:00
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
#include <glm/gtc/quaternion.hpp>
|
|
|
|
|
|
|
|
|
|
namespace wowee::rendering {
|
|
|
|
|
class WMORenderer;
|
2026-03-06 23:01:11 -08:00
|
|
|
class M2Renderer;
|
2026-02-10 21:29:10 -08:00
|
|
|
}
|
|
|
|
|
|
2026-02-11 00:54:38 -08:00
|
|
|
namespace wowee::pipeline {
|
|
|
|
|
class AssetManager;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 21:29:10 -08:00
|
|
|
namespace wowee::game {
|
|
|
|
|
|
|
|
|
|
struct ActiveTransport {
|
|
|
|
|
uint64_t guid; // Entity GUID
|
|
|
|
|
uint32_t wmoInstanceId; // WMO renderer instance ID
|
|
|
|
|
uint32_t pathId; // Current path
|
2026-02-14 20:20:43 -08:00
|
|
|
uint32_t entry = 0; // GameObject entry (for MO_TRANSPORT path updates)
|
2026-02-11 00:54:38 -08:00
|
|
|
glm::vec3 basePosition; // Spawn position (base offset for path)
|
2026-02-10 21:29:10 -08:00
|
|
|
glm::vec3 position; // Current world position
|
|
|
|
|
glm::quat rotation; // Current world rotation
|
|
|
|
|
glm::mat4 transform; // Cached world transform
|
|
|
|
|
glm::mat4 invTransform; // Cached inverse for collision
|
|
|
|
|
|
2026-02-17 15:37:02 -08:00
|
|
|
// Player attachment state
|
2026-02-10 21:29:10 -08:00
|
|
|
bool playerOnBoard;
|
|
|
|
|
glm::vec3 playerLocalOffset;
|
|
|
|
|
|
|
|
|
|
// Optional deck boundaries
|
|
|
|
|
glm::vec3 deckMin;
|
|
|
|
|
glm::vec3 deckMax;
|
|
|
|
|
bool hasDeckBounds;
|
2026-02-11 00:54:38 -08:00
|
|
|
|
|
|
|
|
// Time-based animation (deterministic, no drift)
|
|
|
|
|
uint32_t localClockMs; // Local path time in milliseconds
|
|
|
|
|
bool hasServerClock; // Whether we've synced with server time
|
|
|
|
|
int32_t serverClockOffsetMs; // Offset: serverClock - localNow
|
|
|
|
|
bool useClientAnimation; // Use client-side path animation
|
2026-02-11 17:30:57 -08:00
|
|
|
bool clientAnimationReverse; // Run client animation in reverse along the selected path
|
2026-02-11 00:54:38 -08:00
|
|
|
float serverYaw; // Server-authoritative yaw (radians)
|
|
|
|
|
bool hasServerYaw; // Whether we've received server yaw
|
2026-02-12 02:27:59 -08:00
|
|
|
bool serverYawFlipped180; // Auto-correction when server yaw is consistently opposite movement
|
|
|
|
|
int serverYawAlignmentScore; // Hysteresis score for yaw flip detection
|
2026-02-11 00:54:38 -08:00
|
|
|
|
2026-03-29 20:14:45 -07:00
|
|
|
double lastServerUpdate; // Time of last server movement update
|
2026-02-11 00:54:38 -08:00
|
|
|
int serverUpdateCount; // Number of server updates received
|
2026-02-11 17:30:57 -08:00
|
|
|
|
|
|
|
|
// Dead-reckoning from latest authoritative updates (used only when updates are sparse).
|
|
|
|
|
glm::vec3 serverLinearVelocity;
|
|
|
|
|
float serverAngularVelocity;
|
|
|
|
|
bool hasServerVelocity;
|
2026-02-12 00:14:39 -08:00
|
|
|
bool allowBootstrapVelocity; // Disable DBC bootstrap when spawn/path mismatch is clearly invalid
|
2026-03-06 23:01:11 -08:00
|
|
|
bool isM2 = false; // True if rendered as M2 (not WMO), uses M2Renderer for transforms
|
2026-02-10 21:29:10 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TransportManager {
|
|
|
|
|
public:
|
|
|
|
|
TransportManager();
|
|
|
|
|
~TransportManager();
|
|
|
|
|
|
|
|
|
|
void setWMORenderer(rendering::WMORenderer* renderer) { wmoRenderer_ = renderer; }
|
2026-03-06 23:01:11 -08:00
|
|
|
void setM2Renderer(rendering::M2Renderer* renderer) { m2Renderer_ = renderer; }
|
2026-02-10 21:29:10 -08:00
|
|
|
|
|
|
|
|
void update(float deltaTime);
|
2026-02-14 20:20:43 -08:00
|
|
|
void registerTransport(uint64_t guid, uint32_t wmoInstanceId, uint32_t pathId, const glm::vec3& spawnWorldPos, uint32_t entry = 0);
|
2026-02-10 21:29:10 -08:00
|
|
|
void unregisterTransport(uint64_t guid);
|
|
|
|
|
|
|
|
|
|
ActiveTransport* getTransport(uint64_t guid);
|
2026-03-06 23:01:11 -08:00
|
|
|
const std::unordered_map<uint64_t, ActiveTransport>& getTransports() const { return transports_; }
|
2026-02-10 21:29:10 -08:00
|
|
|
glm::vec3 getPlayerWorldPosition(uint64_t transportGuid, const glm::vec3& localOffset);
|
|
|
|
|
glm::mat4 getTransportInvTransform(uint64_t transportGuid);
|
|
|
|
|
|
|
|
|
|
void loadPathFromNodes(uint32_t pathId, const std::vector<glm::vec3>& waypoints, bool looping = true, float speed = 18.0f);
|
|
|
|
|
void setDeckBounds(uint64_t guid, const glm::vec3& min, const glm::vec3& max);
|
|
|
|
|
|
2026-02-11 00:54:38 -08:00
|
|
|
// Load transport paths from TransportAnimation.dbc
|
|
|
|
|
bool loadTransportAnimationDBC(pipeline::AssetManager* assetMgr);
|
|
|
|
|
|
2026-02-14 20:20:43 -08:00
|
|
|
// Load transport paths from TaxiPathNode.dbc (world-coordinate paths for MO_TRANSPORT)
|
|
|
|
|
bool loadTaxiPathNodeDBC(pipeline::AssetManager* assetMgr);
|
|
|
|
|
|
|
|
|
|
// Check if a TaxiPathNode path exists for a given taxiPathId
|
|
|
|
|
bool hasTaxiPath(uint32_t taxiPathId) const;
|
|
|
|
|
|
|
|
|
|
// Assign a TaxiPathNode path to an existing transport (called when GO query response arrives)
|
|
|
|
|
// Returns true if the transport was updated
|
|
|
|
|
bool assignTaxiPathToTransport(uint32_t entry, uint32_t taxiPathId);
|
|
|
|
|
|
2026-02-11 00:54:38 -08:00
|
|
|
// Check if a path exists for a given GameObject entry
|
|
|
|
|
bool hasPathForEntry(uint32_t entry) const;
|
2026-02-11 17:30:57 -08:00
|
|
|
// Check if a path has meaningful XY travel (used to reject near-stationary false positives).
|
|
|
|
|
bool hasUsableMovingPathForEntry(uint32_t entry, float minXYRange = 1.0f) const;
|
2026-02-11 00:54:38 -08:00
|
|
|
|
2026-02-11 15:24:05 -08:00
|
|
|
// Infer a real moving DBC path by spawn position (for servers whose transport entry IDs
|
|
|
|
|
// don't map 1:1 to TransportAnimation.dbc entry IDs).
|
|
|
|
|
// Returns 0 when no suitable path match is found.
|
|
|
|
|
uint32_t inferMovingPathForSpawn(const glm::vec3& spawnWorldPos, float maxDistance = 1200.0f) const;
|
|
|
|
|
|
2026-02-12 15:38:39 -08:00
|
|
|
// Infer a DBC path by spawn position, optionally including z-only elevator paths.
|
|
|
|
|
// Returns 0 when no suitable path match is found.
|
|
|
|
|
uint32_t inferDbcPathForSpawn(const glm::vec3& spawnWorldPos,
|
|
|
|
|
float maxDistance,
|
|
|
|
|
bool allowZOnly) const;
|
|
|
|
|
|
2026-02-11 15:24:05 -08:00
|
|
|
// Choose a deterministic fallback moving DBC path for known server transport entries/displayIds.
|
|
|
|
|
// Returns 0 when no suitable moving path is available.
|
|
|
|
|
uint32_t pickFallbackMovingPath(uint32_t entry, uint32_t displayId) const;
|
|
|
|
|
|
2026-02-11 00:54:38 -08:00
|
|
|
// Update server-controlled transport position/rotation directly (bypasses path movement)
|
|
|
|
|
void updateServerTransport(uint64_t guid, const glm::vec3& position, float orientation);
|
|
|
|
|
|
|
|
|
|
// Enable/disable client-side animation for transports without server updates
|
|
|
|
|
void setClientSideAnimation(bool enabled) { clientSideAnimation_ = enabled; }
|
|
|
|
|
bool isClientSideAnimation() const { return clientSideAnimation_; }
|
|
|
|
|
|
2026-02-10 21:29:10 -08:00
|
|
|
private:
|
|
|
|
|
void updateTransportMovement(ActiveTransport& transport, float deltaTime);
|
|
|
|
|
void updateTransformMatrices(ActiveTransport& transport);
|
refactor: extract spline math, consolidate packet parsing, decompose TransportManager
Extract CatmullRomSpline (include/math/spline.hpp, src/math/spline.cpp) as a
standalone, immutable, thread-safe spline module with O(log n) binary segment
search and fused position+tangent evaluation — replacing the duplicated O(n)
evalTimedCatmullRom/orientationFromTangent pair in TransportManager.
Consolidate 7 copies of spline packet parsing into shared functions in
game/spline_packet.{hpp,cpp}: parseMonsterMoveSplineBody (WotLK/TBC),
parseMonsterMoveSplineBodyVanilla, parseClassicMoveUpdateSpline,
parseWotlkMoveUpdateSpline, and decodePackedDelta. Named SplineFlag constants
replace magic hex literals throughout.
Extract TransportPathRepository (game/transport_path_repository.{hpp,cpp}) from
TransportManager — owns path data, DBC loading, and path inference. Paths stored
as PathEntry wrapping CatmullRomSpline + metadata (zOnly, fromDBC, worldCoords).
TransportManager reduced from ~1200 to ~500 lines, focused on transport lifecycle
and server sync.
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
2026-04-11 08:30:28 +03:00
|
|
|
/// Legacy transport orientation from tangent (preserves original cross-product order).
|
|
|
|
|
static glm::quat orientationFromSplineTangent(const glm::vec3& tangent);
|
2026-02-10 21:29:10 -08:00
|
|
|
|
refactor: extract spline math, consolidate packet parsing, decompose TransportManager
Extract CatmullRomSpline (include/math/spline.hpp, src/math/spline.cpp) as a
standalone, immutable, thread-safe spline module with O(log n) binary segment
search and fused position+tangent evaluation — replacing the duplicated O(n)
evalTimedCatmullRom/orientationFromTangent pair in TransportManager.
Consolidate 7 copies of spline packet parsing into shared functions in
game/spline_packet.{hpp,cpp}: parseMonsterMoveSplineBody (WotLK/TBC),
parseMonsterMoveSplineBodyVanilla, parseClassicMoveUpdateSpline,
parseWotlkMoveUpdateSpline, and decodePackedDelta. Named SplineFlag constants
replace magic hex literals throughout.
Extract TransportPathRepository (game/transport_path_repository.{hpp,cpp}) from
TransportManager — owns path data, DBC loading, and path inference. Paths stored
as PathEntry wrapping CatmullRomSpline + metadata (zOnly, fromDBC, worldCoords).
TransportManager reduced from ~1200 to ~500 lines, focused on transport lifecycle
and server sync.
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
2026-04-11 08:30:28 +03:00
|
|
|
TransportPathRepository pathRepo_;
|
2026-02-10 21:29:10 -08:00
|
|
|
std::unordered_map<uint64_t, ActiveTransport> transports_;
|
|
|
|
|
rendering::WMORenderer* wmoRenderer_ = nullptr;
|
2026-03-06 23:01:11 -08:00
|
|
|
rendering::M2Renderer* m2Renderer_ = nullptr;
|
2026-02-11 02:23:37 -08:00
|
|
|
bool clientSideAnimation_ = false; // DISABLED - use server positions instead of client prediction
|
2026-03-29 20:14:45 -07:00
|
|
|
// double: float loses millisecond precision after ~4.5 hours (2^23 / 1000),
|
|
|
|
|
// causing transport path interpolation to visibly jerk in long play sessions.
|
|
|
|
|
double elapsedTime_ = 0.0;
|
2026-02-10 21:29:10 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace wowee::game
|