Commit graph

331 commits

Author SHA1 Message Date
Kelsi
83b364a417 Fix jump collision with slope grace period
Add grounded state grace to prevent fall stumbles when descending slopes while maintaining proper jump physics.
2026-02-09 01:01:25 -08:00
Kelsi
16485e691c Convert ActivitySoundManager to use AudioEngine
Replace process-spawning with direct AudioEngine calls for jump, landing, and melee swing sounds.
2026-02-09 01:01:24 -08:00
Kelsi
ffa47f62d6 Implement 3D positional audio with distance attenuation
Add full 3D spatialization support to AudioEngine with inverse distance attenuation model for NPC voices and mount sounds.
2026-02-09 01:01:21 -08:00
Kelsi
af0a3a4daf Fix jump collision and WMO doodad rotation bugs
Prevent character from being yanked down during upward jump movement, and correct quaternion rotation for holiday decorations.
2026-02-09 00:41:19 -08:00
Kelsi
28330adfb0 Eliminate per-frame allocations in M2 renderer to reduce CPU stutter
Use persistent vectors for animation work indices, futures, and glow sprites instead of allocating each frame.
2026-02-09 00:41:07 -08:00
Kelsi
bd3f1921d1 Replace process-spawning audio with miniaudio for non-blocking playback
Eliminates severe stuttering from fork/exec + disk I/O by streaming audio directly from memory using miniaudio library.
2026-02-09 00:40:50 -08:00
Kelsi
c047446fb7 Add dynamic memory-based asset caching and aggressive loading
- Add MemoryMonitor class for dynamic cache sizing based on available RAM
- Increase terrain load radius to 8 tiles (17x17 grid, 289 tiles)
- Scale worker threads to 75% of logical cores (no cap)
- Increase cache budget to 80% of available RAM, max file size to 50%
- Increase M2 render distance: 1200 units during taxi, 800 when >2000 instances
- Fix camera positioning during taxi flights (external follow mode)
- Add 2-second landing cooldown to prevent re-entering taxi mode on lag
- Update interval reduced to 33ms for faster streaming responsiveness

Optimized for high-memory systems while scaling gracefully to lower-end hardware.
Cache and render distances now fully utilize available VRAM on minimum spec GPUs.
2026-02-08 23:15:26 -08:00
Kelsi
27d0496894 Add 1GB RAM cache for decompressed MPQ files
Eliminates repeated MPQ decompression overhead by caching decompressed
files in RAM with LRU eviction. Major performance improvement for file access.

Problem:
- Every readFile() call decompresses from MPQ (expensive!)
- M2 models, textures, WMO files decompressed repeatedly
- No caching of decompressed data
- MPQ decompression is CPU-intensive (zlib/bzip2)

Solution:
- Added 1GB LRU file cache to AssetManager
- Cache hit: instant return of decompressed data
- Cache miss: decompress once, cache for future access
- LRU eviction when cache full (removes least recently used)
- Don't cache files >100MB (avoid giant WMO chunks)
- Thread-safe with existing readMutex

Implementation:
- CachedFile struct: data + lastAccessTime
- fileCacheAccessCounter for LRU tracking
- Hit/miss statistics for monitoring
- Budget: 1GB (modern RAM easily handles this)

Performance impact:
- First load: same speed (decompress + cache)
- Subsequent loads: instant (no decompression)
- Expected 70-90% hit rate during normal play
- Huge benefit for frequently accessed models

Cache stats logged on shutdown to monitor effectiveness.
2026-02-08 22:37:29 -08:00
Kelsi
34cd5a161d Reduce wave amplitude to fix tile boundary gaps
Each water tile generates waves independently using local coordinates,
causing height mismatches at tile boundaries. Reduced amplitude minimizes
visible seams.

Problem:
- Waves calculated per-tile using local vertex positions (aPos)
- Adjacent tiles have different local coords at shared boundary
- Wave height discontinuity creates visible gaps between tiles

Solution:
- Reduced ocean wave amplitude: 0.25 → 0.06 (75% reduction)
- Reduced canal wave amplitude: 0.10 → 0.04
- Kept frequency and speed for subtle animation
- Waves still visible but gaps minimized

