2002-05-20 08:59:37 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: InputQueue
|
|
|
|
|
|
|
|
|
|
Desc: See Header.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
|
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "InputQueue.h"
|
|
|
|
|
#include "IniFile.h"
|
|
|
|
|
#include "GameManager.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageException.h"
|
|
|
|
|
#include "RageTimer.h"
|
2002-07-31 22:37:58 +00:00
|
|
|
#include "InputMapper.h"
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
InputQueue* INPUTQUEUE = NULL; // global and accessable from anywhere in our program
|
|
|
|
|
|
|
|
|
|
|
2002-07-27 19:29:51 +00:00
|
|
|
InputQueue::InputQueue()
|
|
|
|
|
{
|
|
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
2002-10-24 20:15:24 +00:00
|
|
|
m_aQueue[p].insert(m_aQueue[p].begin(), MAX_INPUT_QUEUE_LENGTH, GameButtonAndTime() );
|
2002-07-27 19:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
void InputQueue::RememberInput( const GameInput GameI )
|
2002-07-27 19:29:51 +00:00
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
int c = GameI.controller;
|
2002-10-31 04:11:08 +00:00
|
|
|
/* XXX: this should be a deque, and just pop_back */
|
2002-10-31 03:16:02 +00:00
|
|
|
if( m_aQueue[c].size() >= MAX_INPUT_QUEUE_LENGTH ) // full
|
2002-10-31 04:11:08 +00:00
|
|
|
m_aQueue[c].erase( m_aQueue[c].begin(), m_aQueue[c].begin() + (m_aQueue[c].size()-MAX_INPUT_QUEUE_LENGTH+1) );
|
2002-10-31 04:23:39 +00:00
|
|
|
m_aQueue[c].push_back( GameButtonAndTime(GameI.button,TIMER->GetTimeSinceStart()) );
|
|
|
|
|
}
|
2002-07-27 19:29:51 +00:00
|
|
|
|
2002-07-31 22:37:58 +00:00
|
|
|
bool InputQueue::MatchesPattern( const GameController c, const MenuButton* button_sequence, const int iNumButtons, float fMaxSecondsBack )
|
|
|
|
|
{
|
|
|
|
|
if( fMaxSecondsBack == -1 )
|
|
|
|
|
fMaxSecondsBack = 0.4f + iNumButtons*0.15f;
|
|
|
|
|
|
|
|
|
|
float fOldestTimeAllowed = TIMER->GetTimeSinceStart() - fMaxSecondsBack;
|
|
|
|
|
|
|
|
|
|
int sequence_index = iNumButtons-1; // count down
|
2002-10-31 03:16:02 +00:00
|
|
|
for( int queue_index=m_aQueue[c].size()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest
|
2002-07-31 22:37:58 +00:00
|
|
|
{
|
|
|
|
|
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 )
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if( sequence_index == 0 ) // we matched the whole pattern
|
|
|
|
|
{
|
2002-10-24 20:15:24 +00:00
|
|
|
m_aQueue[c].clear(); // empty the queue so we don't match on it again
|
2002-07-31 22:37:58 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
sequence_index--;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
bool InputQueue::MatchesPattern( const GameController c, const GameButton* button_sequence, const int iNumButtons, float fMaxSecondsBack )
|
2002-07-27 19:29:51 +00:00
|
|
|
{
|
|
|
|
|
if( fMaxSecondsBack == -1 )
|
|
|
|
|
fMaxSecondsBack = 0.4f + iNumButtons*0.15f;
|
|
|
|
|
|
|
|
|
|
float fOldestTimeAllowed = TIMER->GetTimeSinceStart() - fMaxSecondsBack;
|
|
|
|
|
|
|
|
|
|
int sequence_index = iNumButtons-1; // count down
|
2002-10-31 03:16:02 +00:00
|
|
|
for( int queue_index=m_aQueue[c].size()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest
|
2002-07-27 19:29:51 +00:00
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
GameButtonAndTime BandT = m_aQueue[c][queue_index];
|
2002-07-27 19:29:51 +00:00
|
|
|
if( BandT.button != button_sequence[sequence_index] ||
|
|
|
|
|
BandT.fTime < fOldestTimeAllowed )
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if( sequence_index == 0 ) // we matched the whole pattern
|
|
|
|
|
{
|
2002-10-24 20:15:24 +00:00
|
|
|
m_aQueue[c].clear(); // empty the queue so we don't match on it again
|
2002-07-27 19:29:51 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
sequence_index--;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|