summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/assimp/editor_scene_importer_assimp.cpp2
-rw-r--r--modules/bullet/shape_bullet.cpp4
-rw-r--r--modules/bullet/space_bullet.cpp3
-rw-r--r--modules/csg/csg.cpp2117
-rw-r--r--modules/csg/csg.h158
-rw-r--r--modules/csg/csg_shape.cpp45
-rw-r--r--modules/dds/texture_loader_dds.cpp2
-rw-r--r--modules/dds/texture_loader_dds.h2
-rw-r--r--modules/etc/image_etc.cpp6
-rw-r--r--modules/etc/texture_loader_pkm.cpp2
-rw-r--r--modules/etc/texture_loader_pkm.h2
-rw-r--r--modules/gdnative/gdnative.cpp2
-rw-r--r--modules/gdnative/gdnative.h2
-rw-r--r--modules/gdnative/gdnative/variant.cpp12
-rw-r--r--modules/gdnative/gdnative_library_editor_plugin.cpp22
-rw-r--r--modules/gdnative/gdnative_library_singleton_editor.cpp6
-rw-r--r--modules/gdnative/include/gdnative/pool_arrays.h4
-rw-r--r--modules/gdnative/include/gdnative/variant.h14
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp63
-rw-r--r--modules/gdnative/nativescript/nativescript.h14
-rw-r--r--modules/gdnative/pluginscript/pluginscript_language.cpp25
-rw-r--r--modules/gdnative/pluginscript/pluginscript_language.h2
-rw-r--r--modules/gdnative/pluginscript/pluginscript_loader.cpp2
-rw-r--r--modules/gdnative/pluginscript/pluginscript_loader.h2
-rw-r--r--modules/gdnative/videodecoder/video_stream_gdnative.cpp2
-rw-r--r--modules/gdnative/videodecoder/video_stream_gdnative.h2
-rw-r--r--modules/gdnavigation/gd_navigation_server.cpp51
-rw-r--r--modules/gdnavigation/gd_navigation_server.h9
-rw-r--r--modules/gdnavigation/nav_map.cpp7
-rw-r--r--modules/gdnavigation/navigation_mesh_editor_plugin.cpp13
-rw-r--r--modules/gdnavigation/navigation_mesh_editor_plugin.h6
-rw-r--r--modules/gdnavigation/navigation_mesh_generator.cpp2
-rw-r--r--modules/gdnavigation/navigation_mesh_generator.h2
-rw-r--r--modules/gdscript/doc_classes/@GDScript.xml20
-rw-r--r--modules/gdscript/gdscript.cpp169
-rw-r--r--modules/gdscript/gdscript.h4
-rw-r--r--modules/gdscript/gdscript_editor.cpp6
-rw-r--r--modules/gdscript/gdscript_function.cpp19
-rw-r--r--modules/gdscript/gdscript_functions.cpp204
-rw-r--r--modules/gdscript/gdscript_parser.cpp42
-rw-r--r--modules/gdscript/gdscript_tokenizer.cpp8
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.cpp49
-rw-r--r--modules/gdscript/language_server/gdscript_workspace.h5
-rw-r--r--modules/gridmap/grid_map.cpp2
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp50
-rw-r--r--modules/mobile_vr/mobile_vr_interface.cpp14
-rw-r--r--modules/mono/csharp_script.cpp79
-rw-r--r--modules/mono/csharp_script.h12
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs7
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/BuildManager.cs23
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs78
-rw-r--r--modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs28
-rw-r--r--modules/mono/editor/bindings_generator.cpp22
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs2
-rw-r--r--modules/mono/mono_gd/gd_mono_field.cpp14
-rw-r--r--modules/mono/mono_gd/gd_mono_marshal.cpp38
-rw-r--r--modules/mono/mono_gd/gd_mono_marshal.h12
-rw-r--r--modules/mono/mono_gd/gd_mono_utils.cpp4
-rw-r--r--modules/mono/utils/mutex_utils.h67
-rw-r--r--modules/opensimplex/noise_texture.cpp7
-rw-r--r--modules/opensimplex/open_simplex_noise.cpp6
-rw-r--r--modules/opus/audio_stream_opus.cpp2
-rw-r--r--modules/opus/audio_stream_opus.h2
-rw-r--r--modules/pvr/texture_loader_pvr.cpp2
-rw-r--r--modules/pvr/texture_loader_pvr.h2
-rw-r--r--modules/regex/doc_classes/RegEx.xml4
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.cpp5
-rw-r--r--modules/stb_vorbis/resource_importer_ogg_vorbis.cpp2
-rw-r--r--modules/theora/video_stream_theora.cpp2
-rw-r--r--modules/theora/video_stream_theora.h2
-rw-r--r--modules/upnp/doc_classes/UPNP.xml2
-rw-r--r--modules/visual_script/visual_script.cpp38
-rw-r--r--modules/visual_script/visual_script.h2
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.cpp102
-rw-r--r--modules/visual_script/visual_script_editor.cpp204
-rw-r--r--modules/visual_script/visual_script_nodes.cpp6
-rw-r--r--modules/visual_script/visual_script_property_selector.cpp31
-rw-r--r--modules/visual_script/visual_script_property_selector.h10
-rw-r--r--modules/visual_script/visual_script_yield_nodes.cpp2
-rw-r--r--modules/vorbis/audio_stream_ogg_vorbis.cpp2
-rw-r--r--modules/vorbis/audio_stream_ogg_vorbis.h2
-rw-r--r--modules/webm/video_stream_webm.cpp2
-rw-r--r--modules/webm/video_stream_webm.h2
83 files changed, 1872 insertions, 2154 deletions
diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp
index 01d49e7995..1881d0db33 100644
--- a/modules/assimp/editor_scene_importer_assimp.cpp
+++ b/modules/assimp/editor_scene_importer_assimp.cpp
@@ -1275,7 +1275,7 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat
for (size_t l = 0; l < num_vertices; l++) {
AssimpUtils::calc_tangent_from_mesh(ai_mesh, j, l, l, w);
}
- PackedRealArray new_tangents = array_copy[VisualServer::ARRAY_TANGENT].duplicate(true);
+ PackedFloat32Array new_tangents = array_copy[VisualServer::ARRAY_TANGENT].duplicate(true);
ERR_CONTINUE(new_tangents.size() != tangents.size() * 4);
for (int32_t l = 0; l < tangents.size(); l++) {
new_tangents.ptrw()[l + 0] = tangents[l].r;
diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp
index 6315964efd..6780f89d9e 100644
--- a/modules/bullet/shape_bullet.cpp
+++ b/modules/bullet/shape_bullet.cpp
@@ -474,7 +474,7 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) {
Vector<real_t> l_heights;
Variant l_heights_v = d["heights"];
- if (l_heights_v.get_type() == Variant::PACKED_REAL_ARRAY) {
+ if (l_heights_v.get_type() == Variant::PACKED_FLOAT32_ARRAY) {
// Ready-to-use heights can be passed
l_heights = l_heights_v;
@@ -505,7 +505,7 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) {
}
} else {
- ERR_FAIL_MSG("Expected PackedRealArray or float Image.");
+ ERR_FAIL_MSG("Expected PackedFloat32Array or float Image.");
}
ERR_FAIL_COND(l_width <= 0);
diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp
index 0e4c4b4731..f6df97f11d 100644
--- a/modules/bullet/space_bullet.cpp
+++ b/modules/bullet/space_bullet.cpp
@@ -726,9 +726,6 @@ void SpaceBullet::check_ghost_overlaps() {
other_body_shape = static_cast<btCollisionShape *>(otherObject->get_bt_shape(z));
- if (other_body_shape->isConcave())
- continue;
-
btTransform other_shape_transform(otherObject->get_bt_shape_transform(z));
other_shape_transform.getOrigin() *= other_body_scale;
diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp
index 36055ce840..e9ca1d3e5b 100644
--- a/modules/csg/csg.cpp
+++ b/modules/csg/csg.cpp
@@ -29,19 +29,159 @@
/*************************************************************************/
#include "csg.h"
-#include "core/math/face3.h"
+
#include "core/math/geometry.h"
-#include "core/os/os.h"
+#include "core/math/math_funcs.h"
#include "core/sort_array.h"
-#include "thirdparty/misc/triangulator.h"
-void CSGBrush::clear() {
- faces.clear();
+// Static helper functions.
+
+inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2, real_t p_distance) {
+
+ return (p_point1 - p_point2).length_squared() < p_distance * p_distance;
+}
+
+inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2], const Vector2 p_uvs[2], const Vector2 &p_interpolation_point) {
+
+ float segment_length = (p_segement_points[1] - p_segement_points[0]).length();
+ if (segment_length < CMP_EPSILON)
+ return p_uvs[0];
+
+ float distance = (p_interpolation_point - p_segement_points[0]).length();
+ float fraction = distance / segment_length;
+
+ return p_uvs[0].linear_interpolate(p_uvs[1], fraction);
+}
+
+inline static Vector2 interpolate_triangle_uv(const Vector2 p_vertices[3], const Vector2 p_uvs[3], const Vector2 &p_interpolation_point) {
+
+ if (p_interpolation_point.distance_squared_to(p_vertices[0]) < CMP_EPSILON2)
+ return p_uvs[0];
+ if (p_interpolation_point.distance_squared_to(p_vertices[1]) < CMP_EPSILON2)
+ return p_uvs[1];
+ if (p_interpolation_point.distance_squared_to(p_vertices[2]) < CMP_EPSILON2)
+ return p_uvs[2];
+
+ Vector2 edge1 = p_vertices[1] - p_vertices[0];
+ Vector2 edge2 = p_vertices[2] - p_vertices[0];
+ Vector2 interpolation = p_interpolation_point - p_vertices[0];
+
+ float edge1_on_edge1 = edge1.dot(edge1);
+ float edge1_on_edge2 = edge1.dot(edge2);
+ float edge2_on_edge2 = edge2.dot(edge2);
+ float inter_on_edge1 = interpolation.dot(edge1);
+ float inter_on_edge2 = interpolation.dot(edge2);
+ float scale = (edge1_on_edge1 * edge2_on_edge2 - edge1_on_edge2 * edge1_on_edge2);
+ if (scale == 0)
+ return p_uvs[0];
+
+ float v = (edge2_on_edge2 * inter_on_edge1 - edge1_on_edge2 * inter_on_edge2) / scale;
+ float w = (edge1_on_edge1 * inter_on_edge2 - edge1_on_edge2 * inter_on_edge1) / scale;
+ float u = 1.0f - v - w;
+
+ return p_uvs[0] * u + p_uvs[1] * v + p_uvs[2] * w;
+}
+
+static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 p_vertices[3], float p_tolerance, Vector3 &r_intersection_point) {
+
+ Vector3 edge1 = p_vertices[1] - p_vertices[0];
+ Vector3 edge2 = p_vertices[2] - p_vertices[0];
+ Vector3 h = p_dir.cross(edge2);
+ real_t a = edge1.dot(h);
+ // Check if ray is parrallel to triangle.
+ if (Math::is_zero_approx(a))
+ return false;
+ real_t f = 1.0 / a;
+
+ Vector3 s = p_from - p_vertices[0];
+ real_t u = f * s.dot(h);
+ if (u < 0.0 - p_tolerance || u > 1.0 + p_tolerance)
+ return false;
+
+ Vector3 q = s.cross(edge1);
+ real_t v = f * p_dir.dot(q);
+ if (v < 0.0 - p_tolerance || u + v > 1.0 + p_tolerance)
+ return false;
+
+ // Ray intersects triangle.
+ // Calculate distance.
+ real_t t = f * edge2.dot(q);
+ // Confirm triangle is in front of ray.
+ if (t >= p_tolerance) {
+ r_intersection_point = p_from + p_dir * t;
+ return true;
+ } else
+ return false;
+}
+
+inline bool is_point_in_triangle(const Vector3 &p_point, const Vector3 p_vertices[3], int p_shifted = 0) {
+
+ real_t det = p_vertices[0].dot(p_vertices[1].cross(p_vertices[2]));
+
+ // If determinant is, zero try shift the triangle and the point.
+ if (Math::is_zero_approx(det)) {
+ if (p_shifted > 2) {
+ // Triangle appears degenerate, so ignore it.
+ return false;
+ }
+ Vector3 shift_by;
+ shift_by[p_shifted] = 1;
+ Vector3 shifted_point = p_point + shift_by;
+ Vector3 shifted_vertices[3] = { p_vertices[0] + shift_by, p_vertices[1] + shift_by, p_vertices[2] + shift_by };
+ return is_point_in_triangle(shifted_point, shifted_vertices, p_shifted + 1);
+ }
+
+ // Find the barycentric coordinates of the point with respect to the vertices.
+ real_t lambda[3];
+ lambda[0] = p_vertices[1].cross(p_vertices[2]).dot(p_point) / det;
+ lambda[1] = p_vertices[2].cross(p_vertices[0]).dot(p_point) / det;
+ lambda[2] = p_vertices[0].cross(p_vertices[1]).dot(p_point) / det;
+
+ // Point is in the plane if all lambdas sum to 1.
+ if (!Math::is_equal_approx(lambda[0] + lambda[1] + lambda[2], 1)) return false;
+
+ // Point is inside the triangle if all lambdas are positive.
+ if (lambda[0] < 0 || lambda[1] < 0 || lambda[2] < 0) return false;
+
+ return true;
+}
+
+inline static bool are_segements_parallel(const Vector2 p_segment1_points[2], const Vector2 p_segment2_points[2], float p_vertex_snap2) {
+
+ Vector2 segment1 = p_segment1_points[1] - p_segment1_points[0];
+ Vector2 segment2 = p_segment2_points[1] - p_segment2_points[0];
+ real_t segment1_length2 = segment1.dot(segment1);
+ real_t segment2_length2 = segment2.dot(segment2);
+ real_t segment_onto_segment = segment2.dot(segment1);
+
+ if (segment1_length2 < p_vertex_snap2 || segment2_length2 < p_vertex_snap2)
+ return true;
+
+ real_t max_separation2;
+ if (segment1_length2 > segment2_length2) {
+ max_separation2 = segment2_length2 - segment_onto_segment * segment_onto_segment / segment1_length2;
+ } else {
+ max_separation2 = segment1_length2 - segment_onto_segment * segment_onto_segment / segment2_length2;
+ }
+
+ return max_separation2 < p_vertex_snap2;
+}
+
+// CSGBrush
+
+void CSGBrush::_regen_face_aabbs() {
+
+ for (int i = 0; i < faces.size(); i++) {
+ faces.write[i].aabb = AABB();
+ faces.write[i].aabb.position = faces[i].vertices[0];
+ faces.write[i].aabb.expand_to(faces[i].vertices[1]);
+ faces.write[i].aabb.expand_to(faces[i].vertices[2]);
+ }
}
void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector<Vector2> &p_uvs, const Vector<bool> &p_smooth, const Vector<Ref<Material> > &p_materials, const Vector<bool> &p_invert_faces) {
- clear();
+ faces.clear();
int vc = p_vertices.size();
@@ -62,37 +202,42 @@ void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector<
faces.resize(p_vertices.size() / 3);
for (int i = 0; i < faces.size(); i++) {
+
Face &f = faces.write[i];
f.vertices[0] = rv[i * 3 + 0];
f.vertices[1] = rv[i * 3 + 1];
f.vertices[2] = rv[i * 3 + 2];
+
if (uvc == vc) {
f.uvs[0] = ruv[i * 3 + 0];
f.uvs[1] = ruv[i * 3 + 1];
f.uvs[2] = ruv[i * 3 + 2];
}
- if (sc == vc / 3) {
+
+ if (sc == vc / 3)
f.smooth = rs[i];
- } else {
+ else
f.smooth = false;
- }
- if (ic == vc / 3) {
+ if (ic == vc / 3)
f.invert = ri[i];
- } else {
+ else
f.invert = false;
- }
if (mc == vc / 3) {
+
Ref<Material> mat = rm[i];
if (mat.is_valid()) {
+
const Map<Ref<Material>, int>::Element *E = material_map.find(mat);
+
if (E) {
f.material = E->get();
} else {
f.material = material_map.size();
material_map[mat] = f.material;
}
+
} else {
f.material = -1;
}
@@ -107,17 +252,6 @@ void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector<
_regen_face_aabbs();
}
-void CSGBrush::_regen_face_aabbs() {
-
- for (int i = 0; i < faces.size(); i++) {
-
- faces.write[i].aabb.position = faces[i].vertices[0];
- faces.write[i].aabb.expand_to(faces[i].vertices[1]);
- faces.write[i].aabb.expand_to(faces[i].vertices[2]);
- faces.write[i].aabb.grow_by(faces[i].aabb.get_longest_axis_size() * 0.001); //make it a tad bigger to avoid num precision errors
- }
-}
-
void CSGBrush::copy_from(const CSGBrush &p_brush, const Transform &p_xform) {
faces = p_brush.faces;
@@ -132,908 +266,218 @@ void CSGBrush::copy_from(const CSGBrush &p_brush, const Transform &p_xform) {
_regen_face_aabbs();
}
-////////////////////////
-
-void CSGBrushOperation::BuildPoly::create(const CSGBrush *p_brush, int p_face, MeshMerge &mesh_merge, bool p_for_B) {
-
- //creates the initial face that will be used for clipping against the other faces
-
- Vector3 va[3] = {
- p_brush->faces[p_face].vertices[0],
- p_brush->faces[p_face].vertices[1],
- p_brush->faces[p_face].vertices[2],
- };
-
- plane = Plane(va[0], va[1], va[2]);
-
- to_world.origin = va[0];
-
- to_world.basis.set_axis(2, plane.normal);
- to_world.basis.set_axis(0, (va[1] - va[2]).normalized());
- to_world.basis.set_axis(1, to_world.basis.get_axis(0).cross(to_world.basis.get_axis(2)).normalized());
-
- to_poly = to_world.affine_inverse();
-
- face_index = p_face;
-
- for (int i = 0; i < 3; i++) {
-
- Point p;
- Vector3 localp = to_poly.xform(va[i]);
- p.point.x = localp.x;
- p.point.y = localp.y;
- p.uv = p_brush->faces[p_face].uvs[i];
-
- points.push_back(p);
-
- ///edge
-
- Edge e;
- e.points[0] = i;
- e.points[1] = (i + 1) % 3;
- e.outer = true;
- edges.push_back(e);
- }
-
- smooth = p_brush->faces[p_face].smooth;
- invert = p_brush->faces[p_face].invert;
-
- if (p_brush->faces[p_face].material != -1) {
- material = p_brush->materials[p_brush->faces[p_face].material];
- }
-
- base_edges = 3;
-}
-
-static Vector2 interpolate_uv(const Vector2 &p_vertex_a, const Vector2 &p_vertex_b, const Vector2 &p_vertex_c, const Vector2 &p_uv_a, const Vector2 &p_uv_c) {
-
- float len_a_c = (p_vertex_c - p_vertex_a).length();
- if (len_a_c < CMP_EPSILON) {
- return p_uv_a;
- }
-
- float len_a_b = (p_vertex_b - p_vertex_a).length();
-
- float c = len_a_b / len_a_c;
-
- return p_uv_a.linear_interpolate(p_uv_c, c);
-}
-
-static Vector2 interpolate_triangle_uv(const Vector2 &p_pos, const Vector2 *p_vtx, const Vector2 *p_uv) {
-
- if (p_pos.distance_squared_to(p_vtx[0]) < CMP_EPSILON2) {
- return p_uv[0];
- }
- if (p_pos.distance_squared_to(p_vtx[1]) < CMP_EPSILON2) {
- return p_uv[1];
- }
- if (p_pos.distance_squared_to(p_vtx[2]) < CMP_EPSILON2) {
- return p_uv[2];
- }
-
- Vector2 v0 = p_vtx[1] - p_vtx[0];
- Vector2 v1 = p_vtx[2] - p_vtx[0];
- Vector2 v2 = p_pos - p_vtx[0];
-
- float d00 = v0.dot(v0);
- float d01 = v0.dot(v1);
- float d11 = v1.dot(v1);
- float d20 = v2.dot(v0);
- float d21 = v2.dot(v1);
- float denom = (d00 * d11 - d01 * d01);
- if (denom == 0) {
- return p_uv[0];
- }
- float v = (d11 * d20 - d01 * d21) / denom;
- float w = (d00 * d21 - d01 * d20) / denom;
- float u = 1.0f - v - w;
-
- return p_uv[0] * u + p_uv[1] * v + p_uv[2] * w;
-}
-
-void CSGBrushOperation::BuildPoly::_clip_segment(const CSGBrush *p_brush, int p_face, const Vector2 *segment, MeshMerge &mesh_merge, bool p_for_B) {
+// CSGBrushOperation
- //keep track of what was inserted
- Vector<int> inserted_points;
+void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_brush_a, const CSGBrush &p_brush_b, CSGBrush &r_merged_brush, float p_vertex_snap) {
- //keep track of point indices for what was inserted, allowing reuse of points.
- int segment_idx[2] = { -1, -1 };
-
- //check if edge and poly share a vertex, of so, assign it to segment_idx
- for (int i = 0; i < points.size(); i++) {
- for (int j = 0; j < 2; j++) {
- if (segment[j].is_equal_approx(points[i].point)) {
- segment_idx[j] = i;
- inserted_points.push_back(i);
- break;
+ // Check for face collisions and add necessary faces.
+ Build2DFaceCollection build2DFaceCollection;
+ for (int i = 0; i < p_brush_a.faces.size(); i++) {
+ for (int j = 0; j < p_brush_b.faces.size(); j++) {
+ if (p_brush_a.faces[i].aabb.intersects_inclusive(p_brush_b.faces[j].aabb)) {
+ update_faces(p_brush_a, i, p_brush_b, j, build2DFaceCollection, p_vertex_snap);
}
}
}
- //check if both segment points are shared with other vertices
- if (segment_idx[0] != -1 && segment_idx[1] != -1) {
-
- if (segment_idx[0] == segment_idx[1]) {
- return; //segment was too tiny, both mapped to same point
- }
-
- bool found = false;
-
- //check if the segment already exists
- for (int i = 0; i < edges.size(); i++) {
-
- if (
- (edges[i].points[0] == segment_idx[0] && edges[i].points[1] == segment_idx[1]) ||
- (edges[i].points[0] == segment_idx[1] && edges[i].points[1] == segment_idx[0])) {
- found = true;
- break;
- }
- }
-
- if (found) {
- //it does already exist, do nothing
- return;
- }
-
- //directly add the new segment
- Edge new_edge;
- new_edge.points[0] = segment_idx[0];
- new_edge.points[1] = segment_idx[1];
- edges.push_back(new_edge);
- return;
- }
-
- //check edge by edge against the segment points to see if intersects
-
- for (int i = 0; i < base_edges; i++) {
-
- //if a point is shared with one of the edge points, then this edge must not be tested, as it will result in a numerical precision error.
- bool edge_valid = true;
- for (int j = 0; j < 2; j++) {
-
- if (edges[i].points[0] == segment_idx[0] || edges[i].points[1] == segment_idx[1] || edges[i].points[0] == segment_idx[1] || edges[i].points[1] == segment_idx[0]) {
- edge_valid = false; //segment has this point, can't check against this
- break;
- }
- }
-
- if (!edge_valid) //already hit a point in this edge, so don't test it
- continue;
-
- //see if either points are within the edge isntead of crossing it
- Vector2 res;
- bool found = false;
- int assign_segment_id = -1;
-
- for (int j = 0; j < 2; j++) {
+ // Add faces to MeshMerge.
+ MeshMerge mesh_merge;
+ mesh_merge.vertex_snap = p_vertex_snap;
- Vector2 edgeseg[2] = { points[edges[i].points[0]].point, points[edges[i].points[1]].point };
- Vector2 closest = Geometry::get_closest_point_to_segment_2d(segment[j], edgeseg);
+ for (int i = 0; i < p_brush_a.faces.size(); i++) {
- if (closest.is_equal_approx(segment[j])) {
- //point rest of this edge
- res = closest;
- found = true;
- assign_segment_id = j;
- }
- }
-
- //test if the point crosses the edge
- if (!found && Geometry::segment_intersects_segment_2d(segment[0], segment[1], points[edges[i].points[0]].point, points[edges[i].points[1]].point, &res)) {
- //point does cross the edge
- found = true;
+ Ref<Material> material;
+ if (p_brush_a.faces[i].material != -1) {
+ material = p_brush_a.materials[p_brush_a.faces[i].material];
}
- //check whether an intersection against the segment happened
- if (found) {
-
- //It did! so first, must slice the segment
- Point new_point;
- new_point.point = res;
- //make sure to interpolate UV too
- new_point.uv = interpolate_uv(points[edges[i].points[0]].point, new_point.point, points[edges[i].points[1]].point, points[edges[i].points[0]].uv, points[edges[i].points[1]].uv);
-
- int point_idx = points.size();
- points.push_back(new_point);
-
- //split the edge in 2
- Edge new_edge;
- new_edge.points[0] = edges[i].points[0];
- new_edge.points[1] = point_idx;
- new_edge.outer = edges[i].outer;
- edges.write[i].points[0] = point_idx;
- edges.insert(i, new_edge);
- i++; //skip newly inserted edge
- base_edges++; //will need an extra one in the base triangle
- if (assign_segment_id >= 0) {
- //point did split a segment, so make sure to remember this
- segment_idx[assign_segment_id] = point_idx;
+ if (build2DFaceCollection.build2DFacesA.has(i)) {
+ build2DFaceCollection.build2DFacesA[i].addFacesToMesh(mesh_merge, p_brush_a.faces[i].smooth, p_brush_a.faces[i].invert, material, false);
+ } else {
+ Vector3 points[3];
+ Vector2 uvs[3];
+ for (int j = 0; j < 3; j++) {
+ points[j] = p_brush_a.faces[i].vertices[j];
+ uvs[j] = p_brush_a.faces[i].uvs[j];
}
- inserted_points.push_back(point_idx);
+ mesh_merge.add_face(points, uvs, p_brush_a.faces[i].smooth, p_brush_a.faces[i].invert, material, false);
}
}
- //final step: after cutting the original triangle, try to see if we can still insert
- //this segment
-
- //if already inserted two points, just use them for a segment
-
- if (inserted_points.size() >= 2) { //should never be >2 on non-manifold geometry, but cope with error
- //two points were inserted, create the new edge
- Edge new_edge;
- new_edge.points[0] = inserted_points[0];
- new_edge.points[1] = inserted_points[1];
- edges.push_back(new_edge);
- return;
- }
-
- // One or no points were inserted (besides splitting), so try to see if extra points can be placed inside the triangle.
- // This needs to be done here, after the previous tests were exhausted
- for (int i = 0; i < 2; i++) {
-
- if (segment_idx[i] != -1)
- continue; //already assigned to something, so skip
-
- //check whether one of the segment endpoints is inside the triangle. If it is, this points needs to be inserted
- if (Geometry::is_point_in_triangle(segment[i], points[0].point, points[1].point, points[2].point)) {
-
- Point new_point;
- new_point.point = segment[i];
+ for (int i = 0; i < p_brush_b.faces.size(); i++) {
- Vector2 point3[3] = { points[0].point, points[1].point, points[2].point };
- Vector2 uv3[3] = { points[0].uv, points[1].uv, points[2].uv };
-
- new_point.uv = interpolate_triangle_uv(new_point.point, point3, uv3);
-
- int point_idx = points.size();
- points.push_back(new_point);
- inserted_points.push_back(point_idx);
+ Ref<Material> material;
+ if (p_brush_b.faces[i].material != -1) {
+ material = p_brush_b.materials[p_brush_b.faces[i].material];
}
- }
-
- //check again whether two points were inserted, if so then create the new edge
- if (inserted_points.size() >= 2) { //should never be >2 on non-manifold geometry, but cope with error
- Edge new_edge;
- new_edge.points[0] = inserted_points[0];
- new_edge.points[1] = inserted_points[1];
- edges.push_back(new_edge);
- }
-}
-
-void CSGBrushOperation::BuildPoly::clip(const CSGBrush *p_brush, int p_face, MeshMerge &mesh_merge, bool p_for_B) {
-
- //Clip function.. find triangle points that will be mapped to the plane and form a segment
-
- Vector2 segment[3]; //2D
- int src_points = 0;
-
- for (int i = 0; i < 3; i++) {
- Vector3 p = p_brush->faces[p_face].vertices[i];
- if (plane.has_point(p)) {
- Vector3 pp = plane.project(p);
- pp = to_poly.xform(pp);
- segment[src_points++] = Vector2(pp.x, pp.y);
+ if (build2DFaceCollection.build2DFacesB.has(i)) {
+ build2DFaceCollection.build2DFacesB[i].addFacesToMesh(mesh_merge, p_brush_b.faces[i].smooth, p_brush_b.faces[i].invert, material, true);
} else {
- Vector3 q = p_brush->faces[p_face].vertices[(i + 1) % 3];
- if (plane.has_point(q))
- continue; //next point is in plane, will be added eventually
- if (plane.is_point_over(p) == plane.is_point_over(q))
- continue; // both on same side of the plane, don't add
-
- Vector3 res;
- if (plane.intersects_segment(p, q, &res)) {
- res = to_poly.xform(res);
- segment[src_points++] = Vector2(res.x, res.y);
- }
- }
- }
-
- //all above or all below, nothing to do. Should not happen though since a precheck was done before.
- if (src_points == 0)
- return;
-
- //just one point in plane is not worth doing anything
- if (src_points == 1)
- return;
-
- //transform A points to 2D
-
- if (segment[0].is_equal_approx(segment[1]))
- return; //too small
-
- _clip_segment(p_brush, p_face, segment, mesh_merge, p_for_B);
-}
-
-void CSGBrushOperation::_collision_callback(const CSGBrush *A, int p_face_a, Map<int, BuildPoly> &build_polys_a, const CSGBrush *B, int p_face_b, Map<int, BuildPoly> &build_polys_b, MeshMerge &mesh_merge) {
-
- //construct a frame of reference for both transforms, in order to do intersection test
- Vector3 va[3] = {
- A->faces[p_face_a].vertices[0],
- A->faces[p_face_a].vertices[1],
- A->faces[p_face_a].vertices[2],
- };
- Vector3 vb[3] = {
- B->faces[p_face_b].vertices[0],
- B->faces[p_face_b].vertices[1],
- B->faces[p_face_b].vertices[2],
- };
-
- {
- //check if either is a degenerate
- if (va[0].is_equal_approx(va[1]) || va[0].is_equal_approx(va[2]) || va[1].is_equal_approx(va[2]))
- return;
-
- if (vb[0].is_equal_approx(vb[1]) || vb[0].is_equal_approx(vb[2]) || vb[1].is_equal_approx(vb[2]))
- return;
- }
-
- {
- //check if points are the same
- int equal_count = 0;
-
- for (int i = 0; i < 3; i++) {
-
+ Vector3 points[3];
+ Vector2 uvs[3];
for (int j = 0; j < 3; j++) {
- if (va[i].distance_to(vb[j]) < mesh_merge.vertex_snap) {
- equal_count++;
- break;
- }
+ points[j] = p_brush_b.faces[i].vertices[j];
+ uvs[j] = p_brush_b.faces[i].uvs[j];
}
- }
-
- //if 2 or 3 points are the same, there is no point in doing anything. They can't
- //be clipped either, so add both.
- if (equal_count == 2 || equal_count == 3) {
- return;
+ mesh_merge.add_face(points, uvs, p_brush_b.faces[i].smooth, p_brush_b.faces[i].invert, material, true);
}
}
- // do a quick pre-check for no-intersection using the SAT theorem
-
- {
-
- //b under or over a plane
- int over_count = 0, in_plane_count = 0, under_count = 0;
- Plane plane_a(va[0], va[1], va[2]);
- if (plane_a.normal == Vector3()) {
- return; //degenerate
- }
-
- for (int i = 0; i < 3; i++) {
- if (plane_a.has_point(vb[i]))
- in_plane_count++;
- else if (plane_a.is_point_over(vb[i]))
- over_count++;
- else
- under_count++;
- }
-
- if (over_count == 0 || under_count == 0)
- return; //no intersection, something needs to be under AND over
-
- //a under or over b plane
- over_count = 0;
- under_count = 0;
- in_plane_count = 0;
-
- Plane plane_b(vb[0], vb[1], vb[2]);
- if (plane_b.normal == Vector3())
- return; //degenerate
+ // Mark faces that ended up inside the intersection.
+ mesh_merge.mark_inside_faces();
- for (int i = 0; i < 3; i++) {
- if (plane_b.has_point(va[i]))
- in_plane_count++;
- else if (plane_b.is_point_over(va[i]))
- over_count++;
- else
- under_count++;
- }
+ // Create new brush and fill with new faces.
+ r_merged_brush.faces.clear();
- if (over_count == 0 || under_count == 0)
- return; //no intersection, something needs to be under AND over
+ switch (p_operation) {
- //edge pairs (cross product combinations), see SAT theorem
+ case OPERATION_UNION: {
- for (int i = 0; i < 3; i++) {
+ int outside_count = 0;
- Vector3 axis_a = (va[i] - va[(i + 1) % 3]).normalized();
+ for (int i = 0; i < mesh_merge.faces.size(); i++) {
+ if (mesh_merge.faces[i].inside)
+ continue;
+ outside_count++;
+ }
- for (int j = 0; j < 3; j++) {
+ r_merged_brush.faces.resize(outside_count);
- Vector3 axis_b = (vb[j] - vb[(j + 1) % 3]).normalized();
+ outside_count = 0;
- Vector3 sep_axis = axis_a.cross(axis_b);
- if (sep_axis == Vector3())
- continue; //colineal
- sep_axis.normalize();
+ for (int i = 0; i < mesh_merge.faces.size(); i++) {
- real_t min_a = 1e20, max_a = -1e20;
- real_t min_b = 1e20, max_b = -1e20;
+ if (mesh_merge.faces[i].inside)
+ continue;
- for (int k = 0; k < 3; k++) {
- real_t d = sep_axis.dot(va[k]);
- min_a = MIN(min_a, d);
- max_a = MAX(max_a, d);
- d = sep_axis.dot(vb[k]);
- min_b = MIN(min_b, d);
- max_b = MAX(max_b, d);
+ for (int j = 0; j < 3; j++) {
+ r_merged_brush.faces.write[outside_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
+ r_merged_brush.faces.write[outside_count].uvs[j] = mesh_merge.faces[i].uvs[j];
}
- min_b -= (max_a - min_a) * 0.5;
- max_b += (max_a - min_a) * 0.5;
-
- real_t dmin = min_b - (min_a + max_a) * 0.5;
- real_t dmax = max_b - (min_a + max_a) * 0.5;
-
- if (dmin > CMP_EPSILON || dmax < -CMP_EPSILON) {
- return; //does not contain zero, so they don't overlap
- }
+ r_merged_brush.faces.write[outside_count].smooth = mesh_merge.faces[i].smooth;
+ r_merged_brush.faces.write[outside_count].invert = mesh_merge.faces[i].invert;
+ r_merged_brush.faces.write[outside_count].material = mesh_merge.faces[i].material_idx;
+ outside_count++;
}
- }
- }
-
- //if we are still here, it means they most likely intersect, so create BuildPolys if they don't exist
-
- BuildPoly *poly_a = NULL;
-
- if (!build_polys_a.has(p_face_a)) {
- BuildPoly bp;
- bp.create(A, p_face_a, mesh_merge, false);
- build_polys_a[p_face_a] = bp;
- }
-
- poly_a = &build_polys_a[p_face_a];
-
- BuildPoly *poly_b = NULL;
+ r_merged_brush._regen_face_aabbs();
- if (!build_polys_b.has(p_face_b)) {
-
- BuildPoly bp;
- bp.create(B, p_face_b, mesh_merge, true);
- build_polys_b[p_face_b] = bp;
- }
-
- poly_b = &build_polys_b[p_face_b];
-
- //clip each other, this could be improved by using vertex unique IDs (more vertices may be shared instead of using snap)
- poly_a->clip(B, p_face_b, mesh_merge, false);
- poly_b->clip(A, p_face_a, mesh_merge, true);
-}
-
-void CSGBrushOperation::_add_poly_points(const BuildPoly &p_poly, int p_edge, int p_from_point, int p_to_point, const Vector<Vector<int> > &vertex_process, Vector<bool> &edge_process, Vector<PolyPoints> &r_poly) {
-
- //this function follows the polygon points counter clockwise and adds them. It creates lists of unique polygons
- //every time an unused edge is found, it's pushed to a stack and continues from there.
-
- List<EdgeSort> edge_stack;
-
- {
- EdgeSort es;
- es.angle = 0; //won't be checked here
- es.edge = p_edge;
- es.prev_point = p_from_point;
- es.edge_point = p_to_point;
-
- edge_stack.push_back(es);
- }
-
- //attempt to empty the stack.
- while (edge_stack.size()) {
-
- EdgeSort e = edge_stack.front()->get();
- edge_stack.pop_front();
-
- if (edge_process[e.edge]) {
- //nothing to do here
- continue;
- }
-
- Vector<int> points;
- points.push_back(e.prev_point);
-
- int prev_point = e.prev_point;
- int to_point = e.edge_point;
- int current_edge = e.edge;
-
- edge_process.write[e.edge] = true; //mark as processed
-
- int limit = p_poly.points.size() * 4; //avoid infinite recursion
-
- while (to_point != e.prev_point && limit) {
-
- Vector2 segment[2] = { p_poly.points[prev_point].point, p_poly.points[to_point].point };
-
- //construct a basis transform from the segment, which will be used to check the angle
- Transform2D t2d;
- t2d[0] = (segment[1] - segment[0]).normalized(); //use as Y
- t2d[1] = Vector2(-t2d[0].y, t2d[0].x); // use as tangent
- t2d[2] = segment[1]; //origin
-
- if (t2d.basis_determinant() == 0)
- break; //abort poly
-
- t2d.affine_invert();
-
- //push all edges found here, they will be sorted by minimum angle later.
- Vector<EdgeSort> next_edges;
-
- for (int i = 0; i < vertex_process[to_point].size(); i++) {
+ } break;
- int edge = vertex_process[to_point][i];
- int opposite_point = p_poly.edges[edge].points[0] == to_point ? p_poly.edges[edge].points[1] : p_poly.edges[edge].points[0];
- if (opposite_point == prev_point)
- continue; //not going back
+ case OPERATION_INTERSECTION: {
- EdgeSort e2;
- Vector2 local_vec = t2d.xform(p_poly.points[opposite_point].point);
- e2.angle = -local_vec.angle(); //negate so we can sort by minimum angle
- e2.edge = edge;
- e2.edge_point = opposite_point;
- e2.prev_point = to_point;
+ int inside_count = 0;
- next_edges.push_back(e2);
+ for (int i = 0; i < mesh_merge.faces.size(); i++) {
+ if (!mesh_merge.faces[i].inside)
+ continue;
+ inside_count++;
}
- //finally, sort by minimum angle
- next_edges.sort();
+ r_merged_brush.faces.resize(inside_count);
- int next_point = -1;
- int next_edge = -1;
+ inside_count = 0;
- for (int i = 0; i < next_edges.size(); i++) {
+ for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (i == 0) {
- //minimum angle found is the next point
- next_point = next_edges[i].edge_point;
- next_edge = next_edges[i].edge;
+ if (!mesh_merge.faces[i].inside)
+ continue;
- } else {
- //the rest are pushed to the stack IF they were not processed yet.
- if (!edge_process[next_edges[i].edge]) {
- edge_stack.push_back(next_edges[i]);
- }
+ for (int j = 0; j < 3; j++) {
+ r_merged_brush.faces.write[inside_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
+ r_merged_brush.faces.write[inside_count].uvs[j] = mesh_merge.faces[i].uvs[j];
}
- }
- if (next_edge == -1) {
- //did not find anything, may be a dead-end edge (this should normally not happen)
- //just flip the direction and go back
- next_point = prev_point;
- next_edge = current_edge;
+ r_merged_brush.faces.write[inside_count].smooth = mesh_merge.faces[i].smooth;
+ r_merged_brush.faces.write[inside_count].invert = mesh_merge.faces[i].invert;
+ r_merged_brush.faces.write[inside_count].material = mesh_merge.faces[i].material_idx;
+ inside_count++;
}
- points.push_back(to_point);
-
- prev_point = to_point;
- to_point = next_point;
- edge_process.write[next_edge] = true; //mark this edge as processed
- current_edge = next_edge;
-
- limit--;
- }
-
- //if more than 2 points were added to the polygon, add it to the list of polygons.
- if (points.size() > 2) {
- PolyPoints pp;
- pp.points = points;
- r_poly.push_back(pp);
- }
- }
-}
-
-void CSGBrushOperation::_add_poly_outline(const BuildPoly &p_poly, int p_from_point, int p_to_point, const Vector<Vector<int> > &vertex_process, Vector<int> &r_outline) {
-
- //this is the opposite of the function above. It adds polygon outlines instead.
- //this is used for triangulating holes.
- //no stack is used here because only the bigger outline is interesting.
-
- r_outline.push_back(p_from_point);
+ r_merged_brush._regen_face_aabbs();
- int prev_point = p_from_point;
- int to_point = p_to_point;
-
- int limit = p_poly.points.size() * 4; //avoid infinite recursion
-
- while (to_point != p_from_point && limit) {
-
- Vector2 segment[2] = { p_poly.points[prev_point].point, p_poly.points[to_point].point };
- //again create a transform to compute the angle.
- Transform2D t2d;
- t2d[0] = (segment[1] - segment[0]).normalized(); //use as Y
- t2d[1] = Vector2(-t2d[0].y, t2d[0].x); // use as tangent
- t2d[2] = segment[1]; //origin
-
- if (t2d.basis_determinant() == 0)
- break; //abort poly
-
- t2d.affine_invert();
-
- float max_angle = 0;
- int next_point_angle = -1;
+ } break;
- for (int i = 0; i < vertex_process[to_point].size(); i++) {
+ case OPERATION_SUBSTRACTION: {
- int edge = vertex_process[to_point][i];
- int opposite_point = p_poly.edges[edge].points[0] == to_point ? p_poly.edges[edge].points[1] : p_poly.edges[edge].points[0];
- if (opposite_point == prev_point)
- continue; //not going back
+ int face_count = 0;
- float angle = -t2d.xform(p_poly.points[opposite_point].point).angle();
- if (next_point_angle == -1 || angle > max_angle) { //same as before but use greater to check.
- max_angle = angle;
- next_point_angle = opposite_point;
+ for (int i = 0; i < mesh_merge.faces.size(); i++) {
+ if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside)
+ continue;
+ if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside)
+ continue;
+ face_count++;
}
- }
-
- if (next_point_angle == -1) {
- //go back because no route found
- next_point_angle = prev_point;
- }
-
- r_outline.push_back(to_point);
- prev_point = to_point;
- to_point = next_point_angle;
-
- limit--;
- }
-}
-
-void CSGBrushOperation::_merge_poly(MeshMerge &mesh, int p_face_idx, const BuildPoly &p_poly, bool p_from_b) {
-
- //finally, merge the 2D polygon back to 3D
-
- Vector<Vector<int> > vertex_process;
- Vector<bool> edge_process;
-
- vertex_process.resize(p_poly.points.size());
- edge_process.resize(p_poly.edges.size());
-
- //none processed by default
- for (int i = 0; i < edge_process.size(); i++) {
- edge_process.write[i] = false;
- }
-
- //put edges in points, so points can go through them
- for (int i = 0; i < p_poly.edges.size(); i++) {
- vertex_process.write[p_poly.edges[i].points[0]].push_back(i);
- vertex_process.write[p_poly.edges[i].points[1]].push_back(i);
- }
- Vector<PolyPoints> polys;
+ r_merged_brush.faces.resize(face_count);
- //process points that were not processed
- for (int i = 0; i < edge_process.size(); i++) {
- if (edge_process[i])
- continue; //already processed
-
- int intersect_poly = -1;
-
- if (i > 0) {
- //this is disconnected, so it's clearly a hole. lets find where it belongs
- Vector2 ref_point = p_poly.points[p_poly.edges[i].points[0]].point;
-
- for (int j = 0; j < polys.size(); j++) {
-
- //find a point outside poly
- Vector2 out_point(-1e20, -1e20);
-
- const PolyPoints &pp = polys[j];
-
- for (int k = 0; k < pp.points.size(); k++) {
- Vector2 p = p_poly.points[pp.points[k]].point;
- out_point.x = MAX(out_point.x, p.x);
- out_point.y = MAX(out_point.y, p.y);
- }
-
- out_point += Vector2(0.12341234, 0.4123412); // move to a random place to avoid direct edge-point chances
+ face_count = 0;
- int intersections = 0;
+ for (int i = 0; i < mesh_merge.faces.size(); i++) {
- for (int k = 0; k < pp.points.size(); k++) {
- Vector2 p1 = p_poly.points[pp.points[k]].point;
- Vector2 p2 = p_poly.points[pp.points[(k + 1) % pp.points.size()]].point;
+ if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside)
+ continue;
+ if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside)
+ continue;
- if (Geometry::segment_intersects_segment_2d(ref_point, out_point, p1, p2, NULL)) {
- intersections++;
- }
+ for (int j = 0; j < 3; j++) {
+ r_merged_brush.faces.write[face_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
+ r_merged_brush.faces.write[face_count].uvs[j] = mesh_merge.faces[i].uvs[j];
}
- if (intersections % 2 == 1) {
- //hole is inside this poly
- intersect_poly = j;
- break;
+ if (mesh_merge.faces[i].from_b) {
+ //invert facing of insides of B
+ SWAP(r_merged_brush.faces.write[face_count].vertices[1], r_merged_brush.faces.write[face_count].vertices[2]);
+ SWAP(r_merged_brush.faces.write[face_count].uvs[1], r_merged_brush.faces.write[face_count].uvs[2]);
}
- }
- }
- if (intersect_poly != -1) {
- //must add this as a hole
- Vector<int> outline;
- _add_poly_outline(p_poly, p_poly.edges[i].points[0], p_poly.edges[i].points[1], vertex_process, outline);
-
- if (outline.size() > 1) {
- polys.write[intersect_poly].holes.push_back(outline);
+ r_merged_brush.faces.write[face_count].smooth = mesh_merge.faces[i].smooth;
+ r_merged_brush.faces.write[face_count].invert = mesh_merge.faces[i].invert;
+ r_merged_brush.faces.write[face_count].material = mesh_merge.faces[i].material_idx;
+ face_count++;
}
- }
- _add_poly_points(p_poly, i, p_poly.edges[i].points[0], p_poly.edges[i].points[1], vertex_process, edge_process, polys);
- }
-
- //get rid of holes, not the most optiomal way, but also not a common case at all to be inoptimal
- for (int i = 0; i < polys.size(); i++) {
-
- if (!polys[i].holes.size())
- continue;
-
- //repeat until no more holes are left to be merged
- while (polys[i].holes.size()) {
-
- //try to merge a hole with the outline
- bool added_hole = false;
-
- for (int j = 0; j < polys[i].holes.size(); j++) {
-
- //try hole vertices
- int with_outline_vertex = -1;
- int from_hole_vertex = -1;
-
- bool found = false;
-
- for (int k = 0; k < polys[i].holes[j].size(); k++) {
-
- int from_idx = polys[i].holes[j][k];
- Vector2 from = p_poly.points[from_idx].point;
-
- //try a segment from hole vertex to outline vertices
- from_hole_vertex = k;
-
- bool valid = true;
-
- for (int l = 0; l < polys[i].points.size(); l++) {
-
- int to_idx = polys[i].points[l];
- Vector2 to = p_poly.points[to_idx].point;
- with_outline_vertex = l;
-
- //try against outline (other points) first
-
- valid = true;
-
- for (int m = 0; m < polys[i].points.size(); m++) {
- int m_next = (m + 1) % polys[i].points.size();
- if (m == with_outline_vertex || m_next == with_outline_vertex) //do not test with edges that share this point
- continue;
+ r_merged_brush._regen_face_aabbs();
- if (Geometry::segment_intersects_segment_2d(from, to, p_poly.points[polys[i].points[m]].point, p_poly.points[polys[i].points[m_next]].point, NULL)) {
- valid = false;
- break;
- }
- }
-
- if (!valid)
- continue;
-
- //try against all holes including self
-
- for (int m = 0; m < polys[i].holes.size(); m++) {
-
- for (int n = 0; n < polys[i].holes[m].size(); n++) {
-
- int n_next = (n + 1) % polys[i].holes[m].size();
- if (m == j && (n == from_hole_vertex || n_next == from_hole_vertex)) //contains vertex being tested from current hole, skip
- continue;
-
- if (Geometry::segment_intersects_segment_2d(from, to, p_poly.points[polys[i].holes[m][n]].point, p_poly.points[polys[i].holes[m][n_next]].point, NULL)) {
- valid = false;
- break;
- }
- }
-
- if (!valid)
- break;
- }
-
- if (valid) //all passed! exit loop
- break;
- else
- continue; //something went wrong, go on.
- }
-
- if (valid) {
- found = true; //if in the end this was valid, use it
- break;
- }
- }
-
- if (found) {
-
- //hook this hole with outline, and remove from list of holes
-
- //duplicate point
- int insert_at = with_outline_vertex;
- int point = polys[i].points[insert_at];
- polys.write[i].points.insert(insert_at, point);
- insert_at++;
- //insert all others, outline should be backwards (must check)
- int holesize = polys[i].holes[j].size();
- for (int k = 0; k <= holesize; k++) {
- int idx = (from_hole_vertex + k) % holesize;
- int point2 = polys[i].holes[j][idx];
- polys.write[i].points.insert(insert_at, point2);
- insert_at++;
- }
-
- added_hole = true;
- polys.write[i].holes.remove(j);
- break; //got rid of hole, break and continue
- }
- }
-
- ERR_BREAK(!added_hole);
- }
+ } break;
}
- //triangulate polygons
-
- for (int i = 0; i < polys.size(); i++) {
-
- Vector<Vector2> vertices;
- vertices.resize(polys[i].points.size());
- for (int j = 0; j < vertices.size(); j++) {
- vertices.write[j] = p_poly.points[polys[i].points[j]].point;
- }
-
- Vector<int> indices = Geometry::triangulate_polygon(vertices);
-
- for (int j = 0; j < indices.size(); j += 3) {
-
- //obtain the vertex
-
- Vector3 face[3];
- Vector2 uv[3];
- float cp = Geometry::vec2_cross(p_poly.points[polys[i].points[indices[j + 0]]].point, p_poly.points[polys[i].points[indices[j + 1]]].point, p_poly.points[polys[i].points[indices[j + 2]]].point);
- if (Math::abs(cp) < CMP_EPSILON)
- continue;
-
- for (int k = 0; k < 3; k++) {
-
- Vector2 p = p_poly.points[polys[i].points[indices[j + k]]].point;
- face[k] = p_poly.to_world.xform(Vector3(p.x, p.y, 0));
- uv[k] = p_poly.points[polys[i].points[indices[j + k]]].uv;
- }
-
- mesh.add_face(face[0], face[1], face[2], uv[0], uv[1], uv[2], p_poly.smooth, p_poly.invert, p_poly.material, p_from_b);
- }
+ // Update the list of materials.
+ r_merged_brush.materials.resize(mesh_merge.materials.size());
+ for (const Map<Ref<Material>, int>::Element *E = mesh_merge.materials.front(); E; E = E->next()) {
+ r_merged_brush.materials.write[E->get()] = E->key();
}
}
-//use a limit to speed up bvh and limit the depth
+// CSGBrushOperation::MeshMerge
+
+// Use a limit to speed up bvh and limit the depth.
#define BVH_LIMIT 8
-int CSGBrushOperation::MeshMerge::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc) {
+int CSGBrushOperation::MeshMerge::_create_bvh(FaceBVH *facebvhptr, FaceBVH **facebvhptrptr, int p_from, int p_size, int p_depth, int &r_max_depth, int &r_max_alloc) {
- if (p_depth > max_depth) {
- max_depth = p_depth;
+ if (p_depth > r_max_depth) {
+ r_max_depth = p_depth;
}
if (p_size == 0) {
-
return -1;
- } else if (p_size <= BVH_LIMIT) {
+ }
+ if (p_size <= BVH_LIMIT) {
for (int i = 0; i < p_size - 1; i++) {
- p_bb[p_from + i]->next = p_bb[p_from + i + 1] - p_bvh;
+ facebvhptrptr[p_from + i]->next = facebvhptrptr[p_from + i + 1] - facebvhptr;
}
- return p_bb[p_from] - p_bvh;
+ return facebvhptrptr[p_from] - facebvhptr;
}
AABB aabb;
- aabb = p_bb[p_from]->aabb;
+ aabb = facebvhptrptr[p_from]->aabb;
for (int i = 1; i < p_size; i++) {
-
- aabb.merge_with(p_bb[p_from + i]->aabb);
+ aabb.merge_with(facebvhptrptr[p_from + i]->aabb);
}
int li = aabb.get_longest_axis_index();
@@ -1041,28 +485,29 @@ int CSGBrushOperation::MeshMerge::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from
switch (li) {
case Vector3::AXIS_X: {
- SortArray<BVH *, BVHCmpX> sort_x;
- sort_x.nth_element(0, p_size, p_size / 2, &p_bb[p_from]);
+ SortArray<FaceBVH *, FaceBVHCmpX> sort_x;
+ sort_x.nth_element(0, p_size, p_size / 2, &facebvhptrptr[p_from]);
//sort_x.sort(&p_bb[p_from],p_size);
} break;
+
case Vector3::AXIS_Y: {
- SortArray<BVH *, BVHCmpY> sort_y;
- sort_y.nth_element(0, p_size, p_size / 2, &p_bb[p_from]);
+ SortArray<FaceBVH *, FaceBVHCmpY> sort_y;
+ sort_y.nth_element(0, p_size, p_size / 2, &facebvhptrptr[p_from]);
//sort_y.sort(&p_bb[p_from],p_size);
} break;
+
case Vector3::AXIS_Z: {
- SortArray<BVH *, BVHCmpZ> sort_z;
- sort_z.nth_element(0, p_size, p_size / 2, &p_bb[p_from]);
+ SortArray<FaceBVH *, FaceBVHCmpZ> sort_z;
+ sort_z.nth_element(0, p_size, p_size / 2, &facebvhptrptr[p_from]);
//sort_z.sort(&p_bb[p_from],p_size);
-
} break;
}
- int left = _create_bvh(p_bvh, p_bb, p_from, p_size / 2, p_depth + 1, max_depth, max_alloc);
- int right = _create_bvh(p_bvh, p_bb, p_from + p_size / 2, p_size - p_size / 2, p_depth + 1, max_depth, max_alloc);
+ int left = _create_bvh(facebvhptr, facebvhptrptr, p_from, p_size / 2, p_depth + 1, r_max_depth, r_max_alloc);
+ int right = _create_bvh(facebvhptr, facebvhptrptr, p_from + p_size / 2, p_size - p_size / 2, p_depth + 1, r_max_depth, r_max_alloc);
- int index = max_alloc++;
- BVH *_new = &p_bvh[index];
+ int index = r_max_alloc++;
+ FaceBVH *_new = &facebvhptr[index];
_new->aabb = aabb;
_new->center = aabb.position + aabb.size * 0.5;
_new->face = -1;
@@ -1073,7 +518,27 @@ int CSGBrushOperation::MeshMerge::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from
return index;
}
-int CSGBrushOperation::MeshMerge::_bvh_count_intersections(BVH *bvhptr, int p_max_depth, int p_bvh_first, const Vector3 &p_begin, const Vector3 &p_end, int p_exclude) const {
+void CSGBrushOperation::MeshMerge::_add_distance(List<real_t> &r_intersectionsA, List<real_t> &r_intersectionsB, bool p_from_B, real_t p_distance) const {
+
+ List<real_t> &intersections = p_from_B ? r_intersectionsB : r_intersectionsA;
+
+ // Check if distance exists.
+ for (const List<real_t>::Element *E = intersections.front(); E; E = E->next())
+ if (Math::abs(**E - p_distance) < vertex_snap) return;
+
+ intersections.push_back(p_distance);
+}
+
+bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_depth, int p_bvh_first, int p_face_idx) const {
+
+ Face face = faces[p_face_idx];
+ Vector3 face_points[3] = {
+ points[face.points[0]],
+ points[face.points[1]],
+ points[face.points[2]]
+ };
+ Vector3 face_center = (face_points[0] + face_points[1] + face_points[2]) / 3.0;
+ Vector3 face_normal = Plane(face_points[0], face_points[1], face_points[2]).normal;
uint32_t *stack = (uint32_t *)alloca(sizeof(int) * p_max_depth);
@@ -1084,54 +549,58 @@ int CSGBrushOperation::MeshMerge::_bvh_count_intersections(BVH *bvhptr, int p_ma
VISIT_DONE_BIT = 3,
VISITED_BIT_SHIFT = 29,
NODE_IDX_MASK = (1 << VISITED_BIT_SHIFT) - 1,
- VISITED_BIT_MASK = ~NODE_IDX_MASK,
-
+ VISITED_BIT_MASK = ~NODE_IDX_MASK
};
- int intersections = 0;
+ List<real_t> intersectionsA;
+ List<real_t> intersectionsB;
int level = 0;
-
- const Vector3 *vertexptr = points.ptr();
- const Face *facesptr = faces.ptr();
- AABB segment_aabb;
- segment_aabb.position = p_begin;
- segment_aabb.expand_to(p_end);
-
int pos = p_bvh_first;
-
stack[0] = pos;
+
while (true) {
uint32_t node = stack[level] & NODE_IDX_MASK;
- const BVH &b = bvhptr[node];
+ const FaceBVH *current_facebvhptr = &(facebvhptr[node]);
bool done = false;
switch (stack[level] >> VISITED_BIT_SHIFT) {
- case TEST_AABB_BIT: {
-
- if (b.face >= 0) {
-
- const BVH *bp = &b;
- while (bp) {
-
- bool valid = segment_aabb.intersects(bp->aabb) && bp->aabb.intersects_segment(p_begin, p_end);
-
- if (valid && p_exclude != bp->face) {
- const Face &s = facesptr[bp->face];
- Face3 f3(vertexptr[s.points[0]], vertexptr[s.points[1]], vertexptr[s.points[2]]);
-
- Vector3 res;
+ case TEST_AABB_BIT: {
- if (f3.intersects_segment(p_begin, p_end, &res)) {
- intersections++;
+ if (current_facebvhptr->face >= 0) {
+
+ while (current_facebvhptr) {
+
+ if (p_face_idx != current_facebvhptr->face &&
+ current_facebvhptr->aabb.intersects_ray(face_center, face_normal)) {
+
+ const Face &current_face = faces[current_facebvhptr->face];
+ Vector3 current_points[3] = {
+ points[current_face.points[0]],
+ points[current_face.points[1]],
+ points[current_face.points[2]]
+ };
+ Vector3 current_normal = Plane(current_points[0], current_points[1], current_points[2]).normal;
+ Vector3 intersection_point;
+
+ // Check if faces are co-planar.
+ if ((current_normal - face_normal).length_squared() < CMP_EPSILON2 &&
+ is_point_in_triangle(face_center, current_points)) {
+ // Only add an intersection if checking a B face.
+ if (face.from_b)
+ _add_distance(intersectionsA, intersectionsB, current_face.from_b, 0);
+ } else if (ray_intersects_triangle(face_center, face_normal, current_points, CMP_EPSILON, intersection_point)) {
+ real_t distance = (intersection_point - face_center).length();
+ _add_distance(intersectionsA, intersectionsB, current_face.from_b, distance);
}
}
- if (bp->next != -1) {
- bp = &bvhptr[bp->next];
+
+ if (current_facebvhptr->next != -1) {
+ current_facebvhptr = &facebvhptr[current_facebvhptr->next];
} else {
- bp = NULL;
+ current_facebvhptr = nullptr;
}
}
@@ -1139,32 +608,33 @@ int CSGBrushOperation::MeshMerge::_bvh_count_intersections(BVH *bvhptr, int p_ma
} else {
- bool valid = segment_aabb.intersects(b.aabb) && b.aabb.intersects_segment(p_begin, p_end);
+ bool valid = current_facebvhptr->aabb.intersects_ray(face_center, face_normal);
if (!valid) {
-
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
-
} else {
stack[level] = (VISIT_LEFT_BIT << VISITED_BIT_SHIFT) | node;
}
}
continue;
}
+
case VISIT_LEFT_BIT: {
stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node;
- stack[level + 1] = b.left | TEST_AABB_BIT;
+ stack[level + 1] = current_facebvhptr->left | TEST_AABB_BIT;
level++;
continue;
}
+
case VISIT_RIGHT_BIT: {
stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node;
- stack[level + 1] = b.right | TEST_AABB_BIT;
+ stack[level + 1] = current_facebvhptr->right | TEST_AABB_BIT;
level++;
continue;
}
+
case VISIT_DONE_BIT: {
if (level == 0) {
@@ -1180,130 +650,112 @@ int CSGBrushOperation::MeshMerge::_bvh_count_intersections(BVH *bvhptr, int p_ma
break;
}
- return intersections;
+ // Inside if face normal intersects other faces an odd number of times.
+ return (intersectionsA.size() + intersectionsB.size()) & 1;
}
void CSGBrushOperation::MeshMerge::mark_inside_faces() {
- // mark faces that are inside. This helps later do the boolean ops when merging.
- // this approach is very brute force (with a bunch of optimizatios, such as BVH and pre AABB intersection test)
+ // Mark faces that are inside. This helps later do the boolean ops when merging.
+ // This approach is very brute force with a bunch of optimizations,
+ // such as BVH and pre AABB intersection test.
- AABB aabb;
+ Vector<FaceBVH> bvhvec;
+ bvhvec.resize(faces.size() * 3); // Will never be larger than this (TODO: Make better)
+ FaceBVH *facebvh = bvhvec.ptrw();
- for (int i = 0; i < points.size(); i++) {
- if (i == 0) {
- aabb.position = points[i];
- } else {
- aabb.expand_to(points[i]);
- }
- }
-
- float max_distance = aabb.size.length() * 1.2;
-
- Vector<BVH> bvhvec;
- bvhvec.resize(faces.size() * 3); //will never be larger than this (todo make better)
- BVH *bvh = bvhvec.ptrw();
-
- AABB faces_a;
- AABB faces_b;
+ AABB aabb_a;
+ AABB aabb_b;
bool first_a = true;
bool first_b = true;
for (int i = 0; i < faces.size(); i++) {
- bvh[i].left = -1;
- bvh[i].right = -1;
- bvh[i].face = i;
- bvh[i].aabb.position = points[faces[i].points[0]];
- bvh[i].aabb.expand_to(points[faces[i].points[1]]);
- bvh[i].aabb.expand_to(points[faces[i].points[2]]);
- bvh[i].center = bvh[i].aabb.position + bvh[i].aabb.size * 0.5;
- bvh[i].next = -1;
+ facebvh[i].left = -1;
+ facebvh[i].right = -1;
+ facebvh[i].face = i;
+ facebvh[i].aabb.position = points[faces[i].points[0]];
+ facebvh[i].aabb.expand_to(points[faces[i].points[1]]);
+ facebvh[i].aabb.expand_to(points[faces[i].points[2]]);
+ facebvh[i].center = facebvh[i].aabb.position + facebvh[i].aabb.size * 0.5;
+ facebvh[i].aabb.grow_by(vertex_snap);
+ facebvh[i].next = -1;
+
if (faces[i].from_b) {
if (first_b) {
- faces_b = bvh[i].aabb;
+ aabb_b = facebvh[i].aabb;
first_b = false;
} else {
- faces_b.merge_with(bvh[i].aabb);
+ aabb_b.merge_with(facebvh[i].aabb);
}
} else {
if (first_a) {
- faces_a = bvh[i].aabb;
+ aabb_a = facebvh[i].aabb;
first_a = false;
} else {
- faces_a.merge_with(bvh[i].aabb);
+ aabb_a.merge_with(facebvh[i].aabb);
}
}
}
- AABB intersection_aabb = faces_a.intersection(faces_b);
- intersection_aabb.grow_by(intersection_aabb.get_longest_axis_size() * 0.01); //grow a little, avoid numerical error
+ AABB intersection_aabb = aabb_a.intersection(aabb_b);
- if (intersection_aabb.size == Vector3()) //AABB do not intersect, so neither do shapes.
+ // Check if shape AABBs intersect.
+ if (intersection_aabb.size == Vector3())
return;
- Vector<BVH *> bvhtrvec;
+ Vector<FaceBVH *> bvhtrvec;
bvhtrvec.resize(faces.size());
- BVH **bvhptr = bvhtrvec.ptrw();
+ FaceBVH **bvhptr = bvhtrvec.ptrw();
for (int i = 0; i < faces.size(); i++) {
-
- bvhptr[i] = &bvh[i];
+ bvhptr[i] = &facebvh[i];
}
int max_depth = 0;
int max_alloc = faces.size();
- _create_bvh(bvh, bvhptr, 0, faces.size(), 1, max_depth, max_alloc);
+ _create_bvh(facebvh, bvhptr, 0, faces.size(), 1, max_depth, max_alloc);
for (int i = 0; i < faces.size(); i++) {
- if (!intersection_aabb.intersects(bvh[i].aabb))
- continue; //not in AABB intersection, so not in face intersection
- Vector3 center = points[faces[i].points[0]];
- center += points[faces[i].points[1]];
- center += points[faces[i].points[2]];
- center /= 3.0;
-
- Plane plane(points[faces[i].points[0]], points[faces[i].points[1]], points[faces[i].points[2]]);
- Vector3 target = center + plane.normal * max_distance + Vector3(0.0001234, 0.000512, 0.00013423); //reduce chance of edge hits by doing a small increment
-
- int intersections = _bvh_count_intersections(bvh, max_depth, max_alloc - 1, center, target, i);
+ // Check if face AABB intersects the intersection AABB.
+ if (!intersection_aabb.intersects_inclusive(facebvh[i].aabb))
+ continue;
- if (intersections & 1) {
+ if (_bvh_inside(facebvh, max_depth, max_alloc - 1, i))
faces.write[i].inside = true;
- }
}
}
-void CSGBrushOperation::MeshMerge::add_face(const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_c, const Vector2 &p_uv_a, const Vector2 &p_uv_b, const Vector2 &p_uv_c, bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b) {
+void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vector2 p_uvs[], bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b) {
- Vector3 src_points[3] = { p_a, p_b, p_c };
- Vector2 src_uvs[3] = { p_uv_a, p_uv_b, p_uv_c };
int indices[3];
for (int i = 0; i < 3; i++) {
VertexKey vk;
- vk.x = int((double(src_points[i].x) + double(vertex_snap) * 0.31234) / double(vertex_snap));
- vk.y = int((double(src_points[i].y) + double(vertex_snap) * 0.31234) / double(vertex_snap));
- vk.z = int((double(src_points[i].z) + double(vertex_snap) * 0.31234) / double(vertex_snap));
+ vk.x = int((double(p_points[i].x) + double(vertex_snap) * 0.31234) / double(vertex_snap));
+ vk.y = int((double(p_points[i].y) + double(vertex_snap) * 0.31234) / double(vertex_snap));
+ vk.z = int((double(p_points[i].z) + double(vertex_snap) * 0.31234) / double(vertex_snap));
int res;
if (snap_cache.lookup(vk, res)) {
indices[i] = res;
} else {
indices[i] = points.size();
- points.push_back(src_points[i]);
+ points.push_back(p_points[i]);
snap_cache.set(vk, indices[i]);
}
}
+ // Don't add degenerate faces.
if (indices[0] == indices[2] || indices[0] == indices[1] || indices[1] == indices[2])
- return; //not adding degenerate
+ return;
MeshMerge::Face face;
face.from_b = p_from_b;
face.inside = false;
face.smooth = p_smooth;
face.invert = p_invert;
+
if (p_material.is_valid()) {
if (!materials.has(p_material)) {
face.material_idx = materials.size();
@@ -1316,205 +768,708 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 &p_a, const Vector3 &p
}
for (int k = 0; k < 3; k++) {
-
face.points[k] = indices[k];
- face.uvs[k] = src_uvs[k];
- ;
+ face.uvs[k] = p_uvs[k];
}
faces.push_back(face);
}
-void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_A, const CSGBrush &p_B, CSGBrush &result, float p_snap) {
+// CSGBrushOperation::Build2DFaces
- CallbackData cd;
- cd.self = this;
- cd.A = &p_A;
- cd.B = &p_B;
+int CSGBrushOperation::Build2DFaces::_get_point_idx(const Vector2 &p_point) {
- MeshMerge mesh_merge;
- mesh_merge.vertex_snap = p_snap;
-
- //check intersections between faces. Use AABB to speed up precheck
- //this generates list of buildpolys and clips them.
- //this was originally BVH optimized, but its not really worth it.
- for (int i = 0; i < p_A.faces.size(); i++) {
- cd.face_a = i;
- for (int j = 0; j < p_B.faces.size(); j++) {
- if (p_A.faces[i].aabb.intersects(p_B.faces[j].aabb)) {
- _collision_callback(&p_A, i, cd.build_polys_A, &p_B, j, cd.build_polys_B, mesh_merge);
- }
- }
+ for (int vertex_idx = 0; vertex_idx < vertices.size(); ++vertex_idx) {
+ if ((p_point - vertices[vertex_idx].point).length_squared() < vertex_snap2)
+ return vertex_idx;
}
+ return -1;
+}
- //merge the already cliped polys back to 3D
- for (Map<int, BuildPoly>::Element *E = cd.build_polys_A.front(); E; E = E->next()) {
- _merge_poly(mesh_merge, E->key(), E->get(), false);
- }
+int CSGBrushOperation::Build2DFaces::_add_vertex(const Vertex2D &p_vertex) {
- for (Map<int, BuildPoly>::Element *E = cd.build_polys_B.front(); E; E = E->next()) {
- _merge_poly(mesh_merge, E->key(), E->get(), true);
- }
+ // Check if vertex exists.
+ int vertex_id = _get_point_idx(p_vertex.point);
+ if (vertex_id != -1) return vertex_id;
- //merge the non clipped faces back
+ vertices.push_back(p_vertex);
+ return vertices.size() - 1;
+}
- for (int i = 0; i < p_A.faces.size(); i++) {
+void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vertex_indices, int p_new_vertex_index) {
- if (cd.build_polys_A.has(i))
- continue; //made from buildpoly, skipping
+ if (p_new_vertex_index >= 0 && r_vertex_indices.find(p_new_vertex_index) == -1) {
+ ERR_FAIL_COND_MSG(p_new_vertex_index >= vertices.size(), "Invalid vertex index.");
- Vector3 points[3];
- Vector2 uvs[3];
- for (int j = 0; j < 3; j++) {
- points[j] = p_A.faces[i].vertices[j];
- uvs[j] = p_A.faces[i].uvs[j];
- }
- Ref<Material> material;
- if (p_A.faces[i].material != -1) {
- material = p_A.materials[p_A.faces[i].material];
+ // The first vertex.
+ if (r_vertex_indices.size() == 0) {
+ // Simply add it.
+ r_vertex_indices.push_back(p_new_vertex_index);
+ return;
}
- mesh_merge.add_face(points[0], points[1], points[2], uvs[0], uvs[1], uvs[2], p_A.faces[i].smooth, p_A.faces[i].invert, material, false);
- }
- for (int i = 0; i < p_B.faces.size(); i++) {
+ // The second vertex.
+ if (r_vertex_indices.size() == 1) {
- if (cd.build_polys_B.has(i))
- continue; //made from buildpoly, skipping
+ Vector2 first_point = vertices[r_vertex_indices[0]].point;
+ Vector2 new_point = vertices[p_new_vertex_index].point;
- Vector3 points[3];
- Vector2 uvs[3];
- for (int j = 0; j < 3; j++) {
- points[j] = p_B.faces[i].vertices[j];
- uvs[j] = p_B.faces[i].uvs[j];
+ // Sort along the axis with the greatest difference.
+ int axis = 0;
+ if (Math::abs(new_point.x - first_point.x) < Math::abs(new_point.y - first_point.y)) axis = 1;
+
+ // Add it to the beginnig or the end appropriately.
+ if (new_point[axis] < first_point[axis])
+ r_vertex_indices.insert(0, p_new_vertex_index);
+ else
+ r_vertex_indices.push_back(p_new_vertex_index);
+
+ return;
}
- Ref<Material> material;
- if (p_B.faces[i].material != -1) {
- material = p_B.materials[p_B.faces[i].material];
+
+ // Third or later vertices.
+ Vector2 first_point = vertices[r_vertex_indices[0]].point;
+ Vector2 last_point = vertices[r_vertex_indices[r_vertex_indices.size() - 1]].point;
+ Vector2 new_point = vertices[p_new_vertex_index].point;
+
+ // Determine axis being sorted against i.e. the axis with the greatest difference.
+ int axis = 0;
+ if (Math::abs(last_point.x - first_point.x) < Math::abs(last_point.y - first_point.y)) axis = 1;
+
+ // Insert the point at the appropriate index.
+ for (int insert_idx = 0; insert_idx < r_vertex_indices.size(); ++insert_idx) {
+ Vector2 insert_point = vertices[r_vertex_indices[insert_idx]].point;
+ if (new_point[axis] < insert_point[axis]) {
+ r_vertex_indices.insert(insert_idx, p_new_vertex_index);
+ return;
+ }
}
- mesh_merge.add_face(points[0], points[1], points[2], uvs[0], uvs[1], uvs[2], p_B.faces[i].smooth, p_B.faces[i].invert, material, true);
+
+ // New largest, add it to the end.
+ r_vertex_indices.push_back(p_new_vertex_index);
}
+}
- //mark faces that ended up inside the intersection
- mesh_merge.mark_inside_faces();
+void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_indices) {
- //regen new brush to start filling it again
- result.clear();
+ int segments = p_segment_indices.size() - 1;
+ if (segments < 2) return;
- switch (p_operation) {
+ // Faces around an inner vertex are merged by moving the inner vertex to the first vertex.
+ for (int sorted_idx = 1; sorted_idx < segments; ++sorted_idx) {
- case OPERATION_UNION: {
+ int closest_idx = 0;
+ int inner_idx = p_segment_indices[sorted_idx];
- int outside_count = 0;
+ if (sorted_idx > segments / 2) {
+ // Merge to other segment end.
+ closest_idx = segments;
+ // Reverse the merge order.
+ inner_idx = p_segment_indices[segments + segments / 2 - sorted_idx];
+ }
- for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (mesh_merge.faces[i].inside)
- continue;
+ // Find the mergable faces.
+ Vector<int> merge_faces_idx;
+ Vector<Face2D> merge_faces;
+ Vector<int> merge_faces_inner_vertex_idx;
+ for (int face_idx = 0; face_idx < faces.size(); ++face_idx) {
+ for (int face_vertex_idx = 0; face_vertex_idx < 3; ++face_vertex_idx) {
+ if (faces[face_idx].vertex_idx[face_vertex_idx] == inner_idx) {
+ merge_faces_idx.push_back(face_idx);
+ merge_faces.push_back(faces[face_idx]);
+ merge_faces_inner_vertex_idx.push_back(face_vertex_idx);
+ }
+ }
+ }
- outside_count++;
+ Vector<int> degenerate_points;
+
+ // Create the new faces.
+ for (int merge_idx = 0; merge_idx < merge_faces.size(); ++merge_idx) {
+
+ int outer_edge_idx[2];
+ outer_edge_idx[0] = merge_faces[merge_idx].vertex_idx[(merge_faces_inner_vertex_idx[merge_idx] + 1) % 3];
+ outer_edge_idx[1] = merge_faces[merge_idx].vertex_idx[(merge_faces_inner_vertex_idx[merge_idx] + 2) % 3];
+
+ // Skip flattened faces.
+ if (outer_edge_idx[0] == p_segment_indices[closest_idx] ||
+ outer_edge_idx[1] == p_segment_indices[closest_idx]) continue;
+
+ //Don't create degenerate triangles.
+ Vector2 edge1[2] = {
+ vertices[outer_edge_idx[0]].point,
+ vertices[p_segment_indices[closest_idx]].point
+ };
+ Vector2 edge2[2] = {
+ vertices[outer_edge_idx[1]].point,
+ vertices[p_segment_indices[closest_idx]].point
+ };
+ if (are_segements_parallel(edge1, edge2, vertex_snap2)) {
+ degenerate_points.push_back(outer_edge_idx[0]);
+ degenerate_points.push_back(outer_edge_idx[1]);
+ continue;
}
- result.faces.resize(outside_count);
+ // Create new faces.
+ Face2D new_face;
+ new_face.vertex_idx[0] = p_segment_indices[closest_idx];
+ new_face.vertex_idx[1] = outer_edge_idx[0];
+ new_face.vertex_idx[2] = outer_edge_idx[1];
+ faces.push_back(new_face);
+ }
- outside_count = 0;
+ // Delete the old faces in reverse index order.
+ merge_faces_idx.sort();
+ merge_faces_idx.invert();
+ for (int i = 0; i < merge_faces_idx.size(); ++i)
+ faces.remove(merge_faces_idx[i]);
+
+ if (degenerate_points.size() == 0) continue;
+
+ // Split faces using degenerate points.
+ for (int face_idx = 0; face_idx < faces.size(); ++face_idx) {
+
+ Face2D face = faces[face_idx];
+ Vertex2D face_vertices[3] = {
+ vertices[face.vertex_idx[0]],
+ vertices[face.vertex_idx[1]],
+ vertices[face.vertex_idx[2]]
+ };
+ Vector2 face_points[3] = {
+ face_vertices[0].point,
+ face_vertices[1].point,
+ face_vertices[2].point
+ };
+
+ for (int point_idx = 0; point_idx < degenerate_points.size(); ++point_idx) {
+
+ int degenerate_idx = degenerate_points[point_idx];
+ Vector2 point_2D = vertices[degenerate_idx].point;
+
+ // Check if point is existing face vertex.
+ bool existing = false;
+ for (int i = 0; i < 3; ++i) {
+ if ((point_2D - face_vertices[i].point).length_squared() < vertex_snap2) {
+ existing = true;
+ break;
+ }
+ }
+ if (existing) continue;
- for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (mesh_merge.faces[i].inside)
- continue;
- for (int j = 0; j < 3; j++) {
- result.faces.write[outside_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
- result.faces.write[outside_count].uvs[j] = mesh_merge.faces[i].uvs[j];
+ // Check if point is on an each edge.
+ for (int face_edge_idx = 0; face_edge_idx < 3; ++face_edge_idx) {
+
+ Vector2 edge_points[2] = {
+ face_points[face_edge_idx],
+ face_points[(face_edge_idx + 1) % 3]
+ };
+ Vector2 closest_point = Geometry::get_closest_point_to_segment_2d(point_2D, edge_points);
+
+ if ((closest_point - point_2D).length_squared() < vertex_snap2) {
+
+ int opposite_vertex_idx = face.vertex_idx[(face_edge_idx + 2) % 3];
+
+ // If new vertex snaps to degenerate vertex, just delete this face.
+ if (degenerate_idx == opposite_vertex_idx) {
+ faces.remove(face_idx);
+ // Update index.
+ --face_idx;
+ break;
+ }
+
+ // Create two new faces around the new edge and remove this face.
+ // The new edge is the last edge.
+ Face2D left_face;
+ left_face.vertex_idx[0] = degenerate_idx;
+ left_face.vertex_idx[1] = face.vertex_idx[(face_edge_idx + 1) % 3];
+ left_face.vertex_idx[2] = opposite_vertex_idx;
+ Face2D right_face;
+ right_face.vertex_idx[0] = opposite_vertex_idx;
+ right_face.vertex_idx[1] = face.vertex_idx[face_edge_idx];
+ right_face.vertex_idx[2] = degenerate_idx;
+ faces.remove(face_idx);
+ faces.insert(face_idx, right_face);
+ faces.insert(face_idx, left_face);
+
+ // Don't check against the new faces.
+ ++face_idx;
+
+ // No need to check other edges.
+ break;
+ }
}
+ }
+ }
+ }
+}
- result.faces.write[outside_count].smooth = mesh_merge.faces[i].smooth;
- result.faces.write[outside_count].invert = mesh_merge.faces[i].invert;
- result.faces.write[outside_count].material = mesh_merge.faces[i].material_idx;
- outside_count++;
+void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_segment_points[2], Vector<int> &r_segment_indices) {
+
+ // For each face.
+ for (int face_idx = 0; face_idx < faces.size(); ++face_idx) {
+
+ Face2D face = faces[face_idx];
+ Vertex2D face_vertices[3] = {
+ vertices[face.vertex_idx[0]],
+ vertices[face.vertex_idx[1]],
+ vertices[face.vertex_idx[2]]
+ };
+
+ // Check each edge.
+ for (int face_edge_idx = 0; face_edge_idx < 3; ++face_edge_idx) {
+
+ Vector2 edge_points[2] = {
+ face_vertices[face_edge_idx].point,
+ face_vertices[(face_edge_idx + 1) % 3].point
+ };
+ Vector2 edge_uvs[2] = {
+ face_vertices[face_edge_idx].uv,
+ face_vertices[(face_edge_idx + 1) % 3].uv
+ };
+ Vector2 intersection_point;
+
+ // First check if the ends of the segment are on the edge.
+ bool on_edge = false;
+ for (int edge_point_idx = 0; edge_point_idx < 2; ++edge_point_idx) {
+ intersection_point = Geometry::get_closest_point_to_segment_2d(p_segment_points[edge_point_idx], edge_points);
+ if ((intersection_point - p_segment_points[edge_point_idx]).length_squared() < vertex_snap2) {
+ on_edge = true;
+ break;
+ }
}
- result._regen_face_aabbs();
+ // Else check if the segment intersects the edge.
+ if (on_edge || Geometry::segment_intersects_segment_2d(p_segment_points[0], p_segment_points[1], edge_points[0], edge_points[1], &intersection_point)) {
+
+ // Check if intersection point is an edge point.
+ if ((intersection_point - edge_points[0]).length_squared() < vertex_snap2 ||
+ (intersection_point - edge_points[1]).length_squared() < vertex_snap2) continue;
+
+ // Check if edge exists, by checking if the intersecting segment is parallel to the edge.
+ if (are_segements_parallel(p_segment_points, edge_points, vertex_snap2)) continue;
+
+ // Add the intersection point as a new vertex.
+ Vertex2D new_vertex;
+ new_vertex.point = intersection_point;
+ new_vertex.uv = interpolate_segment_uv(edge_points, edge_uvs, intersection_point);
+ int new_vertex_idx = _add_vertex(new_vertex);
+ int opposite_vertex_idx = face.vertex_idx[(face_edge_idx + 2) % 3];
+ _add_vertex_idx_sorted(r_segment_indices, new_vertex_idx);
+
+ // If new vertex snaps to opposite vertex, just delete this face.
+ if (new_vertex_idx == opposite_vertex_idx) {
+ faces.remove(face_idx);
+ // Update index.
+ --face_idx;
+ break;
+ }
- } break;
- case OPERATION_INTERSECTION: {
+ // Don't create degenerate triangles.
+ Vector2 split_edge1[2] = { vertices[new_vertex_idx].point, edge_points[0] };
+ Vector2 split_edge2[2] = { vertices[new_vertex_idx].point, edge_points[1] };
+ Vector2 new_edge[2] = { vertices[new_vertex_idx].point, vertices[opposite_vertex_idx].point };
+ if (are_segements_parallel(split_edge1, new_edge, vertex_snap2) &&
+ are_segements_parallel(split_edge2, new_edge, vertex_snap2)) {
+ break;
+ }
- int inside_count = 0;
+ // If opposite point is on the segemnt, add its index to segment indices too.
+ Vector2 closest_point = Geometry::get_closest_point_to_segment_2d(vertices[opposite_vertex_idx].point, p_segment_points);
+ if ((closest_point - vertices[opposite_vertex_idx].point).length_squared() < vertex_snap2)
+ _add_vertex_idx_sorted(r_segment_indices, opposite_vertex_idx);
+
+ // Create two new faces around the new edge and remove this face.
+ // The new edge is the last edge.
+ Face2D left_face;
+ left_face.vertex_idx[0] = new_vertex_idx;
+ left_face.vertex_idx[1] = face.vertex_idx[(face_edge_idx + 1) % 3];
+ left_face.vertex_idx[2] = opposite_vertex_idx;
+ Face2D right_face;
+ right_face.vertex_idx[0] = opposite_vertex_idx;
+ right_face.vertex_idx[1] = face.vertex_idx[face_edge_idx];
+ right_face.vertex_idx[2] = new_vertex_idx;
+ faces.remove(face_idx);
+ faces.insert(face_idx, right_face);
+ faces.insert(face_idx, left_face);
+
+ // Check against the new faces.
+ --face_idx;
+ break;
+ }
+ }
+ }
+}
- for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (!mesh_merge.faces[i].inside)
- continue;
+int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) {
+
+ int new_vertex_idx = -1;
+
+ for (int face_idx = 0; face_idx < faces.size(); ++face_idx) {
+
+ Face2D face = faces[face_idx];
+ Vertex2D face_vertices[3] = {
+ vertices[face.vertex_idx[0]],
+ vertices[face.vertex_idx[1]],
+ vertices[face.vertex_idx[2]]
+ };
+ Vector2 points[3] = {
+ face_vertices[0].point,
+ face_vertices[1].point,
+ face_vertices[2].point
+ };
+ Vector2 uvs[3] = {
+ face_vertices[0].uv,
+ face_vertices[1].uv,
+ face_vertices[2].uv
+ };
+
+ // Check if point is existing face vertex.
+ for (int i = 0; i < 3; ++i) {
+ if ((p_point - face_vertices[i].point).length_squared() < vertex_snap2)
+ return face.vertex_idx[i];
+ }
- inside_count++;
- }
+ // Check if point is on an each edge.
+ bool on_edge = false;
+ for (int face_edge_idx = 0; face_edge_idx < 3; ++face_edge_idx) {
+
+ Vector2 edge_points[2] = {
+ points[face_edge_idx],
+ points[(face_edge_idx + 1) % 3]
+ };
+ Vector2 edge_uvs[2] = {
+ uvs[face_edge_idx],
+ uvs[(face_edge_idx + 1) % 3]
+ };
+
+ Vector2 closest_point = Geometry::get_closest_point_to_segment_2d(p_point, edge_points);
+ if ((closest_point - p_point).length_squared() < vertex_snap2) {
+ on_edge = true;
+
+ // Add the point as a new vertex.
+ Vertex2D new_vertex;
+ new_vertex.point = p_point;
+ new_vertex.uv = interpolate_segment_uv(edge_points, edge_uvs, p_point);
+ new_vertex_idx = _add_vertex(new_vertex);
+ int opposite_vertex_idx = face.vertex_idx[(face_edge_idx + 2) % 3];
+
+ // If new vertex snaps to opposite vertex, just delete this face.
+ if (new_vertex_idx == opposite_vertex_idx) {
+ faces.remove(face_idx);
+ // Update index.
+ --face_idx;
+ break;
+ }
- result.faces.resize(inside_count);
+ // Don't create degenerate triangles.
+ Vector2 split_edge1[2] = { vertices[new_vertex_idx].point, edge_points[0] };
+ Vector2 split_edge2[2] = { vertices[new_vertex_idx].point, edge_points[1] };
+ Vector2 new_edge[2] = { vertices[new_vertex_idx].point, vertices[opposite_vertex_idx].point };
+ if (are_segements_parallel(split_edge1, new_edge, vertex_snap2) &&
+ are_segements_parallel(split_edge2, new_edge, vertex_snap2)) {
+ break;
+ }
- inside_count = 0;
+ // Create two new faces around the new edge and remove this face.
+ // The new edge is the last edge.
+ Face2D left_face;
+ left_face.vertex_idx[0] = new_vertex_idx;
+ left_face.vertex_idx[1] = face.vertex_idx[(face_edge_idx + 1) % 3];
+ left_face.vertex_idx[2] = opposite_vertex_idx;
+ Face2D right_face;
+ right_face.vertex_idx[0] = opposite_vertex_idx;
+ right_face.vertex_idx[1] = face.vertex_idx[face_edge_idx];
+ right_face.vertex_idx[2] = new_vertex_idx;
+ faces.remove(face_idx);
+ faces.insert(face_idx, right_face);
+ faces.insert(face_idx, left_face);
+
+ // Don't check against the new faces.
+ ++face_idx;
+
+ // No need to check other edges.
+ break;
+ }
+ }
- for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (!mesh_merge.faces[i].inside)
+ // If not on an edge, check if the point is inside the face.
+ if (!on_edge && Geometry::is_point_in_triangle(p_point, face_vertices[0].point, face_vertices[1].point, face_vertices[2].point)) {
+
+ // Add the point as a new vertex.
+ Vertex2D new_vertex;
+ new_vertex.point = p_point;
+ new_vertex.uv = interpolate_triangle_uv(points, uvs, p_point);
+ new_vertex_idx = _add_vertex(new_vertex);
+
+ // Create three new faces around this point and remove this face.
+ // The new vertex is the last vertex.
+ for (int i = 0; i < 3; ++i) {
+
+ // Don't create degenerate triangles.
+ Vector2 edge[2] = { points[i], points[(i + 1) % 3] };
+ Vector2 new_edge1[2] = { vertices[new_vertex_idx].point, points[i] };
+ Vector2 new_edge2[2] = { vertices[new_vertex_idx].point, points[(i + 1) % 3] };
+ if (are_segements_parallel(edge, new_edge1, vertex_snap2) &&
+ are_segements_parallel(edge, new_edge2, vertex_snap2)) {
continue;
- for (int j = 0; j < 3; j++) {
- result.faces.write[inside_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
- result.faces.write[inside_count].uvs[j] = mesh_merge.faces[i].uvs[j];
}
- result.faces.write[inside_count].smooth = mesh_merge.faces[i].smooth;
- result.faces.write[inside_count].invert = mesh_merge.faces[i].invert;
- result.faces.write[inside_count].material = mesh_merge.faces[i].material_idx;
- inside_count++;
+ Face2D new_face;
+ new_face.vertex_idx[0] = face.vertex_idx[i];
+ new_face.vertex_idx[1] = face.vertex_idx[(i + 1) % 3];
+ new_face.vertex_idx[2] = new_vertex_idx;
+ faces.push_back(new_face);
}
+ faces.remove(face_idx);
- result._regen_face_aabbs();
+ // No need to check other faces.
+ break;
+ }
+ }
- } break;
- case OPERATION_SUBSTRACTION: {
+ return new_vertex_idx;
+}
- int face_count = 0;
+void CSGBrushOperation::Build2DFaces::insert(const CSGBrush &p_brush, int p_face_idx) {
- for (int i = 0; i < mesh_merge.faces.size(); i++) {
- if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside)
- continue;
- if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside)
- continue;
+ // Find edge points that cross the plane and face points that are in the plane.
+ // Map those points to 2D.
+ // Create new faces from those points.
- face_count++;
+ Vector2 points_2D[3];
+ int points_count = 0;
+
+ for (int i = 0; i < 3; i++) {
+
+ Vector3 point_3D = p_brush.faces[p_face_idx].vertices[i];
+
+ if (plane.has_point(point_3D)) {
+ // Point is in the plane, add it.
+ Vector3 point_2D = plane.project(point_3D);
+ point_2D = to_2D.xform(point_2D);
+ points_2D[points_count++] = Vector2(point_2D.x, point_2D.y);
+
+ } else {
+
+ Vector3 next_point_3D = p_brush.faces[p_face_idx].vertices[(i + 1) % 3];
+
+ if (plane.has_point(next_point_3D))
+ continue; // Next point is in plane, it will be added separately.
+ if (plane.is_point_over(point_3D) == plane.is_point_over(next_point_3D))
+ continue; // Both points on the same side of the plane, ignore.
+
+ // Edge crosses the plane, find and add the intersection point.
+ Vector3 point_2D;
+ if (plane.intersects_segment(point_3D, next_point_3D, &point_2D)) {
+ point_2D = to_2D.xform(point_2D);
+ points_2D[points_count++] = Vector2(point_2D.x, point_2D.y);
}
+ }
+ }
- result.faces.resize(face_count);
+ Vector<int> segment_indices;
+ Vector2 segment[2];
+ int inserted_index[3] = { -1, -1, -1 };
- face_count = 0;
+ // Insert points.
+ for (int i = 0; i < points_count; ++i) {
+ inserted_index[i] = _insert_point(points_2D[i]);
+ }
- for (int i = 0; i < mesh_merge.faces.size(); i++) {
+ if (points_count == 2) {
+ // Insert a single segment.
+ segment[0] = points_2D[0];
+ segment[1] = points_2D[1];
+ _find_edge_intersections(segment, segment_indices);
+ for (int i = 0; i < 2; ++i) {
+ _add_vertex_idx_sorted(segment_indices, inserted_index[i]);
+ }
+ _merge_faces(segment_indices);
+ }
- if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside)
- continue;
- if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside)
- continue;
+ if (points_count == 3) {
+ // Insert three segments.
+ for (int edge_idx = 0; edge_idx < 3; ++edge_idx) {
+ segment[0] = points_2D[edge_idx];
+ segment[1] = points_2D[(edge_idx + 1) % 3];
+ _find_edge_intersections(segment, segment_indices);
+ for (int i = 0; i < 2; ++i) {
+ _add_vertex_idx_sorted(segment_indices, inserted_index[(edge_idx + i) % 3]);
+ }
+ _merge_faces(segment_indices);
+ segment_indices.clear();
+ }
+ }
+}
- for (int j = 0; j < 3; j++) {
- result.faces.write[face_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]];
- result.faces.write[face_count].uvs[j] = mesh_merge.faces[i].uvs[j];
- }
+void CSGBrushOperation::Build2DFaces::addFacesToMesh(MeshMerge &r_mesh_merge, bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b) {
- if (mesh_merge.faces[i].from_b) {
- //invert facing of insides of B
- SWAP(result.faces.write[face_count].vertices[1], result.faces.write[face_count].vertices[2]);
- SWAP(result.faces.write[face_count].uvs[1], result.faces.write[face_count].uvs[2]);
+ for (int face_idx = 0; face_idx < faces.size(); ++face_idx) {
+ Face2D face = faces[face_idx];
+ Vertex2D fv[3] = {
+ vertices[face.vertex_idx[0]],
+ vertices[face.vertex_idx[1]],
+ vertices[face.vertex_idx[2]]
+ };
+
+ // Convert 2D vertex points to 3D.
+ Vector3 points_3D[3];
+ Vector2 uvs[3];
+ for (int i = 0; i < 3; ++i) {
+ Vector3 point_2D(fv[i].point.x, fv[i].point.y, 0);
+ points_3D[i] = to_3D.xform(point_2D);
+ uvs[i] = fv[i].uv;
+ }
+
+ r_mesh_merge.add_face(points_3D, uvs, p_smooth, p_invert, p_material, p_from_b);
+ }
+}
+
+CSGBrushOperation::Build2DFaces::Build2DFaces(const CSGBrush &p_brush, int p_face_idx, float p_vertex_snap2) :
+ vertex_snap2(p_vertex_snap2 * p_vertex_snap2) {
+
+ // Convert 3D vertex points to 2D.
+ Vector3 points_3D[3] = {
+ p_brush.faces[p_face_idx].vertices[0],
+ p_brush.faces[p_face_idx].vertices[1],
+ p_brush.faces[p_face_idx].vertices[2],
+ };
+
+ plane = Plane(points_3D[0], points_3D[1], points_3D[2]);
+ to_3D.origin = points_3D[0];
+ to_3D.basis.set_axis(2, plane.normal);
+ to_3D.basis.set_axis(0, (points_3D[1] - points_3D[2]).normalized());
+ to_3D.basis.set_axis(1, to_3D.basis.get_axis(0).cross(to_3D.basis.get_axis(2)).normalized());
+ to_2D = to_3D.affine_inverse();
+
+ Face2D face;
+ for (int i = 0; i < 3; i++) {
+ Vertex2D vertex;
+ Vector3 point_2D = to_2D.xform(points_3D[i]);
+ vertex.point.x = point_2D.x;
+ vertex.point.y = point_2D.y;
+ vertex.uv = p_brush.faces[p_face_idx].uvs[i];
+ vertices.push_back(vertex);
+ face.vertex_idx[i] = i;
+ }
+ faces.push_back(face);
+}
+
+void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face_idx_a, const CSGBrush &p_brush_b, const int p_face_idx_b, Build2DFaceCollection &p_collection, float p_vertex_snap) {
+
+ Vector3 vertices_a[3] = {
+ p_brush_a.faces[p_face_idx_a].vertices[0],
+ p_brush_a.faces[p_face_idx_a].vertices[1],
+ p_brush_a.faces[p_face_idx_a].vertices[2],
+ };
+
+ Vector3 vertices_b[3] = {
+ p_brush_b.faces[p_face_idx_b].vertices[0],
+ p_brush_b.faces[p_face_idx_b].vertices[1],
+ p_brush_b.faces[p_face_idx_b].vertices[2],
+ };
+
+ // Don't use degenerate faces.
+ bool has_degenerate = false;
+ if (is_snapable(vertices_a[0], vertices_a[1], p_vertex_snap) ||
+ is_snapable(vertices_a[0], vertices_a[2], p_vertex_snap) ||
+ is_snapable(vertices_a[1], vertices_a[2], p_vertex_snap)) {
+ p_collection.build2DFacesA[p_face_idx_a] = Build2DFaces();
+ has_degenerate = true;
+ }
+
+ if (is_snapable(vertices_b[0], vertices_b[1], p_vertex_snap) ||
+ is_snapable(vertices_b[0], vertices_b[2], p_vertex_snap) ||
+ is_snapable(vertices_b[1], vertices_b[2], p_vertex_snap)) {
+ p_collection.build2DFacesB[p_face_idx_b] = Build2DFaces();
+ has_degenerate = true;
+ }
+ if (has_degenerate) return;
+
+ // Ensure B has points either side of or in the plane of A.
+ int in_plane_count = 0, over_count = 0, under_count = 0;
+ Plane plane_a(vertices_a[0], vertices_a[1], vertices_a[2]);
+ ERR_FAIL_COND_MSG(plane_a.normal == Vector3(), "Couldn't form plane from Brush A face.");
+
+ for (int i = 0; i < 3; i++) {
+ if (plane_a.has_point(vertices_b[i]))
+ in_plane_count++;
+ else if (plane_a.is_point_over(vertices_b[i]))
+ over_count++;
+ else
+ under_count++;
+ }
+ // If all points under or over the plane, there is no intesection.
+ if (over_count == 3 || under_count == 3) return;
+
+ // Ensure A has points either side of or in the plane of B.
+ in_plane_count = 0;
+ over_count = 0;
+ under_count = 0;
+ Plane plane_b(vertices_b[0], vertices_b[1], vertices_b[2]);
+ ERR_FAIL_COND_MSG(plane_b.normal == Vector3(), "Couldn't form plane from Brush B face.");
+
+ for (int i = 0; i < 3; i++) {
+ if (plane_b.has_point(vertices_a[i]))
+ in_plane_count++;
+ else if (plane_b.is_point_over(vertices_a[i]))
+ over_count++;
+ else
+ under_count++;
+ }
+ // If all points under or over the plane, there is no intesection.
+ if (over_count == 3 || under_count == 3) return;
+
+ // Check for intersection using the SAT theorem.
+ {
+
+ // Edge pair cross product combinations.
+ for (int i = 0; i < 3; i++) {
+
+ Vector3 axis_a = (vertices_a[i] - vertices_a[(i + 1) % 3]).normalized();
+
+ for (int j = 0; j < 3; j++) {
+
+ Vector3 axis_b = (vertices_b[j] - vertices_b[(j + 1) % 3]).normalized();
+
+ Vector3 sep_axis = axis_a.cross(axis_b);
+ if (sep_axis == Vector3())
+ continue; //colineal
+ sep_axis.normalize();
+
+ real_t min_a = 1e20, max_a = -1e20;
+ real_t min_b = 1e20, max_b = -1e20;
+
+ for (int k = 0; k < 3; k++) {
+ real_t d = sep_axis.dot(vertices_a[k]);
+ min_a = MIN(min_a, d);
+ max_a = MAX(max_a, d);
+ d = sep_axis.dot(vertices_b[k]);
+ min_b = MIN(min_b, d);
+ max_b = MAX(max_b, d);
}
- result.faces.write[face_count].smooth = mesh_merge.faces[i].smooth;
- result.faces.write[face_count].invert = mesh_merge.faces[i].invert;
- result.faces.write[face_count].material = mesh_merge.faces[i].material_idx;
- face_count++;
- }
+ min_b -= (max_a - min_a) * 0.5;
+ max_b += (max_a - min_a) * 0.5;
- result._regen_face_aabbs();
+ real_t dmin = min_b - (min_a + max_a) * 0.5;
+ real_t dmax = max_b - (min_a + max_a) * 0.5;
- } break;
+ if (dmin > CMP_EPSILON || dmax < -CMP_EPSILON) {
+ return; // Does not contain zero, so they don't overlap.
+ }
+ }
+ }
}
- //updatelist of materials
- result.materials.resize(mesh_merge.materials.size());
- for (const Map<Ref<Material>, int>::Element *E = mesh_merge.materials.front(); E; E = E->next()) {
- result.materials.write[E->get()] = E->key();
+ // If we're still here, the faces probably intersect, so add new faces.
+ if (!p_collection.build2DFacesA.has(p_face_idx_a)) {
+ p_collection.build2DFacesA[p_face_idx_a] = Build2DFaces(p_brush_a, p_face_idx_a, p_vertex_snap);
+ }
+ p_collection.build2DFacesA[p_face_idx_a].insert(p_brush_b, p_face_idx_b);
+
+ if (!p_collection.build2DFacesB.has(p_face_idx_b)) {
+ p_collection.build2DFacesB[p_face_idx_b] = Build2DFaces(p_brush_b, p_face_idx_b, p_vertex_snap);
}
+ p_collection.build2DFacesB[p_face_idx_b].insert(p_brush_a, p_face_idx_a);
}
diff --git a/modules/csg/csg.h b/modules/csg/csg.h
index 472a96d5df..bb83c84cb5 100644
--- a/modules/csg/csg.h
+++ b/modules/csg/csg.h
@@ -31,20 +31,21 @@
#ifndef CSG_H
#define CSG_H
+#include "core/list.h"
#include "core/map.h"
#include "core/math/aabb.h"
#include "core/math/plane.h"
-#include "core/math/rect2.h"
#include "core/math/transform.h"
+#include "core/math/vector2.h"
#include "core/math/vector3.h"
#include "core/oa_hash_map.h"
-
+#include "core/reference.h"
+#include "core/vector.h"
#include "scene/resources/material.h"
struct CSGBrush {
struct Face {
-
Vector3 vertices[3];
Vector2 uvs[3];
AABB aabb;
@@ -56,12 +57,11 @@ struct CSGBrush {
Vector<Face> faces;
Vector<Ref<Material> > materials;
- void _regen_face_aabbs();
- //create a brush from faces
+ inline void _regen_face_aabbs();
+
+ // Create a brush from faces.
void build_from_faces(const Vector<Vector3> &p_vertices, const Vector<Vector2> &p_uvs, const Vector<bool> &p_smooth, const Vector<Ref<Material> > &p_materials, const Vector<bool> &p_invert_faces);
void copy_from(const CSGBrush &p_brush, const Transform &p_xform);
-
- void clear();
};
struct CSGBrushOperation {
@@ -70,12 +70,23 @@ struct CSGBrushOperation {
OPERATION_UNION,
OPERATION_INTERSECTION,
OPERATION_SUBSTRACTION,
-
};
+ void merge_brushes(Operation p_operation, const CSGBrush &p_brush_a, const CSGBrush &p_brush_b, CSGBrush &r_merged_brush, float p_vertex_snap);
+
struct MeshMerge {
- struct BVH {
+ struct Face {
+ bool from_b;
+ bool inside;
+ int points[3];
+ Vector2 uvs[3];
+ bool smooth;
+ bool invert;
+ int material_idx;
+ };
+
+ struct FaceBVH {
int face;
int left;
int right;
@@ -84,32 +95,23 @@ struct CSGBrushOperation {
AABB aabb;
};
- struct BVHCmpX {
-
- bool operator()(const BVH *p_left, const BVH *p_right) const {
-
+ struct FaceBVHCmpX {
+ _FORCE_INLINE_ bool operator()(const FaceBVH *p_left, const FaceBVH *p_right) const {
return p_left->center.x < p_right->center.x;
}
};
- struct BVHCmpY {
-
- bool operator()(const BVH *p_left, const BVH *p_right) const {
-
+ struct FaceBVHCmpY {
+ _FORCE_INLINE_ bool operator()(const FaceBVH *p_left, const FaceBVH *p_right) const {
return p_left->center.y < p_right->center.y;
}
};
- struct BVHCmpZ {
-
- bool operator()(const BVH *p_left, const BVH *p_right) const {
-
+ struct FaceBVHCmpZ {
+ _FORCE_INLINE_ bool operator()(const FaceBVH *p_left, const FaceBVH *p_right) const {
return p_left->center.z < p_right->center.z;
}
};
- int _bvh_count_intersections(BVH *bvhptr, int p_max_depth, int p_bvh_first, const Vector3 &p_begin, const Vector3 &p_end, int p_exclude) const;
- int _create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, int p_depth, int &max_depth, int &max_alloc);
-
struct VertexKey {
int32_t x, y, z;
_FORCE_INLINE_ bool operator<(const VertexKey &p_key) const {
@@ -138,99 +140,59 @@ struct CSGBrushOperation {
}
};
- OAHashMap<VertexKey, int, VertexKeyHash> snap_cache;
-
Vector<Vector3> points;
-
- struct Face {
- bool from_b;
- bool inside;
- int points[3];
- Vector2 uvs[3];
- bool smooth;
- bool invert;
- int material_idx;
- };
-
Vector<Face> faces;
-
Map<Ref<Material>, int> materials;
-
Map<Vector3, int> vertex_map;
- void add_face(const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_c, const Vector2 &p_uv_a, const Vector2 &p_uv_b, const Vector2 &p_uv_c, bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b);
- // void add_face(const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_c, bool p_from_b);
-
+ OAHashMap<VertexKey, int, VertexKeyHash> snap_cache;
float vertex_snap;
+
+ inline void _add_distance(List<real_t> &r_intersectionsA, List<real_t> &r_intersectionsB, bool p_from_B, real_t p_distance) const;
+ inline bool _bvh_inside(FaceBVH *facebvhptr, int p_max_depth, int p_bvh_first, int p_face_idx) const;
+ inline int _create_bvh(FaceBVH *facebvhptr, FaceBVH **facebvhptrptr, int p_from, int p_size, int p_depth, int &r_max_depth, int &r_max_alloc);
+
+ void add_face(const Vector3 p_points[3], const Vector2 p_uvs[3], bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b);
void mark_inside_faces();
};
- struct BuildPoly {
+ struct Build2DFaces {
- Plane plane;
- Transform to_poly;
- Transform to_world;
- int face_index;
-
- struct Point {
+ struct Vertex2D {
Vector2 point;
Vector2 uv;
};
- Vector<Point> points;
-
- struct Edge {
- bool outer;
- int points[2];
- Edge() {
- outer = false;
- }
+ struct Face2D {
+ int vertex_idx[3];
};
- Vector<Edge> edges;
- Ref<Material> material;
- bool smooth;
- bool invert;
-
- int base_edges; //edges from original triangle, even if split
-
- void _clip_segment(const CSGBrush *p_brush, int p_face, const Vector2 *segment, MeshMerge &mesh_merge, bool p_for_B);
-
- void create(const CSGBrush *p_brush, int p_face, MeshMerge &mesh_merge, bool p_for_B);
- void clip(const CSGBrush *p_brush, int p_face, MeshMerge &mesh_merge, bool p_for_B);
- };
-
- struct PolyPoints {
-
- Vector<int> points;
-
- Vector<Vector<int> > holes;
- };
-
- struct EdgeSort {
- int edge;
- int prev_point;
- int edge_point;
- float angle;
- bool operator<(const EdgeSort &p_edge) const { return angle < p_edge.angle; }
+ Vector<Vertex2D> vertices;
+ Vector<Face2D> faces;
+ Plane plane;
+ Transform to_2D;
+ Transform to_3D;
+ float vertex_snap2;
+
+ inline int _get_point_idx(const Vector2 &p_point);
+ inline int _add_vertex(const Vertex2D &p_vertex);
+ inline void _add_vertex_idx_sorted(Vector<int> &r_vertex_indices, int p_new_vertex_index);
+ inline void _merge_faces(const Vector<int> &p_segment_indices);
+ inline void _find_edge_intersections(const Vector2 p_segment_points[2], Vector<int> &r_segment_indices);
+ inline int _insert_point(const Vector2 &p_point);
+
+ void insert(const CSGBrush &p_brush, int p_brush_face);
+ void addFacesToMesh(MeshMerge &r_mesh_merge, bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b);
+
+ Build2DFaces() {}
+ Build2DFaces(const CSGBrush &p_brush, int p_brush_face, float p_vertex_snap2);
};
- struct CallbackData {
- const CSGBrush *A;
- const CSGBrush *B;
- int face_a;
- CSGBrushOperation *self;
- Map<int, BuildPoly> build_polys_A;
- Map<int, BuildPoly> build_polys_B;
+ struct Build2DFaceCollection {
+ Map<int, Build2DFaces> build2DFacesA;
+ Map<int, Build2DFaces> build2DFacesB;
};
- void _add_poly_points(const BuildPoly &p_poly, int p_edge, int p_from_point, int p_to_point, const Vector<Vector<int> > &vertex_process, Vector<bool> &edge_process, Vector<PolyPoints> &r_poly);
- void _add_poly_outline(const BuildPoly &p_poly, int p_from_point, int p_to_point, const Vector<Vector<int> > &vertex_process, Vector<int> &r_outline);
- void _merge_poly(MeshMerge &mesh, int p_face_idx, const BuildPoly &p_poly, bool p_from_b);
-
- void _collision_callback(const CSGBrush *A, int p_face_a, Map<int, BuildPoly> &build_polys_a, const CSGBrush *B, int p_face_b, Map<int, BuildPoly> &build_polys_b, MeshMerge &mesh_merge);
-
- static void _collision_callbacks(void *ud, int p_face_b);
- void merge_brushes(Operation p_operation, const CSGBrush &p_A, const CSGBrush &p_B, CSGBrush &result, float p_snap = 0.001);
+ void update_faces(const CSGBrush &p_brush_a, const int p_face_idx_a, const CSGBrush &p_brush_b, const int p_face_idx_b, Build2DFaceCollection &p_collection, float p_vertex_snap);
};
#endif // CSG_H
diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp
index 7e7f383ea6..a227d49892 100644
--- a/modules/csg/csg_shape.cpp
+++ b/modules/csg/csg_shape.cpp
@@ -621,7 +621,7 @@ void CSGShape::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_meshes"), &CSGShape::get_meshes);
ADD_PROPERTY(PropertyInfo(Variant::INT, "operation", PROPERTY_HINT_ENUM, "Union,Intersection,Subtraction"), "set_operation", "get_operation");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "snap", PROPERTY_HINT_RANGE, "0.0001,1,0.001"), "set_snap", "get_snap");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "snap", PROPERTY_HINT_RANGE, "0.0001,1,0.001"), "set_snap", "get_snap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "calculate_tangents"), "set_calculate_tangents", "is_calculating_tangents");
ADD_GROUP("Collision", "collision_");
@@ -884,8 +884,6 @@ void CSGMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CSGMesh::set_mesh);
ClassDB::bind_method(D_METHOD("get_mesh"), &CSGMesh::get_mesh);
- ClassDB::bind_method(D_METHOD("_mesh_changed"), &CSGMesh::_mesh_changed);
-
ClassDB::bind_method(D_METHOD("set_material", "material"), &CSGMesh::set_material);
ClassDB::bind_method(D_METHOD("get_material"), &CSGMesh::get_material);
@@ -898,12 +896,12 @@ void CSGMesh::set_mesh(const Ref<Mesh> &p_mesh) {
if (mesh == p_mesh)
return;
if (mesh.is_valid()) {
- mesh->disconnect_compat("changed", this, "_mesh_changed");
+ mesh->disconnect("changed", callable_mp(this, &CSGMesh::_mesh_changed));
}
mesh = p_mesh;
if (mesh.is_valid()) {
- mesh->connect_compat("changed", this, "_mesh_changed");
+ mesh->connect("changed", callable_mp(this, &CSGMesh::_mesh_changed));
}
_make_dirty();
@@ -1049,7 +1047,7 @@ void CSGSphere::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_material", "material"), &CSGSphere::set_material);
ClassDB::bind_method(D_METHOD("get_material"), &CSGSphere::get_material);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius", PROPERTY_HINT_RANGE, "0.001,100.0,0.001"), "set_radius", "get_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.001,100.0,0.001"), "set_radius", "get_radius");
ADD_PROPERTY(PropertyInfo(Variant::INT, "radial_segments", PROPERTY_HINT_RANGE, "1,100,1"), "set_radial_segments", "get_radial_segments");
ADD_PROPERTY(PropertyInfo(Variant::INT, "rings", PROPERTY_HINT_RANGE, "1,100,1"), "set_rings", "get_rings");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces");
@@ -1236,9 +1234,9 @@ void CSGBox::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_material", "material"), &CSGBox::set_material);
ClassDB::bind_method(D_METHOD("get_material"), &CSGBox::get_material);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "width", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_width", "get_width");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "height", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_height", "get_height");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "depth", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_depth", "get_depth");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "width", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_width", "get_width");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_height", "get_height");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_depth", "get_depth");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "StandardMaterial3D,ShaderMaterial"), "set_material", "get_material");
}
@@ -1451,8 +1449,8 @@ void CSGCylinder::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_smooth_faces", "smooth_faces"), &CSGCylinder::set_smooth_faces);
ClassDB::bind_method(D_METHOD("get_smooth_faces"), &CSGCylinder::get_smooth_faces);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_radius", "get_radius");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "height", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_height", "get_height");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_radius", "get_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_height", "get_height");
ADD_PROPERTY(PropertyInfo(Variant::INT, "sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_sides", "get_sides");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cone"), "set_cone", "is_cone");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces");
@@ -1678,8 +1676,8 @@ void CSGTorus::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_smooth_faces", "smooth_faces"), &CSGTorus::set_smooth_faces);
ClassDB::bind_method(D_METHOD("get_smooth_faces"), &CSGTorus::get_smooth_faces);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "inner_radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_inner_radius", "get_inner_radius");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "outer_radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_outer_radius", "get_outer_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "inner_radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_inner_radius", "get_inner_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "outer_radius", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_outer_radius", "get_outer_radius");
ADD_PROPERTY(PropertyInfo(Variant::INT, "sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_sides", "get_sides");
ADD_PROPERTY(PropertyInfo(Variant::INT, "ring_sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_ring_sides", "get_ring_sides");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces");
@@ -1812,15 +1810,15 @@ CSGBrush *CSGPolygon::_build_brush() {
if (path != path_cache) {
if (path_cache) {
- path_cache->disconnect_compat("tree_exited", this, "_path_exited");
- path_cache->disconnect_compat("curve_changed", this, "_path_changed");
+ path_cache->disconnect("tree_exited", callable_mp(this, &CSGPolygon::_path_exited));
+ path_cache->disconnect("curve_changed", callable_mp(this, &CSGPolygon::_path_changed));
path_cache = NULL;
}
path_cache = path;
- path_cache->connect_compat("tree_exited", this, "_path_exited");
- path_cache->connect_compat("curve_changed", this, "_path_changed");
+ path_cache->connect("tree_exited", callable_mp(this, &CSGPolygon::_path_exited));
+ path_cache->connect("curve_changed", callable_mp(this, &CSGPolygon::_path_changed));
path_cache = NULL;
}
curve = path->get_curve();
@@ -2236,8 +2234,8 @@ CSGBrush *CSGPolygon::_build_brush() {
void CSGPolygon::_notification(int p_what) {
if (p_what == NOTIFICATION_EXIT_TREE) {
if (path_cache) {
- path_cache->disconnect_compat("tree_exited", this, "_path_exited");
- path_cache->disconnect_compat("curve_changed", this, "_path_changed");
+ path_cache->disconnect("tree_exited", callable_mp(this, &CSGPolygon::_path_exited));
+ path_cache->disconnect("curve_changed", callable_mp(this, &CSGPolygon::_path_changed));
path_cache = NULL;
}
}
@@ -2309,16 +2307,13 @@ void CSGPolygon::_bind_methods() {
ClassDB::bind_method(D_METHOD("_is_editable_3d_polygon"), &CSGPolygon::_is_editable_3d_polygon);
ClassDB::bind_method(D_METHOD("_has_editable_3d_polygon_no_depth"), &CSGPolygon::_has_editable_3d_polygon_no_depth);
- ClassDB::bind_method(D_METHOD("_path_exited"), &CSGPolygon::_path_exited);
- ClassDB::bind_method(D_METHOD("_path_changed"), &CSGPolygon::_path_changed);
-
ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Depth,Spin,Path"), "set_mode", "get_mode");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "depth", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_depth", "get_depth");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "spin_degrees", PROPERTY_HINT_RANGE, "1,360,0.1"), "set_spin_degrees", "get_spin_degrees");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_depth", "get_depth");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spin_degrees", PROPERTY_HINT_RANGE, "1,360,0.1"), "set_spin_degrees", "get_spin_degrees");
ADD_PROPERTY(PropertyInfo(Variant::INT, "spin_sides", PROPERTY_HINT_RANGE, "3,64,1"), "set_spin_sides", "get_spin_sides");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "path_node", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Path"), "set_path_node", "get_path_node");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "path_interval", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_path_interval", "get_path_interval");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_interval", PROPERTY_HINT_EXP_RANGE, "0.001,1000.0,0.001,or_greater"), "set_path_interval", "get_path_interval");
ADD_PROPERTY(PropertyInfo(Variant::INT, "path_rotation", PROPERTY_HINT_ENUM, "Polygon,Path,PathFollow"), "set_path_rotation", "get_path_rotation");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_local"), "set_path_local", "is_path_local");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_continuous_u"), "set_path_continuous_u", "is_path_continuous_u");
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp
index a04989449c..ae21156b8b 100644
--- a/modules/dds/texture_loader_dds.cpp
+++ b/modules/dds/texture_loader_dds.cpp
@@ -94,7 +94,7 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = {
{ "GRAYSCALE_ALPHA", false, false, 1, 2, Image::FORMAT_LA8 }
};
-RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
if (r_error)
*r_error = ERR_CANT_OPEN;
diff --git a/modules/dds/texture_loader_dds.h b/modules/dds/texture_loader_dds.h
index 34f4e9b548..de8088af90 100644
--- a/modules/dds/texture_loader_dds.h
+++ b/modules/dds/texture_loader_dds.h
@@ -36,7 +36,7 @@
class ResourceFormatDDS : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp
index 0dbd5ca905..b3f7b1d94f 100644
--- a/modules/etc/image_etc.cpp
+++ b/modules/etc/image_etc.cpp
@@ -106,9 +106,15 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
// If VRAM compression is using ETC, but image has alpha, convert to RGBA4444 or LA8
// This saves space while maintaining the alpha channel
if (detected_channels == Image::USED_CHANNELS_RGBA) {
+
+ if (p_img->has_mipmaps()) {
+ // Image doesn't support mipmaps with RGBA4444 textures
+ p_img->clear_mipmaps();
+ }
p_img->convert(Image::FORMAT_RGBA4444);
return;
} else if (detected_channels == Image::USE_CHANNELS_LA) {
+
p_img->convert(Image::FORMAT_LA8);
return;
}
diff --git a/modules/etc/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp
index e460c70cec..ad0cc91c96 100644
--- a/modules/etc/texture_loader_pkm.cpp
+++ b/modules/etc/texture_loader_pkm.cpp
@@ -42,7 +42,7 @@ struct ETC1Header {
uint16_t origHeight;
};
-RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
if (r_error)
*r_error = ERR_CANT_OPEN;
diff --git a/modules/etc/texture_loader_pkm.h b/modules/etc/texture_loader_pkm.h
index 3d52a9ea95..d6011993e3 100644
--- a/modules/etc/texture_loader_pkm.h
+++ b/modules/etc/texture_loader_pkm.h
@@ -36,7 +36,7 @@
class ResourceFormatPKM : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index 1571b821a5..33b734f672 100644
--- a/modules/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative.cpp
@@ -493,7 +493,7 @@ Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_
return result;
}
-RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
Ref<GDNativeLibrary> lib;
lib.instance();
diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h
index c0c2cdf24c..b4c5ec9d00 100644
--- a/modules/gdnative/gdnative.h
+++ b/modules/gdnative/gdnative.h
@@ -166,7 +166,7 @@ public:
class GDNativeLibraryResourceLoader : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path, Error *r_error);
+ virtual RES load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp
index 1d8ba6087f..f0fc44ae8a 100644
--- a/modules/gdnative/gdnative/variant.cpp
+++ b/modules/gdnative/gdnative/variant.cpp
@@ -209,13 +209,13 @@ void GDAPI godot_variant_new_packed_byte_array(godot_variant *r_dest, const godo
void GDAPI godot_variant_new_packed_int_array(godot_variant *r_dest, const godot_packed_int_array *p_pia) {
Variant *dest = (Variant *)r_dest;
- PackedIntArray *pia = (PackedIntArray *)p_pia;
+ PackedInt32Array *pia = (PackedInt32Array *)p_pia;
memnew_placement_custom(dest, Variant, Variant(*pia));
}
void GDAPI godot_variant_new_packed_real_array(godot_variant *r_dest, const godot_packed_real_array *p_pra) {
Variant *dest = (Variant *)r_dest;
- PackedRealArray *pra = (PackedRealArray *)p_pra;
+ PackedFloat32Array *pra = (PackedFloat32Array *)p_pra;
memnew_placement_custom(dest, Variant, Variant(*pra));
}
@@ -402,8 +402,8 @@ godot_packed_byte_array GDAPI godot_variant_as_packed_byte_array(const godot_var
godot_packed_int_array GDAPI godot_variant_as_packed_int_array(const godot_variant *p_self) {
godot_packed_int_array raw_dest;
const Variant *self = (const Variant *)p_self;
- PackedIntArray *dest = (PackedIntArray *)&raw_dest;
- memnew_placement(dest, PackedIntArray(self->operator PackedIntArray())); // operator = is overloaded by PackedIntArray
+ PackedInt32Array *dest = (PackedInt32Array *)&raw_dest;
+ memnew_placement(dest, PackedInt32Array(self->operator PackedInt32Array())); // operator = is overloaded by PackedInt32Array
*dest = *self;
return raw_dest;
}
@@ -411,8 +411,8 @@ godot_packed_int_array GDAPI godot_variant_as_packed_int_array(const godot_varia
godot_packed_real_array GDAPI godot_variant_as_packed_real_array(const godot_variant *p_self) {
godot_packed_real_array raw_dest;
const Variant *self = (const Variant *)p_self;
- PackedRealArray *dest = (PackedRealArray *)&raw_dest;
- memnew_placement(dest, PackedRealArray(self->operator PackedRealArray())); // operator = is overloaded by PackedRealArray
+ PackedFloat32Array *dest = (PackedFloat32Array *)&raw_dest;
+ memnew_placement(dest, PackedFloat32Array(self->operator PackedFloat32Array())); // operator = is overloaded by PackedFloat32Array
*dest = *self;
return raw_dest;
}
diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp
index b434bc8385..db90199e63 100644
--- a/modules/gdnative/gdnative_library_editor_plugin.cpp
+++ b/modules/gdnative/gdnative_library_editor_plugin.cpp
@@ -53,14 +53,6 @@ void GDNativeLibraryEditor::edit(Ref<GDNativeLibrary> p_library) {
}
void GDNativeLibraryEditor::_bind_methods() {
-
- ClassDB::bind_method("_on_item_button", &GDNativeLibraryEditor::_on_item_button);
- ClassDB::bind_method("_on_library_selected", &GDNativeLibraryEditor::_on_library_selected);
- ClassDB::bind_method("_on_dependencies_selected", &GDNativeLibraryEditor::_on_dependencies_selected);
- ClassDB::bind_method("_on_filter_selected", &GDNativeLibraryEditor::_on_filter_selected);
- ClassDB::bind_method("_on_item_collapsed", &GDNativeLibraryEditor::_on_item_collapsed);
- ClassDB::bind_method("_on_item_activated", &GDNativeLibraryEditor::_on_item_activated);
- ClassDB::bind_method("_on_create_new_entry", &GDNativeLibraryEditor::_on_create_new_entry);
}
void GDNativeLibraryEditor::_update_tree() {
@@ -359,7 +351,7 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() {
filter_list->set_item_checked(idx, true);
idx += 1;
}
- filter_list->connect_compat("index_pressed", this, "_on_filter_selected");
+ filter_list->connect("index_pressed", callable_mp(this, &GDNativeLibraryEditor::_on_filter_selected));
tree = memnew(Tree);
container->add_child(tree);
@@ -374,16 +366,16 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() {
tree->set_column_title(2, TTR("Dependencies"));
tree->set_column_expand(3, false);
tree->set_column_min_width(3, int(110 * EDSCALE));
- tree->connect_compat("button_pressed", this, "_on_item_button");
- tree->connect_compat("item_collapsed", this, "_on_item_collapsed");
- tree->connect_compat("item_activated", this, "_on_item_activated");
+ tree->connect("button_pressed", callable_mp(this, &GDNativeLibraryEditor::_on_item_button));
+ tree->connect("item_collapsed", callable_mp(this, &GDNativeLibraryEditor::_on_item_collapsed));
+ tree->connect("item_activated", callable_mp(this, &GDNativeLibraryEditor::_on_item_activated));
file_dialog = memnew(EditorFileDialog);
file_dialog->set_access(EditorFileDialog::ACCESS_RESOURCES);
file_dialog->set_resizable(true);
add_child(file_dialog);
- file_dialog->connect_compat("file_selected", this, "_on_library_selected");
- file_dialog->connect_compat("files_selected", this, "_on_dependencies_selected");
+ file_dialog->connect("file_selected", callable_mp(this, &GDNativeLibraryEditor::_on_library_selected));
+ file_dialog->connect("files_selected", callable_mp(this, &GDNativeLibraryEditor::_on_dependencies_selected));
new_architecture_dialog = memnew(ConfirmationDialog);
add_child(new_architecture_dialog);
@@ -392,7 +384,7 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() {
new_architecture_dialog->add_child(new_architecture_input);
new_architecture_dialog->set_custom_minimum_size(Vector2(300, 80) * EDSCALE);
new_architecture_input->set_anchors_and_margins_preset(PRESET_HCENTER_WIDE, PRESET_MODE_MINSIZE, 5 * EDSCALE);
- new_architecture_dialog->get_ok()->connect_compat("pressed", this, "_on_create_new_entry");
+ new_architecture_dialog->get_ok()->connect("pressed", callable_mp(this, &GDNativeLibraryEditor::_on_create_new_entry));
}
void GDNativeLibraryEditorPlugin::edit(Object *p_node) {
diff --git a/modules/gdnative/gdnative_library_singleton_editor.cpp b/modules/gdnative/gdnative_library_singleton_editor.cpp
index e5eb3c44d0..378339ecea 100644
--- a/modules/gdnative/gdnative_library_singleton_editor.cpp
+++ b/modules/gdnative/gdnative_library_singleton_editor.cpp
@@ -192,8 +192,6 @@ void GDNativeLibrarySingletonEditor::_notification(int p_what) {
void GDNativeLibrarySingletonEditor::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_item_edited"), &GDNativeLibrarySingletonEditor::_item_edited);
- ClassDB::bind_method(D_METHOD("_discover_singletons"), &GDNativeLibrarySingletonEditor::_discover_singletons);
ClassDB::bind_method(D_METHOD("_update_libraries"), &GDNativeLibrarySingletonEditor::_update_libraries);
}
@@ -207,8 +205,8 @@ GDNativeLibrarySingletonEditor::GDNativeLibrarySingletonEditor() {
libraries->set_hide_root(true);
add_margin_child(TTR("Libraries: "), libraries, true);
updating = false;
- libraries->connect_compat("item_edited", this, "_item_edited");
- EditorFileSystem::get_singleton()->connect_compat("filesystem_changed", this, "_discover_singletons");
+ libraries->connect("item_edited", callable_mp(this, &GDNativeLibrarySingletonEditor::_item_edited));
+ EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &GDNativeLibrarySingletonEditor::_discover_singletons));
}
#endif // TOOLS_ENABLED
diff --git a/modules/gdnative/include/gdnative/pool_arrays.h b/modules/gdnative/include/gdnative/pool_arrays.h
index 315fb7ada2..c610377f54 100644
--- a/modules/gdnative/include/gdnative/pool_arrays.h
+++ b/modules/gdnative/include/gdnative/pool_arrays.h
@@ -48,7 +48,7 @@ typedef struct {
} godot_packed_byte_array;
#endif
-/////// PackedIntArray
+/////// PackedInt32Array
#define GODOT_PACKED_INT_ARRAY_SIZE sizeof(void *)
@@ -59,7 +59,7 @@ typedef struct {
} godot_packed_int_array;
#endif
-/////// PackedRealArray
+/////// PackedFloat32Array
#define GODOT_PACKED_REAL_ARRAY_SIZE sizeof(void *)
diff --git a/modules/gdnative/include/gdnative/variant.h b/modules/gdnative/include/gdnative/variant.h
index 4d70f1143c..934e856fbf 100644
--- a/modules/gdnative/include/gdnative/variant.h
+++ b/modules/gdnative/include/gdnative/variant.h
@@ -56,31 +56,33 @@ typedef enum godot_variant_type {
GODOT_VARIANT_TYPE_STRING,
// math types
-
- GODOT_VARIANT_TYPE_VECTOR2, // 5
+ GODOT_VARIANT_TYPE_VECTOR2,
+ GODOT_VARIANT_TYPE_VECTOR2I,
GODOT_VARIANT_TYPE_RECT2,
+ GODOT_VARIANT_TYPE_RECT2I,
GODOT_VARIANT_TYPE_VECTOR3,
+ GODOT_VARIANT_TYPE_VECTOR3I,
GODOT_VARIANT_TYPE_TRANSFORM2D,
GODOT_VARIANT_TYPE_PLANE,
- GODOT_VARIANT_TYPE_QUAT, // 10
+ GODOT_VARIANT_TYPE_QUAT,
GODOT_VARIANT_TYPE_AABB,
GODOT_VARIANT_TYPE_BASIS,
GODOT_VARIANT_TYPE_TRANSFORM,
// misc types
GODOT_VARIANT_TYPE_COLOR,
- GODOT_VARIANT_TYPE_NODE_PATH, // 15
+ GODOT_VARIANT_TYPE_NODE_PATH,
GODOT_VARIANT_TYPE_RID,
GODOT_VARIANT_TYPE_OBJECT,
GODOT_VARIANT_TYPE_DICTIONARY,
- GODOT_VARIANT_TYPE_ARRAY, // 20
+ GODOT_VARIANT_TYPE_ARRAY,
// arrays
GODOT_VARIANT_TYPE_PACKED_BYTE_ARRAY,
GODOT_VARIANT_TYPE_PACKED_INT_ARRAY,
GODOT_VARIANT_TYPE_PACKED_REAL_ARRAY,
GODOT_VARIANT_TYPE_PACKED_STRING_ARRAY,
- GODOT_VARIANT_TYPE_PACKED_VECTOR2_ARRAY, // 25
+ GODOT_VARIANT_TYPE_PACKED_VECTOR2_ARRAY,
GODOT_VARIANT_TYPE_PACKED_VECTOR3_ARRAY,
GODOT_VARIANT_TYPE_PACKED_COLOR_ARRAY,
} godot_variant_type;
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index 8240ae2f83..d0e196b3e6 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -222,15 +222,11 @@ ScriptInstance *NativeScript::instance_create(Object *p_this) {
nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data);
#endif
-#ifndef NO_THREADS
- owners_lock->lock();
-#endif
-
- instance_owners.insert(p_this);
+ {
+ MutexLock lock(owners_lock);
-#ifndef NO_THREADS
- owners_lock->unlock();
-#endif
+ instance_owners.insert(p_this);
+ }
return nsi;
}
@@ -782,17 +778,10 @@ NativeScript::NativeScript() {
library = Ref<GDNative>();
lib_path = "";
class_name = "";
-#ifndef NO_THREADS
- owners_lock = Mutex::create();
-#endif
}
NativeScript::~NativeScript() {
NSL->unregister_script(this);
-
-#ifndef NO_THREADS
- memdelete(owners_lock);
-#endif
}
#define GET_SCRIPT_DESC() script->get_script_desc()
@@ -1140,16 +1129,9 @@ NativeScriptInstance::~NativeScriptInstance() {
script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata);
if (owner) {
-
-#ifndef NO_THREADS
- script->owners_lock->lock();
-#endif
+ MutexLock lock(script->owners_lock);
script->instance_owners.erase(owner);
-
-#ifndef NO_THREADS
- script->owners_lock->unlock();
-#endif
}
}
@@ -1246,7 +1228,6 @@ NativeScriptLanguage::NativeScriptLanguage() {
NativeScriptLanguage::singleton = this;
#ifndef NO_THREADS
has_objects_to_register = false;
- mutex = Mutex::create();
#endif
#ifdef DEBUG_ENABLED
@@ -1283,10 +1264,6 @@ NativeScriptLanguage::~NativeScriptLanguage() {
NSL->library_classes.clear();
NSL->library_gdnatives.clear();
NSL->library_script_users.clear();
-
-#ifndef NO_THREADS
- memdelete(mutex);
-#endif
}
String NativeScriptLanguage::get_name() const {
@@ -1413,9 +1390,7 @@ void NativeScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_
void NativeScriptLanguage::profiling_start() {
#ifdef DEBUG_ENABLED
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
profile_data.clear();
profiling = true;
@@ -1424,9 +1399,7 @@ void NativeScriptLanguage::profiling_start() {
void NativeScriptLanguage::profiling_stop() {
#ifdef DEBUG_ENABLED
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
profiling = false;
#endif
@@ -1434,9 +1407,8 @@ void NativeScriptLanguage::profiling_stop() {
int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) {
#ifdef DEBUG_ENABLED
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
+
int current = 0;
for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
@@ -1458,9 +1430,8 @@ int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_a
int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) {
#ifdef DEBUG_ENABLED
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
+
int current = 0;
for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
@@ -1484,9 +1455,7 @@ int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, in
void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p_time) {
#ifdef DEBUG_ENABLED
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
Map<StringName, ProfileData>::Element *d = profile_data.find(p_signature);
if (d) {
@@ -1705,9 +1674,8 @@ void NativeScriptLanguage::defer_init_library(Ref<GDNativeLibrary> lib, NativeSc
#endif
void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) {
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
+
// See if this library was "registered" already.
const String &lib_path = lib->get_current_library_path();
ERR_FAIL_COND_MSG(lib_path.length() == 0, lib->get_name() + " does not have a library for the current platform.");
@@ -1743,16 +1711,14 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) {
}
void NativeScriptLanguage::register_script(NativeScript *script) {
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
+
library_script_users[script->lib_path].insert(script);
}
void NativeScriptLanguage::unregister_script(NativeScript *script) {
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
+
Map<String, Set<NativeScript *> >::Element *S = library_script_users.find(script->lib_path);
if (S) {
S->get().erase(script);
@@ -1803,9 +1769,7 @@ void NativeScriptLanguage::frame() {
#ifdef DEBUG_ENABLED
{
-#ifndef NO_THREADS
MutexLock lock(mutex);
-#endif
for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
d->get().last_frame_call_count = d->get().frame_call_count;
@@ -1867,9 +1831,7 @@ void NativeReloadNode::_notification(int p_what) {
if (unloaded)
break;
-#ifndef NO_THREADS
MutexLock lock(NSL->mutex);
-#endif
NSL->_unload_stuff(true);
for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) {
@@ -1904,9 +1866,8 @@ void NativeReloadNode::_notification(int p_what) {
if (!unloaded)
break;
-#ifndef NO_THREADS
MutexLock lock(NSL->mutex);
-#endif
+
Set<StringName> libs_to_remove;
for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) {
@@ -1970,7 +1931,7 @@ void NativeReloadNode::_notification(int p_what) {
#endif
}
-RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderNativeScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
return ResourceFormatLoaderText::singleton->load(p_path, p_original_path, r_error);
}
diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h
index 609ffa2bd4..90542c96b7 100644
--- a/modules/gdnative/nativescript/nativescript.h
+++ b/modules/gdnative/nativescript/nativescript.h
@@ -35,6 +35,7 @@
#include "core/io/resource_saver.h"
#include "core/oa_hash_map.h"
#include "core/ordered_hash_map.h"
+#include "core/os/mutex.h"
#include "core/os/thread_safe.h"
#include "core/resource.h"
#include "core/script_language.h"
@@ -44,10 +45,6 @@
#include "modules/gdnative/gdnative.h"
#include <nativescript/godot_nativescript.h>
-#ifndef NO_THREADS
-#include "core/os/mutex.h"
-#endif
-
struct NativeScriptDesc {
struct Method {
@@ -127,9 +124,7 @@ class NativeScript : public Script {
String script_class_name;
String script_class_icon_path;
-#ifndef NO_THREADS
- Mutex *owners_lock;
-#endif
+ Mutex owners_lock;
Set<Object *> instance_owners;
protected:
@@ -266,9 +261,8 @@ private:
void _unload_stuff(bool p_reload = false);
+ Mutex mutex;
#ifndef NO_THREADS
- Mutex *mutex;
-
Set<Ref<GDNativeLibrary> > libs_to_init;
Set<NativeScript *> scripts_to_register;
volatile bool has_objects_to_register; // so that we don't lock mutex every frame - it's rarely needed
@@ -412,7 +406,7 @@ public:
class ResourceFormatLoaderNativeScript : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/gdnative/pluginscript/pluginscript_language.cpp b/modules/gdnative/pluginscript/pluginscript_language.cpp
index 4e39f4b0a8..a40b59bb2e 100644
--- a/modules/gdnative/pluginscript/pluginscript_language.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_language.cpp
@@ -399,39 +399,18 @@ void PluginScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool
}
void PluginScriptLanguage::lock() {
-#ifndef NO_THREADS
- if (_lock) {
- _lock->lock();
- }
-#endif
+ _lock.lock();
}
void PluginScriptLanguage::unlock() {
-#ifndef NO_THREADS
- if (_lock) {
- _lock->unlock();
- }
-#endif
+ _lock.unlock();
}
PluginScriptLanguage::PluginScriptLanguage(const godot_pluginscript_language_desc *desc) :
_desc(*desc) {
_resource_loader = Ref<ResourceFormatLoaderPluginScript>(memnew(ResourceFormatLoaderPluginScript(this)));
_resource_saver = Ref<ResourceFormatSaverPluginScript>(memnew(ResourceFormatSaverPluginScript(this)));
-
-// TODO: totally remove _lock attribute if NO_THREADS is set
-#ifdef NO_THREADS
- _lock = NULL;
-#else
- _lock = Mutex::create();
-#endif
}
PluginScriptLanguage::~PluginScriptLanguage() {
-#ifndef NO_THREADS
- if (_lock) {
- memdelete(_lock);
- _lock = NULL;
- }
-#endif
}
diff --git a/modules/gdnative/pluginscript/pluginscript_language.h b/modules/gdnative/pluginscript/pluginscript_language.h
index 037d7a4948..3f0d2b8d3d 100644
--- a/modules/gdnative/pluginscript/pluginscript_language.h
+++ b/modules/gdnative/pluginscript/pluginscript_language.h
@@ -53,7 +53,7 @@ class PluginScriptLanguage : public ScriptLanguage {
const godot_pluginscript_language_desc _desc;
godot_pluginscript_language_data *_data;
- Mutex *_lock;
+ Mutex _lock;
SelfList<PluginScript>::List _script_list;
public:
diff --git a/modules/gdnative/pluginscript/pluginscript_loader.cpp b/modules/gdnative/pluginscript/pluginscript_loader.cpp
index fe1cc83c69..46db20b6c2 100644
--- a/modules/gdnative/pluginscript/pluginscript_loader.cpp
+++ b/modules/gdnative/pluginscript/pluginscript_loader.cpp
@@ -39,7 +39,7 @@ ResourceFormatLoaderPluginScript::ResourceFormatLoaderPluginScript(PluginScriptL
_language = language;
}
-RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
if (r_error)
*r_error = ERR_FILE_CANT_OPEN;
diff --git a/modules/gdnative/pluginscript/pluginscript_loader.h b/modules/gdnative/pluginscript/pluginscript_loader.h
index ede31c027e..a039072fdc 100644
--- a/modules/gdnative/pluginscript/pluginscript_loader.h
+++ b/modules/gdnative/pluginscript/pluginscript_loader.h
@@ -44,7 +44,7 @@ class ResourceFormatLoaderPluginScript : public ResourceFormatLoader {
public:
ResourceFormatLoaderPluginScript(PluginScriptLanguage *language);
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp
index bd16563ff0..f6e2bad739 100644
--- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp
+++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp
@@ -373,7 +373,7 @@ void VideoStreamGDNative::set_audio_track(int p_track) {
/* --- NOTE ResourceFormatLoaderVideoStreamGDNative starts here. ----- */
-RES ResourceFormatLoaderVideoStreamGDNative::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderVideoStreamGDNative::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
if (r_error) {
diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.h b/modules/gdnative/videodecoder/video_stream_gdnative.h
index 024cdec196..21b5245a16 100644
--- a/modules/gdnative/videodecoder/video_stream_gdnative.h
+++ b/modules/gdnative/videodecoder/video_stream_gdnative.h
@@ -199,7 +199,7 @@ public:
class ResourceFormatLoaderVideoStreamGDNative : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp
index 1f1783802d..4db10cda78 100644
--- a/modules/gdnavigation/gd_navigation_server.cpp
+++ b/modules/gdnavigation/gd_navigation_server.cpp
@@ -115,30 +115,27 @@
GdNavigationServer::GdNavigationServer() :
NavigationServer(),
- commands_mutex(Mutex::create()),
- operations_mutex(Mutex::create()),
active(true) {
}
GdNavigationServer::~GdNavigationServer() {
- memdelete(operations_mutex);
- memdelete(commands_mutex);
+ flush_queries();
}
void GdNavigationServer::add_command(SetCommand *command) const {
auto mut_this = const_cast<GdNavigationServer *>(this);
- commands_mutex->lock();
- mut_this->commands.push_back(command);
- commands_mutex->unlock();
+ {
+ MutexLock lock(commands_mutex);
+ mut_this->commands.push_back(command);
+ }
}
RID GdNavigationServer::map_create() const {
auto mut_this = const_cast<GdNavigationServer *>(this);
- mut_this->operations_mutex->lock();
+ MutexLock lock(mut_this->operations_mutex);
NavMap *space = memnew(NavMap);
RID rid = map_owner.make_rid(space);
space->set_self(rid);
- mut_this->operations_mutex->unlock();
return rid;
}
@@ -241,11 +238,10 @@ RID GdNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_
RID GdNavigationServer::region_create() const {
auto mut_this = const_cast<GdNavigationServer *>(this);
- mut_this->operations_mutex->lock();
+ MutexLock lock(mut_this->operations_mutex);
NavRegion *reg = memnew(NavRegion);
RID rid = region_owner.make_rid(reg);
reg->set_self(rid);
- mut_this->operations_mutex->unlock();
return rid;
}
@@ -297,11 +293,10 @@ void GdNavigationServer::region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p
RID GdNavigationServer::agent_create() const {
auto mut_this = const_cast<GdNavigationServer *>(this);
- mut_this->operations_mutex->lock();
+ MutexLock lock(mut_this->operations_mutex);
RvoAgent *agent = memnew(RvoAgent());
RID rid = agent_owner.make_rid(agent);
agent->set_self(rid);
- mut_this->operations_mutex->unlock();
return rid;
}
@@ -469,28 +464,32 @@ COMMAND_1(free, RID, p_object) {
void GdNavigationServer::set_active(bool p_active) const {
auto mut_this = const_cast<GdNavigationServer *>(this);
- mut_this->operations_mutex->lock();
+ MutexLock lock(mut_this->operations_mutex);
mut_this->active = p_active;
- mut_this->operations_mutex->unlock();
}
-void GdNavigationServer::step(real_t p_delta_time) {
- if (!active) {
- return;
- }
-
- // With c++ we can't be 100% sure this is called in single thread so use the mutex.
- commands_mutex->lock();
- operations_mutex->lock();
+void GdNavigationServer::flush_queries() {
+ // In c++ we can't be sure that this is performed in the main thread
+ // even with mutable functions.
+ MutexLock lock(commands_mutex);
+ MutexLock lock2(operations_mutex);
for (size_t i(0); i < commands.size(); i++) {
commands[i]->exec(this);
memdelete(commands[i]);
}
commands.clear();
- operations_mutex->unlock();
- commands_mutex->unlock();
+}
+
+void GdNavigationServer::process(real_t p_delta_time) {
+ flush_queries();
+
+ if (!active) {
+ return;
+ }
- // These are internal operations so don't need to be shielded.
+ // In c++ we can't be sure that this is performed in the main thread
+ // even with mutable functions.
+ MutexLock lock(operations_mutex);
for (int i(0); i < active_maps.size(); i++) {
active_maps[i]->sync();
active_maps[i]->step(p_delta_time);
diff --git a/modules/gdnavigation/gd_navigation_server.h b/modules/gdnavigation/gd_navigation_server.h
index 7fa5979c31..e9f5c1ffe6 100644
--- a/modules/gdnavigation/gd_navigation_server.h
+++ b/modules/gdnavigation/gd_navigation_server.h
@@ -61,7 +61,6 @@
void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3)
class GdNavigationServer;
-class Mutex;
struct SetCommand {
virtual ~SetCommand() {}
@@ -69,9 +68,9 @@ struct SetCommand {
};
class GdNavigationServer : public NavigationServer {
- Mutex *commands_mutex;
+ Mutex commands_mutex;
/// Mutex used to make any operation threadsafe.
- Mutex *operations_mutex;
+ Mutex operations_mutex;
std::vector<SetCommand *> commands;
@@ -131,7 +130,9 @@ public:
COMMAND_1(free, RID, p_object);
virtual void set_active(bool p_active) const;
- virtual void step(real_t p_delta_time);
+
+ void flush_queries();
+ virtual void process(real_t p_delta_time);
};
#undef COMMAND_1
diff --git a/modules/gdnavigation/nav_map.cpp b/modules/gdnavigation/nav_map.cpp
index d3e2f8f388..c3880f89b6 100644
--- a/modules/gdnavigation/nav_map.cpp
+++ b/modules/gdnavigation/nav_map.cpp
@@ -545,8 +545,11 @@ void NavMap::add_region(NavRegion *p_region) {
}
void NavMap::remove_region(NavRegion *p_region) {
- regions.push_back(p_region);
- regenerate_links = true;
+ std::vector<NavRegion *>::iterator it = std::find(regions.begin(), regions.end(), p_region);
+ if (it != regions.end()) {
+ regions.erase(it);
+ regenerate_links = true;
+ }
}
bool NavMap::has_agent(RvoAgent *agent) const {
diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp
index 28fe0bfd06..5c298ae9e4 100644
--- a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp
+++ b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp
@@ -84,7 +84,7 @@ void NavigationMeshEditor::_clear_pressed() {
}
}
-void NavigationMeshEditor::edit(NavigationMeshInstance *p_nav_mesh_instance) {
+void NavigationMeshEditor::edit(NavigationRegion *p_nav_mesh_instance) {
if (p_nav_mesh_instance == NULL || node == p_nav_mesh_instance) {
return;
@@ -94,9 +94,6 @@ void NavigationMeshEditor::edit(NavigationMeshInstance *p_nav_mesh_instance) {
}
void NavigationMeshEditor::_bind_methods() {
-
- ClassDB::bind_method("_bake_pressed", &NavigationMeshEditor::_bake_pressed);
- ClassDB::bind_method("_clear_pressed", &NavigationMeshEditor::_clear_pressed);
}
NavigationMeshEditor::NavigationMeshEditor() {
@@ -107,13 +104,13 @@ NavigationMeshEditor::NavigationMeshEditor() {
bake_hbox->add_child(button_bake);
button_bake->set_toggle_mode(true);
button_bake->set_text(TTR("Bake NavMesh"));
- button_bake->connect_compat("pressed", this, "_bake_pressed");
+ button_bake->connect("pressed", callable_mp(this, &NavigationMeshEditor::_bake_pressed));
button_reset = memnew(ToolButton);
bake_hbox->add_child(button_reset);
// No button text, we only use a revert icon which is set when entering the tree.
button_reset->set_tooltip(TTR("Clear the navigation mesh."));
- button_reset->connect_compat("pressed", this, "_clear_pressed");
+ button_reset->connect("pressed", callable_mp(this, &NavigationMeshEditor::_clear_pressed));
bake_info = memnew(Label);
bake_hbox->add_child(bake_info);
@@ -128,12 +125,12 @@ NavigationMeshEditor::~NavigationMeshEditor() {
void NavigationMeshEditorPlugin::edit(Object *p_object) {
- navigation_mesh_editor->edit(Object::cast_to<NavigationMeshInstance>(p_object));
+ navigation_mesh_editor->edit(Object::cast_to<NavigationRegion>(p_object));
}
bool NavigationMeshEditorPlugin::handles(Object *p_object) const {
- return p_object->is_class("NavigationMeshInstance");
+ return p_object->is_class("NavigationRegion");
}
void NavigationMeshEditorPlugin::make_visible(bool p_visible) {
diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.h b/modules/gdnavigation/navigation_mesh_editor_plugin.h
index f5833f3d7f..7c3faebf57 100644
--- a/modules/gdnavigation/navigation_mesh_editor_plugin.h
+++ b/modules/gdnavigation/navigation_mesh_editor_plugin.h
@@ -36,7 +36,7 @@
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
-class NavigationMeshInstance;
+class NavigationRegion;
class NavigationMeshEditor : public Control {
friend class NavigationMeshEditorPlugin;
@@ -50,7 +50,7 @@ class NavigationMeshEditor : public Control {
ToolButton *button_reset;
Label *bake_info;
- NavigationMeshInstance *node;
+ NavigationRegion *node;
void _bake_pressed();
void _clear_pressed();
@@ -61,7 +61,7 @@ protected:
void _notification(int p_option);
public:
- void edit(NavigationMeshInstance *p_nav_mesh_instance);
+ void edit(NavigationRegion *p_nav_mesh_instance);
NavigationMeshEditor();
~NavigationMeshEditor();
};
diff --git a/modules/gdnavigation/navigation_mesh_generator.cpp b/modules/gdnavigation/navigation_mesh_generator.cpp
index 7f8761dac8..e7038b38a2 100644
--- a/modules/gdnavigation/navigation_mesh_generator.cpp
+++ b/modules/gdnavigation/navigation_mesh_generator.cpp
@@ -42,10 +42,10 @@
#include "scene/resources/concave_polygon_shape.h"
#include "scene/resources/convex_polygon_shape.h"
#include "scene/resources/cylinder_shape.h"
-#include "scene/resources/plane_shape.h"
#include "scene/resources/primitive_meshes.h"
#include "scene/resources/shape.h"
#include "scene/resources/sphere_shape.h"
+#include "scene/resources/world_margin_shape.h"
#include "modules/modules_enabled.gen.h"
#ifdef TOOLS_ENABLED
diff --git a/modules/gdnavigation/navigation_mesh_generator.h b/modules/gdnavigation/navigation_mesh_generator.h
index 27a56e1d7a..d1f2e4b56f 100644
--- a/modules/gdnavigation/navigation_mesh_generator.h
+++ b/modules/gdnavigation/navigation_mesh_generator.h
@@ -33,7 +33,7 @@
#ifndef _3D_DISABLED
-#include "scene/3d/navigation_mesh_instance.h"
+#include "scene/3d/navigation_region.h"
#include <Recast.h>
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
index cf76c09294..2f6f9f30a4 100644
--- a/modules/gdscript/doc_classes/@GDScript.xml
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -481,9 +481,13 @@
<argument index="2" name="weight" type="float">
</argument>
<description>
- Returns a normalized value considering the given range.
+ Returns a normalized value considering the given range. This is the opposite of [method lerp].
[codeblock]
- inverse_lerp(3, 5, 4) # Returns 0.5
+ var middle = lerp(20, 30, 0.75)
+ # `middle` is now 27.5.
+ # Now, we pretend to have forgotten the original ratio and want to get it back.
+ var ratio = inverse_lerp(20, 30, 27.5)
+ # `ratio` is now 0.75.
[/codeblock]
</description>
</method>
@@ -558,7 +562,7 @@
<argument index="2" name="weight" type="float">
</argument>
<description>
- Linearly interpolates between two values by a normalized value.
+ Linearly interpolates between two values by a normalized value. This is the opposite of [method inverse_lerp].
If the [code]from[/code] and [code]to[/code] arguments are of type [int] or [float], the return value is a [float].
If both are of the same vector type ([Vector2], [Vector3] or [Color]), the return value will be of the same type ([code]lerp[/code] then calls the vector type's [code]linear_interpolate[/code] method).
[codeblock]
@@ -578,7 +582,7 @@
</argument>
<description>
Linearly interpolates between two angles (in radians) by a normalized value.
- Similar to [method lerp] but interpolate correctly when the angles wrap around [constant @GDScript.TAU].
+ Similar to [method lerp], but interpolates correctly when the angles wrap around [constant @GDScript.TAU].
[codeblock]
extends Sprite
var elapsed = 0.0
@@ -596,7 +600,13 @@
<argument index="0" name="nrg" type="float">
</argument>
<description>
- Converts from linear energy to decibels (audio).
+ Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear). Example:
+ [codeblock]
+ # "Slider" refers to a node that inherits Range such as HSlider or VSlider.
+ # Its range must be configured to go from 0 to 1.
+ # Change the bus name if you'd like to change the volume of a specific bus only.
+ AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), linear2db($Slider.value))
+ [/codeblock]
</description>
</method>
<method name="load">
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index a72bb7ba49..c641ce37c5 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -104,28 +104,21 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco
/* STEP 2, INITIALIZE AND CONSTRUCT */
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->lock();
-#endif
-
- instances.insert(instance->owner);
+ {
+ MutexLock lock(GDScriptLanguage::singleton->lock);
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->unlock();
-#endif
+ instances.insert(instance->owner);
+ }
initializer->call(instance, p_args, p_argcount, r_error);
if (r_error.error != Callable::CallError::CALL_OK) {
instance->script = Ref<GDScript>();
instance->owner->set_script_instance(NULL);
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->lock();
-#endif
- instances.erase(p_owner);
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->unlock();
-#endif
+ {
+ MutexLock lock(GDScriptLanguage::singleton->lock);
+ instances.erase(p_owner);
+ }
ERR_FAIL_COND_V(r_error.error != Callable::CallError::CALL_OK, NULL); //error constructing
}
@@ -346,16 +339,9 @@ PlaceHolderScriptInstance *GDScript::placeholder_instance_create(Object *p_this)
bool GDScript::instance_has(const Object *p_this) const {
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->lock();
-#endif
- bool hasit = instances.has((Object *)p_this);
-
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->unlock();
-#endif
+ MutexLock lock(GDScriptLanguage::singleton->lock);
- return hasit;
+ return instances.has((Object *)p_this);
}
bool GDScript::has_source_code() const {
@@ -544,14 +530,12 @@ void GDScript::_set_subclass_path(Ref<GDScript> &p_sc, const String &p_path) {
Error GDScript::reload(bool p_keep_state) {
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->lock();
-#endif
- bool has_instances = instances.size();
+ bool has_instances;
+ {
+ MutexLock lock(GDScriptLanguage::singleton->lock);
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->unlock();
-#endif
+ has_instances = instances.size();
+ }
ERR_FAIL_COND_V(!p_keep_state && has_instances, ERR_ALREADY_IN_USE);
@@ -1007,13 +991,10 @@ GDScript::GDScript() :
#endif
#ifdef DEBUG_ENABLED
- if (GDScriptLanguage::get_singleton()->lock) {
- GDScriptLanguage::get_singleton()->lock->lock();
- }
- GDScriptLanguage::get_singleton()->script_list.add(&script_list);
+ {
+ MutexLock lock(GDScriptLanguage::get_singleton()->lock);
- if (GDScriptLanguage::get_singleton()->lock) {
- GDScriptLanguage::get_singleton()->lock->unlock();
+ GDScriptLanguage::get_singleton()->script_list.add(&script_list);
}
#endif
}
@@ -1057,13 +1038,10 @@ GDScript::~GDScript() {
_save_orphaned_subclasses();
#ifdef DEBUG_ENABLED
- if (GDScriptLanguage::get_singleton()->lock) {
- GDScriptLanguage::get_singleton()->lock->lock();
- }
- GDScriptLanguage::get_singleton()->script_list.remove(&script_list);
+ {
+ MutexLock lock(GDScriptLanguage::get_singleton()->lock);
- if (GDScriptLanguage::get_singleton()->lock) {
- GDScriptLanguage::get_singleton()->lock->unlock();
+ GDScriptLanguage::get_singleton()->script_list.remove(&script_list);
}
#endif
}
@@ -1472,14 +1450,9 @@ GDScriptInstance::GDScriptInstance() {
GDScriptInstance::~GDScriptInstance() {
if (script.is_valid() && owner) {
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->lock();
-#endif
+ MutexLock lock(GDScriptLanguage::singleton->lock);
script->instances.erase(owner);
-#ifndef NO_THREADS
- GDScriptLanguage::singleton->lock->unlock();
-#endif
}
}
@@ -1580,9 +1553,7 @@ void GDScriptLanguage::finish() {
void GDScriptLanguage::profiling_start() {
#ifdef DEBUG_ENABLED
- if (lock) {
- lock->lock();
- }
+ MutexLock lock(this->lock);
SelfList<GDScriptFunction> *elem = function_list.first();
while (elem) {
@@ -1599,25 +1570,15 @@ void GDScriptLanguage::profiling_start() {
}
profiling = true;
- if (lock) {
- lock->unlock();
- }
-
#endif
}
void GDScriptLanguage::profiling_stop() {
#ifdef DEBUG_ENABLED
- if (lock) {
- lock->lock();
- }
+ MutexLock lock(this->lock);
profiling = false;
- if (lock) {
- lock->unlock();
- }
-
#endif
}
@@ -1625,9 +1586,8 @@ int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr,
int current = 0;
#ifdef DEBUG_ENABLED
- if (lock) {
- lock->lock();
- }
+
+ MutexLock lock(this->lock);
SelfList<GDScriptFunction> *elem = function_list.first();
while (elem) {
@@ -1640,11 +1600,6 @@ int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr,
elem = elem->next();
current++;
}
-
- if (lock) {
- lock->unlock();
- }
-
#endif
return current;
@@ -1655,9 +1610,7 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_
int current = 0;
#ifdef DEBUG_ENABLED
- if (lock) {
- lock->lock();
- }
+ MutexLock lock(this->lock);
SelfList<GDScriptFunction> *elem = function_list.first();
while (elem) {
@@ -1672,11 +1625,6 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_
}
elem = elem->next();
}
-
- if (lock) {
- lock->unlock();
- }
-
#endif
return current;
@@ -1707,23 +1655,18 @@ void GDScriptLanguage::reload_all_scripts() {
#ifdef DEBUG_ENABLED
print_verbose("GDScript: Reloading all scripts");
- if (lock) {
- lock->lock();
- }
-
List<Ref<GDScript> > scripts;
+ {
+ MutexLock lock(this->lock);
- SelfList<GDScript> *elem = script_list.first();
- while (elem) {
- if (elem->self()->get_path().is_resource_file()) {
- print_verbose("GDScript: Found: " + elem->self()->get_path());
- scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
+ SelfList<GDScript> *elem = script_list.first();
+ while (elem) {
+ if (elem->self()->get_path().is_resource_file()) {
+ print_verbose("GDScript: Found: " + elem->self()->get_path());
+ scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
+ }
+ elem = elem->next();
}
- elem = elem->next();
- }
-
- if (lock) {
- lock->unlock();
}
//as scripts are going to be reloaded, must proceed without locking here
@@ -1743,23 +1686,18 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
#ifdef DEBUG_ENABLED
- if (lock) {
- lock->lock();
- }
-
List<Ref<GDScript> > scripts;
+ {
+ MutexLock lock(this->lock);
- SelfList<GDScript> *elem = script_list.first();
- while (elem) {
- if (elem->self()->get_path().is_resource_file()) {
+ SelfList<GDScript> *elem = script_list.first();
+ while (elem) {
+ if (elem->self()->get_path().is_resource_file()) {
- scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
+ scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
+ }
+ elem = elem->next();
}
- elem = elem->next();
- }
-
- if (lock) {
- lock->unlock();
}
//when someone asks you why dynamically typed languages are easier to write....
@@ -1879,9 +1817,7 @@ void GDScriptLanguage::frame() {
#ifdef DEBUG_ENABLED
if (profiling) {
- if (lock) {
- lock->lock();
- }
+ MutexLock lock(this->lock);
SelfList<GDScriptFunction> *elem = function_list.first();
while (elem) {
@@ -1893,10 +1829,6 @@ void GDScriptLanguage::frame() {
elem->self()->profile.frame_total_time = 0;
elem = elem->next();
}
-
- if (lock) {
- lock->unlock();
- }
}
#endif
@@ -2262,11 +2194,6 @@ GDScriptLanguage::GDScriptLanguage() {
_debug_parse_err_line = -1;
_debug_parse_err_file = "";
-#ifdef NO_THREADS
- lock = NULL;
-#else
- lock = Mutex::create();
-#endif
profiling = false;
script_frame_time = 0;
@@ -2300,10 +2227,6 @@ GDScriptLanguage::GDScriptLanguage() {
GDScriptLanguage::~GDScriptLanguage() {
- if (lock) {
- memdelete(lock);
- lock = NULL;
- }
if (_call_stack) {
memdelete_arr(_call_stack);
}
@@ -2328,7 +2251,7 @@ Ref<GDScript> GDScriptLanguage::get_orphan_subclass(const String &p_qualified_na
/*************** RESOURCE ***************/
-RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
if (r_error)
*r_error = ERR_FILE_CANT_OPEN;
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index 6598a0023b..3a90f0fc20 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -369,7 +369,7 @@ class GDScriptLanguage : public ScriptLanguage {
friend class GDScriptInstance;
- Mutex *lock;
+ Mutex lock;
friend class GDScript;
@@ -542,7 +542,7 @@ public:
class ResourceFormatLoaderGDScript : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp
index bc3f66719f..1bc1aae0d2 100644
--- a/modules/gdscript/gdscript_editor.cpp
+++ b/modules/gdscript/gdscript_editor.cpp
@@ -1124,7 +1124,7 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G
v2 = 1;
v2_use_value = false;
}
- if (vop == Variant::OP_DIVIDE && v2.get_type() == Variant::REAL) {
+ if (vop == Variant::OP_DIVIDE && v2.get_type() == Variant::FLOAT) {
v2 = 1.0;
v2_use_value = false;
}
@@ -2172,8 +2172,8 @@ static void _find_identifiers(const GDScriptCompletionContext &p_context, bool p
}
static const char *_type_names[Variant::VARIANT_MAX] = {
- "null", "bool", "int", "float", "String", "Vector2", "Rect2", "Vector3", "Transform2D", "Plane", "Quat", "AABB", "Basis", "Transform",
- "Color", "NodePath", "RID", "Object", "Dictionary", "Array", "PackedByteArray", "PackedIntArray", "PackedRealArray", "PackedStringArray",
+ "null", "bool", "int", "float", "String", "Vector2", "Vector2i", "Rect2", "Rect2i", "Vector3", "Vector3i", "Transform2D", "Plane", "Quat", "AABB", "Basis", "Transform",
+ "Color", "StringName", "NodePath", "RID", "Object", "Callable", "Signal", "Dictionary", "Array", "PackedByteArray", "PackedInt32Array", "PackedInt64Array", "PackedFloat32Array", "PackedFloat64Array", "PackedStringArray",
"PackedVector2Array", "PackedVector3Array", "PackedColorArray"
};
diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp
index 27857ea91f..79c550c81c 100644
--- a/modules/gdscript/gdscript_function.cpp
+++ b/modules/gdscript/gdscript_function.cpp
@@ -1769,13 +1769,10 @@ GDScriptFunction::GDScriptFunction() :
#ifdef DEBUG_ENABLED
_func_cname = NULL;
- if (GDScriptLanguage::get_singleton()->lock) {
- GDScriptLanguage::get_singleton()->lock->lock();
- }
- GDScriptLanguage::get_singleton()->function_list.add(&function_list);
+ {
+ MutexLock lock(GDScriptLanguage::get_singleton()->lock);
- if (GDScriptLanguage::get_singleton()->lock) {
- GDScriptLanguage::get_singleton()->lock->unlock();
+ GDScriptLanguage::get_singleton()->function_list.add(&function_list);
}
profile.call_count = 0;
@@ -1793,14 +1790,10 @@ GDScriptFunction::GDScriptFunction() :
GDScriptFunction::~GDScriptFunction() {
#ifdef DEBUG_ENABLED
- if (GDScriptLanguage::get_singleton()->lock) {
- GDScriptLanguage::get_singleton()->lock->lock();
- }
- GDScriptLanguage::get_singleton()->function_list.remove(&function_list);
- if (GDScriptLanguage::get_singleton()->lock) {
- GDScriptLanguage::get_singleton()->lock->unlock();
- }
+ MutexLock lock(GDScriptLanguage::get_singleton()->lock);
+
+ GDScriptLanguage::get_singleton()->function_list.remove(&function_list);
#endif
}
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp
index 426b5b58cb..aaa308f40f 100644
--- a/modules/gdscript/gdscript_functions.cpp
+++ b/modules/gdscript/gdscript_functions.cpp
@@ -162,7 +162,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
if (!p_args[m_arg]->is_num()) { \
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; \
r_error.argument = m_arg; \
- r_error.expected = Variant::REAL; \
+ r_error.expected = Variant::FLOAT; \
r_ret = Variant(); \
return; \
}
@@ -272,7 +272,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
int64_t i = *p_args[0];
r_ret = ABS(i);
- } else if (p_args[0]->get_type() == Variant::REAL) {
+ } else if (p_args[0]->get_type() == Variant::FLOAT) {
double r = *p_args[0];
r_ret = Math::abs(r);
@@ -280,7 +280,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
- r_error.expected = Variant::REAL;
+ r_error.expected = Variant::FLOAT;
r_ret = Variant();
}
} break;
@@ -290,7 +290,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
int64_t i = *p_args[0];
r_ret = i < 0 ? -1 : (i > 0 ? +1 : 0);
- } else if (p_args[0]->get_type() == Variant::REAL) {
+ } else if (p_args[0]->get_type() == Variant::FLOAT) {
real_t r = *p_args[0];
r_ret = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0);
@@ -298,7 +298,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
- r_error.expected = Variant::REAL;
+ r_error.expected = Variant::FLOAT;
r_ret = Variant();
}
} break;
@@ -360,7 +360,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
VALIDATE_ARG_COUNT(3);
VALIDATE_ARG_NUM(2);
const double t = (double)*p_args[2];
- switch (p_args[0]->get_type() == p_args[1]->get_type() ? p_args[0]->get_type() : Variant::REAL) {
+ switch (p_args[0]->get_type() == p_args[1]->get_type() ? p_args[0]->get_type() : Variant::FLOAT) {
case Variant::VECTOR2: {
r_ret = ((Vector2)*p_args[0]).linear_interpolate((Vector2)*p_args[1], t);
} break;
@@ -1359,7 +1359,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
case INSTANCE_FROM_ID: {
VALIDATE_ARG_COUNT(1);
- if (p_args[0]->get_type() != Variant::INT && p_args[0]->get_type() != Variant::REAL) {
+ if (p_args[0]->get_type() != Variant::INT && p_args[0]->get_type() != Variant::FLOAT) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::INT;
@@ -1395,14 +1395,24 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
Vector<uint8_t> d = *p_args[0];
r_ret = d.size();
} break;
- case Variant::PACKED_INT_ARRAY: {
+ case Variant::PACKED_INT32_ARRAY: {
- Vector<int> d = *p_args[0];
+ Vector<int32_t> d = *p_args[0];
r_ret = d.size();
} break;
- case Variant::PACKED_REAL_ARRAY: {
+ case Variant::PACKED_INT64_ARRAY: {
- Vector<real_t> d = *p_args[0];
+ Vector<int64_t> d = *p_args[0];
+ r_ret = d.size();
+ } break;
+ case Variant::PACKED_FLOAT32_ARRAY: {
+
+ Vector<float> d = *p_args[0];
+ r_ret = d.size();
+ } break;
+ case Variant::PACKED_FLOAT64_ARRAY: {
+
+ Vector<double> d = *p_args[0];
r_ret = d.size();
} break;
case Variant::PACKED_STRING_ARRAY: {
@@ -1530,69 +1540,69 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
switch (p_func) {
case MATH_SIN: {
- MethodInfo mi("sin", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("sin", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_COS: {
- MethodInfo mi("cos", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("cos", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_TAN: {
- MethodInfo mi("tan", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("tan", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_SINH: {
- MethodInfo mi("sinh", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("sinh", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_COSH: {
- MethodInfo mi("cosh", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("cosh", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_TANH: {
- MethodInfo mi("tanh", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("tanh", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_ASIN: {
- MethodInfo mi("asin", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("asin", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_ACOS: {
- MethodInfo mi("acos", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("acos", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_ATAN: {
- MethodInfo mi("atan", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("atan", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_ATAN2: {
- MethodInfo mi("atan2", PropertyInfo(Variant::REAL, "y"), PropertyInfo(Variant::REAL, "x"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("atan2", PropertyInfo(Variant::FLOAT, "y"), PropertyInfo(Variant::FLOAT, "x"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_SQRT: {
- MethodInfo mi("sqrt", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("sqrt", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_FMOD: {
- MethodInfo mi("fmod", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("fmod", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_FPOSMOD: {
- MethodInfo mi("fposmod", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("fposmod", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_POSMOD: {
@@ -1601,114 +1611,114 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
return mi;
} break;
case MATH_FLOOR: {
- MethodInfo mi("floor", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("floor", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_CEIL: {
- MethodInfo mi("ceil", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("ceil", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_ROUND: {
- MethodInfo mi("round", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("round", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_ABS: {
- MethodInfo mi("abs", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("abs", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_SIGN: {
- MethodInfo mi("sign", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("sign", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_POW: {
- MethodInfo mi("pow", PropertyInfo(Variant::REAL, "base"), PropertyInfo(Variant::REAL, "exp"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("pow", PropertyInfo(Variant::FLOAT, "base"), PropertyInfo(Variant::FLOAT, "exp"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_LOG: {
- MethodInfo mi("log", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("log", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_EXP: {
- MethodInfo mi("exp", PropertyInfo(Variant::REAL, "s"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("exp", PropertyInfo(Variant::FLOAT, "s"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_ISNAN: {
- MethodInfo mi("is_nan", PropertyInfo(Variant::REAL, "s"));
+ MethodInfo mi("is_nan", PropertyInfo(Variant::FLOAT, "s"));
mi.return_val.type = Variant::BOOL;
return mi;
} break;
case MATH_ISINF: {
- MethodInfo mi("is_inf", PropertyInfo(Variant::REAL, "s"));
+ MethodInfo mi("is_inf", PropertyInfo(Variant::FLOAT, "s"));
mi.return_val.type = Variant::BOOL;
return mi;
} break;
case MATH_ISEQUALAPPROX: {
- MethodInfo mi("is_equal_approx", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b"));
+ MethodInfo mi("is_equal_approx", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b"));
mi.return_val.type = Variant::BOOL;
return mi;
} break;
case MATH_ISZEROAPPROX: {
- MethodInfo mi("is_zero_approx", PropertyInfo(Variant::REAL, "s"));
+ MethodInfo mi("is_zero_approx", PropertyInfo(Variant::FLOAT, "s"));
mi.return_val.type = Variant::BOOL;
return mi;
} break;
case MATH_EASE: {
- MethodInfo mi("ease", PropertyInfo(Variant::REAL, "s"), PropertyInfo(Variant::REAL, "curve"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("ease", PropertyInfo(Variant::FLOAT, "s"), PropertyInfo(Variant::FLOAT, "curve"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_STEP_DECIMALS: {
- MethodInfo mi("step_decimals", PropertyInfo(Variant::REAL, "step"));
+ MethodInfo mi("step_decimals", PropertyInfo(Variant::FLOAT, "step"));
mi.return_val.type = Variant::INT;
return mi;
} break;
case MATH_STEPIFY: {
- MethodInfo mi("stepify", PropertyInfo(Variant::REAL, "s"), PropertyInfo(Variant::REAL, "step"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("stepify", PropertyInfo(Variant::FLOAT, "s"), PropertyInfo(Variant::FLOAT, "step"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_LERP: {
- MethodInfo mi("lerp", PropertyInfo(Variant::NIL, "from"), PropertyInfo(Variant::NIL, "to"), PropertyInfo(Variant::REAL, "weight"));
+ MethodInfo mi("lerp", PropertyInfo(Variant::NIL, "from"), PropertyInfo(Variant::NIL, "to"), PropertyInfo(Variant::FLOAT, "weight"));
mi.return_val.type = Variant::NIL;
mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
return mi;
} break;
case MATH_LERP_ANGLE: {
- MethodInfo mi("lerp_angle", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "weight"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("lerp_angle", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"), PropertyInfo(Variant::FLOAT, "weight"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_INVERSE_LERP: {
- MethodInfo mi("inverse_lerp", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "weight"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("inverse_lerp", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"), PropertyInfo(Variant::FLOAT, "weight"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_RANGE_LERP: {
- MethodInfo mi("range_lerp", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "istart"), PropertyInfo(Variant::REAL, "istop"), PropertyInfo(Variant::REAL, "ostart"), PropertyInfo(Variant::REAL, "ostop"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("range_lerp", PropertyInfo(Variant::FLOAT, "value"), PropertyInfo(Variant::FLOAT, "istart"), PropertyInfo(Variant::FLOAT, "istop"), PropertyInfo(Variant::FLOAT, "ostart"), PropertyInfo(Variant::FLOAT, "ostop"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_SMOOTHSTEP: {
- MethodInfo mi("smoothstep", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "weight"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("smoothstep", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"), PropertyInfo(Variant::FLOAT, "weight"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_MOVE_TOWARD: {
- MethodInfo mi("move_toward", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"), PropertyInfo(Variant::REAL, "delta"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("move_toward", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"), PropertyInfo(Variant::FLOAT, "delta"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_DECTIME: {
- MethodInfo mi("dectime", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "amount"), PropertyInfo(Variant::REAL, "step"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("dectime", PropertyInfo(Variant::FLOAT, "value"), PropertyInfo(Variant::FLOAT, "amount"), PropertyInfo(Variant::FLOAT, "step"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_RANDOMIZE: {
@@ -1723,12 +1733,12 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
} break;
case MATH_RANDF: {
MethodInfo mi("randf");
- mi.return_val.type = Variant::REAL;
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_RANDOM: {
- MethodInfo mi("rand_range", PropertyInfo(Variant::REAL, "from"), PropertyInfo(Variant::REAL, "to"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("rand_range", PropertyInfo(Variant::FLOAT, "from"), PropertyInfo(Variant::FLOAT, "to"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_SEED: {
@@ -1742,32 +1752,32 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
return mi;
} break;
case MATH_DEG2RAD: {
- MethodInfo mi("deg2rad", PropertyInfo(Variant::REAL, "deg"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("deg2rad", PropertyInfo(Variant::FLOAT, "deg"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_RAD2DEG: {
- MethodInfo mi("rad2deg", PropertyInfo(Variant::REAL, "rad"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("rad2deg", PropertyInfo(Variant::FLOAT, "rad"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_LINEAR2DB: {
- MethodInfo mi("linear2db", PropertyInfo(Variant::REAL, "nrg"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("linear2db", PropertyInfo(Variant::FLOAT, "nrg"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_DB2LINEAR: {
- MethodInfo mi("db2linear", PropertyInfo(Variant::REAL, "db"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("db2linear", PropertyInfo(Variant::FLOAT, "db"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case MATH_POLAR2CARTESIAN: {
- MethodInfo mi("polar2cartesian", PropertyInfo(Variant::REAL, "r"), PropertyInfo(Variant::REAL, "th"));
+ MethodInfo mi("polar2cartesian", PropertyInfo(Variant::FLOAT, "r"), PropertyInfo(Variant::FLOAT, "th"));
mi.return_val.type = Variant::VECTOR2;
return mi;
} break;
case MATH_CARTESIAN2POLAR: {
- MethodInfo mi("cartesian2polar", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y"));
+ MethodInfo mi("cartesian2polar", PropertyInfo(Variant::FLOAT, "x"), PropertyInfo(Variant::FLOAT, "y"));
mi.return_val.type = Variant::VECTOR2;
return mi;
} break;
@@ -1777,24 +1787,24 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
return mi;
} break;
case MATH_WRAPF: {
- MethodInfo mi("wrapf", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "min"), PropertyInfo(Variant::REAL, "max"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("wrapf", PropertyInfo(Variant::FLOAT, "value"), PropertyInfo(Variant::FLOAT, "min"), PropertyInfo(Variant::FLOAT, "max"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case LOGIC_MAX: {
- MethodInfo mi("max", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("max", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case LOGIC_MIN: {
- MethodInfo mi("min", PropertyInfo(Variant::REAL, "a"), PropertyInfo(Variant::REAL, "b"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("min", PropertyInfo(Variant::FLOAT, "a"), PropertyInfo(Variant::FLOAT, "b"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case LOGIC_CLAMP: {
- MethodInfo mi("clamp", PropertyInfo(Variant::REAL, "value"), PropertyInfo(Variant::REAL, "min"), PropertyInfo(Variant::REAL, "max"));
- mi.return_val.type = Variant::REAL;
+ MethodInfo mi("clamp", PropertyInfo(Variant::FLOAT, "value"), PropertyInfo(Variant::FLOAT, "min"), PropertyInfo(Variant::FLOAT, "max"));
+ mi.return_val.type = Variant::FLOAT;
return mi;
} break;
case LOGIC_NEAREST_PO2: {
@@ -2012,7 +2022,7 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
} break;
case COLORN: {
- MethodInfo mi("ColorN", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::REAL, "alpha"));
+ MethodInfo mi("ColorN", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::FLOAT, "alpha"));
mi.default_arguments.push_back(1.0f);
mi.return_val.type = Variant::COLOR;
return mi;
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index 842ce6c1c1..0382944efd 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -3108,7 +3108,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) {
args.push_back(op->arguments[i]);
if (constant && op->arguments[i]->type == Node::TYPE_CONSTANT) {
ConstantNode *c = static_cast<ConstantNode *>(op->arguments[i]);
- if (c->value.get_type() == Variant::REAL || c->value.get_type() == Variant::INT) {
+ if (c->value.get_type() == Variant::FLOAT || c->value.get_type() == Variant::INT) {
constants.push_back(c->value);
constant = true;
}
@@ -4222,7 +4222,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
[[fallthrough]];
}
- case Variant::REAL: {
+ case Variant::FLOAT: {
if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EASE") {
current_export.hint = PROPERTY_HINT_EXP_EASING;
@@ -5955,10 +5955,10 @@ GDScriptParser::DataType GDScriptParser::_get_operation_type(const Variant::Oper
}
// Avoid division by zero
- if (a_type == Variant::INT || a_type == Variant::REAL) {
+ if (a_type == Variant::INT || a_type == Variant::FLOAT) {
Variant::evaluate(Variant::OP_ADD, a, 1, a, r_valid);
}
- if (b_type == Variant::INT || b_type == Variant::REAL) {
+ if (b_type == Variant::INT || b_type == Variant::FLOAT) {
Variant::evaluate(Variant::OP_ADD, b, 1, b, r_valid);
}
if (a_type == Variant::STRING && b_type != Variant::ARRAY) {
@@ -6598,14 +6598,16 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
// Expect int or real as index
case Variant::PACKED_BYTE_ARRAY:
case Variant::PACKED_COLOR_ARRAY:
- case Variant::PACKED_INT_ARRAY:
- case Variant::PACKED_REAL_ARRAY:
+ case Variant::PACKED_INT32_ARRAY:
+ case Variant::PACKED_INT64_ARRAY:
+ case Variant::PACKED_FLOAT32_ARRAY:
+ case Variant::PACKED_FLOAT64_ARRAY:
case Variant::PACKED_STRING_ARRAY:
case Variant::PACKED_VECTOR2_ARRAY:
case Variant::PACKED_VECTOR3_ARRAY:
case Variant::ARRAY:
case Variant::STRING: {
- error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::REAL;
+ error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::FLOAT;
} break;
// Expect String only
case Variant::RECT2:
@@ -6621,7 +6623,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
case Variant::TRANSFORM2D:
case Variant::BASIS:
case Variant::TRANSFORM: {
- error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::REAL &&
+ error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::FLOAT &&
index_type.builtin_type != Variant::STRING;
} break;
// Expect String or int
@@ -6648,8 +6650,10 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
case Variant::DICTIONARY:
case Variant::PACKED_BYTE_ARRAY:
case Variant::PACKED_COLOR_ARRAY:
- case Variant::PACKED_INT_ARRAY:
- case Variant::PACKED_REAL_ARRAY:
+ case Variant::PACKED_INT32_ARRAY:
+ case Variant::PACKED_INT64_ARRAY:
+ case Variant::PACKED_FLOAT32_ARRAY:
+ case Variant::PACKED_FLOAT64_ARRAY:
case Variant::PACKED_STRING_ARRAY:
case Variant::PACKED_VECTOR2_ARRAY:
case Variant::PACKED_VECTOR3_ARRAY: {
@@ -6691,7 +6695,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
case Variant::NIL:
case Variant::BOOL:
case Variant::INT:
- case Variant::REAL:
+ case Variant::FLOAT:
case Variant::NODE_PATH:
case Variant::_RID: {
_set_error("Can't index on a value of type \"" + base_type.to_string() + "\".", op->line);
@@ -6699,15 +6703,17 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) {
} break;
// Return int
case Variant::PACKED_BYTE_ARRAY:
- case Variant::PACKED_INT_ARRAY: {
+ case Variant::PACKED_INT32_ARRAY:
+ case Variant::PACKED_INT64_ARRAY: {
result.builtin_type = Variant::INT;
} break;
// Return real
- case Variant::PACKED_REAL_ARRAY:
+ case Variant::PACKED_FLOAT32_ARRAY:
+ case Variant::PACKED_FLOAT64_ARRAY:
case Variant::VECTOR2:
case Variant::VECTOR3:
case Variant::QUAT: {
- result.builtin_type = Variant::REAL;
+ result.builtin_type = Variant::FLOAT;
} break;
// Return color
case Variant::PACKED_COLOR_ARRAY: {
@@ -7002,7 +7008,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
break;
} else {
#ifdef DEBUG_ENABLED
- if (arg_type.kind == DataType::BUILTIN && arg_type.builtin_type == Variant::INT && par_types[i].kind == DataType::BUILTIN && par_types[i].builtin_type == Variant::REAL) {
+ if (arg_type.kind == DataType::BUILTIN && arg_type.builtin_type == Variant::INT && par_types[i].kind == DataType::BUILTIN && par_types[i].builtin_type == Variant::FLOAT) {
_add_warning(GDScriptWarning::NARROWING_CONVERSION, p_call->line, Variant::get_type_name(tn->vtype));
}
if (par_types[i].may_yield && p_call->arguments[i + 1]->type == Node::TYPE_OPERATOR) {
@@ -7245,7 +7251,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat
_mark_line_as_unsafe(p_call->line);
}
} else {
- if (arg_type.kind == DataType::BUILTIN && arg_type.builtin_type == Variant::INT && par_type.kind == DataType::BUILTIN && par_type.builtin_type == Variant::REAL) {
+ if (arg_type.kind == DataType::BUILTIN && arg_type.builtin_type == Variant::INT && par_type.kind == DataType::BUILTIN && par_type.builtin_type == Variant::FLOAT) {
_add_warning(GDScriptWarning::NARROWING_CONVERSION, p_call->line, callee_name);
}
}
@@ -8103,7 +8109,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
lv->assign = convert_call;
lv->assign_op->arguments.write[1] = convert_call;
#ifdef DEBUG_ENABLED
- if (lv->datatype.builtin_type == Variant::INT && assign_type.builtin_type == Variant::REAL) {
+ if (lv->datatype.builtin_type == Variant::INT && assign_type.builtin_type == Variant::FLOAT) {
_add_warning(GDScriptWarning::NARROWING_CONVERSION, lv->line);
}
#endif // DEBUG_ENABLED
@@ -8240,7 +8246,7 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
type_match = true; // Since we are converting, the type is matching
}
#ifdef DEBUG_ENABLED
- if (lh_type.builtin_type == Variant::INT && rh_type.builtin_type == Variant::REAL) {
+ if (lh_type.builtin_type == Variant::INT && rh_type.builtin_type == Variant::FLOAT) {
_add_warning(GDScriptWarning::NARROWING_CONVERSION, op->line);
}
#endif // DEBUG_ENABLED
diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp
index 818033025e..9064998d32 100644
--- a/modules/gdscript/gdscript_tokenizer.cpp
+++ b/modules/gdscript/gdscript_tokenizer.cpp
@@ -146,7 +146,7 @@ static const _bit _type_list[] = {
//types
{ Variant::BOOL, "bool" },
{ Variant::INT, "int" },
- { Variant::REAL, "float" },
+ { Variant::FLOAT, "float" },
{ Variant::STRING, "String" },
{ Variant::VECTOR2, "Vector2" },
{ Variant::VECTOR2I, "Vector2i" },
@@ -170,8 +170,10 @@ static const _bit _type_list[] = {
{ Variant::SIGNAL, "Signal" },
{ Variant::ARRAY, "Array" },
{ Variant::PACKED_BYTE_ARRAY, "PackedByteArray" },
- { Variant::PACKED_INT_ARRAY, "PackedIntArray" },
- { Variant::PACKED_REAL_ARRAY, "PackedRealArray" },
+ { Variant::PACKED_INT32_ARRAY, "PackedInt32Array" },
+ { Variant::PACKED_INT64_ARRAY, "PackedInt64Array" },
+ { Variant::PACKED_FLOAT32_ARRAY, "PackedFloat32Array" },
+ { Variant::PACKED_FLOAT64_ARRAY, "PackedFloat64Array" },
{ Variant::PACKED_STRING_ARRAY, "PackedStringArray" },
{ Variant::PACKED_VECTOR2_ARRAY, "PackedVector2Array" },
{ Variant::PACKED_VECTOR3_ARRAY, "PackedVector3Array" },
diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp
index 1c0590cff1..ea54784f96 100644
--- a/modules/gdscript/language_server/gdscript_workspace.cpp
+++ b/modules/gdscript/language_server/gdscript_workspace.cpp
@@ -33,8 +33,11 @@
#include "../gdscript_parser.h"
#include "core/project_settings.h"
#include "core/script_language.h"
+#include "editor/editor_file_system.h"
#include "editor/editor_help.h"
+#include "editor/editor_node.h"
#include "gdscript_language_protocol.h"
+#include "scene/resources/packed_scene.h"
void GDScriptWorkspace::_bind_methods() {
ClassDB::bind_method(D_METHOD("symbol"), &GDScriptWorkspace::symbol);
@@ -373,6 +376,46 @@ void GDScriptWorkspace::publish_diagnostics(const String &p_path) {
GDScriptLanguageProtocol::get_singleton()->notify_client("textDocument/publishDiagnostics", params);
}
+void GDScriptWorkspace::_get_owners(EditorFileSystemDirectory *efsd, String p_path, List<String> &owners) {
+ if (!efsd)
+ return;
+
+ for (int i = 0; i < efsd->get_subdir_count(); i++) {
+ _get_owners(efsd->get_subdir(i), p_path, owners);
+ }
+
+ for (int i = 0; i < efsd->get_file_count(); i++) {
+
+ Vector<String> deps = efsd->get_file_deps(i);
+ bool found = false;
+ for (int j = 0; j < deps.size(); j++) {
+ if (deps[j] == p_path) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ continue;
+
+ owners.push_back(efsd->get_file_path(i));
+ }
+}
+
+Node *GDScriptWorkspace::_get_owner_node(String p_path) {
+ Node *owner_node = NULL;
+ List<String> owners;
+
+ _get_owners(EditorFileSystem::get_singleton()->get_filesystem(), p_path, owners);
+
+ if (owners.size() > 0) {
+ NodePath owner_path = owners[0];
+ Ref<PackedScene> owner_res = ResourceLoader::load(owner_path);
+ owner_node = owner_res->instance(PackedScene::GEN_EDIT_STATE_DISABLED);
+ }
+
+ return owner_node;
+}
+
void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<ScriptCodeCompletionOption> *r_options) {
String path = get_file_path(p_params.textDocument.uri);
@@ -380,8 +423,12 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S
bool forced = false;
if (const ExtendGDScriptParser *parser = get_parse_result(path)) {
+ Node *owner_node = _get_owner_node(path);
String code = parser->get_text_for_completion(p_params.position);
- GDScriptLanguage::get_singleton()->complete_code(code, path, NULL, r_options, forced, call_hint);
+ GDScriptLanguage::get_singleton()->complete_code(code, path, owner_node, r_options, forced, call_hint);
+ if (owner_node) {
+ memdelete(owner_node);
+ }
}
}
diff --git a/modules/gdscript/language_server/gdscript_workspace.h b/modules/gdscript/language_server/gdscript_workspace.h
index 146a5cb7c9..8b46d345d9 100644
--- a/modules/gdscript/language_server/gdscript_workspace.h
+++ b/modules/gdscript/language_server/gdscript_workspace.h
@@ -33,12 +33,17 @@
#include "../gdscript_parser.h"
#include "core/variant.h"
+#include "editor/editor_file_system.h"
#include "gdscript_extend_parser.h"
#include "lsp.hpp"
class GDScriptWorkspace : public Reference {
GDCLASS(GDScriptWorkspace, Reference);
+private:
+ void _get_owners(EditorFileSystemDirectory *efsd, String p_path, List<String> &owners);
+ Node *_get_owner_node(String p_path);
+
protected:
static void _bind_methods();
void remove_cache_parser(const String &p_path);
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index ba0449c046..84075f76fd 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -874,7 +874,7 @@ void GridMap::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_x"), "set_center_x", "get_center_x");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_y"), "set_center_y", "get_center_y");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_center_z"), "set_center_z", "get_center_z");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell_scale"), "set_cell_scale", "get_cell_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_scale"), "set_cell_scale", "get_cell_scale");
ADD_GROUP("Collision", "collision_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index 761771a02c..a656ee8b63 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -752,7 +752,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
if (k.is_valid()) {
if (k->is_pressed()) {
- if (k->get_scancode() == KEY_ESCAPE) {
+ if (k->get_keycode() == KEY_ESCAPE) {
if (input_action == INPUT_PASTE) {
_clear_clipboard_data();
@@ -773,12 +773,12 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
if (k->get_shift() && selection.active && input_action != INPUT_PASTE) {
- if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) {
+ if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) {
selection.click[edit_axis]--;
_validate_selection();
return true;
}
- if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) {
+ if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) {
selection.click[edit_axis]++;
_validate_selection();
return true;
@@ -842,7 +842,7 @@ void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
const Ref<InputEventKey> k = p_ie;
- if (k.is_valid() && (k->get_scancode() == KEY_UP || k->get_scancode() == KEY_DOWN || k->get_scancode() == KEY_PAGEUP || k->get_scancode() == KEY_PAGEDOWN)) {
+ if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) {
// Forward the key input to the ItemList so it can be scrolled
mesh_library_palette->call("_gui_input", k);
@@ -954,7 +954,7 @@ void GridMapEditor::update_palette() {
void GridMapEditor::edit(GridMap *p_gridmap) {
if (!p_gridmap && node)
- node->disconnect_compat("cell_size_changed", this, "_draw_grids");
+ node->disconnect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids));
node = p_gridmap;
@@ -988,7 +988,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
update_grid();
_update_clip();
- node->connect_compat("cell_size_changed", this, "_draw_grids");
+ node->connect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids));
}
void GridMapEditor::_update_clip() {
@@ -1077,8 +1077,8 @@ void GridMapEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- get_tree()->connect_compat("node_removed", this, "_node_removed");
- mesh_library_palette->connect_compat("item_selected", this, "_item_selected_cbk");
+ get_tree()->connect("node_removed", callable_mp(this, &GridMapEditor::_node_removed));
+ mesh_library_palette->connect("item_selected", callable_mp(this, &GridMapEditor::_item_selected_cbk));
for (int i = 0; i < 3; i++) {
grid[i] = VS::get_singleton()->mesh_create();
@@ -1094,7 +1094,7 @@ void GridMapEditor::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
- get_tree()->disconnect_compat("node_removed", this, "_node_removed");
+ get_tree()->disconnect("node_removed", callable_mp(this, &GridMapEditor::_node_removed));
_clear_clipboard_data();
for (int i = 0; i < 3; i++) {
@@ -1198,20 +1198,8 @@ void GridMapEditor::_floor_mouse_exited() {
void GridMapEditor::_bind_methods() {
- ClassDB::bind_method("_text_changed", &GridMapEditor::_text_changed);
- ClassDB::bind_method("_sbox_input", &GridMapEditor::_sbox_input);
- ClassDB::bind_method("_mesh_library_palette_input", &GridMapEditor::_mesh_library_palette_input);
- ClassDB::bind_method("_icon_size_changed", &GridMapEditor::_icon_size_changed);
- ClassDB::bind_method("_menu_option", &GridMapEditor::_menu_option);
ClassDB::bind_method("_configure", &GridMapEditor::_configure);
- ClassDB::bind_method("_item_selected_cbk", &GridMapEditor::_item_selected_cbk);
- ClassDB::bind_method("_floor_changed", &GridMapEditor::_floor_changed);
- ClassDB::bind_method("_floor_mouse_exited", &GridMapEditor::_floor_mouse_exited);
ClassDB::bind_method("_set_selection", &GridMapEditor::_set_selection);
- ClassDB::bind_method("_node_removed", &GridMapEditor::_node_removed);
-
- ClassDB::bind_method(D_METHOD("_set_display_mode", "mode"), &GridMapEditor::_set_display_mode);
- ClassDB::bind_method("_draw_grids", &GridMapEditor::_draw_grids);
}
GridMapEditor::GridMapEditor(EditorNode *p_editor) {
@@ -1241,9 +1229,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
floor->get_line_edit()->add_constant_override("minimum_spaces", 16);
spatial_editor_hb->add_child(floor);
- floor->connect_compat("value_changed", this, "_floor_changed");
- floor->connect_compat("mouse_exited", this, "_floor_mouse_exited");
- floor->get_line_edit()->connect_compat("mouse_exited", this, "_floor_mouse_exited");
+ floor->connect("value_changed", callable_mp(this, &GridMapEditor::_floor_changed));
+ floor->connect("mouse_exited", callable_mp(this, &GridMapEditor::_floor_mouse_exited));
+ floor->get_line_edit()->connect("mouse_exited", callable_mp(this, &GridMapEditor::_floor_mouse_exited));
spatial_editor_hb->add_child(memnew(VSeparator));
@@ -1300,7 +1288,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance);
clip_mode = CLIP_DISABLED;
- options->get_popup()->connect_compat("id_pressed", this, "_menu_option");
+ options->get_popup()->connect("id_pressed", callable_mp(this, &GridMapEditor::_menu_option));
HBoxContainer *hb = memnew(HBoxContainer);
add_child(hb);
@@ -1310,22 +1298,22 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
search_box->set_h_size_flags(SIZE_EXPAND_FILL);
search_box->set_placeholder(TTR("Filter meshes"));
hb->add_child(search_box);
- search_box->connect_compat("text_changed", this, "_text_changed");
- search_box->connect_compat("gui_input", this, "_sbox_input");
+ search_box->connect("text_changed", callable_mp(this, &GridMapEditor::_text_changed));
+ search_box->connect("gui_input", callable_mp(this, &GridMapEditor::_sbox_input));
mode_thumbnail = memnew(ToolButton);
mode_thumbnail->set_toggle_mode(true);
mode_thumbnail->set_pressed(true);
mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail", "EditorIcons"));
hb->add_child(mode_thumbnail);
- mode_thumbnail->connect_compat("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL));
+ mode_thumbnail->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode), varray(DISPLAY_THUMBNAIL));
mode_list = memnew(ToolButton);
mode_list->set_toggle_mode(true);
mode_list->set_pressed(false);
mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons"));
hb->add_child(mode_list);
- mode_list->connect_compat("pressed", this, "_set_display_mode", varray(DISPLAY_LIST));
+ mode_list->connect("pressed", callable_mp(this, &GridMapEditor::_set_display_mode), varray(DISPLAY_LIST));
size_slider = memnew(HSlider);
size_slider->set_h_size_flags(SIZE_EXPAND_FILL);
@@ -1333,7 +1321,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
size_slider->set_max(4.0f);
size_slider->set_step(0.1f);
size_slider->set_value(1.0f);
- size_slider->connect_compat("value_changed", this, "_icon_size_changed");
+ size_slider->connect("value_changed", callable_mp(this, &GridMapEditor::_icon_size_changed));
add_child(size_slider);
EDITOR_DEF("editors/grid_map/preview_size", 64);
@@ -1343,7 +1331,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
mesh_library_palette = memnew(ItemList);
add_child(mesh_library_palette);
mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL);
- mesh_library_palette->connect_compat("gui_input", this, "_mesh_library_palette_input");
+ mesh_library_palette->connect("gui_input", callable_mp(this, &GridMapEditor::_mesh_library_palette_input));
info_message = memnew(Label);
info_message->set_text(TTR("Give a MeshLibrary resource to this GridMap to use its meshes."));
diff --git a/modules/mobile_vr/mobile_vr_interface.cpp b/modules/mobile_vr/mobile_vr_interface.cpp
index afa8766bce..2f1d95cd42 100644
--- a/modules/mobile_vr/mobile_vr_interface.cpp
+++ b/modules/mobile_vr/mobile_vr_interface.cpp
@@ -221,13 +221,13 @@ void MobileVRInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_k2", "k"), &MobileVRInterface::set_k2);
ClassDB::bind_method(D_METHOD("get_k2"), &MobileVRInterface::get_k2);
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "eye_height", PROPERTY_HINT_RANGE, "0.0,3.0,0.1"), "set_eye_height", "get_eye_height");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "iod", PROPERTY_HINT_RANGE, "4.0,10.0,0.1"), "set_iod", "get_iod");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "display_width", PROPERTY_HINT_RANGE, "5.0,25.0,0.1"), "set_display_width", "get_display_width");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "display_to_lens", PROPERTY_HINT_RANGE, "5.0,25.0,0.1"), "set_display_to_lens", "get_display_to_lens");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "oversample", PROPERTY_HINT_RANGE, "1.0,2.0,0.1"), "set_oversample", "get_oversample");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "k1", PROPERTY_HINT_RANGE, "0.1,10.0,0.0001"), "set_k1", "get_k1");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "k2", PROPERTY_HINT_RANGE, "0.1,10.0,0.0001"), "set_k2", "get_k2");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "eye_height", PROPERTY_HINT_RANGE, "0.0,3.0,0.1"), "set_eye_height", "get_eye_height");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "iod", PROPERTY_HINT_RANGE, "4.0,10.0,0.1"), "set_iod", "get_iod");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "display_width", PROPERTY_HINT_RANGE, "5.0,25.0,0.1"), "set_display_width", "get_display_width");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "display_to_lens", PROPERTY_HINT_RANGE, "5.0,25.0,0.1"), "set_display_to_lens", "get_display_to_lens");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "oversample", PROPERTY_HINT_RANGE, "1.0,2.0,0.1"), "set_oversample", "get_oversample");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "k1", PROPERTY_HINT_RANGE, "0.1,10.0,0.0001"), "set_k1", "get_k1");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "k2", PROPERTY_HINT_RANGE, "0.1,10.0,0.0001"), "set_k2", "get_k2");
}
void MobileVRInterface::set_eye_height(const real_t p_eye_height) {
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 2b3b6aa98a..6809cbdff9 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -35,6 +35,7 @@
#include "core/io/json.h"
#include "core/os/file_access.h"
+#include "core/os/mutex.h"
#include "core/os/os.h"
#include "core/os/thread.h"
#include "core/project_settings.h"
@@ -58,7 +59,6 @@
#include "mono_gd/gd_mono_utils.h"
#include "signal_awaiter_utils.h"
#include "utils/macros.h"
-#include "utils/mutex_utils.h"
#include "utils/string_utils.h"
#include "utils/thread_local.h"
@@ -411,7 +411,7 @@ static String variant_type_to_managed_name(const String &p_var_type_name) {
if (p_var_type_name == Variant::get_type_name(Variant::OBJECT))
return "Godot.Object";
- if (p_var_type_name == Variant::get_type_name(Variant::REAL)) {
+ if (p_var_type_name == Variant::get_type_name(Variant::FLOAT)) {
#ifdef REAL_T_IS_DOUBLE
return "double";
#else
@@ -430,9 +430,9 @@ static String variant_type_to_managed_name(const String &p_var_type_name) {
if (p_var_type_name == Variant::get_type_name(Variant::PACKED_BYTE_ARRAY))
return "byte[]";
- if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT_ARRAY))
+ if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT32_ARRAY))
return "int[]";
- if (p_var_type_name == Variant::get_type_name(Variant::PACKED_REAL_ARRAY)) {
+ if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT32_ARRAY)) {
#ifdef REAL_T_IS_DOUBLE
return "double[]";
#else
@@ -633,7 +633,7 @@ Vector<ScriptLanguage::StackInfo> CSharpLanguage::stack_trace_get_info(MonoObjec
void CSharpLanguage::post_unsafe_reference(Object *p_obj) {
#ifdef DEBUG_ENABLED
- SCOPED_MUTEX_LOCK(unsafe_object_references_lock);
+ MutexLock lock(unsafe_object_references_lock);
ObjectID id = p_obj->get_instance_id();
unsafe_object_references[id]++;
#endif
@@ -641,7 +641,7 @@ void CSharpLanguage::post_unsafe_reference(Object *p_obj) {
void CSharpLanguage::pre_unsafe_unreference(Object *p_obj) {
#ifdef DEBUG_ENABLED
- SCOPED_MUTEX_LOCK(unsafe_object_references_lock);
+ MutexLock lock(unsafe_object_references_lock);
ObjectID id = p_obj->get_instance_id();
Map<ObjectID, int>::Element *elem = unsafe_object_references.find(id);
ERR_FAIL_NULL(elem);
@@ -764,7 +764,7 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) {
List<Ref<CSharpScript> > scripts;
{
- SCOPED_MUTEX_LOCK(script_instances_mutex);
+ MutexLock lock(script_instances_mutex);
for (SelfList<CSharpScript> *elem = script_list.first(); elem; elem = elem->next()) {
// Cast to CSharpScript to avoid being erased by accident
@@ -1204,7 +1204,7 @@ void CSharpLanguage::set_language_index(int p_idx) {
void CSharpLanguage::release_script_gchandle(Ref<MonoGCHandle> &p_gchandle) {
if (!p_gchandle->is_released()) { // Do not lock unnecessarily
- SCOPED_MUTEX_LOCK(get_singleton()->script_gchandle_release_mutex);
+ MutexLock lock(get_singleton()->script_gchandle_release_mutex);
p_gchandle->release();
}
}
@@ -1214,7 +1214,7 @@ void CSharpLanguage::release_script_gchandle(MonoObject *p_expected_obj, Ref<Mon
uint32_t pinned_gchandle = MonoGCHandle::new_strong_handle_pinned(p_expected_obj); // We might lock after this, so pin it
if (!p_gchandle->is_released()) { // Do not lock unnecessarily
- SCOPED_MUTEX_LOCK(get_singleton()->script_gchandle_release_mutex);
+ MutexLock lock(get_singleton()->script_gchandle_release_mutex);
MonoObject *target = p_gchandle->get_target();
@@ -1239,24 +1239,6 @@ CSharpLanguage::CSharpLanguage() {
gdmono = NULL;
-#ifdef NO_THREADS
- script_instances_mutex = NULL;
- script_gchandle_release_mutex = NULL;
- language_bind_mutex = NULL;
-#else
- script_instances_mutex = Mutex::create();
- script_gchandle_release_mutex = Mutex::create();
- language_bind_mutex = Mutex::create();
-#endif
-
-#ifdef DEBUG_ENABLED
-#ifdef NO_THREADS
- unsafe_object_references_lock = NULL;
-#else
- unsafe_object_references_lock = Mutex::create();
-#endif
-#endif
-
lang_idx = -1;
scripts_metadata_invalidated = true;
@@ -1269,29 +1251,6 @@ CSharpLanguage::CSharpLanguage() {
CSharpLanguage::~CSharpLanguage() {
finish();
-
- if (script_instances_mutex) {
- memdelete(script_instances_mutex);
- script_instances_mutex = NULL;
- }
-
- if (language_bind_mutex) {
- memdelete(language_bind_mutex);
- language_bind_mutex = NULL;
- }
-
- if (script_gchandle_release_mutex) {
- memdelete(script_gchandle_release_mutex);
- script_gchandle_release_mutex = NULL;
- }
-
-#ifdef DEBUG_ENABLED
- if (unsafe_object_references_lock) {
- memdelete(unsafe_object_references_lock);
- unsafe_object_references_lock = NULL;
- }
-#endif
-
singleton = NULL;
}
@@ -1346,7 +1305,7 @@ bool CSharpLanguage::setup_csharp_script_binding(CSharpScriptBinding &r_script_b
void *CSharpLanguage::alloc_instance_binding_data(Object *p_object) {
- SCOPED_MUTEX_LOCK(language_bind_mutex);
+ MutexLock lock(language_bind_mutex);
Map<Object *, CSharpScriptBinding>::Element *match = script_bindings.find(p_object);
if (match)
@@ -1381,7 +1340,7 @@ void CSharpLanguage::free_instance_binding_data(void *p_data) {
GD_MONO_ASSERT_THREAD_ATTACHED;
{
- SCOPED_MUTEX_LOCK(language_bind_mutex);
+ MutexLock lock(language_bind_mutex);
Map<Object *, CSharpScriptBinding>::Element *data = (Map<Object *, CSharpScriptBinding>::Element *)p_data;
@@ -2187,7 +2146,7 @@ CSharpInstance::~CSharpInstance() {
CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->get();
if (!script_binding.inited) {
- SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->get_language_bind_mutex());
+ MutexLock lock(CSharpLanguage::get_singleton()->get_language_bind_mutex());
if (!script_binding.inited) { // Other thread may have set it up
// Already had a binding that needs to be setup
@@ -2203,7 +2162,7 @@ CSharpInstance::~CSharpInstance() {
}
if (script.is_valid() && owner) {
- SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->script_instances_mutex);
+ MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex);
#ifdef DEBUG_ENABLED
// CSharpInstance must not be created unless it's going to be added to the list for sure
@@ -2979,7 +2938,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg
instance->_reference_owner_unsafe(); // Here, after assigning the gchandle (for the refcount_incremented callback)
{
- SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->script_instances_mutex);
+ MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex);
instances.insert(instance->owner);
}
@@ -3067,7 +3026,7 @@ PlaceHolderScriptInstance *CSharpScript::placeholder_instance_create(Object *p_t
bool CSharpScript::instance_has(const Object *p_this) const {
- SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->script_instances_mutex);
+ MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex);
return instances.has((Object *)p_this);
}
@@ -3140,7 +3099,7 @@ Error CSharpScript::reload(bool p_keep_state) {
bool has_instances;
{
- SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->script_instances_mutex);
+ MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex);
has_instances = instances.size();
}
@@ -3476,7 +3435,7 @@ CSharpScript::CSharpScript() :
#ifdef DEBUG_ENABLED
{
- SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->script_instances_mutex);
+ MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex);
CSharpLanguage::get_singleton()->script_list.add(&this->script_list);
}
#endif
@@ -3485,14 +3444,14 @@ CSharpScript::CSharpScript() :
CSharpScript::~CSharpScript() {
#ifdef DEBUG_ENABLED
- SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->script_instances_mutex);
+ MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex);
CSharpLanguage::get_singleton()->script_list.remove(&this->script_list);
#endif
}
/*************** RESOURCE ***************/
-RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
if (r_error)
*r_error = ERR_FILE_CANT_OPEN;
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index 627218eaf5..18c53aab52 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -325,16 +325,16 @@ class CSharpLanguage : public ScriptLanguage {
GDMono *gdmono;
SelfList<CSharpScript>::List script_list;
- Mutex *script_instances_mutex;
- Mutex *script_gchandle_release_mutex;
- Mutex *language_bind_mutex;
+ Mutex script_instances_mutex;
+ Mutex script_gchandle_release_mutex;
+ Mutex language_bind_mutex;
Map<Object *, CSharpScriptBinding> script_bindings;
#ifdef DEBUG_ENABLED
// List of unsafe object references
Map<ObjectID, int> unsafe_object_references;
- Mutex *unsafe_object_references_lock;
+ Mutex unsafe_object_references_lock;
#endif
struct StringNameCache {
@@ -376,7 +376,7 @@ class CSharpLanguage : public ScriptLanguage {
public:
StringNameCache string_names;
- Mutex *get_language_bind_mutex() { return language_bind_mutex; }
+ const Mutex &get_language_bind_mutex() { return language_bind_mutex; }
_FORCE_INLINE_ int get_language_index() { return lang_idx; }
void set_language_index(int p_idx);
@@ -497,7 +497,7 @@ public:
class ResourceFormatLoaderCSharpScript : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs b/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
index c3db52aa9e..af8d070cbd 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Build/MsBuildFinder.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using Godot;
+using GodotTools.Ides.Rider;
using GodotTools.Internals;
using Directory = System.IO.Directory;
using Environment = System.Environment;
@@ -54,6 +55,12 @@ namespace GodotTools.Build
return msbuildPath;
}
+ case BuildManager.BuildTool.JetBrainsMsBuild:
+ var editorPath = (string)editorSettings.GetSetting(RiderPathManager.EditorPathSettingName);
+ if (!File.Exists(editorPath))
+ throw new FileNotFoundException($"Cannot find Rider executable. Tried with path: {editorPath}");
+ var riderDir = new FileInfo(editorPath).Directory.Parent;
+ return Path.Combine(riderDir.FullName, @"tools\MSBuild\Current\Bin\MSBuild.exe");
default:
throw new IndexOutOfRangeException("Invalid build tool in editor settings");
}
diff --git a/modules/mono/editor/GodotTools/GodotTools/BuildManager.cs b/modules/mono/editor/GodotTools/GodotTools/BuildManager.cs
index fa6bf4dafd..69a8c9cf4a 100644
--- a/modules/mono/editor/GodotTools/GodotTools/BuildManager.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/BuildManager.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using GodotTools.Build;
+using GodotTools.Ides.Rider;
using GodotTools.Internals;
using GodotTools.Utils;
using static GodotTools.Internals.Globals;
@@ -16,6 +17,7 @@ namespace GodotTools
public const string PropNameMsbuildMono = "MSBuild (Mono)";
public const string PropNameMsbuildVs = "MSBuild (VS Build Tools)";
+ public const string PropNameMsbuildJetBrains = "MSBuild (JetBrains Rider)";
public const string MsBuildIssuesFileName = "msbuild_issues.csv";
public const string MsBuildLogFileName = "msbuild_log.txt";
@@ -23,7 +25,8 @@ namespace GodotTools
public enum BuildTool
{
MsBuildMono,
- MsBuildVs
+ MsBuildVs,
+ JetBrainsMsBuild
}
private static void RemoveOldIssuesFile(BuildInfo buildInfo)
@@ -181,7 +184,7 @@ namespace GodotTools
var buildInfo = new BuildInfo(GodotSharpDirs.ProjectSlnPath, config);
// Add Godot defines
- string constants = buildTool == BuildTool.MsBuildVs ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";
+ string constants = buildTool != BuildTool.MsBuildMono ? "GodotDefineConstants=\"" : "GodotDefineConstants=\\\"";
foreach (var godotDefine in godotDefines)
constants += $"GODOT_{godotDefine.ToUpper().Replace("-", "_").Replace(" ", "_").Replace(";", "_")};";
@@ -189,7 +192,7 @@ namespace GodotTools
if (Internal.GodotIsRealTDouble())
constants += "GODOT_REAL_T_IS_DOUBLE;";
- constants += buildTool == BuildTool.MsBuildVs ? "\"" : "\\\"";
+ constants += buildTool != BuildTool.MsBuildMono ? "\"" : "\\\"";
buildInfo.CustomProperties.Add(constants);
@@ -245,18 +248,22 @@ namespace GodotTools
public static void Initialize()
{
// Build tool settings
-
- EditorDef("mono/builds/build_tool", OS.IsWindows ? BuildTool.MsBuildVs : BuildTool.MsBuildMono);
-
var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
-
+ var msbuild = BuildTool.MsBuildMono;
+ if (OS.IsWindows)
+ msbuild = RiderPathManager.IsRider((string) editorSettings.GetSetting(RiderPathManager.EditorPathSettingName))
+ ? BuildTool.JetBrainsMsBuild
+ : BuildTool.MsBuildVs;
+
+ EditorDef("mono/builds/build_tool", msbuild);
+
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
{
["type"] = Godot.Variant.Type.Int,
["name"] = "mono/builds/build_tool",
["hint"] = Godot.PropertyHint.Enum,
["hint_string"] = OS.IsWindows ?
- $"{PropNameMsbuildMono},{PropNameMsbuildVs}" :
+ $"{PropNameMsbuildMono},{PropNameMsbuildVs},{PropNameMsbuildJetBrains}" :
$"{PropNameMsbuildMono}"
});
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs
index 9038333d38..5965e0fbcf 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathLocator.cs
@@ -11,6 +11,10 @@ using Environment = System.Environment;
using File = System.IO.File;
using Path = System.IO.Path;
using OS = GodotTools.Utils.OS;
+// ReSharper disable UnassignedField.Local
+// ReSharper disable InconsistentNaming
+// ReSharper disable UnassignedField.Global
+// ReSharper disable MemberHidesStaticFromOuterClass
namespace GodotTools.Ides.Rider
{
@@ -131,28 +135,45 @@ namespace GodotTools.Ides.Rider
if (OS.IsWindows)
{
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
- return Path.Combine(localAppData, @"JetBrains\Toolbox\apps\Rider");
+ return GetToolboxRiderRootPath(localAppData);
}
if (OS.IsOSX)
{
var home = Environment.GetEnvironmentVariable("HOME");
- if (!string.IsNullOrEmpty(home))
- {
- return Path.Combine(home, @"Library/Application Support/JetBrains/Toolbox/apps/Rider");
- }
+ if (string.IsNullOrEmpty(home))
+ return string.Empty;
+ var localAppData = Path.Combine(home, @"Library/Application Support");
+ return GetToolboxRiderRootPath(localAppData);
}
if (OS.IsUnixLike())
{
var home = Environment.GetEnvironmentVariable("HOME");
- if (!string.IsNullOrEmpty(home))
- {
- return Path.Combine(home, @".local/share/JetBrains/Toolbox/apps/Rider");
- }
+ if (string.IsNullOrEmpty(home))
+ return string.Empty;
+ var localAppData = Path.Combine(home, @".local/share");
+ return GetToolboxRiderRootPath(localAppData);
+ }
+
+ return string.Empty;
+ }
+
+
+ private static string GetToolboxRiderRootPath(string localAppData)
+ {
+ var toolboxPath = Path.Combine(localAppData, @"JetBrains\Toolbox");
+ var settingsJson = Path.Combine(toolboxPath, ".settings.json");
+
+ if (File.Exists(settingsJson))
+ {
+ var path = SettingsJson.GetInstallLocationFromJson(File.ReadAllText(settingsJson));
+ if (!string.IsNullOrEmpty(path))
+ toolboxPath = path;
}
- throw new Exception("Unexpected OS.");
+ var toolboxRiderRootPath = Path.Combine(toolboxPath, @"apps\Rider");
+ return toolboxRiderRootPath;
}
internal static ProductInfo GetBuildVersion(string path)
@@ -226,8 +247,8 @@ namespace GodotTools.Ides.Rider
{
try
{
- // use history.json - last entry stands for the active build https://jetbrains.slack.com/archives/C07KNP99D/p1547807024066500?thread_ts=1547731708.057700&cid=C07KNP99D
- var historyFile = Path.Combine(channelDir, ".history.json");
+ // use history.json - last entry stands for the active build https://jetbrains.slack.com/archives/C07KNP99D/p1547807024066500?thread_ts=1547731708.057700&cid=C07KNP99D
+ var historyFile = Path.Combine(channelDir, ".history.json");
if (File.Exists(historyFile))
{
var json = File.ReadAllText(historyFile);
@@ -255,14 +276,14 @@ namespace GodotTools.Ides.Rider
}
}
- // changes in toolbox json files format may brake the logic above, so return all found Rider installations
- return Directory.GetDirectories(channelDir)
- .SelectMany(buildDir => GetExecutablePaths(dirName, searchPattern, isMac, buildDir));
+ // changes in toolbox json files format may brake the logic above, so return all found Rider installations
+ return Directory.GetDirectories(channelDir)
+ .SelectMany(buildDir => GetExecutablePaths(dirName, searchPattern, isMac, buildDir));
}
catch (Exception e)
{
- // do not write to Debug.Log, just log it.
- Logger.Warn($"Failed to get RiderPath from {channelDir}", e);
+ // do not write to Debug.Log, just log it.
+ Logger.Warn($"Failed to get RiderPath from {channelDir}", e);
}
return new string[0];
@@ -289,6 +310,27 @@ namespace GodotTools.Ides.Rider
#pragma warning disable 0649
[Serializable]
+ class SettingsJson
+ {
+ public string install_location;
+
+ [CanBeNull]
+ public static string GetInstallLocationFromJson(string json)
+ {
+ try
+ {
+ return JsonConvert.DeserializeObject<SettingsJson>(json).install_location;
+ }
+ catch (Exception)
+ {
+ Logger.Warn($"Failed to get install_location from json {json}");
+ }
+
+ return null;
+ }
+ }
+
+ [Serializable]
class ToolboxHistory
{
public List<ItemNode> history;
@@ -372,7 +414,6 @@ namespace GodotTools.Ides.Rider
[Serializable]
class ActiveApplication
{
- // ReSharper disable once InconsistentNaming
public List<string> builds;
}
@@ -380,6 +421,7 @@ namespace GodotTools.Ides.Rider
public struct RiderInfo
{
+ // ReSharper disable once NotAccessedField.Global
public bool IsToolbox;
public string Presentation;
public Version BuildNumber;
diff --git a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
index 558a242bf9..ee5677a6a8 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Ides/Rider/RiderPathManager.cs
@@ -9,13 +9,13 @@ namespace GodotTools.Ides.Rider
{
public static class RiderPathManager
{
- private static readonly string editorPathSettingName = "mono/editor/editor_path_optional";
+ public static readonly string EditorPathSettingName = "mono/editor/editor_path_optional";
private static string GetRiderPathFromSettings()
{
var editorSettings = GodotSharpEditor.Instance.GetEditorInterface().GetEditorSettings();
- if (editorSettings.HasSetting(editorPathSettingName))
- return (string)editorSettings.GetSetting(editorPathSettingName);
+ if (editorSettings.HasSetting(EditorPathSettingName))
+ return (string)editorSettings.GetSetting(EditorPathSettingName);
return null;
}
@@ -25,22 +25,22 @@ namespace GodotTools.Ides.Rider
var editor = (ExternalEditorId)editorSettings.GetSetting("mono/editor/external_editor");
if (editor == ExternalEditorId.Rider)
{
- if (!editorSettings.HasSetting(editorPathSettingName))
+ if (!editorSettings.HasSetting(EditorPathSettingName))
{
- Globals.EditorDef(editorPathSettingName, "Optional");
+ Globals.EditorDef(EditorPathSettingName, "Optional");
editorSettings.AddPropertyInfo(new Godot.Collections.Dictionary
{
["type"] = Variant.Type.String,
- ["name"] = editorPathSettingName,
+ ["name"] = EditorPathSettingName,
["hint"] = PropertyHint.File,
["hint_string"] = ""
});
}
- var riderPath = (string)editorSettings.GetSetting(editorPathSettingName);
+ var riderPath = (string)editorSettings.GetSetting(EditorPathSettingName);
if (IsRiderAndExists(riderPath))
{
- Globals.EditorDef(editorPathSettingName, riderPath);
+ Globals.EditorDef(EditorPathSettingName, riderPath);
return;
}
@@ -50,17 +50,15 @@ namespace GodotTools.Ides.Rider
return;
var newPath = paths.Last().Path;
- Globals.EditorDef(editorPathSettingName, newPath);
- editorSettings.SetSetting(editorPathSettingName, newPath);
+ Globals.EditorDef(EditorPathSettingName, newPath);
+ editorSettings.SetSetting(EditorPathSettingName, newPath);
}
}
- private static bool IsRider(string path)
+ public static bool IsRider(string path)
{
if (string.IsNullOrEmpty(path))
- {
return false;
- }
var fileInfo = new FileInfo(path);
var filename = fileInfo.Name.ToLowerInvariant();
@@ -81,8 +79,8 @@ namespace GodotTools.Ides.Rider
return null;
var newPath = paths.Last().Path;
- editorSettings.SetSetting(editorPathSettingName, newPath);
- Globals.EditorDef(editorPathSettingName, newPath);
+ editorSettings.SetSetting(EditorPathSettingName, newPath);
+ Globals.EditorDef(EditorPathSettingName, newPath);
return newPath;
}
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 10595b4fcc..908c72c591 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -505,9 +505,9 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf
xml_output.append("</c>");
} else if (tag == "PackedByteArray") {
xml_output.append("<see cref=\"byte\"/>");
- } else if (tag == "PackedIntArray") {
+ } else if (tag == "PackedInt32Array") {
xml_output.append("<see cref=\"int\"/>");
- } else if (tag == "PackedRealArray") {
+ } else if (tag == "PackedFloat32Array") {
#ifdef REAL_T_IS_DOUBLE
xml_output.append("<see cref=\"double\"/>");
#else
@@ -2383,7 +2383,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
} else {
if (return_info.type == Variant::INT) {
imethod.return_type.cname = _get_int_type_name_from_meta(m ? m->get_argument_meta(-1) : GodotTypeInfo::METADATA_NONE);
- } else if (return_info.type == Variant::REAL) {
+ } else if (return_info.type == Variant::FLOAT) {
imethod.return_type.cname = _get_float_type_name_from_meta(m ? m->get_argument_meta(-1) : GodotTypeInfo::METADATA_NONE);
} else {
imethod.return_type.cname = Variant::get_type_name(return_info.type);
@@ -2410,7 +2410,7 @@ bool BindingsGenerator::_populate_object_type_interfaces() {
} else {
if (arginfo.type == Variant::INT) {
iarg.type.cname = _get_int_type_name_from_meta(m ? m->get_argument_meta(i) : GodotTypeInfo::METADATA_NONE);
- } else if (arginfo.type == Variant::REAL) {
+ } else if (arginfo.type == Variant::FLOAT) {
iarg.type.cname = _get_float_type_name_from_meta(m ? m->get_argument_meta(i) : GodotTypeInfo::METADATA_NONE);
} else {
iarg.type.cname = Variant::get_type_name(arginfo.type);
@@ -2581,7 +2581,7 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
r_iarg.default_argument = "(%s)" + r_iarg.default_argument;
}
break;
- case Variant::REAL:
+ case Variant::FLOAT:
#ifndef REAL_T_IS_DOUBLE
r_iarg.default_argument += "f";
#endif
@@ -2629,8 +2629,10 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar
break;
case Variant::ARRAY:
case Variant::PACKED_BYTE_ARRAY:
- case Variant::PACKED_INT_ARRAY:
- case Variant::PACKED_REAL_ARRAY:
+ case Variant::PACKED_INT32_ARRAY:
+ case Variant::PACKED_FLOAT32_ARRAY:
+ case Variant::PACKED_INT64_ARRAY:
+ case Variant::PACKED_FLOAT64_ARRAY:
case Variant::PACKED_STRING_ARRAY:
case Variant::PACKED_VECTOR2_ARRAY:
case Variant::PACKED_VECTOR3_ARRAY:
@@ -2914,13 +2916,13 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
#define INSERT_ARRAY(m_type, m_proxy_t) INSERT_ARRAY_FULL(m_type, m_type, m_proxy_t)
- INSERT_ARRAY(PackedIntArray, int);
+ INSERT_ARRAY(PackedInt32Array, int);
INSERT_ARRAY_FULL(PackedByteArray, PackedByteArray, byte);
#ifdef REAL_T_IS_DOUBLE
- INSERT_ARRAY(PackedRealArray, double);
+ INSERT_ARRAY(PackedFloat32Array, double);
#else
- INSERT_ARRAY(PackedRealArray, float);
+ INSERT_ARRAY(PackedFloat32Array, float);
#endif
INSERT_ARRAY(PackedStringArray, string);
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs
index 19962d418a..2a9c2d73b1 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs
@@ -83,7 +83,7 @@ namespace Godot
public static void Print(params object[] what)
{
- godot_icall_GD_print(Array.ConvertAll(what, x => x.ToString()));
+ godot_icall_GD_print(Array.ConvertAll(what, x => x?.ToString()));
}
public static void PrintStack()
diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp
index 21d78483ee..03b56c9949 100644
--- a/modules/mono/mono_gd/gd_mono_field.cpp
+++ b/modules/mono/mono_gd/gd_mono_field.cpp
@@ -252,12 +252,12 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_
}
if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) {
- SET_FROM_ARRAY(PackedIntArray);
+ SET_FROM_ARRAY(PackedInt32Array);
break;
}
if (array_type->eklass == REAL_T_MONOCLASS) {
- SET_FROM_ARRAY(PackedRealArray);
+ SET_FROM_ARRAY(PackedFloat32Array);
break;
}
@@ -370,7 +370,7 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_
int32_t val = p_value.operator signed int();
mono_field_set_value(p_object, mono_field, &val);
} break;
- case Variant::REAL: {
+ case Variant::FLOAT: {
#ifdef REAL_T_IS_DOUBLE
double val = p_value.operator double();
mono_field_set_value(p_object, mono_field, &val);
@@ -437,11 +437,11 @@ void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_
case Variant::PACKED_BYTE_ARRAY: {
SET_FROM_ARRAY(PackedByteArray);
} break;
- case Variant::PACKED_INT_ARRAY: {
- SET_FROM_ARRAY(PackedIntArray);
+ case Variant::PACKED_INT32_ARRAY: {
+ SET_FROM_ARRAY(PackedInt32Array);
} break;
- case Variant::PACKED_REAL_ARRAY: {
- SET_FROM_ARRAY(PackedRealArray);
+ case Variant::PACKED_FLOAT32_ARRAY: {
+ SET_FROM_ARRAY(PackedFloat32Array);
} break;
case Variant::PACKED_STRING_ARRAY: {
SET_FROM_ARRAY(PackedStringArray);
diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp
index 63890f6066..695be64d6e 100644
--- a/modules/mono/mono_gd/gd_mono_marshal.cpp
+++ b/modules/mono/mono_gd/gd_mono_marshal.cpp
@@ -60,9 +60,9 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type) {
return Variant::INT;
case MONO_TYPE_R4:
- return Variant::REAL;
+ return Variant::FLOAT;
case MONO_TYPE_R8:
- return Variant::REAL;
+ return Variant::FLOAT;
case MONO_TYPE_STRING: {
return Variant::STRING;
@@ -116,10 +116,10 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type) {
return Variant::PACKED_BYTE_ARRAY;
if (array_type->eklass == CACHED_CLASS_RAW(int32_t))
- return Variant::PACKED_INT_ARRAY;
+ return Variant::PACKED_INT32_ARRAY;
if (array_type->eklass == REAL_T_MONOCLASS)
- return Variant::PACKED_REAL_ARRAY;
+ return Variant::PACKED_FLOAT32_ARRAY;
if (array_type->eklass == CACHED_CLASS_RAW(String))
return Variant::PACKED_STRING_ARRAY;
@@ -494,10 +494,10 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
return (MonoObject *)PackedByteArray_to_mono_array(p_var->operator PackedByteArray());
if (array_type->eklass == CACHED_CLASS_RAW(int32_t))
- return (MonoObject *)PackedIntArray_to_mono_array(p_var->operator PackedIntArray());
+ return (MonoObject *)PackedInt32Array_to_mono_array(p_var->operator PackedInt32Array());
if (array_type->eklass == REAL_T_MONOCLASS)
- return (MonoObject *)PackedRealArray_to_mono_array(p_var->operator PackedRealArray());
+ return (MonoObject *)PackedFloat32Array_to_mono_array(p_var->operator PackedFloat32Array());
if (array_type->eklass == CACHED_CLASS_RAW(String))
return (MonoObject *)PackedStringArray_to_mono_array(p_var->operator PackedStringArray());
@@ -577,7 +577,7 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
int32_t val = p_var->operator signed int();
return BOX_INT32(val);
}
- case Variant::REAL: {
+ case Variant::FLOAT: {
#ifdef REAL_T_IS_DOUBLE
double val = p_var->operator double();
return BOX_DOUBLE(val);
@@ -640,10 +640,10 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
return GDMonoUtils::create_managed_from(p_var->operator Array(), CACHED_CLASS(Array));
case Variant::PACKED_BYTE_ARRAY:
return (MonoObject *)PackedByteArray_to_mono_array(p_var->operator PackedByteArray());
- case Variant::PACKED_INT_ARRAY:
- return (MonoObject *)PackedIntArray_to_mono_array(p_var->operator PackedIntArray());
- case Variant::PACKED_REAL_ARRAY:
- return (MonoObject *)PackedRealArray_to_mono_array(p_var->operator PackedRealArray());
+ case Variant::PACKED_INT32_ARRAY:
+ return (MonoObject *)PackedInt32Array_to_mono_array(p_var->operator PackedInt32Array());
+ case Variant::PACKED_FLOAT32_ARRAY:
+ return (MonoObject *)PackedFloat32Array_to_mono_array(p_var->operator PackedFloat32Array());
case Variant::PACKED_STRING_ARRAY:
return (MonoObject *)PackedStringArray_to_mono_array(p_var->operator PackedStringArray());
case Variant::PACKED_VECTOR2_ARRAY:
@@ -788,10 +788,10 @@ Variant mono_object_to_variant_impl(MonoObject *p_obj, const ManagedType &p_type
return mono_array_to_PackedByteArray((MonoArray *)p_obj);
if (array_type->eklass == CACHED_CLASS_RAW(int32_t))
- return mono_array_to_PackedIntArray((MonoArray *)p_obj);
+ return mono_array_to_PackedInt32Array((MonoArray *)p_obj);
if (array_type->eklass == REAL_T_MONOCLASS)
- return mono_array_to_PackedRealArray((MonoArray *)p_obj);
+ return mono_array_to_PackedFloat32Array((MonoArray *)p_obj);
if (array_type->eklass == CACHED_CLASS_RAW(String))
return mono_array_to_PackedStringArray((MonoArray *)p_obj);
@@ -987,7 +987,7 @@ Array mono_array_to_Array(MonoArray *p_array) {
// TODO: Use memcpy where possible
-MonoArray *PackedIntArray_to_mono_array(const PackedIntArray &p_array) {
+MonoArray *PackedInt32Array_to_mono_array(const PackedInt32Array &p_array) {
const int *r = p_array.ptr();
MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(int32_t), p_array.size());
@@ -999,8 +999,8 @@ MonoArray *PackedIntArray_to_mono_array(const PackedIntArray &p_array) {
return ret;
}
-PackedIntArray mono_array_to_PackedIntArray(MonoArray *p_array) {
- PackedIntArray ret;
+PackedInt32Array mono_array_to_PackedInt32Array(MonoArray *p_array) {
+ PackedInt32Array ret;
if (!p_array)
return ret;
int length = mono_array_length(p_array);
@@ -1041,7 +1041,7 @@ PackedByteArray mono_array_to_PackedByteArray(MonoArray *p_array) {
return ret;
}
-MonoArray *PackedRealArray_to_mono_array(const PackedRealArray &p_array) {
+MonoArray *PackedFloat32Array_to_mono_array(const PackedFloat32Array &p_array) {
const real_t *r = p_array.ptr();
MonoArray *ret = mono_array_new(mono_domain_get(), REAL_T_MONOCLASS, p_array.size());
@@ -1053,8 +1053,8 @@ MonoArray *PackedRealArray_to_mono_array(const PackedRealArray &p_array) {
return ret;
}
-PackedRealArray mono_array_to_PackedRealArray(MonoArray *p_array) {
- PackedRealArray ret;
+PackedFloat32Array mono_array_to_PackedFloat32Array(MonoArray *p_array) {
+ PackedFloat32Array ret;
if (!p_array)
return ret;
int length = mono_array_length(p_array);
diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h
index d3527109ff..5db59522ce 100644
--- a/modules/mono/mono_gd/gd_mono_marshal.h
+++ b/modules/mono/mono_gd/gd_mono_marshal.h
@@ -127,20 +127,20 @@ String mono_object_to_variant_string(MonoObject *p_obj, MonoException **r_exc);
MonoArray *Array_to_mono_array(const Array &p_array);
Array mono_array_to_Array(MonoArray *p_array);
-// PackedIntArray
+// PackedInt32Array
-MonoArray *PackedIntArray_to_mono_array(const PackedIntArray &p_array);
-PackedIntArray mono_array_to_PackedIntArray(MonoArray *p_array);
+MonoArray *PackedInt32Array_to_mono_array(const PackedInt32Array &p_array);
+PackedInt32Array mono_array_to_PackedInt32Array(MonoArray *p_array);
// PackedByteArray
MonoArray *PackedByteArray_to_mono_array(const PackedByteArray &p_array);
PackedByteArray mono_array_to_PackedByteArray(MonoArray *p_array);
-// PackedRealArray
+// PackedFloat32Array
-MonoArray *PackedRealArray_to_mono_array(const PackedRealArray &p_array);
-PackedRealArray mono_array_to_PackedRealArray(MonoArray *p_array);
+MonoArray *PackedFloat32Array_to_mono_array(const PackedFloat32Array &p_array);
+PackedFloat32Array mono_array_to_PackedFloat32Array(MonoArray *p_array);
// PackedStringArray
diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp
index ae6625a6c6..41f49d8ac9 100644
--- a/modules/mono/mono_gd/gd_mono_utils.cpp
+++ b/modules/mono/mono_gd/gd_mono_utils.cpp
@@ -33,6 +33,7 @@
#include <mono/metadata/exception.h>
#include "core/os/dir_access.h"
+#include "core/os/mutex.h"
#include "core/os/os.h"
#include "core/project_settings.h"
#include "core/reference.h"
@@ -43,7 +44,6 @@
#include "../csharp_script.h"
#include "../utils/macros.h"
-#include "../utils/mutex_utils.h"
#include "gd_mono.h"
#include "gd_mono_cache.h"
#include "gd_mono_class.h"
@@ -74,7 +74,7 @@ MonoObject *unmanaged_get_managed(Object *unmanaged) {
CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->value();
if (!script_binding.inited) {
- SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->get_language_bind_mutex());
+ MutexLock lock(CSharpLanguage::get_singleton()->get_language_bind_mutex());
if (!script_binding.inited) { // Other thread may have set it up
// Already had a binding that needs to be setup
diff --git a/modules/mono/utils/mutex_utils.h b/modules/mono/utils/mutex_utils.h
deleted file mode 100644
index bafd875395..0000000000
--- a/modules/mono/utils/mutex_utils.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*************************************************************************/
-/* mutex_utils.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef MUTEX_UTILS_H
-#define MUTEX_UTILS_H
-
-#include "core/error_macros.h"
-#include "core/os/mutex.h"
-
-#include "macros.h"
-
-class ScopedMutexLock {
- Mutex *mutex;
-
-public:
- ScopedMutexLock(Mutex *mutex) {
- this->mutex = mutex;
-#ifndef NO_THREADS
-#ifdef DEBUG_ENABLED
- CRASH_COND(!mutex);
-#endif
- this->mutex->lock();
-#endif
- }
-
- ~ScopedMutexLock() {
-#ifndef NO_THREADS
-#ifdef DEBUG_ENABLED
- CRASH_COND(!mutex);
-#endif
- mutex->unlock();
-#endif
- }
-};
-
-#define SCOPED_MUTEX_LOCK(m_mutex) ScopedMutexLock GD_UNIQUE_NAME(__scoped_mutex_lock__)(m_mutex);
-
-// TODO: Add version that receives a lambda instead, once C++11 is allowed
-
-#endif // MUTEX_UTILS_H
diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp
index 35f0fb7ac0..8e5b04f995 100644
--- a/modules/opensimplex/noise_texture.cpp
+++ b/modules/opensimplex/noise_texture.cpp
@@ -76,7 +76,6 @@ void NoiseTexture::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bump_strength"), &NoiseTexture::get_bump_strength);
ClassDB::bind_method(D_METHOD("_update_texture"), &NoiseTexture::_update_texture);
- ClassDB::bind_method(D_METHOD("_queue_update"), &NoiseTexture::_queue_update);
ClassDB::bind_method(D_METHOD("_generate_texture"), &NoiseTexture::_generate_texture);
ClassDB::bind_method(D_METHOD("_thread_done", "image"), &NoiseTexture::_thread_done);
@@ -84,7 +83,7 @@ void NoiseTexture::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "height", PROPERTY_HINT_RANGE, "1,2048,1,or_greater"), "set_height", "get_height");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "seamless"), "set_seamless", "get_seamless");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "as_normalmap"), "set_as_normalmap", "is_normalmap");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "bump_strength", PROPERTY_HINT_RANGE, "0,32,0.1,or_greater"), "set_bump_strength", "get_bump_strength");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bump_strength", PROPERTY_HINT_RANGE, "0,32,0.1,or_greater"), "set_bump_strength", "get_bump_strength");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "noise", PROPERTY_HINT_RESOURCE_TYPE, "OpenSimplexNoise"), "set_noise", "get_noise");
}
@@ -184,11 +183,11 @@ void NoiseTexture::set_noise(Ref<OpenSimplexNoise> p_noise) {
if (p_noise == noise)
return;
if (noise.is_valid()) {
- noise->disconnect_compat(CoreStringNames::get_singleton()->changed, this, "_queue_update");
+ noise->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &NoiseTexture::_queue_update));
}
noise = p_noise;
if (noise.is_valid()) {
- noise->connect_compat(CoreStringNames::get_singleton()->changed, this, "_queue_update");
+ noise->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &NoiseTexture::_queue_update));
}
_queue_update();
}
diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp
index bd2dbd74a8..238faa4130 100644
--- a/modules/opensimplex/open_simplex_noise.cpp
+++ b/modules/opensimplex/open_simplex_noise.cpp
@@ -186,9 +186,9 @@ void OpenSimplexNoise::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "seed"), "set_seed", "get_seed");
ADD_PROPERTY(PropertyInfo(Variant::INT, "octaves", PROPERTY_HINT_RANGE, vformat("1,%d,1", MAX_OCTAVES)), "set_octaves", "get_octaves");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "period", PROPERTY_HINT_RANGE, "0.1,256.0,0.1"), "set_period", "get_period");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "persistence", PROPERTY_HINT_RANGE, "0.0,1.0,0.001"), "set_persistence", "get_persistence");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "lacunarity", PROPERTY_HINT_RANGE, "0.1,4.0,0.01"), "set_lacunarity", "get_lacunarity");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "period", PROPERTY_HINT_RANGE, "0.1,256.0,0.1"), "set_period", "get_period");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "persistence", PROPERTY_HINT_RANGE, "0.0,1.0,0.001"), "set_persistence", "get_persistence");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lacunarity", PROPERTY_HINT_RANGE, "0.1,4.0,0.01"), "set_lacunarity", "get_lacunarity");
}
float OpenSimplexNoise::get_noise_1d(float x) {
diff --git a/modules/opus/audio_stream_opus.cpp b/modules/opus/audio_stream_opus.cpp
index 67a07628d9..a983edee91 100644
--- a/modules/opus/audio_stream_opus.cpp
+++ b/modules/opus/audio_stream_opus.cpp
@@ -354,7 +354,7 @@ AudioStreamPlaybackOpus::~AudioStreamPlaybackOpus() {
_clear_stream();
}
-RES ResourceFormatLoaderAudioStreamOpus::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderAudioStreamOpus::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
if (r_error)
*r_error = OK;
diff --git a/modules/opus/audio_stream_opus.h b/modules/opus/audio_stream_opus.h
index 5c0a02a9d0..343cbc6b83 100644
--- a/modules/opus/audio_stream_opus.h
+++ b/modules/opus/audio_stream_opus.h
@@ -133,7 +133,7 @@ public:
class ResourceFormatLoaderAudioStreamOpus : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp
index dab4f64393..179c6f692b 100644
--- a/modules/pvr/texture_loader_pvr.cpp
+++ b/modules/pvr/texture_loader_pvr.cpp
@@ -51,7 +51,7 @@ enum PVRFLags {
};
-RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
if (r_error)
*r_error = ERR_CANT_OPEN;
diff --git a/modules/pvr/texture_loader_pvr.h b/modules/pvr/texture_loader_pvr.h
index e384ed2b4c..c990c3612b 100644
--- a/modules/pvr/texture_loader_pvr.h
+++ b/modules/pvr/texture_loader_pvr.h
@@ -36,7 +36,7 @@
class ResourceFormatPVR : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/regex/doc_classes/RegEx.xml b/modules/regex/doc_classes/RegEx.xml
index e9f46b9853..3130c53331 100644
--- a/modules/regex/doc_classes/RegEx.xml
+++ b/modules/regex/doc_classes/RegEx.xml
@@ -10,7 +10,7 @@
var regex = RegEx.new()
regex.compile("\\w-(\\d+)")
[/codeblock]
- The search pattern must be escaped first for gdscript before it is escaped for the expression. For example, [code]compile("\\d+")[/code] would be read by RegEx as [code]\d+[/code]. Similarly, [code]compile("\"(?:\\\\.|[^\"])*\"")[/code] would be read as [code]"(?:\\.|[^"])*"[/code].
+ The search pattern must be escaped first for GDScript before it is escaped for the expression. For example, [code]compile("\\d+")[/code] would be read by RegEx as [code]\d+[/code]. Similarly, [code]compile("\"(?:\\\\.|[^\"])*\"")[/code] would be read as [code]"(?:\\.|[^"])*"[/code].
Using [method search] you can find the pattern within the given text. If a pattern is found, [RegExMatch] is returned and you can retrieve details of the results using functions such as [method RegExMatch.get_string] and [method RegExMatch.get_start].
[codeblock]
var regex = RegEx.new()
@@ -35,6 +35,8 @@
# Would print 01 03 3f 42
# Note that d0c would not match
[/codeblock]
+ [b]Note:[/b] Godot's regex implementation is based on the [url=https://www.pcre.org/]PCRE2[/url] library. You can view the full pattern reference [url=https://www.pcre.org/current/doc/html/pcre2pattern.html]here[/url].
+ [b]Tip:[/b] You can use [url=https://regexr.com/]Regexr[/url] to test regular expressions online.
</description>
<tutorials>
</tutorials>
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
index 6224db90e7..42f341cef7 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
@@ -57,7 +57,8 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra
if (todo) {
//end of file!
- if (vorbis_stream->loop && mixed > 0) {
+ bool is_not_empty = mixed > 0 || stb_vorbis_stream_length_in_samples(ogg_stream) > 0;
+ if (vorbis_stream->loop && is_not_empty) {
//loop
seek(vorbis_stream->loop_offset);
loops++;
@@ -267,7 +268,7 @@ void AudioStreamOGGVorbis::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_data", "get_data");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "loop"), "set_loop", "has_loop");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "loop_offset"), "set_loop_offset", "get_loop_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "loop_offset"), "set_loop_offset", "get_loop_offset");
}
AudioStreamOGGVorbis::AudioStreamOGGVorbis() {
diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
index ec89f2ac76..13d96541e3 100644
--- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp
@@ -73,7 +73,7 @@ String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const {
void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options, int p_preset) const {
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true));
- r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "loop_offset"), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "loop_offset"), 0));
}
Error ResourceImporterOGGVorbis::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, Variant *r_metadata) {
diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp
index a44ed0304d..ee44c6bf05 100644
--- a/modules/theora/video_stream_theora.cpp
+++ b/modules/theora/video_stream_theora.cpp
@@ -725,7 +725,7 @@ void VideoStreamTheora::_bind_methods() {
////////////
-RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h
index 258b3a1cce..da3558ce34 100644
--- a/modules/theora/video_stream_theora.h
+++ b/modules/theora/video_stream_theora.h
@@ -187,7 +187,7 @@ public:
class ResourceFormatLoaderTheora : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/upnp/doc_classes/UPNP.xml b/modules/upnp/doc_classes/UPNP.xml
index 8549c173db..785c8dad50 100644
--- a/modules/upnp/doc_classes/UPNP.xml
+++ b/modules/upnp/doc_classes/UPNP.xml
@@ -45,7 +45,7 @@
<description>
Adds a mapping to forward the external [code]port[/code] (between 1 and 65535) on the default gateway (see [method get_gateway]) to the [code]internal_port[/code] on the local machine for the given protocol [code]proto[/code] (either [code]TCP[/code] or [code]UDP[/code], with UDP being the default). If a port mapping for the given port and protocol combination already exists on that gateway device, this method tries to overwrite it. If that is not desired, you can retrieve the gateway manually with [method get_gateway] and call [method add_port_mapping] on it, if any.
If [code]internal_port[/code] is [code]0[/code] (the default), the same port number is used for both the external and the internal port (the [code]port[/code] value).
- The description ([code]desc[/code]) is shown in some router UIs and can be used to point out which application added the mapping, and the lifetime of the mapping can be limited by [code]duration[/code]. However, some routers are incompatible with one or both of these, so use with caution and add fallback logic in case of errors to retry without them if in doubt.
+ The description ([code]desc[/code]) is shown in some router UIs and can be used to point out which application added the mapping. The mapping's lease duration can be limited by specifying a [code]duration[/code] (in seconds). However, some routers are incompatible with one or both of these, so use with caution and add fallback logic in case of errors to retry without them if in doubt.
See [enum UPNPResult] for possible return values.
</description>
</method>
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp
index 70f650cfd3..471f43cadd 100644
--- a/modules/visual_script/visual_script.cpp
+++ b/modules/visual_script/visual_script.cpp
@@ -30,14 +30,14 @@
#include "visual_script.h"
-#include <stdint.h>
-
#include "core/core_string_names.h"
#include "core/os/os.h"
#include "core/project_settings.h"
#include "scene/main/node.h"
#include "visual_script_nodes.h"
+#include <stdint.h>
+
//used by editor, this is not really saved
void VisualScriptNode::set_breakpoint(bool p_breakpoint) {
breakpoint = p_breakpoint;
@@ -198,7 +198,7 @@ void VisualScript::remove_function(const StringName &p_name) {
for (Map<int, Function::NodeData>::Element *E = functions[p_name].nodes.front(); E; E = E->next()) {
- E->get().node->disconnect_compat("ports_changed", this, "_node_ports_changed");
+ E->get().node->disconnect("ports_changed", callable_mp(this, &VisualScript::_node_ports_changed));
E->get().node->scripts_used.erase(this);
}
@@ -340,7 +340,7 @@ void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<Visual
nd.pos = p_pos;
Ref<VisualScriptNode> vsn = p_node;
- vsn->connect_compat("ports_changed", this, "_node_ports_changed", varray(p_id));
+ vsn->connect("ports_changed", callable_mp(this, &VisualScript::_node_ports_changed), varray(p_id));
vsn->scripts_used.insert(this);
vsn->validate_input_default_values(); // Validate when fully loaded
@@ -389,7 +389,7 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) {
func.function_id = -1; //revert to invalid
}
- func.nodes[p_id].node->disconnect_compat("ports_changed", this, "_node_ports_changed");
+ func.nodes[p_id].node->disconnect("ports_changed", callable_mp(this, &VisualScript::_node_ports_changed));
func.nodes[p_id].node->scripts_used.erase(this);
func.nodes.erase(p_id);
@@ -928,13 +928,11 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) {
VisualScriptInstance *instance = memnew(VisualScriptInstance);
instance->create(Ref<VisualScript>(this), p_this);
- if (VisualScriptLanguage::singleton->lock)
- VisualScriptLanguage::singleton->lock->lock();
-
- instances[p_this] = instance;
+ {
+ MutexLock lock(VisualScriptLanguage::singleton->lock);
- if (VisualScriptLanguage::singleton->lock)
- VisualScriptLanguage::singleton->lock->unlock();
+ instances[p_this] = instance;
+ }
return instance;
}
@@ -1375,8 +1373,6 @@ Dictionary VisualScript::_get_data() const {
void VisualScript::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_node_ports_changed"), &VisualScript::_node_ports_changed);
-
ClassDB::bind_method(D_METHOD("add_function", "name"), &VisualScript::add_function);
ClassDB::bind_method(D_METHOD("has_function", "name"), &VisualScript::has_function);
ClassDB::bind_method(D_METHOD("remove_function", "name"), &VisualScript::remove_function);
@@ -2391,13 +2387,11 @@ VisualScriptInstance::VisualScriptInstance() {
VisualScriptInstance::~VisualScriptInstance() {
- if (VisualScriptLanguage::singleton->lock)
- VisualScriptLanguage::singleton->lock->lock();
-
- script->instances.erase(owner);
+ {
+ MutexLock lock(VisualScriptLanguage::singleton->lock);
- if (VisualScriptLanguage::singleton->lock)
- VisualScriptLanguage::singleton->lock->unlock();
+ script->instances.erase(owner);
+ }
for (Map<int, VisualScriptNodeInstance *>::Element *E = instances.front(); E; E = E->next()) {
memdelete(E->get());
@@ -2836,9 +2830,6 @@ VisualScriptLanguage::VisualScriptLanguage() {
_step = "_step";
_subcall = "_subcall";
singleton = this;
-#ifndef NO_THREADS
- lock = Mutex::create();
-#endif
_debug_parse_err_node = -1;
_debug_parse_err_file = "";
@@ -2859,9 +2850,6 @@ VisualScriptLanguage::VisualScriptLanguage() {
VisualScriptLanguage::~VisualScriptLanguage() {
- if (lock)
- memdelete(lock);
-
if (_call_stack) {
memdelete_arr(_call_stack);
}
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index 08b84bce1d..0a6daba64f 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -530,7 +530,7 @@ public:
static VisualScriptLanguage *singleton;
- Mutex *lock;
+ Mutex lock;
bool debug_break(const String &p_error, bool p_allow_continue = true);
bool debug_break_parse(const String &p_file, int p_node, const String &p_error);
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp
index 3fd2b474bb..07f152efd4 100644
--- a/modules/visual_script/visual_script_builtin_funcs.cpp
+++ b/modules/visual_script/visual_script_builtin_funcs.cpp
@@ -277,22 +277,22 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case MATH_EXP:
case MATH_ISNAN:
case MATH_ISINF: {
- return PropertyInfo(Variant::REAL, "s");
+ return PropertyInfo(Variant::FLOAT, "s");
} break;
case MATH_ATAN2: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "y");
+ return PropertyInfo(Variant::FLOAT, "y");
else
- return PropertyInfo(Variant::REAL, "x");
+ return PropertyInfo(Variant::FLOAT, "x");
} break;
case MATH_FMOD:
case MATH_FPOSMOD:
case LOGIC_MAX:
case LOGIC_MIN: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "a");
+ return PropertyInfo(Variant::FLOAT, "a");
else
- return PropertyInfo(Variant::REAL, "b");
+ return PropertyInfo(Variant::FLOAT, "b");
} break;
case MATH_POSMOD: {
if (p_idx == 0)
@@ -302,63 +302,63 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
} break;
case MATH_POW: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "base");
+ return PropertyInfo(Variant::FLOAT, "base");
else
- return PropertyInfo(Variant::REAL, "exp");
+ return PropertyInfo(Variant::FLOAT, "exp");
} break;
case MATH_EASE: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "s");
+ return PropertyInfo(Variant::FLOAT, "s");
else
- return PropertyInfo(Variant::REAL, "curve");
+ return PropertyInfo(Variant::FLOAT, "curve");
} break;
case MATH_STEP_DECIMALS: {
- return PropertyInfo(Variant::REAL, "step");
+ return PropertyInfo(Variant::FLOAT, "step");
} break;
case MATH_STEPIFY: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "s");
+ return PropertyInfo(Variant::FLOAT, "s");
else
- return PropertyInfo(Variant::REAL, "steps");
+ return PropertyInfo(Variant::FLOAT, "steps");
} break;
case MATH_LERP:
case MATH_LERP_ANGLE:
case MATH_INVERSE_LERP:
case MATH_SMOOTHSTEP: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "from");
+ return PropertyInfo(Variant::FLOAT, "from");
else if (p_idx == 1)
- return PropertyInfo(Variant::REAL, "to");
+ return PropertyInfo(Variant::FLOAT, "to");
else
- return PropertyInfo(Variant::REAL, "weight");
+ return PropertyInfo(Variant::FLOAT, "weight");
} break;
case MATH_RANGE_LERP: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "value");
+ return PropertyInfo(Variant::FLOAT, "value");
else if (p_idx == 1)
- return PropertyInfo(Variant::REAL, "istart");
+ return PropertyInfo(Variant::FLOAT, "istart");
else if (p_idx == 2)
- return PropertyInfo(Variant::REAL, "istop");
+ return PropertyInfo(Variant::FLOAT, "istop");
else if (p_idx == 3)
- return PropertyInfo(Variant::REAL, "ostart");
+ return PropertyInfo(Variant::FLOAT, "ostart");
else
- return PropertyInfo(Variant::REAL, "ostop");
+ return PropertyInfo(Variant::FLOAT, "ostop");
} break;
case MATH_MOVE_TOWARD: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "from");
+ return PropertyInfo(Variant::FLOAT, "from");
else if (p_idx == 1)
- return PropertyInfo(Variant::REAL, "to");
+ return PropertyInfo(Variant::FLOAT, "to");
else
- return PropertyInfo(Variant::REAL, "delta");
+ return PropertyInfo(Variant::FLOAT, "delta");
} break;
case MATH_DECTIME: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "value");
+ return PropertyInfo(Variant::FLOAT, "value");
else if (p_idx == 1)
- return PropertyInfo(Variant::REAL, "amount");
+ return PropertyInfo(Variant::FLOAT, "amount");
else
- return PropertyInfo(Variant::REAL, "step");
+ return PropertyInfo(Variant::FLOAT, "step");
} break;
case MATH_RANDOMIZE:
case MATH_RAND:
@@ -367,37 +367,37 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
} break;
case MATH_RANDOM: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "from");
+ return PropertyInfo(Variant::FLOAT, "from");
else
- return PropertyInfo(Variant::REAL, "to");
+ return PropertyInfo(Variant::FLOAT, "to");
} break;
case MATH_SEED:
case MATH_RANDSEED: {
return PropertyInfo(Variant::INT, "seed");
} break;
case MATH_DEG2RAD: {
- return PropertyInfo(Variant::REAL, "deg");
+ return PropertyInfo(Variant::FLOAT, "deg");
} break;
case MATH_RAD2DEG: {
- return PropertyInfo(Variant::REAL, "rad");
+ return PropertyInfo(Variant::FLOAT, "rad");
} break;
case MATH_LINEAR2DB: {
- return PropertyInfo(Variant::REAL, "nrg");
+ return PropertyInfo(Variant::FLOAT, "nrg");
} break;
case MATH_DB2LINEAR: {
- return PropertyInfo(Variant::REAL, "db");
+ return PropertyInfo(Variant::FLOAT, "db");
} break;
case MATH_POLAR2CARTESIAN: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "r");
+ return PropertyInfo(Variant::FLOAT, "r");
else
- return PropertyInfo(Variant::REAL, "th");
+ return PropertyInfo(Variant::FLOAT, "th");
} break;
case MATH_CARTESIAN2POLAR: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "x");
+ return PropertyInfo(Variant::FLOAT, "x");
else
- return PropertyInfo(Variant::REAL, "y");
+ return PropertyInfo(Variant::FLOAT, "y");
} break;
case MATH_WRAP: {
if (p_idx == 0)
@@ -410,11 +410,11 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case MATH_WRAPF:
case LOGIC_CLAMP: {
if (p_idx == 0)
- return PropertyInfo(Variant::REAL, "value");
+ return PropertyInfo(Variant::FLOAT, "value");
else if (p_idx == 1)
- return PropertyInfo(Variant::REAL, "min");
+ return PropertyInfo(Variant::FLOAT, "min");
else
- return PropertyInfo(Variant::REAL, "max");
+ return PropertyInfo(Variant::FLOAT, "max");
} break;
case LOGIC_NEAREST_PO2: {
return PropertyInfo(Variant::INT, "value");
@@ -475,7 +475,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
if (p_idx == 0)
return PropertyInfo(Variant::STRING, "name");
else
- return PropertyInfo(Variant::REAL, "alpha");
+ return PropertyInfo(Variant::FLOAT, "alpha");
} break;
case FUNC_MAX: {
}
@@ -504,7 +504,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_FPOSMOD:
case MATH_FLOOR:
case MATH_CEIL: {
- t = Variant::REAL;
+ t = Variant::FLOAT;
} break;
case MATH_POSMOD:
case MATH_ROUND: {
@@ -519,14 +519,14 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_POW:
case MATH_LOG:
case MATH_EXP: {
- t = Variant::REAL;
+ t = Variant::FLOAT;
} break;
case MATH_ISNAN:
case MATH_ISINF: {
t = Variant::BOOL;
} break;
case MATH_EASE: {
- t = Variant::REAL;
+ t = Variant::FLOAT;
} break;
case MATH_STEP_DECIMALS: {
t = Variant::INT;
@@ -539,7 +539,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_SMOOTHSTEP:
case MATH_MOVE_TOWARD:
case MATH_DECTIME: {
- t = Variant::REAL;
+ t = Variant::FLOAT;
} break;
case MATH_RANDOMIZE: {
@@ -551,7 +551,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
} break;
case MATH_RANDF:
case MATH_RANDOM: {
- t = Variant::REAL;
+ t = Variant::FLOAT;
} break;
case MATH_SEED: {
@@ -568,7 +568,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_LINEAR2DB:
case MATH_WRAPF:
case MATH_DB2LINEAR: {
- t = Variant::REAL;
+ t = Variant::FLOAT;
} break;
case MATH_POLAR2CARTESIAN:
case MATH_CARTESIAN2POLAR: {
@@ -679,7 +679,7 @@ VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::get_func() {
if (!p_inputs[m_arg]->is_num()) { \
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; \
r_error.argument = m_arg; \
- r_error.expected = Variant::REAL; \
+ r_error.expected = Variant::FLOAT; \
return; \
}
@@ -781,7 +781,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
int64_t i = *p_inputs[0];
*r_return = ABS(i);
- } else if (p_inputs[0]->get_type() == Variant::REAL) {
+ } else if (p_inputs[0]->get_type() == Variant::FLOAT) {
real_t r = *p_inputs[0];
*r_return = Math::abs(r);
@@ -789,7 +789,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
- r_error.expected = Variant::REAL;
+ r_error.expected = Variant::FLOAT;
}
} break;
case VisualScriptBuiltinFunc::MATH_SIGN: {
@@ -798,7 +798,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
int64_t i = *p_inputs[0];
*r_return = i < 0 ? -1 : (i > 0 ? +1 : 0);
- } else if (p_inputs[0]->get_type() == Variant::REAL) {
+ } else if (p_inputs[0]->get_type() == Variant::FLOAT) {
real_t r = *p_inputs[0];
*r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0);
@@ -806,7 +806,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
- r_error.expected = Variant::REAL;
+ r_error.expected = Variant::FLOAT;
}
} break;
case VisualScriptBuiltinFunc::MATH_POW: {
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp
index 787f0b7f40..8840b9f7cf 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/visual_script_editor.cpp
@@ -346,7 +346,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
case Variant::BOOL: color = Color(0.55, 0.65, 0.94); break;
case Variant::INT: color = Color(0.49, 0.78, 0.94); break;
- case Variant::REAL: color = Color(0.38, 0.85, 0.96); break;
+ case Variant::FLOAT: color = Color(0.38, 0.85, 0.96); break;
case Variant::STRING: color = Color(0.42, 0.65, 0.93); break;
case Variant::VECTOR2: color = Color(0.74, 0.57, 0.95); break;
@@ -367,8 +367,10 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
case Variant::ARRAY: color = Color(0.88, 0.88, 0.88); break;
case Variant::PACKED_BYTE_ARRAY: color = Color(0.67, 0.96, 0.78); break;
- case Variant::PACKED_INT_ARRAY: color = Color(0.69, 0.86, 0.96); break;
- case Variant::PACKED_REAL_ARRAY: color = Color(0.59, 0.91, 0.97); break;
+ case Variant::PACKED_INT32_ARRAY: color = Color(0.69, 0.86, 0.96); break;
+ case Variant::PACKED_FLOAT32_ARRAY: color = Color(0.59, 0.91, 0.97); break;
+ case Variant::PACKED_INT64_ARRAY: color = Color(0.69, 0.86, 0.96); break;
+ case Variant::PACKED_FLOAT64_ARRAY: color = Color(0.59, 0.91, 0.97); break;
case Variant::PACKED_STRING_ARRAY: color = Color(0.62, 0.77, 0.95); break;
case Variant::PACKED_VECTOR2_ARRAY: color = Color(0.82, 0.7, 0.96); break;
case Variant::PACKED_VECTOR3_ARRAY: color = Color(0.87, 0.61, 0.95); break;
@@ -383,7 +385,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
case Variant::BOOL: color = Color(0.43, 0.56, 0.92); break;
case Variant::INT: color = Color(0.31, 0.7, 0.91); break;
- case Variant::REAL: color = Color(0.15, 0.8, 0.94); break;
+ case Variant::FLOAT: color = Color(0.15, 0.8, 0.94); break;
case Variant::STRING: color = Color(0.27, 0.56, 0.91); break;
case Variant::VECTOR2: color = Color(0.68, 0.46, 0.93); break;
@@ -404,8 +406,10 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) {
case Variant::ARRAY: color = Color(0.45, 0.45, 0.45); break;
case Variant::PACKED_BYTE_ARRAY: color = Color(0.38, 0.92, 0.6); break;
- case Variant::PACKED_INT_ARRAY: color = Color(0.38, 0.73, 0.92); break;
- case Variant::PACKED_REAL_ARRAY: color = Color(0.25, 0.83, 0.95); break;
+ case Variant::PACKED_INT32_ARRAY: color = Color(0.38, 0.73, 0.92); break;
+ case Variant::PACKED_FLOAT32_ARRAY: color = Color(0.25, 0.83, 0.95); break;
+ case Variant::PACKED_INT64_ARRAY: color = Color(0.38, 0.73, 0.92); break;
+ case Variant::PACKED_FLOAT64_ARRAY: color = Color(0.25, 0.83, 0.95); break;
case Variant::PACKED_STRING_ARRAY: color = Color(0.38, 0.62, 0.92); break;
case Variant::PACKED_VECTOR2_ARRAY: color = Color(0.62, 0.36, 0.92); break;
case Variant::PACKED_VECTOR3_ARRAY: color = Color(0.79, 0.35, 0.92); break;
@@ -521,8 +525,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
Control::get_icon("Dictionary", "EditorIcons"),
Control::get_icon("Array", "EditorIcons"),
Control::get_icon("PackedByteArray", "EditorIcons"),
- Control::get_icon("PackedIntArray", "EditorIcons"),
- Control::get_icon("PackedRealArray", "EditorIcons"),
+ Control::get_icon("PackedInt32Array", "EditorIcons"),
+ Control::get_icon("PackedFloat32Array", "EditorIcons"),
Control::get_icon("PackedStringArray", "EditorIcons"),
Control::get_icon("PackedVector2Array", "EditorIcons"),
Control::get_icon("PackedVector3Array", "EditorIcons"),
@@ -556,8 +560,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
gnode->set_meta("__vnode", node);
gnode->set_name(itos(E->get()));
- gnode->connect_compat("dragged", this, "_node_moved", varray(E->get()));
- gnode->connect_compat("close_request", this, "_remove_node", varray(E->get()), CONNECT_DEFERRED);
+ gnode->connect("dragged", callable_mp(this, &VisualScriptEditor::_node_moved), varray(E->get()));
+ gnode->connect("close_request", callable_mp(this, &VisualScriptEditor::_remove_node), varray(E->get()), CONNECT_DEFERRED);
if (E->get() != script->get_function_node_id(F->get())) {
//function can't be erased
@@ -575,7 +579,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
Button *btn = memnew(Button);
btn->set_text(TTR("Add Input Port"));
hbnc->add_child(btn);
- btn->connect_compat("pressed", this, "_add_input_port", varray(E->get()), CONNECT_DEFERRED);
+ btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_input_port), varray(E->get()), CONNECT_DEFERRED);
}
if (nd_list->is_output_port_editable()) {
if (nd_list->is_input_port_editable())
@@ -584,7 +588,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
Button *btn = memnew(Button);
btn->set_text(TTR("Add Output Port"));
hbnc->add_child(btn);
- btn->connect_compat("pressed", this, "_add_output_port", varray(E->get()), CONNECT_DEFERRED);
+ btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_output_port), varray(E->get()), CONNECT_DEFERRED);
}
gnode->add_child(hbnc);
} else if (Object::cast_to<VisualScriptExpression>(node.ptr())) {
@@ -594,7 +598,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
line_edit->set_expand_to_text_length(true);
line_edit->add_font_override("font", get_font("source", "EditorFonts"));
gnode->add_child(line_edit);
- line_edit->connect_compat("text_changed", this, "_expression_text_changed", varray(E->get()));
+ line_edit->connect("text_changed", callable_mp(this, &VisualScriptEditor::_expression_text_changed), varray(E->get()));
} else {
String text = node->get_text();
if (!text.empty()) {
@@ -610,7 +614,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
gnode->set_comment(true);
gnode->set_resizable(true);
gnode->set_custom_minimum_size(vsc->get_size() * EDSCALE);
- gnode->connect_compat("resize_request", this, "_comment_node_resized", varray(E->get()));
+ gnode->connect("resize_request", callable_mp(this, &VisualScriptEditor::_comment_node_resized), varray(E->get()));
}
if (node_styles.has(node->get_category())) {
@@ -619,16 +623,24 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
sbf = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox("comment", "GraphNode");
Color c = sbf->get_border_color();
+ Color ic = c;
c.a = 1;
if (EditorSettings::get_singleton()->get("interface/theme/use_graph_node_headers")) {
- Color mono_color = ((c.r + c.g + c.b) / 3) < 0.7 ? Color(1.0, 1.0, 1.0) : Color(0.0, 0.0, 0.0);
+ Color mono_color;
+ if (((c.r + c.g + c.b) / 3) < 0.7) {
+ mono_color = Color(1.0, 1.0, 1.0);
+ ic = Color(0.0, 0.0, 0.0, 0.7);
+ } else {
+ mono_color = Color(0.0, 0.0, 0.0);
+ ic = Color(1.0, 1.0, 1.0, 0.7);
+ }
mono_color.a = 0.85;
c = mono_color;
}
gnode->add_color_override("title_color", c);
c.a = 0.7;
gnode->add_color_override("close_color", c);
- gnode->add_color_override("resizer_color", c);
+ gnode->add_color_override("resizer_color", ic);
gnode->add_style_override("frame", sbf);
}
@@ -720,8 +732,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
name_box->set_custom_minimum_size(Size2(60 * EDSCALE, 0));
name_box->set_text(left_name);
name_box->set_expand_to_text_length(true);
- name_box->connect_compat("resized", this, "_update_node_size", varray(E->get()));
- name_box->connect_compat("focus_exited", this, "_port_name_focus_out", varray(name_box, E->get(), i, true));
+ name_box->connect("resized", callable_mp(this, &VisualScriptEditor::_update_node_size), varray(E->get()));
+ name_box->connect("focus_exited", callable_mp(this, &VisualScriptEditor::_port_name_focus_out), varray(name_box, E->get(), i, true));
} else {
hbc->add_child(memnew(Label(left_name)));
}
@@ -734,13 +746,13 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
opbtn->select(left_type);
opbtn->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
hbc->add_child(opbtn);
- opbtn->connect_compat("item_selected", this, "_change_port_type", varray(E->get(), i, true), CONNECT_DEFERRED);
+ opbtn->connect("item_selected", callable_mp(this, &VisualScriptEditor::_change_port_type), varray(E->get(), i, true), CONNECT_DEFERRED);
}
Button *rmbtn = memnew(Button);
rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Remove", "EditorIcons"));
hbc->add_child(rmbtn);
- rmbtn->connect_compat("pressed", this, "_remove_input_port", varray(E->get(), i), CONNECT_DEFERRED);
+ rmbtn->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_input_port), varray(E->get(), i), CONNECT_DEFERRED);
} else {
hbc->add_child(memnew(Label(left_name)));
}
@@ -760,7 +772,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
if (left_type == Variant::COLOR) {
button->set_custom_minimum_size(Size2(30, 0) * EDSCALE);
- button->connect_compat("draw", this, "_draw_color_over_button", varray(button, value));
+ button->connect("draw", callable_mp(this, &VisualScriptEditor::_draw_color_over_button), varray(button, value));
} else if (left_type == Variant::OBJECT && Ref<Resource>(value).is_valid()) {
Ref<Resource> res = value;
@@ -776,7 +788,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
button->set_text(value);
}
- button->connect_compat("pressed", this, "_default_value_edited", varray(button, E->get(), i));
+ button->connect("pressed", callable_mp(this, &VisualScriptEditor::_default_value_edited), varray(button, E->get(), i));
hbc2->add_child(button);
}
} else {
@@ -802,7 +814,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
Button *rmbtn = memnew(Button);
rmbtn->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Remove", "EditorIcons"));
hbc->add_child(rmbtn);
- rmbtn->connect_compat("pressed", this, "_remove_output_port", varray(E->get(), i), CONNECT_DEFERRED);
+ rmbtn->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_output_port), varray(E->get(), i), CONNECT_DEFERRED);
if (nd_list->is_output_port_type_editable()) {
OptionButton *opbtn = memnew(OptionButton);
@@ -812,7 +824,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
opbtn->select(right_type);
opbtn->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
hbc->add_child(opbtn);
- opbtn->connect_compat("item_selected", this, "_change_port_type", varray(E->get(), i, false), CONNECT_DEFERRED);
+ opbtn->connect("item_selected", callable_mp(this, &VisualScriptEditor::_change_port_type), varray(E->get(), i, false), CONNECT_DEFERRED);
}
if (nd_list->is_output_port_name_editable()) {
@@ -821,8 +833,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
name_box->set_custom_minimum_size(Size2(60 * EDSCALE, 0));
name_box->set_text(right_name);
name_box->set_expand_to_text_length(true);
- name_box->connect_compat("resized", this, "_update_node_size", varray(E->get()));
- name_box->connect_compat("focus_exited", this, "_port_name_focus_out", varray(name_box, E->get(), i, false));
+ name_box->connect("resized", callable_mp(this, &VisualScriptEditor::_update_node_size), varray(E->get()));
+ name_box->connect("focus_exited", callable_mp(this, &VisualScriptEditor::_port_name_focus_out), varray(name_box, E->get(), i, false));
} else {
hbc->add_child(memnew(Label(right_name)));
}
@@ -977,8 +989,8 @@ void VisualScriptEditor::_update_members() {
Control::get_icon("Dictionary", "EditorIcons"),
Control::get_icon("Array", "EditorIcons"),
Control::get_icon("PackedByteArray", "EditorIcons"),
- Control::get_icon("PackedIntArray", "EditorIcons"),
- Control::get_icon("PackedRealArray", "EditorIcons"),
+ Control::get_icon("PackedInt32Array", "EditorIcons"),
+ Control::get_icon("PackedFloat32Array", "EditorIcons"),
Control::get_icon("PackedStringArray", "EditorIcons"),
Control::get_icon("PackedVector2Array", "EditorIcons"),
Control::get_icon("PackedVector3Array", "EditorIcons"),
@@ -1225,7 +1237,7 @@ void VisualScriptEditor::_add_func_input() {
LineEdit *name_box = memnew(LineEdit);
name_box->set_h_size_flags(SIZE_EXPAND_FILL);
name_box->set_text("input");
- name_box->connect_compat("focus_entered", this, "_deselect_input_names");
+ name_box->connect("focus_entered", callable_mp(this, &VisualScriptEditor::_deselect_input_names));
hbox->add_child(name_box);
Label *type_label = memnew(Label);
@@ -1252,7 +1264,7 @@ void VisualScriptEditor::_add_func_input() {
func_input_vbox->add_child(hbox);
hbox->set_meta("id", hbox->get_position_in_parent());
- delete_button->connect_compat("pressed", this, "_remove_func_input", varray(hbox));
+ delete_button->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_func_input), varray(hbox));
name_box->select_all();
name_box->grab_focus();
@@ -1820,7 +1832,7 @@ void VisualScriptEditor::_fn_name_box_input(const Ref<InputEvent> &p_event) {
return;
Ref<InputEventKey> key = p_event;
- if (key.is_valid() && key->is_pressed() && key->get_scancode() == KEY_ENTER) {
+ if (key.is_valid() && key->is_pressed() && key->get_keycode() == KEY_ENTER) {
function_name_edit->hide();
_rename_function(selected, function_name_box->get_text());
function_name_box->clear();
@@ -2408,7 +2420,7 @@ void VisualScriptEditor::set_edited_resource(const RES &p_res) {
variable_editor->script = script;
variable_editor->undo_redo = undo_redo;
- script->connect_compat("node_ports_changed", this, "_node_ports_changed");
+ script->connect("node_ports_changed", callable_mp(this, &VisualScriptEditor::_node_ports_changed));
default_func = script->get_default_func();
@@ -2910,8 +2922,8 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot,
if (to_type != Variant::NIL && from_type != Variant::NIL && to_type != from_type) {
// add a constructor node between the ports
bool exceptions = false; // true if there are any exceptions
- exceptions = exceptions || (to_type == Variant::INT && from_type == Variant::REAL);
- exceptions = exceptions || (to_type == Variant::REAL && from_type == Variant::INT);
+ exceptions = exceptions || (to_type == Variant::INT && from_type == Variant::FLOAT);
+ exceptions = exceptions || (to_type == Variant::FLOAT && from_type == Variant::INT);
if (Variant::can_convert(from_type, to_type) && !exceptions) {
MethodInfo mi;
mi.name = Variant::get_type_name(to_type);
@@ -3904,8 +3916,8 @@ void VisualScriptEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
- variable_editor->connect_compat("changed", this, "_update_members");
- signal_editor->connect_compat("changed", this, "_update_members");
+ variable_editor->connect("changed", callable_mp(this, &VisualScriptEditor::_update_members));
+ signal_editor->connect("changed", callable_mp(this, &VisualScriptEditor::_update_members));
[[fallthrough]];
}
case NOTIFICATION_THEME_CHANGED: {
@@ -4601,77 +4613,23 @@ void VisualScriptEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter
void VisualScriptEditor::_bind_methods() {
- ClassDB::bind_method("_member_button", &VisualScriptEditor::_member_button);
- ClassDB::bind_method("_member_edited", &VisualScriptEditor::_member_edited);
- ClassDB::bind_method("_member_selected", &VisualScriptEditor::_member_selected);
- ClassDB::bind_method("_update_members", &VisualScriptEditor::_update_members);
- ClassDB::bind_method("_members_gui_input", &VisualScriptEditor::_members_gui_input);
- ClassDB::bind_method("_member_rmb_selected", &VisualScriptEditor::_member_rmb_selected);
- ClassDB::bind_method("_member_option", &VisualScriptEditor::_member_option);
- ClassDB::bind_method("_fn_name_box_input", &VisualScriptEditor::_fn_name_box_input);
-
- ClassDB::bind_method("_change_base_type", &VisualScriptEditor::_change_base_type);
- ClassDB::bind_method("_change_base_type_callback", &VisualScriptEditor::_change_base_type_callback);
- ClassDB::bind_method("_toggle_tool_script", &VisualScriptEditor::_toggle_tool_script);
- ClassDB::bind_method("_node_selected", &VisualScriptEditor::_node_selected);
- ClassDB::bind_method("_node_moved", &VisualScriptEditor::_node_moved);
ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node);
- ClassDB::bind_method("_begin_node_move", &VisualScriptEditor::_begin_node_move);
- ClassDB::bind_method("_end_node_move", &VisualScriptEditor::_end_node_move);
- ClassDB::bind_method("_remove_node", &VisualScriptEditor::_remove_node);
ClassDB::bind_method("_update_graph", &VisualScriptEditor::_update_graph, DEFVAL(-1));
- ClassDB::bind_method("_node_ports_changed", &VisualScriptEditor::_node_ports_changed);
-
- ClassDB::bind_method("_create_function_dialog", &VisualScriptEditor::_create_function_dialog);
- ClassDB::bind_method("_create_function", &VisualScriptEditor::_create_function);
- ClassDB::bind_method("_add_node_dialog", &VisualScriptEditor::_add_node_dialog);
- ClassDB::bind_method("_add_func_input", &VisualScriptEditor::_add_func_input);
- ClassDB::bind_method("_remove_func_input", &VisualScriptEditor::_remove_func_input);
- ClassDB::bind_method("_deselect_input_names", &VisualScriptEditor::_deselect_input_names);
-
- ClassDB::bind_method("_default_value_edited", &VisualScriptEditor::_default_value_edited);
- ClassDB::bind_method("_default_value_changed", &VisualScriptEditor::_default_value_changed);
- ClassDB::bind_method("_menu_option", &VisualScriptEditor::_menu_option);
- ClassDB::bind_method("_graph_ofs_changed", &VisualScriptEditor::_graph_ofs_changed);
+
ClassDB::bind_method("_center_on_node", &VisualScriptEditor::_center_on_node);
- ClassDB::bind_method("_comment_node_resized", &VisualScriptEditor::_comment_node_resized);
ClassDB::bind_method("_button_resource_previewed", &VisualScriptEditor::_button_resource_previewed);
ClassDB::bind_method("_port_action_menu", &VisualScriptEditor::_port_action_menu);
- ClassDB::bind_method("_selected_connect_node", &VisualScriptEditor::_selected_connect_node);
- ClassDB::bind_method("_selected_new_virtual_method", &VisualScriptEditor::_selected_new_virtual_method);
- ClassDB::bind_method("_cancel_connect_node", &VisualScriptEditor::_cancel_connect_node);
ClassDB::bind_method("_create_new_node_from_name", &VisualScriptEditor::_create_new_node_from_name);
- ClassDB::bind_method("_expression_text_changed", &VisualScriptEditor::_expression_text_changed);
- ClassDB::bind_method("_add_input_port", &VisualScriptEditor::_add_input_port);
- ClassDB::bind_method("_add_output_port", &VisualScriptEditor::_add_output_port);
- ClassDB::bind_method("_remove_input_port", &VisualScriptEditor::_remove_input_port);
- ClassDB::bind_method("_remove_output_port", &VisualScriptEditor::_remove_output_port);
- ClassDB::bind_method("_change_port_type", &VisualScriptEditor::_change_port_type);
- ClassDB::bind_method("_update_node_size", &VisualScriptEditor::_update_node_size);
- ClassDB::bind_method("_port_name_focus_out", &VisualScriptEditor::_port_name_focus_out);
ClassDB::bind_method("get_drag_data_fw", &VisualScriptEditor::get_drag_data_fw);
ClassDB::bind_method("can_drop_data_fw", &VisualScriptEditor::can_drop_data_fw);
ClassDB::bind_method("drop_data_fw", &VisualScriptEditor::drop_data_fw);
ClassDB::bind_method("_input", &VisualScriptEditor::_input);
- ClassDB::bind_method("_graph_gui_input", &VisualScriptEditor::_graph_gui_input);
-
- ClassDB::bind_method("_on_nodes_delete", &VisualScriptEditor::_on_nodes_delete);
- ClassDB::bind_method("_on_nodes_duplicate", &VisualScriptEditor::_on_nodes_duplicate);
-
- ClassDB::bind_method("_hide_timer", &VisualScriptEditor::_hide_timer);
-
- ClassDB::bind_method("_graph_connected", &VisualScriptEditor::_graph_connected);
- ClassDB::bind_method("_graph_disconnected", &VisualScriptEditor::_graph_disconnected);
- ClassDB::bind_method("_graph_connect_to_empty", &VisualScriptEditor::_graph_connect_to_empty);
ClassDB::bind_method("_update_graph_connections", &VisualScriptEditor::_update_graph_connections);
- ClassDB::bind_method("_selected_method", &VisualScriptEditor::_selected_method);
- ClassDB::bind_method("_draw_color_over_button", &VisualScriptEditor::_draw_color_over_button);
-
ClassDB::bind_method("_generic_search", &VisualScriptEditor::_generic_search);
}
@@ -4697,7 +4655,7 @@ VisualScriptEditor::VisualScriptEditor() {
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/create_function"), EDIT_CREATE_FUNCTION);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/refresh_nodes"), REFRESH_GRAPH);
- edit_menu->get_popup()->connect_compat("id_pressed", this, "_menu_option");
+ edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &VisualScriptEditor::_menu_option));
members_section = memnew(VBoxContainer);
// Add but wait until done setting up this.
@@ -4707,7 +4665,7 @@ VisualScriptEditor::VisualScriptEditor() {
CheckButton *tool_script_check = memnew(CheckButton);
tool_script_check->set_text(TTR("Make Tool:"));
members_section->add_child(tool_script_check);
- tool_script_check->connect_compat("pressed", this, "_toggle_tool_script");
+ tool_script_check->connect("pressed", callable_mp(this, &VisualScriptEditor::_toggle_tool_script));
/// Members ///
@@ -4715,11 +4673,11 @@ VisualScriptEditor::VisualScriptEditor() {
members_section->add_margin_child(TTR("Members:"), members, true);
members->set_custom_minimum_size(Size2(0, 50 * EDSCALE));
members->set_hide_root(true);
- members->connect_compat("button_pressed", this, "_member_button");
- members->connect_compat("item_edited", this, "_member_edited");
- members->connect_compat("cell_selected", this, "_member_selected", varray(), CONNECT_DEFERRED);
- members->connect_compat("gui_input", this, "_members_gui_input");
- members->connect_compat("item_rmb_selected", this, "_member_rmb_selected");
+ members->connect("button_pressed", callable_mp(this, &VisualScriptEditor::_member_button));
+ members->connect("item_edited", callable_mp(this, &VisualScriptEditor::_member_edited));
+ members->connect("cell_selected", callable_mp(this, &VisualScriptEditor::_member_selected), varray(), CONNECT_DEFERRED);
+ members->connect("gui_input", callable_mp(this, &VisualScriptEditor::_members_gui_input));
+ members->connect("item_rmb_selected", callable_mp(this, &VisualScriptEditor::_member_rmb_selected));
members->set_allow_rmb_select(true);
members->set_allow_reselect(true);
members->set_hide_folding(true);
@@ -4727,13 +4685,13 @@ VisualScriptEditor::VisualScriptEditor() {
member_popup = memnew(PopupMenu);
add_child(member_popup);
- member_popup->connect_compat("id_pressed", this, "_member_option");
+ member_popup->connect("id_pressed", callable_mp(this, &VisualScriptEditor::_member_option));
function_name_edit = memnew(PopupDialog);
function_name_box = memnew(LineEdit);
function_name_edit->add_child(function_name_box);
function_name_edit->set_h_size_flags(SIZE_EXPAND);
- function_name_box->connect_compat("gui_input", this, "_fn_name_box_input");
+ function_name_box->connect("gui_input", callable_mp(this, &VisualScriptEditor::_fn_name_box_input));
function_name_box->set_expand_to_text_length(true);
add_child(function_name_edit);
@@ -4743,15 +4701,15 @@ VisualScriptEditor::VisualScriptEditor() {
add_child(graph);
graph->set_v_size_flags(Control::SIZE_EXPAND_FILL);
graph->set_anchors_and_margins_preset(Control::PRESET_WIDE);
- graph->connect_compat("node_selected", this, "_node_selected");
- graph->connect_compat("_begin_node_move", this, "_begin_node_move");
- graph->connect_compat("_end_node_move", this, "_end_node_move");
- graph->connect_compat("delete_nodes_request", this, "_on_nodes_delete");
- graph->connect_compat("duplicate_nodes_request", this, "_on_nodes_duplicate");
- graph->connect_compat("gui_input", this, "_graph_gui_input");
+ graph->connect("node_selected", callable_mp(this, &VisualScriptEditor::_node_selected));
+ graph->connect("_begin_node_move", callable_mp(this, &VisualScriptEditor::_begin_node_move));
+ graph->connect("_end_node_move", callable_mp(this, &VisualScriptEditor::_end_node_move));
+ graph->connect("delete_nodes_request", callable_mp(this, &VisualScriptEditor::_on_nodes_delete));
+ graph->connect("duplicate_nodes_request", callable_mp(this, &VisualScriptEditor::_on_nodes_duplicate));
+ graph->connect("gui_input", callable_mp(this, &VisualScriptEditor::_graph_gui_input));
graph->set_drag_forwarding(this);
graph->hide();
- graph->connect_compat("scroll_offset_changed", this, "_graph_ofs_changed");
+ graph->connect("scroll_offset_changed", callable_mp(this, &VisualScriptEditor::_graph_ofs_changed));
/// Add Buttons to Top Bar/Zoom bar.
HBoxContainer *graph_hbc = graph->get_zoom_hbox();
@@ -4761,18 +4719,18 @@ VisualScriptEditor::VisualScriptEditor() {
graph_hbc->add_child(base_lbl);
base_type_select = memnew(Button);
- base_type_select->connect_compat("pressed", this, "_change_base_type");
+ base_type_select->connect("pressed", callable_mp(this, &VisualScriptEditor::_change_base_type));
graph_hbc->add_child(base_type_select);
Button *add_nds = memnew(Button);
add_nds->set_text(TTR("Add Nodes..."));
graph_hbc->add_child(add_nds);
- add_nds->connect_compat("pressed", this, "_add_node_dialog");
+ add_nds->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_node_dialog));
Button *fn_btn = memnew(Button);
fn_btn->set_text(TTR("Add Function..."));
graph_hbc->add_child(fn_btn);
- fn_btn->connect_compat("pressed", this, "_create_function_dialog");
+ fn_btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_create_function_dialog));
// Add Function Dialog.
VBoxContainer *function_vb = memnew(VBoxContainer);
@@ -4790,7 +4748,7 @@ VisualScriptEditor::VisualScriptEditor() {
func_name_box->set_h_size_flags(SIZE_EXPAND_FILL);
func_name_box->set_placeholder(TTR("function_name"));
func_name_box->set_text("");
- func_name_box->connect_compat("focus_entered", this, "_deselect_input_names");
+ func_name_box->connect("focus_entered", callable_mp(this, &VisualScriptEditor::_deselect_input_names));
func_name_hbox->add_child(func_name_box);
// Add minor setting for function if needed, here!
@@ -4800,7 +4758,7 @@ VisualScriptEditor::VisualScriptEditor() {
Button *add_input_button = memnew(Button);
add_input_button->set_h_size_flags(SIZE_EXPAND_FILL);
add_input_button->set_text(TTR("Add Input"));
- add_input_button->connect_compat("pressed", this, "_add_func_input");
+ add_input_button->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_func_input));
function_vb->add_child(add_input_button);
func_input_scroll = memnew(ScrollContainer);
@@ -4816,7 +4774,7 @@ VisualScriptEditor::VisualScriptEditor() {
function_create_dialog->set_title(TTR("Create Function"));
function_create_dialog->add_child(function_vb);
function_create_dialog->get_ok()->set_text(TTR("Create"));
- function_create_dialog->get_ok()->connect_compat("pressed", this, "_create_function");
+ function_create_dialog->get_ok()->connect("pressed", callable_mp(this, &VisualScriptEditor::_create_function));
add_child(function_create_dialog);
select_func_text = memnew(Label);
@@ -4836,7 +4794,7 @@ VisualScriptEditor::VisualScriptEditor() {
hint_text_timer = memnew(Timer);
hint_text_timer->set_wait_time(4);
- hint_text_timer->connect_compat("timeout", this, "_hide_timer");
+ hint_text_timer->connect("timeout", callable_mp(this, &VisualScriptEditor::_hide_timer));
add_child(hint_text_timer);
// Allowed casts (connections).
@@ -4854,9 +4812,9 @@ VisualScriptEditor::VisualScriptEditor() {
graph->add_valid_left_disconnect_type(TYPE_SEQUENCE);
- graph->connect_compat("connection_request", this, "_graph_connected");
- graph->connect_compat("disconnection_request", this, "_graph_disconnected");
- graph->connect_compat("connection_to_empty", this, "_graph_connect_to_empty");
+ graph->connect("connection_request", callable_mp(this, &VisualScriptEditor::_graph_connected));
+ graph->connect("disconnection_request", callable_mp(this, &VisualScriptEditor::_graph_disconnected));
+ graph->connect("connection_to_empty", callable_mp(this, &VisualScriptEditor::_graph_connect_to_empty));
edit_signal_dialog = memnew(AcceptDialog);
edit_signal_dialog->get_ok()->set_text(TTR("Close"));
@@ -4880,7 +4838,7 @@ VisualScriptEditor::VisualScriptEditor() {
select_base_type = memnew(CreateDialog);
select_base_type->set_base_type("Object"); // Anything goes.
- select_base_type->connect_compat("create", this, "_change_base_type_callback");
+ select_base_type->connect("create", callable_mp(this, &VisualScriptEditor::_change_base_type_callback));
add_child(select_base_type);
undo_redo = EditorNode::get_singleton()->get_undo_redo();
@@ -4892,22 +4850,22 @@ VisualScriptEditor::VisualScriptEditor() {
default_value_edit = memnew(CustomPropertyEditor);
add_child(default_value_edit);
- default_value_edit->connect_compat("variant_changed", this, "_default_value_changed");
+ default_value_edit->connect("variant_changed", callable_mp(this, &VisualScriptEditor::_default_value_changed));
method_select = memnew(VisualScriptPropertySelector);
add_child(method_select);
- method_select->connect_compat("selected", this, "_selected_method");
+ method_select->connect("selected", callable_mp(this, &VisualScriptEditor::_selected_method));
error_line = -1;
new_connect_node_select = memnew(VisualScriptPropertySelector);
add_child(new_connect_node_select);
new_connect_node_select->set_resizable(true);
- new_connect_node_select->connect_compat("selected", this, "_selected_connect_node");
- new_connect_node_select->get_cancel()->connect_compat("pressed", this, "_cancel_connect_node");
+ new_connect_node_select->connect("selected", callable_mp(this, &VisualScriptEditor::_selected_connect_node));
+ new_connect_node_select->get_cancel()->connect("pressed", callable_mp(this, &VisualScriptEditor::_cancel_connect_node));
new_virtual_method_select = memnew(VisualScriptPropertySelector);
add_child(new_virtual_method_select);
- new_virtual_method_select->connect_compat("selected", this, "_selected_new_virtual_method");
+ new_virtual_method_select->connect("selected", callable_mp(this, &VisualScriptEditor::_selected_new_virtual_method));
}
VisualScriptEditor::~VisualScriptEditor() {
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index 1f1c3e2f52..ea09c82013 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -2259,7 +2259,7 @@ PropertyInfo VisualScriptMathConstant::get_input_value_port_info(int p_idx) cons
PropertyInfo VisualScriptMathConstant::get_output_value_port_info(int p_idx) const {
- return PropertyInfo(Variant::REAL, const_name[constant]);
+ return PropertyInfo(Variant::FLOAT, const_name[constant]);
}
String VisualScriptMathConstant::get_caption() const {
@@ -3130,8 +3130,6 @@ void VisualScriptCustomNode::_bind_methods() {
stepmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
BIND_VMETHOD(stepmi);
- ClassDB::bind_method(D_METHOD("_script_changed"), &VisualScriptCustomNode::_script_changed);
-
BIND_ENUM_CONSTANT(START_MODE_BEGIN_SEQUENCE);
BIND_ENUM_CONSTANT(START_MODE_CONTINUE_SEQUENCE);
BIND_ENUM_CONSTANT(START_MODE_RESUME_YIELD);
@@ -3144,7 +3142,7 @@ void VisualScriptCustomNode::_bind_methods() {
}
VisualScriptCustomNode::VisualScriptCustomNode() {
- connect_compat("script_changed", this, "_script_changed");
+ connect("script_changed", callable_mp(this, &VisualScriptCustomNode::_script_changed));
}
//////////////////////////////////////////
diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp
index 51b77659c4..d799f19143 100644
--- a/modules/visual_script/visual_script_property_selector.cpp
+++ b/modules/visual_script/visual_script_property_selector.cpp
@@ -51,7 +51,7 @@ void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
if (k.is_valid()) {
- switch (k->get_scancode()) {
+ switch (k->get_keycode()) {
case KEY_UP:
case KEY_DOWN:
case KEY_PAGEUP:
@@ -120,8 +120,10 @@ void VisualScriptPropertySelector::_update_search() {
Control::get_icon("Dictionary", "EditorIcons"),
Control::get_icon("Array", "EditorIcons"),
Control::get_icon("PackedByteArray", "EditorIcons"),
- Control::get_icon("PackedIntArray", "EditorIcons"),
- Control::get_icon("PackedRealArray", "EditorIcons"),
+ Control::get_icon("PackedInt32Array", "EditorIcons"),
+ Control::get_icon("PackedFloat32Array", "EditorIcons"),
+ Control::get_icon("PackedInt64Array", "EditorIcons"),
+ Control::get_icon("PackedFloat64Array", "EditorIcons"),
Control::get_icon("PackedStringArray", "EditorIcons"),
Control::get_icon("PackedVector2Array", "EditorIcons"),
Control::get_icon("PackedVector3Array", "EditorIcons"),
@@ -279,7 +281,7 @@ void VisualScriptPropertySelector::_update_search() {
if (type == Variant::BOOL) {
get_visual_node_names("operators/logic/", Set<String>(), found, root, search_box);
}
- if (type == Variant::BOOL || type == Variant::INT || type == Variant::REAL || type == Variant::VECTOR2 || type == Variant::VECTOR3) {
+ if (type == Variant::BOOL || type == Variant::INT || type == Variant::FLOAT || type == Variant::VECTOR2 || type == Variant::VECTOR3) {
get_visual_node_names("operators/math/", Set<String>(), found, root, search_box);
}
}
@@ -516,11 +518,15 @@ void VisualScriptPropertySelector::_item_selected() {
help_bit->set_text(text);
}
+void VisualScriptPropertySelector::_hide_requested() {
+ _closed(); // From WindowDialog.
+}
+
void VisualScriptPropertySelector::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
- connect_compat("confirmed", this, "_confirmed");
+ connect("confirmed", callable_mp(this, &VisualScriptPropertySelector::_confirmed));
}
}
@@ -688,11 +694,6 @@ void VisualScriptPropertySelector::show_window(float p_screen_ratio) {
void VisualScriptPropertySelector::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_text_changed"), &VisualScriptPropertySelector::_text_changed);
- ClassDB::bind_method(D_METHOD("_confirmed"), &VisualScriptPropertySelector::_confirmed);
- ClassDB::bind_method(D_METHOD("_sbox_input"), &VisualScriptPropertySelector::_sbox_input);
- ClassDB::bind_method(D_METHOD("_item_selected"), &VisualScriptPropertySelector::_item_selected);
-
ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "category"), PropertyInfo(Variant::BOOL, "connecting")));
}
@@ -703,23 +704,23 @@ VisualScriptPropertySelector::VisualScriptPropertySelector() {
//set_child_rect(vbc);
search_box = memnew(LineEdit);
vbc->add_margin_child(TTR("Search:"), search_box);
- search_box->connect_compat("text_changed", this, "_text_changed");
- search_box->connect_compat("gui_input", this, "_sbox_input");
+ search_box->connect("text_changed", callable_mp(this, &VisualScriptPropertySelector::_text_changed));
+ search_box->connect("gui_input", callable_mp(this, &VisualScriptPropertySelector::_sbox_input));
search_options = memnew(Tree);
vbc->add_margin_child(TTR("Matches:"), search_options, true);
get_ok()->set_text(TTR("Open"));
get_ok()->set_disabled(true);
register_text_enter(search_box);
set_hide_on_ok(false);
- search_options->connect_compat("item_activated", this, "_confirmed");
- search_options->connect_compat("cell_selected", this, "_item_selected");
+ search_options->connect("item_activated", callable_mp(this, &VisualScriptPropertySelector::_confirmed));
+ search_options->connect("cell_selected", callable_mp(this, &VisualScriptPropertySelector::_item_selected));
search_options->set_hide_root(true);
search_options->set_hide_folding(true);
virtuals_only = false;
seq_connect = false;
help_bit = memnew(EditorHelpBit);
vbc->add_margin_child(TTR("Description:"), help_bit);
- help_bit->connect_compat("request_hide", this, "_closed");
+ help_bit->connect("request_hide", callable_mp(this, &VisualScriptPropertySelector::_hide_requested));
search_options->set_columns(3);
search_options->set_column_expand(1, false);
search_options->set_column_expand(2, false);
diff --git a/modules/visual_script/visual_script_property_selector.h b/modules/visual_script/visual_script_property_selector.h
index a1eb0b842c..f438ca1f5b 100644
--- a/modules/visual_script/visual_script_property_selector.h
+++ b/modules/visual_script/visual_script_property_selector.h
@@ -41,16 +41,16 @@ class VisualScriptPropertySelector : public ConfirmationDialog {
LineEdit *search_box;
Tree *search_options;
+ void _text_changed(const String &p_newtext);
+ void _sbox_input(const Ref<InputEvent> &p_ie);
void _update_search();
void create_visualscript_item(const String &name, TreeItem *const root, const String &search_input, const String &text);
-
void get_visual_node_names(const String &root_filter, const Set<String> &p_modifiers, bool &found, TreeItem *const root, LineEdit *const search_box);
- void _sbox_input(const Ref<InputEvent> &p_ie);
-
void _confirmed();
- void _text_changed(const String &p_newtext);
+ void _item_selected();
+ void _hide_requested();
EditorHelpBit *help_bit;
@@ -65,8 +65,6 @@ class VisualScriptPropertySelector : public ConfirmationDialog {
bool virtuals_only;
bool seq_connect;
- void _item_selected();
-
Vector<Variant::Type> type_filter;
protected:
diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp
index 40d2ec88c5..858074742e 100644
--- a/modules/visual_script/visual_script_yield_nodes.cpp
+++ b/modules/visual_script/visual_script_yield_nodes.cpp
@@ -188,7 +188,7 @@ void VisualScriptYield::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_wait_time"), &VisualScriptYield::get_wait_time);
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Frame,Physics Frame,Time", PROPERTY_USAGE_NOEDITOR), "set_yield_mode", "get_yield_mode");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "wait_time"), "set_wait_time", "get_wait_time");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "wait_time"), "set_wait_time", "get_wait_time");
BIND_ENUM_CONSTANT(YIELD_FRAME);
BIND_ENUM_CONSTANT(YIELD_PHYSICS_FRAME);
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp
index 87067faf8e..1e8ee9b17e 100644
--- a/modules/vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp
@@ -381,7 +381,7 @@ AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() {
_clear_stream();
}
-RES ResourceFormatLoaderAudioStreamOGGVorbis::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderAudioStreamOGGVorbis::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
if (r_error)
*r_error = OK;
diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h
index 739765a12f..db621f88d2 100644
--- a/modules/vorbis/audio_stream_ogg_vorbis.h
+++ b/modules/vorbis/audio_stream_ogg_vorbis.h
@@ -128,7 +128,7 @@ public:
class ResourceFormatLoaderAudioStreamOGGVorbis : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp
index 5768392fe5..265383831e 100644
--- a/modules/webm/video_stream_webm.cpp
+++ b/modules/webm/video_stream_webm.cpp
@@ -474,7 +474,7 @@ void VideoStreamWebm::set_audio_track(int p_track) {
////////////
-RES ResourceFormatLoaderWebm::load(const String &p_path, const String &p_original_path, Error *r_error) {
+RES ResourceFormatLoaderWebm::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress) {
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f) {
diff --git a/modules/webm/video_stream_webm.h b/modules/webm/video_stream_webm.h
index a3d3c173f4..3feaa1278f 100644
--- a/modules/webm/video_stream_webm.h
+++ b/modules/webm/video_stream_webm.h
@@ -128,7 +128,7 @@ public:
class ResourceFormatLoaderWebm : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL, bool p_use_sub_threads = false, float *r_progress = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;