Technical note: Proper fix would be world-space wave calculation, but
requires passing tile offset to shader. This amplitude reduction is
simpler and effective for smooth ocean appearance.
2026-02-08 22:35:11 -08:00
Kelsi
26e984b60f Skip all camera controller logic during taxi flights
Taxi flights are externally controlled - no need for collision detection,
movement processing, or input handling. Massive performance improvement.

Changes:
- Early return in CameraController::update() when externalFollow_ is true
- Skips all collision queries (terrain, WMO, M2)
- Skips all movement physics (gravity, swimming, jumping)
- Skips input processing (keyboard, mouse)
- Skips camera collision raycasts

Performance impact:
- 100% elimination of ~17 collision queries per frame during taxi
- No wasted cycles on movement code when position is scripted
- Camera still updates position via setExternalFollow system
- Smooth taxi flights with zero collision overhead

This addresses the core issue: "shouldn't be looking for collision at all
during taxi" - now it doesn't!
2026-02-08 22:33:45 -08:00
Kelsi
6158d56316 Add collision query caching to reduce map traversal overhead
Caches floor height checks to skip redundant collision queries when position
hasn't changed significantly. Major performance improvement during movement.

Problem:
- 17+ collision queries per frame during movement
- getFloorHeight calls expensive (WMO/terrain/M2 raycasts)
- Same queries repeated when barely moving

Solution:
- Cache last collision check position and result
- Skip checks if moved < 15cm (COLLISION_CACHE_DISTANCE)
- Update cache when threshold exceeded or result changes

Implementation:
- Added lastCollisionCheckPos_, cachedFloorHeight_, hasCachedFloor_
- Check distance moved before main ground height query
- Reuse cached floor height for micro-movements
- Full collision check only when meaningfully repositioned

Performance impact:
- Stationary/slow: ~90% reduction in collision queries
- Fast movement: Still helps on same-tile micro-adjustments
- No accuracy loss (15cm is smaller than collision step size)

This addresses "computationally heavy" operations during map traversal.
2026-02-08 22:30:37 -08:00
Kelsi
27d550d521 Break up regular wave pattern with randomized phases and octaves
Eliminates visible grid symmetry when viewing ocean from altitude by adding
pseudo-random phase offsets and multiple wave frequencies.

Changes:
- Added position-based hash functions for pseudo-random phase offsets
- Phase-shifted primary waves (w1, w2) by hash * 2π
- Added 2 higher-frequency detail waves (w3, w4) at lower amplitudes
- Detail waves: 1.7x-2.1x frequency, 0.28-0.35x amplitude
- Different speeds and directions for each octave

Result: Natural-looking ocean with broken symmetry visible from altitude.
No more obvious grid pattern or repetitive crests.

The hash function creates consistent randomness per vertex position,
breaking the regular sine/cosine pattern without performance impact.
2026-02-08 22:28:26 -08:00
Kelsi
e98e0562b8 Fill water tile gaps at coastlines with neighbor checking
Fixes visible square gaps in ocean near coastlines by rendering masked tiles
if they have any water neighbors. Creates smoother, more natural coastlines.

Implementation:
- Check 8 neighboring tiles when a tile is masked out
- If any neighbor is water, render the edge tile anyway
- Creates 1-tile overlap at coastline boundaries
- Fills square gaps between water tiles

Before: Hard square edges with missing ocean tiles at coast
After: Continuous water coverage with smooth blended coastlines

The straight-line grid artifacts are reduced by ensuring adjacent water
tiles connect properly instead of leaving rectangular voids.
2026-02-08 22:27:11 -08:00
Kelsi
709138cf5d Relax aggressive taxi culling to show more detail
With VRAM model caching eliminating loading hitches, we can now render
much more detail during taxi flights for better visual quality.

Changes:
- boundRadius threshold: 15.0 → 2.0 (now show buildings, trees, large props)
- Foliage: was skipping ALL, now only skip small bushes/flowers < 5 units
- Trees: now visible (removed collisionTreeTrunk blanket skip)
- Underwater: -5.0 → -10.0 (only skip very deep objects)

Before: Only massive buildings visible, world looked empty
After: Buildings, trees, large props visible for immersive flight experience

