diff --git a/src/input/input.cpp b/src/input/input.cpp index c1d80fc2..75a01121 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -16,6 +16,7 @@ namespace lol { array InputDevice::devices; +int InputDevice::joystick_count = 0; bool InputDevice::m_capturemouse; array InputDevice::GetAvailableDevices() diff --git a/src/input/input.h b/src/input/input.h index cbf6abcf..f16d80fc 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -16,6 +16,10 @@ namespace lol const String g_name_max("MAX"); const String g_name_mouse("Mouse"); const String g_name_keyboard("Keyboard"); +static String g_name_joystick() +{ + return String("Joystick"); +} static String g_name_joystick(const uint64_t num) { return String::format("Joystick%d", (int)num); @@ -166,6 +170,10 @@ public: { return GetDevice(g_name_mouse); } + static int GetJoystickCount() + { + return joystick_count; + } static InputDevice* GetJoystick(const uint64_t num) { return GetDevice(g_name_joystick(num)); @@ -219,6 +227,7 @@ protected: private: static array devices; + static int joystick_count; template ptrdiff_t GetItemIndex(String const &name, const array& a) const @@ -233,6 +242,9 @@ private: static InputDevice* GetDevice(String const &name) { + //Count the device types. TODO: Multi mouse/keyboard + if (name.contains(g_name_joystick())) joystick_count++; + for (int i = 0; i < devices.count(); ++i) { if (devices[i]->m_name == name) diff --git a/src/input/input_internal.h b/src/input/input_internal.h index d80b79f6..ca6b2cc8 100644 --- a/src/input/input_internal.h +++ b/src/input/input_internal.h @@ -19,7 +19,7 @@ namespace lol class InputDeviceInternal : public InputDevice { public: - inline InputDeviceInternal(char const * name) : InputDevice(name) { } + inline InputDeviceInternal(String const& name) : InputDevice(name) { } void AddKey(int id, char const * name); diff --git a/src/platform/d3d9/d3d9input.cpp b/src/platform/d3d9/d3d9input.cpp index 866e0a43..8bee4b32 100644 --- a/src/platform/d3d9/d3d9input.cpp +++ b/src/platform/d3d9/d3d9input.cpp @@ -53,7 +53,7 @@ D3d9Input::D3d9Input() if (XInputGetState(i, &state) != ERROR_SUCCESS) continue; // TODO: we can put more friendly name here, such as LeftAxisX, ButtonX... - InputDeviceInternal* stick = new InputDeviceInternal(String::format("Joystick%d", i+1).C()); + InputDeviceInternal* stick = new InputDeviceInternal(g_name_joystick(i + 1)); stick->AddAxis(g_name_xbox_axis_left_x.C()); stick->AddAxis(g_name_xbox_axis_left_y.C()); diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index eab04f3e..78da6eb8 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -189,7 +189,8 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) continue; } - InputDeviceInternal* stick = new InputDeviceInternal(String::format("Joystick%d", i+1).C()); + //String::format("Joystick%d", i + 1).C() + InputDeviceInternal* stick = new InputDeviceInternal(g_name_joystick(i + 1)); for (int j = 0; j < SDL_JoystickNumAxes(sdlstick); ++j) stick->AddAxis(String::format("Axis%d", j + 1).C()); for (int j = 0; j < SDL_JoystickNumButtons(sdlstick); ++j) @@ -344,6 +345,7 @@ void SdlInputData::Tick(float seconds) # else case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + //event.button.which m_mouse->SetKey(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN); break; case SDL_MOUSEWHEEL: