Game Engine Architecture

(Ben Green) #1
357

check ΔT against the maximum period ΔTmax = 1/fmin directly). If this threshold
is satisifi ed, we update the value of Tlast , and the gesture is considered to be
on-going. If the threshold is not satisfi ed, we simply don’t update Tlast. The
gesture will be considered invalid until a new pair of rapid-enough butt on-
down events occurs. This is illustrated by the following pseudocode:


classButtonTapDetector
{
U32 m_buttonMask; // which button to observe (bit
// mask)
F32 m_dtMax; // max allowed time between
// presses
F32 m_tLast; // last button-down event, in
// seconds
public:
// Construct an object that detects rapid tapping of
// the given button (identified by an index).
ButtonTapDetector(U32 buttonId, F32 dtMax) :
m_buttonMask(1U << buttonId),
m_dtMax(dtMax),
m_tLast(CurrentTime() – dtMax) // start out
// invalid
{
}

// Call this at any time to query whether or not the
// gesture is currently being performed.
void IsGestureValid() const
{
F32 t = CurrentTime();
F32 dt = t – m_tLast;
return (dt < m_dtMax);
}
// Call this once per frame.
void Update()
{
if (ButtonsJustWentDown(m_buttonMask))
{
m_tLast = CurrentTime();
}
}
};
In the above code excerpt, we assume that each butt on is identifi ed by a
unique id. The id is really just an index, ranging from 0 to N – 1 (where N is
the number of butt ons on the HID in question). We convert the butt on id to a


8.5. Game Engine HID Systems

Free download pdf