Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Nov 26, 2024
1 parent ab63086 commit b03ea49
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 30 deletions.
10 changes: 10 additions & 0 deletions Client/mods/deathmatch/logic/CClientModelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*****************************************************************************/

#include "StdInc.h"
#include "CLodModels.h"

CClientModelManager::CClientModelManager() : m_Models(std::make_unique<std::shared_ptr<CClientModel>[]>(g_pGame->GetBaseIDforCOL()))
{
const unsigned int uiMaxModelID = g_pGame->GetBaseIDforCOL();
Expand All @@ -21,6 +23,9 @@ CClientModelManager::CClientModelManager() : m_Models(std::make_unique<std::shar
CClientModelManager::~CClientModelManager(void)
{
RemoveAll();

// Reset Level-Of-Detail system
CLodModels::ResetAllModelLOD();
}

void CClientModelManager::RemoveAll(void)
Expand Down Expand Up @@ -55,6 +60,11 @@ bool CClientModelManager::Remove(const std::shared_ptr<CClientModel>& 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;
Expand Down
36 changes: 21 additions & 15 deletions Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ void CLuaModelDefs::LoadFunctions()
{"isValidModel", ArgumentParser<IsValidModel>},

// LOD funcs
{"getLowLODModel", ArgumentParser<GetLowLODModel>},
{"getHighLODModel", ArgumentParser<GetHighLODModel>},
{"setLowLODModel", ArgumentParser<SetLowLODModel>},
{"resetLowLODModel", ArgumentParser<ResetLowLODModel>},
{"resetLowLODModels", ArgumentParser<ResetLowLODModels>},
{"getModelLowLOD", ArgumentParser<GetModelLowLOD>},
{"getModelHighLOD", ArgumentParser<GetModelHighLOD>},
{"setModelLOD", ArgumentParser<SetModelLOD>},
{"resetModelLODByHigh", ArgumentParser<ResetModelLODByHigh>},
{"resetModelLODByLow", ArgumentParser<ResetModelLODByLow>},
{"resetAllModelLOD", ArgumentParser<ResetAllModelLOD>},
};

// Add functions
Expand All @@ -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<bool, std::uint32_t> CLuaModelDefs::GetLowLODModel(std::uint32_t hLODModel) noexcept
std::variant<bool, std::uint32_t> CLuaModelDefs::GetModelLowLOD(std::uint32_t hLODModel) noexcept
{
return CLodModels::GetLowLODModel(hLODModel);
return CLodModels::GetModelLowLOD(hLODModel);
}

std::variant<bool, std::uint32_t> CLuaModelDefs::GetHighLODModel(std::uint32_t lLODModel) noexcept
std::variant<bool, std::uint32_t> 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'");
Expand All @@ -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();
}
11 changes: 6 additions & 5 deletions Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class CLuaModelDefs : public CLuaDefs
static bool IsValidModel(std::string modelPurpose, std::uint32_t id);

// LOD funcs
static std::variant<bool, std::uint32_t> GetLowLODModel(std::uint32_t hLODModel) noexcept;
static std::variant<bool, std::uint32_t> 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<bool, std::uint32_t> GetModelLowLOD(std::uint32_t hLODModel) noexcept;
static std::variant<bool, std::uint32_t> 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;
};
20 changes: 15 additions & 5 deletions Shared/mods/deathmatch/logic/CLodModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4329,7 +4329,7 @@ void CLodModels::UpdateReverseCustomLODModels() noexcept
m_reverseCustomLODModels[entry.second] = entry.first;
}

std::variant<bool, std::uint32_t> CLodModels::GetLowLODModel(std::uint32_t hLODModel) noexcept
std::variant<bool, std::uint32_t> CLodModels::GetModelLowLOD(std::uint32_t hLODModel) noexcept
{
if (auto it = m_customLODModels.find(hLODModel); it != m_customLODModels.end())
return it->second;
Expand All @@ -4340,7 +4340,7 @@ std::variant<bool, std::uint32_t> CLodModels::GetLowLODModel(std::uint32_t hLODM
return false;
}

std::variant<bool, std::uint32_t> CLodModels::GetHighLODModel(std::uint32_t lLODModel) noexcept
std::variant<bool, std::uint32_t> CLodModels::GetModelHighLOD(std::uint32_t lLODModel) noexcept
{
if (auto it = m_reverseCustomLODModels.find(lLODModel); it != m_reverseCustomLODModels.end())
return it->second;
Expand All @@ -4351,7 +4351,7 @@ std::variant<bool, std::uint32_t> 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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down
11 changes: 6 additions & 5 deletions Shared/mods/deathmatch/logic/CLodModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
class CLodModels
{
public:
static std::variant<bool, std::uint32_t> GetLowLODModel(std::uint32_t hLODModel) noexcept;
static std::variant<bool, std::uint32_t> GetHighLODModel(std::uint32_t lLODModel) noexcept;
static std::variant<bool, std::uint32_t> GetModelLowLOD(std::uint32_t hLODModel) noexcept;
static std::variant<bool, std::uint32_t> 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
Expand Down

0 comments on commit b03ea49

Please sign in to comment.