Skip to content

Commit eb76ac6

Browse files
LamaaarDutchman101tederisFileEX
authored
Add functionality to re-stream models separately (#4357)
* 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) * Make suggested changes * Make suggested changes * Make engineRestreamModel return bool --------- Co-authored-by: Dutchman101 <[email protected]> Co-authored-by: TEDERIs <[email protected]> Co-authored-by: FileEX <[email protected]>
1 parent 117f804 commit eb76ac6

File tree

8 files changed

+107
-19
lines changed

8 files changed

+107
-19
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6797,47 +6797,54 @@ bool CClientGame::TriggerBrowserRequestResultEvent(const std::unordered_set<SStr
67976797
return GetRootEntity()->CallEvent("onClientBrowserWhitelistChange", Arguments, false);
67986798
}
67996799

6800-
void CClientGame::RestreamModel(unsigned short usModel)
6800+
bool CClientGame::RestreamModel(std::uint16_t model)
68016801
{
68026802
// Is this a vehicle ID?
6803-
if (CClientVehicleManager::IsValidModel(usModel))
6803+
if (CClientVehicleManager::IsValidModel(model))
68046804
{
68056805
// Stream the vehicles of that model out so we have no
68066806
// loaded when we do the restore. The streamer will
68076807
// eventually stream them back in with async loading.
6808-
m_pManager->GetVehicleManager()->RestreamVehicles(usModel);
6809-
}
6808+
m_pManager->GetVehicleManager()->RestreamVehicles(model);
68106809

6810+
return true;
6811+
}
68116812
// Is this an object ID?
6812-
else if (CClientObjectManager::IsValidModel(usModel))
6813+
else if (CClientObjectManager::IsValidModel(model))
68136814
{
6814-
if (CClientPedManager::IsValidWeaponModel(usModel))
6815+
if (CClientPedManager::IsValidWeaponModel(model))
68156816
{
68166817
// Stream the weapon of that model out so we have no
68176818
// loaded when we do the restore. The streamer will
68186819
// eventually stream them back in with async loading.
6819-
m_pManager->GetPedManager()->RestreamWeapon(usModel);
6820-
m_pManager->GetPickupManager()->RestreamPickups(usModel);
6820+
m_pManager->GetPedManager()->RestreamWeapon(model);
6821+
m_pManager->GetPickupManager()->RestreamPickups(model);
68216822
}
68226823
// Stream the objects of that model out so we have no
68236824
// loaded when we do the restore. The streamer will
68246825
// eventually stream them back in with async loading.
6825-
m_pManager->GetObjectManager()->RestreamObjects(usModel);
6826-
g_pGame->GetModelInfo(usModel)->RestreamIPL();
6826+
m_pManager->GetObjectManager()->RestreamObjects(model);
6827+
g_pGame->GetModelInfo(model)->RestreamIPL();
6828+
6829+
return true;
68276830
}
68286831
// Is this an ped ID?
6829-
else if (CClientPlayerManager::IsValidModel(usModel))
6832+
else if (CClientPlayerManager::IsValidModel(model))
68306833
{
68316834
// Stream the ped of that model out so we have no
68326835
// loaded when we do the restore. The streamer will
68336836
// eventually stream them back in with async loading.
6834-
m_pManager->GetPedManager()->RestreamPeds(usModel);
6835-
}
6836-
else
6837+
m_pManager->GetPedManager()->RestreamPeds(model);
68376838

6838-
// 'Restream' upgrades after model replacement to propagate visual changes with immediate effect
6839-
if (CClientObjectManager::IsValidModel(usModel) && CVehicleUpgrades::IsUpgrade(usModel))
6840-
m_pManager->GetVehicleManager()->RestreamVehicleUpgrades(usModel);
6839+
return true;
6840+
}
6841+
// 'Restream' upgrades after model replacement to propagate visual changes with immediate effect
6842+
else if (CClientObjectManager::IsValidModel(model) && CVehicleUpgrades::IsUpgrade(model))
6843+
{
6844+
m_pManager->GetVehicleManager()->RestreamVehicleUpgrades(model);
6845+
return true;
6846+
}
6847+
return false;
68416848
}
68426849

68436850
void CClientGame::RestreamWorld()
@@ -6858,6 +6865,55 @@ void CClientGame::RestreamWorld()
68586865
g_pGame->GetStreaming()->ReinitStreaming();
68596866
}
68606867

