summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/array.cpp72
-rw-r--r--core/array.h3
-rw-r--r--core/color.h12
-rw-r--r--core/debugger/remote_debugger.cpp35
-rw-r--r--core/debugger/remote_debugger.h11
-rw-r--r--core/input/godotcontrollerdb.txt3
-rw-r--r--core/input/input_event.cpp2
-rw-r--r--core/os/os.h2
-rw-r--r--core/variant.cpp5
-rw-r--r--core/variant_call.cpp9
10 files changed, 97 insertions, 57 deletions
diff --git a/core/array.cpp b/core/array.cpp
index cd4e0fb4c8..7c0129ffde 100644
--- a/core/array.cpp
+++ b/core/array.cpp
@@ -285,59 +285,49 @@ Array Array::duplicate(bool p_deep) const {
return new_arr;
}
-int Array::_fix_slice_index(int p_index, int p_arr_len, int p_top_mod) {
- p_index = CLAMP(p_index, -p_arr_len, p_arr_len + p_top_mod);
- if (p_index < 0) {
- p_index = (p_index % p_arr_len + p_arr_len) % p_arr_len; // positive modulo
- }
- return p_index;
-}
+int Array::_clamp_slice_index(int p_index) const {
-int Array::_clamp_index(int p_index) const {
- return CLAMP(p_index, -size() + 1, size() - 1);
+ int arr_size = size();
+ int fixed_index = CLAMP(p_index, -arr_size, arr_size - 1);
+ if (fixed_index < 0) {
+ fixed_index = arr_size + fixed_index;
+ }
+ return fixed_index;
}
-#define ARRAY_GET_DEEP(idx, is_deep) is_deep ? get(idx).duplicate(is_deep) : get(idx)
-
Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // like python, but inclusive on upper bound
- Array new_arr;
-
- if (empty()) // Don't try to slice empty arrays.
- return new_arr;
- p_begin = Array::_fix_slice_index(p_begin, size(), -1); // can't start out of range
- p_end = Array::_fix_slice_index(p_end, size(), 0);
+ Array new_arr;
- int x = p_begin;
- int new_arr_i = 0;
+ ERR_FAIL_COND_V_MSG(p_step == 0, new_arr, "Array slice step size cannot be zero.");
- ERR_FAIL_COND_V(p_step == 0, new_arr);
- if (Array::_clamp_index(p_begin) == Array::_clamp_index(p_end)) { // don't include element twice
- new_arr.resize(1);
- // new_arr[0] = 1;
- new_arr[0] = ARRAY_GET_DEEP(Array::_clamp_index(p_begin), p_deep);
+ if (empty()) // Don't try to slice empty arrays.
return new_arr;
- } else {
- int element_count = ceil((int)MAX(0, (p_end - p_begin) / p_step)) + 1;
- if (element_count == 1) { // delta going in wrong direction to reach end
- new_arr.resize(0);
+ if (p_step > 0) {
+ if (p_begin >= size() || p_end < -size())
+ return new_arr;
+ } else { // p_step < 0
+ if (p_begin < -size() || p_end >= size())
return new_arr;
- }
- new_arr.resize(element_count);
}
- // if going backwards, have to have a different terminating condition
- if (p_step < 0) {
- while (x >= p_end) {
- new_arr[new_arr_i] = ARRAY_GET_DEEP(Array::_clamp_index(x), p_deep);
- x += p_step;
- new_arr_i += 1;
+ int begin = _clamp_slice_index(p_begin);
+ int end = _clamp_slice_index(p_end);
+
+ int new_arr_size = MAX(((end - begin + p_step) / p_step), 0);
+ new_arr.resize(new_arr_size);
+
+ if (p_step > 0) {
+ int dest_idx = 0;
+ for (int idx = begin; idx <= end; idx += p_step) {
+ ERR_FAIL_COND_V_MSG(dest_idx < 0 || dest_idx >= new_arr_size, Array(), "Bug in Array slice()");
+ new_arr[dest_idx++] = p_deep ? get(idx).duplicate(p_deep) : get(idx);
}
- } else if (p_step > 0) {
- while (x <= p_end) {
- new_arr[new_arr_i] = ARRAY_GET_DEEP(Array::_clamp_index(x), p_deep);
- x += p_step;
- new_arr_i += 1;
+ } else { // p_step < 0
+ int dest_idx = 0;
+ for (int idx = begin; idx >= end; idx += p_step) {
+ ERR_FAIL_COND_V_MSG(dest_idx < 0 || dest_idx >= new_arr_size, Array(), "Bug in Array slice()");
+ new_arr[dest_idx++] = p_deep ? get(idx).duplicate(p_deep) : get(idx);
}
}
diff --git a/core/array.h b/core/array.h
index 2840ce199c..14db57f15f 100644
--- a/core/array.h
+++ b/core/array.h
@@ -44,8 +44,7 @@ class Array {
void _ref(const Array &p_from) const;
void _unref() const;
- int _clamp_index(int p_index) const;
- static int _fix_slice_index(int p_index, int p_arr_len, int p_top_mod);
+ inline int _clamp_slice_index(int p_index) const;
protected:
Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
diff --git a/core/color.h b/core/color.h
index d95e80f5da..8b689fdde1 100644
--- a/core/color.h
+++ b/core/color.h
@@ -205,7 +205,7 @@ struct Color {
operator String() const;
/**
- * No construct parameters, r=0, g=0, b=0. a=255
+ * No construct parameters, r=0, g=0, b=0. a=1
*/
_FORCE_INLINE_ Color() {
r = 0;
@@ -223,6 +223,16 @@ struct Color {
b = p_b;
a = p_a;
}
+
+ /**
+ * Construct a Color from another Color, but with the specified alpha value.
+ */
+ _FORCE_INLINE_ Color(const Color &p_c, float p_a) {
+ r = p_c.r;
+ g = p_c.g;
+ b = p_c.b;
+ a = p_a;
+ }
};
bool Color::operator<(const Color &p_color) const {
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp
index fd109c62b6..97d5c71b6f 100644
--- a/core/debugger/remote_debugger.cpp
+++ b/core/debugger/remote_debugger.cpp
@@ -466,7 +466,7 @@ void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p
String s = p_string;
int allowed_chars = MIN(MAX(rd->max_chars_per_second - rd->char_count, 0), s.length());
- if (allowed_chars == 0)
+ if (allowed_chars == 0 && s.length() > 0)
return;
if (allowed_chars < s.length()) {
@@ -480,10 +480,16 @@ void RemoteDebugger::_print_handler(void *p_this, const String &p_string, bool p
if (rd->is_peer_connected()) {
if (overflowed)
s += "[...]";
- rd->output_strings.push_back(s);
+
+ OutputString output_string;
+ output_string.message = s;
+ output_string.type = p_error ? MESSAGE_TYPE_ERROR : MESSAGE_TYPE_LOG;
+ rd->output_strings.push_back(output_string);
if (overflowed) {
- rd->output_strings.push_back("[output overflow, print less text!]");
+ output_string.message = "[output overflow, print less text!]";
+ output_string.type = MESSAGE_TYPE_ERROR;
+ rd->output_strings.push_back(output_string);
}
}
}
@@ -517,15 +523,32 @@ void RemoteDebugger::flush_output() {
if (output_strings.size()) {
// Join output strings so we generate less messages.
+ Vector<String> joined_log_strings;
Vector<String> strings;
- strings.resize(output_strings.size());
- String *w = strings.ptrw();
+ Vector<int> types;
for (int i = 0; i < output_strings.size(); i++) {
- w[i] = output_strings[i];
+ const OutputString &output_string = output_strings[i];
+ if (output_string.type == MESSAGE_TYPE_ERROR) {
+ if (!joined_log_strings.empty()) {
+ strings.push_back(String("\n").join(joined_log_strings));
+ types.push_back(MESSAGE_TYPE_LOG);
+ joined_log_strings.clear();
+ }
+ strings.push_back(output_string.message);
+ types.push_back(MESSAGE_TYPE_ERROR);
+ } else {
+ joined_log_strings.push_back(output_string.message);
+ }
+ }
+
+ if (!joined_log_strings.empty()) {
+ strings.push_back(String("\n").join(joined_log_strings));
+ types.push_back(MESSAGE_TYPE_LOG);
}
Array arr;
arr.push_back(strings);
+ arr.push_back(types);
_put_msg("output", arr);
output_strings.clear();
}
diff --git a/core/debugger/remote_debugger.h b/core/debugger/remote_debugger.h
index f805eec631..cac0bc3730 100644
--- a/core/debugger/remote_debugger.h
+++ b/core/debugger/remote_debugger.h
@@ -40,6 +40,11 @@
#include "core/ustring.h"
class RemoteDebugger : public EngineDebugger {
+public:
+ enum MessageType {
+ MESSAGE_TYPE_LOG,
+ MESSAGE_TYPE_ERROR,
+ };
private:
typedef DebuggerMarshalls::OutputError ErrorMessage;
@@ -57,7 +62,11 @@ private:
Ref<RemoteDebuggerPeer> peer;
- List<String> output_strings;
+ struct OutputString {
+ String message;
+ MessageType type;
+ };
+ List<OutputString> output_strings;
List<ErrorMessage> errors;
int n_messages_dropped = 0;
diff --git a/core/input/godotcontrollerdb.txt b/core/input/godotcontrollerdb.txt
index f6411e2429..adc3649d64 100644
--- a/core/input/godotcontrollerdb.txt
+++ b/core/input/godotcontrollerdb.txt
@@ -1,6 +1,9 @@
# Game Controller DB for Godot in SDL 2.0.10 format
# Source: https://github.com/godotengine/godot
+# Windows
+__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,platform:Windows,
+
# Javascript
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,platform:Javascript,
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,platform:Javascript,
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index d18adb1983..4b8c104f39 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -708,7 +708,7 @@ String InputEventMouseMotion::as_text() const {
button_mask_string = itos(get_button_mask());
break;
}
- return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")";
+ return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + "), pressure=(" + rtos(get_pressure()) + "), tilt=(" + String(get_tilt()) + ")";
}
bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
diff --git a/core/os/os.h b/core/os/os.h
index 714a10bf76..38114e6814 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -59,6 +59,7 @@ class OS {
bool _allow_layered;
bool _use_vsync;
bool _vsync_via_compositor;
+ bool _disable_wintab;
char *last_error;
@@ -148,6 +149,7 @@ public:
bool is_layered_allowed() const { return _allow_layered; }
bool is_hidpi_allowed() const { return _allow_hidpi; }
+ bool is_wintab_disabled() const { return _disable_wintab; }
void ensure_user_data_dir();
diff --git a/core/variant.cpp b/core/variant.cpp
index b3611536b8..a91876dd98 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -102,11 +102,6 @@ String Variant::get_type_name(Variant::Type p_type) {
return "Plane";
} break;
- /*
- case QUAT: {
-
-
- } break;*/
case AABB: {
return "AABB";
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 39bfd04a0b..9fffb42ff6 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -1075,6 +1075,11 @@ struct _VariantCall {
r_ret = Color::hex(*p_args[0]);
}
+ static void Color_init5(Variant &r_ret, const Variant **p_args) {
+
+ r_ret = Color(((Color)(*p_args[0])), *p_args[1]);
+ }
+
static void AABB_init1(Variant &r_ret, const Variant **p_args) {
r_ret = ::AABB(*p_args[0], *p_args[1]);
@@ -1353,6 +1358,8 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
case RECT2I: return (Rect2i(*p_args[0]));
case VECTOR3: return (Vector3(*p_args[0]));
case VECTOR3I: return (Vector3i(*p_args[0]));
+ case TRANSFORM2D:
+ return (Transform2D(p_args[0]->operator Transform2D()));
case PLANE: return (Plane(*p_args[0]));
case QUAT: return (p_args[0]->operator Quat());
case AABB:
@@ -2209,6 +2216,8 @@ void register_variant_methods() {
_VariantCall::add_constructor(_VariantCall::Color_init1, Variant::COLOR, "r", Variant::FLOAT, "g", Variant::FLOAT, "b", Variant::FLOAT, "a", Variant::FLOAT);
_VariantCall::add_constructor(_VariantCall::Color_init2, Variant::COLOR, "r", Variant::FLOAT, "g", Variant::FLOAT, "b", Variant::FLOAT);
+ // init3 and init4 are the constructors for HTML hex strings and integers respectively which don't need binding here, so we skip to init5.
+ _VariantCall::add_constructor(_VariantCall::Color_init5, Variant::COLOR, "c", Variant::COLOR, "a", Variant::FLOAT);
_VariantCall::add_constructor(_VariantCall::AABB_init1, Variant::AABB, "position", Variant::VECTOR3, "size", Variant::VECTOR3);