Browse Source

Added Joystick count

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 9 years ago
parent
commit
3b00a2e5ee
5 changed files with 18 additions and 3 deletions
  1. +1
    -0
      src/input/input.cpp
  2. +12
    -0
      src/input/input.h
  3. +1
    -1
      src/input/input_internal.h
  4. +1
    -1
      src/platform/d3d9/d3d9input.cpp
  5. +3
    -1
      src/platform/sdl/sdlinput.cpp

+ 1
- 0
src/input/input.cpp View File

@@ -16,6 +16,7 @@ namespace lol
{

array<InputDevice*> InputDevice::devices;
int InputDevice::joystick_count = 0;
bool InputDevice::m_capturemouse;

array<String> InputDevice::GetAvailableDevices()


+ 12
- 0
src/input/input.h View File

@@ -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<InputDevice*> devices;
static int joystick_count;

template <typename... T>
ptrdiff_t GetItemIndex(String const &name, const array<String, T...>& 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)


+ 1
- 1
src/input/input_internal.h View File

@@ -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);



+ 1
- 1
src/platform/d3d9/d3d9input.cpp View File

@@ -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());


+ 3
- 1
src/platform/sdl/sdlinput.cpp View File

@@ -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:


Loading…
Cancel
Save