Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LOD management functions #3831

Draft
wants to merge 36 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6f7c6c6
add shared func getObjectLODModel(int objectModel)
Fernando-A-Rocha Oct 29, 2024
f182db2
Merge branch 'master' into add-lod-model-func
Fernando-A-Rocha Oct 29, 2024
cb928f1
refactor 1
Fernando-A-Rocha Oct 29, 2024
93251bd
new arg parser
Fernando-A-Rocha Oct 30, 2024
d0419a3
Merge branch 'master' into add-lod-model-func
Fernando-A-Rocha Oct 30, 2024
62cb6e8
rename to GetObjectLODOfModel
Fernando-A-Rocha Oct 30, 2024
c648cbb
add getObjectModelOfLOD
Fernando-A-Rocha Oct 30, 2024
405ad8d
refactors
Fernando-A-Rocha Oct 30, 2024
51e8967
refactor
Fernando-A-Rocha Oct 30, 2024
21e7b28
test @TracerDS
Fernando-A-Rocha Oct 30, 2024
6244ebb
fix OBJ_LOD_MODELS array @TracerDS
Fernando-A-Rocha Oct 31, 2024
73a4252
constexpr
Fernando-A-Rocha Oct 31, 2024
832c6bd
Update CLodModels.cpp
Fernando-A-Rocha Nov 1, 2024
be36dc5
Update CLodModels.cpp
Fernando-A-Rocha Nov 1, 2024
765f7aa
rename GetObjectLowLODOfModel and GetObjectHighLODOfModel
Fernando-A-Rocha Nov 2, 2024
c3613f3
Merge branch 'add-lod-model-func' of github.com:Fernando-A-Rocha/mtas…
Fernando-A-Rocha Nov 2, 2024
71fb7f5
incomplete lod array sorted WIP
Fernando-A-Rocha Nov 2, 2024
26f980e
comment
Fernando-A-Rocha Nov 2, 2024
81c971a
Fixed LOD table WIP
Fernando-A-Rocha Nov 2, 2024
1e223ab
funcs refactor
Fernando-A-Rocha Nov 4, 2024
4225df7
uselesss include
Fernando-A-Rocha Nov 4, 2024
caec9d7
del getObjectCustomLowLODModel
Fernando-A-Rocha Nov 4, 2024
a6466f5
Merge branch 'master' into add-lod-model-func
Fernando-A-Rocha Nov 10, 2024
a43f1ad
Merge branch 'master' into add-lod-model-func
Fernando-A-Rocha Nov 18, 2024
9a1fece
Update Shared/mods/deathmatch/logic/CLodModels.h
Fernando-A-Rocha Nov 18, 2024
0b771df
Update Shared/mods/deathmatch/logic/CLodModels.h
Fernando-A-Rocha Nov 18, 2024
9c117fd
optimize lookups
Fernando-A-Rocha Nov 18, 2024
1f3ddc6
comments
Fernando-A-Rocha Nov 18, 2024
e563d71
Merge branch 'master' into add-lod-model-func
Fernando-A-Rocha Nov 20, 2024
50e282e
Merge branch 'master' into add-lod-model-func
Fernando-A-Rocha Nov 22, 2024
70809d5
Merge branch 'master' into add-lod-model-func
Fernando-A-Rocha Nov 25, 2024
5af6b06
rename funcs, add isValidModel WIP
Fernando-A-Rocha Nov 25, 2024
93c98c8
.
Fernando-A-Rocha Nov 25, 2024
cbad928
.
Fernando-A-Rocha Nov 26, 2024
ab63086
isValidModel update
Fernando-A-Rocha Nov 26, 2024
b03ea49
wip
Fernando-A-Rocha Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Client/mods/deathmatch/StdInc.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
#include <luadefs/CLuaMarkerDefs.h>
#include <luadefs/CLuaNetworkDefs.h>
#include <luadefs/CLuaObjectDefs.h>
#include <luadefs/CLuaModelDefs.h>
#include <luadefs/CLuaPointLightDefs.h>
#include <luadefs/CLuaPedDefs.h>
#include <luadefs/CLuaPickupDefs.h>
Expand Down
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
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/lua/CLuaManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ void CLuaManager::LoadCFunctions()
CLuaMarkerDefs::LoadFunctions();
CLuaNetworkDefs::LoadFunctions();
CLuaObjectDefs::LoadFunctions();
CLuaModelDefs::LoadFunctions();
CLuaPedDefs::LoadFunctions();
CLuaPickupDefs::LoadFunctions();
CLuaPlayerDefs::LoadFunctions();
Expand Down
93 changes: 93 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/shared_logic/luadefs/CLuaModelDefs.cpp
* PURPOSE: Lua model definitions class
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#include "StdInc.h"
#include <lua/CLuaFunctionParser.h>
#include "CLodModels.h"
#include "CClientObjectManager.h"
#include "CClientBuildingManager.h"

