diff --git a/src/rendering/terrain_manager.cpp b/src/rendering/terrain_manager.cpp index b13ed706..e4bf2d35 100644 --- a/src/rendering/terrain_manager.cpp +++ b/src/rendering/terrain_manager.cpp @@ -479,6 +479,34 @@ std::shared_ptr TerrainManager::prepareTile(int x, int y) { for (uint32_t idx : wom.indices) m2Model.indices.push_back(static_cast(idx)); + // Set up textures from WOM paths + for (const auto& texPath : wom.texturePaths) { + pipeline::M2Texture tex; + tex.type = 0; + tex.flags = 0; + tex.filename = texPath; + m2Model.textures.push_back(tex); + } + m2Model.textureLookup = {0}; + + // Create default render batch covering all geometry + pipeline::M2Batch batch{}; + batch.flags = 0; + batch.shader = 0; + batch.textureCount = std::min(1u, static_cast(wom.texturePaths.size())); + batch.textureIndex = 0; + batch.indexStart = 0; + batch.indexCount = static_cast(m2Model.indices.size()); + batch.vertexStart = 0; + batch.vertexCount = static_cast(m2Model.vertices.size()); + m2Model.batches.push_back(batch); + + // Default opaque material + pipeline::M2Material mat; + mat.flags = 0; + mat.blendMode = 0; + m2Model.materials.push_back(mat); + pending->m2Models.push_back({modelId, std::move(m2Model), {}}); preparedModelIds.insert(modelId); LOG_INFO("Loaded WOM model: ", womPath); diff --git a/tests/test_dbc_loader.cpp b/tests/test_dbc_loader.cpp index 6a6fcea1..8a892bd9 100644 --- a/tests/test_dbc_loader.cpp +++ b/tests/test_dbc_loader.cpp @@ -206,3 +206,75 @@ TEST_CASE("DBCFile getStringByOffset", "[dbc]") { REQUIRE(dbc.getStringByOffset(1) == "Offset5"); REQUIRE(dbc.getStringByOffset(0).empty()); } + +// ============== JSON DBC Tests ============== + +static std::vector buildJsonDBC(const std::string& json) { + return std::vector(json.begin(), json.end()); +} + +TEST_CASE("JSON DBC basic load", "[dbc][json]") { + auto data = buildJsonDBC(R"({ + "format": "wowee-dbc-json-1.0", + "fieldCount": 3, + "recordCount": 2, + "records": [ + [1, "Fireball", 100], + [2, "Frostbolt", 200] + ] + })"); + + DBCFile dbc; + REQUIRE(dbc.load(data)); + REQUIRE(dbc.getRecordCount() == 2); + REQUIRE(dbc.getFieldCount() == 3); + REQUIRE(dbc.getUInt32(0, 0) == 1); + REQUIRE(dbc.getString(0, 1) == "Fireball"); + REQUIRE(dbc.getUInt32(0, 2) == 100); + REQUIRE(dbc.getUInt32(1, 0) == 2); + REQUIRE(dbc.getString(1, 1) == "Frostbolt"); + REQUIRE(dbc.getUInt32(1, 2) == 200); +} + +TEST_CASE("JSON DBC with float values", "[dbc][json]") { + auto data = buildJsonDBC(R"({ + "fieldCount": 2, + "records": [ + [1, 3.14] + ] + })"); + + DBCFile dbc; + REQUIRE(dbc.load(data)); + REQUIRE(dbc.getUInt32(0, 0) == 1); + REQUIRE(dbc.getFloat(0, 1) == Catch::Approx(3.14f).margin(0.01f)); +} + +TEST_CASE("JSON DBC empty records", "[dbc][json]") { + auto data = buildJsonDBC(R"({"records": []})"); + DBCFile dbc; + REQUIRE_FALSE(dbc.load(data)); +} + +TEST_CASE("JSON DBC missing records key", "[dbc][json]") { + auto data = buildJsonDBC(R"({"format": "test"})"); + DBCFile dbc; + REQUIRE_FALSE(dbc.load(data)); +} + +TEST_CASE("JSON DBC findRecordById", "[dbc][json]") { + auto data = buildJsonDBC(R"({ + "fieldCount": 2, + "records": [ + [10, "Alpha"], + [20, "Beta"], + [30, "Gamma"] + ] + })"); + + DBCFile dbc; + REQUIRE(dbc.load(data)); + REQUIRE(dbc.findRecordById(20) == 1); + REQUIRE(dbc.findRecordById(30) == 2); + REQUIRE(dbc.findRecordById(99) == -1); +}