Skip to content

Commit

Permalink
Merge branch 'master' into issue-9608
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikjuvonen committed Jul 23, 2018
2 parents 7793c2d + 3924406 commit 490efa5
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 52 deletions.
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;
}

void CSettingsSA::ResetPedsLODDistance()
{
bool bHighDetailPeds;
g_pCore->GetCVars()->Get("high_detail_peds", bHighDetailPeds);
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 @@ -5574,6 +5574,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
16 changes: 0 additions & 16 deletions Client/mods/deathmatch/logic/CClientVehicle.cpp
Expand Up @@ -4724,22 +4724,6 @@ bool CClientVehicle::DoesSupportUpgrade(const SString& strFrameName)
return true;
}

void CClientVehicle::SetModelExhaustFumesPosition(unsigned short modelID, const CVector& position)
{
auto pModelInfo = g_pGame->GetModelInfo(modelID);
if (pModelInfo)
pModelInfo->SetVehicleExhaustFumesPosition(position);
}

CVector CClientVehicle::GetModelExhaustFumesPosition(unsigned short modelID)
{
auto pModelInfo = g_pGame->GetModelInfo(modelID);
if (pModelInfo)
return pModelInfo->GetVehicleExhaustFumesPosition();

return CVector();
}

bool CClientVehicle::OnVehicleFallThroughMap()
{
// if we have fallen through the map a small number of times
Expand Down
3 changes: 0 additions & 3 deletions Client/mods/deathmatch/logic/CClientVehicle.h
Expand Up @@ -484,9 +484,6 @@ class CClientVehicle : public CClientStreamElement

void SetHeliBladeCollisionsEnabled(bool bEnable) { m_bEnableHeliBladeCollisions = bEnable; }

static void SetModelExhaustFumesPosition(unsigned short modelID, const CVector& position);
static CVector GetModelExhaustFumesPosition(unsigned short modelID);

bool OnVehicleFallThroughMap();

protected:
Expand Down
28 changes: 28 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -3414,6 +3414,34 @@ bool CStaticFunctionDefinitions::IsVehicleWindowOpen(CClientVehicle& Vehicle, uc
return Vehicle.IsWindowOpen(ucWindow);
}

bool CStaticFunctionDefinitions::SetVehicleModelExhaustFumesPosition(unsigned short usModel, CVector& vecPosition)
{
if (CClientVehicleManager::IsValidModel(usModel))
{
auto pModelInfo = g_pGame->GetModelInfo(usModel);
if (pModelInfo)
{
pModelInfo->SetVehicleExhaustFumesPosition(vecPosition);
return true;
}
}
return false;
}

bool CStaticFunctionDefinitions::GetVehicleModelExhaustFumesPosition(unsigned short usModel, CVector& vecPosition)
{
if (CClientVehicleManager::IsValidModel(usModel))
{
auto pModelInfo = g_pGame->GetModelInfo(usModel);
if (pModelInfo)
{
vecPosition = pModelInfo->GetVehicleExhaustFumesPosition();
return true;
}
}
return false;
}

bool CStaticFunctionDefinitions::SetElementCollisionsEnabled(CClientEntity& Entity, bool bEnabled)
{
switch (Entity.GetType())
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -218,6 +218,8 @@ class CStaticFunctionDefinitions
static bool GetVehicleNitroLevel(CClientVehicle& Vehicle, float& fLevel);
static bool GetHeliBladeCollisionsEnabled(CClientVehicle& Vehicle);
static bool IsVehicleWindowOpen(CClientVehicle& Vehicle, uchar ucWindow);
static bool SetVehicleModelExhaustFumesPosition(unsigned short usModel, CVector& vecPosition);
static bool GetVehicleModelExhaustFumesPosition(unsigned short usModel, CVector& vecPosition);

// Vehicle set functions
static bool FixVehicle(CClientEntity& Entity);
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
23 changes: 11 additions & 12 deletions Client/mods/deathmatch/logic/luadefs/CLuaFireDefs.cpp
Expand Up @@ -13,8 +13,7 @@
void CLuaFireDefs::LoadFunctions(void)
{
CLuaCFunctions::AddFunction("createFire", CLuaFireDefs::CreateFire);
CLuaCFunctions::AddFunction("extinguishFireInRadius", CLuaFireDefs::ExtinguishFireInRadius);
CLuaCFunctions::AddFunction("extinguishAllFires", CLuaFireDefs::ExtinguishAllFires);
CLuaCFunctions::AddFunction("extinguishFire", CLuaFireDefs::ExtinguishFire);
}

int CLuaFireDefs::CreateFire(lua_State* luaVM)
Expand Down Expand Up @@ -42,13 +41,20 @@ int CLuaFireDefs::CreateFire(lua_State* luaVM)
return 1;
}

int CLuaFireDefs::ExtinguishFireInRadius(lua_State* luaVM)
int CLuaFireDefs::ExtinguishFire(lua_State* luaVM)
{
// bool extinguishFireInRadius ( float x, float y, float z [, float radius = 1.0 ] )
// bool extinguishFire ( [ float x, float y, float z [, float radius = 1.0 ] ] )
CScriptArgReader argStream(luaVM);

if (argStream.NextIsNone())
{
lua_pushboolean(luaVM, CStaticFunctionDefinitions::ExtinguishAllFires());
return 1;
}

CVector vecPosition;
float fRadius;

CScriptArgReader argStream(luaVM);
argStream.ReadVector3D(vecPosition);
argStream.ReadNumber(fRadius, 1.0f);

Expand All @@ -66,10 +72,3 @@ int CLuaFireDefs::ExtinguishFireInRadius(lua_State* luaVM)
lua_pushboolean(luaVM, false);
return 1;
}

int CLuaFireDefs::ExtinguishAllFires(lua_State* luaVM)
{
// bool extinguishAllFires ( )
lua_pushboolean(luaVM, CStaticFunctionDefinitions::ExtinguishAllFires());
return 1;
}
3 changes: 1 addition & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaFireDefs.h
Expand Up @@ -17,6 +17,5 @@ class CLuaFireDefs : public CLuaDefs
static void LoadFunctions(void);

LUA_DECLARE(CreateFire);
LUA_DECLARE(ExtinguishFireInRadius);
LUA_DECLARE(ExtinguishAllFires);
LUA_DECLARE(ExtinguishFire);
};
65 changes: 48 additions & 17 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Expand Up @@ -205,6 +205,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "getUpgradeSlotName", "getVehicleUpgradeSlotName");
lua_classfunction(luaVM, "getCompatibleUpgrades", "getVehicleCompatibleUpgrades");
lua_classfunction(luaVM, "getUpgradeOnSlot", "getVehicleUpgradeOnSlot");
lua_classfunction(luaVM, "getModelExhaustFumesPosition", OOP_GetVehicleModelExhaustFumesPosition);

