split InputQueue::WasPressedRecently from AllWerePressedRecently.
This simplifies AllWerePressedRecently, and makes the input state at the time of the press available.
This commit is contained in:
@@ -82,6 +82,26 @@ bool InputQueue::MatchesSequence( GameController c, const GameButton* button_seq
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputQueue::WasPressedRecently( GameController c, const GameButton button, const RageTimer &OldestTimeAllowed, InputEventPlus *pIEP )
|
||||
{
|
||||
for( int queue_index=m_aQueue[c].size()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest
|
||||
{
|
||||
const InputEventPlus &iep = m_aQueue[c][queue_index];
|
||||
if( iep.DeviceI.ts < OldestTimeAllowed ) // buttons are too old. Stop searching because we're not going to find a match
|
||||
return false;
|
||||
|
||||
if( iep.GameI.button != button )
|
||||
continue;
|
||||
|
||||
if( pIEP != NULL )
|
||||
*pIEP = iep;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // didn't find the button
|
||||
}
|
||||
|
||||
bool InputQueue::AllWerePressedRecently( GameController c, const GameButton* buttons, int iNumButtons, float fMaxSecondsBack )
|
||||
{
|
||||
RageTimer OldestTimeAllowed;
|
||||
@@ -89,20 +109,8 @@ bool InputQueue::AllWerePressedRecently( GameController c, const GameButton* but
|
||||
|
||||
for( int b=0; b<iNumButtons; b++ )
|
||||
{
|
||||
GameButton button = buttons[b];
|
||||
|
||||
for( int queue_index=m_aQueue[c].size()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest
|
||||
{
|
||||
const InputEventPlus &iep = m_aQueue[c][queue_index];
|
||||
if( iep.DeviceI.ts < OldestTimeAllowed ) // buttons are too old. Stop searching because we're not going to find a match
|
||||
return false;
|
||||
|
||||
if( iep.GameI.button == button )
|
||||
goto found_button;
|
||||
}
|
||||
return false; // didn't find the button
|
||||
found_button:
|
||||
; // hush VC6
|
||||
if( !WasPressedRecently(c, buttons[b], OldestTimeAllowed) )
|
||||
return false; // didn't find the button
|
||||
}
|
||||
|
||||
m_aQueue[c].clear(); // empty the queue so we don't match on it again
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
const unsigned MAX_INPUT_QUEUE_LENGTH = 16;
|
||||
class InputEventPlus;
|
||||
class RageTimer;
|
||||
|
||||
class InputQueue
|
||||
{
|
||||
@@ -18,6 +19,7 @@ public:
|
||||
void RememberInput( const InputEventPlus &gi );
|
||||
bool MatchesSequence( GameController c, const GameButton* button_sequence, int iNumButtons, float fMaxSecondsBack );
|
||||
bool MatchesSequence( GameController c, const MenuButton* button_sequence, int iNumButtons, float fMaxSecondsBack );
|
||||
bool WasPressedRecently( GameController c, const GameButton button, const RageTimer &OldestTimeAllowed, InputEventPlus *pIEP = NULL );
|
||||
bool AllWerePressedRecently( GameController c, const GameButton* buttons, int iNumButtons, float fMaxSecondsBack );
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user