Performance remains good due to persistent VRAM caching from earlier optimization.
2026-02-08 22:24:11 -08:00
Kelsi
08f0b4d028 Simplify foam to fix grid artifact
Removed complex noise-based foam that created visible grid pattern.
Replaced with simple subtle highlight on highest wave peaks only.

Kept the increased wave strength (bigger, more visible ocean waves).
2026-02-08 22:22:58 -08:00
Kelsi
3cab27060c Increase wave strength and add shoreline foam
Ocean waves are now much more pronounced, and foam appears on shorelines
in addition to wave crests.

Wave strength increases:
- Amplitude: 0.12 → 0.25 (ocean), 0.07 → 0.10 (canals)
- Frequency: 0.18 → 0.22 (ocean) - more waves per distance
- Speed: 1.60 → 2.00 (ocean) - faster wave motion

Shoreline foam:
- Appears on shallow/near-camera water (20-80 unit range)
- Uses upward-facing surface detection (horizontal = shore)
- Combined with wave crest foam for realistic effect
- Animated with same noise pattern as wave foam

Wave crest foam improvements:
- Lower threshold (0.15 vs 0.25) - more visible
- Increased intensity (0.85 vs 0.65)
- Faster animation (time * 0.8)
- Higher frequency noise (50.0 vs 40.0)

Result: Ocean now has visible motion from distance and foam on beaches.
2026-02-08 22:20:45 -08:00
Kelsi
e7ff0ce0ce Add distance-based water opacity and procedural ocean foam
Makes distant water more opaque to hide underwater objects and improve
visual quality during flight. Also adds animated foam on wave crests.

Distance-based opacity:
- Water becomes more opaque from 80-400 units distance
- Smoothstep fade adds up to 50% opacity at far distances
- Hides underwater M2 models and terrain from aerial view
- Max alpha increased from 0.82 to 0.95 for distant water

Procedural foam:
- Generated on wave peaks (positive WaveOffset values)
- Uses noise function for natural foam texture
- Animated with time and texture coordinates
- Adds white highlights to wave crests for ocean realism

This improves taxi flight visuals by making oceans look more solid
and realistic from altitude, similar to authentic WoW.
2026-02-08 22:14:54 -08:00
Kelsi
11dbca7413 Fix character attachment to follow mount's full rotation
Character now properly rotates with the mount during flight instead of just
bobbing up and down. This fixes the issue where the character appeared to
float away from the mount during rolls and pitch changes.

Implementation:
- Create rotation matrix from mount's pitch, roll, yaw
- Transform rider offset through rotation (local → world space)
- Apply same rotation to character model (glued to mount)
- Character stays properly seated during all mount movements

Before: Character only offset vertically, sliding around during banking
After: Character rotates with mount, stays firmly attached during all maneuvers
2026-02-08 22:11:40 -08:00
Kelsi
71b52046e0 Keep M2 models permanently in VRAM to eliminate loading hitches
Modern GPUs have 8-16GB VRAM - leverage this to cache all M2 models permanently.

Changes:
- Disabled cleanupUnusedModels() call when tiles unload
- Models now stay in VRAM after initial load, even when tiles unload
- Increased taxi mounting delay from 3s to 5s for more precache time
- Added logging: M2 model count, instance count, and GPU upload duration
- Added debug logging when M2 models are uploaded per tile

This fixes the "building pops up then pause" issue - models were being:
1. Loaded when tile loads
2. Unloaded when tile unloads (behind taxi)
3. Re-loaded when flying through again (causing hitch)

Now models persist in VRAM permanently (few hundred MB for typical session).
First pass loads to VRAM, subsequent passes are instant.
2026-02-08 22:08:42 -08:00
Kelsi
92031102e4 Add mount pitch and roll for realistic taxi flight animation
Flying mounts now tilt and bank realistically during taxi flights:
- Pitch (up/down): calculated from spline tangent's z-component (altitude change)
- Roll (banking): proportional to turn rate, clamped to ~40 degrees
- Yaw: existing horizontal orientation from spline direction

