Fix instance portals: WDT byte order, box trigger sizing, suppress ping-pong, WMO cache cleanup

- Fix WDT chunk magic constants to big-endian ASCII (matching ADTLoader)
- Add minimum effective size for box area triggers (90 units, like sphere 45-unit radius)
- Add areaTriggerSuppressFirst_ flag to prevent portal ping-pong on map transfer
- Add WMORenderer::clearAll() to clear models/textures on map change (prevents GPU crash)
- Increase WMO texture cache default to 8GB
- Fix setMapName called after loadTestTerrain so WMO renderer exists
- Save/restore player position around CMSG_AREATRIGGER to prevent bad DB persistence
This commit is contained in:
Kelsi 2026-02-27 04:59:12 -08:00
parent d0e8b44866
commit 16d88f19fc
6 changed files with 120 additions and 41 deletions

View file

@ -274,7 +274,7 @@ bool WMORenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFrameLayou
flatNormalTexture_->createSampler(device, VK_FILTER_LINEAR, VK_FILTER_LINEAR,
VK_SAMPLER_ADDRESS_MODE_REPEAT);
textureCacheBudgetBytes_ =
envSizeMBOrDefault("WOWEE_WMO_TEX_CACHE_MB", 4096) * 1024ull * 1024ull;
envSizeMBOrDefault("WOWEE_WMO_TEX_CACHE_MB", 8192) * 1024ull * 1024ull;
modelCacheLimit_ = envSizeMBOrDefault("WOWEE_WMO_MODEL_LIMIT", 4000);
core::Logger::getInstance().info("WMO texture cache budget: ",
textureCacheBudgetBytes_ / (1024 * 1024), " MB");
@ -1039,6 +1039,40 @@ void WMORenderer::clearInstances() {
core::Logger::getInstance().info("Cleared all WMO instances");
}
void WMORenderer::clearAll() {
clearInstances();
if (vkCtx_) {
VkDevice device = vkCtx_->getDevice();
VmaAllocator allocator = vkCtx_->getAllocator();
vkDeviceWaitIdle(device);
// Free GPU resources for loaded models
for (auto& [id, model] : loadedModels) {
for (auto& group : model.groups) {
destroyGroupGPU(group);
}
}
// Free cached textures
for (auto& [path, entry] : textureCache) {
if (entry.texture) entry.texture->destroy(device, allocator);
if (entry.normalHeightMap) entry.normalHeightMap->destroy(device, allocator);
}
}
loadedModels.clear();
textureCache.clear();
textureCacheBytes_ = 0;
textureCacheCounter_ = 0;
failedTextureCache_.clear();
loggedTextureLoadFails_.clear();
textureBudgetRejectWarnings_ = 0;
precomputedFloorGrid.clear();
LOG_WARNING("Cleared all WMO models, instances, and texture cache");
}
void WMORenderer::setCollisionFocus(const glm::vec3& worldPos, float radius) {
collisionFocusEnabled = (radius > 0.0f);
collisionFocusPos = worldPos;