6868+
void CClientGame::Restream(std::optional<RestreamOption> option)
6869+
{
6870+
if (!option.has_value())
6871+
option = RestreamOption::ALL;
6872+
6873+
if (option == RestreamOption::ALL || option == RestreamOption::VEHICLES)
6874+
{
6875+
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::VEHICLE))
6876+
{
6877+
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
6878+
}
6879+
6880+
m_pManager->GetVehicleManager()->RestreamAllVehicles();
6881+
}
6882+
6883+
if (option == RestreamOption::ALL || option == RestreamOption::PEDS)
6884+
{
6885+
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::PED))
6886+
{
6887+
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
6888+
}
6889+
6890+
m_pManager->GetPedManager()->RestreamAllPeds();
6891+
}
6892+
6893+
if (option == RestreamOption::ALL || option == RestreamOption::OBJECTS)
6894+
{
6895+
static constexpr eClientModelType restreamTypes[] = {eClientModelType::OBJECT, eClientModelType::OBJECT_DAMAGEABLE, eClientModelType::TIMED_OBJECT,
6896+
eClientModelType::CLUMP};
6897+
6898+
for (eClientModelType type : restreamTypes)
6899+
{
6900+
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(type))
6901+
{
6902+
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
6903+
}
6904+
}
6905+
6906+
m_pManager->GetObjectManager()->RestreamAllObjects();
6907+
m_pManager->GetPickupManager()->RestreamAllPickups();
6908+
}
6909+
6910+
if (option == RestreamOption::ALL)
6911+
{
6912+
g_pGame->GetStreaming()->RemoveBigBuildings();
6913+
g_pGame->GetStreaming()->ReinitStreaming();
6914+
}
6915+
}
6916+
68616917
void CClientGame::ReinitMarkers()
68626918
{
68636919
g_pGame->Get3DMarkers()->ReinitMarkers();

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,9 @@ class CClientGame
504504
bool IsHighFloatPrecision() const;
505505

506506
bool TriggerBrowserRequestResultEvent(const std::unordered_set<SString>& newPages);
507-
void RestreamModel(unsigned short usModel);
507+
bool RestreamModel(std::uint16_t model);
508508
void RestreamWorld();
509+
void Restream(std::optional<RestreamOption> option);
509510
void ReinitMarkers();
510511

511512
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
@@ -946,6 +946,13 @@ ADD_ENUM(PreloadAreaOption::COLLISIONS, "collisions")
946946
ADD_ENUM(PreloadAreaOption::ALL, "all")
947947
IMPLEMENT_ENUM_CLASS_END("preload-area-option")
948948

949+
IMPLEMENT_ENUM_CLASS_BEGIN(RestreamOption)
950+
ADD_ENUM(RestreamOption::ALL, "world")
951+
ADD_ENUM(RestreamOption::VEHICLES, "vehicles")
952+
ADD_ENUM(RestreamOption::PEDS, "peds")
953+
ADD_ENUM(RestreamOption::OBJECTS, "objects")
954+
IMPLEMENT_ENUM_CLASS_END("restream-option")
955+
949956

950957
IMPLEMENT_ENUM_CLASS_BEGIN(taskType)
951958
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: 13 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 );
@@ -2602,3 +2605,13 @@ void CLuaEngineDefs::EnginePreloadWorldArea(CVector position, std::optional<Prel
26022605
if (option == PreloadAreaOption::ALL || option == PreloadAreaOption::COLLISIONS)
26032606
g_pGame->GetStreaming()->LoadSceneCollision(&position);
26042607
}
2608+
2609+
bool CLuaEngineDefs::EngineRestreamModel(std::uint16_t modelId)
2610+
{
2611+
return g_pClientGame->RestreamModel(modelId);
2612+
}
2613+
2614+
void CLuaEngineDefs::EngineRestream(std::optional<RestreamOption> option)
2615+
{
2616+
g_pClientGame->Restream(option);
2617+
}

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 void EngineRestream(std::optional<RestreamOption> option);
99101

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

Client/sdk/core/CClientBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CClientBase
2424
virtual void PreHUDRenderExecutionHandler(bool bDidUnminimize, bool bDidRecreateRenderTargets) = 0;
2525
virtual void PostFrameExecutionHandler() = 0;
2626
virtual void IdleHandler() = 0;
27-
virtual void RestreamModel(unsigned short usModel) = 0;
27+
virtual void RestreamModel(std::uint16_t model) = 0;
2828

2929
virtual bool WebsiteRequestResultHandler(const std::unordered_set<SString>& newPages) = 0;
3030

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)