Skip to content

Commit

Permalink
Native gear ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
chrystianfarias committed Jan 20, 2022
1 parent 90fc86f commit 4836180
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
34 changes: 19 additions & 15 deletions GTAFmod/GTAFmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class GTAFmod {
}
static void _stdcall ProcessVehicleEngine(cVehicleParams* params)
{

if (lastVehicle && !CTimer::m_UserPause && audio)
{
//Set 3D space position
Expand Down Expand Up @@ -257,27 +258,30 @@ class GTAFmod {
nLastGearChangeTime = CTimer::m_snTimeInMilliseconds;
}

//Gear relation
float relation[] = {
iniConfig->m_fRalationR,
iniConfig->m_fRalation1,
iniConfig->m_fRalation2,
iniConfig->m_fRalation3,
iniConfig->m_fRalation4,
iniConfig->m_fRalation5
};

//Calculate target RPM
float targetRpm = 400 + (lastVehicle->m_vecMoveSpeed.Magnitude() * abs(relation[nGear])) * (iniConfig->m_fFinalRPM - 1500);
//Calculate target RPM
float speed = fabs(params->m_fVelocity);
float ratio = (speed- params->m_pTransmission->m_aGears[nGear].m_fChangeDownVelocity)
/ (*(float*)&params->m_pTransmission->m_aGears[nGear].m_fMaxVelocity
- params->m_pTransmission->m_aGears[nGear].m_fChangeDownVelocity);
if (ratio > 1.0 || ratio >= 0.0)
{
if (ratio > 1.0)
ratio = 1.0;
}
else
{
ratio = 0.0;
}
float targetRpm = iniConfig->m_fMinRPM + (iniConfig->m_fMaxRPM * ratio);

if (clutch > 0)
{
fRPM += (gasPedal * CTimer::ms_fTimeStep) * 200 * clutch;
if (fRPM > iniConfig->m_fFinalRPM)
if (fRPM > iniConfig->m_fMaxRPM)
{
fRPM = iniConfig->m_fFinalRPM;
fRPM = iniConfig->m_fMaxRPM;
}
if (gasPedal == 0 && fRPM > 800)
if (gasPedal == 0 && fRPM > iniConfig->m_fMinRPM)
{
fRPM -= (CTimer::ms_fTimeStep) * 20;
}
Expand Down
22 changes: 4 additions & 18 deletions GTAFmod/INIConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,18 @@ class INIConfig
{
public:
//Audio
float m_fFinalRPM;
float m_fMinRPM;
float m_fMaxRPM;
float m_fRPMAcceleration;
float m_fRPMDesaceleration;
//GearRatio
float m_fRalationR;
float m_fRalation1;
float m_fRalation2;
float m_fRalation3;
float m_fRalation4;
float m_fRalation5;
float m_fRalation6;

INIConfig(std::string iniPath)
{
CIniReader ini(iniPath);
m_fFinalRPM = ini.ReadFloat("Audio", "FinalRPM", 8000);
m_fMinRPM = ini.ReadFloat("Audio", "FinalRPM", 800);
m_fMaxRPM = ini.ReadFloat("Audio", "FinalRPM", 6200);
m_fRPMAcceleration = ini.ReadFloat("Audio", "RPMAcceleration", 50);
m_fRPMDesaceleration = ini.ReadFloat("Audio", "RPMDesaceleration", 60);

m_fRalationR = ini.ReadFloat("GearRatio", "RelationR", -1);
m_fRalation1 = ini.ReadFloat("GearRatio", "Relation1", 3);
m_fRalation2 = ini.ReadFloat("GearRatio", "Relation2", 2);
m_fRalation3 = ini.ReadFloat("GearRatio", "Relation3", 1.6);
m_fRalation4 = ini.ReadFloat("GearRatio", "Relation4", 1.2);
m_fRalation5 = ini.ReadFloat("GearRatio", "Relation5", 0.9);
m_fRalation6 = ini.ReadFloat("GearRatio", "Relation6", 0.7);
}
};

0 comments on commit 4836180

Please sign in to comment.