lua_classfunction(luaVM, "setComponentVisible", "setVehicleComponentVisible");
lua_classfunction(luaVM, "setSirensOn", "setVehicleSirensOn");
Expand Down Expand Up @@ -245,6 +246,7 @@ void CLuaVehicleDefs::AddClass(lua_State* luaVM)
lua_classfunction(luaVM, "setColor", "setVehicleColor");
lua_classfunction(luaVM, "setPlateText", "setVehiclePlateText");
lua_classfunction(luaVM, "setGravity", "setVehicleGravity");
lua_classfunction(luaVM, "setModelExhaustFumesPosition", "setVehicleModelExhaustFumesPosition");

lua_classfunction(luaVM, "resetComponentPosition", "resetVehicleComponentPosition");
lua_classfunction(luaVM, "resetComponentRotation", "resetVehicleComponentRotation");
Expand Down Expand Up @@ -3751,20 +3753,21 @@ int CLuaVehicleDefs::IsVehicleWindowOpen(lua_State* luaVM)

int CLuaVehicleDefs::SetVehicleModelExhaustFumesPosition(lua_State* luaVM)
{
// bool setVehicleModelExhaustPosition(int modelID, float x, float y, float z)
unsigned short modelID;
CVector position;
// bool setVehicleModelExhaustPosition ( int modelID, float x, float y, float z )
unsigned short usModel;
CVector vecPosition;

CScriptArgReader argStream(luaVM);
argStream.ReadNumber(modelID);
argStream.ReadVector3D(position);
argStream.ReadNumber(usModel);
argStream.ReadVector3D(vecPosition);

if (!argStream.HasErrors())
{
CClientVehicle::SetModelExhaustFumesPosition(modelID, position);

lua_pushboolean(luaVM, true);
return 1;
if (CStaticFunctionDefinitions::SetVehicleModelExhaustFumesPosition(usModel, vecPosition))
{
lua_pushboolean(luaVM, true);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
Expand All @@ -3775,20 +3778,48 @@ int CLuaVehicleDefs::SetVehicleModelExhaustFumesPosition(lua_State* luaVM)

int CLuaVehicleDefs::GetVehicleModelExhaustFumesPosition(lua_State* luaVM)
{
// bool getVehicleModelExhaustPosition(int modelID)
unsigned short modelID;
// float, float, float getVehicleModelExhaustPosition ( int modelID )
unsigned short usModel;

CScriptArgReader argStream(luaVM);
argStream.ReadNumber(modelID);
argStream.ReadNumber(usModel);

if (!argStream.HasErrors())
{
CVector position = CClientVehicle::GetModelExhaustFumesPosition(modelID);
CVector vecPosition;

if (CStaticFunctionDefinitions::GetVehicleModelExhaustFumesPosition(usModel, vecPosition))
{
lua_pushnumber(luaVM, vecPosition.fX);
lua_pushnumber(luaVM, vecPosition.fY);
lua_pushnumber(luaVM, vecPosition.fZ);
return 3;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushnumber(luaVM, position.fX);
lua_pushnumber(luaVM, position.fY);
lua_pushnumber(luaVM, position.fZ);
return 3;
lua_pushboolean(luaVM, false);
return 1;
}

int CLuaVehicleDefs::OOP_GetVehicleModelExhaustFumesPosition(lua_State* luaVM)
{
// float, float, float getVehicleModelExhaustPosition ( int modelID )
unsigned short usModel;

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

if (!argStream.HasErrors())
{
CVector vecPosition;

if (CStaticFunctionDefinitions::GetVehicleModelExhaustFumesPosition(usModel, vecPosition))
{
lua_pushvector(luaVM, vecPosition);
return 1;
}
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.h
Expand Up @@ -137,7 +137,7 @@ class CLuaVehicleDefs : public CLuaDefs
LUA_DECLARE(SetVehicleWindowOpen);

LUA_DECLARE(SetVehicleModelExhaustFumesPosition);
LUA_DECLARE(GetVehicleModelExhaustFumesPosition);
LUA_DECLARE_OOP(GetVehicleModelExhaustFumesPosition);

// Components
LUA_DECLARE(SetVehicleComponentPosition);
Expand Down

0 comments on commit 490efa5

Please sign in to comment.