From c4417a067804ca4dcc534ec183abef5bcea9552e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 13 Jul 2003 01:00:55 +0000 Subject: [PATCH] Add InputHandler::ButtonPressed. --- .../src/arch/InputHandler/InputHandler.cpp | 25 +++++++++++++++++++ .../src/arch/InputHandler/InputHandler.h | 21 +++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 stepmania/src/arch/InputHandler/InputHandler.cpp diff --git a/stepmania/src/arch/InputHandler/InputHandler.cpp b/stepmania/src/arch/InputHandler/InputHandler.cpp new file mode 100644 index 0000000000..3f8f4bc912 --- /dev/null +++ b/stepmania/src/arch/InputHandler/InputHandler.cpp @@ -0,0 +1,25 @@ +#include "global.h" +#include "InputFilter.h" +#include "InputHandler.h" + +void InputHandler::Update(float fDeltaTime) +{ + m_LastUpdate.Touch(); +} + +void InputHandler::ButtonPressed( DeviceInput di, bool Down ) +{ + if( di.ts.IsZero() ) + { + const RageTimer now; + const float ProbableDelay = -(now - m_LastUpdate) / 2; + di.ts = now + ProbableDelay; + } + + INPUTFILTER->ButtonPressed( di, Down ); +} + +/* + * Copyright (c) 2003 by the person(s) listed below. All rights reserved. + * Glenn Maynard + */ diff --git a/stepmania/src/arch/InputHandler/InputHandler.h b/stepmania/src/arch/InputHandler/InputHandler.h index bc65878933..182420840e 100644 --- a/stepmania/src/arch/InputHandler/InputHandler.h +++ b/stepmania/src/arch/InputHandler/InputHandler.h @@ -26,14 +26,33 @@ class InputHandler { + RageTimer m_LastUpdate; + public: - virtual void Update(float fDeltaTime) { } + /* It's vital that this be called at the *end* of any overloads. */ + virtual void Update(float fDeltaTime); virtual ~InputHandler() { } virtual void GetDevicesAndDescriptions(vector& vDevicesOut, vector& vDescriptionsOut) = 0; /* In Windows, some devices need to be recreated if we recreate our main window. * Override this if you need to do that. */ virtual void WindowReset() { } + +protected: + /* Convenience function: Call this to queue a received event. This may be called + * in a thread. + * + * Important detail: If the timestamp, di.ts, is zero, then it is assumed that + * this is not a threaded event handler. In that case, input is being polled, + * and the actual time the button was pressed may be any time since the last + * poll. In this case, ButtonPressed will pretend the button was pressed at + * the midpoint since the last update, which will smooth out the error. + * + * Note that timestamps are set to the current time by default, so for this to + * happen, you need to explicitly call di.ts.SetZero(). + * + * If the timestamp is set, it'll be left alone. */ + void ButtonPressed( DeviceInput di, bool Down ); }; #endif