Implementation:
- Added mountPitch_ and mountRoll_ to Renderer (radians)
- Updated TaxiOrientationCallback to pass yaw, pitch, roll
- Calculate pitch using asin(tangent.z) for altitude tilt
- Calculate roll from yaw change rate: -orientDiff * 2.5, clamped to ±0.7 rad
- Applied to mount rotation: glm::vec3(pitch, roll, yaw)

This fixes the "weirdness" where mounts flew sideways or without natural banking.
2026-02-08 22:05:38 -08:00
Kelsi
2e0a7e0039 Fix taxi mount orientation and eliminate tile loading hitches
Fixes two critical taxi flight issues:

1. Mount orientation now correctly faces flight direction:
   - Prevent camera controller from updating facingYaw during taxi (externalFollow_ check)
   - Taxi orientation callback system updates mount rotation from spline tangent
   - Initial orientation set when flight starts
   - Smooth Catmull-Rom spline interpolation for natural curved paths

2. Eliminate frame hitches from tile loading during flight:
   - New taxiFlightStartCallback uploads ALL precached tiles to GPU before flight begins
   - Previously tiles loaded async during 3s mount delay but uploaded 1/frame during flight
   - Now processAllReadyTiles() blocks briefly after mount delay to batch upload everything
   - Combined with 2.0s terrain update interval and aggressive culling for smooth flight

Additional optimizations:
   - Aggressive taxi culling: skip models <15 units, all foliage/trees, underwater objects
   - Max render distance reduced to 150 units during taxi
   - Movement heartbeat packets disabled during taxi (server controls position)
   - Reduced taxi speed from 32 to 18 units/sec to prevent streaming overload
2026-02-08 22:00:33 -08:00
Kelsi
536b3cea48 Implement comprehensive taxi flight optimizations and proper spline paths
Major improvements:
- Load TaxiPathNode.dbc for actual curved flight paths (no more flying through terrain)
- Add 3-second mounting delay with terrain precaching for entire route
- Implement LOD system for M2 models with distance-based quality reduction
- Add circular terrain loading pattern (13 tiles vs 25, 48% reduction)
- Increase terrain cache from 2GB to 8GB for modern systems

Performance optimizations during taxi:
- Cull small M2 models (boundRadius < 3.0) - not visible from altitude
- Disable particle systems (weather, smoke, M2 emitters) - saves ~7000 particles
- Disable specular lighting on M2 models - saves Blinn-Phong calculations
- Disable shadow mapping on M2 models - saves shadow map sampling and PCF

Technical details:
- Parse TaxiPathNode.dbc spline waypoints for curved paths around terrain
- Build full path from node pairs using TaxiPathEdge lookup
- Precache callback triggers during mounting delay for smooth takeoff
- Circular tile loading uses Euclidean distance check (dx²+dy² <= r²)
- LOD fallback to base mesh when higher LODs unavailable

Result: Buttery smooth taxi flights with no terrain clipping or performance hitches
2026-02-08 21:32:38 -08:00
Kelsi
941dac446d Implement distance-based LOD system for M2 models
Added LOD (Level of Detail) selection based on camera distance:
- 0-40 units: LOD 0 (base detail)
- 40-80 units: LOD 1 (medium detail)
- 80-150 units: LOD 2 (medium-low detail)
- 150+ units: LOD 3 (lowest detail)

