Skip to content
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

function: get/set/resetPedsLODDistance #231

Merged
14 commits merged into from Jul 22, 2018
Merged
33 changes: 32 additions & 1 deletion Client/game_sa/CSettingsSA.cpp
Expand Up @@ -35,7 +35,7 @@ void HOOK_GetFxQuality();
DWORD RETURN_StoreShadowForVehicle = 0x70BDA9;
void HOOK_StoreShadowForVehicle();

float ms_fVehicleLODDistance, ms_fTrainPlaneLODDistance;
float ms_fVehicleLODDistance, ms_fTrainPlaneLODDistance, ms_fPedsLODDistance;

CSettingsSA::CSettingsSA(void)
{
Expand All @@ -52,6 +52,7 @@ CSettingsSA::CSettingsSA(void)

MemPut(0x732926, &ms_fVehicleLODDistance);
MemPut(0x732940, &ms_fTrainPlaneLODDistance);
MemPut(0x73295E, &ms_fPedsLODDistance);

// Set "radar map and radar" as default radar mode
SetRadarMode(RADAR_MODE_ALL);
Expand Down Expand Up @@ -590,6 +591,36 @@ void CSettingsSA::GetVehiclesLODDistance(float& fVehiclesLODDistance, float& fTr
fTrainsPlanesLODDistance = ms_fTrainPlaneLODDistance;
}

////////////////////////////////////////////////
//
// Peds LOD draw distance
//
////////////////////////////////////////////////

void CSettingsSA::SetPedsLODDistance(float fPedsLODDistance)
{
ms_fPedsLODDistance = fPedsLODDistance;
}

float CSettingsSA::GetPedsLODDistance()
{
return ms_fPedsLODDistance;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetPedsLODDistance should return instead of taking a parameter by reference.
float CSettingsSA::GetPedsLODDistance() { return ms_fPedsLODDistance; }


void CSettingsSA::ResetPedsLODDistance()
{
bool bHighDetailPeds;
g_pCore->GetCVars()->Get("high_detail_vehicles", bHighDetailPeds);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it have its own property ? or is it overkilled ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CrosRoad95 the name clearly says "high_detail_vehicles", any reason for not creating a new property?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm lazy

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't merge it like this. You can add the new property under high_detail_vehicles property in code.

Client\core\CSettings.cpp: line 1455, 1680, and 3199
Client\sdk\core\CRenderItemManagerInterface.h: 128
Client\core\Graphics\CRenderItemManager.cpp: line 767
Client\game_sa\CSettingsSA.cpp: line 574 and 613
Client\mods\deathmatch\logic\luadefs\CLuaDrawingDefs.cpp: line 1299

if (bHighDetailPeds)
{
ms_fPedsLODDistance = MAX_PEDS_LOD_DISTANCE;
}
else
{
ms_fPedsLODDistance = DEFAULT_PEDS_LOD_DISTANCE;
}
}

////////////////////////////////////////////////
//
// CSettingsSA::HasUnsafeResolutions
Expand Down
6 changes: 6 additions & 0 deletions Client/game_sa/CSettingsSA.h
Expand Up @@ -35,9 +35,11 @@
#define FUNC_SetAntiAliasing 0x7F8A90

#define DEFAULT_VEHICLE_LOD_DISTANCE ( 70.0f )
#define DEFAULT_PEDS_LOD_DISTANCE ( 60.0f )
// Default train distance is 150, so make it relative to default vehicle distance
#define TRAIN_LOD_DISTANCE_MULTIPLIER ( 2.14f )
#define MAX_VEHICLE_LOD_DISTANCE ( 500.0f )
#define MAX_PEDS_LOD_DISTANCE ( 500.0f )

struct CSettingsSAInterface // see code around 0x57CE9A for where these are
{
Expand Down Expand Up @@ -163,6 +165,10 @@ class CSettingsSA : public CGameSettings

void Save(void);

void SetPedsLODDistance(float fPedsLODDistance);
void ResetPedsLODDistance(void);
float GetPedsLODDistance(void);

static void StaticSetHooks(void);

uint FindVideoMode(int iResX, int iResY, int iColorBits);
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Expand Up @@ -5567,6 +5567,9 @@ void CClientGame::ResetMapInfo(void)
// Vehicles LOD distance
g_pGame->GetSettings()->ResetVehiclesLODDistance();

// Peds LOD distance
g_pGame->GetSettings()->ResetPedsLODDistance();

// Sun color
g_pMultiplayer->ResetSunColor();

Expand Down
34 changes: 34 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.World.cpp
Expand Up @@ -1548,6 +1548,40 @@ int CLuaFunctionDefs::ResetVehiclesLODDistance(lua_State* luaVM)
return 1;
}

int CLuaFunctionDefs::GetPedsLODDistance(lua_State* luaVM)
{
lua_pushnumber(luaVM, g_pGame->GetSettings()->GetPedsLODDistance());
return 1;
}

int CLuaFunctionDefs::SetPedsLODDistance(lua_State* luaVM)
{
float fPedsDistance;

CScriptArgReader argStream(luaVM);
argStream.ReadNumber(fPedsDistance);

if (!argStream.HasErrors())
{
fPedsDistance = Clamp(0.0f, fPedsDistance, 500.0f);
g_pGame->GetSettings()->SetPedsLODDistance(fPedsDistance);
lua_pushnumber(luaVM, fPedsDistance);
return 1;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaFunctionDefs::ResetPedsLODDistance(lua_State* luaVM)
{
g_pGame->GetSettings()->ResetPedsLODDistance();
lua_pushboolean(luaVM, true);
return 1;
}

int CLuaFunctionDefs::GetFogDistance(lua_State* luaVM)
{
lua_pushnumber(luaVM, g_pMultiplayer->GetFogDistance());
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaFunctionDefs.h
Expand Up @@ -150,6 +150,9 @@ class CLuaFunctionDefs
LUA_DECLARE(GetVehiclesLODDistance);
LUA_DECLARE(SetVehiclesLODDistance);
LUA_DECLARE(ResetVehiclesLODDistance);
LUA_DECLARE(GetPedsLODDistance);
LUA_DECLARE(SetPedsLODDistance);
LUA_DECLARE(ResetPedsLODDistance);
LUA_DECLARE(GetFogDistance);
LUA_DECLARE(SetFogDistance);
LUA_DECLARE(ResetFogDistance);
Expand Down
3 changes: 3 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaManager.cpp
Expand Up @@ -287,6 +287,7 @@ void CLuaManager::LoadCFunctions(void)
CLuaCFunctions::AddFunction("getFarClipDistance", CLuaFunctionDefs::GetFarClipDistance);
CLuaCFunctions::AddFunction("getNearClipDistance", CLuaFunctionDefs::GetNearClipDistance);
CLuaCFunctions::AddFunction("getVehiclesLODDistance", CLuaFunctionDefs::GetVehiclesLODDistance);
CLuaCFunctions::AddFunction("getPedsLODDistance", CLuaFunctionDefs::GetPedsLODDistance);
CLuaCFunctions::AddFunction("getFogDistance", CLuaFunctionDefs::GetFogDistance);
CLuaCFunctions::AddFunction("getSunColor", CLuaFunctionDefs::GetSunColor);
CLuaCFunctions::AddFunction("getSunSize", CLuaFunctionDefs::GetSunSize);
Expand Down Expand Up @@ -333,6 +334,8 @@ void CLuaManager::LoadCFunctions(void)
CLuaCFunctions::AddFunction("resetNearClipDistance", CLuaFunctionDefs::ResetNearClipDistance);
CLuaCFunctions::AddFunction("setVehiclesLODDistance", CLuaFunctionDefs::SetVehiclesLODDistance);
CLuaCFunctions::AddFunction("resetVehiclesLODDistance", CLuaFunctionDefs::ResetVehiclesLODDistance);
CLuaCFunctions::AddFunction("setPedsLODDistance", CLuaFunctionDefs::SetPedsLODDistance);
CLuaCFunctions::AddFunction("resetPedsLODDistance", CLuaFunctionDefs::ResetPedsLODDistance);
CLuaCFunctions::AddFunction("setFogDistance", CLuaFunctionDefs::SetFogDistance);
CLuaCFunctions::AddFunction("resetFogDistance", CLuaFunctionDefs::ResetFogDistance);
CLuaCFunctions::AddFunction("setSunColor", CLuaFunctionDefs::SetSunColor);
Expand Down
4 changes: 4 additions & 0 deletions Client/sdk/game/CSettings.h
Expand Up @@ -161,6 +161,10 @@ class CGameSettings
virtual void ResetVehiclesLODDistance(void) = 0;
virtual void GetVehiclesLODDistance(float& fVehiclesLODDistance, float& fTrainsPlanesLODDistance) = 0;

virtual void SetPedsLODDistance(float fPedsLODDistance) = 0;
virtual void ResetPedsLODDistance(void) = 0;
virtual float GetPedsLODDistance(void) = 0;

virtual void Save(void) = 0;
};

Expand Down