|
10 | 10 | #include "StdInc.h" |
11 | 11 | #include "CLodModels.h" |
12 | 12 |
|
13 | | -// This array contains all HLOD Object Model ID -> LLOD Object Model ID associations according to the game's IPL files (plaintext + binary). |
14 | 13 | constexpr std::size_t OBJ_LOD_MODELS_COUNT = 4289; |
15 | | -constexpr std::array<std::pair<std::uint32_t, std::uint32_t>, OBJ_LOD_MODELS_COUNT> OBJ_LOD_MODELS = {{ |
| 14 | +constexpr std::pair<std::uint32_t, std::uint32_t> OBJ_LOD_MODELS_ARRAY[] = { |
16 | 15 | {694, 784}, // sm_redwoodgrp => lod_redwoodgrp (countryS) |
17 | 16 | {791, 785}, // vbg_fir_copse => lod_vbg_fir_co (countrye) |
18 | 17 | {1259, 1268}, // billbd1 => lodlbd1 (LAe) |
@@ -4302,54 +4301,76 @@ constexpr std::array<std::pair<std::uint32_t, std::uint32_t>, OBJ_LOD_MODELS_COU |
4302 | 4301 | {18552, 18554}, // cunts_ammun => cunts_ammun_lod (countryS) |
4303 | 4302 | {18561, 18562}, // cs_newbridge => cs_newbridge_lod (countryS) |
4304 | 4303 | {18563, 18564}, // cs_bsupport => cs_bsupportlod (countryS) |
4305 | | -}}; |
| 4304 | +}; |
| 4305 | + |
| 4306 | +const std::unordered_map<std::uint32_t, std::uint32_t> CLodModels::m_predefinedLODModels = []() |
| 4307 | +{ |
| 4308 | + std::unordered_map<std::uint32_t, std::uint32_t> map; |
| 4309 | + for (const auto& pair : OBJ_LOD_MODELS_ARRAY) |
| 4310 | + map.emplace(pair.first, pair.second); |
| 4311 | + return map; |
| 4312 | +}(); |
| 4313 | + |
| 4314 | +const std::unordered_map<std::uint32_t, std::uint32_t> CLodModels::m_reversePredefinedLODModels = []() |
| 4315 | +{ |
| 4316 | + std::unordered_map<std::uint32_t, std::uint32_t> map; |
| 4317 | + for (const auto& entry : OBJ_LOD_MODELS_ARRAY) |
| 4318 | + map[entry.second] = entry.first; |
| 4319 | + return map; |
| 4320 | +}(); |
4306 | 4321 |
|
4307 | | -// This map is for custom definitions of LLOD models for HLOD models. |
4308 | 4322 | std::unordered_map<std::uint32_t, std::uint32_t> CLodModels::m_customLODModels; |
| 4323 | +std::unordered_map<std::uint32_t, std::uint32_t> CLodModels::m_reverseCustomLODModels; |
| 4324 | + |
| 4325 | +void CLodModels::UpdateReverseCustomLODModels() |
| 4326 | +{ |
| 4327 | + m_reverseCustomLODModels.clear(); |
| 4328 | + for (const auto& entry : m_customLODModels) |
| 4329 | + m_reverseCustomLODModels[entry.second] = entry.first; |
| 4330 | +} |
4309 | 4331 |
|
4310 | 4332 | std::uint32_t CLodModels::GetObjectLowLODModel(std::uint32_t hLODModel) noexcept |
4311 | 4333 | { |
4312 | | - auto it = CLodModels::m_customLODModels.find(hLODModel); |
4313 | | - if (it != CLodModels::m_customLODModels.end()) |
| 4334 | + // Check custom LOD models first |
| 4335 | + if (auto it = m_customLODModels.find(hLODModel); it != m_customLODModels.end()) |
4314 | 4336 | return it->second; |
4315 | 4337 |
|
4316 | | - for (const auto& entry : OBJ_LOD_MODELS) |
4317 | | - { |
4318 | | - if (entry.first == hLODModel) |
4319 | | - return entry.second; |
4320 | | - } |
| 4338 | + // Fallback to predefined LOD models |
| 4339 | + if (auto it2 = m_predefinedLODModels.find(hLODModel); it2 != m_predefinedLODModels.end()) |
| 4340 | + return it2->second; |
4321 | 4341 |
|
| 4342 | + // Default value if no match found |
4322 | 4343 | return 0; |
4323 | 4344 | } |
4324 | 4345 |
|
4325 | 4346 | std::uint32_t CLodModels::GetObjectHighLODModel(std::uint32_t lLODModel) noexcept |
4326 | 4347 | { |
4327 | | - for (const auto& entry : CLodModels::m_customLODModels) |
4328 | | - { |
4329 | | - if (entry.second == lLODModel) |
4330 | | - return entry.first; |
4331 | | - } |
| 4348 | + // Check custom reverse lookup map |
| 4349 | + if (auto it = m_reverseCustomLODModels.find(lLODModel); it != m_reverseCustomLODModels.end()) |
| 4350 | + return it->second; |
4332 | 4351 |
|
4333 | | - for (const auto& entry : OBJ_LOD_MODELS) |
4334 | | - { |
4335 | | - if (entry.second == lLODModel) |
4336 | | - return entry.first; |
4337 | | - } |
| 4352 | + // Check predefined reverse lookup map |
| 4353 | + if (auto it2 = m_reversePredefinedLODModels.find(lLODModel); it2 != m_reversePredefinedLODModels.end()) |
| 4354 | + return it2->second; |
4338 | 4355 |
|
| 4356 | + // Default return value if no match found |
4339 | 4357 | return 0; |
4340 | 4358 | } |
4341 | 4359 |
|
4342 | 4360 | void CLodModels::SetObjectCustomLowLODModel(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept |
4343 | 4361 | { |
4344 | | - CLodModels::m_customLODModels[hLODModel] = lLODModel; |
| 4362 | + m_customLODModels[hLODModel] = lLODModel; |
| 4363 | + UpdateReverseCustomLODModels(); |
4345 | 4364 | } |
4346 | 4365 |
|
4347 | 4366 | void CLodModels::ResetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept |
4348 | 4367 | { |
4349 | | - CLodModels::m_customLODModels.erase(hLODModel); |
| 4368 | + m_customLODModels.erase(hLODModel); |
| 4369 | + UpdateReverseCustomLODModels(); |
4350 | 4370 | } |
4351 | 4371 |
|
4352 | 4372 | void CLodModels::ResetAllObjectCustomLowLODModels() noexcept |
4353 | 4373 | { |
4354 | | - CLodModels::m_customLODModels.clear(); |
| 4374 | + m_customLODModels.clear(); |
| 4375 | + UpdateReverseCustomLODModels(); |
4355 | 4376 | } |
0 commit comments