summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/SCsub1
-rw-r--r--core/bind/core_bind.cpp175
-rw-r--r--core/bind/core_bind.h47
-rw-r--r--core/color.cpp2
-rw-r--r--core/color_names.inc1
-rw-r--r--core/command_queue_mt.h4
-rw-r--r--core/core_string_names.cpp1
-rw-r--r--core/core_string_names.h1
-rw-r--r--core/engine.cpp1
-rw-r--r--core/error_macros.h2
-rw-r--r--core/func_ref.cpp13
-rw-r--r--core/func_ref.h1
-rw-r--r--core/global_constants.cpp16
-rw-r--r--core/hash_map.h19
-rw-r--r--core/image.cpp151
-rw-r--r--core/image.h1
-rw-r--r--core/input_map.cpp2
-rw-r--r--core/io/config_file.cpp4
-rw-r--r--core/io/file_access_encrypted.cpp5
-rw-r--r--core/io/file_access_network.cpp11
-rw-r--r--core/io/http_client.cpp8
-rw-r--r--core/io/image_loader.cpp3
-rw-r--r--core/io/image_loader.h1
-rw-r--r--core/io/marshalls.cpp6
-rw-r--r--core/io/multiplayer_api.cpp26
-rw-r--r--core/io/resource_format_binary.h2
-rw-r--r--core/io/resource_importer.cpp3
-rw-r--r--core/io/resource_importer.h4
-rw-r--r--core/io/translation_loader_po.h1
-rw-r--r--core/io/xml_parser.cpp2
-rw-r--r--core/io/zip_io.h2
-rw-r--r--core/list.h3
-rw-r--r--core/math/a_star.cpp125
-rw-r--r--core/math/a_star.h23
-rw-r--r--core/math/basis.cpp29
-rw-r--r--core/math/expression.cpp9
-rw-r--r--core/math/expression.h1
-rw-r--r--core/math/geometry.cpp106
-rw-r--r--core/math/geometry.h93
-rw-r--r--core/math/math_funcs.h8
-rw-r--r--core/math/random_number_generator.h5
-rw-r--r--core/math/random_pcg.cpp8
-rw-r--r--core/math/random_pcg.h62
-rw-r--r--core/math/vector2.cpp7
-rw-r--r--core/math/vector2.h1
-rw-r--r--core/math/vector3.cpp7
-rw-r--r--core/math/vector3.h3
-rw-r--r--core/message_queue.cpp22
-rw-r--r--core/message_queue.h2
-rw-r--r--core/object.cpp34
-rw-r--r--core/object.h7
-rw-r--r--core/os/input_event.cpp26
-rw-r--r--core/os/input_event.h20
-rw-r--r--core/os/os.cpp3
-rw-r--r--core/os/os.h9
-rw-r--r--core/print_string.cpp2
-rw-r--r--core/project_settings.cpp31
-rw-r--r--core/script_language.cpp1
-rw-r--r--core/script_language.h9
-rw-r--r--core/sort_array.h6
-rw-r--r--core/undo_redo.cpp16
-rw-r--r--core/undo_redo.h4
-rw-r--r--core/ustring.cpp90
-rw-r--r--core/ustring.h9
-rw-r--r--core/variant.cpp2
-rw-r--r--core/variant_call.cpp16
-rw-r--r--core/vector.h2
67 files changed, 1062 insertions, 255 deletions
diff --git a/core/SCsub b/core/SCsub
index 06efc8408d..166b7083e4 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -58,6 +58,7 @@ thirdparty_misc_sources = [
"md5.cpp",
"pcg.cpp",
"triangulator.cpp",
+ "clipper.cpp",
]
thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources]
env_thirdparty.add_source_files(env.core_sources, thirdparty_misc_sources)
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index ba595b9627..8a898f3b53 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -308,6 +308,14 @@ void _OS::set_window_position(const Point2 &p_position) {
OS::get_singleton()->set_window_position(p_position);
}
+Size2 _OS::get_max_window_size() const {
+ return OS::get_singleton()->get_max_window_size();
+}
+
+Size2 _OS::get_min_window_size() const {
+ return OS::get_singleton()->get_min_window_size();
+}
+
Size2 _OS::get_window_size() const {
return OS::get_singleton()->get_window_size();
}
@@ -316,6 +324,14 @@ Size2 _OS::get_real_window_size() const {
return OS::get_singleton()->get_real_window_size();
}
+void _OS::set_max_window_size(const Size2 &p_size) {
+ OS::get_singleton()->set_max_window_size(p_size);
+}
+
+void _OS::set_min_window_size(const Size2 &p_size) {
+ OS::get_singleton()->set_min_window_size(p_size);
+}
+
void _OS::set_window_size(const Size2 &p_size) {
OS::get_singleton()->set_window_size(p_size);
}
@@ -442,14 +458,14 @@ Error _OS::shell_open(String p_uri) {
return OS::get_singleton()->shell_open(p_uri);
};
-int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output) {
+int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr) {
OS::ProcessID pid = -2;
List<String> args;
for (int i = 0; i < p_arguments.size(); i++)
args.push_back(p_arguments[i]);
String pipe;
- Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe);
+ Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, NULL, p_read_stderr);
p_output.clear();
p_output.push_back(pipe);
if (err != OK)
@@ -611,6 +627,11 @@ uint64_t _OS::get_dynamic_memory_usage() const {
return OS::get_singleton()->get_dynamic_memory_usage();
}
+void _OS::set_native_icon(const String &p_filename) {
+
+ OS::get_singleton()->set_native_icon(p_filename);
+}
+
void _OS::set_icon(const Ref<Image> &p_icon) {
OS::get_singleton()->set_icon(p_icon);
@@ -1134,6 +1155,10 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_window_position"), &_OS::get_window_position);
ClassDB::bind_method(D_METHOD("set_window_position", "position"), &_OS::set_window_position);
ClassDB::bind_method(D_METHOD("get_window_size"), &_OS::get_window_size);
+ ClassDB::bind_method(D_METHOD("get_max_window_size"), &_OS::get_max_window_size);
+ ClassDB::bind_method(D_METHOD("get_min_window_size"), &_OS::get_min_window_size);
+ ClassDB::bind_method(D_METHOD("set_max_window_size", "size"), &_OS::set_max_window_size);
+ ClassDB::bind_method(D_METHOD("set_min_window_size", "size"), &_OS::set_min_window_size);
ClassDB::bind_method(D_METHOD("set_window_size", "size"), &_OS::set_window_size);
ClassDB::bind_method(D_METHOD("get_window_safe_area"), &_OS::get_window_safe_area);
ClassDB::bind_method(D_METHOD("set_window_fullscreen", "enabled"), &_OS::set_window_fullscreen);
@@ -1178,7 +1203,7 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_processor_count"), &_OS::get_processor_count);
ClassDB::bind_method(D_METHOD("get_executable_path"), &_OS::get_executable_path);
- ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "blocking", "output"), &_OS::execute, DEFVAL(Array()));
+ ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "blocking", "output", "read_stderr"), &_OS::execute, DEFVAL(Array()), DEFVAL(false));
ClassDB::bind_method(D_METHOD("kill", "pid"), &_OS::kill);
ClassDB::bind_method(D_METHOD("shell_open", "uri"), &_OS::shell_open);
ClassDB::bind_method(D_METHOD("get_process_id"), &_OS::get_process_id);
@@ -1199,6 +1224,7 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs);
ClassDB::bind_method(D_METHOD("get_system_time_msecs"), &_OS::get_system_time_msecs);
+ ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &_OS::set_native_icon);
ClassDB::bind_method(D_METHOD("set_icon", "icon"), &_OS::set_icon);
ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code);
@@ -1278,6 +1304,8 @@ void _OS::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_enabled"), "set_use_vsync", "is_vsync_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_screen_on"), "set_keep_screen_on", "is_keep_screen_on");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_window_size"), "set_min_window_size", "get_min_window_size");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "max_window_size"), "set_max_window_size", "get_max_window_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"), "set_screen_orientation", "get_screen_orientation");
ADD_GROUP("Window", "window_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_borderless"), "set_borderless_window", "get_borderless_window");
@@ -1491,11 +1519,21 @@ PoolVector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from,
return r;
}
+bool _Geometry::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
+
+ return Geometry::is_polygon_clockwise(p_polygon);
+}
+
Vector<int> _Geometry::triangulate_polygon(const Vector<Vector2> &p_polygon) {
return Geometry::triangulate_polygon(p_polygon);
}
+Vector<int> _Geometry::triangulate_delaunay_2d(const Vector<Vector2> &p_points) {
+
+ return Geometry::triangulate_delaunay_2d(p_points);
+}
+
Vector<Point2> _Geometry::convex_hull_2d(const Vector<Point2> &p_points) {
return Geometry::convex_hull_2d(p_points);
@@ -1506,6 +1544,107 @@ Vector<Vector3> _Geometry::clip_polygon(const Vector<Vector3> &p_points, const P
return Geometry::clip_polygon(p_points, p_plane);
}
+Array _Geometry::merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
+
+ Vector<Vector<Point2> > polys = Geometry::merge_polygons_2d(p_polygon_a, p_polygon_b);
+
+ Array ret;
+
+ for (int i = 0; i < polys.size(); ++i) {
+ ret.push_back(polys[i]);
+ }
+ return ret;
+}
+
+Array _Geometry::clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
+
+ Vector<Vector<Point2> > polys = Geometry::clip_polygons_2d(p_polygon_a, p_polygon_b);
+
+ Array ret;
+
+ for (int i = 0; i < polys.size(); ++i) {
+ ret.push_back(polys[i]);
+ }
+ return ret;
+}
+
+Array _Geometry::intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
+
+ Vector<Vector<Point2> > polys = Geometry::intersect_polygons_2d(p_polygon_a, p_polygon_b);
+
+ Array ret;
+
+ for (int i = 0; i < polys.size(); ++i) {
+ ret.push_back(polys[i]);
+ }
+ return ret;
+}
+
+Array _Geometry::exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
+
+ Vector<Vector<Point2> > polys = Geometry::exclude_polygons_2d(p_polygon_a, p_polygon_b);
+
+ Array ret;
+
+ for (int i = 0; i < polys.size(); ++i) {
+ ret.push_back(polys[i]);
+ }
+ return ret;
+}
+
+Array _Geometry::clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
+
+ Vector<Vector<Point2> > polys = Geometry::clip_polyline_with_polygon_2d(p_polyline, p_polygon);
+
+ Array ret;
+
+ for (int i = 0; i < polys.size(); ++i) {
+ ret.push_back(polys[i]);
+ }
+ return ret;
+}
+
+Array _Geometry::intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
+
+ Vector<Vector<Point2> > polys = Geometry::intersect_polyline_with_polygon_2d(p_polyline, p_polygon);
+
+ Array ret;
+
+ for (int i = 0; i < polys.size(); ++i) {
+ ret.push_back(polys[i]);
+ }
+ return ret;
+}
+
+Array _Geometry::offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
+
+ Vector<Vector<Point2> > polys = Geometry::offset_polygon_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type));
+
+ Array ret;
+
+ for (int i = 0; i < polys.size(); ++i) {
+ ret.push_back(polys[i]);
+ }
+ return ret;
+}
+
+Array _Geometry::offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
+
+ Vector<Vector<Point2> > polys = Geometry::offset_polyline_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type), Geometry::PolyEndType(p_end_type));
+
+ Array ret;
+
+ for (int i = 0; i < polys.size(); ++i) {
+ ret.push_back(polys[i]);
+ }
+ return ret;
+}
+
+Vector<Point2> _Geometry::transform_points_2d(const Vector<Point2> &p_points, const Transform2D &p_mat) {
+
+ return Geometry::transform_points_2d(p_points, p_mat);
+}
+
Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) {
Dictionary ret;
@@ -1566,11 +1705,41 @@ void _Geometry::_bind_methods() {
ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &_Geometry::segment_intersects_convex);
ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &_Geometry::point_is_inside_triangle);
+ ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &_Geometry::is_polygon_clockwise);
ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &_Geometry::triangulate_polygon);
+ ClassDB::bind_method(D_METHOD("triangulate_delaunay_2d", "points"), &_Geometry::triangulate_delaunay_2d);
ClassDB::bind_method(D_METHOD("convex_hull_2d", "points"), &_Geometry::convex_hull_2d);
ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &_Geometry::clip_polygon);
+ ClassDB::bind_method(D_METHOD("merge_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::merge_polygons_2d);
+ ClassDB::bind_method(D_METHOD("clip_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::clip_polygons_2d);
+ ClassDB::bind_method(D_METHOD("intersect_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::intersect_polygons_2d);
+ ClassDB::bind_method(D_METHOD("exclude_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::exclude_polygons_2d);
+
+ ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon_2d", "polyline", "polygon"), &_Geometry::clip_polyline_with_polygon_2d);
+ ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon_2d", "polyline", "polygon"), &_Geometry::intersect_polyline_with_polygon_2d);
+
+ ClassDB::bind_method(D_METHOD("offset_polygon_2d", "polygon", "delta", "join_type"), &_Geometry::offset_polygon_2d, DEFVAL(JOIN_SQUARE));
+ ClassDB::bind_method(D_METHOD("offset_polyline_2d", "polyline", "delta", "join_type", "end_type"), &_Geometry::offset_polyline_2d, DEFVAL(JOIN_SQUARE), DEFVAL(END_SQUARE));
+
+ ClassDB::bind_method(D_METHOD("transform_points_2d", "points", "transform"), &_Geometry::transform_points_2d);
+
ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &_Geometry::make_atlas);
+
+ BIND_ENUM_CONSTANT(OPERATION_UNION);
+ BIND_ENUM_CONSTANT(OPERATION_DIFFERENCE);
+ BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
+ BIND_ENUM_CONSTANT(OPERATION_XOR);
+
+ BIND_ENUM_CONSTANT(JOIN_SQUARE);
+ BIND_ENUM_CONSTANT(JOIN_ROUND);
+ BIND_ENUM_CONSTANT(JOIN_MITER);
+
+ BIND_ENUM_CONSTANT(END_POLYGON);
+ BIND_ENUM_CONSTANT(END_JOINED);
+ BIND_ENUM_CONSTANT(END_BUTT);
+ BIND_ENUM_CONSTANT(END_SQUARE);
+ BIND_ENUM_CONSTANT(END_ROUND);
}
_Geometry::_Geometry() {
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 2906de4a4a..2751ff242c 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -175,9 +175,13 @@ public:
virtual int get_screen_dpi(int p_screen = -1) const;
virtual Point2 get_window_position() const;
virtual void set_window_position(const Point2 &p_position);
+ virtual Size2 get_max_window_size() const;
+ virtual Size2 get_min_window_size() const;
virtual Size2 get_window_size() const;
virtual Size2 get_real_window_size() const;
virtual Rect2 get_window_safe_area() const;
+ virtual void set_max_window_size(const Size2 &p_size);
+ virtual void set_min_window_size(const Size2 &p_size);
virtual void set_window_size(const Size2 &p_size);
virtual void set_window_fullscreen(bool p_enabled);
virtual bool is_window_fullscreen() const;
@@ -214,7 +218,7 @@ public:
bool is_in_low_processor_usage_mode() const;
String get_executable_path() const;
- int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output = Array());
+ int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output = Array(), bool p_read_stderr = false);
Error kill(int p_pid);
Error shell_open(String p_uri);
@@ -275,6 +279,7 @@ public:
void set_use_file_access_save_and_swap(bool p_enable);
+ void set_native_icon(const String &p_filename);
void set_icon(const Ref<Image> &p_icon);
int get_exit_code() const;
@@ -402,15 +407,55 @@ public:
real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius);
int get_uv84_normal_bit(const Vector3 &p_vector);
+ bool is_polygon_clockwise(const Vector<Vector2> &p_polygon);
Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon);
+ Vector<int> triangulate_delaunay_2d(const Vector<Vector2> &p_points);
Vector<Point2> convex_hull_2d(const Vector<Point2> &p_points);
Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
+ enum PolyBooleanOperation {
+ OPERATION_UNION,
+ OPERATION_DIFFERENCE,
+ OPERATION_INTERSECTION,
+ OPERATION_XOR
+ };
+ // 2D polygon boolean operations
+ Array merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // union (add)
+ Array clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // difference (subtract)
+ Array intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // common area (multiply)
+ Array exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // all but common area (xor)
+
+ // 2D polyline vs polygon operations
+ Array clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // cut
+ Array intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // chop
+
+ // 2D offset polygons/polylines
+ enum PolyJoinType {
+ JOIN_SQUARE,
+ JOIN_ROUND,
+ JOIN_MITER
+ };
+ enum PolyEndType {
+ END_POLYGON,
+ END_JOINED,
+ END_BUTT,
+ END_SQUARE,
+ END_ROUND
+ };
+ Array offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE);
+ Array offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE, PolyEndType p_end_type = END_SQUARE);
+
+ Vector<Point2> transform_points_2d(const Vector<Point2> &p_points, const Transform2D &p_mat);
+
Dictionary make_atlas(const Vector<Size2> &p_rects);
_Geometry();
};
+VARIANT_ENUM_CAST(_Geometry::PolyBooleanOperation);
+VARIANT_ENUM_CAST(_Geometry::PolyJoinType);
+VARIANT_ENUM_CAST(_Geometry::PolyEndType);
+
class _File : public Reference {
GDCLASS(_File, Reference);
diff --git a/core/color.cpp b/core/color.cpp
index efd2941b47..8959fce4e3 100644
--- a/core/color.cpp
+++ b/core/color.cpp
@@ -525,7 +525,7 @@ Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
float Color::gray() const {
ERR_EXPLAIN("Color.gray() is deprecated and will be removed in a future version. Use Color.get_v() for a better grayscale approximation.");
- WARN_DEPRECATED
+ WARN_DEPRECATED;
return (r + g + b) / 3.0;
}
diff --git a/core/color_names.inc b/core/color_names.inc
index e126bfe0f8..b0ef507d92 100644
--- a/core/color_names.inc
+++ b/core/color_names.inc
@@ -143,6 +143,7 @@ static void _populate_named_colors() {
_named_colors.insert("thistle", Color(0.85, 0.75, 0.85));
_named_colors.insert("tomato", Color(1.00, 0.39, 0.28));
_named_colors.insert("turquoise", Color(0.25, 0.88, 0.82));
+ _named_colors.insert("transparent", Color(1.00, 1.00, 1.00, 0.00));
_named_colors.insert("violet", Color(0.93, 0.51, 0.93));
_named_colors.insert("wheat", Color(0.96, 0.87, 0.70));
_named_colors.insert("white", Color(1.00, 1.00, 1.00));
diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h
index 59eabd8786..798fa4394d 100644
--- a/core/command_queue_mt.h
+++ b/core/command_queue_mt.h
@@ -406,8 +406,10 @@ class CommandQueueMT {
tryagain:
// tried to read an empty queue
- if (read_ptr == write_ptr)
+ if (read_ptr == write_ptr) {
+ if (p_lock) unlock();
return false;
+ }
uint32_t size_ptr = read_ptr;
uint32_t size = *(uint32_t *)&command_mem[read_ptr] >> 1;
diff --git a/core/core_string_names.cpp b/core/core_string_names.cpp
index 1b59508abf..eeaae96754 100644
--- a/core/core_string_names.cpp
+++ b/core/core_string_names.cpp
@@ -44,6 +44,7 @@ CoreStringNames::CoreStringNames() :
_iter_next(StaticCString::create("_iter_next")),
_iter_get(StaticCString::create("_iter_get")),
get_rid(StaticCString::create("get_rid")),
+ _to_string(StaticCString::create("_to_string")),
#ifdef TOOLS_ENABLED
_sections_unfolded(StaticCString::create("_sections_unfolded")),
#endif
diff --git a/core/core_string_names.h b/core/core_string_names.h
index 6fea40e1b2..85f8bb7f62 100644
--- a/core/core_string_names.h
+++ b/core/core_string_names.h
@@ -62,6 +62,7 @@ public:
StringName _iter_next;
StringName _iter_get;
StringName get_rid;
+ StringName _to_string;
#ifdef TOOLS_ENABLED
StringName _sections_unfolded;
#endif
diff --git a/core/engine.cpp b/core/engine.cpp
index 9607dedb3c..50822244cf 100644
--- a/core/engine.cpp
+++ b/core/engine.cpp
@@ -38,6 +38,7 @@
void Engine::set_iterations_per_second(int p_ips) {
+ ERR_FAIL_COND(p_ips <= 0);
ips = p_ips;
}
int Engine::get_iterations_per_second() const {
diff --git a/core/error_macros.h b/core/error_macros.h
index 78e29551d4..f72e987e23 100644
--- a/core/error_macros.h
+++ b/core/error_macros.h
@@ -41,7 +41,7 @@
*/
/**
- * Pointer to the error macro priting function. Reassign to any function to have errors printed
+ * Pointer to the error macro printing function. Reassign to any function to have errors printed
*/
/** Function used by the error macros */
diff --git a/core/func_ref.cpp b/core/func_ref.cpp
index 4a965473d9..3d03137d09 100644
--- a/core/func_ref.cpp
+++ b/core/func_ref.cpp
@@ -51,11 +51,23 @@ void FuncRef::set_instance(Object *p_obj) {
ERR_FAIL_NULL(p_obj);
id = p_obj->get_instance_id();
}
+
void FuncRef::set_function(const StringName &p_func) {
function = p_func;
}
+bool FuncRef::is_valid() const {
+ if (id == 0)
+ return false;
+
+ Object *obj = ObjectDB::get_instance(id);
+ if (!obj)
+ return false;
+
+ return obj->has_method(function);
+}
+
void FuncRef::_bind_methods() {
{
@@ -67,6 +79,7 @@ void FuncRef::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_instance", "instance"), &FuncRef::set_instance);
ClassDB::bind_method(D_METHOD("set_function", "name"), &FuncRef::set_function);
+ ClassDB::bind_method(D_METHOD("is_valid"), &FuncRef::is_valid);
}
FuncRef::FuncRef() :
diff --git a/core/func_ref.h b/core/func_ref.h
index 339279fdba..a143b58bf0 100644
--- a/core/func_ref.h
+++ b/core/func_ref.h
@@ -46,6 +46,7 @@ public:
Variant call_func(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
void set_instance(Object *p_obj);
void set_function(const StringName &p_func);
+ bool is_valid() const;
FuncRef();
};
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index fb90403226..671b3c545b 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -425,6 +425,16 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_X);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_GRIP);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_PAD);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_TRIGGER);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_AX);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_BY);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_MENU);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_MENU);
+
BIND_GLOBAL_ENUM_CONSTANT(JOY_SELECT);
BIND_GLOBAL_ENUM_CONSTANT(JOY_START);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_UP);
@@ -459,6 +469,12 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_L2);
BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_R2);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_ANALOG_TRIGGER);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_ANALOG_GRIP);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_TOUCHPADX);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_TOUCHPADY);
+
// midi
BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_OFF);
BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_ON);
diff --git a/core/hash_map.h b/core/hash_map.h
index 44459a3080..31332991de 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -162,20 +162,21 @@ private:
new_hash_table[i] = 0;
}
- for (int i = 0; i < (1 << hash_table_power); i++) {
+ if (hash_table) {
+ for (int i = 0; i < (1 << hash_table_power); i++) {
- while (hash_table[i]) {
+ while (hash_table[i]) {
- Element *se = hash_table[i];
- hash_table[i] = se->next;
- int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
- se->next = new_hash_table[new_pos];
- new_hash_table[new_pos] = se;
+ Element *se = hash_table[i];
+ hash_table[i] = se->next;
+ int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
+ se->next = new_hash_table[new_pos];
+ new_hash_table[new_pos] = se;
+ }
}
- }
- if (hash_table)
memdelete_arr(hash_table);
+ }
hash_table = new_hash_table;
hash_table_power = new_hash_table_power;
}
diff --git a/core/image.cpp b/core/image.cpp
index 99d5eab864..c85d7f6bcc 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -725,6 +725,131 @@ static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict
}
}
+#define LANCZOS_TYPE 3
+
+static float _lanczos(float p_x) {
+ return Math::abs(p_x) >= LANCZOS_TYPE ? 0 : Math::sincn(p_x) * Math::sincn(p_x / LANCZOS_TYPE);
+}
+
+template <int CC, class T>
+static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
+
+ int32_t src_width = p_src_width;
+ int32_t src_height = p_src_height;
+ int32_t dst_height = p_dst_height;
+ int32_t dst_width = p_dst_width;
+
+ uint32_t buffer_size = src_height * dst_width * CC;
+ float *buffer = memnew_arr(float, buffer_size); // Store the first pass in a buffer
+
+ { // FIRST PASS (horizontal)
+
+ float x_scale = float(src_width) / float(dst_width);
+
+ float scale_factor = MAX(x_scale, 1); // A larger kernel is required only when downscaling
+ int32_t half_kernel = LANCZOS_TYPE * scale_factor;
+
+ float *kernel = memnew_arr(float, half_kernel * 2);
+
+ for (int32_t buffer_x = 0; buffer_x < dst_width; buffer_x++) {
+
+ float src_real_x = buffer_x * x_scale;
+ int32_t src_x = src_real_x;
+
+ int32_t start_x = MAX(0, src_x - half_kernel + 1);
+ int32_t end_x = MIN(src_width - 1, src_x + half_kernel);
+
+ // Create the kernel used by all the pixels of the column
+ for (int32_t target_x = start_x; target_x <= end_x; target_x++)
+ kernel[target_x - start_x] = _lanczos((src_real_x - target_x) / scale_factor);
+
+ for (int32_t buffer_y = 0; buffer_y < src_height; buffer_y++) {
+
+ float pixel[CC] = { 0 };
+ float weight = 0;
+
+ for (int32_t target_x = start_x; target_x <= end_x; target_x++) {
+
+ float lanczos_val = kernel[target_x - start_x];
+ weight += lanczos_val;
+
+ const T *__restrict src_data = ((const T *)p_src) + (buffer_y * src_width + target_x) * CC;
+
+ for (uint32_t i = 0; i < CC; i++) {
+ if (sizeof(T) == 2) //half float
+ pixel[i] += Math::half_to_float(src_data[i]) * lanczos_val;
+ else
+ pixel[i] += src_data[i] * lanczos_val;
+ }
+ }
+
+ float *dst_data = ((float *)buffer) + (buffer_y * dst_width + buffer_x) * CC;
+
+ for (uint32_t i = 0; i < CC; i++)
+ dst_data[i] = pixel[i] / weight; // Normalize the sum of all the samples
+ }
+ }
+
+ memdelete_arr(kernel);
+ } // End of first pass
+
+ { // SECOND PASS (vertical + result)
+
+ float y_scale = float(src_height) / float(dst_height);
+
+ float scale_factor = MAX(y_scale, 1);
+ int32_t half_kernel = LANCZOS_TYPE * scale_factor;
+
+ float *kernel = memnew_arr(float, half_kernel * 2);
+
+ for (int32_t dst_y = 0; dst_y < dst_height; dst_y++) {
+
+ float buffer_real_y = dst_y * y_scale;
+ int32_t buffer_y = buffer_real_y;
+
+ int32_t start_y = MAX(0, buffer_y - half_kernel + 1);
+ int32_t end_y = MIN(src_height - 1, buffer_y + half_kernel);
+
+ for (int32_t target_y = start_y; target_y <= end_y; target_y++)
+ kernel[target_y - start_y] = _lanczos((buffer_real_y - target_y) / scale_factor);
+
+ for (int32_t dst_x = 0; dst_x < dst_width; dst_x++) {
+
+ float pixel[CC] = { 0 };
+ float weight = 0;
+
+ for (int32_t target_y = start_y; target_y <= end_y; target_y++) {
+
+ float lanczos_val = kernel[target_y - start_y];
+ weight += lanczos_val;
+
+ float *buffer_data = ((float *)buffer) + (target_y * dst_width + dst_x) * CC;
+
+ for (uint32_t i = 0; i < CC; i++)
+ pixel[i] += buffer_data[i] * lanczos_val;
+ }
+
+ T *dst_data = ((T *)p_dst) + (dst_y * dst_width + dst_x) * CC;
+
+ for (uint32_t i = 0; i < CC; i++) {
+ pixel[i] /= weight;
+
+ if (sizeof(T) == 1) //byte
+ dst_data[i] = CLAMP(Math::fast_ftoi(pixel[i]), 0, 255);
+ else if (sizeof(T) == 2) //half float
+ dst_data[i] = Math::make_half_float(pixel[i]);
+ else // float
+ dst_data[i] = pixel[i];
+ }
+ }
+ }
+
+ memdelete_arr(kernel);
+ } // End of second pass
+
+ memdelete_arr(buffer);
+}
+
static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, float p_alpha, uint32_t p_width, uint32_t p_height, uint32_t p_pixel_size) {
uint16_t alpha = CLAMP((uint16_t)(p_alpha * 256.0f), 0, 256);
@@ -939,6 +1064,31 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
}
}
} break;
+ case INTERPOLATE_LANCZOS: {
+
+ if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) {
+ switch (get_format_pixel_size(format)) {
+ case 1: _scale_lanczos<1, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 2: _scale_lanczos<2, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 3: _scale_lanczos<3, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 4: _scale_lanczos<4, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
+ } else if (format >= FORMAT_RF && format <= FORMAT_RGBAF) {
+ switch (get_format_pixel_size(format)) {
+ case 4: _scale_lanczos<1, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 8: _scale_lanczos<2, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 12: _scale_lanczos<3, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 16: _scale_lanczos<4, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
+ } else if (format >= FORMAT_RH && format <= FORMAT_RGBAH) {
+ switch (get_format_pixel_size(format)) {
+ case 2: _scale_lanczos<1, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 4: _scale_lanczos<2, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 6: _scale_lanczos<3, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 8: _scale_lanczos<4, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
+ }
+ } break;
}
r = PoolVector<uint8_t>::Read();
@@ -2685,6 +2835,7 @@ void Image::_bind_methods() {
BIND_ENUM_CONSTANT(INTERPOLATE_BILINEAR);
BIND_ENUM_CONSTANT(INTERPOLATE_CUBIC);
BIND_ENUM_CONSTANT(INTERPOLATE_TRILINEAR);
+ BIND_ENUM_CONSTANT(INTERPOLATE_LANCZOS);
BIND_ENUM_CONSTANT(ALPHA_NONE);
BIND_ENUM_CONSTANT(ALPHA_BIT);
diff --git a/core/image.h b/core/image.h
index 69a42f169a..752ef20208 100644
--- a/core/image.h
+++ b/core/image.h
@@ -109,6 +109,7 @@ public:
INTERPOLATE_BILINEAR,
INTERPOLATE_CUBIC,
INTERPOLATE_TRILINEAR,
+ INTERPOLATE_LANCZOS,
/* INTERPOLATE_TRICUBIC, */
/* INTERPOLATE GAUSS */
};
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 15f68f9c2a..012c6a7c4f 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -202,7 +202,7 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
if (p_pressed != NULL)
*p_pressed = input_event_action->is_pressed();
if (p_strength != NULL)
- *p_strength = (*p_pressed) ? 1.0f : 0.0f;
+ *p_strength = (*p_pressed) ? input_event_action->get_strength() : 0.0f;
return input_event_action->get_action() == p_action;
}
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index 414742deeb..871e21df3e 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -198,10 +198,6 @@ Error ConfigFile::load(const String &p_path) {
section = next_tag.name;
}
}
-
- memdelete(f);
-
- return OK;
}
void ConfigFile::_bind_methods() {
diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp
index 3cf6908961..7dea749a43 100644
--- a/core/io/file_access_encrypted.cpp
+++ b/core/io/file_access_encrypted.cpp
@@ -100,6 +100,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
MD5Update(&md5, (uint8_t *)data.ptr(), data.size());
MD5Final(&md5);
+ ERR_EXPLAIN("The MD5 sum of the decrypted file does not match the expected value. It could be that the file is corrupt, or that the provided decryption key is invalid.");
ERR_FAIL_COND_V(String::md5(md5.digest) != String::md5(md5d), ERR_FILE_CORRUPT);
file = p_base;
@@ -307,8 +308,8 @@ uint32_t FileAccessEncrypted::_get_unix_permissions(const String &p_file) {
}
Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t p_permissions) {
-
- return FAILED;
+ ERR_PRINT("Setting UNIX permissions on encrypted files is not implemented yet");
+ return ERR_UNAVAILABLE;
}
FileAccessEncrypted::FileAccessEncrypted() {
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 722e62c54e..5dd167c581 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -118,7 +118,10 @@ void FileAccessNetworkClient::_thread_func() {
FileAccessNetwork *fa = NULL;
if (response != FileAccessNetwork::RESPONSE_DATA) {
- ERR_FAIL_COND(!accesses.has(id));
+ if (!accesses.has(id)) {
+ unlock_mutex();
+ ERR_FAIL_COND(!accesses.has(id));
+ }
}
if (accesses.has(id))
@@ -498,13 +501,13 @@ uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
}
uint32_t FileAccessNetwork::_get_unix_permissions(const String &p_file) {
- //could be implemented, not sure if worth it
+ ERR_PRINT("Getting UNIX permissions from network drives is not implemented yet");
return 0;
}
Error FileAccessNetwork::_set_unix_permissions(const String &p_file, uint32_t p_permissions) {
-
- return FAILED;
+ ERR_PRINT("Setting UNIX permissions on network drives is not implemented yet");
+ return ERR_UNAVAILABLE;
}
void FileAccessNetwork::configure() {
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index e5c6d2a4f2..891fb7b0ca 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -346,6 +346,12 @@ Error HTTPClient::poll() {
} else {
// We are already handshaking, which means we can use your already active SSL connection
ssl = static_cast<Ref<StreamPeerSSL> >(connection);
+ if (ssl.is_null()) {
+ close();
+ status = STATUS_SSL_HANDSHAKE_ERROR;
+ return ERR_CANT_CONNECT;
+ }
+
ssl->poll(); // Try to finish the handshake
}
@@ -429,7 +435,7 @@ Error HTTPClient::poll() {
response_num = RESPONSE_OK;
// Per the HTTP 1.1 spec, keep-alive is the default.
- // Not following that specification breaks standard implemetations.
+ // Not following that specification breaks standard implementations.
// Broken web servers should be fixed.
bool keep_alive = true;
diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp
index a5a0738140..a759e615c7 100644
--- a/core/io/image_loader.cpp
+++ b/core/io/image_loader.cpp
@@ -65,6 +65,9 @@ Error ImageLoader::load_image(String p_file, Ref<Image> p_image, FileAccess *p_c
if (!loader[i]->recognize(extension))
continue;
Error err = loader[i]->load_image(p_image, f, p_force_linear, p_scale);
+ if (err != OK) {
+ ERR_PRINTS("Error loading image: " + p_file);
+ }
if (err != ERR_FILE_UNRECOGNIZED) {
diff --git a/core/io/image_loader.h b/core/io/image_loader.h
index 95c562b7a9..ae4b72a534 100644
--- a/core/io/image_loader.h
+++ b/core/io/image_loader.h
@@ -88,7 +88,6 @@ public:
};
class ResourceFormatLoaderImage : public ResourceFormatLoader {
- GDCLASS(ResourceFormatLoaderImage, ResourceFormatLoader)
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 81b3829ffc..d1b6b82cf0 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -1231,11 +1231,15 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
buf += 4;
PoolVector<uint8_t>::Read r = data.read();
copymem(buf, &r[0], datalen * datasize);
+ buf += datalen * datasize;
}
r_len += 4 + datalen * datasize;
- while (r_len % 4)
+ while (r_len % 4) {
r_len++;
+ if (buf)
+ *(buf++) = 0;
+ }
} break;
case Variant::POOL_INT_ARRAY: {
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 2e76ce68ed..2779837190 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -283,8 +283,9 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_name);
}
- ERR_EXPLAIN("RPC '" + String(p_name) + "' is not allowed from: " + itos(p_from) + ". Mode is " + itos((int)rpc_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
- ERR_FAIL_COND(!_can_call_mode(p_node, rpc_mode, p_from));
+ bool can_call = _can_call_mode(p_node, rpc_mode, p_from);
+ ERR_EXPLAIN("RPC '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rpc_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
+ ERR_FAIL_COND(!can_call);
int argc = p_packet[p_offset];
Vector<Variant> args;
@@ -332,8 +333,9 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p
rset_mode = p_node->get_script_instance()->get_rset_mode(p_name);
}
- ERR_EXPLAIN("RSET '" + String(p_name) + "' is not allowed from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
- ERR_FAIL_COND(!_can_call_mode(p_node, rset_mode, p_from));
+ bool can_call = _can_call_mode(p_node, rset_mode, p_from);
+ ERR_EXPLAIN("RSET '" + String(p_name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
+ ERR_FAIL_COND(!can_call);
Variant value;
Error err = decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset, NULL, allow_object_decoding || network_peer->is_object_decoding_allowed());
@@ -632,7 +634,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
ERR_FAIL_COND(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED);
int node_id = network_peer->get_unique_id();
- bool skip_rpc = false;
+ bool skip_rpc = node_id == p_peer_id;
bool call_local_native = false;
bool call_local_script = false;
bool is_master = p_node->is_network_master();
@@ -686,6 +688,9 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
return;
}
}
+
+ ERR_EXPLAIN("RPC '" + p_method + "' on yourself is not allowed by selected mode");
+ ERR_FAIL_COND(skip_rpc && !(call_local_native || call_local_script));
}
void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) {
@@ -699,13 +704,11 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
int node_id = network_peer->get_unique_id();
bool is_master = p_node->is_network_master();
- bool skip_rset = false;
+ bool skip_rset = node_id == p_peer_id;
+ bool set_local = false;
if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
// Check that send mode can use local call.
-
- bool set_local = false;
-
const Map<StringName, RPCMode>::Element *E = p_node->get_node_rset_mode(p_property);
if (E) {
@@ -747,8 +750,11 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
}
- if (skip_rset)
+ if (skip_rset) {
+ ERR_EXPLAIN("RSET for '" + p_property + "' on yourself is not allowed by selected mode");
+ ERR_FAIL_COND(!set_local);
return;
+ }
const Variant *vptr = &p_value;
diff --git a/core/io/resource_format_binary.h b/core/io/resource_format_binary.h
index a4894e4033..27777c8e8b 100644
--- a/core/io/resource_format_binary.h
+++ b/core/io/resource_format_binary.h
@@ -100,7 +100,6 @@ public:
};
class ResourceFormatLoaderBinary : public ResourceFormatLoader {
- GDCLASS(ResourceFormatLoaderBinary, ResourceFormatLoader)
public:
virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
@@ -162,7 +161,6 @@ public:
};
class ResourceFormatSaverBinary : public ResourceFormatSaver {
- GDCLASS(ResourceFormatSaverBinary, ResourceFormatSaver)
public:
static ResourceFormatSaverBinary *singleton;
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp
index 038a34ed51..4a58d37ca5 100644
--- a/core/io/resource_importer.cpp
+++ b/core/io/resource_importer.cpp
@@ -301,8 +301,7 @@ String ResourceFormatImporter::get_import_group_file(const String &p_path) const
bool valid = true;
PathAndType pat;
_get_path_and_type(p_path, pat, &valid);
- return valid?pat.group_file:String();
-
+ return valid ? pat.group_file : String();
}
bool ResourceFormatImporter::is_import_valid(const String &p_path) const {
diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h
index bdbdde6df6..317f301b5c 100644
--- a/core/io/resource_importer.h
+++ b/core/io/resource_importer.h
@@ -37,8 +37,6 @@ class ResourceImporter;
class ResourceFormatImporter : public ResourceFormatLoader {
- GDCLASS(ResourceFormatImporter, ResourceFormatLoader)
-
struct PathAndType {
String path;
String type;
@@ -126,7 +124,7 @@ public:
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL) = 0;
- virtual Error import_group_file(const String& p_group_file,const Map<String,Map<StringName, Variant> >&p_source_file_options, const Map<String,String>& p_base_paths) { return ERR_UNAVAILABLE; }
+ virtual Error import_group_file(const String &p_group_file, const Map<String, Map<StringName, Variant> > &p_source_file_options, const Map<String, String> &p_base_paths) { return ERR_UNAVAILABLE; }
virtual bool are_import_settings_valid(const String &p_path) const { return true; }
virtual String get_import_settings_string() const { return String(); }
};
diff --git a/core/io/translation_loader_po.h b/core/io/translation_loader_po.h
index d5fd264385..9d9c5d16ee 100644
--- a/core/io/translation_loader_po.h
+++ b/core/io/translation_loader_po.h
@@ -36,7 +36,6 @@
#include "core/translation.h"
class TranslationLoaderPO : public ResourceFormatLoader {
- GDCLASS(TranslationLoaderPO, ResourceFormatLoader)
public:
static RES load_translation(FileAccess *f, Error *r_error, const String &p_path = String());
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index 4638ddcc09..f55af5a96a 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -348,7 +348,7 @@ uint64_t XMLParser::get_node_offset() const {
Error XMLParser::seek(uint64_t p_pos) {
- ERR_FAIL_COND_V(!data, ERR_FILE_EOF)
+ ERR_FAIL_COND_V(!data, ERR_FILE_EOF);
ERR_FAIL_COND_V(p_pos >= length, ERR_FILE_EOF);
P = data + p_pos;
diff --git a/core/io/zip_io.h b/core/io/zip_io.h
index fb63878a4c..4eb1c8b46c 100644
--- a/core/io/zip_io.h
+++ b/core/io/zip_io.h
@@ -33,7 +33,7 @@
#include "core/os/file_access.h"
-// Not direclty used in this header, but assumed available in downstream users
+// Not directly used in this header, but assumed available in downstream users
// like platform/*/export/export.cpp. Could be fixed, but probably better to have
// thirdparty includes in as little headers as possible.
#include "thirdparty/minizip/unzip.h"
diff --git a/core/list.h b/core/list.h
index 103a82a31d..d1b528562d 100644
--- a/core/list.h
+++ b/core/list.h
@@ -602,9 +602,6 @@ public:
Element *next = current->next_ptr;
- //disconnect
- current->next_ptr = NULL;
-
if (from != current) {
current->prev_ptr = NULL;
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index e1388ad2ac..359446dde6 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -54,7 +54,8 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
pt->pos = p_pos;
pt->weight_scale = p_weight_scale;
pt->prev_point = NULL;
- pt->last_pass = 0;
+ pt->open_pass = 0;
+ pt->closed_pass = 0;
pt->enabled = true;
points[p_id] = pt;
} else {
@@ -98,14 +99,22 @@ void AStar::remove_point(int p_id) {
Point *p = points[p_id];
- Map<int, Point *>::Element *PE = points.front();
- while (PE) {
- for (Set<Point *>::Element *E = PE->get()->neighbours.front(); E; E = E->next()) {
- Segment s(p_id, E->get()->id);
- segments.erase(s);
- E->get()->neighbours.erase(p);
- }
- PE = PE->next();
+ for (Set<Point *>::Element *E = p->neighbours.front(); E; E = E->next()) {
+
+ Segment s(p_id, E->get()->id);
+ segments.erase(s);
+
+ E->get()->neighbours.erase(p);
+ E->get()->unlinked_neighbours.erase(p);
+ }
+
+ for (Set<Point *>::Element *E = p->unlinked_neighbours.front(); E; E = E->next()) {
+
+ Segment s(p_id, E->get()->id);
+ segments.erase(s);
+
+ E->get()->neighbours.erase(p);
+ E->get()->unlinked_neighbours.erase(p);
}
memdelete(p);
@@ -124,6 +133,8 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
if (bidirectional)
b->neighbours.insert(a);
+ else
+ b->unlinked_neighbours.insert(a);
Segment s(p_id, p_with_id);
if (s.from == p_id) {
@@ -146,7 +157,9 @@ void AStar::disconnect_points(int p_id, int p_with_id) {
Point *a = points[p_id];
Point *b = points[p_with_id];
a->neighbours.erase(b);
+ a->unlinked_neighbours.erase(b);
b->neighbours.erase(a);
+ b->unlinked_neighbours.erase(a);
}
bool AStar::has_point(int p_id) const {
@@ -246,86 +259,62 @@ bool AStar::_solve(Point *begin_point, Point *end_point) {
if (!end_point->enabled)
return false;
- SelfList<Point>::List open_list;
-
bool found_route = false;
- for (Set<Point *>::Element *E = begin_point->neighbours.front(); E; E = E->next()) {
+ Vector<Point *> open_list;
+ SortArray<Point *, SortPoints> sorter;
- Point *n = E->get();
+ begin_point->g_score = 0;
+ begin_point->f_score = _estimate_cost(begin_point->id, end_point->id);
- if (!n->enabled)
- continue;
-
- n->prev_point = begin_point;
- n->distance = _compute_cost(begin_point->id, n->id) * n->weight_scale;
- n->last_pass = pass;
- open_list.add(&n->list);
- }
+ open_list.push_back(begin_point);
while (true) {
- if (open_list.first() == NULL) {
- // No path found
+ if (open_list.size() == 0) // No path found
break;
- }
- // Check open list
-
- SelfList<Point> *least_cost_point = open_list.first();
- real_t least_cost = Math_INF;
- // TODO: Cache previous results
- for (SelfList<Point> *E = open_list.first(); E; E = E->next()) {
+ Point *p = open_list[0]; // The currently processed point
- Point *p = E->self();
-
- real_t cost = p->distance;
- cost += _estimate_cost(p->id, end_point->id);
-
- if (cost < least_cost) {
- least_cost_point = E;
- least_cost = cost;
- }
- }
-
- Point *p = least_cost_point->self();
if (p == end_point) {
found_route = true;
break;
}
+ sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list
+ open_list.remove(open_list.size() - 1);
+ p->closed_pass = pass; // Mark the point as closed
+
for (Set<Point *>::Element *E = p->neighbours.front(); E; E = E->next()) {
- Point *e = E->get();
+ Point *e = E->get(); // The neighbour point
- if (!e->enabled)
+ if (!e->enabled || e->closed_pass == pass)
continue;
- real_t distance = _compute_cost(p->id, e->id) * e->weight_scale + p->distance;
+ real_t tentative_g_score = p->g_score + _compute_cost(p->id, e->id) * e->weight_scale;
- if (e->last_pass == pass) {
- // Already visited, is this cheaper?
+ bool new_point = false;
- if (e->distance > distance) {
- e->prev_point = p;
- e->distance = distance;
- }
- } else {
- // Add to open neighbours
+ if (e->open_pass != pass) { // The point wasn't inside the open list
- e->prev_point = p;
- e->distance = distance;
- e->last_pass = pass; // Mark as used
- open_list.add(&e->list);
+ e->open_pass = pass;
+ open_list.push_back(e);
+ new_point = true;
+ } else if (tentative_g_score >= e->g_score) { // The new path is worse than the previous
+
+ continue;
}
- }
- open_list.remove(least_cost_point);
- }
+ e->prev_point = p;
+ e->g_score = tentative_g_score;
+ e->f_score = e->g_score + _estimate_cost(e->id, end_point->id);
- // Clear the openf list
- while (open_list.first()) {
- open_list.remove(open_list.first());
+ if (new_point) // The position of the new points is already known
+ sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
+ else
+ sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
+ }
}
return found_route;
@@ -352,8 +341,6 @@ PoolVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
ERR_FAIL_COND_V(!points.has(p_from_id), PoolVector<Vector3>());
ERR_FAIL_COND_V(!points.has(p_to_id), PoolVector<Vector3>());
- pass++;
-
Point *a = points[p_from_id];
Point *b = points[p_to_id];
@@ -403,8 +390,6 @@ PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
ERR_FAIL_COND_V(!points.has(p_from_id), PoolVector<int>());
ERR_FAIL_COND_V(!points.has(p_to_id), PoolVector<int>());
- pass++;
-
Point *a = points[p_from_id];
Point *b = points[p_to_id];
@@ -450,10 +435,16 @@ PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
}
void AStar::set_point_disabled(int p_id, bool p_disabled) {
+
+ ERR_FAIL_COND(!points.has(p_id));
+
points[p_id]->enabled = !p_disabled;
}
bool AStar::is_point_disabled(int p_id) const {
+
+ ERR_FAIL_COND_V(!points.has(p_id), false);
+
return !points[p_id]->enabled;
}
diff --git a/core/math/a_star.h b/core/math/a_star.h
index c63e1aa4dc..ba35d929b3 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -48,26 +48,35 @@ class AStar : public Reference {
struct Point {
- SelfList<Point> list;
-
int id;
Vector3 pos;
real_t weight_scale;
- uint64_t last_pass;
bool enabled;
Set<Point *> neighbours;
+ Set<Point *> unlinked_neighbours;
// Used for pathfinding
Point *prev_point;
- real_t distance;
-
- Point() :
- list(this) {}
+ real_t g_score;
+ real_t f_score;
+ uint64_t open_pass;
+ uint64_t closed_pass;
};
Map<int, Point *> points;
+ struct SortPoints {
+ _FORCE_INLINE_ bool operator()(const Point *A, const Point *B) const { // Returns true when the Point A is worse than Point B
+ if (A->f_score > B->f_score)
+ return true;
+ else if (A->f_score < B->f_score)
+ return false;
+ else
+ return A->g_score < B->g_score; // If the f_costs are the same then prioritize the points that are further away from the start
+ }
+ };
+
struct Segment {
union {
struct {
diff --git a/core/math/basis.cpp b/core/math/basis.cpp
index 9fcecd1ba6..1540bc8fe1 100644
--- a/core/math/basis.cpp
+++ b/core/math/basis.cpp
@@ -813,21 +813,28 @@ void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) {
ERR_FAIL_COND(!p_axis.is_normalized());
#endif
Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z);
-
real_t cosine = Math::cos(p_phi);
- real_t sine = Math::sin(p_phi);
-
elements[0][0] = axis_sq.x + cosine * (1.0 - axis_sq.x);
- elements[0][1] = p_axis.x * p_axis.y * (1.0 - cosine) - p_axis.z * sine;
- elements[0][2] = p_axis.z * p_axis.x * (1.0 - cosine) + p_axis.y * sine;
-
- elements[1][0] = p_axis.x * p_axis.y * (1.0 - cosine) + p_axis.z * sine;
elements[1][1] = axis_sq.y + cosine * (1.0 - axis_sq.y);
- elements[1][2] = p_axis.y * p_axis.z * (1.0 - cosine) - p_axis.x * sine;
-
- elements[2][0] = p_axis.z * p_axis.x * (1.0 - cosine) - p_axis.y * sine;
- elements[2][1] = p_axis.y * p_axis.z * (1.0 - cosine) + p_axis.x * sine;
elements[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z);
+
+ real_t sine = Math::sin(p_phi);
+ real_t t = 1 - cosine;
+
+ real_t xyzt = p_axis.x * p_axis.y * t;
+ real_t zyxs = p_axis.z * sine;
+ elements[0][1] = xyzt - zyxs;
+ elements[1][0] = xyzt + zyxs;
+
+ xyzt = p_axis.x * p_axis.z * t;
+ zyxs = p_axis.y * sine;
+ elements[0][2] = xyzt + zyxs;
+ elements[2][0] = xyzt - zyxs;
+
+ xyzt = p_axis.y * p_axis.z * t;
+ zyxs = p_axis.x * sine;
+ elements[1][2] = xyzt - zyxs;
+ elements[2][1] = xyzt + zyxs;
}
void Basis::set_axis_angle_scale(const Vector3 &p_axis, real_t p_phi, const Vector3 &p_scale) {
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 079c9b524f..e484e9194d 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -70,6 +70,7 @@ const char *Expression::func_name[Expression::FUNC_MAX] = {
"inverse_lerp",
"range_lerp",
"smoothstep",
+ "move_toward",
"dectime",
"randomize",
"randi",
@@ -189,6 +190,7 @@ int Expression::get_func_argument_count(BuiltinFunc p_func) {
case MATH_LERP:
case MATH_INVERSE_LERP:
case MATH_SMOOTHSTEP:
+ case MATH_MOVE_TOWARD:
case MATH_DECTIME:
case MATH_WRAP:
case MATH_WRAPF:
@@ -407,6 +409,13 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
VALIDATE_ARG_NUM(2);
*r_return = Math::smoothstep((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
} break;
+ case MATH_MOVE_TOWARD: {
+
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ VALIDATE_ARG_NUM(2);
+ *r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]);
+ } break;
case MATH_DECTIME: {
VALIDATE_ARG_NUM(0);
diff --git a/core/math/expression.h b/core/math/expression.h
index f20619f0b6..79f6f3989d 100644
--- a/core/math/expression.h
+++ b/core/math/expression.h
@@ -68,6 +68,7 @@ public:
MATH_INVERSE_LERP,
MATH_RANGE_LERP,
MATH_SMOOTHSTEP,
+ MATH_MOVE_TOWARD,
MATH_DECTIME,
MATH_RANDOMIZE,
MATH_RAND,
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index 0ab8707d3a..8314cb827c 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -31,8 +31,11 @@
#include "geometry.h"
#include "core/print_string.h"
+#include "thirdparty/misc/clipper.hpp"
#include "thirdparty/misc/triangulator.h"
+#define SCALE_FACTOR 100000.0 // based on CMP_EPSILON
+
/* this implementation is very inefficient, commenting unless bugs happen. See the other one.
bool Geometry::is_point_in_polygon(const Vector2 &p_point, const Vector<Vector2> &p_polygon) {
@@ -1134,3 +1137,106 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu
r_size = Size2(results[best].max_w, results[best].max_h);
}
+
+Vector<Vector<Point2> > Geometry::_polypaths_do_operation(PolyBooleanOperation p_op, const Vector<Point2> &p_polypath_a, const Vector<Point2> &p_polypath_b, bool is_a_open) {
+
+ using namespace ClipperLib;
+
+ ClipType op = ctUnion;
+
+ switch (p_op) {
+ case OPERATION_UNION: op = ctUnion; break;
+ case OPERATION_DIFFERENCE: op = ctDifference; break;
+ case OPERATION_INTERSECTION: op = ctIntersection; break;
+ case OPERATION_XOR: op = ctXor; break;
+ }
+ Path path_a, path_b;
+
+ // Need to scale points (Clipper's requirement for robust computation)
+ for (int i = 0; i != p_polypath_a.size(); ++i) {
+ path_a << IntPoint(p_polypath_a[i].x * SCALE_FACTOR, p_polypath_a[i].y * SCALE_FACTOR);
+ }
+ for (int i = 0; i != p_polypath_b.size(); ++i) {
+ path_b << IntPoint(p_polypath_b[i].x * SCALE_FACTOR, p_polypath_b[i].y * SCALE_FACTOR);
+ }
+ Clipper clp;
+ clp.AddPath(path_a, ptSubject, !is_a_open); // forward compatible with Clipper 10.0.0
+ clp.AddPath(path_b, ptClip, true); // polylines cannot be set as clip
+
+ Paths paths;
+
+ if (is_a_open) {
+ PolyTree tree; // needed to populate polylines
+ clp.Execute(op, tree);
+ OpenPathsFromPolyTree(tree, paths);
+ } else {
+ clp.Execute(op, paths); // works on closed polygons only
+ }
+ // Have to scale points down now
+ Vector<Vector<Point2> > polypaths;
+
+ for (Paths::size_type i = 0; i < paths.size(); ++i) {
+ Vector<Vector2> polypath;
+
+ const Path &scaled_path = paths[i];
+
+ for (Paths::size_type j = 0; j < scaled_path.size(); ++j) {
+ polypath.push_back(Point2(
+ static_cast<real_t>(scaled_path[j].X) / SCALE_FACTOR,
+ static_cast<real_t>(scaled_path[j].Y) / SCALE_FACTOR));
+ }
+ polypaths.push_back(polypath);
+ }
+ return polypaths;
+}
+
+Vector<Vector<Point2> > Geometry::_polypath_offset(const Vector<Point2> &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
+
+ using namespace ClipperLib;
+
+ JoinType jt = jtSquare;
+
+ switch (p_join_type) {
+ case JOIN_SQUARE: jt = jtSquare; break;
+ case JOIN_ROUND: jt = jtRound; break;
+ case JOIN_MITER: jt = jtMiter; break;
+ }
+
+ EndType et = etClosedPolygon;
+
+ switch (p_end_type) {
+ case END_POLYGON: et = etClosedPolygon; break;
+ case END_JOINED: et = etClosedLine; break;
+ case END_BUTT: et = etOpenButt; break;
+ case END_SQUARE: et = etOpenSquare; break;
+ case END_ROUND: et = etOpenRound; break;
+ }
+ ClipperOffset co;
+ Path path;
+
+ // Need to scale points (Clipper's requirement for robust computation)
+ for (int i = 0; i != p_polypath.size(); ++i) {
+ path << IntPoint(p_polypath[i].x * SCALE_FACTOR, p_polypath[i].y * SCALE_FACTOR);
+ }
+ co.AddPath(path, jt, et);
+
+ Paths paths;
+ co.Execute(paths, p_delta * SCALE_FACTOR); // inflate/deflate
+
+ // Have to scale points down now
+ Vector<Vector<Point2> > polypaths;
+
+ for (Paths::size_type i = 0; i < paths.size(); ++i) {
+ Vector<Vector2> polypath;
+
+ const Path &scaled_path = paths[i];
+
+ for (Paths::size_type j = 0; j < scaled_path.size(); ++j) {
+ polypath.push_back(Point2(
+ static_cast<real_t>(scaled_path[j].X) / SCALE_FACTOR,
+ static_cast<real_t>(scaled_path[j].Y) / SCALE_FACTOR));
+ }
+ polypaths.push_back(polypath);
+ }
+ return polypaths;
+}
diff --git a/core/math/geometry.h b/core/math/geometry.h
index f3a671aa9a..0e144e491f 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -31,6 +31,7 @@
#ifndef GEOMETRY_H
#define GEOMETRY_H
+#include "core/math/delaunay.h"
#include "core/math/face3.h"
#include "core/math/rect2.h"
#include "core/math/triangulate.h"
@@ -785,6 +786,91 @@ public:
return clipped;
}
+ enum PolyBooleanOperation {
+ OPERATION_UNION,
+ OPERATION_DIFFERENCE,
+ OPERATION_INTERSECTION,
+ OPERATION_XOR
+ };
+ enum PolyJoinType {
+ JOIN_SQUARE,
+ JOIN_ROUND,
+ JOIN_MITER
+ };
+ enum PolyEndType {
+ END_POLYGON,
+ END_JOINED,
+ END_BUTT,
+ END_SQUARE,
+ END_ROUND
+ };
+
+ static Vector<Vector<Point2> > merge_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) {
+
+ return _polypaths_do_operation(OPERATION_UNION, p_polygon_a, p_polygon_b);
+ }
+
+ static Vector<Vector<Point2> > clip_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) {
+
+ return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polygon_a, p_polygon_b);
+ }
+
+ static Vector<Vector<Point2> > intersect_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) {
+
+ return _polypaths_do_operation(OPERATION_INTERSECTION, p_polygon_a, p_polygon_b);
+ }
+
+ static Vector<Vector<Point2> > exclude_polygons_2d(const Vector<Point2> &p_polygon_a, const Vector<Point2> &p_polygon_b) {
+
+ return _polypaths_do_operation(OPERATION_XOR, p_polygon_a, p_polygon_b);
+ }
+
+ static Vector<Vector<Point2> > clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
+
+ return _polypaths_do_operation(OPERATION_DIFFERENCE, p_polyline, p_polygon, true);
+ }
+
+ static Vector<Vector<Point2> > intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
+
+ return _polypaths_do_operation(OPERATION_INTERSECTION, p_polyline, p_polygon, true);
+ }
+
+ static Vector<Vector<Point2> > offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
+
+ return _polypath_offset(p_polygon, p_delta, p_join_type, END_POLYGON);
+ }
+
+ static Vector<Vector<Point2> > offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
+
+ ERR_EXPLAIN("Attempt to offset a polyline like a polygon (use offset_polygon_2d instead).");
+ ERR_FAIL_COND_V(p_end_type == END_POLYGON, Vector<Vector<Point2> >());
+
+ return _polypath_offset(p_polygon, p_delta, p_join_type, p_end_type);
+ }
+
+ static Vector<Point2> transform_points_2d(const Vector<Point2> &p_points, const Transform2D &p_mat) {
+
+ Vector<Point2> points;
+
+ for (int i = 0; i < p_points.size(); ++i) {
+ points.push_back(p_mat.xform(p_points[i]));
+ }
+ return points;
+ }
+
+ static Vector<int> triangulate_delaunay_2d(const Vector<Vector2> &p_points) {
+
+ Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(p_points);
+ Vector<int> triangles;
+
+ for (int i = 0; i < tr.size(); i++) {
+ triangles.push_back(tr[i].points[0]);
+ triangles.push_back(tr[i].points[1]);
+ triangles.push_back(tr[i].points[2]);
+ }
+ return triangles;
+ }
+
static Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon) {
Vector<int> triangles;
@@ -833,7 +919,7 @@ public:
further_away_opposite.y = MIN(p[i].y, further_away_opposite.y);
}
- further_away += (further_away - further_away_opposite) * Vector2(1.221313, 1.512312); // make point outside that wont intersect with points in segment from p_point
+ further_away += (further_away - further_away_opposite) * Vector2(1.221313, 1.512312); // make point outside that won't intersect with points in segment from p_point
int intersections = 0;
for (int i = 0; i < c; i++) {
@@ -951,7 +1037,6 @@ public:
H.resize(k);
return H;
}
-
static Vector<Vector<Vector2> > decompose_polygon_in_convex(Vector<Point2> polygon);
static MeshData build_convex_mesh(const PoolVector<Plane> &p_planes);
@@ -961,6 +1046,10 @@ public:
static PoolVector<Plane> build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis = Vector3::AXIS_Z);
static void make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size);
+
+private:
+ static Vector<Vector<Point2> > _polypaths_do_operation(PolyBooleanOperation p_op, const Vector<Point2> &p_polypath_a, const Vector<Point2> &p_polypath_b, bool is_a_open = false);
+ static Vector<Vector<Point2> > _polypath_offset(const Vector<Point2> &p_polypath, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type);
};
#endif
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index a75f2fb4ab..0e3bd8a318 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -61,6 +61,12 @@ public:
static _ALWAYS_INLINE_ double sinh(double p_x) { return ::sinh(p_x); }
static _ALWAYS_INLINE_ float sinh(float p_x) { return ::sinhf(p_x); }
+ static _ALWAYS_INLINE_ float sinc(float p_x) { return p_x == 0 ? 1 : ::sin(p_x) / p_x; }
+ static _ALWAYS_INLINE_ double sinc(double p_x) { return p_x == 0 ? 1 : ::sin(p_x) / p_x; }
+
+ static _ALWAYS_INLINE_ float sincn(float p_x) { return sinc(Math_PI * p_x); }
+ static _ALWAYS_INLINE_ double sincn(double p_x) { return sinc(Math_PI * p_x); }
+
static _ALWAYS_INLINE_ double cosh(double p_x) { return ::cosh(p_x); }
static _ALWAYS_INLINE_ float cosh(float p_x) { return ::coshf(p_x); }
@@ -218,6 +224,8 @@ public:
float x = CLAMP((p_weight - p_from) / (p_to - p_from), 0.0f, 1.0f);
return x * x * (3.0f - 2.0f * x);
}
+ static _ALWAYS_INLINE_ double move_toward(double p_from, double p_to, double p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SGN(p_to - p_from) * p_delta; }
+ static _ALWAYS_INLINE_ float move_toward(float p_from, float p_to, float p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SGN(p_to - p_from) * p_delta; }
static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; }
static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; }
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h
index 6b6bcdd2cd..a6182a4b33 100644
--- a/core/math/random_number_generator.h
+++ b/core/math/random_number_generator.h
@@ -59,7 +59,10 @@ public:
_FORCE_INLINE_ int randi_range(int from, int to) {
unsigned int ret = randbase.rand();
- return ret % (to - from + 1) + from;
+ if (to < from)
+ return ret % (from - to + 1) + to;
+ else
+ return ret % (to - from + 1) + from;
}
RandomNumberGenerator();
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp
index 8351bd138e..00c0af515d 100644
--- a/core/math/random_pcg.cpp
+++ b/core/math/random_pcg.cpp
@@ -43,13 +43,9 @@ void RandomPCG::randomize() {
}
double RandomPCG::random(double p_from, double p_to) {
- unsigned int r = rand();
- double ret = (double)r / (double)RANDOM_MAX;
- return (ret) * (p_to - p_from) + p_from;
+ return randd() * (p_to - p_from) + p_from;
}
float RandomPCG::random(float p_from, float p_to) {
- unsigned int r = rand();
- float ret = (float)r / (float)RANDOM_MAX;
- return (ret) * (p_to - p_from) + p_from;
+ return randf() * (p_to - p_from) + p_from;
}
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index 0d1b311c0d..aa25914638 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -37,6 +37,28 @@
#include "thirdparty/misc/pcg.h"
+#if defined(__GNUC__) || (_llvm_has_builtin(__builtin_clz))
+#define CLZ32(x) __builtin_clz(x)
+#elif defined(_MSC_VER)
+#include "intrin.h"
+static int __bsr_clz32(uint32_t x) {
+ unsigned long index;
+ _BitScanReverse(&index, x);
+ return 31 - index;
+}
+#define CLZ32(x) __bsr_clz32(x)
+#else
+#endif
+
+#if defined(__GNUC__) || (_llvm_has_builtin(__builtin_ldexp) && _llvm_has_builtin(__builtin_ldexpf))
+#define LDEXP(s, e) __builtin_ldexp(s, e)
+#define LDEXPF(s, e) __builtin_ldexpf(s, e)
+#else
+#include "math.h"
+#define LDEXP(s, e) ldexp(s, e)
+#define LDEXPF(s, e) ldexp(s, e)
+#endif
+
class RandomPCG {
pcg32_random_t pcg;
uint64_t current_seed; // seed with this to get the same state
@@ -60,8 +82,44 @@ public:
current_seed = pcg.state;
return pcg32_random_r(&pcg);
}
- _FORCE_INLINE_ double randd() { return (double)rand() / (double)RANDOM_MAX; }
- _FORCE_INLINE_ float randf() { return (float)rand() / (float)RANDOM_MAX; }
+
+ // Obtaining floating point numbers in [0, 1] range with "good enough" uniformity.
+ // These functions sample the output of rand() as the fraction part of an infinite binary number,
+ // with some tricks applied to reduce ops and branching:
+ // 1. Instead of shifting to the first 1 and connecting random bits, we simply set the MSB and LSB to 1.
+ // Provided that the RNG is actually uniform bit by bit, this should have the exact same effect.
+ // 2. In order to compensate for exponent info loss, we count zeros from another random number,
+ // and just add that to the initial offset.
+ // This has the same probability as counting and shifting an actual bit stream: 2^-n for n zeroes.
+ // For all numbers above 2^-96 (2^-64 for floats), the functions should be uniform.
+ // However, all numbers below that threshold are floored to 0.
+ // The thresholds are chosen to minimize rand() calls while keeping the numbers within a totally subjective quality standard.
+ // If clz or ldexp isn't available, fall back to bit truncation for performance, sacrificing uniformity.
+ _FORCE_INLINE_ double randd() {
+#if defined(CLZ32)
+ uint32_t proto_exp_offset = rand();
+ if (unlikely(proto_exp_offset == 0)) {
+ return 0;
+ }
+ uint64_t significand = (((uint64_t)rand()) << 32) | rand() | 0x8000000000000001U;
+ return LDEXP((double)significand, -64 - CLZ32(proto_exp_offset));
+#else
+#pragma message("RandomPCG::randd - intrinsic clz is not available, falling back to bit truncation")
+ return (double)(((((uint64_t)rand()) << 32) | rand()) & 0x1FFFFFFFFFFFFFU) / (double)0x1FFFFFFFFFFFFFU;
+#endif
+ }
+ _FORCE_INLINE_ float randf() {
+#if defined(CLZ32)
+ uint32_t proto_exp_offset = rand();
+ if (unlikely(proto_exp_offset == 0)) {
+ return 0;
+ }
+ return LDEXPF((float)(rand() | 0x80000001), -32 - CLZ32(proto_exp_offset));
+#else
+#pragma message("RandomPCG::randf - intrinsic clz is not available, falling back to bit truncation")
+ return (float)(rand() & 0xFFFFFF) / (float)0xFFFFFF;
+#endif
+ }
_FORCE_INLINE_ double randfn(double p_mean, double p_deviation) {
return p_mean + p_deviation * (cos(Math_TAU * randd()) * sqrt(-2.0 * log(randd()))); // Box-Muller transform
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp
index 5c1ea5943d..779a28be66 100644
--- a/core/math/vector2.cpp
+++ b/core/math/vector2.cpp
@@ -164,6 +164,13 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
return out;
}
+Vector2 Vector2::move_toward(const Vector2 &p_to, const real_t p_delta) const {
+ Vector2 v = *this;
+ Vector2 vd = p_to - v;
+ real_t len = vd.length();
+ return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta;
+}
+
// slide returns the component of the vector along the given plane, specified by its normal vector.
Vector2 Vector2::slide(const Vector2 &p_normal) const {
#ifdef MATH_CHECKS
diff --git a/core/math/vector2.h b/core/math/vector2.h
index a0c6024c9f..78a1641c1e 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -79,6 +79,7 @@ struct Vector2 {
_FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const;
_FORCE_INLINE_ Vector2 slerp(const Vector2 &p_b, real_t p_t) const;
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
+ Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const;
Vector2 slide(const Vector2 &p_normal) const;
Vector2 bounce(const Vector2 &p_normal) const;
diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp
index 1c28934422..73927821cf 100644
--- a/core/math/vector3.cpp
+++ b/core/math/vector3.cpp
@@ -127,6 +127,13 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, c
return out;
}
+Vector3 Vector3::move_toward(const Vector3 &p_to, const real_t p_delta) const {
+ Vector3 v = *this;
+ Vector3 vd = p_to - v;
+ real_t len = vd.length();
+ return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta;
+}
+
Vector3::operator String() const {
return (rtos(x) + ", " + rtos(y) + ", " + rtos(z));
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 21fc09653f..811a207138 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -94,6 +94,7 @@ struct Vector3 {
_FORCE_INLINE_ Vector3 slerp(const Vector3 &p_b, real_t p_t) const;
Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
Vector3 cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
+ Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const;
_FORCE_INLINE_ Vector3 cross(const Vector3 &p_b) const;
_FORCE_INLINE_ real_t dot(const Vector3 &p_b) const;
@@ -223,7 +224,7 @@ Vector3 Vector3::slerp(const Vector3 &p_b, real_t p_t) const {
#endif
real_t theta = angle_to(p_b);
- return rotated(cross(p_b), theta * p_t);
+ return rotated(cross(p_b).normalized(), theta * p_t);
}
real_t Vector3::distance_to(const Vector3 &p_b) const {
diff --git a/core/message_queue.cpp b/core/message_queue.cpp
index c57bd4081c..32d2b805f6 100644
--- a/core/message_queue.cpp
+++ b/core/message_queue.cpp
@@ -58,7 +58,7 @@ Error MessageQueue::push_call(ObjectID p_id, const StringName &p_method, const V
Message *msg = memnew_placement(&buffer[buffer_end], Message);
msg->args = p_argcount;
- msg->instance_ID = p_id;
+ msg->instance_id = p_id;
msg->target = p_method;
msg->type = TYPE_CALL;
if (p_show_error)
@@ -109,7 +109,7 @@ Error MessageQueue::push_set(ObjectID p_id, const StringName &p_prop, const Vari
Message *msg = memnew_placement(&buffer[buffer_end], Message);
msg->args = 1;
- msg->instance_ID = p_id;
+ msg->instance_id = p_id;
msg->target = p_prop;
msg->type = TYPE_SET;
@@ -143,7 +143,7 @@ Error MessageQueue::push_notification(ObjectID p_id, int p_notification) {
Message *msg = memnew_placement(&buffer[buffer_end], Message);
msg->type = TYPE_NOTIFICATION;
- msg->instance_ID = p_id;
+ msg->instance_id = p_id;
//msg->target;
msg->notification = p_notification;
@@ -177,7 +177,7 @@ void MessageQueue::statistics() {
while (read_pos < buffer_end) {
Message *message = (Message *)&buffer[read_pos];
- Object *target = ObjectDB::get_instance(message->instance_ID);
+ Object *target = ObjectDB::get_instance(message->instance_id);
if (target != NULL) {
@@ -289,7 +289,7 @@ void MessageQueue::flush() {
_THREAD_SAFE_UNLOCK_
- Object *target = ObjectDB::get_instance(message->instance_ID);
+ Object *target = ObjectDB::get_instance(message->instance_id);
if (target != NULL) {
@@ -302,10 +302,6 @@ void MessageQueue::flush() {
_call_function(target, message->target, args, message->args, message->type & FLAG_SHOW_ERROR);
- for (int i = 0; i < message->args; i++) {
- args[i].~Variant();
- }
-
} break;
case TYPE_NOTIFICATION: {
@@ -319,11 +315,17 @@ void MessageQueue::flush() {
// messages don't expect a return value
target->set(message->target, *arg);
- arg->~Variant();
} break;
}
}
+ if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
+ Variant *args = (Variant *)(message + 1);
+ for (int i = 0; i < message->args; i++) {
+ args[i].~Variant();
+ }
+ }
+
message->~Message();
_THREAD_SAFE_LOCK_
diff --git a/core/message_queue.h b/core/message_queue.h
index 2515eb4a98..026d17ad3f 100644
--- a/core/message_queue.h
+++ b/core/message_queue.h
@@ -54,7 +54,7 @@ class MessageQueue {
struct Message {
- ObjectID instance_ID;
+ ObjectID instance_id;
StringName target;
int16_t type;
union {
diff --git a/core/object.cpp b/core/object.cpp
index f860423a27..64f55f08a9 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -608,18 +608,16 @@ Variant Object::get_indexed(const Vector<StringName> &p_names, bool *r_valid) co
}
bool valid = false;
- Variant current_value = get(p_names[0]);
+ Variant current_value = get(p_names[0], &valid);
for (int i = 1; i < p_names.size(); i++) {
current_value = current_value.get_named(p_names[i], &valid);
- if (!valid) {
- if (r_valid)
- *r_valid = false;
- return Variant();
- }
+ if (!valid)
+ break;
}
if (r_valid)
- *r_valid = true;
+ *r_valid = valid;
+
return current_value;
}
@@ -956,6 +954,16 @@ void Object::notification(int p_notification, bool p_reversed) {
}
}
+String Object::to_string() {
+ if (script_instance) {
+ bool valid;
+ String ret = script_instance->to_string(&valid);
+ if (valid)
+ return ret;
+ }
+ return "[" + get_class() + ":" + itos(get_instance_id()) + "]";
+}
+
void Object::_changed_callback(Object *p_changed, const char *p_prop) {
}
@@ -1689,6 +1697,7 @@ void Object::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_property_list"), &Object::_get_property_list_bind);
ClassDB::bind_method(D_METHOD("get_method_list"), &Object::_get_method_list_bind);
ClassDB::bind_method(D_METHOD("notification", "what", "reversed"), &Object::notification, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("to_string"), &Object::to_string);
ClassDB::bind_method(D_METHOD("get_instance_id"), &Object::get_instance_id);
ClassDB::bind_method(D_METHOD("set_script", "script"), &Object::set_script);
@@ -1776,6 +1785,7 @@ void Object::_bind_methods() {
#endif
BIND_VMETHOD(MethodInfo("_init"));
+ BIND_VMETHOD(MethodInfo(Variant::STRING, "_to_string"));
BIND_CONSTANT(NOTIFICATION_POSTINITIALIZE);
BIND_CONSTANT(NOTIFICATION_PREDELETE);
@@ -1947,8 +1957,8 @@ Object::Object() {
_class_ptr = NULL;
_block_signals = false;
_predelete_ok = 0;
- _instance_ID = 0;
- _instance_ID = ObjectDB::add_instance(this);
+ _instance_id = 0;
+ _instance_id = ObjectDB::add_instance(this);
_can_translate = true;
_is_queued_for_deletion = false;
instance_binding_count = 0;
@@ -2002,7 +2012,7 @@ Object::~Object() {
}
ObjectDB::remove_instance(this);
- _instance_ID = 0;
+ _instance_id = 0;
_predelete_ok = 2;
if (!ScriptServer::are_languages_finished()) {
@@ -2050,10 +2060,10 @@ void ObjectDB::remove_instance(Object *p_object) {
rw_lock->write_unlock();
}
-Object *ObjectDB::get_instance(ObjectID p_instance_ID) {
+Object *ObjectDB::get_instance(ObjectID p_instance_id) {
rw_lock->read_lock();
- Object **obj = instances.getptr(p_instance_ID);
+ Object **obj = instances.getptr(p_instance_id);
rw_lock->read_unlock();
if (!obj)
diff --git a/core/object.h b/core/object.h
index 94abaacdcc..4394c1c3da 100644
--- a/core/object.h
+++ b/core/object.h
@@ -465,7 +465,7 @@ private:
bool _block_signals;
int _predelete_ok;
Set<Object *> change_receptors;
- ObjectID _instance_ID;
+ ObjectID _instance_id;
bool _predelete();
void _postinitialize();
bool _can_translate;
@@ -577,7 +577,7 @@ public:
bool _is_gpl_reversed() const { return false; }
- _FORCE_INLINE_ ObjectID get_instance_id() const { return _instance_ID; }
+ _FORCE_INLINE_ ObjectID get_instance_id() const { return _instance_id; }
// this is used for editors
void add_change_receptor(Object *p_receptor);
@@ -659,6 +659,7 @@ public:
void call_multilevel(const StringName &p_name, VARIANT_ARG_LIST); // C++ helper
void notification(int p_notification, bool p_reversed = false);
+ String to_string();
//used mainly by script, get and set all INCLUDING string
virtual Variant getvar(const Variant &p_key, bool *r_valid = NULL) const;
@@ -776,7 +777,7 @@ class ObjectDB {
public:
typedef void (*DebugFunc)(Object *p_obj);
- static Object *get_instance(ObjectID p_instance_ID);
+ static Object *get_instance(ObjectID p_instance_id);
static void debug_objects(DebugFunc p_func);
static int get_object_count();
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 25a5c2afeb..9c5066da3d 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -717,8 +717,17 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool *
bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
if (p_pressed != NULL)
*p_pressed = pressed;
- if (p_strength != NULL)
- *p_strength = pressed ? CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f) : 0.0f;
+ if (p_strength != NULL) {
+ if (pressed) {
+ if (p_deadzone == 1.0f) {
+ *p_strength = 1.0f;
+ } else {
+ *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f);
+ }
+ } else {
+ *p_strength = 0.0f;
+ }
+ }
}
return match;
}
@@ -1001,6 +1010,14 @@ bool InputEventAction::is_pressed() const {
return pressed;
}
+void InputEventAction::set_strength(float p_strength) {
+ strength = CLAMP(p_strength, 0.0f, 1.0f);
+}
+
+float InputEventAction::get_strength() const {
+ return strength;
+}
+
bool InputEventAction::shortcut_match(const Ref<InputEvent> &p_event) const {
if (p_event.is_null())
return false;
@@ -1042,14 +1059,19 @@ void InputEventAction::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
//ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
+ ClassDB::bind_method(D_METHOD("set_strength", "strength"), &InputEventAction::set_strength);
+ ClassDB::bind_method(D_METHOD("get_strength"), &InputEventAction::get_strength);
+
// ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
}
InputEventAction::InputEventAction() {
pressed = false;
+ strength = 1.0f;
}
/////////////////////////////
diff --git a/core/os/input_event.h b/core/os/input_event.h
index ba01516519..2eb321f134 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -117,6 +117,16 @@ enum JoystickList {
JOY_WII_MINUS = JOY_BUTTON_10,
JOY_WII_PLUS = JOY_BUTTON_11,
+ JOY_VR_GRIP = JOY_BUTTON_2,
+ JOY_VR_PAD = JOY_BUTTON_14,
+ JOY_VR_TRIGGER = JOY_BUTTON_15,
+
+ JOY_OCULUS_AX = JOY_BUTTON_7,
+ JOY_OCULUS_BY = JOY_BUTTON_1,
+ JOY_OCULUS_MENU = JOY_BUTTON_3,
+
+ JOY_OPENVR_MENU = JOY_BUTTON_1,
+
// end of history
JOY_AXIS_0 = 0,
@@ -139,6 +149,12 @@ enum JoystickList {
JOY_ANALOG_L2 = JOY_AXIS_6,
JOY_ANALOG_R2 = JOY_AXIS_7,
+
+ JOY_VR_ANALOG_TRIGGER = JOY_AXIS_2,
+ JOY_VR_ANALOG_GRIP = JOY_AXIS_4,
+
+ JOY_OPENVR_TOUCHPADX = JOY_AXIS_0,
+ JOY_OPENVR_TOUCHPADY = JOY_AXIS_1,
};
enum MidiMessageList {
@@ -475,6 +491,7 @@ class InputEventAction : public InputEvent {
StringName action;
bool pressed;
+ float strength;
protected:
static void _bind_methods();
@@ -486,6 +503,9 @@ public:
void set_pressed(bool p_pressed);
virtual bool is_pressed() const;
+ void set_strength(float p_strength);
+ float get_strength() const;
+
virtual bool is_action(const StringName &p_action) const;
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
diff --git a/core/os/os.cpp b/core/os/os.cpp
index ea378c9e83..1a3c9ac5f8 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -465,6 +465,9 @@ void OS::_ensure_user_data_dir() {
memdelete(da);
}
+void OS::set_native_icon(const String &p_filename) {
+}
+
void OS::set_icon(const Ref<Image> &p_icon) {
}
diff --git a/core/os/os.h b/core/os/os.h
index 4ae8a354e5..514e1e2ad3 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -104,7 +104,6 @@ public:
bool maximized;
bool always_on_top;
bool use_vsync;
- bool layered_splash;
bool layered;
float get_aspect() const { return (float)width / (float)height; }
VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false) {
@@ -117,7 +116,6 @@ public:
always_on_top = p_always_on_top;
use_vsync = p_use_vsync;
layered = false;
- layered_splash = false;
}
};
@@ -207,8 +205,12 @@ public:
virtual int get_screen_dpi(int p_screen = -1) const { return 72; }
virtual Point2 get_window_position() const { return Vector2(); }
virtual void set_window_position(const Point2 &p_position) {}
+ virtual Size2 get_max_window_size() const { return Size2(); };
+ virtual Size2 get_min_window_size() const { return Size2(); };
virtual Size2 get_window_size() const = 0;
virtual Size2 get_real_window_size() const { return get_window_size(); }
+ virtual void set_min_window_size(const Size2 p_size) {}
+ virtual void set_max_window_size(const Size2 p_size) {}
virtual void set_window_size(const Size2 p_size) {}
virtual void set_window_fullscreen(bool p_enabled) {}
virtual bool is_window_fullscreen() const { return true; }
@@ -273,7 +275,7 @@ public:
virtual String get_environment(const String &p_var) const = 0;
virtual bool set_environment(const String &p_var, const String &p_value) const = 0;
- virtual String get_name() = 0;
+ virtual String get_name() const = 0;
virtual List<String> get_cmdline_args() const { return _cmdline; }
virtual String get_model_name() const;
@@ -451,6 +453,7 @@ public:
virtual void make_rendering_thread();
virtual void swap_buffers();
+ virtual void set_native_icon(const String &p_filename);
virtual void set_icon(const Ref<Image> &p_icon);
virtual int get_exit_code() const;
diff --git a/core/print_string.cpp b/core/print_string.cpp
index d91d49f53b..3271744af3 100644
--- a/core/print_string.cpp
+++ b/core/print_string.cpp
@@ -68,8 +68,8 @@ void remove_print_handler(PrintHandlerList *p_handler) {
}
//OS::get_singleton()->print("print handler list is %p\n",print_handler_list);
- ERR_FAIL_COND(l == NULL);
_global_unlock();
+ ERR_FAIL_COND(l == NULL);
}
void print_line(String p_string) {
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index c86d1567dd..0508806a35 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -75,11 +75,19 @@ String ProjectSettings::localize_path(const String &p_path) const {
memdelete(dir);
- if (!cwd.begins_with(resource_path)) {
+ // Ensure that we end with a '/'.
+ // This is important to ensure that we do not wrongly localize the resource path
+ // in an absolute path that just happens to contain this string but points to a
+ // different folder (e.g. "/my/project" as resource_path would be contained in
+ // "/my/project_data", even though the latter is not part of res://.
+ // `plus_file("")` is an easy way to ensure we have a trailing '/'.
+ const String res_path = resource_path.plus_file("");
+
+ if (!cwd.begins_with(res_path)) {
return p_path;
};
- return cwd.replace_first(resource_path, "res:/");
+ return cwd.replace_first(res_path, "res://");
} else {
memdelete(dir);
@@ -481,7 +489,7 @@ Error ProjectSettings::_load_settings_binary(const String p_path) {
memdelete(f);
ERR_EXPLAIN("Corrupted header in binary project.binary (not ECFG)");
- ERR_FAIL_V(ERR_FILE_CORRUPT;)
+ ERR_FAIL_V(ERR_FILE_CORRUPT);
}
uint32_t count = f->get_32();
@@ -571,10 +579,6 @@ Error ProjectSettings::_load_settings_text(const String p_path) {
section = next_tag.name;
}
}
-
- memdelete(f);
-
- return OK;
}
Error ProjectSettings::_load_settings_text_or_binary(const String p_text_path, const String p_bin_path) {
@@ -632,7 +636,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
if (err != OK) {
ERR_EXPLAIN("Couldn't save project.binary at " + p_file);
- ERR_FAIL_COND_V(err, err)
+ ERR_FAIL_COND_V(err, err);
}
uint8_t hdr[4] = { 'E', 'C', 'F', 'G' };
@@ -724,7 +728,7 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
if (err) {
ERR_EXPLAIN("Couldn't save project.godot - " + p_file);
- ERR_FAIL_COND_V(err, err)
+ ERR_FAIL_COND_V(err, err);
}
file->store_line("; Engine configuration file.");
@@ -1007,6 +1011,15 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("audio/default_bus_layout", "res://default_bus_layout.tres");
custom_prop_info["audio/default_bus_layout"] = PropertyInfo(Variant::STRING, "audio/default_bus_layout", PROPERTY_HINT_FILE, "*.tres");
+ PoolStringArray extensions = PoolStringArray();
+ extensions.push_back("gd");
+ if (Engine::get_singleton()->has_singleton("GodotSharp"))
+ extensions.push_back("cs");
+ extensions.push_back("shader");
+
+ GLOBAL_DEF("editor/search_in_file_extensions", extensions);
+ custom_prop_info["editor/search_in_file_extensions"] = PropertyInfo(Variant::POOL_STRING_ARRAY, "editor/search_in_file_extensions");
+
action = Dictionary();
action["deadzone"] = Variant(0.5f);
events = Array();
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 4a6f904f9d..97758ced66 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -30,6 +30,7 @@
#include "script_language.h"
+#include "core/core_string_names.h"
#include "core/project_settings.h"
ScriptLanguage *ScriptServer::_languages[MAX_LANGUAGES];
diff --git a/core/script_language.h b/core/script_language.h
index 005e21e2cc..b0c60b4e90 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -173,6 +173,11 @@ public:
virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount);
virtual void notification(int p_notification) = 0;
+ virtual String to_string(bool *r_valid) {
+ if (r_valid)
+ *r_valid = false;
+ return String();
+ }
//this is used by script languages that keep a reference counter of their own
//you can make make Ref<> not die when it reaches zero, so deleting the reference
@@ -245,7 +250,7 @@ public:
virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { return ERR_UNAVAILABLE; }
virtual bool overrides_external_editor() { return false; }
- virtual Error complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; }
+ virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<String> *r_options, bool &r_force, String &r_call_hint) { return ERR_UNAVAILABLE; }
struct LookupResult {
enum Type {
@@ -264,7 +269,7 @@ public:
int location;
};
- virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_base_path, Object *p_owner, LookupResult &r_result) { return ERR_UNAVAILABLE; }
+ virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { return ERR_UNAVAILABLE; }
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const = 0;
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) = 0;
diff --git a/core/sort_array.h b/core/sort_array.h
index 0f258aec3e..8660ee3333 100644
--- a/core/sort_array.h
+++ b/core/sort_array.h
@@ -179,14 +179,14 @@ public:
while (true) {
while (compare(p_array[p_first], p_pivot)) {
if (Validate) {
- ERR_BAD_COMPARE(p_first == unmodified_last - 1)
+ ERR_BAD_COMPARE(p_first == unmodified_last - 1);
}
p_first++;
}
p_last--;
while (compare(p_pivot, p_array[p_last])) {
if (Validate) {
- ERR_BAD_COMPARE(p_last == unmodified_first)
+ ERR_BAD_COMPARE(p_last == unmodified_first);
}
p_last--;
}
@@ -259,7 +259,7 @@ public:
int next = p_last - 1;
while (compare(p_value, p_array[next])) {
if (Validate) {
- ERR_BAD_COMPARE(next == 0)
+ ERR_BAD_COMPARE(next == 0);
}
p_array[p_last] = p_array[next];
p_last = next;
diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp
index 69581e4115..f7ca6d3bde 100644
--- a/core/undo_redo.cpp
+++ b/core/undo_redo.cpp
@@ -239,8 +239,8 @@ void UndoRedo::_pop_history_tail() {
}
}
-bool UndoRedo::is_commiting_action() const {
- return commiting > 0;
+bool UndoRedo::is_committing_action() const {
+ return committing > 0;
}
void UndoRedo::commit_action() {
@@ -255,9 +255,9 @@ void UndoRedo::commit_action() {
merging = false;
}
- commiting++;
+ committing++;
redo(); // perform action
- commiting--;
+ committing--;
if (callback && actions.size() > 0) {
callback(callback_ud, actions[actions.size() - 1].name);
}
@@ -396,7 +396,7 @@ void UndoRedo::set_property_notify_callback(PropertyNotifyCallback p_property_ca
UndoRedo::UndoRedo() {
- commiting = 0;
+ committing = 0;
version = 1;
action_level = 0;
current_action = -1;
@@ -496,10 +496,8 @@ void UndoRedo::_bind_methods() {
ClassDB::bind_method(D_METHOD("create_action", "name", "merge_mode"), &UndoRedo::create_action, DEFVAL(MERGE_DISABLE));
ClassDB::bind_method(D_METHOD("commit_action"), &UndoRedo::commit_action);
- ClassDB::bind_method(D_METHOD("is_commiting_action"), &UndoRedo::is_commiting_action);
-
- //ClassDB::bind_method(D_METHOD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method);
- //ClassDB::bind_method(D_METHOD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method);
+ // FIXME: Typo in "commiting", fix in 4.0 when breaking compat.
+ ClassDB::bind_method(D_METHOD("is_commiting_action"), &UndoRedo::is_committing_action);
{
MethodInfo mi;
diff --git a/core/undo_redo.h b/core/undo_redo.h
index 6293e77acc..e2cc6c659b 100644
--- a/core/undo_redo.h
+++ b/core/undo_redo.h
@@ -95,7 +95,7 @@ private:
MethodNotifyCallback method_callback;
PropertyNotifyCallback property_callback;
- int commiting;
+ int committing;
protected:
static void _bind_methods();
@@ -110,7 +110,7 @@ public:
void add_do_reference(Object *p_object);
void add_undo_reference(Object *p_object);
- bool is_commiting_action() const;
+ bool is_committing_action() const;
void commit_action();
bool redo();
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 78feddb229..35b817b1d2 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -1725,6 +1725,45 @@ int64_t String::hex_to_int64(bool p_with_prefix) const {
return hex * sign;
}
+int64_t String::bin_to_int64(bool p_with_prefix) const {
+
+ if (p_with_prefix && length() < 3)
+ return 0;
+
+ const CharType *s = ptr();
+
+ int64_t sign = s[0] == '-' ? -1 : 1;
+
+ if (sign < 0) {
+ s++;
+ }
+
+ if (p_with_prefix) {
+ if (s[0] != '0' || s[1] != 'b')
+ return 0;
+ s += 2;
+ }
+
+ int64_t binary = 0;
+
+ while (*s) {
+
+ CharType c = LOWERCASE(*s);
+ int64_t n;
+ if (c == '0' || c == '1') {
+ n = c - '0';
+ } else {
+ return 0;
+ }
+
+ binary *= 2;
+ binary += n;
+ s++;
+ }
+
+ return binary * sign;
+}
+
int String::to_int() const {
if (length() == 0)
@@ -2917,26 +2956,12 @@ String String::replace(const char *p_key, const char *p_with) const {
String String::replace_first(const String &p_key, const String &p_with) const {
- String new_string;
- int search_from = 0;
- int result = 0;
-
- while ((result = find(p_key, search_from)) >= 0) {
-
- new_string += substr(search_from, result - search_from);
- new_string += p_with;
- search_from = result + p_key.length();
- break;
+ int pos = find(p_key);
+ if (pos >= 0) {
+ return substr(0, pos) + p_with + substr(pos + p_key.length(), length());
}
- if (search_from == 0) {
-
- return *this;
- }
-
- new_string += substr(search_from, length() - search_from);
-
- return new_string;
+ return *this;
}
String String::replacen(const String &p_key, const String &p_with) const {
@@ -3063,29 +3088,16 @@ String String::strip_edges(bool left, bool right) const {
String String::strip_escapes() const {
- int len = length();
- int beg = 0, end = len;
-
+ String new_string;
for (int i = 0; i < length(); i++) {
- if (operator[](i) <= 31)
- beg++;
- else
- break;
- }
-
- for (int i = (int)(length() - 1); i >= 0; i--) {
-
- if (operator[](i) <= 31)
- end--;
- else
- break;
+ // Escape characters on first page of the ASCII table, before 32 (Space).
+ if (operator[](i) < 32)
+ continue;
+ new_string += operator[](i);
}
- if (beg == 0 && end == len)
- return *this;
-
- return substr(beg, end - beg);
+ return new_string;
}
String String::lstrip(const String &p_chars) const {
@@ -3209,7 +3221,7 @@ static int _humanize_digits(int p_num) {
String String::humanize_size(size_t p_size) {
uint64_t _div = 1;
- static const char *prefix[] = { " Bytes", " KB", " MB", " GB", "TB", " PB", "HB", "" };
+ static const char *prefix[] = { " Bytes", " KB", " MB", " GB", " TB", " PB", " EB", "" };
int prefix_idx = 0;
while (p_size > (_div * 1024) && prefix[prefix_idx][0]) {
@@ -3220,7 +3232,7 @@ String String::humanize_size(size_t p_size) {
int digits = prefix_idx > 0 ? _humanize_digits(p_size / _div) : 0;
double divisor = prefix_idx > 0 ? _div : 1;
- return String::num(p_size / divisor, digits) + prefix[prefix_idx];
+ return String::num(p_size / divisor).pad_decimals(digits) + prefix[prefix_idx];
}
bool String::is_abs_path() const {
diff --git a/core/ustring.h b/core/ustring.h
index e2e62874d6..5b9be9f27c 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -251,6 +251,7 @@ public:
int to_int() const;
int64_t hex_to_int64(bool p_with_prefix = true) const;
+ int64_t bin_to_int64(bool p_with_prefix = true) const;
int64_t to_int64() const;
static int to_int(const char *p_str, int p_len = -1);
static double to_double(const char *p_str);
@@ -414,16 +415,16 @@ _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
//gets parsed
String TTR(const String &);
-//use for c strings
-#define TTRC(m_value) m_value
+//use for C strings
+#define TTRC(m_value) (m_value)
//use to avoid parsing (for use later with C strings)
#define TTRGET(m_value) TTR(m_value)
#else
-#define TTR(m_val) (String())
-#define TTRCDEF(m_value) (m_value)
+#define TTR(m_value) (String())
#define TTRC(m_value) (m_value)
+#define TTRGET(m_value) (m_value)
#endif
diff --git a/core/variant.cpp b/core/variant.cpp
index 1bc3cff505..6eadf59fce 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -1601,7 +1601,7 @@ String Variant::stringify(List<const void *> &stack) const {
};
};
#endif
- return "[" + _get_obj().obj->get_class() + ":" + itos(_get_obj().obj->get_instance_id()) + "]";
+ return _get_obj().obj->to_string();
} else
return "[Object:null]";
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index f9f73b4e51..5d5f18926f 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -265,6 +265,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(String, right);
VCALL_LOCALMEM0R(String, dedent);
VCALL_LOCALMEM2R(String, strip_edges);
+ VCALL_LOCALMEM0R(String, strip_escapes);
VCALL_LOCALMEM1R(String, lstrip);
VCALL_LOCALMEM1R(String, rstrip);
VCALL_LOCALMEM0R(String, get_extension);
@@ -284,6 +285,8 @@ struct _VariantCall {
VCALL_LOCALMEM0R(String, get_file);
VCALL_LOCALMEM0R(String, xml_escape);
VCALL_LOCALMEM0R(String, xml_unescape);
+ VCALL_LOCALMEM0R(String, http_escape);
+ VCALL_LOCALMEM0R(String, http_unescape);
VCALL_LOCALMEM0R(String, c_escape);
VCALL_LOCALMEM0R(String, c_unescape);
VCALL_LOCALMEM0R(String, json_escape);
@@ -347,6 +350,7 @@ struct _VariantCall {
VCALL_LOCALMEM2R(Vector2, linear_interpolate);
VCALL_LOCALMEM2R(Vector2, slerp);
VCALL_LOCALMEM4R(Vector2, cubic_interpolate);
+ VCALL_LOCALMEM2R(Vector2, move_toward);
VCALL_LOCALMEM1R(Vector2, rotated);
VCALL_LOCALMEM0R(Vector2, tangent);
VCALL_LOCALMEM0R(Vector2, floor);
@@ -388,6 +392,7 @@ struct _VariantCall {
VCALL_LOCALMEM2R(Vector3, linear_interpolate);
VCALL_LOCALMEM2R(Vector3, slerp);
VCALL_LOCALMEM4R(Vector3, cubic_interpolate);
+ VCALL_LOCALMEM2R(Vector3, move_toward);
VCALL_LOCALMEM1R(Vector3, dot);
VCALL_LOCALMEM1R(Vector3, cross);
VCALL_LOCALMEM1R(Vector3, outer);
@@ -1516,9 +1521,9 @@ void register_variant_methods() {
ADDFUNC2R(STRING, STRING, String, replacen, STRING, "what", STRING, "forwhat", varray());
ADDFUNC2R(STRING, STRING, String, insert, INT, "position", STRING, "what", varray());
ADDFUNC0R(STRING, STRING, String, capitalize, varray());
- ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, split, STRING, "divisor", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
- ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, rsplit, STRING, "divisor", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
- ADDFUNC2R(STRING, POOL_REAL_ARRAY, String, split_floats, STRING, "divisor", BOOL, "allow_empty", varray(true));
+ ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, split, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
+ ADDFUNC3R(STRING, POOL_STRING_ARRAY, String, rsplit, STRING, "delimiter", BOOL, "allow_empty", INT, "maxsplit", varray(true, 0));
+ ADDFUNC2R(STRING, POOL_REAL_ARRAY, String, split_floats, STRING, "delimiter", BOOL, "allow_empty", varray(true));
ADDFUNC0R(STRING, STRING, String, to_upper, varray());
ADDFUNC0R(STRING, STRING, String, to_lower, varray());
@@ -1526,6 +1531,7 @@ void register_variant_methods() {
ADDFUNC1R(STRING, STRING, String, left, INT, "position", varray());
ADDFUNC1R(STRING, STRING, String, right, INT, "position", varray());
ADDFUNC2R(STRING, STRING, String, strip_edges, BOOL, "left", BOOL, "right", varray(true, true));
+ ADDFUNC0R(STRING, STRING, String, strip_escapes, varray());
ADDFUNC1R(STRING, STRING, String, lstrip, STRING, "chars", varray());
ADDFUNC1R(STRING, STRING, String, rstrip, STRING, "chars", varray());
ADDFUNC0R(STRING, STRING, String, get_extension, varray());
@@ -1546,6 +1552,8 @@ void register_variant_methods() {
ADDFUNC0R(STRING, STRING, String, get_file, varray());
ADDFUNC0R(STRING, STRING, String, xml_escape, varray());
ADDFUNC0R(STRING, STRING, String, xml_unescape, varray());
+ ADDFUNC0R(STRING, STRING, String, http_escape, varray());
+ ADDFUNC0R(STRING, STRING, String, http_unescape, varray());
ADDFUNC0R(STRING, STRING, String, c_escape, varray());
ADDFUNC0R(STRING, STRING, String, c_unescape, varray());
ADDFUNC0R(STRING, STRING, String, json_escape, varray());
@@ -1583,6 +1591,7 @@ void register_variant_methods() {
ADDFUNC2R(VECTOR2, VECTOR2, Vector2, linear_interpolate, VECTOR2, "b", REAL, "t", varray());
ADDFUNC2R(VECTOR2, VECTOR2, Vector2, slerp, VECTOR2, "b", REAL, "t", varray());
ADDFUNC4R(VECTOR2, VECTOR2, Vector2, cubic_interpolate, VECTOR2, "b", VECTOR2, "pre_a", VECTOR2, "post_b", REAL, "t", varray());
+ ADDFUNC2R(VECTOR2, VECTOR2, Vector2, move_toward, VECTOR2, "to", REAL, "delta", varray());
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, rotated, REAL, "phi", varray());
ADDFUNC0R(VECTOR2, VECTOR2, Vector2, tangent, varray());
ADDFUNC0R(VECTOR2, VECTOR2, Vector2, floor, varray());
@@ -1624,6 +1633,7 @@ void register_variant_methods() {
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, slerp, VECTOR3, "b", REAL, "t", varray());
ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", REAL, "t", varray());
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, direction_to, VECTOR3, "b", varray());
+ ADDFUNC2R(VECTOR3, VECTOR3, Vector3, move_toward, VECTOR3, "to", REAL, "delta", varray());
ADDFUNC1R(VECTOR3, REAL, Vector3, dot, VECTOR3, "b", varray());
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, cross, VECTOR3, "b", varray());
ADDFUNC1R(VECTOR3, BASIS, Vector3, outer, VECTOR3, "b", varray());
diff --git a/core/vector.h b/core/vector.h
index 93ee003519..e6bb4a96fc 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -150,7 +150,7 @@ template <class T>
bool Vector<T>::push_back(const T &p_elem) {
Error err = resize(size() + 1);
- ERR_FAIL_COND_V(err, true)
+ ERR_FAIL_COND_V(err, true);
set(size() - 1, p_elem);
return false;