Simplify InputQueue: use InputEventPlus. This has the

timestamp it needs, and we can match MenuI from it without
doing extra conversions.
This commit is contained in:
Glenn Maynard
2006-09-08 03:16:35 +00:00
parent 8ebab0dde7
commit 4da8857f1d
3 changed files with 18 additions and 26 deletions
+14 -16
View File
@@ -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
+3 -9
View File
@@ -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<GameButtonAndTime> m_aQueue[MAX_GAME_CONTROLLERS];
vector<InputEventPlus> m_aQueue[MAX_GAME_CONTROLLERS];
};
+1 -1
View File
@@ -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 );