From 4da8857f1db16f67a45aca8ff1a9cc23354144f6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 8 Sep 2006 03:16:35 +0000 Subject: [PATCH] Simplify InputQueue: use InputEventPlus. This has the timestamp it needs, and we can match MenuI from it without doing extra conversions. --- stepmania/src/InputQueue.cpp | 30 ++++++++++++++---------------- stepmania/src/InputQueue.h | 12 +++--------- stepmania/src/StepMania.cpp | 2 +- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/stepmania/src/InputQueue.cpp b/stepmania/src/InputQueue.cpp index 69af132b1e..c012dc25bb 100644 --- a/stepmania/src/InputQueue.cpp +++ b/stepmania/src/InputQueue.cpp @@ -4,6 +4,7 @@ #include "RageException.h" #include "RageTimer.h" #include "InputMapper.h" +#include "InputEventPlus.h" InputQueue* INPUTQUEUE = NULL; // global and accessable from anywhere in our program @@ -12,15 +13,15 @@ InputQueue* INPUTQUEUE = NULL; // global and accessable from anywhere in our pro InputQueue::InputQueue() { FOREACH_GameController ( gc ) - m_aQueue[gc].insert(m_aQueue[gc].begin(), MAX_INPUT_QUEUE_LENGTH, GameButtonAndTime() ); + m_aQueue[gc].resize( MAX_INPUT_QUEUE_LENGTH ); } -void InputQueue::RememberInput( const GameInput GameI ) +void InputQueue::RememberInput( const InputEventPlus &iep ) { - int c = GameI.controller; + int c = iep.GameI.controller; if( m_aQueue[c].size() >= MAX_INPUT_QUEUE_LENGTH ) // full m_aQueue[c].erase( m_aQueue[c].begin(), m_aQueue[c].begin() + (m_aQueue[c].size()-MAX_INPUT_QUEUE_LENGTH+1) ); - m_aQueue[c].push_back( GameButtonAndTime(GameI.button,RageTimer::GetTimeSinceStart()) ); + m_aQueue[c].push_back( iep ); } bool InputQueue::MatchesSequence( GameController c, const MenuButton* button_sequence, const int iNumButtons, float fMaxSecondsBack ) @@ -36,12 +37,9 @@ bool InputQueue::MatchesSequence( GameController c, const MenuButton* button_seq int sequence_index = iNumButtons-1; // count down for( int queue_index=m_aQueue[c].size()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest { - GameButtonAndTime BandT = m_aQueue[c][queue_index]; - GameInput GameI( c, BandT.button ); - MenuInput MenuI; - INPUTMAPPER->GameToMenu( GameI, MenuI ); - if( MenuI.button != button_sequence[sequence_index] || - BandT.fTime < fOldestTimeAllowed ) + const InputEventPlus &iep = m_aQueue[c][queue_index]; + if( iep.MenuI.button != button_sequence[sequence_index] || + iep.DeviceI.ts.Ago() > fOldestTimeAllowed ) { return false; } @@ -68,9 +66,9 @@ bool InputQueue::MatchesSequence( GameController c, const GameButton* button_seq int sequence_index = iNumButtons-1; // count down for( int queue_index=m_aQueue[c].size()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest { - GameButtonAndTime BandT = m_aQueue[c][queue_index]; - if( BandT.button != button_sequence[sequence_index] || - BandT.fTime < fOldestTimeAllowed ) + const InputEventPlus &iep = m_aQueue[c][queue_index]; + if( iep.GameI.button != button_sequence[sequence_index] || + iep.DeviceI.ts.Ago() > fOldestTimeAllowed ) { return false; } @@ -94,11 +92,11 @@ bool InputQueue::AllWerePressedRecently( GameController c, const GameButton* but for( int queue_index=m_aQueue[c].size()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest { - GameButtonAndTime BandT = m_aQueue[c][queue_index]; - if( BandT.fTime < fOldestTimeAllowed ) // buttons are too old. Stop searching because we're not going to find a match + const InputEventPlus &iep = m_aQueue[c][queue_index]; + if( iep.DeviceI.ts.Ago() > fOldestTimeAllowed ) // buttons are too old. Stop searching because we're not going to find a match return false; - if( BandT.button == button ) + if( iep.GameI.button == button ) goto found_button; } return false; // didn't find the button diff --git a/stepmania/src/InputQueue.h b/stepmania/src/InputQueue.h index e9ccfcd962..946d70a877 100644 --- a/stepmania/src/InputQueue.h +++ b/stepmania/src/InputQueue.h @@ -8,26 +8,20 @@ #include "MenuInput.h" const unsigned MAX_INPUT_QUEUE_LENGTH = 16; +class InputEventPlus; class InputQueue { public: InputQueue(); - void RememberInput( GameInput gi ); + 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 AllWerePressedRecently( GameController c, const GameButton* buttons, int iNumButtons, float fMaxSecondsBack ); protected: - struct GameButtonAndTime - { - GameButtonAndTime() {} - GameButtonAndTime( GameButton b, float t ) { button = b; fTime = t; }; - GameButton button; - float fTime; - }; - vector m_aQueue[MAX_GAME_CONTROLLERS]; + vector m_aQueue[MAX_GAME_CONTROLLERS]; }; diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 620c4ec50a..073fc501fa 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1402,7 +1402,7 @@ void HandleInputEvents(float fDeltaTime) INPUTMAPPER->DeviceToGame( input.DeviceI, input.GameI ); if( input.GameI.IsValid() && input.type == IET_FIRST_PRESS ) - INPUTQUEUE->RememberInput( input.GameI ); + INPUTQUEUE->RememberInput( input ); if( input.GameI.IsValid() ) { INPUTMAPPER->GameToMenu( input.GameI, input.MenuI );