1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +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

@@ -27,48 +27,46 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "input_default.h"
#include "servers/visual_server.h"
#include "os/os.h"
#include "input_map.h"
#include "os/os.h"
#include "scene/resources/texture.h"
#include "servers/visual_server.h"
void InputDefault::SpeedTrack::update(const Vector2& p_delta_p) {
void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) {
uint64_t tick = OS::get_singleton()->get_ticks_usec();
uint32_t tdiff = tick-last_tick;
uint32_t tdiff = tick - last_tick;
float delta_t = tdiff / 1000000.0;
last_tick=tick;
last_tick = tick;
accum += p_delta_p;
accum_t += delta_t;
accum+=p_delta_p;
accum_t+=delta_t;
if (accum_t > max_ref_frame * 10)
accum_t = max_ref_frame * 10;
if (accum_t>max_ref_frame*10)
accum_t=max_ref_frame*10;
while( accum_t>=min_ref_frame ) {
while (accum_t >= min_ref_frame) {
float slice_t = min_ref_frame / accum_t;
Vector2 slice = accum*slice_t;
accum=accum-slice;
accum_t-=min_ref_frame;
Vector2 slice = accum * slice_t;
accum = accum - slice;
accum_t -= min_ref_frame;
speed=(slice/min_ref_frame).linear_interpolate(speed,min_ref_frame/max_ref_frame);
speed = (slice / min_ref_frame).linear_interpolate(speed, min_ref_frame / max_ref_frame);
}
}
void InputDefault::SpeedTrack::reset() {
last_tick = OS::get_singleton()->get_ticks_usec();
speed=Vector2();
accum_t=0;
speed = Vector2();
accum_t = 0;
}
InputDefault::SpeedTrack::SpeedTrack() {
min_ref_frame=0.1;
max_ref_frame=0.3;
reset();
min_ref_frame = 0.1;
max_ref_frame = 0.3;
reset();
}
bool InputDefault::is_key_pressed(int p_scancode) {
@@ -80,22 +78,21 @@ bool InputDefault::is_key_pressed(int p_scancode) {
bool InputDefault::is_mouse_button_pressed(int p_button) {
_THREAD_SAFE_METHOD_
return (mouse_button_mask&(1<<p_button))!=0;
return (mouse_button_mask & (1 << p_button)) != 0;
}
static int _combine_device(int p_value, int p_device) {
static int _combine_device(int p_value,int p_device) {
return p_value|(p_device<<20);
return p_value | (p_device << 20);
}
bool InputDefault::is_joy_button_pressed(int p_device, int p_button) {
_THREAD_SAFE_METHOD_
return joy_buttons_pressed.has(_combine_device(p_button,p_device));
return joy_buttons_pressed.has(_combine_device(p_button, p_device));
}
bool InputDefault::is_action_pressed(const StringName& p_action) {
bool InputDefault::is_action_pressed(const StringName &p_action) {
if (custom_action_press.has(p_action))
return true; //simpler
@@ -104,43 +101,40 @@ bool InputDefault::is_action_pressed(const StringName& p_action) {
if (!alist)
return false;
for (const List<InputEvent>::Element *E = alist->front(); E; E = E->next()) {
for (const List<InputEvent>::Element *E=alist->front();E;E=E->next()) {
int device = E->get().device;
int device=E->get().device;
switch(E->get().type) {
switch (E->get().type) {
case InputEvent::KEY: {
const InputEventKey &iek=E->get().key;
const InputEventKey &iek = E->get().key;
if ((keys_pressed.has(iek.scancode)))
return true;
} break;
case InputEvent::MOUSE_BUTTON: {
const InputEventMouseButton &iemb=E->get().mouse_button;
if(mouse_button_mask&(1<<iemb.button_index))
return true;
const InputEventMouseButton &iemb = E->get().mouse_button;
if (mouse_button_mask & (1 << iemb.button_index))
return true;
} break;
case InputEvent::JOYSTICK_BUTTON: {
const InputEventJoystickButton &iejb=E->get().joy_button;
int c = _combine_device(iejb.button_index,device);
const InputEventJoystickButton &iejb = E->get().joy_button;
int c = _combine_device(iejb.button_index, device);
if (joy_buttons_pressed.has(c))
return true;
} break;
case InputEvent::JOYSTICK_MOTION: {
const InputEventJoystickMotion &iejm=E->get().joy_motion;
int c = _combine_device(iejm.axis,device);
const InputEventJoystickMotion &iejm = E->get().joy_motion;
int c = _combine_device(iejm.axis, device);
if (_joy_axis.has(c)) {
if (iejm.axis_value < 0) {
if (_joy_axis[c] < -0.5f) return true;
}
else
if (_joy_axis[c] > 0.5f) return true;
} else if (_joy_axis[c] > 0.5f)
return true;
}
} break;
}
@@ -149,10 +143,10 @@ bool InputDefault::is_action_pressed(const StringName& p_action) {
return false;
}
float InputDefault::get_joy_axis(int p_device,int p_axis) {
float InputDefault::get_joy_axis(int p_device, int p_axis) {
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis,p_device);
int c = _combine_device(p_axis, p_device);
if (_joy_axis.has(c)) {
return _joy_axis[c];
} else {
@@ -192,11 +186,11 @@ float InputDefault::get_joy_vibration_duration(int p_device) {
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;
@@ -216,22 +210,21 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_
String uidname = p_guid;
if (p_guid == "") {
int uidlen = MIN(p_name.length(), 16);
for (int i=0; i<uidlen; i++) {
for (int i = 0; i < uidlen; i++) {
uidname = uidname + _hex_str(p_name[i]);
};
};
js.uid = uidname;
js.connected = true;
int mapping = fallback_mapping;
for (int i=0; i < map_db.size(); i++) {
for (int i = 0; i < map_db.size(); i++) {
if (js.uid == map_db[i].uid) {
mapping = i;
js.name = map_db[i].name;
};
};
js.mapping = mapping;
}
else {
} else {
js.connected = false;
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
@@ -271,19 +264,19 @@ Vector3 InputDefault::get_gyroscope() {
return gyroscope;
}
void InputDefault::parse_input_event(const InputEvent& p_event) {
void InputDefault::parse_input_event(const InputEvent &p_event) {
_THREAD_SAFE_METHOD_
switch(p_event.type) {
switch (p_event.type) {
case InputEvent::KEY: {
if (p_event.key.echo)
break;
if (p_event.key.scancode==0)
if (p_event.key.scancode == 0)
break;
// print_line(p_event);
// print_line(p_event);
if (p_event.key.pressed)
keys_pressed.insert(p_event.key.scancode);
@@ -296,37 +289,37 @@ void InputDefault::parse_input_event(const InputEvent& p_event) {
break;
if (p_event.mouse_button.pressed)
mouse_button_mask|=(1<<p_event.mouse_button.button_index);
mouse_button_mask |= (1 << p_event.mouse_button.button_index);
else
mouse_button_mask&=~(1<<p_event.mouse_button.button_index);
mouse_button_mask &= ~(1 << p_event.mouse_button.button_index);
if (main_loop && emulate_touch && p_event.mouse_button.button_index==1) {
if (main_loop && emulate_touch && p_event.mouse_button.button_index == 1) {
InputEventScreenTouch touch_event;
touch_event.index=0;
touch_event.pressed=p_event.mouse_button.pressed;
touch_event.x=p_event.mouse_button.x;
touch_event.y=p_event.mouse_button.y;
touch_event.index = 0;
touch_event.pressed = p_event.mouse_button.pressed;
touch_event.x = p_event.mouse_button.x;
touch_event.y = p_event.mouse_button.y;
InputEvent ev;
ev.type=InputEvent::SCREEN_TOUCH;
ev.screen_touch=touch_event;
ev.type = InputEvent::SCREEN_TOUCH;
ev.screen_touch = touch_event;
main_loop->input_event(ev);
}
} break;
case InputEvent::MOUSE_MOTION: {
if (main_loop && emulate_touch && p_event.mouse_motion.button_mask&1) {
if (main_loop && emulate_touch && p_event.mouse_motion.button_mask & 1) {
InputEventScreenDrag drag_event;
drag_event.index=0;
drag_event.x=p_event.mouse_motion.x;
drag_event.y=p_event.mouse_motion.y;
drag_event.relative_x=p_event.mouse_motion.relative_x;
drag_event.relative_y=p_event.mouse_motion.relative_y;
drag_event.speed_x=p_event.mouse_motion.speed_x;
drag_event.speed_y=p_event.mouse_motion.speed_y;
drag_event.index = 0;
drag_event.x = p_event.mouse_motion.x;
drag_event.y = p_event.mouse_motion.y;
drag_event.relative_x = p_event.mouse_motion.relative_x;
drag_event.relative_y = p_event.mouse_motion.relative_y;
drag_event.speed_x = p_event.mouse_motion.speed_x;
drag_event.speed_y = p_event.mouse_motion.speed_y;
InputEvent ev;
ev.type=InputEvent::SCREEN_DRAG;
ev.screen_drag=drag_event;
ev.type = InputEvent::SCREEN_DRAG;
ev.screen_drag = drag_event;
main_loop->input_event(ev);
}
@@ -334,7 +327,7 @@ void InputDefault::parse_input_event(const InputEvent& p_event) {
} break;
case InputEvent::JOYSTICK_BUTTON: {
int c = _combine_device(p_event.joy_button.button_index,p_event.device);
int c = _combine_device(p_event.joy_button.button_index, p_event.device);
if (p_event.joy_button.pressed)
joy_buttons_pressed.insert(c);
@@ -344,19 +337,17 @@ void InputDefault::parse_input_event(const InputEvent& p_event) {
case InputEvent::JOYSTICK_MOTION: {
set_joy_axis(p_event.device, p_event.joy_motion.axis, p_event.joy_motion.axis_value);
} break;
}
if (main_loop)
main_loop->input_event(p_event);
}
void InputDefault::set_joy_axis(int p_device,int p_axis,float p_value) {
void InputDefault::set_joy_axis(int p_device, int p_axis, float p_value) {
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis,p_device);
_joy_axis[c]=p_value;
int c = _combine_device(p_axis, p_device);
_joy_axis[c] = p_value;
}
void InputDefault::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) {
@@ -382,47 +373,42 @@ void InputDefault::stop_joy_vibration(int p_device) {
joy_vibration[p_device] = vibration;
}
void InputDefault::set_gravity(const Vector3& p_gravity) {
void InputDefault::set_gravity(const Vector3 &p_gravity) {
_THREAD_SAFE_METHOD_
gravity=p_gravity;
gravity = p_gravity;
}
void InputDefault::set_accelerometer(const Vector3& p_accel) {
void InputDefault::set_accelerometer(const Vector3 &p_accel) {
_THREAD_SAFE_METHOD_
accelerometer=p_accel;
accelerometer = p_accel;
}
void InputDefault::set_magnetometer(const Vector3& p_magnetometer) {
void InputDefault::set_magnetometer(const Vector3 &p_magnetometer) {
_THREAD_SAFE_METHOD_
magnetometer=p_magnetometer;
magnetometer = p_magnetometer;
}
void InputDefault::set_gyroscope(const Vector3& p_gyroscope) {
void InputDefault::set_gyroscope(const Vector3 &p_gyroscope) {
_THREAD_SAFE_METHOD_
gyroscope=p_gyroscope;
gyroscope = p_gyroscope;
}
void InputDefault::set_main_loop(MainLoop *p_main_loop) {
main_loop=p_main_loop;
main_loop = p_main_loop;
}
void InputDefault::set_mouse_pos(const Point2& p_posf) {
void InputDefault::set_mouse_pos(const Point2 &p_posf) {
mouse_speed_track.update(p_posf-mouse_pos);
mouse_pos=p_posf;
mouse_speed_track.update(p_posf - mouse_pos);
mouse_pos = p_posf;
if (custom_cursor.is_valid()) {
VisualServer::get_singleton()->cursor_set_pos(get_mouse_pos());
}
@@ -442,39 +428,36 @@ int InputDefault::get_mouse_button_mask() const {
return OS::get_singleton()->get_mouse_button_state();
}
void InputDefault::warp_mouse_pos(const Vector2& p_to) {
void InputDefault::warp_mouse_pos(const Vector2 &p_to) {
OS::get_singleton()->warp_mouse_pos(p_to);
}
void InputDefault::iteration(float p_step) {
}
void InputDefault::action_press(const StringName& p_action) {
void InputDefault::action_press(const StringName &p_action) {
if (custom_action_press.has(p_action)) {
custom_action_press[p_action]++;
} else {
custom_action_press[p_action]=1;
custom_action_press[p_action] = 1;
}
}
void InputDefault::action_release(const StringName& p_action){
void InputDefault::action_release(const StringName &p_action) {
ERR_FAIL_COND(!custom_action_press.has(p_action));
custom_action_press[p_action]--;
if (custom_action_press[p_action]==0) {
if (custom_action_press[p_action] == 0) {
custom_action_press.erase(p_action);
}
}
void InputDefault::set_emulate_touch(bool p_emulate) {
emulate_touch=p_emulate;
emulate_touch = p_emulate;
}
bool InputDefault::is_emulating_touchscreen() const {
@@ -482,11 +465,11 @@ bool InputDefault::is_emulating_touchscreen() const {
return emulate_touch;
}
void InputDefault::set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_hotspot) {
if (custom_cursor==p_cursor)
void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, const Vector2 &p_hotspot) {
if (custom_cursor == p_cursor)
return;
custom_cursor=p_cursor;
custom_cursor = p_cursor;
if (p_cursor.is_null()) {
set_mouse_mode(MOUSE_MODE_VISIBLE);
@@ -496,7 +479,7 @@ void InputDefault::set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_
Rect2 region = atex.is_valid() ? atex->get_region() : Rect2();
set_mouse_mode(MOUSE_MODE_HIDDEN);
VisualServer::get_singleton()->cursor_set_visible(true);
VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(),p_hotspot, 0, region);
VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(), p_hotspot, 0, region);
VisualServer::get_singleton()->cursor_set_pos(get_mouse_pos());
}
}
@@ -512,13 +495,12 @@ void InputDefault::set_mouse_in_window(bool p_in_window) {
set_mouse_mode(MOUSE_MODE_VISIBLE);
VisualServer::get_singleton()->cursor_set_visible(false);
}
}
}
// from github.com/gabomdq/SDL_GameControllerDB
static const char *s_ControllerMappings [] = {
#ifdef WINDOWS_ENABLED
static const char *s_ControllerMappings[] = {
#ifdef WINDOWS_ENABLED
"00f00300000000000000504944564944,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,",
"00f0f100000000000000504944564944,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,",
"02200090000000000000504944564944,8Bitdo NES30 PRO USB,a:b0,b:b1,x:b3,y:b4,leftshoulder:b6,rightshoulder:b7,lefttrigger:b8,righttrigger:b9,back:b10,start:b11,leftstick:b13,rightstick:b14,leftx:a0,lefty:a1,rightx:a3,righty:a4,dpup:h0.1,dpright:h0.2,dpdown:h0.4,dpleft:h0.8,",
@@ -565,9 +547,9 @@ static const char *s_ControllerMappings [] = {
"ff113133000000000000504944564944,SVEN X-PAD,a:b2,b:b3,y:b1,x:b0,start:b5,back:b4,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b8,righttrigger:b9,",
"ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"__XINPUT_DEVICE__,XInput Gamepad,a:b12,b:b13,x:b14,y:b15,start:b4,back:b5,leftstick:b6,rightstick:b7,leftshoulder:b8,rightshoulder:b9,dpup:b0,dpdown:b1,dpleft:b2,dpright:b3,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,",
#endif
#endif
#ifdef OSX_ENABLED
#ifdef OSX_ENABLED
"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"050000005769696d6f74652028303000,Wii Remote,a:b4,b:b5,y:b9,x:b10,start:b6,guide:b8,back:b7,dpup:b2,dpleft:b0,dpdown:b3,dpright:b1,leftx:a0,lefty:a1,lefttrigger:b12,righttrigger:,leftshoulder:b11,",
"050000005769696d6f74652028313800,Wii U Pro Controller,a:b16,b:b15,x:b18,y:b17,back:b7,guide:b8,start:b6,leftstick:b23,rightstick:b24,leftshoulder:b19,rightshoulder:b20,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b21,righttrigger:b22,",
@@ -594,9 +576,9 @@ static const char *s_ControllerMappings [] = {
"ad1b00000000000001f9000000000000,Gamestop BB-070 X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
"b4040000000000000a01000000000000,Sega Saturn USB Gamepad,a:b0,b:b1,x:b3,y:b4,back:b5,guide:b2,start:b8,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,",
"d814000000000000cecf000000000000,MC Cthulhu,leftx:,lefty:,rightx:,righty:,lefttrigger:b6,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,righttrigger:b7,",
#endif
#endif
#if X11_ENABLED
#if X11_ENABLED
"0000000058626f782047616d65706100,Xbox Gamepad (userspace driver),a:b0,b:b1,x:b2,y:b3,start:b7,back:b6,guide:b8,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,lefttrigger:a5,righttrigger:a4,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
"0300000000f000000300000000010000,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,",
"0300000000f00000f100000000010000,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,",
@@ -679,9 +661,9 @@ static const char *s_ControllerMappings [] = {
"050000007e0500003003000001000000,Nintendo Wii U Pro Controller,a:b0,b:b1,x:b3,y:b2,back:b8,start:b9,guide:b10,leftshoulder:b4,rightshoulder:b5,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:b13,dpleft:b15,dpdown:b14,dpright:b16,",
"05000000d6200000ad0d000001000000,Moga Pro,a:b0,b:b1,y:b3,x:b2,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4,",
"060000004c0500006802000000010000,PS3 Controller (Bluetooth),a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,",
#endif
#endif
#if defined(__ANDROID__)
#if defined(__ANDROID__)
"Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,",
"47656e6572696320582d426f78207061,Logitech F-310,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a5,x:b2,dpup:h0.1,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a4,b:b1,",
"484f524920434f2e2c4c544420205041,Hori Gem Pad 3,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b6,rightshoulder:b18,rightx:a2,start:b16,righty:a3,dpleft:h0.8,lefttrigger:b9,x:b0,dpup:h0.1,back:b15,leftstick:b4,leftshoulder:b3,y:b2,a:b1,dpright:h0.2,righttrigger:b10,b:b17,",
@@ -689,9 +671,9 @@ static const char *s_ControllerMappings [] = {
"4e564944494120436f72706f72617469,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
"532e542e442e20496e74657261637420,3dfx InterAct HammerHead FX,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b25,rightshoulder:b27,rightx:a2,start:b31,righty:a3,dpleft:h0.8,lefttrigger:b28,x:b20,dpup:h0.1,back:b30,leftstick:b22,leftshoulder:b26,y:b21,a:b23,dpright:h0.2,righttrigger:b29,b:b24,",
"506572666f726d616e63652044657369,PDP Rock Candy Wireless Controller for PS3,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b6,rightshoulder:b18,rightx:a2,start:b16,righty:a3,dpleft:h0.8,lefttrigger:b9,x:b0,dpup:h0.1,back:h0.2,leftstick:b4,leftshoulder:b3,y:b2,a:b1,dpright:h0.2,righttrigger:b10,b:b17,",
#endif
#endif
#ifdef JAVASCRIPT_ENABLED
#ifdef JAVASCRIPT_ENABLED
"Default HTML5 Gamepad, Default Mapping,leftx:a0,lefty:a1,dpdown:b13,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a3,dpleft:b14,lefttrigger:a6,x:b2,dpup:b12,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b0,dpright:b15,righttrigger:a7,b:b1,",
"303435652d303238652d4d6963726f73,Wired X360 Controller,leftx:a0,lefty:a1,dpdown:a7,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:a6,lefttrigger:a2,x:b2,dpup:a7,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:a6,righttrigger:a5,b:b1,",
"303435652d303731392d58626f782033,Wireless X360 Controller,leftx:a0,lefty:a1,dpdown:b14,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:b11,lefttrigger:a2,x:b2,dpup:b13,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:b12,righttrigger:a5,b:b1,",
@@ -699,15 +681,15 @@ static const char *s_ControllerMappings [] = {
"303534632d303563342d536f6e792043,PS4 Controller USB/Linux,leftx:a0,lefty:a1,dpdown:a7,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a5,dpleft:a6,lefttrigger:a3,x:b0,dpup:a7,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b1,dpright:a6,righttrigger:a4,b:b2,",
"303534632d303563342d576972656c65,PS4 Controller USB/Win,leftx:a0,lefty:a1,dpdown:b15,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a5,lefttrigger:a3,x:b0,dpup:b14,dpleft:b16,dpright:b17,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b1,righttrigger:b7,b:b2,",
"c2a94d6963726f736f66742058626f78,Wireless X360 Controller,leftx:a0,lefty:a1,dpdown:b14,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:b11,lefttrigger:a2,x:b2,dpup:b13,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:b12,righttrigger:a5,b:b1,",
#endif
#endif
NULL
};
InputDefault::InputDefault() {
mouse_button_mask=0;
emulate_touch=false;
main_loop=NULL;
mouse_button_mask = 0;
emulate_touch = false;
main_loop = NULL;
hat_map_default[HAT_UP].type = TYPE_BUTTON;
hat_map_default[HAT_UP].index = JOY_DPAD_UP;
@@ -731,7 +713,7 @@ InputDefault::InputDefault() {
if (env_mapping != "") {
Vector<String> entries = env_mapping.split("\n");
for (int i=0; i < entries.size(); i++) {
for (int i = 0; i < entries.size(); i++) {
if (entries[i] == "")
continue;
parse_mapping(entries[i]);
@@ -745,11 +727,10 @@ InputDefault::InputDefault() {
};
}
uint32_t InputDefault::joy_button(uint32_t p_last_id, int p_device, int p_button, bool p_pressed) {
_THREAD_SAFE_METHOD_;
Joystick& joy = joy_names[p_device];
Joystick &joy = joy_names[p_device];
//printf("got button %i, mapping is %i\n", p_button, joy.mapping);
if (joy.last_buttons[p_button] == p_pressed) {
return p_last_id;
@@ -760,7 +741,7 @@ uint32_t InputDefault::joy_button(uint32_t p_last_id, int p_device, int p_button
return _button_event(p_last_id, p_device, p_button, p_pressed);
};
Map<int,JoyEvent>::Element* el = map_db[joy.mapping].buttons.find(p_button);
Map<int, JoyEvent>::Element *el = map_db[joy.mapping].buttons.find(p_button);
if (!el) {
//don't process un-mapped events for now, it could mess things up badly for devices with additional buttons/axis
//return _button_event(p_last_id, p_device, p_button, p_pressed);
@@ -785,11 +766,11 @@ uint32_t InputDefault::joy_button(uint32_t p_last_id, int p_device, int p_button
return p_last_id; // no event?
};
uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, const JoyAxis& p_value) {
uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, const JoyAxis &p_value) {
_THREAD_SAFE_METHOD_;
Joystick& joy = joy_names[p_device];
Joystick &joy = joy_names[p_device];
if (joy.last_axis[p_axis] == p_value.value) {
return p_last_id;
@@ -797,12 +778,11 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
if (p_value.value > joy.last_axis[p_axis]) {
if (p_value.value < joy.last_axis[p_axis] + joy.filter ) {
if (p_value.value < joy.last_axis[p_axis] + joy.filter) {
return p_last_id;
}
}
else if (p_value.value > joy.last_axis[p_axis] - joy.filter) {
} else if (p_value.value > joy.last_axis[p_axis] - joy.filter) {
return p_last_id;
}
@@ -822,13 +802,12 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
return _axis_event(p_last_id, p_device, p_axis, val);
};
Map<int,JoyEvent>::Element* el = map_db[joy.mapping].axis.find(p_axis);
Map<int, JoyEvent>::Element *el = map_db[joy.mapping].axis.find(p_axis);
if (!el) {
//return _axis_event(p_last_id, p_device, p_axis, p_value);
return p_last_id;
};
JoyEvent map = el->get();
if (map.type == TYPE_BUTTON) {
@@ -851,7 +830,7 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
p_last_id = _button_event(p_last_id, p_device, JOY_DPAD_DOWN, false);
}
}
if ( pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) {
if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) {
return p_last_id;
}
return _button_event(p_last_id, p_device, button, true);
@@ -868,14 +847,14 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
p_last_id = _button_event(p_last_id, p_device, JOY_DPAD_RIGHT, false);
}
}
if ( pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) {
if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) {
return p_last_id;
}
return _button_event(p_last_id, p_device, button, true);
}
float deadzone = p_value.min == 0 ? 0.5f : 0.0f;
bool pressed = p_value.value > deadzone ? true : false;
if (pressed == joy_buttons_pressed.has(_combine_device(map.index,p_device))) {
if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) {
// button already pressed or released, this is an axis bounce value
return p_last_id;
};
@@ -884,7 +863,7 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
if (map.type == TYPE_AXIS) {
return _axis_event(p_last_id, p_device, map.index, val );
return _axis_event(p_last_id, p_device, map.index, val);
};
//printf("invalid mapping\n");
return p_last_id;
@@ -893,9 +872,9 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
uint32_t InputDefault::joy_hat(uint32_t p_last_id, int p_device, int p_val) {
_THREAD_SAFE_METHOD_;
const Joystick& joy = joy_names[p_device];
const Joystick &joy = joy_names[p_device];
JoyEvent* map;
JoyEvent *map;
if (joy.mapping == -1) {
map = hat_map_default;
@@ -905,17 +884,17 @@ uint32_t InputDefault::joy_hat(uint32_t p_last_id, int p_device, int p_val) {
int cur_val = joy_names[p_device].hat_current;
if ( (p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP) ) {
if ((p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP)) {
p_last_id = _button_event(p_last_id, p_device, map[HAT_UP].index, p_val & HAT_MASK_UP);
};
if ( (p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT) ) {
if ((p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT)) {
p_last_id = _button_event(p_last_id, p_device, map[HAT_RIGHT].index, p_val & HAT_MASK_RIGHT);
};
if ( (p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN) ) {
if ((p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN)) {
p_last_id = _button_event(p_last_id, p_device, map[HAT_DOWN].index, p_val & HAT_MASK_DOWN);
};
if ( (p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT) ) {
if ((p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT)) {
p_last_id = _button_event(p_last_id, p_device, map[HAT_LEFT].index, p_val & HAT_MASK_LEFT);
};
@@ -947,7 +926,7 @@ uint32_t InputDefault::_axis_event(uint32_t p_last_id, int p_device, int p_axis,
ievent.joy_motion.axis = p_axis;
ievent.joy_motion.axis_value = p_value;
parse_input_event( ievent );
parse_input_event(ievent);
return p_last_id;
};
@@ -955,14 +934,14 @@ uint32_t InputDefault::_axis_event(uint32_t p_last_id, int p_device, int p_axis,
InputDefault::JoyEvent InputDefault::_find_to_event(String p_to) {
// string names of the SDL buttons in the same order as input_event.h godot buttons
static const char* buttons[] = {"a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", NULL };
static const char *buttons[] = { "a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", NULL };
static const char* axis[] = {"leftx", "lefty", "rightx", "righty", NULL };
static const char *axis[] = { "leftx", "lefty", "rightx", "righty", NULL };
JoyEvent ret;
ret.type = -1;
int i=0;
int i = 0;
while (buttons[i]) {
if (p_to == buttons[i]) {
@@ -1018,30 +997,30 @@ void InputDefault::parse_mapping(String p_mapping) {
String etype = from.substr(0, 1);
if (etype == "a") {
int aid = from.substr(1, from.length()-1).to_int();
int aid = from.substr(1, from.length() - 1).to_int();
mapping.axis[aid] = to_event;
} else if (etype == "b") {
int bid = from.substr(1, from.length()-1).to_int();
int bid = from.substr(1, from.length() - 1).to_int();
mapping.buttons[bid] = to_event;
} else if (etype == "h") {
int hat_value = from.get_slice(".", 1).to_int();
switch (hat_value) {
case 1:
mapping.hat[HAT_UP] = to_event;
break;
case 2:
mapping.hat[HAT_RIGHT] = to_event;
break;
case 4:
mapping.hat[HAT_DOWN] = to_event;
break;
case 8:
mapping.hat[HAT_LEFT] = to_event;
break;
case 1:
mapping.hat[HAT_UP] = to_event;
break;
case 2:
mapping.hat[HAT_RIGHT] = to_event;
break;
case 4:
mapping.hat[HAT_DOWN] = to_event;
break;
case 8:
mapping.hat[HAT_LEFT] = to_event;
break;
};
};
};
@@ -1054,21 +1033,21 @@ void InputDefault::add_joy_mapping(String p_mapping, bool p_update_existing) {
if (p_update_existing) {
Vector<String> entry = p_mapping.split(",");
String uid = entry[0];
for (int i=0; i<joy_names.size(); i++) {
for (int i = 0; i < joy_names.size(); i++) {
if (uid == joy_names[i].uid) {
joy_names[i].mapping = map_db.size() -1;
joy_names[i].mapping = map_db.size() - 1;
}
}
}
}
void InputDefault::remove_joy_mapping(String p_guid) {
for (int i=map_db.size()-1; i >= 0;i--) {
for (int i = map_db.size() - 1; i >= 0; i--) {
if (p_guid == map_db[i].uid) {
map_db.remove(i);
}
}
for (int i=0; i<joy_names.size(); i++) {
for (int i = 0; i < joy_names.size(); i++) {
if (joy_names[i].uid == p_guid) {
joy_names[i].mapping = -1;
}
@@ -1118,7 +1097,7 @@ Array InputDefault::get_connected_joysticks() {
return ret;
}
static const char* _buttons[] = {
static const char *_buttons[] = {
"Face Button Bottom",
"Face Button Right",
"Face Button Left",
@@ -1137,7 +1116,7 @@ static const char* _buttons[] = {
"DPAD Right"
};
static const char* _axes[] = {
static const char *_axes[] = {
"Left Stick X",
"Left Stick Y",
"Right Stick X",