From d9ed603f183ca07168af57ea1ba4b8ef90758a42 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 19 Jun 2005 21:58:11 +0000 Subject: [PATCH] implement coin settling --- stepmania/src/StepMania.cpp | 24 ++++++++++++++++++++++-- stepmania/src/StepMania.h | 3 ++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 4d6eda952e..e9b6d2384f 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1248,8 +1248,28 @@ CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, return sFileName; } -void InsertCoin( int iNum ) +static Preference g_iCoinSettleTime( "CoinSettleTime", 0.03f ); + +void InsertCoin( int iNum, const RageTimer *pTime ) { + if( pTime != NULL ) + { + /* If a time is supplied for the button press, don't allow coin inserts + * in very rapid succession, to be sure one insert signal isn't counted + * as two coins. Use pTime, and never the current time, or we'll drop + * coins if multiple coins are inserted during a screen load. */ + static RageTimer LastCoin( RageZeroTimer ); + + float fAgo = *pTime - LastCoin; + if( !LastCoin.IsZero() && fAgo < g_iCoinSettleTime.Get() ) + { + LOG->Trace("Ignored coin input (%f since last accepted)", fAgo ); + return; + } + + LastCoin = *pTime; + } + GAMESTATE->m_iCoins += iNum; LOG->Trace("%i coins inserted, %i needed to play", GAMESTATE->m_iCoins, PREFSMAN->m_iCoinsPerCredit.Get() ); BOOKKEEPER->CoinInserted(); @@ -1294,7 +1314,7 @@ bool HandleGlobalInputs( DeviceInput DeviceI, InputEventType type, GameInput Gam LOG->Trace( "Ignored coin insertion (editing)" ); break; } - InsertCoin(); + InsertCoin( 1, &DeviceI.ts ); return false; // Attract need to know because they go to TitleMenu on > 1 credit } diff --git a/stepmania/src/StepMania.h b/stepmania/src/StepMania.h index 2e2bc38e63..49ccda2cae 100644 --- a/stepmania/src/StepMania.h +++ b/stepmania/src/StepMania.h @@ -2,6 +2,7 @@ #define STEPMANIA_H class Game; +class RageTimer; #ifdef _XBOX void __cdecl main(); @@ -19,7 +20,7 @@ void FocusChanged( bool bHasFocus ); // If successful, return filename of screenshot in sDir, else return "" CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex = -1 ); -void InsertCoin( int iNum = 1 ); +void InsertCoin( int iNum = 1, const RageTimer *pTime = NULL ); void InsertCredit(); extern int g_argc;