void CLuaModelDefs::LoadFunctions()
{
constexpr static const std::pair<const char*, lua_CFunction> functions[]{
// Util func
{"isValidModel", ArgumentParser<IsValidModel>},

// LOD funcs
{"getModelLowLOD", ArgumentParser<GetModelLowLOD>},
{"getModelHighLOD", ArgumentParser<GetModelHighLOD>},
{"setModelLOD", ArgumentParser<SetModelLOD>},
{"resetModelLODByHigh", ArgumentParser<ResetModelLODByHigh>},
{"resetModelLODByLow", ArgumentParser<ResetModelLODByLow>},
{"resetAllModelLOD", ArgumentParser<ResetAllModelLOD>},
};

// Add functions
for (const auto& [name, func] : functions)
CLuaCFunctions::AddFunction(name, func);
}

bool CLuaModelDefs::IsValidModel(std::string modelPurpose, std::uint32_t id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about an enum instead of string?

{
if (modelPurpose == "object")
return CClientObjectManager::IsValidModel(id);
else if (modelPurpose == "weapon")
return CClientPedManager::IsValidWeaponModel(id);
else if (modelPurpose == "upgrade")
return CVehicleUpgrades::IsUpgrade(id);
else if (modelPurpose == "building")
return CClientBuildingManager::IsValidModel(id);
else if (modelPurpose == "vehicle")
return CClientVehicleManager::IsValidModel(id);
else if (modelPurpose == "ped" || modelPurpose == "player")
return CClientPlayerManager::IsValidModel(id);

throw std::invalid_argument("Invalid model purpose passed, expected [object, weapon, upgrade, building, vehicle, ped, player]");
}

std::variant<bool, std::uint32_t> CLuaModelDefs::GetModelLowLOD(std::uint32_t hLODModel) noexcept
{
return CLodModels::GetModelLowLOD(hLODModel);
}

std::variant<bool, std::uint32_t> CLuaModelDefs::GetModelHighLOD(std::uint32_t lLODModel) noexcept
{
return CLodModels::GetModelHighLOD(lLODModel);
}

bool CLuaModelDefs::SetModelLOD(std::string modelPurpose, std::uint32_t hLODModel, std::uint32_t lLODModel)
{
if (!(modelPurpose == "object" || modelPurpose == "building"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(modelPurpose != "object" && modelPurpose != "building")

throw std::invalid_argument("Invalid model purpose passed, the only options for LOD are 'object' or 'building'");

if (!IsValidModel(modelPurpose, hLODModel))
throw std::invalid_argument("Invalid High-LOD model ID passed");

if (!IsValidModel(modelPurpose, lLODModel))
throw std::invalid_argument("Invalid Low-LOD model ID passed");

return CLodModels::SetModelLOD(hLODModel, lLODModel);
}

bool CLuaModelDefs::ResetModelLODByHigh(std::uint32_t hLODModel) noexcept
{
return CLodModels::ResetModelLODByHigh(hLODModel);
}

bool CLuaModelDefs::ResetModelLODByLow(std::uint32_t hLODModel) noexcept
{
return CLodModels::ResetModelLODByLow(hLODModel);
}

void CLuaModelDefs::ResetAllModelLOD() noexcept
{
CLodModels::ResetAllModelLOD();
}
30 changes: 30 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaModelDefs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/shared_logic/luadefs/CLuaModelDefs.h
* PURPOSE: Lua model definitions class header
*
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once
#include "CLuaDefs.h"

class CLuaModelDefs : public CLuaDefs
{
public:
static void LoadFunctions();

// Util func
static bool IsValidModel(std::string modelPurpose, std::uint32_t id);

// LOD funcs
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;
};
Loading
Loading