2002-05-20 08:59:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
Class: InputQueue
|
|
|
|
|
|
|
|
|
|
Desc: Stores a list of the most recently pressed MenuInputs for each player.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
|
|
|
|
Chris Danford
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "MenuInput.h"
|
|
|
|
|
#include "GameConstantsAndTypes.h"
|
|
|
|
|
|
|
|
|
|
const int MAX_INPUT_QUEUE_LENGTH = 8;
|
|
|
|
|
|
|
|
|
|
class InputQueue
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
InputQueue()
|
|
|
|
|
{
|
|
|
|
|
for( int p=0; p<NUM_PLAYERS; p++ )
|
2002-06-14 22:25:22 +00:00
|
|
|
m_aQueue[p].SetSize( MAX_INPUT_QUEUE_LENGTH );
|
2002-05-20 08:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleInput( const PlayerNumber p, const MenuButton b )
|
|
|
|
|
{
|
2002-06-14 22:25:22 +00:00
|
|
|
if( m_aQueue[p].GetSize() >= MAX_INPUT_QUEUE_LENGTH ) // full
|
|
|
|
|
m_aQueue[p].RemoveAt( 0, m_aQueue[p].GetSize()-MAX_INPUT_QUEUE_LENGTH+1 );
|
|
|
|
|
m_aQueue[p].Add( MenuButtonAndTime(b,TIMER->GetTimeSinceStart()) );
|
2002-05-20 08:59:37 +00:00
|
|
|
};
|
|
|
|
|
bool MatchesPattern( const PlayerNumber p, const MenuButton* button_sequence, const int iNumButtons, float fMaxSecondsBack = -1 )
|
|
|
|
|
{
|
|
|
|
|
if( fMaxSecondsBack == -1 )
|
|
|
|
|
fMaxSecondsBack = 0.4f + iNumButtons*0.15f;
|
|
|
|
|
|
2002-06-14 22:25:22 +00:00
|
|
|
float fOldestTimeAllowed = TIMER->GetTimeSinceStart() - fMaxSecondsBack;
|
2002-05-20 08:59:37 +00:00
|
|
|
|
|
|
|
|
int sequence_index = iNumButtons-1; // count down
|
2002-06-14 22:25:22 +00:00
|
|
|
for( int queue_index=m_aQueue[p].GetSize()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2002-06-14 22:25:22 +00:00
|
|
|
MenuButtonAndTime BandT = m_aQueue[p][queue_index];
|
2002-05-20 08:59:37 +00:00
|
|
|
if( BandT.button != button_sequence[sequence_index] ||
|
2002-06-14 22:25:22 +00:00
|
|
|
BandT.fTime < fOldestTimeAllowed )
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if( sequence_index == 0 ) // we matched the whole pattern
|
|
|
|
|
{
|
2002-06-14 22:25:22 +00:00
|
|
|
m_aQueue[p].RemoveAll(); // empty the queue so we don't match on it again
|
2002-05-20 08:59:37 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
sequence_index--;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2002-06-14 22:25:22 +00:00
|
|
|
struct MenuButtonAndTime
|
2002-05-20 08:59:37 +00:00
|
|
|
{
|
2002-06-14 22:25:22 +00:00
|
|
|
MenuButtonAndTime() {}
|
|
|
|
|
MenuButtonAndTime( MenuButton b, float t ) { button = b; fTime = t; };
|
|
|
|
|
MenuButton button;
|
|
|
|
|
float fTime;
|
2002-05-20 08:59:37 +00:00
|
|
|
};
|
2002-06-14 22:25:22 +00:00
|
|
|
CArray<MenuButtonAndTime,MenuButtonAndTime> m_aQueue[NUM_PLAYERS];
|
2002-05-20 08:59:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern InputQueue* INPUTQUEUE; // global and accessable from anywhere in our program
|