Skip to content

Commit 2d8bc47

Browse files
committed
Add functionality to re-stream models separately
engineRestreamModel - re-stream a specific model using it's ID engineRestream - re-stream a specific group of models (world, vehicles, peds, objects)
1 parent a49ce03 commit 2d8bc47

File tree

7 files changed

+84
-1
lines changed

7 files changed

+84
-1
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6748,7 +6748,7 @@ bool CClientGame::TriggerBrowserRequestResultEvent(const std::unordered_set<SStr
67486748
return GetRootEntity()->CallEvent("onClientBrowserWhitelistChange", Arguments, false);
67496749
}
67506750

6751-
void CClientGame::RestreamModel(unsigned short usModel)
6751+
bool CClientGame::RestreamModel(unsigned short usModel)
67526752
{
67536753
// Is this a vehicle ID?
67546754
if (CClientVehicleManager::IsValidModel(usModel))
@@ -6808,6 +6808,55 @@ void CClientGame::RestreamWorld()
68086808
g_pGame->GetStreaming()->ReinitStreaming();
68096809
}
68106810

6811+
void CClientGame::Restream(std::optional<RestreamOption> option)
6812+
{
6813+
if (!option.has_value())
6814+
option = RestreamOption::ALL;
6815+
6816+
if (option == RestreamOption::ALL || option == RestreamOption::VEHICLES)
6817+
{
6818+
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::VEHICLE))
6819+
{
6820+
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
6821+
}
6822+
6823+
m_pManager->GetVehicleManager()->RestreamAllVehicles();
6824+
}
6825+
6826+
if (option == RestreamOption::ALL || option == RestreamOption::PEDS)
6827+
{
6828+
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::PED))
6829+
{
6830+
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
6831+
}
6832+
6833+
m_pManager->GetPedManager()->RestreamAllPeds();
6834+
}
6835+
6836+
if (option == RestreamOption::ALL || option == RestreamOption::OBJECTS)
6837+
{
6838+
static constexpr eClientModelType restreamTypes[] = {eClientModelType::OBJECT, eClientModelType::OBJECT_DAMAGEABLE, eClientModelType::TIMED_OBJECT,
6839+
eClientModelType::CLUMP};
6840+
6841+
for (eClientModelType type : restreamTypes)
6842+
{
6843+
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(type))
6844+
{
6845+
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
6846+
}
6847+
}
6848+
6849+
m_pManager->GetObjectManager()->RestreamAllObjects();
6850+
}
6851+
6852+
if (option == RestreamOption::ALL)
6853+
{
6854+
m_pManager->GetPickupManager()->RestreamAllPickups();
6855+
g_pGame->GetStreaming()->RemoveBigBuildings();
6856+
g_pGame->GetStreaming()->ReinitStreaming();
6857+
}
6858+
}
6859+
68116860
void CClientGame::ReinitMarkers()
68126861
{
68136862
g_pGame->Get3DMarkers()->ReinitMarkers();

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ class CClientGame
467467
bool TriggerBrowserRequestResultEvent(const std::unordered_set<SString>& newPages);
468468
void RestreamModel(unsigned short usModel);
469469
void RestreamWorld();
470+
void Restream(std::optional<RestreamOption> option);
470471
void ReinitMarkers();
471472

472473
void OnWindowFocusChange(bool state);

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,13 @@ ADD_ENUM(PreloadAreaOption::COLLISIONS, "collisions")
943943
ADD_ENUM(PreloadAreaOption::ALL, "all")
944944
IMPLEMENT_ENUM_CLASS_END("preload-area-option")
945945

946+
IMPLEMENT_ENUM_CLASS_BEGIN(RestreamOption)
947+
ADD_ENUM(RestreamOption::ALL, "world")
948+
ADD_ENUM(RestreamOption::VEHICLES, "vehicles")
949+
ADD_ENUM(RestreamOption::PEDS, "peds")
950+
ADD_ENUM(RestreamOption::OBJECTS, "objects")
951+
IMPLEMENT_ENUM_CLASS_END("restream-option")
952+
946953

947954
IMPLEMENT_ENUM_CLASS_BEGIN(taskType)
948955
ADD_ENUM(taskType::PRIMARY_TASK, "primary")

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ DECLARE_ENUM(ePools);
9898
DECLARE_ENUM_CLASS(WorldProperty);
9999
DECLARE_ENUM_CLASS(eModelLoadState);
100100
DECLARE_ENUM_CLASS(PreloadAreaOption);
101+
DECLARE_ENUM_CLASS(RestreamOption);
101102
DECLARE_ENUM_CLASS(taskType);
102103
DECLARE_ENUM(eEntityType);
103104
DECLARE_ENUM_CLASS(VehicleAudioSettingProperty);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ void CLuaEngineDefs::LoadFunctions()
150150
{"engineGetPoolUsedCapacity", ArgumentParser<EngineGetPoolUsedCapacity>},
151151
{"engineSetPoolCapacity", ArgumentParser<EngineSetPoolCapacity>},
152152
{"enginePreloadWorldArea", ArgumentParser<EnginePreloadWorldArea>},
153+
{"engineRestreamModel", ArgumentParser<EngineRestreamModel>},
154+
{"engineRestream", ArgumentParser<EngineRestream>},
155+
153156

154157
// CLuaCFunctions::AddFunction ( "engineReplaceMatchingAtomics", EngineReplaceMatchingAtomics );
155158
// CLuaCFunctions::AddFunction ( "engineReplaceWheelAtomics", EngineReplaceWheelAtomics );
@@ -2593,3 +2596,15 @@ void CLuaEngineDefs::EnginePreloadWorldArea(CVector position, std::optional<Prel
25932596
if (option == PreloadAreaOption::ALL || option == PreloadAreaOption::COLLISIONS)
25942597
g_pGame->GetStreaming()->LoadSceneCollision(&position);
25952598
}
2599+
2600+
bool CLuaEngineDefs::EngineRestreamModel(std::uint16_t modelId)
2601+
{
2602+
return g_pClientGame->RestreamModel(modelId);
2603+
}
2604+
2605+
bool CLuaEngineDefs::EngineRestream(std::optional<RestreamOption> option)
2606+
{
2607+
g_pClientGame->Restream(option);
2608+
2609+
return true;
2610+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class CLuaEngineDefs : public CLuaDefs
9696
static eModelLoadState EngineStreamingGetModelLoadState(std::uint16_t modelId);
9797

9898
static void EnginePreloadWorldArea(CVector position, std::optional<PreloadAreaOption> option);
99+
static bool EngineRestreamModel(std::uint16_t modelId);
100+
static bool EngineRestream(std::optional<RestreamOption> option);
99101

100102
private:
101103
static void AddEngineColClass(lua_State* luaVM);

Client/sdk/game/CStreaming.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ enum class PreloadAreaOption
4444
ALL
4545
};
4646

47+
enum class RestreamOption
48+
{
49+
ALL = 0,
50+
VEHICLES,
51+
PEDS,
52+
OBJECTS
53+
};
54+
4755
struct CStreamingInfo
4856
{
4957
uint16_t prevId = (uint16_t)-1;

0 commit comments

Comments
 (0)