Commit 539efcb1 authored by DavidWyand-GG's avatar DavidWyand-GG

Input event changes

- New InputEventManager class.  It will be used by 3rd party input
devices to generate Torque 3D input events.
- Expanded the input event signal to include three new floats and a new
integer.
- Expanded the number of joystick buttons to 48.
- The input virtual map is now extendable rather than hard coded.
- The input devices types are now extendable rather than hard coded.
- New SI_POS, SI_ROT, SI_INT, and SI_FLOAT input event types.
- New SI_VALUE input action type.
- ActionMap has been updated to work with these changes.
- Removed unnecessary references to platform/event.h
parent 5d6751cd
......@@ -23,10 +23,6 @@
#ifndef _AUTH_H_
#define _AUTH_H_
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
/// Formerly contained a certificate, showing that something was valid.
class Auth2Certificate
{
......
......@@ -291,6 +291,9 @@ void StandardMainLoop::init()
tm = new TimeManager;
tm->timeEvent.notify(&::processTimeEvent);
// Start up the Input Event Manager
INPUTMGR->start();
Sampler::init();
// Hook in for UDP notification
......@@ -307,6 +310,9 @@ void StandardMainLoop::init()
void StandardMainLoop::shutdown()
{
// Stop the Input Event Manager
INPUTMGR->stop();
delete tm;
preShutdown();
......
......@@ -23,7 +23,6 @@
#include "app/net/httpObject.h"
#include "platform/platform.h"
#include "platform/event.h"
#include "core/stream/fileStream.h"
#include "console/simBase.h"
#include "console/consoleInternal.h"
......
......@@ -22,7 +22,6 @@
#include "platform/platform.h"
#include "console/simBase.h"
#include "platform/event.h"
#include "sim/netConnection.h"
#include "core/stream/bitStream.h"
#include "sim/netObject.h"
......
......@@ -96,7 +96,6 @@
#include "app/net/serverQuery.h"
#include "platform/platform.h"
#include "platform/event.h"
#include "core/dnet.h"
#include "core/util/tVector.h"
#include "core/stream/bitStream.h"
......
......@@ -26,9 +26,6 @@
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#ifndef _BITSET_H_
#include "core/bitSet.h"
#endif
......
......@@ -23,7 +23,6 @@
#include "app/net/tcpObject.h"
#include "platform/platform.h"
#include "platform/event.h"
#include "console/simBase.h"
#include "console/consoleInternal.h"
#include "core/strings/stringUnit.h"
......
......@@ -23,7 +23,6 @@
#include "platform/platform.h"
#include "console/console.h"
#include "console/telnetDebugger.h"
#include "platform/event.h"
#include "console/ast.h"
#include "core/tAlgorithm.h"
......
......@@ -23,7 +23,6 @@
#include "platform/platform.h"
#include "console/console.h"
#include "console/telnetDebugger.h"
#include "platform/event.h"
#include "console/ast.h"
#include "core/tAlgorithm.h"
......
......@@ -30,7 +30,6 @@
#include "core/strings/unicode.h"
#include "core/stream/fileStream.h"
#include "console/compiler.h"
#include "platform/event.h"
#include "platform/platformInput.h"
#include "core/util/journal/journal.h"
#include "core/util/uuid.h"
......
......@@ -27,7 +27,6 @@
#include "console/ast.h"
#include "core/stream/fileStream.h"
#include "console/compiler.h"
#include "platform/event.h"
#include "platform/platformInput.h"
#include "torqueConfig.h"
#include "core/frameAllocator.h"
......
......@@ -25,7 +25,6 @@
#include "console/engineAPI.h"
#include "core/strings/stringFunctions.h"
#include "platform/event.h"
#include "core/util/journal/process.h"
#include "core/module.h"
......
......@@ -26,9 +26,6 @@
#ifndef _CONSOLE_H_
#include "console/console.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#include "platform/platformNet.h"
/// Telnet admin console.
......
......@@ -25,7 +25,6 @@
#include "core/frameAllocator.h"
#include "console/console.h"
#include "platform/event.h"
#include "core/stringTable.h"
#include "console/consoleInternal.h"
#include "console/ast.h"
......
......@@ -26,9 +26,6 @@
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#include "platform/platformNet.h"
......
......@@ -394,8 +394,8 @@ typedef JournaledSignal<void(WindowId, S32, S32)> ResizeEvent;
/// void event(S32 timeDelta)
typedef JournaledSignal<void(S32)> TimeManagerEvent;
// void event(U32 deviceInst,F32 fValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier)
typedef JournaledSignal<void(U32,F32,U16,U16,U16,U16,U8,U8)> InputEvent;
// void event(U32 deviceInst, F32 fValue, F32 fValue2, F32 fValue3, F32 fValue4, S32 iValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier)
typedef JournaledSignal<void(U32,F32,F32,F32,F32,S32,U16,U16,U16,U16,U8,U8)> InputEvent;
/// void event(U32 popupGUID, U32 commandID, bool& returnValue)
typedef JournaledSignal<void(U32, U32)> PopupMenuEvent;
......
......@@ -26,7 +26,6 @@
#include "console/engineAPI.h"
#include "console/console.h"
#include "gfx/bitmap/gBitmap.h"
#include "platform/event.h"
#include "gui/core/guiDefaultControlRender.h"
#include "gfx/gfxDevice.h"
#include "gfx/gfxDrawUtil.h"
......
......@@ -24,7 +24,6 @@
#include "gui/containers/guiScrollCtrl.h"
#include "gui/core/guiCanvas.h"
#include "console/consoleTypes.h"
#include "platform/event.h"
#include "core/frameAllocator.h"
#include "core/stringBuffer.h"
#include "gfx/gfxDrawUtil.h"
......
......@@ -26,7 +26,6 @@
#include "gfx/gfxTextureManager.h"
#include "gui/controls/guiSliderCtrl.h"
#include "gui/core/guiDefaultControlRender.h"
#include "platform/event.h"
#include "gfx/primBuilder.h"
#include "gfx/gfxDrawUtil.h"
#include "sfx/sfxSystem.h"
......
......@@ -30,7 +30,6 @@
#include "console/consoleTypes.h"
#include "console/console.h"
#include "gui/core/guiTypes.h"
#include "platform/event.h"
#include "gfx/gfxDrawUtil.h"
#include "gui/controls/guiTextEditCtrl.h"
#ifdef TORQUE_TOOLS
......
......@@ -25,7 +25,6 @@
#include "console/console.h"
#include "console/engineAPI.h"
#include "platform/event.h"
#include "gui/containers/guiScrollCtrl.h"
#include "gfx/gfxDrawUtil.h"
#include "gui/core/guiDefaultControlRender.h"
......
......@@ -26,7 +26,6 @@
#include "console/console.h"
#include "console/engineAPI.h"
#include "platform/profiler.h"
#include "platform/event.h"
#include "gfx/gfxDevice.h"
#include "gfx/gfxDrawUtil.h"
#include "gui/core/guiTypes.h"
......
......@@ -26,9 +26,6 @@
#ifndef _SIMBASE_H_
#include "console/simBase.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#ifndef _GUICONTROL_H_
#include "gui/core/guiControl.h"
#endif
......
......@@ -28,7 +28,6 @@
#include "console/consoleInternal.h"
#include "console/engineAPI.h"
#include "console/codeBlock.h"
#include "platform/event.h"
#include "gfx/bitmap/gBitmap.h"
#include "sim/actionMap.h"
#include "gui/core/guiCanvas.h"
......
......@@ -38,9 +38,6 @@
#ifndef _GUITYPES_H_
#include "gui/core/guiTypes.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#ifndef _UTIL_DELEGATE_H_
#include "core/util/delegate.h"
#endif
......
......@@ -26,9 +26,6 @@
#ifndef _GUIMOUSEEVENTCTRL_H_
#include "gui/utility/guiMouseEventCtrl.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
/// A control that locks the mouse and reports all keyboard input events
......
......@@ -26,9 +26,6 @@
#ifndef _GUICONTROL_H_
#include "gui/core/guiControl.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
class GuiMouseEventCtrl : public GuiControl
......
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _IINPUTDEVICE_H_
#define _IINPUTDEVICE_H_
#include "console/consoleTypes.h"
class IInputDevice
{
protected:
/// Device name
char mName[30];
/// Device type
U32 mDeviceType;
/// Is the device enabled
bool mEnabled;
public:
inline const char* getDeviceName() const
{
return mName;
}
inline U32 getDeviceType() const
{
return mDeviceType;
}
inline bool isEnabled()
{
return mEnabled;
}
virtual bool process() = 0;
};
#endif
This diff is collapsed.
......@@ -30,13 +30,21 @@
#define _EVENT_H_
#include "platform/types.h"
#include "platform/IInputDevice.h"
#include "core/util/journal/journaledSignal.h"
#include "core/util/tSingleton.h"
#include "core/util/tDictionary.h"
#include "core/tSimpleHashTable.h"
#define AddInputVirtualMap( description, type, code ) \
INPUTMGR->addVirtualMap( #description, type, code );
/// @defgroup input_constants Input system constants
/// @{
/// Input event constants:
enum InputObjectInstances
typedef U32 InputObjectInstances;
enum InputObjectInstancesEnum
{
KEY_NULL = 0x000, ///< Invalid KeyCode
KEY_BACKSPACE = 0x001,
......@@ -203,6 +211,22 @@ enum InputObjectInstances
KEY_BUTTON29 = 0x011D,
KEY_BUTTON30 = 0x011E,
KEY_BUTTON31 = 0x011F,
KEY_BUTTON32 = 0x0120,
KEY_BUTTON33 = 0x0121,
KEY_BUTTON34 = 0x0122,
KEY_BUTTON35 = 0x0123,
KEY_BUTTON36 = 0x0124,
KEY_BUTTON37 = 0x0125,
KEY_BUTTON38 = 0x0126,
KEY_BUTTON39 = 0x0127,
KEY_BUTTON40 = 0x0128,
KEY_BUTTON41 = 0x0129,
KEY_BUTTON42 = 0x012A,
KEY_BUTTON43 = 0x012B,
KEY_BUTTON44 = 0x012C,
KEY_BUTTON45 = 0x012D,
KEY_BUTTON46 = 0x012E,
KEY_BUTTON47 = 0x012F,
KEY_ANYKEY = 0xfffe,
/// Joystick event codes.
......@@ -250,10 +274,13 @@ enum InputObjectInstances
XI_B = 0x318,
XI_X = 0x319,
XI_Y = 0x320,
INPUT_DEVICE_PLUGIN_CODES_START = 0x400,
};
/// Input device types
enum InputDeviceTypes
typedef U32 InputDeviceTypes;
enum InputDeviceTypesEnum
{
UnknownDeviceType,
MouseDeviceType,
......@@ -262,7 +289,9 @@ enum InputDeviceTypes
GamepadDeviceType,
XInputDeviceType,
NUM_INPUT_DEVICE_TYPES
NUM_INPUT_DEVICE_TYPES,
INPUT_DEVICE_PLUGIN_DEVICES_START = NUM_INPUT_DEVICE_TYPES,
};
/// Device Event Action Types
......@@ -278,17 +307,24 @@ enum InputActionType
SI_MOVE = 0x03,
/// A key repeat occurred. Happens in between a SI_MAKE and SI_BREAK.
SI_REPEAT = 0x04,
SI_REPEAT = 0x04,
/// A value of some type. Matched with SI_FLOAT or SI_INT.
SI_VALUE = 0x05,
};
///Device Event Types
enum InputEventType
{
SI_UNKNOWN = 0x01,
SI_BUTTON = 0x02,
SI_POV = 0x03,
SI_AXIS = 0x04,
SI_KEY = 0x0A,
SI_BUTTON = 0x02, // Button press/release
SI_POV = 0x03, // Point of View hat
SI_AXIS = 0x04, // Axis in range -1.0..1.0
SI_POS = 0x05, // Absolute position value (Point3F)
SI_ROT = 0x06, // Absolute rotation value (QuatF)
SI_INT = 0x07, // Integer value (S32)
SI_FLOAT = 0x08, // Float value (F32)
SI_KEY = 0x0A, // Keyboard key
};
/// Wildcard match used by the input system.
......@@ -356,6 +392,10 @@ struct InputEventInfo
{
deviceInst = 0;
fValue = 0.f;
fValue2 = 0.f;
fValue3 = 0.f;
fValue4 = 0.f;
iValue = 0;
deviceType = (InputDeviceTypes)0;
objType = (InputEventType)0;
ascii = 0;
......@@ -367,9 +407,18 @@ struct InputEventInfo
/// Device instance: joystick0, joystick1, etc
U32 deviceInst;
/// Value ranges from -1.0 to 1.0
/// Value typically ranges from -1.0 to 1.0, but doesn't have to.
/// It depends on the context.
F32 fValue;
/// Extended float values (often used for absolute rotation Quat)
F32 fValue2;
F32 fValue3;
F32 fValue4;
/// Signed integer value
S32 iValue;
/// What was the action? (MAKE/BREAK/MOVE)
InputActionType action;
InputDeviceTypes deviceType;
......@@ -384,9 +433,99 @@ struct InputEventInfo
inline void postToSignal(InputEvent &ie)
{
ie.trigger(deviceInst, fValue, deviceType, objType, ascii, objInst, action, modifier);
ie.trigger(deviceInst, fValue, fValue2, fValue3, fValue4, iValue, deviceType, objType, ascii, objInst, action, modifier);
}
};
class Point3F;
class QuatF;
/// Handles input device plug-ins
class InputEventManager
{
public:
struct VirtualMapData
{
StringTableEntry desc;
InputEventType type;
InputObjectInstances code;
};
public:
InputEventManager();
virtual ~InputEventManager();
/// Get the next device type code
U32 getNextDeviceType();
/// Get the next device action code
U32 getNextDeviceCode();
void registerDevice(IInputDevice* device);
void unregisterDevice(IInputDevice* device);
/// Check if the given device name is a registered device.
/// The given name can optionally include an instance number on the end.
bool isRegisteredDevice(const char* name);
/// Check if the given device type is a registered device.
bool isRegisteredDevice(U32 type);
/// Same as above but also provides the found device type and actual
// device name length. Used by ActionMap::getDeviceTypeAndInstance()
bool isRegisteredDeviceWithAttributes(const char* name, U32& deviceType, U32&nameLen);
/// Returns the name of a registered device given its type
const char* getRegisteredDeviceName(U32 type);
void start();
void stop();
void process();
// Add to the virtual map table
void addVirtualMap(const char* description, InputEventType type, InputObjectInstances code);
// Find a virtual map entry based on the text description
VirtualMapData* findVirtualMap(const char* description);
// Find a virtual map entry's description based on the action code
const char* findVirtualMapDescFromCode(U32 code);
/// Build an input event based on a single iValue
void buildInputEvent(U32 deviceType, U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, S32 iValue);
/// Build an input event based on a single fValue
void buildInputEvent(U32 deviceType, U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, float fValue);
/// Build an input event based on a Point3F
void buildInputEvent(U32 deviceType, U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, Point3F& pValue);
/// Build an input event based on a QuatF
void buildInputEvent(U32 deviceType, U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, QuatF& qValue);
protected:
U32 mNextDeviceTypeCode;
U32 mNextDeviceCode;
Vector<IInputDevice*> mDeviceList;
// Holds description to VirtualMapData struct
SimpleHashTable<VirtualMapData> mVirtualMap;
// Used to look up a description based on a VirtualMapData.code
HashTable<U32, VirtualMapData> mActionCodeMap;
protected:
void buildVirtualMap();
public:
// For ManagedSingleton.
static const char* getSingletonName() { return "InputEventManager"; }
};
/// Returns the InputEventManager singleton.
#define INPUTMGR ManagedSingleton<InputEventManager>::instance()
#endif
......@@ -21,7 +21,6 @@
//-----------------------------------------------------------------------------
#include "platform/platformNet.h"
#include "platform/event.h"
#include "core/strings/stringFunctions.h"
#if defined (TORQUE_OS_WIN32)
......
......@@ -27,9 +27,6 @@
#ifndef _CONSOLE_H_
#include "console/console.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
class WinConsole
{
......
......@@ -29,9 +29,6 @@
#ifndef _PLATFORMINPUT_H_
#include "platform/platformInput.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
......
......@@ -23,7 +23,6 @@
#include "platformWin32/platformWin32.h"
#include "platformWin32/winDirectInput.h"
#include "platformWin32/winDInputDevice.h"
#include "platform/event.h"
#include "console/console.h"
#include "console/consoleTypes.h"
#include "sim/actionMap.h"
......
......@@ -24,7 +24,6 @@
#include "platform/platformInput.h"
#include "platformWin32/winDirectInput.h"
#include "platform/event.h"
#include "console/console.h"
#include "core/util/journal/process.h"
#include "windowManager/platformWindowMgr.h"
......
......@@ -21,7 +21,6 @@
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "platform/event.h"
#include "platformWin32/platformWin32.h"
#include "platformWin32/winConsole.h"
#include "platformWin32/winDirectInput.h"
......
This diff is collapsed.
......@@ -32,9 +32,6 @@
#ifndef _NETSTRINGTABLE_H_
#include "sim/netStringTable.h"
#endif
#ifndef _EVENT_H_
#include "platform/event.h"
#endif
#ifndef _DNET_H_
#include "core/dnet.h"
#endif
......
......@@ -21,7 +21,6 @@
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "platform/event.h"
#include "sim/netConnection.h"
#include "sim/netInterface.h"
#include "core/stream/bitStream.h"
......
......@@ -21,7 +21,6 @@
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "platform/event.h"
#include "windowManager/platformWindowMgr.h"
#include "gfx/gfxInit.h"
#include "gfx/gfxDevice.h"
......
......@@ -31,7 +31,6 @@
#include <windows.h>
#include "platform/event.h"
#include "platform/platformInput.h"
#include "windowManager/win32/winDispatch.h"
#include "windowManager/win32/win32Window.h"
......
......@@ -310,7 +310,7 @@ void WindowInputGenerator::handleKeyboard( WindowId did, U32 modifier, U32 actio
//-----------------------------------------------------------------------------
// Raw input
//-----------------------------------------------------------------------------
void WindowInputGenerator::handleInputEvent( U32 deviceInst,F32 fValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier )
void WindowInputGenerator::handleInputEvent( U32 deviceInst, F32 fValue, F32 fValue2, F32 fValue3, F32 fValue4, S32 iValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier )
{
// Skip it if we don't have focus.
if(!mInputController || !mFocused)
......@@ -320,6 +320,10 @@ void WindowInputGenerator::handleInputEvent( U32 deviceInst,F32 fValue, U16 devi
InputEventInfo event;
event.deviceInst = deviceInst;
event.fValue = fValue;
event.fValue2 = fValue2;
event.fValue3 = fValue3;
event.fValue4 = fValue4;
event.iValue = iValue;
event.deviceType = (InputDeviceTypes)deviceType;
event.objType = (InputEventType)objType;
event.ascii = ascii;
......
......@@ -58,7 +58,7 @@ class WindowInputGenerator
void handleKeyboard (WindowId did, U32 modifier, U32 action, U16 key);
void handleCharInput (WindowId did, U32 modifier, U16 key);
void handleAppEvent (WindowId did, S32 event);
void handleInputEvent (U32 deviceInst,F32 fValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier);
void handleInputEvent (U32 deviceInst, F32 fValue, F32 fValue2, F32 fValue3, F32 fValue4, S32 iValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier);
void generateInputEvent( InputEventInfo &inputEvent );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment