Browse Source

Added script bindings for the new SDL controller constants. Updated Input documentation.

Lasse Öörni 12 years ago
parent
commit
18e2349ae1

+ 5 - 0
Docs/Reference.dox

@@ -1323,6 +1323,9 @@ The input events include:
 - E_JOYSTICKBUTTONUP: a joystick button was released.
 - E_JOYSTICKAXISMOVE: a joystick axis was moved.
 - E_JOYSTICKHATMOVE: a joystick POV hat was moved.
+- E_CONTROLLERBUTTONDOWN: a joystick button on an SDL controller was pressed.
+- E_CONTROLLERBUTTONUP: a joystick button on an SDL controller was released.
+- E_CONTROLLERAXISMOVE: a joystick axis on an SDL controller was moved.
 
 The input polling API differentiates between the initiation of a key/mouse button press, and holding the key or button down. \ref Input::GetKeyPress "GetKeyPress()" and \ref Input::GetMouseButtonPress "GetMouseButtonPress()" return true only for one frame (the initiation) while \ref Input::GetKeyDown "GetKeyDown()" and \ref Input::GetMouseButtonDown "GetMouseButtonDown()" return true as long as the key or button is held down.
 
@@ -1330,6 +1333,8 @@ In script, the polling API is accessed via properties: input.keyDown[], input.ke
 
 To get joystick input, the joystick(s) must first be explicitly opened using \ref Input::OpenJoystick "OpenJoystick()". Accessing the polled joystick state using \ref Input::GetJoystick "GetJoystick()" also automatically opens the joystick. The plugged in joysticks are detected on application start and must be manually redetected using \ref Input::DetectJoysticks "DetectJoysticks()" if they are plugged in or disconnected during runtime.
 
+If the joystick model is recognized by SDL you will also get the "controller" variety of events shown above, and the buttons and axes mappings utilize known constants such as CONTROLLER_BUTTON_A or CONTROLLER_AXIS_LEFTX without having to guess them.
+
 From the input subsystem you can also query whether the application window has input focus, or is minimized.
 
 On platforms that support it (such as Android) an on-screen virtual keyboard can be shown or hidden. When shown, keypresses from the virtual keyboard will be sent as char events just as if typed from an actual keyboard. Show or hide it by calling \ref Input::SetScreenKeyboardVisible "SetScreenKeyboardVisible()". The UI subsystem can also automatically show the virtual keyboard when a LineEdit element is focused, and hide it when defocused. This behavior can be controlled by calling \ref UI::SetUseScreenKeyboard "SetUseScreenKeyboard()".

+ 1 - 0
Docs/Urho3D.dox

@@ -70,6 +70,7 @@ Urho3D development, contributions and bugfixes by:
 - Pete Leigh
 - Paul Noome
 - Alex Parlett
+- Jordan Patterson
 - Vladimir Pobedinsky
 - Nick Royer
 - Miika Santala

+ 1 - 0
Readme.txt

@@ -29,6 +29,7 @@ Urho3D development, contributions and bugfixes by:
 - Pete Leigh
 - Paul Noome
 - Alex Parlett
+- Jordan Patterson
 - Vladimir Pobedinsky
 - Nick Royer
 - Miika Santala

+ 1 - 2
Source/Engine/Input/Input.cpp

@@ -256,9 +256,8 @@ bool Input::OpenJoystick(unsigned index)
         JoystickState& state = joysticks_[index];
         state.joystick_ = joystick;
         if (SDL_IsGameController(index))
-        {
             state.controller_ = SDL_GameControllerOpen(index);
-        }
+        
         state.buttons_.Resize(SDL_JoystickNumButtons(joystick));
         state.buttonPress_.Resize(state.buttons_.Size());
         state.axes_.Resize(SDL_JoystickNumAxes(joystick));

+ 1 - 1
Source/Engine/Input/InputEvents.h

@@ -149,7 +149,7 @@ EVENT(E_JOYSTICKHATMOVE, JoystickHatMove)
     PARAM(P_POSITION, Position);            // int
 }
 
