mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-06 03:47:13 +00:00
fix: load the zone without scene lookups when its raw terrain is missing or unreadable
Log at debug when it parses; build the terrain mesh only for the OBJ export; read the zone name and description only for version 31 and later, as the client does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -94,39 +94,36 @@ void Zone::LoadZoneIntoMemory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BinaryIO::ReadString<uint8_t>(file, m_ZoneRawPath, BinaryIO::ReadType::String);
|
BinaryIO::ReadString<uint8_t>(file, m_ZoneRawPath, BinaryIO::ReadType::String);
|
||||||
BinaryIO::ReadString<uint8_t>(file, m_ZoneName, BinaryIO::ReadType::String);
|
if (m_FileFormatVersion > Zone::FileFormatVersion::PrePreAlpha) {
|
||||||
BinaryIO::ReadString<uint8_t>(file, m_ZoneDesc, BinaryIO::ReadType::String);
|
BinaryIO::ReadString<uint8_t>(file, m_ZoneName, BinaryIO::ReadType::String);
|
||||||
|
BinaryIO::ReadString<uint8_t>(file, m_ZoneDesc, BinaryIO::ReadType::String);
|
||||||
auto zoneFolderPath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1);
|
|
||||||
if (!Game::assetManager->HasFile(zoneFolderPath + m_ZoneRawPath)) {
|
|
||||||
LOG("Failed to find %s", (zoneFolderPath + m_ZoneRawPath).c_str());
|
|
||||||
throw std::runtime_error("Aborting Zone loading due to no Zone Raw File.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto rawFile = Game::assetManager->GetFile(zoneFolderPath + m_ZoneRawPath);
|
// The terrain gives the scene at a position. Like the client, a missing or unreadable .raw is logged
|
||||||
|
// and the zone loads without it.
|
||||||
|
const auto rawPath = m_ZoneFilePath.substr(0, m_ZoneFilePath.rfind('/') + 1) + m_ZoneRawPath;
|
||||||
if (m_FileFormatVersion < Zone::FileFormatVersion::PrePreAlpha) {
|
if (m_FileFormatVersion < Zone::FileFormatVersion::PrePreAlpha) {
|
||||||
LOG("Zone %s uses legacy raw terrain format (version %u) which is not supported", m_ZoneFilePath.c_str(), static_cast<uint32_t>(m_FileFormatVersion));
|
LOG("Zone %s uses the legacy raw terrain format (version %u), which is not supported; no scene lookups", m_ZoneFilePath.c_str(), static_cast<uint32_t>(m_FileFormatVersion));
|
||||||
throw std::runtime_error("Aborting Zone loading due to unsupported Raw File version.");
|
} else if (!Game::assetManager->HasFile(rawPath)) {
|
||||||
|
LOG("Failed to find %s; no scene lookups", rawPath.c_str());
|
||||||
} else {
|
} else {
|
||||||
|
auto rawFile = Game::assetManager->GetFile(rawPath);
|
||||||
if (Raw::ReadRaw(rawFile, m_Raw)) {
|
if (Raw::ReadRaw(rawFile, m_Raw)) {
|
||||||
LOG("Successfully parsed %s", (zoneFolderPath + m_ZoneRawPath).c_str());
|
LOG_DEBUG("Successfully parsed %s", rawPath.c_str());
|
||||||
} else {
|
} else {
|
||||||
LOG("Failed to parse %s", (zoneFolderPath + m_ZoneRawPath).c_str());
|
LOG("Failed to parse %s; no scene lookups", rawPath.c_str());
|
||||||
throw std::runtime_error("Aborting Zone loading due to invalid Raw File.");
|
m_Raw = Raw::Raw{};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Optionally export terrain mesh to OBJ for debugging/visualization
|
// Optionally export terrain mesh to OBJ for debugging/visualization
|
||||||
if (Game::config->GetValue("export_terrain_to_obj") == "1") {
|
if (Game::config->GetValue("export_terrain_to_obj") == "1") {
|
||||||
|
Raw::TerrainMesh terrainMesh;
|
||||||
|
Raw::GenerateTerrainMesh(m_Raw, terrainMesh);
|
||||||
|
LOG("Generated terrain mesh with %zu vertices and %zu triangles", terrainMesh.vertices.size(), terrainMesh.triangles.size() / 3);
|
||||||
|
|
||||||
// Generate terrain mesh
|
const std::string objFileName = "terrain_" + std::to_string(m_ZoneID.GetMapID()) + ".obj";
|
||||||
Raw::GenerateTerrainMesh(m_Raw, m_TerrainMesh);
|
if (Raw::WriteTerrainMeshToOBJ(terrainMesh, objFileName)) {
|
||||||
LOG("Generated terrain mesh with %zu vertices and %zu 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());
|
LOG("Exported terrain mesh to %s", objFileName.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,7 +234,6 @@ public:
|
|||||||
void SetSpawnRot(const NiQuaternion& rot) { m_SpawnpointRotation = rot; }
|
void SetSpawnRot(const NiQuaternion& rot) { m_SpawnpointRotation = rot; }
|
||||||
|
|
||||||
const Raw::Raw& GetZoneRaw() const { return m_Raw; }
|
const Raw::Raw& GetZoneRaw() const { return m_Raw; }
|
||||||
const Raw::TerrainMesh& GetTerrainMesh() const { return m_TerrainMesh; }
|
|
||||||
const SceneRef* GetScene(LWOSCENEID sceneID) const;
|
const SceneRef* GetScene(LWOSCENEID sceneID) const;
|
||||||
const std::vector<SceneTransition>& GetSceneTransitions() const { return m_SceneTransitions; }
|
const std::vector<SceneTransition>& GetSceneTransitions() const { return m_SceneTransitions; }
|
||||||
const std::map<LWOSCENEID, SceneRef>& GetScenes() const { return m_Scenes; }
|
const std::map<LWOSCENEID, SceneRef>& GetScenes() const { return m_Scenes; }
|
||||||
@@ -256,7 +255,6 @@ private:
|
|||||||
std::string m_ZoneDesc; //Description of the zone by a level designer
|
std::string m_ZoneDesc; //Description of the zone by a level designer
|
||||||
std::string m_ZoneRawPath; //Path to the .raw file of this zone.
|
std::string m_ZoneRawPath; //Path to the .raw file of this zone.
|
||||||
Raw::Raw m_Raw; // The Raw data for this zone
|
Raw::Raw m_Raw; // The Raw data for this zone
|
||||||
Raw::TerrainMesh m_TerrainMesh; // Pre-generated terrain mesh for fast scene lookups
|
|
||||||
|
|
||||||
std::map<LWOSCENEID, SceneRef> m_Scenes;
|
std::map<LWOSCENEID, SceneRef> m_Scenes;
|
||||||
std::vector<SceneTransition> m_SceneTransitions;
|
std::vector<SceneTransition> m_SceneTransitions;
|
||||||
|
|||||||
Reference in New Issue
Block a user