Skip to content

Add functionality to re-stream models separately #4357

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
90 changes: 73 additions & 17 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6748,47 +6748,54 @@ bool CClientGame::TriggerBrowserRequestResultEvent(const std::unordered_set<SStr
return GetRootEntity()->CallEvent("onClientBrowserWhitelistChange", Arguments, false);
}

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

return true;
}
// Is this an object ID?
else if (CClientObjectManager::IsValidModel(usModel))
else if (CClientObjectManager::IsValidModel(model))
{
if (CClientPedManager::IsValidWeaponModel(usModel))
if (CClientPedManager::IsValidWeaponModel(model))
{
// Stream the weapon of that model out so we have no
// loaded when we do the restore. The streamer will
// eventually stream them back in with async loading.
m_pManager->GetPedManager()->RestreamWeapon(usModel);
m_pManager->GetPickupManager()->RestreamPickups(usModel);
m_pManager->GetPedManager()->RestreamWeapon(model);
m_pManager->GetPickupManager()->RestreamPickups(model);
}
// Stream the objects of that model out so we have no
// loaded when we do the restore. The streamer will
// eventually stream them back in with async loading.
m_pManager->GetObjectManager()->RestreamObjects(usModel);
g_pGame->GetModelInfo(usModel)->RestreamIPL();
m_pManager->GetObjectManager()->RestreamObjects(model);
g_pGame->GetModelInfo(model)->RestreamIPL();

return true;
}
// Is this an ped ID?
else if (CClientPlayerManager::IsValidModel(usModel))
else if (CClientPlayerManager::IsValidModel(model))
{
// Stream the ped of that model out so we have no
// loaded when we do the restore. The streamer will
// eventually stream them back in with async loading.
m_pManager->GetPedManager()->RestreamPeds(usModel);
}
else
m_pManager->GetPedManager()->RestreamPeds(model);

// 'Restream' upgrades after model replacement to propagate visual changes with immediate effect
if (CClientObjectManager::IsValidModel(usModel) && CVehicleUpgrades::IsUpgrade(usModel))
m_pManager->GetVehicleManager()->RestreamVehicleUpgrades(usModel);
return true;
}
// 'Restream' upgrades after model replacement to propagate visual changes with immediate effect
else if (CClientObjectManager::IsValidModel(model) && CVehicleUpgrades::IsUpgrade(model))
{
m_pManager->GetVehicleManager()->RestreamVehicleUpgrades(model);
return true;
}
return false;
}

void CClientGame::RestreamWorld()
Expand All @@ -6808,6 +6815,55 @@ void CClientGame::RestreamWorld()
g_pGame->GetStreaming()->ReinitStreaming();
}

void CClientGame::Restream(std::optional<RestreamOption> option)
{
if (!option.has_value())
option = RestreamOption::ALL;

if (option == RestreamOption::ALL || option == RestreamOption::VEHICLES)
{
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::VEHICLE))
{
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
}

m_pManager->GetVehicleManager()->RestreamAllVehicles();
}

if (option == RestreamOption::ALL || option == RestreamOption::PEDS)
{
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(eClientModelType::PED))
{
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
}

m_pManager->GetPedManager()->RestreamAllPeds();
}

if (option == RestreamOption::ALL || option == RestreamOption::OBJECTS)
{
static constexpr eClientModelType restreamTypes[] = {eClientModelType::OBJECT, eClientModelType::OBJECT_DAMAGEABLE, eClientModelType::TIMED_OBJECT,
eClientModelType::CLUMP};

for (eClientModelType type : restreamTypes)
{
for (const auto& model : m_pManager->GetModelManager()->GetModelsByType(type))
{
g_pClientGame->GetModelCacheManager()->OnRestreamModel(model->GetModelID());
}
}

m_pManager->GetObjectManager()->RestreamAllObjects();
m_pManager->GetPickupManager()->RestreamAllPickups();
}

if (option == RestreamOption::ALL)
{
g_pGame->GetStreaming()->RemoveBigBuildings();
g_pGame->GetStreaming()->ReinitStreaming();
}
}

void CClientGame::ReinitMarkers()
{
g_pGame->Get3DMarkers()->ReinitMarkers();
Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CClientGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,9 @@ class CClientGame
bool IsHighFloatPrecision() const;

bool TriggerBrowserRequestResultEvent(const std::unordered_set<SString>& newPages);
void RestreamModel(unsigned short usModel);
bool RestreamModel(std::uint16_t model);
void RestreamWorld();
void Restream(std::optional<RestreamOption> option);
void ReinitMarkers();

void OnWindowFocusChange(bool state);
Expand Down
7 changes: 7 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,13 @@ ADD_ENUM(PreloadAreaOption::COLLISIONS, "collisions")
ADD_ENUM(PreloadAreaOption::ALL, "all")
IMPLEMENT_ENUM_CLASS_END("preload-area-option")

IMPLEMENT_ENUM_CLASS_BEGIN(RestreamOption)
ADD_ENUM(RestreamOption::ALL, "world")
ADD_ENUM(RestreamOption::VEHICLES, "vehicles")
ADD_ENUM(RestreamOption::PEDS, "peds")
ADD_ENUM(RestreamOption::OBJECTS, "objects")
IMPLEMENT_ENUM_CLASS_END("restream-option")


IMPLEMENT_ENUM_CLASS_BEGIN(taskType)
ADD_ENUM(taskType::PRIMARY_TASK, "primary")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ DECLARE_ENUM(ePools);
DECLARE_ENUM_CLASS(WorldProperty);
DECLARE_ENUM_CLASS(eModelLoadState);
DECLARE_ENUM_CLASS(PreloadAreaOption);
DECLARE_ENUM_CLASS(RestreamOption);
DECLARE_ENUM_CLASS(taskType);
DECLARE_ENUM(eEntityType);
DECLARE_ENUM_CLASS(VehicleAudioSettingProperty);
Expand Down
13 changes: 13 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ void CLuaEngineDefs::LoadFunctions()
{"engineGetPoolUsedCapacity", ArgumentParser<EngineGetPoolUsedCapacity>},
{"engineSetPoolCapacity", ArgumentParser<EngineSetPoolCapacity>},
{"enginePreloadWorldArea", ArgumentParser<EnginePreloadWorldArea>},
{"engineRestreamModel", ArgumentParser<EngineRestreamModel>},
{"engineRestream", ArgumentParser<EngineRestream>},


// CLuaCFunctions::AddFunction ( "engineReplaceMatchingAtomics", EngineReplaceMatchingAtomics );
// CLuaCFunctions::AddFunction ( "engineReplaceWheelAtomics", EngineReplaceWheelAtomics );
Expand Down Expand Up @@ -2593,3 +2596,13 @@ void CLuaEngineDefs::EnginePreloadWorldArea(CVector position, std::optional<Prel
if (option == PreloadAreaOption::ALL || option == PreloadAreaOption::COLLISIONS)
g_pGame->GetStreaming()->LoadSceneCollision(&position);
}

bool CLuaEngineDefs::EngineRestreamModel(std::uint16_t modelId)
{
return g_pClientGame->RestreamModel(modelId);
}

void CLuaEngineDefs::EngineRestream(std::optional<RestreamOption> option)
{
g_pClientGame->Restream(option);
}
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class CLuaEngineDefs : public CLuaDefs
static eModelLoadState EngineStreamingGetModelLoadState(std::uint16_t modelId);

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

private:
static void AddEngineColClass(lua_State* luaVM);
Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/core/CClientBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CClientBase
virtual void PreHUDRenderExecutionHandler(bool bDidUnminimize, bool bDidRecreateRenderTargets) = 0;
virtual void PostFrameExecutionHandler() = 0;
virtual void IdleHandler() = 0;
virtual void RestreamModel(unsigned short usModel) = 0;
virtual void RestreamModel(std::uint16_t model) = 0;

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

Expand Down
8 changes: 8 additions & 0 deletions Client/sdk/game/CStreaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ enum class PreloadAreaOption
ALL
};

enum class RestreamOption
{
ALL = 0,
VEHICLES,
PEDS,
OBJECTS
};

struct CStreamingInfo
{
uint16_t prevId = (uint16_t)-1;
Expand Down