1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-16 14:00:40 +00:00

Bring that Whole New World to the Old Continent too

Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6.
This commit is contained in:
Rémi Verschelde
2017-03-19 00:36:26 +01:00
parent 1d418afe86
commit f8db8a3faa
1308 changed files with 147754 additions and 174357 deletions

View File

@@ -32,21 +32,21 @@
#include "joystick_linux.h"
#include <errno.h>
#include <fcntl.h>
#include <linux/input.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#ifdef UDEV_ENABLED
#include <libudev.h>
#endif
#define LONG_BITS (sizeof(long) * 8)
#define test_bit(nr, addr) (((1UL << ((nr) % LONG_BITS)) & ((addr)[(nr) / LONG_BITS])) != 0)
#define NBITS(x) ((((x)-1)/LONG_BITS)+1)
#define LONG_BITS (sizeof(long) * 8)
#define test_bit(nr, addr) (((1UL << ((nr) % LONG_BITS)) & ((addr)[(nr) / LONG_BITS])) != 0)
#define NBITS(x) ((((x)-1) / LONG_BITS) + 1)
#ifdef UDEV_ENABLED
static const char* ignore_str = "/dev/input/js";
static const char *ignore_str = "/dev/input/js";
#endif
joystick_linux::Joystick::Joystick() {
@@ -68,20 +68,19 @@ joystick_linux::Joystick::~Joystick() {
}
void joystick_linux::Joystick::reset() {
dpad = 0;
fd = -1;
dpad = 0;
fd = -1;
InputDefault::JoyAxis jx;
jx.min = -1;
jx.value = 0.0f;
for (int i=0; i < MAX_ABS; i++) {
for (int i = 0; i < MAX_ABS; i++) {
abs_map[i] = -1;
curr_axis[i] = jx;
}
}
joystick_linux::joystick_linux(InputDefault *in)
{
joystick_linux::joystick_linux(InputDefault *in) {
exit_udev = false;
input = in;
joy_mutex = Mutex::create();
@@ -99,7 +98,7 @@ joystick_linux::~joystick_linux() {
void joystick_linux::joy_thread_func(void *p_user) {
if (p_user) {
joystick_linux* joy = (joystick_linux*) p_user;
joystick_linux *joy = (joystick_linux *)p_user;
joy->run_joystick_thread();
}
return;
@@ -125,16 +124,16 @@ void joystick_linux::enumerate_joysticks(udev *p_udev) {
udev_device *dev;
enumerate = udev_enumerate_new(p_udev);
udev_enumerate_add_match_subsystem(enumerate,"input");
udev_enumerate_add_match_subsystem(enumerate, "input");
udev_enumerate_add_match_property(enumerate, "ID_INPUT_JOYSTICK", "1");
udev_enumerate_scan_devices(enumerate);
devices = udev_enumerate_get_list_entry(enumerate);
udev_list_entry_foreach(dev_list_entry, devices) {
const char* path = udev_list_entry_get_name(dev_list_entry);
const char *path = udev_list_entry_get_name(dev_list_entry);
dev = udev_device_new_from_syspath(p_udev, path);
const char* devnode = udev_device_get_devnode(dev);
const char *devnode = udev_device_get_devnode(dev);
if (devnode) {
@@ -169,7 +168,7 @@ void joystick_linux::monitor_joysticks(udev *p_udev) {
tv.tv_sec = 0;
tv.tv_usec = 0;
ret = select(fd+1, &fds, NULL, NULL, &tv);
ret = select(fd + 1, &fds, NULL, NULL, &tv);
/* Check if our file descriptor has received data. */
if (ret > 0 && FD_ISSET(fd, &fds)) {
@@ -181,7 +180,7 @@ void joystick_linux::monitor_joysticks(udev *p_udev) {
joy_mutex->lock();
String action = udev_device_get_action(dev);
const char* devnode = udev_device_get_devnode(dev);
const char *devnode = udev_device_get_devnode(dev);
if (devnode) {
String devnode_str = devnode;
@@ -242,13 +241,13 @@ int joystick_linux::get_joy_from_path(String p_path) const {
void joystick_linux::close_joystick(int p_id) {
if (p_id == -1) {
for (int i=0; i<JOYSTICKS_MAX; i++) {
for (int i = 0; i < JOYSTICKS_MAX; i++) {
close_joystick(i);
};
return;
}
else if (p_id < 0) return;
} else if (p_id < 0)
return;
Joystick &joy = joysticks[p_id];
@@ -263,11 +262,11 @@ void joystick_linux::close_joystick(int p_id) {
static String _hex_str(uint8_t p_byte) {
static const char* dict = "0123456789abcdef";
static const char *dict = "0123456789abcdef";
char ret[3];
ret[2] = 0;
ret[0] = dict[p_byte>>4];
ret[0] = dict[p_byte >> 4];
ret[1] = dict[p_byte & 0xF];
return ret;
@@ -275,7 +274,7 @@ static String _hex_str(uint8_t p_byte) {
void joystick_linux::setup_joystick_properties(int p_id) {
Joystick* joy = &joysticks[p_id];
Joystick *joy = &joysticks[p_id];
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
@@ -284,7 +283,7 @@ void joystick_linux::setup_joystick_properties(int p_id) {
int num_axes = 0;
if ((ioctl(joy->fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
(ioctl(joy->fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
(ioctl(joy->fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
return;
}
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
@@ -342,8 +341,8 @@ void joystick_linux::open_joystick(const char *p_path) {
attached_devices.push_back(String(p_path));
if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
(ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
(ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
(ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
(ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
close(fd);
return;
}
@@ -351,10 +350,10 @@ 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
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)) &&
(test_bit(BTN_A, keybit) || test_bit(BTN_THUMBL, keybit) ||
test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_1, keybit)))) {
(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)) &&
(test_bit(BTN_A, keybit) || test_bit(BTN_THUMBL, keybit) ||
test_bit(BTN_TRIGGER, keybit) || test_bit(BTN_1, keybit)))) {
close(fd);
return;
}
@@ -385,13 +384,12 @@ void joystick_linux::open_joystick(const char *p_path) {
uint16_t product = __bswap_16(inpid.product);
uint16_t version = __bswap_16(inpid.version);
sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor,0,product,0,version,0);
sprintf(uid + String(uid).length(), "%04x%04x%04x%04x%04x%04x", vendor, 0, product, 0, version, 0);
input->joy_connection_changed(joy_num, true, name, uid);
}
else {
} else {
String uidname = uid;
int uidlen = MIN(name.length(), 11);
for (int i=0; i<uidlen; i++) {
for (int i = 0; i < uidlen; i++) {
uidname = uidname + _hex_str(name[i]);
}
@@ -401,9 +399,8 @@ 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)
{
Joystick& joy = joysticks[p_id];
void joystick_linux::joystick_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];
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;
}
@@ -427,15 +424,14 @@ void joystick_linux::joystick_vibration_start(int p_id, float p_weak_magnitude,
play.type = EV_FF;
play.code = effect.id;
play.value = 1;
write(joy.fd, (const void*)&play, sizeof(play));
write(joy.fd, (const void *)&play, sizeof(play));
joy.ff_effect_id = effect.id;
joy.ff_effect_timestamp = p_timestamp;
}
void joystick_linux::joystick_vibration_stop(int p_id, uint64_t p_timestamp)
{
Joystick& joy = joysticks[p_id];
void joystick_linux::joystick_vibration_stop(int p_id, uint64_t p_timestamp) {
Joystick &joy = joysticks[p_id];
if (!joy.force_feedback || joy.fd == -1 || joy.ff_effect_id == -1) {
return;
}
@@ -457,13 +453,13 @@ InputDefault::JoyAxis joystick_linux::axis_correct(const input_absinfo *p_abs, i
if (min < 0) {
jx.min = -1;
if (p_value < 0) {
jx.value = (float) -p_value / min;
jx.value = (float)-p_value / min;
}
jx.value = (float) p_value / max;
jx.value = (float)p_value / max;
}
if (min == 0) {
jx.min = 0;
jx.value = 0.0f + (float) p_value / max;
jx.value = 0.0f + (float)p_value / max;
}
return jx;
}
@@ -473,12 +469,12 @@ uint32_t joystick_linux::process_joysticks(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 < JOYSTICKS_MAX; i++) {
if (joysticks[i].fd == -1) continue;
input_event events[32];
Joystick* joy = &joysticks[i];
Joystick *joy = &joysticks[i];
int len;
@@ -490,45 +486,49 @@ uint32_t joystick_linux::process_joysticks(uint32_t p_event_id) {
// ev may be tainted and out of MAX_KEY range, which will cause
// joy->key_map[ev.code] to crash
if( ev.code < 0 || ev.code >= MAX_KEY )
if (ev.code < 0 || ev.code >= MAX_KEY)
return p_event_id;
switch (ev.type) {
case EV_KEY:
p_event_id = input->joy_button(p_event_id, i, joy->key_map[ev.code], ev.value);
break;
case EV_ABS:
switch (ev.code) {
case ABS_HAT0X:
if (ev.value != 0) {
if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_LEFT;
else joy->dpad |= InputDefault::HAT_MASK_RIGHT;
}
else joy->dpad &= ~(InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_RIGHT);
p_event_id = input->joy_hat(p_event_id, i, joy->dpad);
case EV_KEY:
p_event_id = input->joy_button(p_event_id, i, joy->key_map[ev.code], ev.value);
break;
case ABS_HAT0Y:
if (ev.value != 0) {
if (ev.value < 0) joy->dpad |= InputDefault::HAT_MASK_UP;
else joy->dpad |= InputDefault::HAT_MASK_DOWN;
}
else joy->dpad &= ~(InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_DOWN);
case EV_ABS:
p_event_id = input->joy_hat(p_event_id, i, joy->dpad);
break;
switch (ev.code) {
case ABS_HAT0X:
if (ev.value != 0) {
if (ev.value < 0)
joy->dpad |= InputDefault::HAT_MASK_LEFT;
else
joy->dpad |= InputDefault::HAT_MASK_RIGHT;
} else
joy->dpad &= ~(InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_RIGHT);
default:
if (joy->abs_map[ev.code] != -1 && joy->abs_info[ev.code]) {
InputDefault::JoyAxis value = axis_correct(joy->abs_info[ev.code], ev.value);
joy->curr_axis[joy->abs_map[ev.code]] = value;
p_event_id = input->joy_hat(p_event_id, i, joy->dpad);
break;
case ABS_HAT0Y:
if (ev.value != 0) {
if (ev.value < 0)
joy->dpad |= InputDefault::HAT_MASK_UP;
else
joy->dpad |= InputDefault::HAT_MASK_DOWN;
} else
joy->dpad &= ~(InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_DOWN);
p_event_id = input->joy_hat(p_event_id, i, joy->dpad);
break;
default:
if (joy->abs_map[ev.code] != -1 && joy->abs_info[ev.code]) {
InputDefault::JoyAxis value = axis_correct(joy->abs_info[ev.code], ev.value);
joy->curr_axis[joy->abs_map[ev.code]] = value;
}
break;
}
break;
}
break;
}
}
}