Matches WoW retail behavior. Each M2 skin file contains multiple LOD
versions (submeshLevel 0-3). System filters batches to only render
the appropriate LOD for each instance's distance, significantly
improving performance with many distant models.
2026-02-08 20:55:10 -08:00
Kelsi
cbbf819c0d Increase terrain load radius during taxi for aggressive caching
During taxi flights, increased terrain load radius from 2 to 4 tiles
(5x5 to 9x9 grid) to pre-cache more tiles ahead of flight path. Returns
to normal 5x5 after landing. 2GB cache stores loaded tiles for fast
retrieval. WMO/M2 models already cached in RAM once loaded.
2026-02-08 20:51:17 -08:00
Kelsi
1f0e948d34 Skip M2 collision queries during taxi instead of rendering
Reverted M2 rendering skip. Instead disable M2 collision/floor queries
during taxi (externalFollow mode) for performance. M2 models remain
visible but don't affect movement, grounding, or camera collision during
flight paths.
2026-02-08 20:45:59 -08:00
Kelsi
01816d2a3a Skip M2 rendering during taxi flights for performance
Disabled M2 doodad rendering (trees, rocks, etc) and their shadows
during taxi flights to improve performance. Terrain and WMO structures
still render. M2 rendering resumes when taxi ends.
2026-02-08 20:43:25 -08:00
Kelsi
9090fb8727 Fix jump snap-down: only ground when velocity is non-positive
Removed the '|| *groundH > feetZ' condition that was snapping player
to ground during upward jumps when ground was above current position.
Now only grounds when vertical velocity is <= 0 (falling or landing),
preventing premature grounding during jump arc.
2026-02-08 20:39:25 -08:00
Kelsi
4ca4d1e509 Disable all WMO floor caching including per-frame cache
Removed both persistent grid cache and per-frame dedup cache. Even the
per-frame cache was causing issues when player Z changes between queries
in the same frame (multi-sampling), returning stale floor heights and
causing fall-through at stairs. Floor queries now always raycast fresh.
2026-02-08 20:37:04 -08:00
Kelsi
f9dbc052dc Fix build error: remove persistent floor cache update code 2026-02-08 20:34:27 -08:00
Kelsi
7765b41611 Disable WMO floor cache and add camera collision with WMO/M2
Disabled persistent WMO floor grid cache - it stored one height per
2-unit cell causing fall-through at stairs where floor height changes
within a cell. Per-frame dedup cache is sufficient for performance.

Added camera raycast collision against WMO walls (when inside) and M2
objects to zoom in when camera would clip through geometry instead of
phasing through walls.
2026-02-08 20:33:40 -08:00
Kelsi
dbadfb043b Fix stair approach fall-through and relax steep slope climbing
Relaxed walkable slope threshold from 0.40 to 0.35 (~70° max) for
steeper stair climbing. Tightened WMO floor cache above-tolerance
back to 0.25 units to prevent cached stair landing from overriding
approach floor. Added M2 floor preference for ship decks to prevent
falling through to water below.
2026-02-08 20:31:00 -08:00
Kelsi
58ec7693a1 Relax walkable slope threshold and floor cache for steep stairs
Changed walkable slope threshold from 0.45 (63°) to 0.40 (66°) in both
WMO and M2 collision to allow climbing steeper stairs (like 60° steps).
Increased WMO floor cache above-tolerance from 0.35 to 0.50 units to
prevent falling through floors in places like Booty Bay where cached
floor is slightly above query point.
2026-02-08 20:26:24 -08:00
Kelsi
b51543fdd2 Allow full camera zoom on outdoor WMO structures without ceilings
Removed blanket 3.5-unit zoom limit when inside any WMO. Now only
constrains zoom when ceiling raycast detects actual structure above.
Increased ceiling detect range from 15 to 20 units. Allows full zoom
on bridges, platforms, ramparts, and other outdoor WMO areas while
still preventing camera clipping through enclosed building ceilings.
2026-02-08 20:21:49 -08:00
Kelsi
b48802855b Tighten WMO collision detection when inside buildings
When inside a WMO, use:
- Smaller sweep step size (0.20 vs 0.35) for more frequent collision checks
- Tighter player radius (0.45 vs 0.50) for less claustrophobic corridors
- Stronger push response (0.12 vs 0.08 max) for more responsive walls

