aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Haas2017-03-25 23:41:00 +0100
committerAndreas Haas2017-03-26 00:12:11 +0100
commit8c06da0d49825dd4cbdd48f0cb7f2bb80b10a56e (patch)
tree9d3d7d3c034721b45cb8f8fcd0bea5a0a41cbf2c
parented3134088be869a9e0c8bd3a7a6cfd672b532809 (diff)
downloadgodot-8c06da0d49825dd4cbdd48f0cb7f2bb80b10a56e.tar.gz
godot-8c06da0d49825dd4cbdd48f0cb7f2bb80b10a56e.tar.zst
godot-8c06da0d49825dd4cbdd48f0cb7f2bb80b10a56e.zip
-rw-r--r--main/input_default.cpp9
-rw-r--r--main/input_default.h7
-rw-r--r--platform/osx/joystick_osx.cpp17
-rw-r--r--platform/osx/joystick_osx.h2
-rw-r--r--platform/windows/joystick.cpp14
-rw-r--r--platform/windows/joystick.h1
-rw-r--r--platform/x11/joystick_linux.cpp11
-rw-r--r--platform/x11/joystick_linux.h1
8 files changed, 20 insertions, 42 deletions
diff --git a/main/input_default.cpp b/main/input_default.cpp
index 1c4b8f8e5..61169985b 100644
--- a/main/input_default.cpp
+++ b/main/input_default.cpp
@@ -1157,6 +1157,15 @@ int InputDefault::get_joy_button_index_from_string(String p_button) {
ERR_FAIL_V(-1);
}
+int InputDefault::get_unused_joy_id() {
+ for (int i = 0; i < JOYSTICKS_MAX; i++) {
+ if (!joy_names.has(i) || !joy_names[i].connected) {
+ return i;
+ }
+ }
+ return -1;
+}
+
String InputDefault::get_joy_axis_string(int p_axis) {
ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, "");
return _axes[p_axis];
diff --git a/main/input_default.h b/main/input_default.h
index 8faa354e9..a0dcdcd77 100644
--- a/main/input_default.h
+++ b/main/input_default.h
@@ -122,6 +122,11 @@ public:
HAT_LEFT,
HAT_MAX,
};
+
+ enum {
+ JOYSTICKS_MAX = 16,
+ };
+
struct JoyAxis {
int min;
float value;
@@ -226,6 +231,8 @@ public:
virtual int get_joy_axis_index_from_string(String p_axis);
virtual int get_joy_button_index_from_string(String p_button);
+ int get_unused_joy_id();
+
bool is_joy_mapped(int p_device);
String get_joy_guid_remapped(int p_device) const;
void set_fallback_mapping(String p_guid);
diff --git a/platform/osx/joystick_osx.cpp b/platform/osx/joystick_osx.cpp
index c1359da0d..c03f481f0 100644
--- a/platform/osx/joystick_osx.cpp
+++ b/platform/osx/joystick_osx.cpp
@@ -271,7 +271,6 @@ void JoystickOSX::_device_removed(int p_id) {
input->joy_connection_changed(p_id, false, "");
device_list[device].free();
device_list.remove(device);
- attached_devices[p_id] = false;
}
static String _hex_str(uint8_t p_byte) {
@@ -303,7 +302,7 @@ bool JoystickOSX::configure_joystick(IOHIDDeviceRef p_device_ref, joystick *p_jo
}
name = c_name;
- int id = get_free_joy_id();
+ int id = input->get_unused_joy_id();
ERR_FAIL_COND_V(id == -1, false);
p_joy->id = id;
int vendor = 0;
@@ -512,16 +511,6 @@ void JoystickOSX::joystick_vibration_stop(int p_id, uint64_t p_timestamp) {
FFEffectStop(joy->ff_object);
}
-int JoystickOSX::get_free_joy_id() {
- for (int i = 0; i < JOYSTICKS_MAX; i++) {
- if (!attached_devices[i]) {
- attached_devices[i] = true;
- return i;
- }
- }
- return -1;
-}
-
int JoystickOSX::get_joy_index(int p_id) const {
for (int i = 0; i < device_list.size(); i++) {
if (device_list[i].id == p_id) return i;
@@ -582,10 +571,6 @@ JoystickOSX::JoystickOSX() {
self = this;
input = (InputDefault *)Input::get_singleton();
- for (int i = 0; i < JOYSTICKS_MAX; i++) {
- attached_devices[i] = false;
- }
-
int okay = 1;
const void *vals[] = {
(void *)create_match_dictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay),
diff --git a/platform/osx/joystick_osx.h b/platform/osx/joystick_osx.h
index 5118a18af..e368fa9f0 100644
--- a/platform/osx/joystick_osx.h
+++ b/platform/osx/joystick_osx.h
@@ -95,13 +95,11 @@ private:
InputDefault *input;
IOHIDManagerRef hid_manager;
- bool attached_devices[JOYSTICKS_MAX];
Vector<joystick> device_list;
bool have_device(IOHIDDeviceRef p_device) const;
bool configure_joystick(IOHIDDeviceRef p_device_ref, joystick *p_joy);
- int get_free_joy_id();
int get_joy_index(int p_id) const;
void poll_joysticks() const;
diff --git a/platform/windows/joystick.cpp b/platform/windows/joystick.cpp
index 71f81f64d..7ccff852c 100644
--- a/platform/windows/joystick.cpp
+++ b/platform/windows/joystick.cpp
@@ -89,16 +89,6 @@ bool joystick_windows::have_device(const GUID &p_guid) {
return false;
}
-int joystick_windows::check_free_joy_slot() const {
-
- for (int i = 0; i < JOYSTICKS_MAX; i++) {
-
- if (!attached_joysticks[i])
- return i;
- }
- return -1;
-}
-
// adapted from SDL2, works a lot better than the MSDN version
bool joystick_windows::is_xinput_device(const GUID *p_guid) {
@@ -147,7 +137,7 @@ bool joystick_windows::is_xinput_device(const GUID *p_guid) {
bool joystick_windows::setup_dinput_joystick(const DIDEVICEINSTANCE *instance) {
HRESULT hr;
- int num = check_free_joy_slot();
+ int num = input->get_unused_joy_id();
if (have_device(instance->guidInstance) || num == -1)
return false;
@@ -295,7 +285,7 @@ void joystick_windows::probe_joysticks() {
dwResult = xinput_get_state(i, &x_joysticks[i].state);
if (dwResult == ERROR_SUCCESS) {
- int id = check_free_joy_slot();
+ int id = input->get_unused_joy_id();
if (id != -1 && !x_joysticks[i].attached) {
x_joysticks[i].attached = true;
diff --git a/platform/windows/joystick.h b/platform/windows/joystick.h
index be36cecab..158001863 100644
--- a/platform/windows/joystick.h
+++ b/platform/windows/joystick.h
@@ -131,7 +131,6 @@ private:
void load_xinput();
void unload_xinput();
- int check_free_joy_slot() const;
unsigned int post_hat(unsigned int p_last_id, int p_device, DWORD p_dpad);
bool have_device(const GUID &p_guid);
diff --git a/platform/x11/joystick_linux.cpp b/platform/x11/joystick_linux.cpp
index 1e2cf2563..049946976 100644
--- a/platform/x11/joystick_linux.cpp
+++ b/platform/x11/joystick_linux.cpp
@@ -219,15 +219,6 @@ void joystick_linux::monitor_joysticks() {
}
}
-int joystick_linux::get_free_joy_slot() const {
-
- for (int i = 0; i < JOYSTICKS_MAX; i++) {
-
- if (joysticks[i].fd == -1) return i;
- }
- return -1;
-}
-
int joystick_linux::get_joy_from_path(String p_path) const {
for (int i = 0; i < JOYSTICKS_MAX; i++) {
@@ -329,7 +320,7 @@ void joystick_linux::setup_joystick_properties(int p_id) {
void joystick_linux::open_joystick(const char *p_path) {
- int joy_num = get_free_joy_slot();
+ int joy_num = input->get_unused_joy_id();
int fd = open(p_path, O_RDWR | O_NONBLOCK);
if (fd != -1 && joy_num != -1) {
diff --git a/platform/x11/joystick_linux.h b/platform/x11/joystick_linux.h
index 4d3f16d1a..6defd93eb 100644
--- a/platform/x11/joystick_linux.h
+++ b/platform/x11/joystick_linux.h
@@ -79,7 +79,6 @@ private:
static void joy_thread_func(void *p_user);
int get_joy_from_path(String path) const;
- int get_free_joy_slot() const;
void setup_joystick_properties(int p_id);
void close_joystick(int p_id = -1);