mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 01:23:51 +00:00
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.
This commit is contained in:
parent
27d0496894
commit
c047446fb7
12 changed files with 198 additions and 19 deletions
|
|
@ -80,8 +80,51 @@ void CameraController::update(float deltaTime) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Skip all collision/movement logic during taxi flights (position controlled externally)
|
||||
// During taxi flights, skip input/movement logic but still position camera
|
||||
if (externalFollow_) {
|
||||
// Mouse look (right mouse button)
|
||||
if (rightMouseDown) {
|
||||
int mouseDX, mouseDY;
|
||||
SDL_GetRelativeMouseState(&mouseDX, &mouseDY);
|
||||
yaw -= mouseDX * mouseSensitivity;
|
||||
pitch -= mouseDY * mouseSensitivity;
|
||||
pitch = glm::clamp(pitch, -89.0f, 89.0f);
|
||||
camera->setRotation(yaw, pitch);
|
||||
}
|
||||
|
||||
// Position camera behind character during taxi
|
||||
if (thirdPerson && followTarget) {
|
||||
glm::vec3 targetPos = *followTarget;
|
||||
glm::vec3 forward3D = camera->getForward();
|
||||
|
||||
// Pivot point at upper chest/neck
|
||||
float mountedOffset = mounted_ ? mountHeightOffset_ : 0.0f;
|
||||
glm::vec3 pivot = targetPos + glm::vec3(0.0f, 0.0f, PIVOT_HEIGHT + mountedOffset);
|
||||
|
||||
// Camera direction from yaw/pitch
|
||||
glm::vec3 camDir = -forward3D;
|
||||
|
||||
// Use current distance
|
||||
float actualDist = std::min(currentDistance, collisionDistance);
|
||||
|
||||
// Compute camera position
|
||||
glm::vec3 actualCam;
|
||||
if (actualDist < MIN_DISTANCE + 0.1f) {
|
||||
actualCam = pivot + forward3D * 0.1f;
|
||||
} else {
|
||||
actualCam = pivot + camDir * actualDist;
|
||||
}
|
||||
|
||||
// Smooth camera position
|
||||
if (glm::length(smoothedCamPos) < 0.01f) {
|
||||
smoothedCamPos = actualCam;
|
||||
}
|
||||
float camLerp = 1.0f - std::exp(-CAM_SMOOTH_SPEED * deltaTime);
|
||||
smoothedCamPos += (actualCam - smoothedCamPos) * camLerp;
|
||||
|
||||
camera->setPosition(smoothedCamPos);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1379,7 +1379,7 @@ void M2Renderer::update(float deltaTime, const glm::vec3& cameraPos, const glm::
|
|||
|
||||
// Cache camera state for frustum-culling bone computation
|
||||
cachedCamPos_ = cameraPos;
|
||||
const float maxRenderDistance = (instances.size() > 600) ? 320.0f : 2800.0f;
|
||||
const float maxRenderDistance = (instances.size() > 2000) ? 800.0f : 2800.0f;
|
||||
cachedMaxRenderDistSq_ = maxRenderDistance * maxRenderDistance;
|
||||
|
||||
// Build frustum for culling bones
|
||||
|
|
@ -1643,9 +1643,9 @@ void M2Renderer::render(const Camera& camera, const glm::mat4& view, const glm::
|
|||
|
||||
lastDrawCallCount = 0;
|
||||
|
||||
// Adaptive render distance: keep longer tree/foliage visibility to reduce pop-in.
|
||||
// During taxi, use very short render distance to prevent loading hitches
|
||||
const float maxRenderDistance = onTaxi_ ? 150.0f : (instances.size() > 600) ? 320.0f : 2800.0f;
|
||||
// Adaptive render distance: aggressive settings to utilize VRAM fully
|
||||
// During taxi, render far to upload models/textures to VRAM cache
|
||||
const float maxRenderDistance = onTaxi_ ? 1200.0f : (instances.size() > 2000) ? 800.0f : 2800.0f;
|
||||
const float maxRenderDistanceSq = maxRenderDistance * maxRenderDistance;
|
||||
const float fadeStartFraction = 0.75f;
|
||||
const glm::vec3 camPos = camera.getPosition();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "rendering/wmo_renderer.hpp"
|
||||
#include "rendering/camera.hpp"
|
||||
#include "core/coordinates.hpp"
|
||||
#include "core/memory_monitor.hpp"
|
||||
#include "pipeline/asset_manager.hpp"
|
||||
#include "pipeline/adt_loader.hpp"
|
||||
#include "pipeline/m2_loader.hpp"
|
||||
|
|
@ -113,10 +114,21 @@ bool TerrainManager::initialize(pipeline::AssetManager* assets, TerrainRenderer*
|
|||
return false;
|
||||
}
|
||||
|
||||
// Start background worker pool
|
||||
// Set dynamic tile cache budget (use other half of recommended budget)
|
||||
auto& memMonitor = core::MemoryMonitor::getInstance();
|
||||
tileCacheBudgetBytes_ = memMonitor.getRecommendedCacheBudget() / 2;
|
||||
LOG_INFO("Terrain tile cache budget: ", tileCacheBudgetBytes_ / (1024 * 1024), " MB (dynamic)");
|
||||
|
||||
// Start background worker pool (dynamic: scales with available cores)
|
||||
// Use 75% of logical cores for decompression, leaving headroom for render/OS
|
||||
workerRunning.store(true);
|
||||
unsigned hc = std::thread::hardware_concurrency();
|
||||
workerCount = static_cast<int>(hc > 0 ? std::min(4u, std::max(2u, hc - 1)) : 2u);
|
||||
if (hc > 0) {
|
||||
unsigned targetWorkers = std::max(6u, (hc * 3) / 4); // 75% of cores, minimum 6
|
||||
workerCount = static_cast<int>(targetWorkers);
|
||||
} else {
|
||||
workerCount = 6; // Fallback
|
||||
}
|
||||
workerThreads.reserve(workerCount);
|
||||
for (int i = 0; i < workerCount; i++) {
|
||||
workerThreads.emplace_back(&TerrainManager::workerLoop, this);
|
||||
|
|
@ -917,10 +929,16 @@ void TerrainManager::unloadAll() {
|
|||
m2Renderer->clear();
|
||||
}
|
||||
|
||||
// Restart worker threads so streaming can resume
|
||||
// Restart worker threads so streaming can resume (dynamic: scales with available cores)
|
||||
// Use 75% of logical cores for decompression, leaving headroom for render/OS
|
||||
workerRunning.store(true);
|
||||
unsigned hc = std::thread::hardware_concurrency();
|
||||
workerCount = static_cast<int>(hc > 0 ? std::min(4u, std::max(2u, hc - 1)) : 2u);
|
||||
if (hc > 0) {
|
||||
unsigned targetWorkers = std::max(6u, (hc * 3) / 4); // 75% of cores, minimum 6
|
||||
workerCount = static_cast<int>(targetWorkers);
|
||||
} else {
|
||||
workerCount = 6; // Fallback
|
||||
}
|
||||
workerThreads.reserve(workerCount);
|
||||
for (int i = 0; i < workerCount; i++) {
|
||||
workerThreads.emplace_back(&TerrainManager::workerLoop, this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue