Skip to content

Commit 2308f5a

Browse files
committed
Set maximum lod for vehs and peds and reset to the min of all sources
1 parent 879d8c6 commit 2308f5a

File tree

7 files changed

+148
-67
lines changed

7 files changed

+148
-67
lines changed

Client/core/CCore.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ void CCore::ApplyGameSettings()
552552
CVARS_GET("tyre_smoke_enabled", bVal);
553553
m_pMultiplayer->SetTyreSmokeEnabled(bVal);
554554
pGameSettings->UpdateFieldOfViewFromSettings();
555-
pGameSettings->ResetVehiclesLODDistance();
555+
pGameSettings->ResetVehiclesLODDistance(false);
556+
pGameSettings->ResetPedsLODDistance(false);
556557
pController->SetVerticalAimSensitivityRawValue(CVARS_GET_VALUE<float>("vertical_aim_sensitivity"));
557558
CVARS_GET("mastervolume", fVal);
558559
pGameSettings->SetRadioVolume(pGameSettings->GetRadioVolume() * fVal);

Client/core/CSettings.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,8 +1753,8 @@ bool CSettings::OnVideoDefaultClick(CGUIElement* pElement)
17531753
gameSettings->SetBrightness(253);
17541754
gameSettings->SetFXQuality(2);
17551755
gameSettings->SetAntiAliasing(1, true);
1756-
gameSettings->ResetVehiclesLODDistance();
1757-
gameSettings->ResetPedsLODDistance();
1756+
gameSettings->ResetVehiclesLODDistance(false);
1757+
gameSettings->ResetPedsLODDistance(false);
17581758

17591759
// change
17601760
bool bIsVideoModeChanged = GetVideoModeManager()->SetVideoMode(0, false, false, FULLSCREEN_STANDARD);
@@ -3327,12 +3327,12 @@ void CSettings::SaveData()
33273327
// High detail vehicles
33283328
bool bHighDetailVehicles = m_pCheckBoxHighDetailVehicles->GetSelected();
33293329
CVARS_SET("high_detail_vehicles", bHighDetailVehicles);
3330-
gameSettings->ResetVehiclesLODDistance();
3330+
gameSettings->ResetVehiclesLODDistance(false);
33313331

33323332
// High detail peds
33333333
bool bHighDetailPeds = m_pCheckBoxHighDetailPeds->GetSelected();
33343334
CVARS_SET("high_detail_peds", bHighDetailPeds);
3335-
gameSettings->ResetPedsLODDistance();
3335+
gameSettings->ResetPedsLODDistance(false);
33363336

33373337
// Fast clothes loading
33383338
if (CGUIListItem* pSelected = m_pFastClothesCombo->GetSelectedItem())

Client/game_sa/CSettingsSA.cpp

Lines changed: 124 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: game_sa/CSettingsSA.cpp
66
* PURPOSE: Game settings
@@ -24,14 +24,14 @@ unsigned long CSettingsSA::FUNC_GetNumSubSystems;
2424
unsigned long CSettingsSA::FUNC_GetCurrentSubSystem;
2525
unsigned long CSettingsSA::FUNC_SetSubSystem;
2626

27-
#define VAR_CurVideoMode (*((uint*)(0x08D6220)))
28-
#define VAR_SavedVideoMode (*((uint*)(0x0BA6820)))
29-
#define VAR_CurAdapter (*((uint*)(0x0C920F4)))
27+
#define VAR_CurVideoMode (*((uint*)(0x08D6220)))
28+
#define VAR_SavedVideoMode (*((uint*)(0x0BA6820)))
29+
#define VAR_CurAdapter (*((uint*)(0x0C920F4)))
3030

31-
#define HOOKPOS_GetFxQuality 0x49EA50
31+
#define HOOKPOS_GetFxQuality 0x49EA50
3232
void HOOK_GetFxQuality();
3333

34-
#define HOOKPOS_StoreShadowForVehicle 0x70BDA0
34+
#define HOOKPOS_StoreShadowForVehicle 0x70BDA0
3535
DWORD RETURN_StoreShadowForVehicle = 0x70BDA9;
3636
void HOOK_StoreShadowForVehicle();
3737

