diff --git a/include/game/game_handler.hpp b/include/game/game_handler.hpp index ab586d17..21b90645 100644 --- a/include/game/game_handler.hpp +++ b/include/game/game_handler.hpp @@ -496,6 +496,11 @@ public: // Mount state using MountCallback = std::function; // 0 = dismount void setMountCallback(MountCallback cb) { mountCallback_ = std::move(cb); } + + // Taxi terrain precaching callback + using TaxiPrecacheCallback = std::function&)>; + void setTaxiPrecacheCallback(TaxiPrecacheCallback cb) { taxiPrecacheCallback_ = std::move(cb); } + bool isMounted() const { return currentMountDisplayId_ != 0; } bool isHostileAttacker(uint64_t guid) const { return hostileAttackers_.count(guid) > 0; } float getServerRunSpeed() const { return serverRunSpeed_; } @@ -522,6 +527,13 @@ public: uint32_t fromNode = 0, toNode = 0; uint32_t cost = 0; }; + struct TaxiPathNode { + uint32_t id = 0; + uint32_t pathId = 0; + uint32_t nodeIndex = 0; + uint32_t mapId = 0; + float x = 0, y = 0, z = 0; + }; const std::unordered_map& getTaxiNodes() const { return taxiNodes_; } uint32_t getTaxiCostTo(uint32_t destNodeId) const; @@ -934,6 +946,7 @@ private: // Taxi / Flight Paths std::unordered_map taxiNodes_; std::vector taxiPathEdges_; + std::unordered_map> taxiPathNodes_; // pathId -> ordered waypoints bool taxiDbcLoaded_ = false; bool taxiWindowOpen_ = false; ShowTaxiNodesData currentTaxiData_; @@ -948,6 +961,9 @@ private: std::vector taxiClientPath_; float taxiClientSpeed_ = 32.0f; float taxiClientSegmentProgress_ = 0.0f; + bool taxiMountingDelay_ = false; // Delay before flight starts (terrain precache time) + float taxiMountingTimer_ = 0.0f; + std::vector taxiPendingPath_; // Path nodes waiting for mounting delay bool taxiRecoverPending_ = false; uint32_t taxiRecoverMapId_ = 0; glm::vec3 taxiRecoverPos_{0.0f}; @@ -1006,6 +1022,7 @@ private: MeleeSwingCallback meleeSwingCallback_; NpcSwingCallback npcSwingCallback_; MountCallback mountCallback_; + TaxiPrecacheCallback taxiPrecacheCallback_; uint32_t currentMountDisplayId_ = 0; float serverRunSpeed_ = 7.0f; bool playerDead_ = false; diff --git a/include/rendering/camera_controller.hpp b/include/rendering/camera_controller.hpp index d0312137..113092d0 100644 --- a/include/rendering/camera_controller.hpp +++ b/include/rendering/camera_controller.hpp @@ -76,6 +76,7 @@ public: bool isSitting() const { return sitting; } bool isSwimming() const { return swimming; } bool isInsideWMO() const { return cachedInsideWMO; } + bool isOnTaxi() const { return externalFollow_; } const glm::vec3* getFollowTarget() const { return followTarget; } glm::vec3* getFollowTargetMutable() { return followTarget; } diff --git a/include/rendering/m2_renderer.hpp b/include/rendering/m2_renderer.hpp index 9322eb7e..9772b0ec 100644 --- a/include/rendering/m2_renderer.hpp +++ b/include/rendering/m2_renderer.hpp @@ -35,6 +35,7 @@ struct M2ModelGPU { uint16_t textureAnimIndex = 0xFFFF; // 0xFFFF = no texture animation uint16_t blendMode = 0; // 0=Opaque, 1=AlphaKey, 2=Alpha, 3=Add, etc. uint16_t materialFlags = 0; // M2 material flags (0x01=Unlit, 0x04=TwoSided, 0x10=NoDepthWrite) + uint16_t submeshLevel = 0; // LOD level: 0=base, 1=LOD1, 2=LOD2, 3=LOD3 glm::vec3 center = glm::vec3(0.0f); // Center of batch geometry (model space) float glowSize = 1.0f; // Approx radius of batch geometry }; @@ -58,6 +59,7 @@ struct M2ModelGPU { bool collisionTreeTrunk = false; bool collisionNoBlock = false; bool collisionStatue = false; + bool isSmallFoliage = false; // Small foliage (bushes, grass, plants) - skip during taxi // Collision mesh with spatial grid (from M2 bounding geometry) struct CollisionMesh { @@ -310,9 +312,11 @@ public: void clearShadowMap() { shadowEnabled = false; } void setInsideInterior(bool inside) { insideInterior = inside; } + void setOnTaxi(bool onTaxi) { onTaxi_ = onTaxi; } private: bool insideInterior = false; + bool onTaxi_ = false; pipeline::AssetManager* assetManager = nullptr; std::unique_ptr shader; diff --git a/include/rendering/terrain_manager.hpp b/include/rendering/terrain_manager.hpp index ea336492..43d731f2 100644 --- a/include/rendering/terrain_manager.hpp +++ b/include/rendering/terrain_manager.hpp @@ -166,6 +166,12 @@ public: */ void unloadAll(); + /** + * Precache a set of tiles (for taxi routes, etc.) + * @param tiles Vector of (x, y) tile coordinates to preload + */ + void precacheTiles(const std::vector>& tiles); + /** * Set streaming parameters */ @@ -294,7 +300,7 @@ private: std::unordered_map tileCache_; std::list tileCacheLru_; size_t tileCacheBytes_ = 0; - size_t tileCacheBudgetBytes_ = 2ull * 1024 * 1024 * 1024; // 2GB default + size_t tileCacheBudgetBytes_ = 8ull * 1024 * 1024 * 1024; // 8GB for modern systems std::mutex tileCacheMutex_; std::shared_ptr getCachedTile(const TileCoord& coord); diff --git a/src/core/application.cpp b/src/core/application.cpp index ecd02854..190e35d3 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -420,11 +420,11 @@ void Application::update(float deltaTime) { } if (renderer && renderer->getTerrainManager()) { renderer->getTerrainManager()->setStreamingEnabled(true); - // With 2GB tile cache, keep streaming active during taxi at moderate rate. + // With 8GB tile cache, keep streaming active during taxi at moderate rate. // Increase load radius to pre-cache tiles ahead of flight path. if (onTaxi) { renderer->getTerrainManager()->setUpdateInterval(0.3f); - renderer->getTerrainManager()->setLoadRadius(4); // 9x9 grid for taxi + renderer->getTerrainManager()->setLoadRadius(2); // 5x5 grid for taxi (each tile ~533 yards) } else { // Ramp streaming back in after taxi to avoid end-of-flight hitches. if (lastTaxiFlight_) { @@ -689,6 +689,35 @@ void Application::setupUICallbacks() { pendingMountDisplayId_ = mountDisplayId; }); + // Taxi precache callback - preload terrain tiles along flight path + gameHandler->setTaxiPrecacheCallback([this](const std::vector& path) { + if (!renderer || !renderer->getTerrainManager()) return; + + std::set> uniqueTiles; + + // Sample waypoints along path and gather tiles + for (const auto& waypoint : path) { + glm::vec3 renderPos = core::coords::canonicalToRender(waypoint); + int tileX = static_cast(32 - (renderPos.x / 533.33333f)); + int tileY = static_cast(32 - (renderPos.y / 533.33333f)); + + // Load tile at waypoint + 1 radius around it (3x3 per waypoint) + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) { + int tx = tileX + dx; + int ty = tileY + dy; + if (tx >= 0 && tx <= 63 && ty >= 0 && ty <= 63) { + uniqueTiles.insert({tx, ty}); + } + } + } + } + + std::vector> tilesToLoad(uniqueTiles.begin(), uniqueTiles.end()); + LOG_INFO("Precaching ", tilesToLoad.size(), " tiles for taxi route"); + renderer->getTerrainManager()->precacheTiles(tilesToLoad); + }); + // Creature move callback (online mode) - update creature positions gameHandler->setCreatureMoveCallback([this](uint64_t guid, float x, float y, float z, uint32_t durationMs) { auto it = creatureInstances_.find(guid); diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index 1cb613f8..e93225e6 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -262,6 +262,20 @@ void GameHandler::update(float deltaTime) { } } + // Mounting delay for taxi (terrain precache time) + if (taxiMountingDelay_) { + taxiMountingTimer_ += deltaTime; + // 3 second delay for "mounting" animation and terrain precache + if (taxiMountingTimer_ >= 3.0f) { + taxiMountingDelay_ = false; + taxiMountingTimer_ = 0.0f; + if (!taxiPendingPath_.empty()) { + startClientTaxiPath(taxiPendingPath_); + taxiPendingPath_.clear(); + } + } + } + // Leave combat if auto-attack target is too far away (leash range) if (autoAttacking && autoAttackTarget != 0) { auto targetEntity = entityManager.getEntity(autoAttackTarget); @@ -5003,6 +5017,33 @@ void GameHandler::loadTaxiDbc() { } else { LOG_WARNING("Could not load TaxiPath.dbc"); } + + // Load TaxiPathNode.dbc: actual spline waypoints for each path + // 0=ID, 1=PathID, 2=NodeIndex, 3=MapID, 4=X, 5=Y, 6=Z + auto pathNodeDbc = am->loadDBC("TaxiPathNode.dbc"); + if (pathNodeDbc && pathNodeDbc->isLoaded()) { + for (uint32_t i = 0; i < pathNodeDbc->getRecordCount(); i++) { + TaxiPathNode node; + node.id = pathNodeDbc->getUInt32(i, 0); + node.pathId = pathNodeDbc->getUInt32(i, 1); + node.nodeIndex = pathNodeDbc->getUInt32(i, 2); + node.mapId = pathNodeDbc->getUInt32(i, 3); + node.x = pathNodeDbc->getFloat(i, 4); + node.y = pathNodeDbc->getFloat(i, 5); + node.z = pathNodeDbc->getFloat(i, 6); + taxiPathNodes_[node.pathId].push_back(node); + } + // Sort waypoints by nodeIndex for each path + for (auto& [pathId, nodes] : taxiPathNodes_) { + std::sort(nodes.begin(), nodes.end(), + [](const TaxiPathNode& a, const TaxiPathNode& b) { + return a.nodeIndex < b.nodeIndex; + }); + } + LOG_INFO("Loaded ", pathNodeDbc->getRecordCount(), " taxi path waypoints from TaxiPathNode.dbc"); + } else { + LOG_WARNING("Could not load TaxiPathNode.dbc"); + } } void GameHandler::handleShowTaxiNodes(network::Packet& packet) { @@ -5107,15 +5148,41 @@ void GameHandler::startClientTaxiPath(const std::vector& pathNodes) { taxiClientActive_ = false; taxiClientSegmentProgress_ = 0.0f; - for (uint32_t nodeId : pathNodes) { - auto it = taxiNodes_.find(nodeId); - if (it == taxiNodes_.end()) continue; - glm::vec3 serverPos(it->second.x, it->second.y, it->second.z); - glm::vec3 canonical = core::coords::serverToCanonical(serverPos); - taxiClientPath_.push_back(canonical); + // Build full spline path using TaxiPathNode waypoints (not just node positions) + for (size_t i = 0; i + 1 < pathNodes.size(); i++) { + uint32_t fromNode = pathNodes[i]; + uint32_t toNode = pathNodes[i + 1]; + // Find the pathId connecting these nodes + uint32_t pathId = 0; + for (const auto& edge : taxiPathEdges_) { + if (edge.fromNode == fromNode && edge.toNode == toNode) { + pathId = edge.pathId; + break; + } + } + if (pathId == 0) { + LOG_WARNING("No taxi path found from node ", fromNode, " to ", toNode); + continue; + } + // Get spline waypoints for this path segment + auto pathIt = taxiPathNodes_.find(pathId); + if (pathIt != taxiPathNodes_.end()) { + for (const auto& wpNode : pathIt->second) { + glm::vec3 serverPos(wpNode.x, wpNode.y, wpNode.z); + glm::vec3 canonical = core::coords::serverToCanonical(serverPos); + taxiClientPath_.push_back(canonical); + } + } else { + LOG_WARNING("No spline waypoints found for taxi pathId ", pathId); + } } - if (taxiClientPath_.size() < 2) return; + if (taxiClientPath_.size() < 2) { + LOG_WARNING("Taxi path too short: ", taxiClientPath_.size(), " waypoints"); + return; + } + + LOG_INFO("Taxi flight started with ", taxiClientPath_.size(), " spline waypoints"); taxiClientActive_ = true; } @@ -5335,7 +5402,44 @@ void GameHandler::activateTaxi(uint32_t destNodeId) { onTaxiFlight_ = true; applyTaxiMountForCurrentNode(); } - startClientTaxiPath(path); + + // Start mounting delay (gives terrain precache time to load) + taxiMountingDelay_ = true; + taxiMountingTimer_ = 0.0f; + taxiPendingPath_ = path; + + // Trigger terrain precache immediately (uses mounting delay time to load) + if (taxiPrecacheCallback_) { + std::vector previewPath; + // Build full spline path using TaxiPathNode waypoints + for (size_t i = 0; i + 1 < path.size(); i++) { + uint32_t fromNode = path[i]; + uint32_t toNode = path[i + 1]; + // Find the pathId connecting these nodes + uint32_t pathId = 0; + for (const auto& edge : taxiPathEdges_) { + if (edge.fromNode == fromNode && edge.toNode == toNode) { + pathId = edge.pathId; + break; + } + } + if (pathId == 0) continue; + // Get spline waypoints for this path segment + auto pathIt = taxiPathNodes_.find(pathId); + if (pathIt != taxiPathNodes_.end()) { + for (const auto& wpNode : pathIt->second) { + glm::vec3 serverPos(wpNode.x, wpNode.y, wpNode.z); + glm::vec3 canonical = core::coords::serverToCanonical(serverPos); + previewPath.push_back(canonical); + } + } + } + if (previewPath.size() >= 2) { + taxiPrecacheCallback_(previewPath); + } + } + + addSystemChatMessage("Mounting for flight..."); // Save recovery target in case of disconnect during taxi. auto destIt = taxiNodes_.find(destNodeId); diff --git a/src/rendering/m2_renderer.cpp b/src/rendering/m2_renderer.cpp index 7bf076df..3c0b6412 100644 --- a/src/rendering/m2_renderer.cpp +++ b/src/rendering/m2_renderer.cpp @@ -1084,6 +1084,9 @@ bool M2Renderer::loadModel(const pipeline::M2Model& model, uint32_t modelId) { bgpu.materialFlags = model.materials[batch.materialIndex].flags; } + // Copy LOD level from batch + bgpu.submeshLevel = batch.submeshLevel; + // Resolve texture: batch.textureIndex → textureLookup → allTextures GLuint tex = whiteTexture; if (batch.textureIndex < model.textureLookup.size()) { @@ -1621,15 +1624,17 @@ void M2Renderer::render(const Camera& camera, const glm::mat4& view, const glm:: shader->setUniform("uProjection", projection); shader->setUniform("uLightDir", lightDir); shader->setUniform("uLightColor", glm::vec3(1.5f, 1.4f, 1.3f)); - shader->setUniform("uSpecularIntensity", 0.5f); + shader->setUniform("uSpecularIntensity", onTaxi_ ? 0.0f : 0.5f); // Disable specular during taxi for performance shader->setUniform("uAmbientColor", ambientColor); shader->setUniform("uViewPos", camera.getPosition()); shader->setUniform("uFogColor", fogColor); shader->setUniform("uFogStart", fogStart); shader->setUniform("uFogEnd", fogEnd); - shader->setUniform("uShadowEnabled", shadowEnabled ? 1 : 0); + // Disable shadows during taxi for better performance + bool useShadows = shadowEnabled && !onTaxi_; + shader->setUniform("uShadowEnabled", useShadows ? 1 : 0); shader->setUniform("uShadowStrength", 0.65f); - if (shadowEnabled) { + if (useShadows) { shader->setUniform("uLightSpaceMatrix", lightSpaceMatrix); glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, shadowDepthTex); @@ -1708,6 +1713,12 @@ void M2Renderer::render(const Camera& camera, const glm::mat4& view, const glm:: const M2ModelGPU& model = *currentModel; + // Skip small models when on taxi (performance optimization) + // Small props/foliage aren't visible from flight altitude anyway + if (onTaxi_ && model.boundRadius < 3.0f) { + continue; + } + // Distance-based fade alpha for smooth pop-in (squared-distance, no sqrt) float fadeAlpha = 1.0f; float fadeFrac = model.disableAnimation ? 0.55f : fadeStartFraction; @@ -1734,20 +1745,35 @@ void M2Renderer::render(const Camera& camera, const glm::mat4& view, const glm:: glDepthMask(GL_FALSE); } + // LOD selection based on distance (WoW retail behavior) + // submeshLevel: 0=base detail, 1=LOD1, 2=LOD2, 3=LOD3 + float dist = std::sqrt(entry.distSq); + uint16_t desiredLOD = 0; + if (dist > 150.0f) desiredLOD = 3; // Far: LOD3 (lowest detail) + else if (dist > 80.0f) desiredLOD = 2; // Medium-far: LOD2 + else if (dist > 40.0f) desiredLOD = 1; // Medium: LOD1 + // else desiredLOD = 0 (close: base detail) + + // Check if model has the desired LOD level; if not, fall back to LOD 0 + uint16_t targetLOD = desiredLOD; + if (desiredLOD > 0) { + bool hasDesiredLOD = false; + for (const auto& b : model.batches) { + if (b.submeshLevel == desiredLOD) { + hasDesiredLOD = true; + break; + } + } + if (!hasDesiredLOD) { + targetLOD = 0; // Fall back to base LOD + } + } + for (const auto& batch : model.batches) { if (batch.indexCount == 0) continue; - // LOD selection based on distance (WoW retail behavior) - // submeshLevel: 0=base detail, 1=LOD1, 2=LOD2, 3=LOD3 - float dist = std::sqrt(entry.distSq); - uint16_t desiredLOD = 0; - if (dist > 150.0f) desiredLOD = 3; // Far: LOD3 (lowest detail) - else if (dist > 80.0f) desiredLOD = 2; // Medium-far: LOD2 - else if (dist > 40.0f) desiredLOD = 1; // Medium: LOD1 - // else desiredLOD = 0 (close: base detail) - - // Skip batches that don't match desired LOD level - if (batch.submeshLevel != desiredLOD) continue; + // Skip batches that don't match target LOD level + if (batch.submeshLevel != targetLOD) continue; // Additive/mod batches (glow halos, light effects): collect as glow sprites // instead of rendering the mesh geometry which appears as flat orange disks. diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 6d475e37..dd9f93e4 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -1552,7 +1552,9 @@ void Renderer::renderWorld(game::World* world) { } // Render weather particles (after terrain/water, before characters) - if (weather && camera) { + // Skip during taxi flights for performance and visual clarity + bool onTaxi = cameraController && cameraController->isOnTaxi(); + if (weather && camera && !onTaxi) { weather->render(*camera); } @@ -1586,11 +1588,15 @@ void Renderer::renderWorld(game::World* world) { // Dim M2 lighting when player is inside a WMO if (cameraController) { m2Renderer->setInsideInterior(cameraController->isInsideWMO()); + m2Renderer->setOnTaxi(cameraController->isOnTaxi()); } auto m2Start = std::chrono::steady_clock::now(); m2Renderer->render(*camera, view, projection); - m2Renderer->renderSmokeParticles(*camera, view, projection); - m2Renderer->renderM2Particles(view, projection); + // Skip particle fog during taxi (expensive and visually distracting) + if (!onTaxi) { + m2Renderer->renderSmokeParticles(*camera, view, projection); + m2Renderer->renderM2Particles(view, projection); + } auto m2End = std::chrono::steady_clock::now(); lastM2RenderMs = std::chrono::duration(m2End - m2Start).count(); } diff --git a/src/rendering/terrain_manager.cpp b/src/rendering/terrain_manager.cpp index 7405a002..10959c64 100644 --- a/src/rendering/terrain_manager.cpp +++ b/src/rendering/terrain_manager.cpp @@ -1161,6 +1161,11 @@ void TerrainManager::streamTiles() { continue; } + // Circular pattern: skip corner tiles beyond radius (Euclidean distance) + if (dx*dx + dy*dy > loadRadius*loadRadius) { + continue; + } + TileCoord coord = {tileX, tileY}; // Skip if already loaded, pending, or failed @@ -1183,11 +1188,11 @@ void TerrainManager::streamTiles() { for (const auto& pair : loadedTiles) { const TileCoord& coord = pair.first; - int dx = std::abs(coord.x - currentTile.x); - int dy = std::abs(coord.y - currentTile.y); + int dx = coord.x - currentTile.x; + int dy = coord.y - currentTile.y; - // Chebyshev distance - if (dx > unloadRadius || dy > unloadRadius) { + // Circular pattern: unload beyond radius (Euclidean distance) + if (dx*dx + dy*dy > unloadRadius*unloadRadius) { tilesToUnload.push_back(coord); } } @@ -1210,5 +1215,24 @@ void TerrainManager::streamTiles() { } } +void TerrainManager::precacheTiles(const std::vector>& tiles) { + std::lock_guard lock(queueMutex); + + for (const auto& [x, y] : tiles) { + TileCoord coord = {x, y}; + + // Skip if already loaded, pending, or failed + if (loadedTiles.find(coord) != loadedTiles.end()) continue; + if (pendingTiles.find(coord) != pendingTiles.end()) continue; + if (failedTiles.find(coord) != failedTiles.end()) continue; + + loadQueue.push(coord); + pendingTiles[coord] = true; + } + + // Notify workers to start loading + queueCV.notify_all(); +} + } // namespace rendering } // namespace wowee