Prevents clipping through walls in tight indoor spaces while keeping
outdoor movement smooth.
2026-02-08 20:20:37 -08:00
Kelsi
d49b69a3a8 Fix build error: use raycastBoundingBoxes instead of raycast 2026-02-08 20:16:21 -08:00
Kelsi
b47bfdc644 Fix camera snapping to upper floors with step-up constraint and ceiling check
Reduced camera floor step-up budget from 3.0f to 0.5f to prevent
snapping to floors far above camera. Added upward raycast to detect
ceilings/upper floors and constrain zoom distance in multi-story
buildings, preventing camera from phasing through upper levels.
2026-02-08 20:15:34 -08:00
Kelsi
85ff6234cb Fix camera snapping to floors above player in WMO buildings
Removed +3.0f offset from camera WMO floor query. The offset combined
with the +2.0f allowAbove in getFloorHeight was detecting floors 5 units
above camera, causing snaps to upper stories. Camera now queries at its
actual Z position to only detect reachable floors.
2026-02-08 20:10:40 -08:00
Kelsi
36834332eb Enable terrain streaming during taxi flights with RAM cache
Changed taxi terrain streaming from frozen (9999s) to active (0.3s
interval). The 2GB tile cache now serves tiles from RAM without
blocking, making terrain rendering safe and smooth during flight paths.
2026-02-08 20:05:04 -08:00
Kelsi
4e0e54a0f0 Fix taxi dismount: clear currentMountDisplayId_ in client path completion
The client path animation completion was calling mountCallback_(0) but
not clearing currentMountDisplayId_, leaving isMounted() returning true
after landing. All three dismount paths now consistently clear the flag.
2026-02-08 20:01:23 -08:00
Kelsi
d7aabc0caa Add M2 collision mesh parsing and mesh-based wall/floor collision
Parse bounding vertices, triangles, and normals from M2 files and use
them for proper triangle-level collision instead of AABB heuristics.
Spatial grid bucketing for efficient queries, closest-point wall push
with soft clamping, and ray-triangle floor detection alongside existing
AABB fallback.
2026-02-08 19:56:17 -08:00
Kelsi
fc003a2aba Soften WMO wall pushback and fix fountain climbing
Cap WMO swept wall collision pushback to 0.15 units (was 0.55) so walls
stop the player without violent shoves. Fix M2 stepped fountain lateral
push using effectiveTop instead of rawMax.z so the near-top check matches
the stepped profile height at the player's radial position.
2026-02-08 18:53:56 -08:00
Kelsi
02dd796e2e Fix: make grace “hold” instead of “pull down” don't yank us down in jumps 2026-02-08 18:39:45 -08:00
Kelsi
6880ca9ce6 Trust the floor cache if it is close too foot level 2026-02-08 18:25:43 -08:00
Kelsi
22c4d033cf Tune skin for collision "sticky" feel on walls 2026-02-08 18:17:43 -08:00
Kelsi
a503583b6b The walls should not push back so violently lets make this softer 2026-02-08 18:12:52 -08:00
Kelsi
3eb64dd9dd Stop falling through the damn ramps :P 2026-02-08 17:51:35 -08:00
Kelsi
f8aba30f2d Fix WMO ramp/stair clipping with WoW-style floor snap and collision fixes
Remove active group fast path from getFloorHeight to fix bridge clipping.
Replace ground smoothing with immediate step-up snap (WoW-style: snap up,
smooth down). Accept upward Z from wall collision at all call sites. Skip
floor-like surfaces (absNz >= 0.45) in wall collision to prevent false
wall hits on ramps. Increase getFloorHeight allowAbove from 0.5 to 2.0
for ramp reacquisition. Prefer highest reachable surface in floor selection.
2026-02-08 17:38:30 -08:00
Kelsi
ef54f62df0 Add multi-tier unstuck system with void fall detection
Replace broken hardcoded-coordinate unstuck with tiered fallbacks:
last safe position > hearth bind > map spawn. Track safe positions
only on real geometry, let player fall after 500ms with no ground,
and auto-trigger unstuck after 5s of continuous falling.
2026-02-08 15:37:34 -08:00
Kelsi
8fee55f99f Fix /unstuckgy hang by skipping WMO floor search
Add CameraController::teleportTo() that directly places the player at
the target position without the expensive floor-search loop in reset().
The loop does hundreds of WMO collision checks which hangs in cities.
2026-02-08 15:13:55 -08:00
Kelsi
eb92a71b71 Fix trainer buy packet and grey out unmet prerequisites
CMSG_TRAINER_BUY_SPELL was missing the trainerId field — server expects
guid(8) + trainerId(4) + spellId(4) = 16 bytes, not 12. Spells with
unmet prerequisites (chainNode1/2/3), insufficient level, or already
known are now greyed out with disabled Train buttons. Tooltips show
prerequisite status in green/red.
2026-02-08 15:03:43 -08:00