| @@ -16,6 +16,7 @@ namespace lol | |||||
| { | { | ||||
| array<InputDevice*> InputDevice::devices; | array<InputDevice*> InputDevice::devices; | ||||
| int InputDevice::joystick_count = 0; | |||||
| bool InputDevice::m_capturemouse; | bool InputDevice::m_capturemouse; | ||||
| array<String> InputDevice::GetAvailableDevices() | array<String> InputDevice::GetAvailableDevices() | ||||
| @@ -16,6 +16,10 @@ namespace lol | |||||
| const String g_name_max("MAX"); | const String g_name_max("MAX"); | ||||
| const String g_name_mouse("Mouse"); | const String g_name_mouse("Mouse"); | ||||
| const String g_name_keyboard("Keyboard"); | const String g_name_keyboard("Keyboard"); | ||||
| static String g_name_joystick() | |||||
| { | |||||
| return String("Joystick"); | |||||
| } | |||||
| static String g_name_joystick(const uint64_t num) | static String g_name_joystick(const uint64_t num) | ||||
| { | { | ||||
| return String::format("Joystick%d", (int)num); | return String::format("Joystick%d", (int)num); | ||||
| @@ -166,6 +170,10 @@ public: | |||||
| { | { | ||||
| return GetDevice(g_name_mouse); | return GetDevice(g_name_mouse); | ||||
| } | } | ||||
| static int GetJoystickCount() | |||||
| { | |||||
| return joystick_count; | |||||
| } | |||||
| static InputDevice* GetJoystick(const uint64_t num) | static InputDevice* GetJoystick(const uint64_t num) | ||||
| { | { | ||||
| return GetDevice(g_name_joystick(num)); | return GetDevice(g_name_joystick(num)); | ||||
| @@ -219,6 +227,7 @@ protected: | |||||
| private: | private: | ||||
| static array<InputDevice*> devices; | static array<InputDevice*> devices; | ||||
| static int joystick_count; | |||||
| template <typename... T> | template <typename... T> | ||||
| ptrdiff_t GetItemIndex(String const &name, const array<String, T...>& a) const | ptrdiff_t GetItemIndex(String const &name, const array<String, T...>& a) const | ||||
| @@ -233,6 +242,9 @@ private: | |||||
| static InputDevice* GetDevice(String const &name) | 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) | for (int i = 0; i < devices.count(); ++i) | ||||
| { | { | ||||
| if (devices[i]->m_name == name) | if (devices[i]->m_name == name) | ||||
| @@ -19,7 +19,7 @@ namespace lol | |||||
| class InputDeviceInternal : public InputDevice | class InputDeviceInternal : public InputDevice | ||||
| { | { | ||||
| public: | public: | ||||
| inline InputDeviceInternal(char const * name) : InputDevice(name) { } | |||||
| inline InputDeviceInternal(String const& name) : InputDevice(name) { } | |||||
| void AddKey(int id, char const * name); | void AddKey(int id, char const * name); | ||||
| @@ -53,7 +53,7 @@ D3d9Input::D3d9Input() | |||||
| if (XInputGetState(i, &state) != ERROR_SUCCESS) | if (XInputGetState(i, &state) != ERROR_SUCCESS) | ||||
| continue; | continue; | ||||
| // TODO: we can put more friendly name here, such as LeftAxisX, ButtonX... | // 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_x.C()); | ||||
| stick->AddAxis(g_name_xbox_axis_left_y.C()); | stick->AddAxis(g_name_xbox_axis_left_y.C()); | ||||
| @@ -189,7 +189,8 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) | |||||
| continue; | 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) | for (int j = 0; j < SDL_JoystickNumAxes(sdlstick); ++j) | ||||
| stick->AddAxis(String::format("Axis%d", j + 1).C()); | stick->AddAxis(String::format("Axis%d", j + 1).C()); | ||||
| for (int j = 0; j < SDL_JoystickNumButtons(sdlstick); ++j) | for (int j = 0; j < SDL_JoystickNumButtons(sdlstick); ++j) | ||||
| @@ -344,6 +345,7 @@ void SdlInputData::Tick(float seconds) | |||||
| # else | # else | ||||
| case SDL_MOUSEBUTTONDOWN: | case SDL_MOUSEBUTTONDOWN: | ||||
| case SDL_MOUSEBUTTONUP: | case SDL_MOUSEBUTTONUP: | ||||
| //event.button.which | |||||
| m_mouse->SetKey(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN); | m_mouse->SetKey(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN); | ||||
| break; | break; | ||||
| case SDL_MOUSEWHEEL: | case SDL_MOUSEWHEEL: | ||||