You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
This commit is contained in:
@@ -37,7 +37,6 @@
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) {
|
||||
|
||||
uint64_t tick = OS::get_singleton()->get_ticks_usec();
|
||||
uint32_t tdiff = tick - last_tick;
|
||||
float delta_t = tdiff / 1000000.0;
|
||||
@@ -50,7 +49,6 @@ void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) {
|
||||
accum_t = max_ref_frame * 10;
|
||||
|
||||
while (accum_t >= min_ref_frame) {
|
||||
|
||||
float slice_t = min_ref_frame / accum_t;
|
||||
Vector2 slice = accum * slice_t;
|
||||
accum = accum - slice;
|
||||
@@ -67,31 +65,26 @@ void InputDefault::SpeedTrack::reset() {
|
||||
}
|
||||
|
||||
InputDefault::SpeedTrack::SpeedTrack() {
|
||||
|
||||
min_ref_frame = 0.1;
|
||||
max_ref_frame = 0.3;
|
||||
reset();
|
||||
}
|
||||
|
||||
bool InputDefault::is_key_pressed(int p_scancode) const {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
return keys_pressed.has(p_scancode);
|
||||
}
|
||||
|
||||
bool InputDefault::is_mouse_button_pressed(int p_button) const {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
return (mouse_button_mask & (1 << (p_button - 1))) != 0;
|
||||
}
|
||||
|
||||
static int _combine_device(int p_value, int p_device) {
|
||||
|
||||
return p_value | (p_device << 20);
|
||||
}
|
||||
|
||||
bool InputDefault::is_joy_button_pressed(int p_device, int p_button) const {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
return joy_buttons_pressed.has(_combine_device(p_button, p_device));
|
||||
}
|
||||
@@ -149,7 +142,6 @@ float InputDefault::get_action_strength(const StringName &p_action) const {
|
||||
}
|
||||
|
||||
float InputDefault::get_joy_axis(int p_device, int p_axis) const {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
int c = _combine_device(p_axis, p_device);
|
||||
if (_joy_axis.has(c)) {
|
||||
@@ -160,7 +152,6 @@ float InputDefault::get_joy_axis(int p_device, int p_axis) const {
|
||||
}
|
||||
|
||||
String InputDefault::get_joy_name(int p_idx) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
return joy_names[p_idx].name;
|
||||
};
|
||||
@@ -190,7 +181,6 @@ float InputDefault::get_joy_vibration_duration(int p_device) {
|
||||
}
|
||||
|
||||
static String _hex_str(uint8_t p_byte) {
|
||||
|
||||
static const char *dict = "0123456789abcdef";
|
||||
char ret[3];
|
||||
ret[2] = 0;
|
||||
@@ -202,14 +192,12 @@ static String _hex_str(uint8_t p_byte) {
|
||||
};
|
||||
|
||||
void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
Joypad js;
|
||||
js.name = p_connected ? p_name : "";
|
||||
js.uid = p_connected ? p_guid : "";
|
||||
|
||||
if (p_connected) {
|
||||
|
||||
String uidname = p_guid;
|
||||
if (p_guid == "") {
|
||||
int uidlen = MIN(p_name.length(), 16);
|
||||
@@ -230,7 +218,6 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_
|
||||
} else {
|
||||
js.connected = false;
|
||||
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
|
||||
|
||||
if (i < JOY_AXIS_MAX)
|
||||
set_joy_axis(p_idx, i, 0.0f);
|
||||
|
||||
@@ -244,36 +231,30 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_
|
||||
};
|
||||
|
||||
Vector3 InputDefault::get_gravity() const {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
return gravity;
|
||||
}
|
||||
|
||||
Vector3 InputDefault::get_accelerometer() const {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
return accelerometer;
|
||||
}
|
||||
|
||||
Vector3 InputDefault::get_magnetometer() const {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
return magnetometer;
|
||||
}
|
||||
|
||||
Vector3 InputDefault::get_gyroscope() const {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
return gyroscope;
|
||||
}
|
||||
|
||||
void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) {
|
||||
|
||||
_parse_input_event_impl(p_event, false);
|
||||
}
|
||||
|
||||
void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {
|
||||
|
||||
// Notes on mouse-touch emulation:
|
||||
// - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects
|
||||
// as true mouse events. The only difference is the situation is flagged as emulated so they are not
|
||||
@@ -294,7 +275,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
Ref<InputEventMouseButton> mb = p_event;
|
||||
|
||||
if (mb.is_valid()) {
|
||||
|
||||
if (mb->is_pressed()) {
|
||||
mouse_button_mask |= (1 << (mb->get_button_index() - 1));
|
||||
} else {
|
||||
@@ -318,7 +298,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
Ref<InputEventMouseMotion> mm = p_event;
|
||||
|
||||
if (mm.is_valid()) {
|
||||
|
||||
Point2 pos = mm->get_global_position();
|
||||
if (mouse_pos != pos) {
|
||||
set_mouse_position(pos);
|
||||
@@ -339,7 +318,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
Ref<InputEventScreenTouch> st = p_event;
|
||||
|
||||
if (st.is_valid()) {
|
||||
|
||||
if (st->is_pressed()) {
|
||||
SpeedTrack &track = touch_speed_track[st->get_index()];
|
||||
track.reset();
|
||||
@@ -350,7 +328,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
}
|
||||
|
||||
if (emulate_mouse_from_touch) {
|
||||
|
||||
bool translate = false;
|
||||
if (st->is_pressed()) {
|
||||
if (mouse_from_touch_index == -1) {
|
||||
@@ -387,13 +364,11 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
Ref<InputEventScreenDrag> sd = p_event;
|
||||
|
||||
if (sd.is_valid()) {
|
||||
|
||||
SpeedTrack &track = touch_speed_track[sd->get_index()];
|
||||
track.update(sd->get_relative());
|
||||
sd->set_speed(track.speed);
|
||||
|
||||
if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) {
|
||||
|
||||
Ref<InputEventMouseMotion> motion_event;
|
||||
motion_event.instance();
|
||||
|
||||
@@ -412,7 +387,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
Ref<InputEventJoypadButton> jb = p_event;
|
||||
|
||||
if (jb.is_valid()) {
|
||||
|
||||
int c = _combine_device(jb->get_button_index(), jb->get_device());
|
||||
|
||||
if (jb->is_pressed())
|
||||
@@ -430,7 +404,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
Ref<InputEventGesture> ge = p_event;
|
||||
|
||||
if (ge.is_valid()) {
|
||||
|
||||
if (main_loop) {
|
||||
main_loop->input_event(ge);
|
||||
}
|
||||
@@ -438,7 +411,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
|
||||
for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) {
|
||||
if (InputMap::get_singleton()->event_is_action(p_event, E->key())) {
|
||||
|
||||
// Save the action's state
|
||||
if (!p_event->is_echo() && is_action_pressed(E->key()) != p_event->is_action_pressed(E->key())) {
|
||||
Action action;
|
||||
@@ -457,7 +429,6 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -491,28 +462,24 @@ void InputDefault::vibrate_handheld(int p_duration_ms) {
|
||||
}
|
||||
|
||||
void InputDefault::set_gravity(const Vector3 &p_gravity) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
gravity = p_gravity;
|
||||
}
|
||||
|
||||
void InputDefault::set_accelerometer(const Vector3 &p_accel) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
accelerometer = p_accel;
|
||||
}
|
||||
|
||||
void InputDefault::set_magnetometer(const Vector3 &p_magnetometer) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
magnetometer = p_magnetometer;
|
||||
}
|
||||
|
||||
void InputDefault::set_gyroscope(const Vector3 &p_gyroscope) {
|
||||
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
gyroscope = p_gyroscope;
|
||||
@@ -523,32 +490,26 @@ void InputDefault::set_main_loop(MainLoop *p_main_loop) {
|
||||
}
|
||||
|
||||
void InputDefault::set_mouse_position(const Point2 &p_posf) {
|
||||
|
||||
mouse_speed_track.update(p_posf - mouse_pos);
|
||||
mouse_pos = p_posf;
|
||||
}
|
||||
|
||||
Point2 InputDefault::get_mouse_position() const {
|
||||
|
||||
return mouse_pos;
|
||||
}
|
||||
Point2 InputDefault::get_last_mouse_speed() const {
|
||||
|
||||
return mouse_speed_track.speed;
|
||||
}
|
||||
|
||||
int InputDefault::get_mouse_button_mask() const {
|
||||
|
||||
return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state();
|
||||
}
|
||||
|
||||
void InputDefault::warp_mouse_position(const Vector2 &p_to) {
|
||||
|
||||
OS::get_singleton()->warp_mouse_position(p_to);
|
||||
}
|
||||
|
||||
Point2i InputDefault::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) {
|
||||
|
||||
// The relative distance reported for the next event after a warp is in the boundaries of the
|
||||
// size of the rect on that axis, but it may be greater, in which case there's not problem as fmod()
|
||||
// will warp it, but if the pointer has moved in the opposite direction between the pointer relocation
|
||||
@@ -577,7 +538,6 @@ void InputDefault::iteration(float p_step) {
|
||||
}
|
||||
|
||||
void InputDefault::action_press(const StringName &p_action, float p_strength) {
|
||||
|
||||
Action action;
|
||||
|
||||
action.physics_frame = Engine::get_singleton()->get_physics_frames();
|
||||
@@ -589,7 +549,6 @@ void InputDefault::action_press(const StringName &p_action, float p_strength) {
|
||||
}
|
||||
|
||||
void InputDefault::action_release(const StringName &p_action) {
|
||||
|
||||
Action action;
|
||||
|
||||
action.physics_frame = Engine::get_singleton()->get_physics_frames();
|
||||
@@ -601,19 +560,16 @@ void InputDefault::action_release(const StringName &p_action) {
|
||||
}
|
||||
|
||||
void InputDefault::set_emulate_touch_from_mouse(bool p_emulate) {
|
||||
|
||||
emulate_touch_from_mouse = p_emulate;
|
||||
}
|
||||
|
||||
bool InputDefault::is_emulating_touch_from_mouse() const {
|
||||
|
||||
return emulate_touch_from_mouse;
|
||||
}
|
||||
|
||||
// Calling this whenever the game window is focused helps unstucking the "touch mouse"
|
||||
// if the OS or its abstraction class hasn't properly reported that touch pointers raised
|
||||
void InputDefault::ensure_touch_mouse_raised() {
|
||||
|
||||
if (mouse_from_touch_index != -1) {
|
||||
mouse_from_touch_index = -1;
|
||||
|
||||
@@ -632,22 +588,18 @@ void InputDefault::ensure_touch_mouse_raised() {
|
||||
}
|
||||
|
||||
void InputDefault::set_emulate_mouse_from_touch(bool p_emulate) {
|
||||
|
||||
emulate_mouse_from_touch = p_emulate;
|
||||
}
|
||||
|
||||
bool InputDefault::is_emulating_mouse_from_touch() const {
|
||||
|
||||
return emulate_mouse_from_touch;
|
||||
}
|
||||
|
||||
Input::CursorShape InputDefault::get_default_cursor_shape() const {
|
||||
|
||||
return default_shape;
|
||||
}
|
||||
|
||||
void InputDefault::set_default_cursor_shape(CursorShape p_shape) {
|
||||
|
||||
if (default_shape == p_shape)
|
||||
return;
|
||||
|
||||
@@ -662,7 +614,6 @@ void InputDefault::set_default_cursor_shape(CursorShape p_shape) {
|
||||
}
|
||||
|
||||
Input::CursorShape InputDefault::get_current_cursor_shape() const {
|
||||
|
||||
return (Input::CursorShape)OS::get_singleton()->get_cursor_shape();
|
||||
}
|
||||
|
||||
@@ -687,7 +638,6 @@ void InputDefault::accumulate_input_event(const Ref<InputEvent> &p_event) {
|
||||
accumulated_events.push_back(p_event);
|
||||
}
|
||||
void InputDefault::flush_accumulated_events() {
|
||||
|
||||
while (accumulated_events.front()) {
|
||||
parse_input_event(accumulated_events.front()->get());
|
||||
accumulated_events.pop_front();
|
||||
@@ -695,12 +645,10 @@ void InputDefault::flush_accumulated_events() {
|
||||
}
|
||||
|
||||
void InputDefault::set_use_accumulated_input(bool p_enable) {
|
||||
|
||||
use_accumulated_input = p_enable;
|
||||
}
|
||||
|
||||
void InputDefault::release_pressed_events() {
|
||||
|
||||
flush_accumulated_events(); // this is needed to release actions strengths
|
||||
|
||||
keys_pressed.clear();
|
||||
@@ -714,7 +662,6 @@ void InputDefault::release_pressed_events() {
|
||||
}
|
||||
|
||||
InputDefault::InputDefault() {
|
||||
|
||||
use_accumulated_input = true;
|
||||
mouse_button_mask = 0;
|
||||
emulate_touch_from_mouse = false;
|
||||
@@ -746,7 +693,6 @@ InputDefault::InputDefault() {
|
||||
}
|
||||
|
||||
void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) {
|
||||
|
||||
_THREAD_SAFE_METHOD_;
|
||||
Joypad &joy = joy_names[p_device];
|
||||
//printf("got button %i, mapping is %i\n", p_button, joy.mapping);
|
||||
@@ -779,7 +725,6 @@ void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) {
|
||||
}
|
||||
|
||||
void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
|
||||
|
||||
_THREAD_SAFE_METHOD_;
|
||||
|
||||
ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX);
|
||||
@@ -859,7 +804,6 @@ void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
|
||||
}
|
||||
|
||||
if (map.type == TYPE_AXIS) {
|
||||
|
||||
_axis_event(p_device, map.index, val);
|
||||
return;
|
||||
}
|
||||
@@ -867,7 +811,6 @@ void InputDefault::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
|
||||
}
|
||||
|
||||
void InputDefault::joy_hat(int p_device, int p_val) {
|
||||
|
||||
_THREAD_SAFE_METHOD_;
|
||||
const Joypad &joy = joy_names[p_device];
|
||||
|
||||
@@ -910,7 +853,6 @@ void InputDefault::joy_hat(int p_device, int p_val) {
|
||||
}
|
||||
|
||||
void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) {
|
||||
|
||||
Ref<InputEventJoypadButton> ievent;
|
||||
ievent.instance();
|
||||
ievent->set_device(p_device);
|
||||
@@ -921,7 +863,6 @@ void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) {
|
||||
}
|
||||
|
||||
void InputDefault::_axis_event(int p_device, int p_axis, float p_value) {
|
||||
|
||||
Ref<InputEventJoypadMotion> ievent;
|
||||
ievent.instance();
|
||||
ievent->set_device(p_device);
|
||||
@@ -932,7 +873,6 @@ void InputDefault::_axis_event(int p_device, int p_axis, float p_value) {
|
||||
};
|
||||
|
||||
InputDefault::JoyEvent InputDefault::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) {
|
||||
|
||||
JoyEvent event;
|
||||
event.type = TYPE_MAX;
|
||||
|
||||
@@ -969,7 +909,6 @@ InputDefault::JoyEvent InputDefault::_get_mapped_button_event(const JoyDeviceMap
|
||||
}
|
||||
|
||||
InputDefault::JoyEvent InputDefault::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value) {
|
||||
|
||||
JoyEvent event;
|
||||
event.type = TYPE_MAX;
|
||||
|
||||
@@ -1039,11 +978,9 @@ InputDefault::JoyEvent InputDefault::_get_mapped_axis_event(const JoyDeviceMappi
|
||||
}
|
||||
|
||||
void InputDefault::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[]) {
|
||||
|
||||
for (int i = 0; i < mapping.bindings.size(); i++) {
|
||||
const JoyBinding binding = mapping.bindings[i];
|
||||
if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) {
|
||||
|
||||
int hat_direction;
|
||||
switch (binding.input.hat.hat_mask) {
|
||||
case HAT_MASK_UP:
|
||||
@@ -1096,7 +1033,6 @@ static const char *_joy_buttons[] = { "a", "b", "x", "y", "leftshoulder", "right
|
||||
static const char *_joy_axes[] = { "leftx", "lefty", "rightx", "righty", nullptr };
|
||||
|
||||
JoystickList InputDefault::_get_output_button(String output) {
|
||||
|
||||
for (int i = 0; _joy_buttons[i]; i++) {
|
||||
if (output == _joy_buttons[i])
|
||||
return JoystickList(i);
|
||||
@@ -1105,7 +1041,6 @@ JoystickList InputDefault::_get_output_button(String output) {
|
||||
}
|
||||
|
||||
JoystickList InputDefault::_get_output_axis(String output) {
|
||||
|
||||
for (int i = 0; _joy_axes[i]; i++) {
|
||||
if (output == _joy_axes[i])
|
||||
return JoystickList(i);
|
||||
@@ -1114,7 +1049,6 @@ JoystickList InputDefault::_get_output_axis(String output) {
|
||||
}
|
||||
|
||||
void InputDefault::parse_mapping(String p_mapping) {
|
||||
|
||||
_THREAD_SAFE_METHOD_;
|
||||
JoyDeviceMapping mapping;
|
||||
|
||||
@@ -1131,7 +1065,6 @@ void InputDefault::parse_mapping(String p_mapping) {
|
||||
|
||||
int idx = 1;
|
||||
while (++idx < entry.size()) {
|
||||
|
||||
if (entry[idx] == "")
|
||||
continue;
|
||||
|
||||
@@ -1241,7 +1174,6 @@ void InputDefault::remove_joy_mapping(String p_guid) {
|
||||
}
|
||||
|
||||
void InputDefault::set_fallback_mapping(String p_guid) {
|
||||
|
||||
for (int i = 0; i < map_db.size(); i++) {
|
||||
if (map_db[i].uid == p_guid) {
|
||||
fallback_mapping = i;
|
||||
@@ -1252,7 +1184,6 @@ void InputDefault::set_fallback_mapping(String p_guid) {
|
||||
|
||||
//Defaults to simple implementation for platforms with a fixed gamepad layout, like consoles.
|
||||
bool InputDefault::is_joy_known(int p_device) {
|
||||
|
||||
return OS::get_singleton()->is_joy_known(p_device);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user