From c87c9c20be856a07778023ba5020c97e45dc133f Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Thu, 16 Oct 2025 15:20:31 -0500 Subject: [PATCH] don't try to load the raw if the map version is too old fixup some comments --- dZoneManager/Raw.cpp | 7 +++---- dZoneManager/Zone.cpp | 46 +++++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/dZoneManager/Raw.cpp b/dZoneManager/Raw.cpp index 87d86b27..3431eedf 100644 --- a/dZoneManager/Raw.cpp +++ b/dZoneManager/Raw.cpp @@ -100,7 +100,7 @@ namespace Raw { return false; } - // ColorMap (size varies by version) + // ColorMap if (version >= 32) { BinaryIO::BinaryRead(stream, chunk.colorMapResolution); } else { @@ -114,8 +114,7 @@ namespace Raw { if (stream.fail()) { return false; } - - // LightMap DDS + // LightMap/diffusemap.dds uint32_t lightMapSize; BinaryIO::BinaryRead(stream, lightMapSize); @@ -126,7 +125,7 @@ namespace Raw { return false; } - // TextureMap (size varies by version) + // TextureMap if (version >= 32) { BinaryIO::BinaryRead(stream, chunk.textureMapResolution); } else { diff --git a/dZoneManager/Zone.cpp b/dZoneManager/Zone.cpp index bc3a79e5..7d681f14 100644 --- a/dZoneManager/Zone.cpp +++ b/dZoneManager/Zone.cpp @@ -57,6 +57,11 @@ void Zone::LoadZoneIntoMemory() { if (file) { BinaryIO::BinaryRead(file, m_FileFormatVersion); + if (m_FileFormatVersion < Zone::FileFormatVersion::PrePreAlpha) { + LOG("Zone %s is too old to be supported, please update the map", m_ZoneFilePath.c_str()); + throw std::runtime_error("Aborting Zone loading due to old Zone File."); + } + uint32_t mapRevision = 0; if (m_FileFormatVersion >= Zone::FileFormatVersion::Alpha) BinaryIO::BinaryRead(file, mapRevision); @@ -92,23 +97,30 @@ void Zone::LoadZoneIntoMemory() { throw std::runtime_error("Aborting Zone loading due to no Zone Raw File."); } - auto rawFile = Game::assetManager->GetFile(zoneFolderPath + m_ZoneRawPath); - if (!Raw::ReadRaw(rawFile, m_Raw)) { - LOG("Failed to parse %s", (zoneFolderPath + m_ZoneRawPath).c_str()); - throw std::runtime_error("Aborting Zone loading due to invalid Raw File."); - } - - // Generate terrain mesh for fast scene lookups - Raw::GenerateTerrainMesh(m_Raw, m_TerrainMesh); - LOG("Generated terrain mesh with %llu vertices and %llu triangles", - m_TerrainMesh.vertices.size(), m_TerrainMesh.triangles.size() / 3); - - // Optionally export terrain mesh to OBJ for debugging/visualization - if (Game::config->GetValue("export_terrain_to_obj") == "1") { - std::string objFileName = "terrain_" + std::to_string(m_ZoneID.GetMapID()) + ".obj"; - if (Raw::WriteTerrainMeshToOBJ(m_TerrainMesh, objFileName)) { - LOG("Exported terrain mesh to %s", objFileName.c_str()); + if (m_FileFormatVersion >= Zone::FileFormatVersion::PrePreAlpha) { + auto rawFile = Game::assetManager->GetFile(zoneFolderPath + m_ZoneRawPath); + if (!Raw::ReadRaw(rawFile, m_Raw)) { + LOG("Failed to parse %s", (zoneFolderPath + m_ZoneRawPath).c_str()); + throw std::runtime_error("Aborting Zone loading due to invalid Raw File."); } + LOG("Loaded Raw Terrain with %u chunks", m_Raw.numChunks); + + + // Optionally export terrain mesh to OBJ for debugging/visualization + if (Game::config->GetValue("export_terrain_to_obj") == "1") { + + // Generate terrain mesh + Raw::GenerateTerrainMesh(m_Raw, m_TerrainMesh); + LOG("Generated terrain mesh with %llu vertices and %llu triangles", m_TerrainMesh.vertices.size(), m_TerrainMesh.triangles.size() / 3); + + // Write to OBJ + std::string objFileName = "terrain_" + std::to_string(m_ZoneID.GetMapID()) + ".obj"; + if (Raw::WriteTerrainMeshToOBJ(m_TerrainMesh, objFileName)) { + LOG("Exported terrain mesh to %s", objFileName.c_str()); + } + } + } else { + LOG("Zone %s is too old to have Raw data, please update the map", m_ZoneFilePath.c_str()); } if (m_FileFormatVersion >= Zone::FileFormatVersion::PreAlpha) { @@ -221,7 +233,7 @@ uint32_t Zone::CalculateChecksum() const { void Zone::LoadLevelsIntoMemory() { for (auto& [sceneID, scene] : m_Scenes) { if (scene.level) continue; - scene.level = std::make_unique(this, m_ZonePath + scene.filename); + scene.level = std::make_unique(this, sceneID, m_ZonePath + scene.filename); if (scene.level->m_ChunkHeaders.empty()) continue;