Skip to content

Commit 1e223ab

Browse files
funcs refactor
1 parent 81c971a commit 1e223ab

File tree

6 files changed

+90
-42
lines changed

6 files changed

+90
-42
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ void CLuaObjectDefs::LoadFunctions()
4141
{"setObjectProperty", SetObjectProperty},
4242

4343
// Object util functions
44-
{"getObjectLowLODOfModel", ArgumentParser<GetObjectLowLODOfModel>},
45-
{"getObjectHighLODOfModel", ArgumentParser<GetObjectHighLODOfModel>},
44+
{"getObjectLowLODModel", ArgumentParser<GetObjectLowLODModel>},
45+
{"getObjectHighLODModel", ArgumentParser<GetObjectHighLODModel>},
46+
{"setObjectCustomLowLODModel", ArgumentParser<SetObjectCustomLowLODModel>},
47+
{"getObjectCustomLowLODModel", ArgumentParser<GetObjectCustomLowLODModel>},
48+
{"resetObjectCustomLowLODModel", ArgumentParser<ResetObjectCustomLowLODModel>},
49+
{"resetAllObjectCustomLowLODModels", ArgumentParser<ResetAllObjectCustomLowLODModels>},
4650
};
4751

4852
// Add functions
@@ -727,18 +731,41 @@ bool CLuaObjectDefs::IsObjectRespawnable(CClientEntity* const pEntity) noexcept
727731
return pObject->IsRespawnEnabled();
728732
}
729733

730-
std::variant<bool, std::uint32_t> CLuaObjectDefs::GetObjectLowLODOfModel(std::uint32_t objectModel) noexcept
734+
std::variant<bool, std::uint32_t> CLuaObjectDefs::GetObjectLowLODModel(std::uint32_t hLODModel) noexcept
731735
{
732-
std::uint32_t lodModel = CLodModels::GetObjectLowLODOfModel(objectModel);
736+
std::uint32_t lodModel = CLodModels::GetObjectLowLODModel(hLODModel);
733737
if (lodModel == 0) // LLOD Model not found for HLOD Model provided
734738
return false;
735739
return lodModel;
736740
}
737741

738-
std::variant<bool, std::uint32_t> CLuaObjectDefs::GetObjectHighLODOfModel(std::uint32_t objectModel) noexcept
742+
std::variant<bool, std::uint32_t> CLuaObjectDefs::GetObjectHighLODModel(std::uint32_t lLODModel) noexcept
739743
{
740-
std::uint32_t objModel = CLodModels::GetObjectHighLODOfModel(objectModel);
744+
std::uint32_t objModel = CLodModels::GetObjectHighLODModel(lLODModel);
741745
if (objModel == 0) // HLOD Model not found for LLOD Model provided
742746
return false;
743747
return objModel;
744748
}
749+
750+
void CLuaObjectDefs::SetObjectCustomLowLODModel(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept
751+
{
752+
CLodModels::SetObjectCustomLowLODModel(hLODModel, lLODModel);
753+
}
754+
755+
std::variant<bool, std::uint32_t> CLuaObjectDefs::GetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept
756+
{
757+
std::uint32_t lLODModel = CLodModels::GetObjectCustomLowLODModel(hLODModel);
758+
if (lLODModel == 0) // Custom LLOD Model not found for HLOD Model provided
759+
return false;
760+
return lLODModel;
761+
}
762+
763+
void CLuaObjectDefs::ResetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept
764+
{
765+
CLodModels::ResetObjectCustomLowLODModel(hLODModel);
766+
}
767+
768+
void CLuaObjectDefs::ResetAllObjectCustomLowLODModels() noexcept
769+
{
770+
CLodModels::ResetAllObjectCustomLowLODModels();
771+
}

Client/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class CLuaObjectDefs : public CLuaDefs
4545
LUA_DECLARE(SetObjectProperty);
4646

4747
// Object util funcs
48-
static std::variant<bool, std::uint32_t> GetObjectLowLODOfModel(std::uint32_t objectModel) noexcept;
49-
static std::variant<bool, std::uint32_t> GetObjectHighLODOfModel(std::uint32_t objectModel) noexcept;
48+
static std::variant<bool, std::uint32_t> GetObjectLowLODModel(std::uint32_t hLODModel) noexcept;
49+
static std::variant<bool, std::uint32_t> GetObjectHighLODModel(std::uint32_t lLODModel) noexcept;
50+
static void SetObjectCustomLowLODModel(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept;
51+
static std::variant<bool, std::uint32_t> GetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept;
52+
static void ResetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept;
53+
static void ResetAllObjectCustomLowLODModels() noexcept;
5054
};

Server/mods/deathmatch/logic/luadefs/CLuaObjectDefs.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ void CLuaObjectDefs::LoadFunctions()
3737
{"stopObject", StopObject},
3838
{"breakObject", ArgumentParser<BreakObject>},
3939
{"toggleObjectRespawn", ArgumentParser<ToggleObjectRespawn>},
40-
41-
// Object util functions
42-
{"getObjectLowLODOfModel", ArgumentParser<GetObjectLowLODOfModel>},
43-
{"getObjectHighLODOfModel", ArgumentParser<GetObjectHighLODOfModel>},
4440
};
4541

