瀏覽代碼

Some fixes for input handling

Marko Pintera 11 年之前
父節點
當前提交
8069c9bdeb

+ 32 - 34
BansheeCore/Include/BsInputFwd.h

@@ -191,42 +191,40 @@ namespace BansheeEngine
 		BC_MOUSE_BTN30 = 0x8000010C,
 		BC_MOUSE_BTN31 = 0x8000010D,
 		BC_MOUSE_BTN32 = 0x8000010E,
-		BC_JOY_BTN1 = 0x4000010F, // Joystick/Gamepad buttons- Second most important bit signifies key is a joystick button
-		BC_JOY_BTN2 = 0x40000110,
-		BC_JOY_BTN3 = 0x40000111,
-		BC_JOY_BTN4 = 0x40000112,
-		BC_JOY_BTN5 = 0x40000113,
-		BC_JOY_BTN6 = 0x40000114,
-		BC_JOY_BTN7 = 0x40000115,
-		BC_JOY_BTN8 = 0x40000116,
-		BC_JOY_BTN9 = 0x40000117,
-		BC_JOY_BTN10 = 0x40000118,
-		BC_JOY_BTN11 = 0x40000119,
-		BC_JOY_BTN12 = 0x4000011A,
-		BC_JOY_BTN13 = 0x4000011B,
-		BC_JOY_BTN14 = 0x4000011C,
-		BC_JOY_BTN15 = 0x4000011D,
-		BC_JOY_BTN16 = 0x4000011E,
-		BC_JOY_BTN17 = 0x4000011F,
-		BC_JOY_BTN18 = 0x40000120,
-		BC_JOY_BTN19 = 0x40000121,
-		BC_JOY_BTN20 = 0x40000123,
-		BC_JOY_BTN21 = 0x40000124,
-		BC_JOY_BTN22 = 0x40000125,
-		BC_JOY_BTN23 = 0x40000126,
-		BC_JOY_BTN24 = 0x40000127,
-		BC_JOY_BTN25 = 0x40000128,
-		BC_JOY_BTN26 = 0x40000129,
-		BC_JOY_BTN27 = 0x4000012A,
-		BC_JOY_BTN28 = 0x4000012B,
-		BC_JOY_BTN29 = 0x4000012C,
-		BC_JOY_BTN30 = 0x4000012D,
-		BC_JOY_BTN31 = 0x4000012E,
-		BC_JOY_BTN32 = 0x4000012F,
-		BC_Count = 0x00000130,
+		BC_GAMEPAD_A = 0x4000010F, // Joystick/Gamepad buttons- Second most important bit signifies key is a gamepad button
+		BC_GAMEPAD_B = 0x40000110, // Similar to keyboard names, these are for convenience named after Xbox controller buttons
+		BC_GAMEPAD_X = 0x40000111, // but if some other controller is connected you will need to learn yourself which of these
+		BC_GAMEPAD_Y = 0x40000112, // corresponds to which actual button on the controller.
+		BC_GAMEPAD_LB = 0x40000113,
+		BC_GAMEPAD_RB = 0x40000114,
+		BC_GAMEPAD_LS = 0x40000115,
+		BC_GAMEPAD_RS = 0x40000116,
+		BC_GAMEPAD_BACK = 0x40000117,
+		BC_GAMEPAD_START = 0x40000118,
+		BC_GAMEPAD_BTN1 = 0x40000119,
+		BC_GAMEPAD_BTN2 = 0x4000011A,
+		BC_GAMEPAD_BTN3 = 0x4000011B,
+		BC_GAMEPAD_BTN4 = 0x4000011C,
+		BC_GAMEPAD_BTN5 = 0x4000011D,
+		BC_GAMEPAD_BTN6 = 0x4000011E,
+		BC_GAMEPAD_BTN7 = 0x4000011F,
+		BC_GAMEPAD_BTN8 = 0x40000120,
+		BC_GAMEPAD_BTN9 = 0x40000121,
+		BC_GAMEPAD_BTN10 = 0x40000122,
+		BC_GAMEPAD_BTN11 = 0x40000123,
+		BC_GAMEPAD_BTN12 = 0x40000124,
+		BC_GAMEPAD_BTN13 = 0x40000125,
+		BC_GAMEPAD_BTN14 = 0x40000126,
+		BC_GAMEPAD_BTN15 = 0x40000127,
+		BC_GAMEPAD_BTN16 = 0x40000128,
+		BC_GAMEPAD_BTN17 = 0x40000129,
+		BC_GAMEPAD_BTN18 = 0x4000012A,
+		BC_GAMEPAD_BTN19 = 0x4000012B,
+		BC_GAMEPAD_BTN20 = 0x4000012C,
+		BC_Count = 0x0000012C,
 		BC_NumKeys = 0xEE, // IMPORTANT: Make sure to update these if you modify the values above
 		BC_NumMouse = 0x20,
-		BC_NumJoy = 0x20,
+		BC_NumGamepad = 0x1E,
 	};
 
 	/**

+ 40 - 6
BansheeOISInput/Source/BsInputHandlerOIS.cpp

@@ -4,6 +4,7 @@
 #include "BsRenderWindow.h"
 #include "BsTime.h"
 #include "BsMath.h"
+#include "BsDebug.h"
 
 namespace BansheeEngine
 {
@@ -17,7 +18,8 @@ namespace BansheeEngine
 	{
 		ButtonCode bc = InputHandlerOIS::gamepadButtonToButtonCode(button);
 
-		mParentHandler->onButtonDown(mGamepadIdx, bc, 0); // TODO - No timestamps
+		// Note: No timestamps for gamepad buttons, but they shouldn't be used for anything anyway
+		mParentHandler->onButtonDown(mGamepadIdx, bc, 0);
 		return true;
 	}
 
@@ -25,7 +27,8 @@ namespace BansheeEngine
 	{
 		ButtonCode bc = InputHandlerOIS::gamepadButtonToButtonCode(button);
 
-		mParentHandler->onButtonUp(mGamepadIdx, bc, 0); // TODO - No timestamps
+		// Note: No timestamps for gamepad buttons, but they shouldn't be used for anything anyway
+		mParentHandler->onButtonUp(mGamepadIdx, bc, 0);
 		return true;
 	}
 
@@ -38,11 +41,13 @@ namespace BansheeEngine
 		INT32 axisAbs = arg.state.mAxes[axis].abs;
 
 		RawAxisState axisState;
-		axisState.rel = ((axisRel + OIS::JoyStick::MIN_AXIS) / axisRange) * 2.0f - 1.0f;
-		axisState.abs = ((axisAbs + OIS::JoyStick::MIN_AXIS) / axisRange) * 2.0f - 1.0f;
+		axisState.rel = ((axisRel + Math::abs((float)OIS::JoyStick::MIN_AXIS)) / axisRange) * 2.0f - 1.0f;
+		axisState.abs = ((axisAbs + Math::abs((float)OIS::JoyStick::MIN_AXIS)) / axisRange) * 2.0f - 1.0f;
 
 		mParentHandler->onAxisMoved(mGamepadIdx, axisState, (UINT32)axis);
 
+		LOGWRN(toString(axis) + " - " + toString(axisState.abs));
+
 		return true;
 	}
 
@@ -94,6 +99,8 @@ namespace BansheeEngine
 
 			gamepadData.gamepad = static_cast<OIS::JoyStick*>(mInputManager->createInputObject(OIS::OISJoyStick, true));
 			gamepadData.listener = bs_new<GamepadEventListener>(this, i);
+
+			gamepadData.gamepad->setEventCallback(gamepadData.listener);
 		}
 
 		// OIS reports times since system start but we use time since program start
@@ -206,7 +213,34 @@ namespace BansheeEngine
 
 	ButtonCode InputHandlerOIS::gamepadButtonToButtonCode(INT32 joystickCode)
 	{
-		// TODO
-		return BC_0;
+		switch (joystickCode)
+		{
+		case 0:
+			return BC_GAMEPAD_A;
+		case 1:
+			return BC_GAMEPAD_B;
+		case 2:
+			return BC_GAMEPAD_X;
+		case 3:
+			return BC_GAMEPAD_Y;
+		case 4:
+			return BC_GAMEPAD_LB;
+		case 5:
+			return BC_GAMEPAD_RB;
+		case 6:
+			return BC_GAMEPAD_BACK;
+		case 7:
+			return BC_GAMEPAD_START;
+		case 8:
+			return BC_GAMEPAD_BTN1;
+		case 9:
+			return BC_GAMEPAD_RS;
+		case 10:
+			return BC_GAMEPAD_BTN2;
+		case 11:
+			return BC_GAMEPAD_LS;
+		}
+
+		return (ButtonCode)(BC_GAMEPAD_BTN3 + (joystickCode - 11));
 	}
 }

+ 20 - 0
BansheeUtility/Source/BsDebug.cpp

@@ -6,31 +6,51 @@
 #include "BsDataStream.h"
 #include "BsPath.h"
 
+#if BS_PLATFORM == BS_PLATFORM_WIN32 && BS_COMPILER == BS_COMPILER_MSVC
+#include <windows.h>
+
+void logToIDEConsole(const BansheeEngine::String& message)
+{
+	OutputDebugString(message.c_str());
+	OutputDebugString("\n");
+}
+#else
+void logToIDEConsole(const BansheeEngine::String& message)
+{
+	// Do nothing
+}
+#endif
+
 namespace BansheeEngine
 {
 	void Debug::logDebug(const String& msg)
 	{
 		mLog.logMsg(msg, "GlobalDebug");
+		logToIDEConsole(msg);
 	}
 
 	void Debug::logInfo(const String& msg)
 	{
 		mLog.logMsg(msg, "GlobalInfo");
+		logToIDEConsole(msg);
 	}
 
 	void Debug::logWarning(const String& msg)
 	{
 		mLog.logMsg(msg, "GlobalWarning");
+		logToIDEConsole(msg);
 	}
 
 	void Debug::logError(const String& msg)
 	{
 		mLog.logMsg(msg, "GlobalError");
+		logToIDEConsole(msg);
 	}
 
 	void Debug::log(const String& msg, const String& channel)
 	{
 		mLog.logMsg(msg, channel);
+		logToIDEConsole(msg);
 	}
 
 	void Debug::writeAsBMP(UINT8* rawPixels, UINT32 bytesPerPixel, UINT32 width, UINT32 height, const Path& filePath, bool overwrite) const

+ 0 - 14
BansheeUtility/Source/BsLog.cpp

@@ -1,8 +1,6 @@
 #include "BsLog.h"
 #include "BsException.h"
 
-void dbg_VSLog(const BansheeEngine::String& message);
-
 namespace BansheeEngine
 {
 	LogEntry::LogEntry(const String& msg, const String& level)
@@ -28,8 +26,6 @@ namespace BansheeEngine
 		LogEntry* newEntry = bs_new<LogEntry, PoolAlloc>(message, level);
 		mEntries.push_back(newEntry);
 
-		dbg_VSLog(message);
-
 		doOnEntryAdded(*newEntry);
 	}
 
@@ -53,14 +49,4 @@ namespace BansheeEngine
 	{
 		onEntryAdded(entry);
 	}
-}
-
-// TODO: Debug only - Remove later
-
-#include <windows.h>
-
-void dbg_VSLog(const BansheeEngine::String& message)
-{
-	OutputDebugString(message.c_str());
-	OutputDebugString("\n");
 }

+ 2 - 2
Polish.txt

@@ -15,8 +15,7 @@ Polish TODO:
 Rebuild OIS with XINPUT support (OIS_WIN32_XINPUT_SUPPORT)
 Rename CamelotOIS to BansheeOIS
 
-TODO - How do I convert joystick buttons to in-engine button codes?
-TODO - I don't have timestamps for joystick buttons
+OIS doesn't report D-pad as buttons
 
 Mouse sensitivity/sampling rate/whatever needs to be tweaked
  - Use DirectInput DIPROPRANGE and SetProperty/GetProperty?
@@ -24,6 +23,7 @@ Mouse sensitivity/sampling rate/whatever needs to be tweaked
 Add smoothing
   - See http://www.flipcode.com/archives/Smooth_Mouse_Filtering.shtml or UE4 implementation
   - UE4 seems to receive multiple mouse samples per frame. I only sample input once per frame
+    - Actually OIS seems to receive multiple samples too, but it just accumulates them automatically
 
 -----------------