-/// Controller button pressed
+/// Controller button pressed.
 EVENT(E_CONTROLLERBUTTONDOWN, ControllerButtonDown)
 {
     PARAM(P_JOYSTICK, Joystick);            // int

+ 23 - 0
Source/Engine/LuaScript/pkgs/Input/InputEvents.pkg

@@ -127,6 +127,29 @@ static const int HAT_RIGHT;
 static const int HAT_DOWN;
 static const int HAT_LEFT;
 
+static const int CONTROLLER_BUTTON_A;
+static const int CONTROLLER_BUTTON_B;
+static const int CONTROLLER_BUTTON_X;
+static const int CONTROLLER_BUTTON_Y;
+static const int CONTROLLER_BUTTON_BACK;
+static const int CONTROLLER_BUTTON_GUIDE;
+static const int CONTROLLER_BUTTON_START;
+static const int CONTROLLER_BUTTON_LEFTSTICK;
+static const int CONTROLLER_BUTTON_RIGHTSTICK;
+static const int CONTROLLER_BUTTON_LEFTSHOULDER;
+static const int CONTROLLER_BUTTON_RIGHTSHOULDER;
+static const int CONTROLLER_BUTTON_DPAD_UP;
+static const int CONTROLLER_BUTTON_DPAD_DOWN;
+static const int CONTROLLER_BUTTON_DPAD_LEFT;
+static const int CONTROLLER_BUTTON_DPAD_RIGHT;
+
+static const int CONTROLLER_AXIS_LEFTX;
+static const int CONTROLLER_AXIS_LEFTY;
+static const int CONTROLLER_AXIS_RIGHTX;
+static const int CONTROLLER_AXIS_RIGHTY;
+static const int CONTROLLER_AXIS_TRIGGERLEFT;
+static const int CONTROLLER_AXIS_TRIGGERRIGHT;
+
 ${
 static const int KEY_1 = '1';
 static const int KEY_2 = '2';

+ 21 - 0
Source/Engine/Script/InputAPI.cpp

@@ -113,6 +113,27 @@ static void RegisterInputConstants(asIScriptEngine* engine)
     engine->RegisterGlobalProperty("const int HAT_RIGHT", (void*)&HAT_RIGHT);
     engine->RegisterGlobalProperty("const int HAT_DOWN", (void*)&HAT_DOWN);
     engine->RegisterGlobalProperty("const int HAT_LEFT", (void*)&HAT_LEFT);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_A", (void*)&CONTROLLER_BUTTON_A);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_B", (void*)&CONTROLLER_BUTTON_B);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_X", (void*)&CONTROLLER_BUTTON_X);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_Y", (void*)&CONTROLLER_BUTTON_Y);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_BACK", (void*)&CONTROLLER_BUTTON_BACK);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_GUIDE", (void*)&CONTROLLER_BUTTON_GUIDE);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_START", (void*)&CONTROLLER_BUTTON_START);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_LEFTSTICK", (void*)&CONTROLLER_BUTTON_LEFTSTICK);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_RIGHTSTICK", (void*)&CONTROLLER_BUTTON_RIGHTSTICK);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_LEFTSHOULDER", (void*)&CONTROLLER_BUTTON_LEFTSHOULDER);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_RIGHTSHOULDER", (void*)&CONTROLLER_BUTTON_RIGHTSHOULDER);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_DPAD_UP", (void*)&CONTROLLER_BUTTON_DPAD_UP);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_DPAD_DOWN", (void*)&CONTROLLER_BUTTON_DPAD_DOWN);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_DPAD_LEFT", (void*)&CONTROLLER_BUTTON_DPAD_LEFT);
+    engine->RegisterGlobalProperty("const int CONTROLLER_BUTTON_DPAD_RIGHT", (void*)&CONTROLLER_BUTTON_DPAD_RIGHT);
+    engine->RegisterGlobalProperty("const int CONTROLLER_AXIS_LEFTX", (void*)&CONTROLLER_AXIS_LEFTX);
+    engine->RegisterGlobalProperty("const int CONTROLLER_AXIS_LEFTY", (void*)&CONTROLLER_AXIS_LEFTY);
+    engine->RegisterGlobalProperty("const int CONTROLLER_AXIS_RIGHTX", (void*)&CONTROLLER_AXIS_RIGHTX);
+    engine->RegisterGlobalProperty("const int CONTROLLER_AXIS_RIGHTY", (void*)&CONTROLLER_AXIS_RIGHTY);
+    engine->RegisterGlobalProperty("const int CONTROLLER_AXIS_TRIGGERLEFT", (void*)&CONTROLLER_AXIS_TRIGGERLEFT);
+    engine->RegisterGlobalProperty("const int CONTROLLER_AXIS_TRIGGERRIGHT", (void*)&CONTROLLER_AXIS_TRIGGERRIGHT);
 }
 
 static Input* GetInput()