4642
// Add functions
@@ -338,19 +334,3 @@ bool CLuaObjectDefs::IsObjectRespawnable(CObject* const pObject) noexcept
338334
{
339335
return pObject->IsRespawnEnabled();
340336
}
341-
342-
std::variant<bool, std::uint32_t> CLuaObjectDefs::GetObjectLowLODOfModel(std::uint32_t objectModel) noexcept
343-
{
344-
std::uint32_t lodModel = CLodModels::GetObjectLowLODOfModel(objectModel);
345-
if (lodModel == 0) // LLOD Model not found for HLOD Model provided
346-
return false;
347-
return lodModel;
348-
}
349-
350-
std::variant<bool, std::uint32_t> CLuaObjectDefs::GetObjectHighLODOfModel(std::uint32_t objectModel) noexcept
351-
{
352-
std::uint32_t objModel = CLodModels::GetObjectHighLODOfModel(objectModel);
353-
if (objModel == 0) // HLOD Model not found for LLOD Model provided
354-
return false;
355-
return objModel;
356-
}

Server/mods/deathmatch/logic/luadefs/CLuaObjectDefs.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,4 @@ class CLuaObjectDefs : public CLuaDefs
3939
LUA_DECLARE(StopObject);
4040
static bool BreakObject(CObject* const pObject);
4141
static bool ToggleObjectRespawn(CObject* const pObject, const bool bRespawn) noexcept;
42-
43-
// Object util funcs
44-
static std::variant<bool, std::uint32_t> GetObjectLowLODOfModel(std::uint32_t objectModel) noexcept;
45-
static std::variant<bool, std::uint32_t> GetObjectHighLODOfModel(std::uint32_t objectModel) noexcept;
4642
};

Shared/mods/deathmatch/logic/CLodModels.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
#include "StdInc.h"
1111
#include "CLodModels.h"
1212

13-
// This array associates HLOD Object Model ID -> LLOD Object Model ID for all objects that have LLOD models.
14-
// Data was taken to the game's IPL files (plaintext + binary).
15-
13+
// This array contains all HLOD Object Model ID -> LLOD Object Model ID associations according to the game's IPL files (plaintext + binary).
1614
constexpr std::size_t OBJ_LOD_MODELS_COUNT = 4289;
17-
1815
constexpr std::array<std::pair<std::uint32_t, std::uint32_t>, OBJ_LOD_MODELS_COUNT> OBJ_LOD_MODELS = {{
1916
{694, 784}, // sm_redwoodgrp => lod_redwoodgrp (countryS)
2017
{791, 785}, // vbg_fir_copse => lod_vbg_fir_co (countrye)
@@ -4307,22 +4304,58 @@ constexpr std::array<std::pair<std::uint32_t, std::uint32_t>, OBJ_LOD_MODELS_COU
43074304
{18563, 18564}, // cs_bsupport => cs_bsupportlod (countryS)
43084305
}};
43094306

4310-
std::uint32_t CLodModels::GetObjectLowLODOfModel(std::uint32_t objectModel) noexcept
4307+
// This map is for custom definitions of LLOD models for HLOD models.
4308+
std::unordered_map<std::uint32_t, std::uint32_t> CLodModels::m_customLODModels;
4309+
4310+
std::uint32_t CLodModels::GetObjectLowLODModel(std::uint32_t hLODModel) noexcept
43114311
{
4312+
auto it = CLodModels::m_customLODModels.find(hLODModel);
4313+
if (it != CLodModels::m_customLODModels.end())
4314+
return it->second;
4315+
43124316
for (const auto& entry : OBJ_LOD_MODELS)
43134317
{
4314-
if (entry.first == objectModel)
4318+
if (entry.first == hLODModel)
43154319
return entry.second;
43164320
}
4321+
43174322
return 0;
43184323
}
43194324

4320-
std::uint32_t CLodModels::GetObjectHighLODOfModel(std::uint32_t objectModel) noexcept
4325+
std::uint32_t CLodModels::GetObjectHighLODModel(std::uint32_t lLODModel) noexcept
43214326
{
4327+
for (const auto& entry : CLodModels::m_customLODModels)
4328+
{
4329+
if (entry.second == lLODModel)
4330+
return entry.first;
4331+
}
4332+
43224333
for (const auto& entry : OBJ_LOD_MODELS)
43234334
{
4324-
if (entry.second == objectModel)
4335+
if (entry.second == lLODModel)
43254336
return entry.first;
43264337
}
4338+
43274339
return 0;
43284340
}
4341+
4342+
void CLodModels::SetObjectCustomLowLODModel(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept
4343+
{
4344+
CLodModels::m_customLODModels[hLODModel] = lLODModel;
4345+
}
4346+
4347+
std::uint32_t CLodModels::GetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept
4348+
{
4349+
auto it = CLodModels::m_customLODModels.find(hLODModel);
4350+
return (it != CLodModels::m_customLODModels.end()) ? it->second : 0;
4351+
}
4352+
4353+
void CLodModels::ResetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept
4354+
{
4355+
CLodModels::m_customLODModels.erase(hLODModel);
4356+
}
4357+
4358+
void CLodModels::ResetAllObjectCustomLowLODModels() noexcept
4359+
{
4360+
CLodModels::m_customLODModels.clear();
4361+
}

Shared/mods/deathmatch/logic/CLodModels.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
class CLodModels
1616
{
1717
public:
18-
static std::uint32_t GetObjectLowLODOfModel(std::uint32_t objectModel) noexcept;
19-
static std::uint32_t GetObjectHighLODOfModel(std::uint32_t objectModel) noexcept;
18+
static std::uint32_t GetObjectLowLODModel(std::uint32_t hLODModel) noexcept;
19+
static std::uint32_t GetObjectHighLODModel(std::uint32_t lLODModel) noexcept;
20+
21+
static void SetObjectCustomLowLODModel(std::uint32_t hLODModel, std::uint32_t lLODModel) noexcept;
22+
static std::uint32_t GetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept;
23+
static void ResetObjectCustomLowLODModel(std::uint32_t hLODModel) noexcept;
24+
static void ResetAllObjectCustomLowLODModels() noexcept;
25+
26+
protected:
27+
static std::unordered_map<std::uint32_t, std::uint32_t> m_customLODModels;
2028
};

0 commit comments

Comments
 (0)