diff options
Diffstat (limited to 'platform')
| -rw-r--r-- | platform/android/java_glue.cpp | 10 | ||||
| -rw-r--r-- | platform/android/os_android.cpp | 2 | ||||
| -rw-r--r-- | platform/android/os_android.h | 4 | ||||
| -rw-r--r-- | platform/iphone/os_iphone.cpp | 6 | ||||
| -rw-r--r-- | platform/javascript/os_javascript.cpp | 4 | ||||
| -rw-r--r-- | platform/javascript/os_javascript.h | 2 | ||||
| -rw-r--r-- | platform/osx/joystick_osx.cpp | 96 | ||||
| -rw-r--r-- | platform/osx/joystick_osx.h | 36 | ||||
| -rw-r--r-- | platform/osx/os_osx.h | 4 | ||||
| -rw-r--r-- | platform/uwp/joystick_uwp.cpp | 24 | ||||
| -rw-r--r-- | platform/uwp/joystick_uwp.h | 12 | ||||
| -rw-r--r-- | platform/uwp/os_uwp.cpp | 8 | ||||
| -rw-r--r-- | platform/uwp/os_uwp.h | 6 | ||||
| -rw-r--r-- | platform/windows/joystick.cpp | 158 | ||||
| -rw-r--r-- | platform/windows/joystick.h | 38 | ||||
| -rw-r--r-- | platform/windows/os_windows.cpp | 10 | ||||
| -rw-r--r-- | platform/windows/os_windows.h | 4 | ||||
| -rw-r--r-- | platform/x11/joystick_linux.cpp | 104 | ||||
| -rw-r--r-- | platform/x11/joystick_linux.h | 44 | ||||
| -rw-r--r-- | platform/x11/os_x11.cpp | 6 | ||||
| -rw-r--r-- | platform/x11/os_x11.h | 2 |
21 files changed, 290 insertions, 290 deletions
diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp index 6d4794626..3e8ce3591 100644 --- a/platform/android/java_glue.cpp +++ b/platform/android/java_glue.cpp @@ -642,7 +642,7 @@ struct JAndroidPointerEvent { static List<JAndroidPointerEvent> pointer_events; static List<InputEvent> key_events; -static List<OS_Android::JoystickEvent> joy_events; +static List<OS_Android::JoypadEvent> joy_events; static bool initialized=false; static Mutex *input_mutex=NULL; static Mutex *suspend_mutex=NULL; @@ -1090,7 +1090,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv * env, jo while (joy_events.size()) { - OS_Android::JoystickEvent event = joy_events.front()->get(); + OS_Android::JoypadEvent event = joy_events.front()->get(); os_android->process_joy_event(event); joy_events.pop_front(); @@ -1415,7 +1415,7 @@ static unsigned int android_get_keysym(unsigned int p_code) { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv * env, jobject obj, jint p_device, jint p_button, jboolean p_pressed) { - OS_Android::JoystickEvent jevent; + OS_Android::JoypadEvent jevent; jevent.device = p_device; jevent.type = OS_Android::JOY_EVENT_BUTTON; jevent.index = p_button; @@ -1428,7 +1428,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv * en JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv * env, jobject obj, jint p_device, jint p_axis, jfloat p_value) { - OS_Android::JoystickEvent jevent; + OS_Android::JoypadEvent jevent; jevent.device = p_device; jevent.type = OS_Android::JOY_EVENT_AXIS; jevent.index = p_axis; @@ -1440,7 +1440,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv * env, } JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv * env, jobject obj, jint p_device, jint p_hat_x, jint p_hat_y) { - OS_Android::JoystickEvent jevent; + OS_Android::JoypadEvent jevent; jevent.device = p_device; jevent.type = OS_Android::JOY_EVENT_HAT; int hat = 0; diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 093064104..e625c0d7e 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -370,7 +370,7 @@ void OS_Android::main_loop_focusin(){ } -void OS_Android::process_joy_event(OS_Android::JoystickEvent p_event) { +void OS_Android::process_joy_event(OS_Android::JoypadEvent p_event) { switch (p_event.type) { case JOY_EVENT_BUTTON: diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 68b50b208..5e1fc10fd 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -91,7 +91,7 @@ public: JOY_EVENT_HAT = 2 }; - struct JoystickEvent { + struct JoypadEvent { int device; int type; @@ -249,7 +249,7 @@ public: void process_magnetometer(const Vector3& p_magnetometer); void process_gyroscope(const Vector3& p_gyroscope); void process_touch(int p_what,int p_pointer, const Vector<TouchPos>& p_points); - void process_joy_event(JoystickEvent p_event); + void process_joy_event(JoypadEvent p_event); void process_event(InputEvent p_event); void init_video_mode(int p_video_width,int p_video_height); diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index e4d99cc50..1d12501ae 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -331,7 +331,7 @@ void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) { if (p_x != last_accel.x) { //printf("updating accel x %f\n", p_x); InputEvent ev; - ev.type = InputEvent::JOYSTICK_MOTION; + ev.type = InputEvent::JOYPAD_MOTION; ev.device = 0; ev.joy_motion.axis = JOY_ANALOG_0_X; ev.joy_motion.axis_value = (p_x / (float)ACCEL_RANGE); @@ -342,7 +342,7 @@ void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) { if (p_y != last_accel.y) { //printf("updating accel y %f\n", p_y); InputEvent ev; - ev.type = InputEvent::JOYSTICK_MOTION; + ev.type = InputEvent::JOYPAD_MOTION; ev.device = 0; ev.joy_motion.axis = JOY_ANALOG_0_Y; ev.joy_motion.axis_value = (p_y / (float)ACCEL_RANGE); @@ -353,7 +353,7 @@ void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) { if (p_z != last_accel.z) { //printf("updating accel z %f\n", p_z); InputEvent ev; - ev.type = InputEvent::JOYSTICK_MOTION; + ev.type = InputEvent::JOYPAD_MOTION; ev.device = 0; ev.joy_motion.axis = JOY_ANALOG_1_X; ev.joy_motion.axis_value = ( (1.0 - p_z) / (float)ACCEL_RANGE); diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 3553bdc7a..47c8ea89d 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -519,7 +519,7 @@ bool OS_JavaScript::main_loop_iterate() { } - process_joysticks(); + process_joypads(); return Main::iteration(); } @@ -824,7 +824,7 @@ void OS_JavaScript::_close_notification_funcs(const String& p_file,int p_flags) } } -void OS_JavaScript::process_joysticks() { +void OS_JavaScript::process_joypads() { int joy_count = emscripten_get_num_gamepads(); for (int i = 0; i < joy_count; i++) { diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 4cdc88f4f..370322e93 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -93,7 +93,7 @@ private: static void _close_notification_funcs(const String& p_file,int p_flags); - void process_joysticks(); + void process_joypads(); public: diff --git a/platform/osx/joystick_osx.cpp b/platform/osx/joystick_osx.cpp index 740c349fe..18c714e92 100644 --- a/platform/osx/joystick_osx.cpp +++ b/platform/osx/joystick_osx.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* joystick_osx.cpp */ +/* joypad_osx.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -26,14 +26,14 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "joystick_osx.h" +#include "joypad_osx.h" #include <machine/endian.h> -#define GODOT_JOY_LOOP_RUN_MODE CFSTR("GodotJoystick") +#define GODOT_JOY_LOOP_RUN_MODE CFSTR("GodotJoypad") -static JoystickOSX* self = NULL; +static JoypadOSX* self = NULL; -joystick::joystick() { +joypad::joypad() { device_ref = NULL; ff_device = NULL; ff_axes = NULL; @@ -56,7 +56,7 @@ joystick::joystick() { ff_effect.dwSize = sizeof(ff_effect); } -void joystick::free() { +void joypad::free() { if (device_ref) { IOHIDDeviceUnscheduleFromRunLoop(device_ref, CFRunLoopGetCurrent(), GODOT_JOY_LOOP_RUN_MODE); } @@ -68,7 +68,7 @@ void joystick::free() { } } -bool joystick::has_element(IOHIDElementCookie p_cookie, Vector<rec_element> *p_list) const { +bool joypad::has_element(IOHIDElementCookie p_cookie, Vector<rec_element> *p_list) const { for (int i = 0; i < p_list->size(); i++) { if (p_cookie == p_list->get(i).cookie) { return true; @@ -77,7 +77,7 @@ bool joystick::has_element(IOHIDElementCookie p_cookie, Vector<rec_element> *p_l return false; } -int joystick::get_hid_element_state(rec_element *p_element) const { +int joypad::get_hid_element_state(rec_element *p_element) const { int value = 0; if (p_element && p_element->ref) { IOHIDValueRef valueRef; @@ -95,7 +95,7 @@ int joystick::get_hid_element_state(rec_element *p_element) const { } return value; } -void joystick::add_hid_element(IOHIDElementRef p_element) { +void joypad::add_hid_element(IOHIDElementRef p_element) { const CFTypeID elementTypeID = p_element ? CFGetTypeID(p_element) : 0; if (p_element && (elementTypeID == IOHIDElementGetTypeID())) { @@ -198,26 +198,26 @@ void joystick::add_hid_element(IOHIDElementRef p_element) { } static void hid_element_added(const void *p_value, void *p_parameter) { - joystick *joy = (joystick*) p_parameter; + joypad *joy = (joypad*) p_parameter; joy->add_hid_element((IOHIDElementRef) p_value); } -void joystick::add_hid_elements(CFArrayRef p_array) { +void joypad::add_hid_elements(CFArrayRef p_array) { CFRange range = { 0, CFArrayGetCount(p_array) }; CFArrayApplyFunction(p_array, range,hid_element_added,this); } -static void joystick_removed_callback(void *ctx, IOReturn result, void *sender) { +static void joypad_removed_callback(void *ctx, IOReturn result, void *sender) { int id = (intptr_t) ctx; self->_device_removed(id); } -static void joystick_added_callback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject) { +static void joypad_added_callback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject) { self->_device_added(res, ioHIDDeviceObject); } -static bool is_joystick(IOHIDDeviceRef p_device_ref) { +static bool is_joypad(IOHIDDeviceRef p_device_ref) { CFTypeRef refCF = NULL; int usage_page = 0; int usage = 0; @@ -233,7 +233,7 @@ static bool is_joystick(IOHIDDeviceRef p_device_ref) { if (refCF) { CFNumberGetValue((CFNumberRef) refCF, kCFNumberSInt32Type, &usage); } - if ((usage != kHIDUsage_GD_Joystick && + if ((usage != kHIDUsage_GD_Joypad && usage != kHIDUsage_GD_GamePad && usage != kHIDUsage_GD_MultiAxisController)) { return false; @@ -241,32 +241,32 @@ static bool is_joystick(IOHIDDeviceRef p_device_ref) { return true; } -void JoystickOSX::_device_added(IOReturn p_res, IOHIDDeviceRef p_device) { +void JoypadOSX::_device_added(IOReturn p_res, IOHIDDeviceRef p_device) { if (p_res != kIOReturnSuccess || have_device(p_device)) { return; } - joystick new_joystick; - if (is_joystick(p_device)) { - configure_joystick(p_device, &new_joystick); + joypad new_joypad; + if (is_joypad(p_device)) { + configure_joypad(p_device, &new_joypad); #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 if (IOHIDDeviceGetService != NULL) { #endif const io_service_t ioservice = IOHIDDeviceGetService(p_device); - if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK) && new_joystick.config_force_feedback(ioservice)) { - new_joystick.ffservice = ioservice; + if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK) && new_joypad.config_force_feedback(ioservice)) { + new_joypad.ffservice = ioservice; } #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 } #endif - device_list.push_back(new_joystick); + device_list.push_back(new_joypad); } - IOHIDDeviceRegisterRemovalCallback(p_device, joystick_removed_callback, (void*) (intptr_t) new_joystick.id); + IOHIDDeviceRegisterRemovalCallback(p_device, joypad_removed_callback, (void*) (intptr_t) new_joypad.id); IOHIDDeviceScheduleWithRunLoop(p_device, CFRunLoopGetCurrent(), GODOT_JOY_LOOP_RUN_MODE); } -void JoystickOSX::_device_removed(int p_id) { +void JoypadOSX::_device_removed(int p_id) { int device = get_joy_index(p_id); ERR_FAIL_COND(device == -1); @@ -289,7 +289,7 @@ static String _hex_str(uint8_t p_byte) { return ret; } -bool JoystickOSX::configure_joystick(IOHIDDeviceRef p_device_ref, joystick* p_joy) { +bool JoypadOSX::configure_joypad(IOHIDDeviceRef p_device_ref, joypad* p_joy) { CFTypeRef refCF = NULL; @@ -302,7 +302,7 @@ bool JoystickOSX::configure_joystick(IOHIDDeviceRef p_device_ref, joystick* p_jo refCF = IOHIDDeviceGetProperty(p_device_ref, CFSTR(kIOHIDManufacturerKey)); } if ((!refCF) || (!CFStringGetCString((CFStringRef) refCF, c_name, sizeof (c_name), kCFStringEncodingUTF8))) { - name = "Unidentified Joystick"; + name = "Unidentified Joypad"; } name = c_name; @@ -345,7 +345,7 @@ bool JoystickOSX::configure_joystick(IOHIDDeviceRef p_device_ref, joystick* p_jo } #define FF_ERR() { if (ret != FF_OK) { FFReleaseDevice(ff_device); return false; } } -bool joystick::config_force_feedback(io_service_t p_service) { +bool joypad::config_force_feedback(io_service_t p_service) { HRESULT ret = FFCreateDevice(p_service, &ff_device); ERR_FAIL_COND_V(ret != FF_OK, false); @@ -367,7 +367,7 @@ bool joystick::config_force_feedback(io_service_t p_service) { #undef FF_ERR #define TEST_FF(ff) (features.supportedEffects & (ff)) -bool joystick::check_ff_features() { +bool joypad::check_ff_features() { FFCAPABILITIES features; HRESULT ret = FFDeviceGetForceFeedbackCapabilities(ff_device, &features); @@ -432,7 +432,7 @@ static int process_hat_value(int p_min, int p_max, int p_value) { return hat_value; } -void JoystickOSX::poll_joysticks() const { +void JoypadOSX::poll_joypads() const { while (CFRunLoopRunInMode(GODOT_JOY_LOOP_RUN_MODE,0,TRUE) == kCFRunLoopRunHandledSource) { /* no-op. Pending callbacks will fire. */ } @@ -454,11 +454,11 @@ static const InputDefault::JoyAxis axis_correct(int p_value, int p_min, int p_ma return jx; } -uint32_t JoystickOSX::process_joysticks(uint32_t p_last_id){ - poll_joysticks(); +uint32_t JoypadOSX::process_joypads(uint32_t p_last_id){ + poll_joypads(); for (int i = 0; i < device_list.size(); i++) { - joystick &joy = device_list[i]; + joypad &joy = device_list[i]; for (int j = 0; j < joy.axis_elements.size(); j++) { rec_element &elem = joy.axis_elements[j]; @@ -482,11 +482,11 @@ uint32_t JoystickOSX::process_joysticks(uint32_t p_last_id){ Vector2 strength = input->get_joy_vibration_strength(joy.id); float duration = input->get_joy_vibration_duration(joy.id); if (strength.x == 0 && strength.y == 0) { - joystick_vibration_stop(joy.id, timestamp); + joypad_vibration_stop(joy.id, timestamp); } else { float gain = MAX(strength.x, strength.y); - joystick_vibration_start(joy.id, gain, duration, timestamp); + joypad_vibration_start(joy.id, gain, duration, timestamp); } } } @@ -494,8 +494,8 @@ uint32_t JoystickOSX::process_joysticks(uint32_t p_last_id){ return p_last_id; } -void JoystickOSX::joystick_vibration_start(int p_id, float p_magnitude, float p_duration, uint64_t p_timestamp) { - joystick *joy = &device_list[get_joy_index(p_id)]; +void JoypadOSX::joypad_vibration_start(int p_id, float p_magnitude, float p_duration, uint64_t p_timestamp) { + joypad *joy = &device_list[get_joy_index(p_id)]; joy->ff_timestamp = p_timestamp; joy->ff_effect.dwDuration = p_duration * FF_SECONDS; joy->ff_effect.dwGain = p_magnitude * FF_FFNOMINALMAX; @@ -503,14 +503,14 @@ void JoystickOSX::joystick_vibration_start(int p_id, float p_magnitude, float p_ FFEffectStart(joy->ff_object, 1, 0); } -void JoystickOSX::joystick_vibration_stop(int p_id, uint64_t p_timestamp) { - joystick* joy = &device_list[get_joy_index(p_id)]; +void JoypadOSX::joypad_vibration_stop(int p_id, uint64_t p_timestamp) { + joypad* joy = &device_list[get_joy_index(p_id)]; joy->ff_timestamp = p_timestamp; FFEffectStop(joy->ff_object); } -int JoystickOSX::get_free_joy_id() { - for (int i = 0; i < JOYSTICKS_MAX; i++) { +int JoypadOSX::get_free_joy_id() { + for (int i = 0; i < JOYPADS_MAX; i++) { if (!attached_devices[i]) { attached_devices[i] = true; return i; @@ -519,14 +519,14 @@ int JoystickOSX::get_free_joy_id() { return -1; } -int JoystickOSX::get_joy_index(int p_id) const { +int JoypadOSX::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; } return -1; } -bool JoystickOSX::have_device(IOHIDDeviceRef p_device) const { +bool JoypadOSX::have_device(IOHIDDeviceRef p_device) const { for (int i = 0; i < device_list.size(); i++) { if (device_list[i].device_ref == p_device) { return true; @@ -561,14 +561,14 @@ static CFDictionaryRef create_match_dictionary(const UInt32 page, const UInt32 u return retval; } -void JoystickOSX::config_hid_manager(CFArrayRef p_matching_array) const { +void JoypadOSX::config_hid_manager(CFArrayRef p_matching_array) const { CFRunLoopRef runloop = CFRunLoopGetCurrent(); IOReturn ret = IOHIDManagerOpen(hid_manager, kIOHIDOptionsTypeNone); ERR_FAIL_COND(ret != kIOReturnSuccess); IOHIDManagerSetDeviceMatchingMultiple(hid_manager, p_matching_array); - IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, joystick_added_callback, NULL); + IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, joypad_added_callback, NULL); IOHIDManagerScheduleWithRunLoop(hid_manager, runloop, GODOT_JOY_LOOP_RUN_MODE); while (CFRunLoopRunInMode(GODOT_JOY_LOOP_RUN_MODE,0,TRUE) == kCFRunLoopRunHandledSource) { @@ -576,18 +576,18 @@ void JoystickOSX::config_hid_manager(CFArrayRef p_matching_array) const { } } -JoystickOSX::JoystickOSX() +JoypadOSX::JoypadOSX() { self = this; input = (InputDefault*)Input::get_singleton(); - for (int i = 0; i < JOYSTICKS_MAX; i++) { + for (int i = 0; i < JOYPADS_MAX; i++) { attached_devices[i] = false; } int okay = 1; const void *vals[] = { - (void *) create_match_dictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay), + (void *) create_match_dictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joypad, &okay), (void *) create_match_dictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad, &okay), (void *) create_match_dictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_MultiAxisController, &okay), }; @@ -609,7 +609,7 @@ JoystickOSX::JoystickOSX() } } -JoystickOSX::~JoystickOSX() { +JoypadOSX::~JoypadOSX() { for (int i = 0; i < device_list.size(); i++) { device_list[i].free(); diff --git a/platform/osx/joystick_osx.h b/platform/osx/joystick_osx.h index ec745fe5d..aafd82880 100644 --- a/platform/osx/joystick_osx.h +++ b/platform/osx/joystick_osx.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* joystick_osx.h */ +/* joypad_osx.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -26,8 +26,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef JOYSTICKOSX_H -#define JOYSTICKOSX_H +#ifndef JOYPADOSX_H +#define JOYPADOSX_H #ifdef MACOS_10_0_4 #include <IOKit/hidsystem/IOHIDUsageTables.h> @@ -54,7 +54,7 @@ struct rec_element { }; }; -struct joystick { +struct joypad { IOHIDDeviceRef device_ref; Vector<rec_element> axis_elements; @@ -82,44 +82,44 @@ struct joystick { int get_hid_element_state(rec_element *p_element) const; void free(); - joystick(); + joypad(); }; -class JoystickOSX { +class JoypadOSX { enum { - JOYSTICKS_MAX = 16, + JOYPADS_MAX = 16, }; private: InputDefault *input; IOHIDManagerRef hid_manager; - bool attached_devices[JOYSTICKS_MAX]; - Vector<joystick> device_list; + bool attached_devices[JOYPADS_MAX]; + Vector<joypad> device_list; bool have_device(IOHIDDeviceRef p_device) const; - bool configure_joystick(IOHIDDeviceRef p_device_ref, joystick *p_joy); + bool configure_joypad(IOHIDDeviceRef p_device_ref, joypad *p_joy); int get_free_joy_id(); int get_joy_index(int p_id) const; - void poll_joysticks() const; - void setup_joystick_objects(); + void poll_joypads() const; + void setup_joypad_objects(); void config_hid_manager(CFArrayRef p_matching_array) const; - void joystick_vibration_start(int p_id, float p_magnitude, float p_duration, uint64_t p_timestamp); - void joystick_vibration_stop(int p_id, uint64_t p_timestamp); + void joypad_vibration_start(int p_id, float p_magnitude, float p_duration, uint64_t p_timestamp); + void joypad_vibration_stop(int p_id, uint64_t p_timestamp); public: - uint32_t process_joysticks(uint32_t p_last_id); + uint32_t process_joypads(uint32_t p_last_id); void _device_added(IOReturn p_res, IOHIDDeviceRef p_device); void _device_removed(int p_id); - JoystickOSX(); - ~JoystickOSX(); + JoypadOSX(); + ~JoypadOSX(); }; -#endif // JOYSTICKOSX_H +#endif // JOYPADOSX_H diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index a547e318c..fc64c2b86 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -31,7 +31,7 @@ #include "os/input.h" -#include "joystick_osx.h" +#include "joypad_osx.h" #include "drivers/unix/os_unix.h" #include "main/input_default.h" #include "servers/visual_server.h" @@ -78,7 +78,7 @@ public: SpatialSound2DServerSW *spatial_sound_2d_server; InputDefault *input; - JoystickOSX *joystick_osx; + JoypadOSX *joypad_osx; /* objc */ diff --git a/platform/uwp/joystick_uwp.cpp b/platform/uwp/joystick_uwp.cpp index 8ed6473c3..e26b81bb6 100644 --- a/platform/uwp/joystick_uwp.cpp +++ b/platform/uwp/joystick_uwp.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* joystick_uwp.cpp */ +/* joypad_uwp.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,20 +27,20 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "joystick_uwp.h" +#include "joypad_uwp.h" using namespace Windows::Gaming::Input; using namespace Windows::Foundation; -void JoystickUWP::register_events() { +void JoypadUWP::register_events() { Gamepad::GamepadAdded += - ref new EventHandler<Gamepad^>(this, &JoystickUWP::OnGamepadAdded); + ref new EventHandler<Gamepad^>(this, &JoypadUWP::OnGamepadAdded); Gamepad::GamepadRemoved += - ref new EventHandler<Gamepad^>(this, &JoystickUWP::OnGamepadRemoved); + ref new EventHandler<Gamepad^>(this, &JoypadUWP::OnGamepadRemoved); } -uint32_t JoystickUWP::process_controllers(uint32_t p_last_id) { +uint32_t JoypadUWP::process_controllers(uint32_t p_last_id) { for (int i = 0; i < MAX_CONTROLLERS; i++) { @@ -74,20 +74,20 @@ uint32_t JoystickUWP::process_controllers(uint32_t p_last_id) { return p_last_id; } -JoystickUWP::JoystickUWP() { +JoypadUWP::JoypadUWP() { for (int i = 0; i < MAX_CONTROLLERS; i++) controllers[i].id = i; } -JoystickUWP::JoystickUWP(InputDefault * p_input) { +JoypadUWP::JoypadUWP(InputDefault * p_input) { input = p_input; - JoystickUWP(); + JoypadUWP(); } -void JoystickUWP::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { +void JoypadUWP::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { short idx = -1; @@ -109,7 +109,7 @@ void JoystickUWP::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::Inp input->joy_connection_changed(controllers[idx].id, true, "Xbox Controller", "__UWP_GAMEPAD__"); } -void JoystickUWP::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { +void JoypadUWP::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { short idx = -1; @@ -136,7 +136,7 @@ void JoystickUWP::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::I input->joy_connection_changed(idx, false, "Xbox Controller"); } -InputDefault::JoyAxis JoystickUWP::axis_correct(double p_val, bool p_negate, bool p_trigger) const { +InputDefault::JoyAxis JoypadUWP::axis_correct(double p_val, bool p_negate, bool p_trigger) const { InputDefault::JoyAxis jx; diff --git a/platform/uwp/joystick_uwp.h b/platform/uwp/joystick_uwp.h index f854f0b47..7e15e5ddb 100644 --- a/platform/uwp/joystick_uwp.h +++ b/platform/uwp/joystick_uwp.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* joystick_uwp.h */ +/* joypad_uwp.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -26,20 +26,20 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef JOYSTICK_UWP_H -#define JOYSTICK_UWP_H +#ifndef JOYPAD_UWP_H +#define JOYPAD_UWP_H #include "main/input_default.h" -ref class JoystickUWP sealed { +ref class JoypadUWP sealed { internal: void register_events(); uint32_t process_controllers(uint32_t p_last_id); - JoystickUWP(); - JoystickUWP(InputDefault* p_input); + JoypadUWP(); + JoypadUWP(InputDefault* p_input); private: diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 387cfe579..34977bc04 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -285,8 +285,8 @@ void OSUWP::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio input = memnew( InputDefault ); - joystick = ref new JoystickUWP(input); - joystick->register_events(); + joypad = ref new JoypadUWP(input); + joypad->register_events(); AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -429,7 +429,7 @@ void OSUWP::finalize() { physics_2d_server->finish(); memdelete(physics_2d_server); - joystick = nullptr; + joypad = nullptr; } void OSUWP::finalize_core() { @@ -725,7 +725,7 @@ uint64_t OSUWP::get_ticks_usec() const { void OSUWP::process_events() { - last_id = joystick->process_controllers(last_id); + last_id = joypad->process_controllers(last_id); process_key_events(); } diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index c50d34aca..82376dd2f 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -55,7 +55,7 @@ #include <stdio.h> #include "main/input_default.h" -#include "joystick_uwp.h" +#include "joypad_uwp.h" /** @author Juan Linietsky <reduzio@gmail.com> @@ -85,7 +85,7 @@ public: private: enum { - JOYSTICKS_MAX = 8, + JOYPADS_MAX = 8, JOY_AXIS_COUNT = 6, MAX_JOY_AXIS = 32768, // I've no idea KEY_EVENT_BUFFER_SIZE=512 @@ -137,7 +137,7 @@ private: InputDefault *input; - JoystickUWP^ joystick; + JoypadUWP^ joypad; Windows::System::Display::DisplayRequest^ display_request; diff --git a/platform/windows/joystick.cpp b/platform/windows/joystick.cpp index 3fdf20a47..932403114 100644 --- a/platform/windows/joystick.cpp +++ b/platform/windows/joystick.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* joystick.cpp */ +/* joypad.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ //author: Andreas Haas <hondres, liugam3@gmail.com> -#include "joystick.h" +#include "joypad.h" #include <iostream> #include <wbemidl.h> #include <oleauto.h> @@ -39,15 +39,15 @@ DWORD WINAPI _xinput_get_state(DWORD dwUserIndex, XINPUT_STATE* pState) { return ERROR_DEVICE_NOT_CONNECTED; } DWORD WINAPI _xinput_set_state(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration) { return ERROR_DEVICE_NOT_CONNECTED; } -joystick_windows::joystick_windows() { +joypad_windows::joypad_windows() { } -joystick_windows::joystick_windows(InputDefault* _input, HWND* hwnd) { +joypad_windows::joypad_windows(InputDefault* _input, HWND* hwnd) { input = _input; hWnd = hwnd; - joystick_count = 0; + joypad_count = 0; dinput = NULL; xinput_dll = NULL; xinput_get_state = NULL; @@ -55,8 +55,8 @@ joystick_windows::joystick_windows(InputDefault* _input, HWND* hwnd) { load_xinput(); - for (int i = 0; i < JOYSTICKS_MAX; i++) - attached_joysticks[i] = false; + for (int i = 0; i < JOYPADS_MAX; i++) + attached_joypads[i] = false; HRESULT result; @@ -64,35 +64,35 @@ joystick_windows::joystick_windows(InputDefault* _input, HWND* hwnd) { if (FAILED(result)) { printf("failed init DINPUT: %ld\n", result); } - probe_joysticks(); + probe_joypads(); } -joystick_windows::~joystick_windows() { +joypad_windows::~joypad_windows() { - close_joystick(); + close_joypad(); dinput->Release(); unload_xinput(); } -bool joystick_windows::have_device(const GUID &p_guid) { +bool joypad_windows::have_device(const GUID &p_guid) { - for (int i = 0; i < JOYSTICKS_MAX; i++) { + for (int i = 0; i < JOYPADS_MAX; i++) { - if (d_joysticks[i].guid == p_guid) { + if (d_joypads[i].guid == p_guid) { - d_joysticks[i].confirmed = true; + d_joypads[i].confirmed = true; return true; } } return false; } -int joystick_windows::check_free_joy_slot() const { +int joypad_windows::check_free_joy_slot() const { - for (int i = 0; i < JOYSTICKS_MAX; i++) { + for (int i = 0; i < JOYPADS_MAX; i++) { - if (!attached_joysticks[i]) + if (!attached_joypads[i]) return i; } return -1; @@ -100,7 +100,7 @@ int joystick_windows::check_free_joy_slot() const { // adapted from SDL2, works a lot better than the MSDN version -bool joystick_windows::is_xinput_device(const GUID *p_guid) { +bool joypad_windows::is_xinput_device(const GUID *p_guid) { static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; @@ -144,7 +144,7 @@ bool joystick_windows::is_xinput_device(const GUID *p_guid) { return false; } -bool joystick_windows::setup_dinput_joystick(const DIDEVICEINSTANCE* instance) { +bool joypad_windows::setup_dinput_joypad(const DIDEVICEINSTANCE* instance) { HRESULT hr; int num = check_free_joy_slot(); @@ -152,12 +152,12 @@ bool joystick_windows::setup_dinput_joystick(const DIDEVICEINSTANCE* instance) { if (have_device(instance->guidInstance) || num == -1) return false; - d_joysticks[joystick_count] = dinput_gamepad(); - dinput_gamepad* joy = &d_joysticks[joystick_count]; + d_joypads[joypad_count] = dinput_gamepad(); + dinput_gamepad* joy = &d_joypads[joypad_count]; const DWORD devtype = (instance->dwDevType & 0xFF); - if ((devtype != DI8DEVTYPE_JOYSTICK) && (devtype != DI8DEVTYPE_GAMEPAD) && (devtype != DI8DEVTYPE_1STPERSON)) { + if ((devtype != DI8DEVTYPE_JOYPAD) && (devtype != DI8DEVTYPE_GAMEPAD) && (devtype != DI8DEVTYPE_1STPERSON)) { //printf("ignore device %s, type %x\n", instance->tszProductName, devtype); return false; } @@ -177,9 +177,9 @@ bool joystick_windows::setup_dinput_joystick(const DIDEVICEINSTANCE* instance) { guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); - id_to_change = joystick_count; + id_to_change = joypad_count; - joy->di_joy->SetDataFormat(&c_dfDIJoystick2); + joy->di_joy->SetDataFormat(&c_dfDIJoypad2); joy->di_joy->SetCooperativeLevel(*hWnd, DISCL_FOREGROUND); joy->di_joy->EnumObjects(objectsCallback, this, NULL); joy->joy_axis.sort(); @@ -188,13 +188,13 @@ bool joystick_windows::setup_dinput_joystick(const DIDEVICEINSTANCE* instance) { input->joy_connection_changed(num, true, instance->tszProductName, uid); joy->attached = true; joy->id = num; - attached_joysticks[num] = true; + attached_joypads[num] = true; joy->confirmed = true; - joystick_count++; + joypad_count++; return true; } -void joystick_windows::setup_joystick_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id) { +void joypad_windows::setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id) { if (ob->dwType & DIDFT_AXIS) { @@ -225,7 +225,7 @@ void joystick_windows::setup_joystick_object(const DIDEVICEOBJECTINSTANCE *ob, i prop_range.lMin = -MAX_JOY_AXIS; prop_range.lMax = +MAX_JOY_AXIS; - dinput_gamepad &joy = d_joysticks[p_joy_id]; + dinput_gamepad &joy = d_joypads[p_joy_id]; res = IDirectInputDevice8_SetProperty(joy.di_joy, DIPROP_RANGE, &prop_range.diph); @@ -246,100 +246,100 @@ void joystick_windows::setup_joystick_object(const DIDEVICEOBJECTINSTANCE *ob, i } } -BOOL CALLBACK joystick_windows::enumCallback(const DIDEVICEINSTANCE* instance, void* pContext) { +BOOL CALLBACK joypad_windows::enumCallback(const DIDEVICEINSTANCE* instance, void* pContext) { - joystick_windows* self = (joystick_windows*)pContext; + joypad_windows* self = (joypad_windows*)pContext; if (self->is_xinput_device(&instance->guidProduct)) {; return DIENUM_CONTINUE; } - self->setup_dinput_joystick(instance); + self->setup_dinput_joypad(instance); return DIENUM_CONTINUE; } -BOOL CALLBACK joystick_windows::objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context) { +BOOL CALLBACK joypad_windows::objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context) { - joystick_windows* self = (joystick_windows*)context; - self->setup_joystick_object(instance, self->id_to_change); + joypad_windows* self = (joypad_windows*)context; + self->setup_joypad_object(instance, self->id_to_change); return DIENUM_CONTINUE; } -void joystick_windows::close_joystick(int id) { +void joypad_windows::close_joypad(int id) { if (id == -1) { - for (int i = 0; i < JOYSTICKS_MAX; i++) { + for (int i = 0; i < JOYPADS_MAX; i++) { - close_joystick(i); + close_joypad(i); } return; } - if (!d_joysticks[id].attached) return; + if (!d_joypads[id].attached) return; - d_joysticks[id].di_joy->Unacquire(); - d_joysticks[id].di_joy->Release(); - d_joysticks[id].attached = false; - attached_joysticks[d_joysticks[id].id] = false; - d_joysticks[id].guid.Data1 = d_joysticks[id].guid.Data2 = d_joysticks[id].guid.Data3 = 0; - input->joy_connection_changed(d_joysticks[id].id, false, ""); - joystick_count--; + d_joypads[id].di_joy->Unacquire(); + d_joypads[id].di_joy->Release(); + d_joypads[id].attached = false; + attached_joypads[d_joypads[id].id] = false; + d_joypads[id].guid.Data1 = d_joypads[id].guid.Data2 = d_joypads[id].guid.Data3 = 0; + input->joy_connection_changed(d_joypads[id].id, false, ""); + joypad_count--; } -void joystick_windows::probe_joysticks() { +void joypad_windows::probe_joypads() { DWORD dwResult; for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) { - ZeroMemory(&x_joysticks[i].state, sizeof(XINPUT_STATE)); + ZeroMemory(&x_joypads[i].state, sizeof(XINPUT_STATE)); - dwResult = xinput_get_state(i, &x_joysticks[i].state); + dwResult = xinput_get_state(i, &x_joypads[i].state); if ( dwResult == ERROR_SUCCESS) { int id = check_free_joy_slot(); - if (id != -1 && !x_joysticks[i].attached) { + if (id != -1 && !x_joypads[i].attached) { - x_joysticks[i].attached = true; - x_joysticks[i].id = id; - x_joysticks[i].ff_timestamp = 0; - x_joysticks[i].ff_end_timestamp = 0; - x_joysticks[i].vibrating = false; - attached_joysticks[id] = true; + x_joypads[i].attached = true; + x_joypads[i].id = id; + x_joypads[i].ff_timestamp = 0; + x_joypads[i].ff_end_timestamp = 0; + x_joypads[i].vibrating = false; + attached_joypads[id] = true; input->joy_connection_changed(id, true, "XInput Gamepad","__XINPUT_DEVICE__"); } } - else if (x_joysticks[i].attached) { + else if (x_joypads[i].attached) { - x_joysticks[i].attached = false; - attached_joysticks[x_joysticks[i].id] = false; - input->joy_connection_changed(x_joysticks[i].id, false, ""); + x_joypads[i].attached = false; + attached_joypads[x_joypads[i].id] = false; + input->joy_connection_changed(x_joypads[i].id, false, ""); } } - for (int i = 0; i < joystick_count; i++) { + for (int i = 0; i < joypad_count; i++) { - d_joysticks[i].confirmed = false; + d_joypads[i].confirmed = false; } dinput->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, this, DIEDFL_ATTACHEDONLY); - for (int i = 0; i < joystick_count; i++) { + for (int i = 0; i < joypad_count; i++) { - if (!d_joysticks[i].confirmed) { + if (!d_joypads[i].confirmed) { - close_joystick(i); + close_joypad(i); } } } -unsigned int joystick_windows::process_joysticks(unsigned int p_last_id) { +unsigned int joypad_windows::process_joypads(unsigned int p_last_id) { HRESULT hr; for (int i = 0; i < XUSER_MAX_COUNT; i++) { - xinput_gamepad &joy = x_joysticks[i]; + xinput_gamepad &joy = x_joypads[i]; if (!joy.attached) { continue; } @@ -368,20 +368,20 @@ unsigned int joystick_windows::process_joysticks(unsigned int p_last_id) { Vector2 strength = input->get_joy_vibration_strength(joy.id); float duration = input->get_joy_vibration_duration(joy.id); if (strength.x == 0 && strength.y == 0) { - joystick_vibration_stop_xinput(i, timestamp); + joypad_vibration_stop_xinput(i, timestamp); } else { - joystick_vibration_start_xinput(i, strength.x, strength.y, duration, timestamp); + joypad_vibration_start_xinput(i, strength.x, strength.y, duration, timestamp); } } else if (joy.vibrating && joy.ff_end_timestamp != 0) { uint64_t current_time = OS::get_singleton()->get_ticks_usec(); if (current_time >= joy.ff_end_timestamp) - joystick_vibration_stop_xinput(i, current_time); + joypad_vibration_stop_xinput(i, current_time); } } - for (int i = 0; i < JOYSTICKS_MAX; i++) { + for (int i = 0; i < JOYPADS_MAX; i++) { - dinput_gamepad* joy = &d_joysticks[i]; + dinput_gamepad* joy = &d_joypads[i]; if (!joy->attached) continue; @@ -438,7 +438,7 @@ unsigned int joystick_windows::process_joysticks(unsigned int p_last_id) { return p_last_id; } -unsigned int joystick_windows::post_hat(unsigned int p_last_id, int p_device, DWORD p_dpad) { +unsigned int joypad_windows::post_hat(unsigned int p_last_id, int p_device, DWORD p_dpad) { int dpad_val = 0; @@ -487,7 +487,7 @@ unsigned int joystick_windows::post_hat(unsigned int p_last_id, int p_device, DW return input->joy_hat(p_last_id, p_device, dpad_val); }; -InputDefault::JoyAxis joystick_windows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const { +InputDefault::JoyAxis joypad_windows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const { InputDefault::JoyAxis jx; if (Math::abs(p_val) < MIN_JOY_AXIS) { @@ -519,8 +519,8 @@ InputDefault::JoyAxis joystick_windows::axis_correct(int p_val, bool p_xinput, b return jx; } -void joystick_windows::joystick_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) { - xinput_gamepad &joy = x_joysticks[p_device]; +void joypad_windows::joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) { + xinput_gamepad &joy = x_joypads[p_device]; if (joy.attached) { XINPUT_VIBRATION effect; effect.wLeftMotorSpeed = (65535 * p_strong_magnitude); @@ -533,8 +533,8 @@ void joystick_windows::joystick_vibration_start_xinput(int p_device, float p_wea } } -void joystick_windows::joystick_vibration_stop_xinput(int p_device, uint64_t p_timestamp) { - xinput_gamepad &joy = x_joysticks[p_device]; +void joypad_windows::joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp) { + xinput_gamepad &joy = x_joypads[p_device]; if (joy.attached) { XINPUT_VIBRATION effect; effect.wLeftMotorSpeed = 0; @@ -547,7 +547,7 @@ void joystick_windows::joystick_vibration_stop_xinput(int p_device, uint64_t p_t } -void joystick_windows::load_xinput() { +void joypad_windows::load_xinput() { xinput_get_state = &_xinput_get_state; xinput_set_state = &_xinput_set_state; @@ -576,7 +576,7 @@ void joystick_windows::load_xinput() { xinput_set_state = set_func; } -void joystick_windows::unload_xinput() { +void joypad_windows::unload_xinput() { if (xinput_dll) { diff --git a/platform/windows/joystick.h b/platform/windows/joystick.h index 6de05bf10..8875e6d0c 100644 --- a/platform/windows/joystick.h +++ b/platform/windows/joystick.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* joystick.h */ +/* joypad.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,8 +27,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ //author: Andreas Haas <hondres, liugam3@gmail.com> -#ifndef JOYSTICK_H -#define JOYSTICK_H +#ifndef JOYPAD_H +#define JOYPAD_H #include "os_windows.h" #define DIRECTINPUT_VERSION 0x0800 @@ -48,19 +48,19 @@ if(x != NULL) \ #define XUSER_MAX_COUNT 4 #endif -class joystick_windows +class joypad_windows { public: - joystick_windows(); - joystick_windows(InputDefault* _input, HWND* hwnd); - ~joystick_windows(); + joypad_windows(); + joypad_windows(InputDefault* _input, HWND* hwnd); + ~joypad_windows(); - void probe_joysticks(); - unsigned int process_joysticks(unsigned int p_last_id); + void probe_joypads(); + unsigned int process_joypads(unsigned int p_last_id); private: enum { - JOYSTICKS_MAX = 16, + JOYPADS_MAX = 16, JOY_AXIS_COUNT = 6, MIN_JOY_AXIS = 10, MAX_JOY_AXIS = 32768, @@ -120,16 +120,16 @@ private: InputDefault* input; int id_to_change; - int joystick_count; - bool attached_joysticks[JOYSTICKS_MAX]; - dinput_gamepad d_joysticks[JOYSTICKS_MAX]; - xinput_gamepad x_joysticks[XUSER_MAX_COUNT]; + int joypad_count; + bool attached_joypads[JOYPADS_MAX]; + dinput_gamepad d_joypads[JOYPADS_MAX]; + xinput_gamepad x_joypads[XUSER_MAX_COUNT]; static BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* p_instance, void* p_context); static BOOL CALLBACK objectsCallback(const DIDEVICEOBJECTINSTANCE* instance, void* context); - void setup_joystick_object(const DIDEVICEOBJECTINSTANCE* ob, int p_joy_id); - void close_joystick(int id = -1); + void setup_joypad_object(const DIDEVICEOBJECTINSTANCE* ob, int p_joy_id); + void close_joypad(int id = -1); void load_xinput(); void unload_xinput(); @@ -138,9 +138,9 @@ private: bool have_device(const GUID &p_guid); bool is_xinput_device(const GUID* p_guid); - bool setup_dinput_joystick(const DIDEVICEINSTANCE* instance); - void joystick_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); - void joystick_vibration_stop_xinput(int p_device, uint64_t p_timestamp); + bool setup_dinput_joypad(const DIDEVICEINSTANCE* instance); + void joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); + void joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp); InputDefault::JoyAxis axis_correct(int p_val, bool p_xinput = false, bool p_trigger = false, bool p_negate = false) const; XInputGetState_t xinput_get_state; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 34ea9cd15..28e55b531 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -51,7 +51,7 @@ #include "globals.h" #include "io/marshalls.h" -#include "joystick.h" +#include "joypad.h" #include "shlobj.h" #include <regstr.h> @@ -714,7 +714,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { #endif case WM_DEVICECHANGE: { - joystick->probe_joysticks(); + joypad->probe_joypads(); } break; case WM_SETCURSOR: { @@ -1120,7 +1120,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ visual_server->init(); input = memnew( InputDefault ); - joystick = memnew (joystick_windows(input, &hWnd)); + joypad = memnew (joypad_windows(input, &hWnd)); AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -1253,7 +1253,7 @@ void OS_Windows::finalize() { main_loop=NULL; - memdelete(joystick); + memdelete(joypad); memdelete(input); visual_server->finish(); @@ -1928,7 +1928,7 @@ void OS_Windows::process_events() { MSG msg; - last_id = joystick->process_joysticks(last_id); + last_id = joypad->process_joypads(last_id); while(PeekMessageW(&msg,NULL,0,0,PM_REMOVE)) { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index e265313f0..cfc5546ae 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -61,7 +61,7 @@ /** @author Juan Linietsky <reduzio@gmail.com> */ -class joystick_windows; +class joypad_windows; class OS_Windows : public OS { enum { @@ -133,7 +133,7 @@ class OS_Windows : public OS { CursorShape cursor_shape; InputDefault *input; - joystick_windows *joystick; + joypad_windows *joypad; #ifdef RTAUDIO_ENABLED AudioDriverRtAudio driver_rtaudio; diff --git a/platform/x11/joystick_linux.cpp b/platform/x11/joystick_linux.cpp index d101a725a..bef2ef3fc 100644 --- a/platform/x11/joystick_linux.cpp +++ b/platform/x11/joystick_linux.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* joystick_linux.cpp */ +/* joypad_linux.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -49,7 +49,7 @@ static const char* ignore_str = "/dev/input/js"; #endif -joystick_linux::Joystick::Joystick() { +joypad_linux::Joypad::Joypad() { fd = -1; dpad = 0; devpath = ""; @@ -58,7 +58,7 @@ joystick_linux::Joystick::Joystick() { } } -joystick_linux::Joystick::~Joystick() { +joypad_linux::Joypad::~Joypad() { for (int i = 0; i < MAX_ABS; i++) { if (abs_info[i]) { @@ -67,7 +67,7 @@ joystick_linux::Joystick::~Joystick() { } } -void joystick_linux::Joystick::reset() { +void joypad_linux::Joypad::reset() { dpad = 0; fd = -1; @@ -80,7 +80,7 @@ void joystick_linux::Joystick::reset() { } } -joystick_linux::joystick_linux(InputDefault *in) +joypad_linux::joypad_linux(InputDefault *in) { exit_udev = false; input = in; @@ -88,37 +88,37 @@ joystick_linux::joystick_linux(InputDefault *in) joy_thread = Thread::create(joy_thread_func, this); } -joystick_linux::~joystick_linux() { +joypad_linux::~joypad_linux() { exit_udev = true; Thread::wait_to_finish(joy_thread); memdelete(joy_thread); memdelete(joy_mutex); - close_joystick(); + close_joypad(); } -void joystick_linux::joy_thread_func(void *p_user) { +void joypad_linux::joy_thread_func(void *p_user) { if (p_user) { - joystick_linux* joy = (joystick_linux*) p_user; - joy->run_joystick_thread(); + joypad_linux* joy = (joypad_linux*) p_user; + joy->run_joypad_thread(); } return; } -void joystick_linux::run_joystick_thread() { +void joypad_linux::run_joypad_thread() { #ifdef UDEV_ENABLED udev *_udev = udev_new(); ERR_FAIL_COND(!_udev); - enumerate_joysticks(_udev); - monitor_joysticks(_udev); + enumerate_joypads(_udev); + monitor_joypads(_udev); udev_unref(_udev); #else - monitor_joysticks(); + monitor_joypads(); #endif } #ifdef UDEV_ENABLED -void joystick_linux::enumerate_joysticks(udev *p_udev) { +void joypad_linux::enumerate_joypads(udev *p_udev) { udev_enumerate *enumerate; udev_list_entry *devices, *dev_list_entry; @@ -126,7 +126,7 @@ void joystick_linux::enumerate_joysticks(udev *p_udev) { enumerate = udev_enumerate_new(p_udev); udev_enumerate_add_match_subsystem(enumerate,"input"); - udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1"); + udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYPAD", "1"); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); @@ -141,7 +141,7 @@ void joystick_linux::enumerate_joysticks(udev *p_udev) { String devnode_str = devnode; if (devnode_str.find(ignore_str) == -1) { joy_mutex->lock(); - open_joystick(devnode); + open_joypad(devnode); joy_mutex->unlock(); } } @@ -150,7 +150,7 @@ void joystick_linux::enumerate_joysticks(udev *p_udev) { udev_enumerate_unref(enumerate); } -void joystick_linux::monitor_joysticks(udev *p_udev) { +void joypad_linux::monitor_joypads(udev *p_udev) { udev_device *dev = NULL; udev_monitor *mon = udev_monitor_new_from_netlink(p_udev, "udev"); @@ -188,9 +188,9 @@ void joystick_linux::monitor_joysticks(udev *p_udev) { if (devnode_str.find(ignore_str) == -1) { if (action == "add") - open_joystick(devnode); + open_joypad(devnode); else if (String(action) == "remove") - close_joystick(get_joy_from_path(devnode)); + close_joypad(get_joy_from_path(devnode)); } } @@ -204,7 +204,7 @@ void joystick_linux::monitor_joysticks(udev *p_udev) { } #endif -void joystick_linux::monitor_joysticks() { +void joypad_linux::monitor_joypads() { while (!exit_udev) { joy_mutex->lock(); @@ -212,7 +212,7 @@ void joystick_linux::monitor_joysticks() { char fname[64]; sprintf(fname, "/dev/input/event%d", i); if (attached_devices.find(fname) == -1) { - open_joystick(fname); + open_joypad(fname); } } joy_mutex->unlock(); @@ -220,37 +220,37 @@ void joystick_linux::monitor_joysticks() { } } -int joystick_linux::get_free_joy_slot() const { +int joypad_linux::get_free_joy_slot() const { - for (int i = 0; i < JOYSTICKS_MAX; i++) { + for (int i = 0; i < JOYPADS_MAX; i++) { - if (joysticks[i].fd == -1) return i; + if (joypads[i].fd == -1) return i; } return -1; } -int joystick_linux::get_joy_from_path(String p_path) const { +int joypad_linux::get_joy_from_path(String p_path) const { - for (int i = 0; i < JOYSTICKS_MAX; i++) { + for (int i = 0; i < JOYPADS_MAX; i++) { - if (joysticks[i].devpath == p_path) { + if (joypads[i].devpath == p_path) { return i; } } return -2; } -void joystick_linux::close_joystick(int p_id) { +void joypad_linux::close_joypad(int p_id) { if (p_id == -1) { - for (int i=0; i<JOYSTICKS_MAX; i++) { + for (int i=0; i<JOYPADS_MAX; i++) { - close_joystick(i); + close_joypad(i); }; return; } else if (p_id < 0) return; - Joystick &joy = joysticks[p_id]; + Joypad &joy = joypads[p_id]; if (joy.fd != -1) { @@ -273,9 +273,9 @@ static String _hex_str(uint8_t p_byte) { return ret; } -void joystick_linux::setup_joystick_properties(int p_id) { +void joypad_linux::setup_joypad_properties(int p_id) { - Joystick* joy = &joysticks[p_id]; + Joypad* joy = &joypads[p_id]; unsigned long keybit[NBITS(KEY_MAX)] = { 0 }; unsigned long absbit[NBITS(ABS_MAX)] = { 0 }; @@ -328,7 +328,7 @@ void joystick_linux::setup_joystick_properties(int p_id) { } } -void joystick_linux::open_joystick(const char *p_path) { +void joypad_linux::open_joypad(const char *p_path) { int joy_num = get_free_joy_slot(); int fd = open(p_path, O_RDWR | O_NONBLOCK); @@ -349,7 +349,7 @@ void joystick_linux::open_joystick(const char *p_path) { } //check if the device supports basic gamepad events, prevents certain keyboards from - //being detected as joysticks + //being detected as joypads if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) && (test_bit(ABS_X, absbit) || test_bit(ABS_Y, absbit) || test_bit(ABS_HAT0X, absbit) || test_bit(ABS_GAS, absbit) || test_bit(ABS_RUDDER, absbit)) && @@ -372,12 +372,12 @@ void joystick_linux::open_joystick(const char *p_path) { return; } - joysticks[joy_num].reset(); + joypads[joy_num].reset(); - Joystick &joy = joysticks[joy_num]; + Joypad &joy = joypads[joy_num]; joy.fd = fd; joy.devpath = String(p_path); - setup_joystick_properties(joy_num); + setup_joypad_properties(joy_num); sprintf(uid, "%04x%04x", __bswap_16(inpid.bustype), 0); if (inpid.vendor && inpid.product && inpid.version) { @@ -401,14 +401,14 @@ void joystick_linux::open_joystick(const char *p_path) { } } -void joystick_linux::joystick_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) +void joypad_linux::joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) { - Joystick& joy = joysticks[p_id]; + Joypad& joy = joypads[p_id]; if (!joy.force_feedback || joy.fd == -1 || p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) { return; } if (joy.ff_effect_id != -1) { - joystick_vibration_stop(p_id, p_timestamp); + joypad_vibration_stop(p_id, p_timestamp); } struct ff_effect effect; @@ -433,9 +433,9 @@ void joystick_linux::joystick_vibration_start(int p_id, float p_weak_magnitude, joy.ff_effect_timestamp = p_timestamp; } -void joystick_linux::joystick_vibration_stop(int p_id, uint64_t p_timestamp) +void joypad_linux::joypad_vibration_stop(int p_id, uint64_t p_timestamp) { - Joystick& joy = joysticks[p_id]; + Joypad& joy = joypads[p_id]; if (!joy.force_feedback || joy.fd == -1 || joy.ff_effect_id == -1) { return; } @@ -448,7 +448,7 @@ void joystick_linux::joystick_vibration_stop(int p_id, uint64_t p_timestamp) joy.ff_effect_timestamp = p_timestamp; } -InputDefault::JoyAxis joystick_linux::axis_correct(const input_absinfo *p_abs, int p_value) const { +InputDefault::JoyAxis joypad_linux::axis_correct(const input_absinfo *p_abs, int p_value) const { int min = p_abs->minimum; int max = p_abs->maximum; @@ -468,17 +468,17 @@ InputDefault::JoyAxis joystick_linux::axis_correct(const input_absinfo *p_abs, i return jx; } -uint32_t joystick_linux::process_joysticks(uint32_t p_event_id) { +uint32_t joypad_linux::process_joypads(uint32_t p_event_id) { if (joy_mutex->try_lock() != OK) { return p_event_id; } - for (int i=0; i<JOYSTICKS_MAX; i++) { + for (int i=0; i<JOYPADS_MAX; i++) { - if (joysticks[i].fd == -1) continue; + if (joypads[i].fd == -1) continue; input_event events[32]; - Joystick* joy = &joysticks[i]; + Joypad* joy = &joypads[i]; int len; @@ -539,7 +539,7 @@ uint32_t joystick_linux::process_joysticks(uint32_t p_event_id) { } } if (len == 0 || (len < 0 && errno != EAGAIN)) { - close_joystick(i); + close_joypad(i); }; if (joy->force_feedback) { @@ -548,9 +548,9 @@ uint32_t joystick_linux::process_joysticks(uint32_t p_event_id) { Vector2 strength = input->get_joy_vibration_strength(i); float duration = input->get_joy_vibration_duration(i); if (strength.x == 0 && strength.y == 0) { - joystick_vibration_stop(i, timestamp); + joypad_vibration_stop(i, timestamp); } else { - joystick_vibration_start(i, strength.x, strength.y, duration, timestamp); + joypad_vibration_start(i, strength.x, strength.y, duration, timestamp); } } } diff --git a/platform/x11/joystick_linux.h b/platform/x11/joystick_linux.h index 34e7001ca..ebd1e8210 100644 --- a/platform/x11/joystick_linux.h +++ b/platform/x11/joystick_linux.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* joystick_linux.h */ +/* joypad_linux.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,8 +28,8 @@ /*************************************************************************/ //author: Andreas Haas <hondres, liugam3@gmail.com> -#ifndef JOYSTICK_LINUX_H -#define JOYSTICK_LINUX_H +#ifndef JOYPAD_LINUX_H +#define JOYPAD_LINUX_H #ifdef JOYDEV_ENABLED #include "main/input_default.h" #include "os/thread.h" @@ -37,21 +37,21 @@ struct input_absinfo; -class joystick_linux +class joypad_linux { public: - joystick_linux(InputDefault *in); - ~joystick_linux(); - uint32_t process_joysticks(uint32_t p_event_id); + joypad_linux(InputDefault *in); + ~joypad_linux(); + uint32_t process_joypads(uint32_t p_event_id); private: enum { - JOYSTICKS_MAX = 16, + JOYPADS_MAX = 16, MAX_ABS = 63, MAX_KEY = 767, // Hack because <linux/input.h> can't be included here }; - struct Joystick { + struct Joypad { InputDefault::JoyAxis curr_axis[MAX_ABS]; int key_map[MAX_KEY]; int abs_map[MAX_ABS]; @@ -65,8 +65,8 @@ private: int ff_effect_id; uint64_t ff_effect_timestamp; - Joystick(); - ~Joystick(); + Joypad(); + ~Joypad(); void reset(); }; @@ -74,7 +74,7 @@ private: Mutex *joy_mutex; Thread *joy_thread; InputDefault *input; - Joystick joysticks[JOYSTICKS_MAX]; + Joypad joypads[JOYPADS_MAX]; Vector<String> attached_devices; static void joy_thread_func(void *p_user); @@ -82,21 +82,21 @@ private: 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); + void setup_joypad_properties(int p_id); + void close_joypad(int p_id = -1); #ifdef UDEV_ENABLED - void enumerate_joysticks(struct udev *_udev); - void monitor_joysticks(struct udev *_udev); + void enumerate_joypads(struct udev *_udev); + void monitor_joypads(struct udev *_udev); #endif - void monitor_joysticks(); - void run_joystick_thread(); - void open_joystick(const char* path); + void monitor_joypads(); + void run_joypad_thread(); + void open_joypad(const char* path); - void joystick_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); - void joystick_vibration_stop(int p_id, uint64_t p_timestamp); + void joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); + void joypad_vibration_stop(int p_id, uint64_t p_timestamp); InputDefault::JoyAxis axis_correct(const input_absinfo *abs, int value) const; }; #endif -#endif // JOYSTICK_LINUX_H +#endif // JOYPAD_LINUX_H diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index e560b46d4..d1c9c866c 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -458,7 +458,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi input = memnew( InputDefault ); #ifdef JOYDEV_ENABLED - joystick = memnew( joystick_linux(input)); + joypad = memnew( joypad_linux(input)); #endif _ensure_data_dir(); } @@ -479,7 +479,7 @@ void OS_X11::finalize() { //} #ifdef JOYDEV_ENABLED - memdelete(joystick); + memdelete(joypad); #endif memdelete(input); @@ -1932,7 +1932,7 @@ void OS_X11::run() { process_xevents(); // get rid of pending events #ifdef JOYDEV_ENABLED - event_id = joystick->process_joysticks(event_id); + event_id = joypad->process_joypads(event_id); #endif if (Main::iteration()==true) break; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index b89921fb3..4f9ff7129 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -155,7 +155,7 @@ class OS_X11 : public OS_Unix { InputDefault *input; #ifdef JOYDEV_ENABLED - joystick_linux *joystick; + joypad_linux *joypad; #endif #ifdef RTAUDIO_ENABLED |
