Fix toggling siren at high FPS

This commit is contained in:
Veyrdite 2021-08-01 15:58:42 +10:00
parent 9282db1e8f
commit 882a977c66
3 changed files with 47 additions and 4 deletions

View File

@ -235,6 +235,12 @@ CAutomobile::CAutomobile(int32 id, uint8 CreatedBy)
bExplosionProof = true;
bBulletProof = true;
}
#ifdef FIX_BUGS
// Probably not neccesary to zero these
m_nCarHornTimer = 0;
m_fCarHornTimeButtonLastHit = 0.0f;
#endif
}
void
@ -1366,18 +1372,49 @@ CAutomobile::ProcessControl(void)
ReduceHornCounter();
}else{
if(UsesSiren()){
#ifdef FIX_BUGS
// Allow sirens to be toggled at high FPS
const float minPressTime = 100.0f; // milli-seconds
bool currentButtonState = Pads[0].bHornHistory[(CPad::HORNHISTORY_SIZE + Pads[0].iCurrHornHistory - 0) % CPad::HORNHISTORY_SIZE];
bool lastButtonState = Pads[0].bHornHistory[(CPad::HORNHISTORY_SIZE + Pads[0].iCurrHornHistory - 1) % CPad::HORNHISTORY_SIZE]; // Extra addition of CPad::HORNHISTORY_SIZE avoids modulo of negative numbers
if (currentButtonState && !lastButtonState)
{
// Horn button has just been hit
m_fCarHornTimeButtonLastHit = CTimer::GetTimeInMilliseconds();
}
else if (currentButtonState && lastButtonState)
{
// Horn button is being held down
if (CTimer::GetTimeInMilliseconds() - m_fCarHornTimeButtonLastHit >= minPressTime)
m_nCarHornTimer = 1; // enable horn
}
else if (!currentButtonState && lastButtonState)
{
// Horn button has just been released
m_nCarHornTimer = 0;
if (CTimer::GetTimeInMilliseconds() - m_fCarHornTimeButtonLastHit < minPressTime)
m_bSirenOrAlarm = !m_bSirenOrAlarm; // Toggle siren-like-feature
}
else
{
// Nothing pressed
m_nCarHornTimer = 0; // Should not be neccesary, but may as well keep in
}
#else
if(Pads[0].bHornHistory[Pads[0].iCurrHornHistory]){
if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5] &&
Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+3) % 5])
if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % CPad::HORNHISTORY_SIZE] &&
Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+3) % CPad::HORNHISTORY_SIZE])
m_nCarHornTimer = 1;
else
m_nCarHornTimer = 0;
}else if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % 5] &&
!Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+1) % 5]){
}else if(Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+4) % CPad::HORNHISTORY_SIZE] &&
!Pads[0].bHornHistory[(Pads[0].iCurrHornHistory+1) % CPad::HORNHISTORY_SIZE]){
m_nCarHornTimer = 0;
m_bSirenOrAlarm = !m_bSirenOrAlarm;
}else
m_nCarHornTimer = 0;
#endif
}else if(GetModelIndex() != MI_VOODOO && !CVehicle::bCheat3 && !carHasNitro){
if(!IsAlarmOn()){
if(Pads[0].GetHorn())

View File

@ -126,6 +126,9 @@ CVehicle::CVehicle(uint8 CreatedBy)
m_nCarHornTimer = 0;
m_nCarHornPattern = 0;
m_nCarHornDelay = 0;
#ifdef FIX_BUGS
m_fCarHornTimeButtonLastHit = 0.0f;
#endif
bPartOfConvoy = false;
bHeliMinimumTilt = false;
bAudioChangingGear = false;

View File

@ -273,6 +273,9 @@ public:
uint8 m_nCarHornPattern;
bool m_bSirenOrAlarm;
uint8 m_nCarHornDelay;
#ifdef FIX_BUGS
float m_fCarHornTimeButtonLastHit;
#endif
int8 m_comedyControlState;
CStoredCollPoly m_aCollPolys[2]; // poly which is under front/rear part of car
float m_fSteerInput;