@@ -227,11 +227,11 @@ float CSettingsSA::GetDrawDistance()
227227
void CSettingsSA::SetDrawDistance(float fDistance)
228228
{
229229
_asm
230-
{
230+
{
231231
push fDistance
232232
call FUNC_SetDrawDistance
233233
add esp, 4
234-
}
234+
}
235235
m_pInterface->fDrawDistance = fDistance;
236236
}
237237

@@ -281,11 +281,11 @@ void CSettingsSA::SetAntiAliasing(unsigned int uiAntiAliasing, bool bOnRestart)
281281
{
282282
DWORD dwFunc = FUNC_SetAntiAliasing;
283283
_asm
284-
{
284+
{
285285
push uiAntiAliasing
286286
call dwFunc
287287
add esp, 4
288-
}
288+
}
289289
SetCurrentVideoMode(m_pInterface->dwVideoMode, false);
290290
}
291291

@@ -369,10 +369,10 @@ void _declspec(naked) HOOK_GetFxQuality()
369369
_asm
370370
{
371371
pushad
372-
mov eax, [ecx+054h] // Current FxQuality setting
372+
mov eax, [ecx+054h] // Current FxQuality setting
373373
mov dwFxQualityValue, eax
374374

375-
mov eax, [esp+32] // Address GetFxQuality was called from
375+
mov eax, [esp+32] // Address GetFxQuality was called from
376376
push eax
377377
call MaybeAlterFxQualityValue
378378
add esp, 4
@@ -389,12 +389,12 @@ void _declspec(naked) HOOK_StoreShadowForVehicle()
389389
_asm
390390
{
391391
// Hooked from 0x70BDA0 5 bytes
392-
mov eax, [esp+4] // Get vehicle
393-
mov ax, [eax+34] // pEntity->m_nModelIndex
392+
mov eax, [esp+4] // Get vehicle
393+
mov ax, [eax+34] // pEntity->m_nModelIndex
394394
mov usCallingForVehicleModel, ax
395395
sub esp, 44h
396396
push ebx
397-
mov eax, 0x70F9B0 // CVolumetricShadowMgr::IsAvailable
397+
mov eax, 0x70F9B0 // CVolumetricShadowMgr::IsAvailable
398398
call eax
399399
jmp RETURN_StoreShadowForVehicle
400400
}
@@ -562,29 +562,76 @@ void CSettingsSA::SetFieldOfViewVehicleMax(float fAngle, bool bFromScript)
562562
// Vehicles LOD draw distance
563563
//
564564
////////////////////////////////////////////////
565-
void CSettingsSA::SetVehiclesLODDistance(float fVehiclesLODDistance, float fTrainsPlanesLODDistance)
566-
{
567-
ms_fVehicleLODDistance = fVehiclesLODDistance;
568-
ms_fTrainPlaneLODDistance = fTrainsPlanesLODDistance;
569-
}
565+
float ms_fClientMaxVehicleLODDistance = DEFAULT_VEHICLE_LOD_DISTANCE;
566+
float ms_fClientMaxTrainPlaneLODDistance = DEFAULT_VEHICLE_LOD_DISTANCE * TRAIN_LOD_DISTANCE_MULTIPLIER;
567+
float ms_fScriptMaxVehicleLODDistance = ms_fClientMaxVehicleLODDistance;
568+
float ms_fScriptMaxTrainPlaneLODDistance = ms_fClientMaxTrainPlaneLODDistance;
569+
bool ms_bMaxVehicleLODDistanceFromScript = false;
570570

571-
void CSettingsSA::ResetVehiclesLODDistance()
571+
void CSettingsSA::SetVehiclesLODDistance(float fVehiclesLODDistance, float fTrainsPlanesLODDistance, bool bFromScript)
572572
{
573-
bool bHighDetailVehicles;
574-
g_pCore->GetCVars()->Get("high_detail_vehicles", bHighDetailVehicles);
573+
if (bFromScript)
574+
{
575+
ms_fScriptMaxVehicleLODDistance = fVehiclesLODDistance;
576+
ms_fScriptMaxTrainPlaneLODDistance = fTrainsPlanesLODDistance;
577+
ms_bMaxVehicleLODDistanceFromScript = bFromScript;
578+
}
579+
else
580+
{
581+
ms_fClientMaxVehicleLODDistance = fVehiclesLODDistance;
582+
ms_fClientMaxTrainPlaneLODDistance = fTrainsPlanesLODDistance;
583+
}
575584

576-
if (bHighDetailVehicles)
585+
if (ms_bMaxVehicleLODDistanceFromScript)
577586
{
578-
ms_fVehicleLODDistance = MAX_VEHICLE_LOD_DISTANCE;
579-
ms_fTrainPlaneLODDistance = MAX_VEHICLE_LOD_DISTANCE;
587+
ms_fVehicleLODDistance = Min(ms_fClientMaxVehicleLODDistance, ms_fScriptMaxVehicleLODDistance);
588+
ms_fTrainPlaneLODDistance = Min(ms_fClientMaxTrainPlaneLODDistance, ms_fScriptMaxTrainPlaneLODDistance);
580589
}
581590
else
582591
{
583-
ms_fVehicleLODDistance = DEFAULT_VEHICLE_LOD_DISTANCE;
584-
ms_fTrainPlaneLODDistance = DEFAULT_VEHICLE_LOD_DISTANCE * TRAIN_LOD_DISTANCE_MULTIPLIER;
592+
ms_fVehicleLODDistance = Min(fVehiclesLODDistance, ms_fClientMaxVehicleLODDistance);
593+
ms_fTrainPlaneLODDistance = Min(fTrainsPlanesLODDistance, ms_fClientMaxTrainPlaneLODDistance);
585594
}
586595
}
587596

597+
void CSettingsSA::ResetVehiclesLODDistance(bool bFromScript)
598+
{
599+
if (!bFromScript)
600+
{
601+
bool bHighDetailVehicles;
602+
g_pCore->GetCVars()->Get("high_detail_vehicles", bHighDetailVehicles);
603+
604+
if (bHighDetailVehicles)
605+
{
606+
ms_fClientMaxVehicleLODDistance = MAX_VEHICLE_LOD_DISTANCE;
607+
ms_fClientMaxTrainPlaneLODDistance = MAX_VEHICLE_LOD_DISTANCE;
608+
}
609+
else
610+
{
611+
ms_fClientMaxVehicleLODDistance = DEFAULT_VEHICLE_LOD_DISTANCE;
612+
ms_fClientMaxTrainPlaneLODDistance = DEFAULT_VEHICLE_LOD_DISTANCE * TRAIN_LOD_DISTANCE_MULTIPLIER;
613+
}
614+
615+
// Script still wants to override client setting, let's make sure we use latest max
616+
if (ms_bMaxVehicleLODDistanceFromScript)
617+
{
618+
ms_fVehicleLODDistance = Min(ms_fClientMaxVehicleLODDistance, ms_fScriptMaxVehicleLODDistance);
619+
ms_fTrainPlaneLODDistance = Min(ms_fClientMaxTrainPlaneLODDistance, ms_fScriptMaxTrainPlaneLODDistance);
620+
return;
621+
}
622+
}
623+
624+
ms_bMaxVehicleLODDistanceFromScript = false;
625+
ms_fVehicleLODDistance = ms_fClientMaxVehicleLODDistance;
626+
ms_fTrainPlaneLODDistance = ms_fClientMaxTrainPlaneLODDistance;
627+
}
628+
629+
void CSettingsSA::ResetVehiclesLODDistanceFromScript()
630+
{
631+
ms_bMaxVehicleLODDistanceFromScript = false;
632+
ResetVehiclesLODDistance(false);
633+
}
634+
588635
void CSettingsSA::GetVehiclesLODDistance(float& fVehiclesLODDistance, float& fTrainsPlanesLODDistance)
589636
{
590637
fVehiclesLODDistance = ms_fVehicleLODDistance;
@@ -596,29 +643,59 @@ void CSettingsSA::GetVehiclesLODDistance(float& fVehiclesLODDistance, float& fTr
596643
// Peds LOD draw distance
597644
//
598645
////////////////////////////////////////////////
646+
float ms_fClientMaxPedsLODDistance = DEFAULT_PEDS_LOD_DISTANCE;
647+
float ms_fScriptMaxPedsLODDistance = ms_fClientMaxPedsLODDistance;
648+
bool ms_bMaxPedsLODDistanceFromScript = false;
599649

600-
void CSettingsSA::SetPedsLODDistance(float fPedsLODDistance)
650+
void CSettingsSA::SetPedsLODDistance(float fPedsLODDistance, bool bFromScript)
601651
{
602-
ms_fPedsLODDistance = fPedsLODDistance;
603-
}
652+
if (bFromScript)
653+
{
654+
ms_fScriptMaxPedsLODDistance = fPedsLODDistance;
655+
ms_bMaxPedsLODDistanceFromScript = bFromScript;
656+
}
657+
else
658+
ms_fClientMaxPedsLODDistance = fPedsLODDistance;
604659

605-
float CSettingsSA::GetPedsLODDistance()
606-
{
607-
return ms_fPedsLODDistance;
660+
if (ms_bMaxPedsLODDistanceFromScript)
661+
ms_fPedsLODDistance = Min(ms_fClientMaxPedsLODDistance, ms_fScriptMaxPedsLODDistance);
662+
else
663+
ms_fPedsLODDistance = Min(fPedsLODDistance, ms_fClientMaxPedsLODDistance);
608664
}
609665

610-
void CSettingsSA::ResetPedsLODDistance()
666+
void CSettingsSA::ResetPedsLODDistance(bool bFromScript)
611667
{
612-
bool bHighDetailPeds;
613-
g_pCore->GetCVars()->Get("high_detail_peds", bHighDetailPeds);
614-
if (bHighDetailPeds)
668+
if (!bFromScript)
615669
{
616-
ms_fPedsLODDistance = MAX_PEDS_LOD_DISTANCE;
617-
}
618-
else
619-
{
620-
ms_fPedsLODDistance = DEFAULT_PEDS_LOD_DISTANCE;
670+
bool bHighDetailPeds;
671+
g_pCore->GetCVars()->Get("high_detail_peds", bHighDetailPeds);
672+
673+
if (bHighDetailPeds)
674+
ms_fClientMaxPedsLODDistance = MAX_PEDS_LOD_DISTANCE;
675+
else
676+
ms_fClientMaxPedsLODDistance = DEFAULT_PEDS_LOD_DISTANCE;
677+
678+
// Script still wants to override client setting, let's make sure we use latest max
679+
if (ms_bMaxPedsLODDistanceFromScript)
680+
{
681+
ms_fPedsLODDistance = Min(ms_fClientMaxPedsLODDistance, ms_fScriptMaxPedsLODDistance);
682+
return;
683+
}
621684
}
685+
686+
ms_bMaxPedsLODDistanceFromScript = false;
687+
ms_fPedsLODDistance = ms_fClientMaxPedsLODDistance;
688+
}
689+
690+
void CSettingsSA::ResetPedsLODDistanceFromScript()
691+
{
692+
ms_bMaxPedsLODDistanceFromScript = false;
693+
ResetPedsLODDistance(false);
694+
}
695+
696+
float CSettingsSA::GetPedsLODDistance()
697+
{
698+
return ms_fPedsLODDistance;
622699
}
623700

624701
////////////////////////////////////////////////
@@ -867,15 +944,14 @@ __declspec(noinline) int OnMY_SelectDevice()
867944
}
868945

869946
// Hook info
870-
#define HOOKPOS_SelectDevice 0x0746219
871-
#define HOOKSIZE_SelectDevice 6
947+
#define HOOKPOS_SelectDevice 0x0746219
948+
#define HOOKSIZE_SelectDevice 6
872949
DWORD RETURN_SelectDeviceSingle = 0x0746273;
873950
DWORD RETURN_SelectDeviceMultiHide = 0x074622C;
874951
DWORD RETURN_SelectDeviceMultiShow = 0x0746227;
875952
void _declspec(naked) HOOK_SelectDevice()
876953
{
877-
_asm
878-
{
954+
_asm {
879955
pushad
880956
call OnMY_SelectDevice
881957
cmp eax, 1
@@ -884,7 +960,7 @@ void _declspec(naked) HOOK_SelectDevice()
884960
jl single
885961
jz multishow
886962

887-
// multhide
963+
// multhide
888964
mov eax, 1
889965
jmp RETURN_SelectDeviceMultiHide
890966

Client/game_sa/CSettingsSA.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,16 @@ class CSettingsSA : public CGameSettings
158158
float GetFieldOfViewVehicle();
159159
float GetFieldOfViewVehicleMax();
160160

161-
void SetVehiclesLODDistance(float fVehiclesLODDistance, float fTrainsPlanesLODDistance);
162-
void ResetVehiclesLODDistance();
161+
void SetVehiclesLODDistance(float fVehiclesLODDistance, float fTrainsPlanesLODDistance, bool bFromScript);
162+
void ResetVehiclesLODDistance(bool bFromScript);
163+
void ResetVehiclesLODDistanceFromScript();
163164
void GetVehiclesLODDistance(float& fVehiclesLODDistance, float& fTrainsPlanesLODDistance);
164165

165166
void Save();
166167

167-
void SetPedsLODDistance(float fPedsLODDistance);
168-
void ResetPedsLODDistance();
168+
void SetPedsLODDistance(float fPedsLODDistance, bool bFromScript);
169+
void ResetPedsLODDistance(bool bFromScript);
170+
void ResetPedsLODDistanceFromScript();
169171
float GetPedsLODDistance();
170172

171173
static void StaticSetHooks();

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5707,10 +5707,10 @@ void CClientGame::ResetMapInfo()
57075707
g_pMultiplayer->RestoreFogDistance();
57085708

57095709
// Vehicles LOD distance
5710-
g_pGame->GetSettings()->ResetVehiclesLODDistance();
5710+
g_pGame->GetSettings()->ResetVehiclesLODDistanceFromScript();
57115711

57125712
// Peds LOD distance
5713-
g_pGame->GetSettings()->ResetPedsLODDistance();
5713+
g_pGame->GetSettings()->ResetPedsLODDistanceFromScript();
57145714

57155715
// Sun color
57165716
g_pMultiplayer->ResetSunColor();

Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.World.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ int CLuaFunctionDefs::SetVehiclesLODDistance(lua_State* luaVM)
15301530

15311531
if (!argStream.HasErrors())
15321532
{
1533-
g_pGame->GetSettings()->SetVehiclesLODDistance(fVehiclesDistance, fTrainsPlanesDistance);
1533+
g_pGame->GetSettings()->SetVehiclesLODDistance(fVehiclesDistance, fTrainsPlanesDistance, true);
15341534
lua_pushboolean(luaVM, true);
15351535
return 1;
15361536
}
@@ -1543,7 +1543,7 @@ int CLuaFunctionDefs::SetVehiclesLODDistance(lua_State* luaVM)
15431543

15441544
int CLuaFunctionDefs::ResetVehiclesLODDistance(lua_State* luaVM)
15451545
{
1546-
g_pGame->GetSettings()->ResetVehiclesLODDistance();
1546+
g_pGame->GetSettings()->ResetVehiclesLODDistance(true);
15471547
lua_pushboolean(luaVM, true);
15481548
return 1;
15491549
}
@@ -1564,7 +1564,7 @@ int CLuaFunctionDefs::SetPedsLODDistance(lua_State* luaVM)
15641564
if (!argStream.HasErrors())
15651565
{
15661566
fPedsDistance = Clamp(0.0f, fPedsDistance, 500.0f);
1567-
g_pGame->GetSettings()->SetPedsLODDistance(fPedsDistance);
1567+
g_pGame->GetSettings()->SetPedsLODDistance(fPedsDistance, true);
15681568
lua_pushboolean(luaVM, true);
15691569
return 1;
15701570
}
@@ -1577,7 +1577,7 @@ int CLuaFunctionDefs::SetPedsLODDistance(lua_State* luaVM)
15771577

15781578
int CLuaFunctionDefs::ResetPedsLODDistance(lua_State* luaVM)
15791579
{
1580-
g_pGame->GetSettings()->ResetPedsLODDistance();
1580+
g_pGame->GetSettings()->ResetPedsLODDistance(true);
15811581
lua_pushboolean(luaVM, true);
15821582
return 1;
15831583
}

0 commit comments

Comments
 (0)