From b03ea49515cde73c833f84db82b2f42daf130a88 Mon Sep 17 00:00:00 2001 From: Fernando-A-Rocha Date: Tue, 26 Nov 2024 02:23:39 +0000 Subject: [PATCH] wip --- .../deathmatch/logic/CClientModelManager.cpp | 10 ++++++ .../logic/luadefs/CLuaModelDefs.cpp | 36 +++++++++++-------- .../deathmatch/logic/luadefs/CLuaModelDefs.h | 11 +++--- Shared/mods/deathmatch/logic/CLodModels.cpp | 20 ++++++++--- Shared/mods/deathmatch/logic/CLodModels.h | 11 +++--- 5 files changed, 58 insertions(+), 30 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientModelManager.cpp b/Client/mods/deathmatch/logic/CClientModelManager.cpp index 9b4ae7cc39..bb927984c3 100644 --- a/Client/mods/deathmatch/logic/CClientModelManager.cpp +++ b/Client/mods/deathmatch/logic/CClientModelManager.cpp @@ -9,6 +9,8 @@ *****************************************************************************/ #include "StdInc.h" +#include "CLodModels.h" + CClientModelManager::CClientModelManager() : m_Models(std::make_unique[]>(g_pGame->GetBaseIDforCOL())) { const unsigned int uiMaxModelID = g_pGame->GetBaseIDforCOL(); @@ -21,6 +23,9 @@ CClientModelManager::CClientModelManager() : m_Models(std::make_unique& pModel) m_Models[modelId]->RestoreEntitiesUsingThisModel(); m_Models[modelId] = nullptr; m_modelCount--; + + // Force reset the model in Level-Of-Detail system + CLodModels::ResetModelLODByHigh(modelId); + CLodModels::ResetModelLODByLow(modelId); + return true; } return false; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.cpp index 57bc2c6a47..c9d7c19dc6 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.cpp @@ -22,11 +22,12 @@ void CLuaModelDefs::LoadFunctions() {"isValidModel", ArgumentParser}, // LOD funcs - {"getLowLODModel", ArgumentParser}, - {"getHighLODModel", ArgumentParser}, - {"setLowLODModel", ArgumentParser}, - {"resetLowLODModel", ArgumentParser}, - {"resetLowLODModels", ArgumentParser}, + {"getModelLowLOD", ArgumentParser}, + {"getModelHighLOD", ArgumentParser}, + {"setModelLOD", ArgumentParser}, + {"resetModelLODByHigh", ArgumentParser}, + {"resetModelLODByLow", ArgumentParser}, + {"resetAllModelLOD", ArgumentParser}, }; // Add functions @@ -52,17 +53,17 @@ bool CLuaModelDefs::IsValidModel(std::string modelPurpose, std::uint32_t id) throw std::invalid_argument("Invalid model purpose passed, expected [object, weapon, upgrade, building, vehicle, ped, player]"); } -std::variant CLuaModelDefs::GetLowLODModel(std::uint32_t hLODModel) noexcept +std::variant CLuaModelDefs::GetModelLowLOD(std::uint32_t hLODModel) noexcept { - return CLodModels::GetLowLODModel(hLODModel); + return CLodModels::GetModelLowLOD(hLODModel); } -std::variant CLuaModelDefs::GetHighLODModel(std::uint32_t lLODModel) noexcept +std::variant CLuaModelDefs::GetModelHighLOD(std::uint32_t lLODModel) noexcept { - return CLodModels::GetHighLODModel(lLODModel); + return CLodModels::GetModelHighLOD(lLODModel); } -bool CLuaModelDefs::SetLowLODModel(std::string modelPurpose, std::uint32_t hLODModel, std::uint32_t lLODModel) +bool CLuaModelDefs::SetModelLOD(std::string modelPurpose, std::uint32_t hLODModel, std::uint32_t lLODModel) { if (!(modelPurpose == "object" || modelPurpose == "building")) throw std::invalid_argument("Invalid model purpose passed, the only options for LOD are 'object' or 'building'"); @@ -73,15 +74,20 @@ bool CLuaModelDefs::SetLowLODModel(std::string modelPurpose, std::uint32_t hLODM if (!IsValidModel(modelPurpose, lLODModel)) throw std::invalid_argument("Invalid Low-LOD model ID passed"); - return CLodModels::SetLowLODModel(hLODModel, lLODModel); + return CLodModels::SetModelLOD(hLODModel, lLODModel); } -bool CLuaModelDefs::ResetLowLODModel(std::uint32_t hLODModel) noexcept +bool CLuaModelDefs::ResetModelLODByHigh(std::uint32_t hLODModel) noexcept { - return CLodModels::ResetLowLODModel(hLODModel); + return CLodModels::ResetModelLODByHigh(hLODModel); } -void CLuaModelDefs::ResetLowLODModels() noexcept +bool CLuaModelDefs::ResetModelLODByLow(std::uint32_t hLODModel) noexcept { - CLodModels::ResetLowLODModels(); + return CLodModels::ResetModelLODByLow(hLODModel); +} + +void CLuaModelDefs::ResetAllModelLOD() noexcept +{ + CLodModels::ResetAllModelLOD(); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.h index 80d14a0d15..482350a593 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.h @@ -21,9 +21,10 @@ class CLuaModelDefs : public CLuaDefs static bool IsValidModel(std::string modelPurpose, std::uint32_t id); // LOD funcs - static std::variant GetLowLODModel(std::uint32_t hLODModel) noexcept; - static std::variant GetHighLODModel(std::uint32_t lLODModel) noexcept; - static bool SetLowLODModel(std::string modelPurpose, std::uint32_t hLODModel, std::uint32_t lLODModel); - static bool ResetLowLODModel(std::uint32_t hLODModel) noexcept; - static void ResetLowLODModels() noexcept; + static std::variant GetModelLowLOD(std::uint32_t hLODModel) noexcept; + static std::variant GetModelHighLOD(std::uint32_t lLODModel) noexcept; + static bool SetModelLOD(std::string modelPurpose, std::uint32_t hLODModel, std::uint32_t lLODModel); + static bool ResetModelLODByHigh(std::uint32_t hLODModel) noexcept; + static bool ResetModelLODByLow(std::uint32_t lLODModel) noexcept; + static void ResetAllModelLOD() noexcept; }; diff --git a/Shared/mods/deathmatch/logic/CLodModels.cpp b/Shared/mods/deathmatch/logic/CLodModels.cpp index eac25251dc..5a78e8447f 100644 --- a/Shared/mods/deathmatch/logic/CLodModels.cpp +++ b/Shared/mods/deathmatch/logic/CLodModels.cpp @@ -4329,7 +4329,7 @@ void CLodModels::UpdateReverseCustomLODModels() noexcept m_reverseCustomLODModels[entry.second] = entry.first; } -std::variant CLodModels::GetLowLODModel(std::uint32_t hLODModel) noexcept +std::variant CLodModels::GetModelLowLOD(std::uint32_t hLODModel) noexcept { if (auto it = m_customLODModels.find(hLODModel); it != m_customLODModels.end()) return it->second; @@ -4340,7 +4340,7 @@ std::variant CLodModels::GetLowLODModel(std::uint32_t hLODM return false; } -std::variant CLodModels::GetHighLODModel(std::uint32_t lLODModel) noexcept +std::variant CLodModels::GetModelHighLOD(std::uint32_t lLODModel) noexcept { if (auto it = m_reverseCustomLODModels.find(lLODModel); it != m_reverseCustomLODModels.end()) return it->second; @@ -4351,7 +4351,7 @@ std::variant CLodModels::GetHighLODModel(std::uint32_t lLOD return false; } -bool CLodModels::SetLowLODModel(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept +bool CLodModels::SetModelLOD(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept { if (m_customLODModels.find(hLODModel) != m_customLODModels.end()) return false; @@ -4361,7 +4361,7 @@ bool CLodModels::SetLowLODModel(std::uint32_t hLODModel, std::uint32_t lLODModel return true; } -bool CLodModels::ResetLowLODModel(std::uint32_t hLODModel) noexcept +bool CLodModels::ResetModelLODByHigh(std::uint32_t hLODModel) noexcept { if (m_customLODModels.find(hLODModel) == m_customLODModels.end()) return false; @@ -4371,7 +4371,17 @@ bool CLodModels::ResetLowLODModel(std::uint32_t hLODModel) noexcept return true; } -void CLodModels::ResetLowLODModels() noexcept +bool CLodModels::ResetModelLODByLow(std::uint32_t lLODModel) noexcept +{ + if (m_reverseCustomLODModels.find(lLODModel) == m_reverseCustomLODModels.end()) + return false; + + m_customLODModels.erase(m_reverseCustomLODModels[lLODModel]); + UpdateReverseCustomLODModels(); + return true; +} + +void CLodModels::ResetAllModelLOD() noexcept { m_customLODModels.clear(); UpdateReverseCustomLODModels(); diff --git a/Shared/mods/deathmatch/logic/CLodModels.h b/Shared/mods/deathmatch/logic/CLodModels.h index 9488e23af9..8669869681 100644 --- a/Shared/mods/deathmatch/logic/CLodModels.h +++ b/Shared/mods/deathmatch/logic/CLodModels.h @@ -13,13 +13,14 @@ class CLodModels { public: - static std::variant GetLowLODModel(std::uint32_t hLODModel) noexcept; - static std::variant GetHighLODModel(std::uint32_t lLODModel) noexcept; + static std::variant GetModelLowLOD(std::uint32_t hLODModel) noexcept; + static std::variant GetModelHighLOD(std::uint32_t lLODModel) noexcept; - static bool SetLowLODModel(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept; - static bool ResetLowLODModel(std::uint32_t hLODModel) noexcept; + static bool SetModelLOD(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept; + static bool ResetModelLODByHigh(std::uint32_t hLODModel) noexcept; + static bool ResetModelLODByLow(std::uint32_t lLODModel) noexcept; - static void ResetLowLODModels() noexcept; + static void ResetAllModelLOD() noexcept; private: // This map contains all HLOD Object Model ID -> LLOD Object Model ID associations