diff options
Diffstat (limited to 'modules')
234 files changed, 2695 insertions, 2278 deletions
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index a45333e5bc..7b20fad28c 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -303,6 +303,7 @@ RigidBodyBullet::~RigidBodyBullet() { void RigidBodyBullet::init_kinematic_utilities() { kinematic_utilities = memnew(KinematicUtilities(this)); + reload_kinematic_shapes(); } void RigidBodyBullet::destroy_kinematic_utilities() { diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index a9a811c445..0cfd658bd5 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -947,7 +947,6 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform3D &p if (!p_body->get_kinematic_utilities()) { p_body->init_kinematic_utilities(); - p_body->reload_kinematic_shapes(); } btVector3 initial_recover_motion(0, 0, 0); @@ -1089,7 +1088,6 @@ int SpaceBullet::test_ray_separation(RigidBodyBullet *p_body, const Transform3D if (!p_body->get_kinematic_utilities()) { p_body->init_kinematic_utilities(); - p_body->reload_kinematic_shapes(); } btVector3 recover_motion(0, 0, 0); diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index cb82b65307..f7e92aaa90 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -40,13 +40,13 @@ inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2, 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 (p_segement_points[0].is_equal_approx(p_segement_points[1])) { +inline static Vector2 interpolate_segment_uv(const Vector2 p_segment_points[2], const Vector2 p_uvs[2], const Vector2 &p_interpolation_point) { + float segment_length = (p_segment_points[1] - p_segment_points[0]).length(); + if (p_segment_points[0].is_equal_approx(p_segment_points[1])) { return p_uvs[0]; } - float distance = (p_interpolation_point - p_segement_points[0]).length(); + float distance = (p_interpolation_point - p_segment_points[0]).length(); float fraction = distance / segment_length; return p_uvs[0].lerp(p_uvs[1], fraction); @@ -162,7 +162,7 @@ inline static bool is_triangle_degenerate(const Vector2 p_vertices[3], real_t p_ return det < p_vertex_snap2; } -inline static bool are_segements_parallel(const Vector2 p_segment1_points[2], const Vector2 p_segment2_points[2], float p_vertex_snap2) { +inline static bool are_segments_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); @@ -517,7 +517,7 @@ int CSGBrushOperation::MeshMerge::_create_bvh(FaceBVH *facebvhptr, FaceBVH **fac int index = r_max_alloc++; FaceBVH *_new = &facebvhptr[index]; _new->aabb = aabb; - _new->center = aabb.position + aabb.size * 0.5; + _new->center = aabb.get_center(); _new->face = -1; _new->left = left; _new->right = right; @@ -678,7 +678,7 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() { 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].center = facebvh[i].aabb.get_center(); facebvh[i].aabb.grow_by(vertex_snap); facebvh[i].next = -1; @@ -911,7 +911,7 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ vertices[outer_edge_idx[1]].point, vertices[p_segment_indices[closest_idx]].point }; - if (are_segements_parallel(edge1, edge2, vertex_snap2)) { + if (are_segments_parallel(edge1, edge2, vertex_snap2)) { if (!degenerate_points.find(outer_edge_idx[0])) { degenerate_points.push_back(outer_edge_idx[0]); } @@ -1056,7 +1056,7 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s } // 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)) { + if (are_segments_parallel(p_segment_points, edge_points, vertex_snap2)) { continue; } @@ -1172,8 +1172,8 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { 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)) { + if (are_segments_parallel(split_edge1, new_edge, vertex_snap2) && + are_segments_parallel(split_edge2, new_edge, vertex_snap2)) { break; } diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index 452fb32d9d..e4297a593e 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -1732,6 +1732,7 @@ CSGBrush *CSGPolygon3D::_build_brush() { int extrusion_face_count = shape_sides * 2; int end_count = 0; int shape_face_count = shape_faces.size() / 3; + real_t curve_length = 1.0; switch (mode) { case MODE_DEPTH: extrusions = 1; @@ -1744,7 +1745,12 @@ CSGBrush *CSGPolygon3D::_build_brush() { } break; case MODE_PATH: { - extrusions = Math::ceil(1.0 * curve->get_point_count() / path_interval); + curve_length = curve->get_baked_length(); + if (path_interval_type == PATH_INTERVAL_DISTANCE) { + extrusions = MAX(1, Math::ceil(curve_length / path_interval)) + 1; + } else { + extrusions = Math::ceil(1.0 * curve->get_point_count() / path_interval); + } if (!path_joined) { end_count = 2; extrusions -= 1; @@ -1767,212 +1773,245 @@ CSGBrush *CSGPolygon3D::_build_brush() { smooth.resize(face_count); materials.resize(face_count); invert.resize(face_count); + int faces_removed = 0; - Vector3 *facesw = faces.ptrw(); - Vector2 *uvsw = uvs.ptrw(); - bool *smoothw = smooth.ptrw(); - Ref<Material> *materialsw = materials.ptrw(); - bool *invertw = invert.ptrw(); - - int face = 0; - Transform3D base_xform; - Transform3D current_xform; - Transform3D previous_xform; - double u_step = 1.0 / extrusions; - double v_step = 1.0 / shape_sides; - double spin_step = Math::deg2rad(spin_degrees / spin_sides); - double extrusion_step = 1.0 / extrusions; - if (mode == MODE_PATH) { - if (path_joined) { - extrusion_step = 1.0 / (extrusions - 1); - } - extrusion_step *= curve->get_baked_length(); - } + { + Vector3 *facesw = faces.ptrw(); + Vector2 *uvsw = uvs.ptrw(); + bool *smoothw = smooth.ptrw(); + Ref<Material> *materialsw = materials.ptrw(); + bool *invertw = invert.ptrw(); - if (mode == MODE_PATH) { - if (!path_local) { - base_xform = path->get_global_transform(); + int face = 0; + Transform3D base_xform; + Transform3D current_xform; + Transform3D previous_xform; + Transform3D previous_previous_xform; + double u_step = 1.0 / extrusions; + if (path_u_distance > 0.0) { + u_step *= curve_length / path_u_distance; + } + double v_step = 1.0 / shape_sides; + double spin_step = Math::deg2rad(spin_degrees / spin_sides); + double extrusion_step = 1.0 / extrusions; + if (mode == MODE_PATH) { + if (path_joined) { + extrusion_step = 1.0 / (extrusions - 1); + } + extrusion_step *= curve_length; } - Vector3 current_point = curve->interpolate_baked(0); - Vector3 next_point = curve->interpolate_baked(extrusion_step); - Vector3 current_up = Vector3(0, 1, 0); - Vector3 direction = next_point - current_point; + if (mode == MODE_PATH) { + if (!path_local) { + base_xform = path->get_global_transform(); + } - if (path_joined) { - Vector3 last_point = curve->interpolate_baked(curve->get_baked_length()); - direction = next_point - last_point; - } + Vector3 current_point = curve->interpolate_baked(0); + Vector3 next_point = curve->interpolate_baked(extrusion_step); + Vector3 current_up = Vector3(0, 1, 0); + Vector3 direction = next_point - current_point; - switch (path_rotation) { - case PATH_ROTATION_POLYGON: - direction = Vector3(0, 0, -1); - break; - case PATH_ROTATION_PATH: - break; - case PATH_ROTATION_PATH_FOLLOW: - current_up = curve->interpolate_baked_up_vector(0); - break; + if (path_joined) { + Vector3 last_point = curve->interpolate_baked(curve->get_baked_length()); + direction = next_point - last_point; + } + + switch (path_rotation) { + case PATH_ROTATION_POLYGON: + direction = Vector3(0, 0, -1); + break; + case PATH_ROTATION_PATH: + break; + case PATH_ROTATION_PATH_FOLLOW: + current_up = curve->interpolate_baked_up_vector(0); + break; + } + + Transform3D facing = Transform3D().looking_at(direction, current_up); + current_xform = base_xform.translated(current_point) * facing; } - Transform3D facing = Transform3D().looking_at(direction, current_up); - current_xform = base_xform.translated(current_point) * facing; - } + // Create the mesh. + if (end_count > 0) { + // Add front end face. + for (int face_idx = 0; face_idx < shape_face_count; face_idx++) { + for (int face_vertex_idx = 0; face_vertex_idx < 3; face_vertex_idx++) { + // We need to reverse the rotation of the shape face vertices. + int index = shape_faces[face_idx * 3 + 2 - face_vertex_idx]; + Point2 p = shape_polygon[index]; + Point2 uv = (p - shape_rect.position) / shape_rect.size; + + // Use the left side of the bottom half of the y-inverted texture. + uv.x = uv.x / 2; + uv.y = 1 - (uv.y / 2); + + facesw[face * 3 + face_vertex_idx] = current_xform.xform(Vector3(p.x, p.y, 0)); + uvsw[face * 3 + face_vertex_idx] = uv; + } - // Create the mesh. - if (end_count > 0) { - // Add front end face. - for (int face_idx = 0; face_idx < shape_face_count; face_idx++) { - for (int face_vertex_idx = 0; face_vertex_idx < 3; face_vertex_idx++) { - // We need to reverse the rotation of the shape face vertices. - int index = shape_faces[face_idx * 3 + 2 - face_vertex_idx]; - Point2 p = shape_polygon[index]; - Point2 uv = (p - shape_rect.position) / shape_rect.size; - - // Use the left side of the bottom half of the y-inverted texture. - uv.x = uv.x / 2; - uv.y = 1 - (uv.y / 2); - - facesw[face * 3 + face_vertex_idx] = current_xform.xform(Vector3(p.x, p.y, 0)); - uvsw[face * 3 + face_vertex_idx] = uv; + smoothw[face] = false; + materialsw[face] = material; + invertw[face] = invert_faces; + face++; } - - smoothw[face] = false; - materialsw[face] = material; - invertw[face] = invert_faces; - face++; } - } - // Add extrusion faces. - for (int x0 = 0; x0 < extrusions; x0++) { - previous_xform = current_xform; - - switch (mode) { - case MODE_DEPTH: { - current_xform.translate(Vector3(0, 0, -depth)); - } break; - case MODE_SPIN: { - current_xform.rotate(Vector3(0, 1, 0), spin_step); - } break; - case MODE_PATH: { - double previous_offset = x0 * extrusion_step; - double current_offset = (x0 + 1) * extrusion_step; - double next_offset = (x0 + 2) * extrusion_step; - if (x0 == extrusions - 1) { - if (path_joined) { - current_offset = 0; - next_offset = extrusion_step; + real_t angle_simplify_dot = Math::cos(Math::deg2rad(path_simplify_angle)); + Vector3 previous_simplify_dir = Vector3(0, 0, 0); + int faces_combined = 0; + + // Add extrusion faces. + for (int x0 = 0; x0 < extrusions; x0++) { + previous_previous_xform = previous_xform; + previous_xform = current_xform; + + switch (mode) { + case MODE_DEPTH: { + current_xform.translate(Vector3(0, 0, -depth)); + } break; + case MODE_SPIN: { + current_xform.rotate(Vector3(0, 1, 0), spin_step); + } break; + case MODE_PATH: { + double previous_offset = x0 * extrusion_step; + double current_offset = (x0 + 1) * extrusion_step; + double next_offset = (x0 + 2) * extrusion_step; + if (x0 == extrusions - 1) { + if (path_joined) { + current_offset = 0; + next_offset = extrusion_step; + } else { + next_offset = current_offset; + } + } + + Vector3 previous_point = curve->interpolate_baked(previous_offset); + Vector3 current_point = curve->interpolate_baked(current_offset); + Vector3 next_point = curve->interpolate_baked(next_offset); + Vector3 current_up = Vector3(0, 1, 0); + Vector3 direction = next_point - previous_point; + Vector3 current_dir = (current_point - previous_point).normalized(); + + // If the angles are similar, remove the previous face and replace it with this one. + if (path_simplify_angle > 0.0 && x0 > 0 && previous_simplify_dir.dot(current_dir) > angle_simplify_dot) { + faces_combined += 1; + previous_xform = previous_previous_xform; + face -= extrusion_face_count; + faces_removed += extrusion_face_count; } else { - next_offset = current_offset; + faces_combined = 0; + previous_simplify_dir = current_dir; } - } - Vector3 previous_point = curve->interpolate_baked(previous_offset); - Vector3 current_point = curve->interpolate_baked(current_offset); - Vector3 next_point = curve->interpolate_baked(next_offset); - Vector3 current_up = Vector3(0, 1, 0); - Vector3 direction = next_point - previous_point; + switch (path_rotation) { + case PATH_ROTATION_POLYGON: + direction = Vector3(0, 0, -1); + break; + case PATH_ROTATION_PATH: + break; + case PATH_ROTATION_PATH_FOLLOW: + current_up = curve->interpolate_baked_up_vector(current_offset); + break; + } - switch (path_rotation) { - case PATH_ROTATION_POLYGON: - direction = Vector3(0, 0, -1); - break; - case PATH_ROTATION_PATH: - break; - case PATH_ROTATION_PATH_FOLLOW: - current_up = curve->interpolate_baked_up_vector(current_offset); - break; - } + Transform3D facing = Transform3D().looking_at(direction, current_up); + current_xform = base_xform.translated(current_point) * facing; + } break; + } - Transform3D facing = Transform3D().looking_at(direction, current_up); - current_xform = base_xform.translated(current_point) * facing; - } break; - } + double u0 = (x0 - faces_combined) * u_step; + double u1 = ((x0 + 1) * u_step); + if (mode == MODE_PATH && !path_continuous_u) { + u0 = 0.0; + u1 = 1.0; + } - double u0 = x0 * u_step; - double u1 = ((x0 + 1) * u_step); - if (mode == MODE_PATH && !path_continuous_u) { - u0 = 0.0; - u1 = 1.0; - } + for (int y0 = 0; y0 < shape_sides; y0++) { + int y1 = (y0 + 1) % shape_sides; + // Use the top half of the texture. + double v0 = (y0 * v_step) / 2; + double v1 = ((y0 + 1) * v_step) / 2; - for (int y0 = 0; y0 < shape_sides; y0++) { - int y1 = (y0 + 1) % shape_sides; - // Use the top half of the texture. - double v0 = (y0 * v_step) / 2; - double v1 = ((y0 + 1) * v_step) / 2; - - Vector3 v[4] = { - previous_xform.xform(Vector3(shape_polygon[y0].x, shape_polygon[y0].y, 0)), - current_xform.xform(Vector3(shape_polygon[y0].x, shape_polygon[y0].y, 0)), - current_xform.xform(Vector3(shape_polygon[y1].x, shape_polygon[y1].y, 0)), - previous_xform.xform(Vector3(shape_polygon[y1].x, shape_polygon[y1].y, 0)), - }; - - Vector2 u[4] = { - Vector2(u0, v0), - Vector2(u1, v0), - Vector2(u1, v1), - Vector2(u0, v1), - }; - - // Face 1 - facesw[face * 3 + 0] = v[0]; - facesw[face * 3 + 1] = v[1]; - facesw[face * 3 + 2] = v[2]; - - uvsw[face * 3 + 0] = u[0]; - uvsw[face * 3 + 1] = u[1]; - uvsw[face * 3 + 2] = u[2]; - - smoothw[face] = smooth_faces; - invertw[face] = invert_faces; - materialsw[face] = material; - - face++; - - // Face 2 - facesw[face * 3 + 0] = v[2]; - facesw[face * 3 + 1] = v[3]; - facesw[face * 3 + 2] = v[0]; - - uvsw[face * 3 + 0] = u[2]; - uvsw[face * 3 + 1] = u[3]; - uvsw[face * 3 + 2] = u[0]; - - smoothw[face] = smooth_faces; - invertw[face] = invert_faces; - materialsw[face] = material; - - face++; - } - } + Vector3 v[4] = { + previous_xform.xform(Vector3(shape_polygon[y0].x, shape_polygon[y0].y, 0)), + current_xform.xform(Vector3(shape_polygon[y0].x, shape_polygon[y0].y, 0)), + current_xform.xform(Vector3(shape_polygon[y1].x, shape_polygon[y1].y, 0)), + previous_xform.xform(Vector3(shape_polygon[y1].x, shape_polygon[y1].y, 0)), + }; - if (end_count > 1) { - // Add back end face. - for (int face_idx = 0; face_idx < shape_face_count; face_idx++) { - for (int face_vertex_idx = 0; face_vertex_idx < 3; face_vertex_idx++) { - int index = shape_faces[face_idx * 3 + face_vertex_idx]; - Point2 p = shape_polygon[index]; - Point2 uv = (p - shape_rect.position) / shape_rect.size; + Vector2 u[4] = { + Vector2(u0, v0), + Vector2(u1, v0), + Vector2(u1, v1), + Vector2(u0, v1), + }; - // Use the x-inverted ride side of the bottom half of the y-inverted texture. - uv.x = 1 - uv.x / 2; - uv.y = 1 - (uv.y / 2); + // Face 1 + facesw[face * 3 + 0] = v[0]; + facesw[face * 3 + 1] = v[1]; + facesw[face * 3 + 2] = v[2]; - facesw[face * 3 + face_vertex_idx] = current_xform.xform(Vector3(p.x, p.y, 0)); - uvsw[face * 3 + face_vertex_idx] = uv; + uvsw[face * 3 + 0] = u[0]; + uvsw[face * 3 + 1] = u[1]; + uvsw[face * 3 + 2] = u[2]; + + smoothw[face] = smooth_faces; + invertw[face] = invert_faces; + materialsw[face] = material; + + face++; + + // Face 2 + facesw[face * 3 + 0] = v[2]; + facesw[face * 3 + 1] = v[3]; + facesw[face * 3 + 2] = v[0]; + + uvsw[face * 3 + 0] = u[2]; + uvsw[face * 3 + 1] = u[3]; + uvsw[face * 3 + 2] = u[0]; + + smoothw[face] = smooth_faces; + invertw[face] = invert_faces; + materialsw[face] = material; + + face++; } + } + + if (end_count > 1) { + // Add back end face. + for (int face_idx = 0; face_idx < shape_face_count; face_idx++) { + for (int face_vertex_idx = 0; face_vertex_idx < 3; face_vertex_idx++) { + int index = shape_faces[face_idx * 3 + face_vertex_idx]; + Point2 p = shape_polygon[index]; + Point2 uv = (p - shape_rect.position) / shape_rect.size; - smoothw[face] = false; - materialsw[face] = material; - invertw[face] = invert_faces; - face++; + // Use the x-inverted ride side of the bottom half of the y-inverted texture. + uv.x = 1 - uv.x / 2; + uv.y = 1 - (uv.y / 2); + + facesw[face * 3 + face_vertex_idx] = current_xform.xform(Vector3(p.x, p.y, 0)); + uvsw[face * 3 + face_vertex_idx] = uv; + } + + smoothw[face] = false; + materialsw[face] = material; + invertw[face] = invert_faces; + face++; + } } + + face_count -= faces_removed; + ERR_FAIL_COND_V_MSG(face != face_count, brush, "Bug: Failed to create the CSGPolygon mesh correctly."); } - ERR_FAIL_COND_V_MSG(face != face_count, brush, "Bug: Failed to create the CSGPolygon mesh correctly."); + if (faces_removed > 0) { + faces.resize(face_count * 3); + uvs.resize(face_count * 3); + smooth.resize(face_count); + materials.resize(face_count); + invert.resize(face_count); + } brush->build_from_faces(faces, uvs, smooth, materials, invert); @@ -2031,9 +2070,15 @@ void CSGPolygon3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_path_node", "path"), &CSGPolygon3D::set_path_node); ClassDB::bind_method(D_METHOD("get_path_node"), &CSGPolygon3D::get_path_node); + ClassDB::bind_method(D_METHOD("set_path_interval_type", "interval_type"), &CSGPolygon3D::set_path_interval_type); + ClassDB::bind_method(D_METHOD("get_path_interval_type"), &CSGPolygon3D::get_path_interval_type); + ClassDB::bind_method(D_METHOD("set_path_interval", "interval"), &CSGPolygon3D::set_path_interval); ClassDB::bind_method(D_METHOD("get_path_interval"), &CSGPolygon3D::get_path_interval); + ClassDB::bind_method(D_METHOD("set_path_simplify_angle", "degrees"), &CSGPolygon3D::set_path_simplify_angle); + ClassDB::bind_method(D_METHOD("get_path_simplify_angle"), &CSGPolygon3D::get_path_simplify_angle); + ClassDB::bind_method(D_METHOD("set_path_rotation", "path_rotation"), &CSGPolygon3D::set_path_rotation); ClassDB::bind_method(D_METHOD("get_path_rotation"), &CSGPolygon3D::get_path_rotation); @@ -2043,6 +2088,9 @@ void CSGPolygon3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_path_continuous_u", "enable"), &CSGPolygon3D::set_path_continuous_u); ClassDB::bind_method(D_METHOD("is_path_continuous_u"), &CSGPolygon3D::is_path_continuous_u); + ClassDB::bind_method(D_METHOD("set_path_u_distance", "distance"), &CSGPolygon3D::set_path_u_distance); + ClassDB::bind_method(D_METHOD("get_path_u_distance"), &CSGPolygon3D::get_path_u_distance); + ClassDB::bind_method(D_METHOD("set_path_joined", "enable"), &CSGPolygon3D::set_path_joined); ClassDB::bind_method(D_METHOD("is_path_joined"), &CSGPolygon3D::is_path_joined); @@ -2061,10 +2109,13 @@ void CSGPolygon3D::_bind_methods() { 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, "Path3D"), "set_path_node", "get_path_node"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_interval", PROPERTY_HINT_RANGE, "0.1,1.0,0.05,exp"), "set_path_interval", "get_path_interval"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "path_interval_type", PROPERTY_HINT_ENUM, "Distance,Subdivide"), "set_path_interval_type", "get_path_interval_type"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_interval", PROPERTY_HINT_RANGE, "0.01,1.0,0.01,exp,or_greater"), "set_path_interval", "get_path_interval"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_simplify_angle", PROPERTY_HINT_RANGE, "0.0,180.0,0.1,exp"), "set_path_simplify_angle", "get_path_simplify_angle"); 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"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_u_distance", PROPERTY_HINT_RANGE, "0.0,10.0,0.01,or_greater"), "set_path_u_distance", "get_path_u_distance"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "path_joined"), "set_path_joined", "is_path_joined"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_faces"), "set_smooth_faces", "get_smooth_faces"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "BaseMaterial3D,ShaderMaterial"), "set_material", "get_material"); @@ -2076,6 +2127,9 @@ void CSGPolygon3D::_bind_methods() { BIND_ENUM_CONSTANT(PATH_ROTATION_POLYGON); BIND_ENUM_CONSTANT(PATH_ROTATION_PATH); BIND_ENUM_CONSTANT(PATH_ROTATION_PATH_FOLLOW); + + BIND_ENUM_CONSTANT(PATH_INTERVAL_DISTANCE); + BIND_ENUM_CONSTANT(PATH_INTERVAL_SUBDIVIDE); } void CSGPolygon3D::set_polygon(const Vector<Vector2> &p_polygon) { @@ -2119,6 +2173,16 @@ bool CSGPolygon3D::is_path_continuous_u() const { return path_continuous_u; } +void CSGPolygon3D::set_path_u_distance(real_t p_path_u_distance) { + path_u_distance = p_path_u_distance; + _make_dirty(); + update_gizmos(); +} + +real_t CSGPolygon3D::get_path_u_distance() const { + return path_u_distance; +} + void CSGPolygon3D::set_spin_degrees(const float p_spin_degrees) { ERR_FAIL_COND(p_spin_degrees < 0.01 || p_spin_degrees > 360); spin_degrees = p_spin_degrees; @@ -2151,8 +2215,17 @@ NodePath CSGPolygon3D::get_path_node() const { return path_node; } +void CSGPolygon3D::set_path_interval_type(PathIntervalType p_interval_type) { + path_interval_type = p_interval_type; + _make_dirty(); + update_gizmos(); +} + +CSGPolygon3D::PathIntervalType CSGPolygon3D::get_path_interval_type() const { + return path_interval_type; +} + void CSGPolygon3D::set_path_interval(float p_interval) { - ERR_FAIL_COND_MSG(p_interval <= 0 || p_interval > 1, "Path interval must be greater than 0 and less than or equal to 1.0."); path_interval = p_interval; _make_dirty(); update_gizmos(); @@ -2162,6 +2235,16 @@ float CSGPolygon3D::get_path_interval() const { return path_interval; } +void CSGPolygon3D::set_path_simplify_angle(float p_angle) { + path_simplify_angle = p_angle; + _make_dirty(); + update_gizmos(); +} + +float CSGPolygon3D::get_path_simplify_angle() const { + return path_simplify_angle; +} + void CSGPolygon3D::set_path_rotation(PathRotation p_rotation) { path_rotation = p_rotation; _make_dirty(); @@ -2229,10 +2312,13 @@ CSGPolygon3D::CSGPolygon3D() { spin_degrees = 360; spin_sides = 8; smooth_faces = false; + path_interval_type = PATH_INTERVAL_DISTANCE; path_interval = 1.0; + path_simplify_angle = 0.0; path_rotation = PATH_ROTATION_PATH_FOLLOW; path_local = false; path_continuous_u = true; + path_u_distance = 1.0; path_joined = false; path = nullptr; } diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h index 5cf371665e..c85cce776b 100644 --- a/modules/csg/csg_shape.h +++ b/modules/csg/csg_shape.h @@ -336,6 +336,11 @@ public: MODE_PATH }; + enum PathIntervalType { + PATH_INTERVAL_DISTANCE, + PATH_INTERVAL_SUBDIVIDE + }; + enum PathRotation { PATH_ROTATION_POLYGON, PATH_ROTATION_PATH, @@ -356,7 +361,9 @@ private: int spin_sides; NodePath path_node; + PathIntervalType path_interval_type; float path_interval; + float path_simplify_angle; PathRotation path_rotation; bool path_local; @@ -364,6 +371,7 @@ private: bool smooth_faces; bool path_continuous_u; + real_t path_u_distance; bool path_joined; bool _is_editable_3d_polygon() const; @@ -396,9 +404,15 @@ public: void set_path_node(const NodePath &p_path); NodePath get_path_node() const; + void set_path_interval_type(PathIntervalType p_interval_type); + PathIntervalType get_path_interval_type() const; + void set_path_interval(float p_interval); float get_path_interval() const; + void set_path_simplify_angle(float p_angle); + float get_path_simplify_angle() const; + void set_path_rotation(PathRotation p_rotation); PathRotation get_path_rotation() const; @@ -408,6 +422,9 @@ public: void set_path_continuous_u(bool p_enable); bool is_path_continuous_u() const; + void set_path_u_distance(real_t p_path_u_distance); + real_t get_path_u_distance() const; + void set_path_joined(bool p_enable); bool is_path_joined() const; @@ -422,5 +439,6 @@ public: VARIANT_ENUM_CAST(CSGPolygon3D::Mode) VARIANT_ENUM_CAST(CSGPolygon3D::PathRotation) +VARIANT_ENUM_CAST(CSGPolygon3D::PathIntervalType) #endif // CSG_SHAPE_H diff --git a/modules/csg/doc_classes/CSGBox3D.xml b/modules/csg/doc_classes/CSGBox3D.xml index 5bb1c4e75b..d64e58ae4d 100644 --- a/modules/csg/doc_classes/CSGBox3D.xml +++ b/modules/csg/doc_classes/CSGBox3D.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="material" type="Material" setter="set_material" getter="get_material"> The material used to render the box. @@ -18,6 +16,4 @@ The box's width, height and depth. </member> </members> - <constants> - </constants> </class> diff --git a/modules/csg/doc_classes/CSGCombiner3D.xml b/modules/csg/doc_classes/CSGCombiner3D.xml index b55111eee4..422c5d35b7 100644 --- a/modules/csg/doc_classes/CSGCombiner3D.xml +++ b/modules/csg/doc_classes/CSGCombiner3D.xml @@ -8,8 +8,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/csg/doc_classes/CSGCylinder3D.xml b/modules/csg/doc_classes/CSGCylinder3D.xml index bfd2a5d5f2..40e989bfb3 100644 --- a/modules/csg/doc_classes/CSGCylinder3D.xml +++ b/modules/csg/doc_classes/CSGCylinder3D.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="cone" type="bool" setter="set_cone" getter="is_cone" default="false"> If [code]true[/code] a cone is created, the [member radius] will only apply to one side. @@ -30,6 +28,4 @@ If [code]true[/code] the normals of the cylinder are set to give a smooth effect making the cylinder seem rounded. If [code]false[/code] the cylinder will have a flat shaded look. </member> </members> - <constants> - </constants> </class> diff --git a/modules/csg/doc_classes/CSGMesh3D.xml b/modules/csg/doc_classes/CSGMesh3D.xml index 5fa8427843..2810343139 100644 --- a/modules/csg/doc_classes/CSGMesh3D.xml +++ b/modules/csg/doc_classes/CSGMesh3D.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="material" type="Material" setter="set_material" getter="get_material"> The [Material] used in drawing the CSG shape. @@ -19,6 +17,4 @@ [b]Note:[/b] When using an [ArrayMesh], avoid meshes with vertex normals unless a flat shader is required. By default, CSGMesh will ignore the mesh's vertex normals and use a smooth shader calculated using the faces' normals. If a flat shader is required, ensure that all faces' vertex normals are parallel. </member> </members> - <constants> - </constants> </class> diff --git a/modules/csg/doc_classes/CSGPolygon3D.xml b/modules/csg/doc_classes/CSGPolygon3D.xml index 5309cde956..ecbb7962d1 100644 --- a/modules/csg/doc_classes/CSGPolygon3D.xml +++ b/modules/csg/doc_classes/CSGPolygon3D.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="depth" type="float" setter="set_depth" getter="get_depth" default="1.0"> When [member mode] is [constant MODE_DEPTH], the depth of the extrusion. @@ -26,6 +24,9 @@ <member name="path_interval" type="float" setter="set_path_interval" getter="get_path_interval"> When [member mode] is [constant MODE_PATH], the path interval or ratio of path points to extrusions. </member> + <member name="path_interval_type" type="int" setter="set_path_interval_type" getter="get_path_interval_type" enum="CSGPolygon3D.PathIntervalType"> + When [member mode] is [constant MODE_PATH], this will determine if the interval should be by distance ([constant PATH_INTERVAL_DISTANCE]) or subdivision fractions ([constant PATH_INTERVAL_SUBDIVIDE]). + </member> <member name="path_joined" type="bool" setter="set_path_joined" getter="is_path_joined"> When [member mode] is [constant MODE_PATH], if [code]true[/code] the ends of the path are joined, by adding an extrusion between the last and first points of the path. </member> @@ -38,6 +39,12 @@ <member name="path_rotation" type="int" setter="set_path_rotation" getter="get_path_rotation" enum="CSGPolygon3D.PathRotation"> When [member mode] is [constant MODE_PATH], the [enum PathRotation] method used to rotate the [member polygon] as it is extruded. </member> + <member name="path_simplify_angle" type="float" setter="set_path_simplify_angle" getter="get_path_simplify_angle"> + When [member mode] is [constant MODE_PATH], extrusions that are less than this angle, will be merged together to reduce polygon count. + </member> + <member name="path_u_distance" type="float" setter="set_path_u_distance" getter="get_path_u_distance"> + When [member mode] is [constant MODE_PATH], this is the distance along the path, in meters, the texture coordinates will tile. When set to 0, texture coordinates will match geometry exactly with no tiling. + </member> <member name="polygon" type="PackedVector2Array" setter="set_polygon" getter="get_polygon" default="PackedVector2Array(0, 0, 0, 1, 1, 1, 1, 0)"> The point array that defines the 2D polygon that is extruded. </member> @@ -72,5 +79,11 @@ <constant name="PATH_ROTATION_PATH_FOLLOW" value="2" enum="PathRotation"> The [member polygon] shape follows the path and its rotations around the path axis. </constant> + <constant name="PATH_INTERVAL_DISTANCE" value="0" enum="PathIntervalType"> + When [member mode] is set to [constant MODE_PATH], [member path_interval] will determine the distance, in meters, each interval of the path will extrude. + </constant> + <constant name="PATH_INTERVAL_SUBDIVIDE" value="1" enum="PathIntervalType"> + When [member mode] is set to [constant MODE_PATH], [member path_interval] will subdivide the polygons along the path. + </constant> </constants> </class> diff --git a/modules/csg/doc_classes/CSGPrimitive3D.xml b/modules/csg/doc_classes/CSGPrimitive3D.xml index 31b7360fac..8f4c8b9451 100644 --- a/modules/csg/doc_classes/CSGPrimitive3D.xml +++ b/modules/csg/doc_classes/CSGPrimitive3D.xml @@ -8,13 +8,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="invert_faces" type="bool" setter="set_invert_faces" getter="is_inverting_faces" default="false"> Invert the faces of the mesh. </member> </members> - <constants> - </constants> </class> diff --git a/modules/csg/doc_classes/CSGSphere3D.xml b/modules/csg/doc_classes/CSGSphere3D.xml index 4d5b3be099..b8dfb4cf5f 100644 --- a/modules/csg/doc_classes/CSGSphere3D.xml +++ b/modules/csg/doc_classes/CSGSphere3D.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="material" type="Material" setter="set_material" getter="get_material"> The material used to render the sphere. @@ -27,6 +25,4 @@ If [code]true[/code] the normals of the sphere are set to give a smooth effect making the sphere seem rounded. If [code]false[/code] the sphere will have a flat shaded look. </member> </members> - <constants> - </constants> </class> diff --git a/modules/csg/doc_classes/CSGTorus3D.xml b/modules/csg/doc_classes/CSGTorus3D.xml index abe3eab913..91ee63a4c9 100644 --- a/modules/csg/doc_classes/CSGTorus3D.xml +++ b/modules/csg/doc_classes/CSGTorus3D.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="inner_radius" type="float" setter="set_inner_radius" getter="get_inner_radius" default="2.0"> The inner radius of the torus. @@ -30,6 +28,4 @@ If [code]true[/code] the normals of the torus are set to give a smooth effect making the torus seem rounded. If [code]false[/code] the torus will have a flat shaded look. </member> </members> - <constants> - </constants> </class> diff --git a/modules/enet/doc_classes/ENetMultiplayerPeer.xml b/modules/enet/doc_classes/ENetMultiplayerPeer.xml index 43e1d40e47..f9659c092a 100644 --- a/modules/enet/doc_classes/ENetMultiplayerPeer.xml +++ b/modules/enet/doc_classes/ENetMultiplayerPeer.xml @@ -77,12 +77,8 @@ <member name="host" type="ENetConnection" setter="" getter="get_host"> The underlying [ENetConnection] created after [method create_client] and [method create_server]. </member> - <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> <member name="server_relay" type="bool" setter="set_server_relay_enabled" getter="is_server_relay_enabled" default="true"> Enable or disable the server feature that notifies clients of other peers' connection/disconnection, and relays messages between them. When this option is [code]false[/code], clients won't be automatically notified of other peers and won't be able to send them packets through the server. </member> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="TransferMode" default="2" /> </members> - <constants> - </constants> </class> diff --git a/modules/enet/doc_classes/ENetPacketPeer.xml b/modules/enet/doc_classes/ENetPacketPeer.xml index 8f0693fb01..4116ba17f2 100644 --- a/modules/enet/doc_classes/ENetPacketPeer.xml +++ b/modules/enet/doc_classes/ENetPacketPeer.xml @@ -6,6 +6,7 @@ <description> A PacketPeer implementation representing a peer of an [ENetConnection]. This class cannot be instantiated directly but can be retrieved during [method ENetConnection.service] or via [method ENetConnection.get_peers]. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> <link title="API documentation on the ENet website">http://enet.bespin.org/usergroup0.html</link> diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index afd31207f6..52eb46f070 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -33,22 +33,6 @@ #include "core/io/marshalls.h" #include "core/os/os.h" -void ENetMultiplayerPeer::set_transfer_channel(int p_channel) { - transfer_channel = p_channel; -} - -int ENetMultiplayerPeer::get_transfer_channel() const { - return transfer_channel; -} - -void ENetMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) { - transfer_mode = p_mode; -} - -Multiplayer::TransferMode ENetMultiplayerPeer::get_transfer_mode() const { - return transfer_mode; -} - void ENetMultiplayerPeer::set_target_peer(int p_peer) { target_peer = p_peer; } @@ -62,6 +46,7 @@ int ENetMultiplayerPeer::get_packet_peer() const { Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) { ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); + set_refuse_new_connections(false); Ref<ENetConnection> host; host.instantiate(); Error err = host->create_host_bound(bind_ip, p_port, p_max_clients, 0, p_max_channels > 0 ? p_max_channels + SYSCH_MAX : 0, p_out_bandwidth); @@ -70,7 +55,6 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma } active_mode = MODE_SERVER; - refuse_connections = false; unique_id = 1; connection_status = CONNECTION_CONNECTED; hosts[0] = host; @@ -79,6 +63,7 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_channel_count, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) { ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); + set_refuse_new_connections(false); Ref<ENetConnection> host; host.instantiate(); Error err; @@ -102,7 +87,6 @@ Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, in // Need to wait for CONNECT event. connection_status = CONNECTION_CONNECTING; active_mode = MODE_CLIENT; - refuse_connections = false; peers[1] = peer; hosts[0] = host; @@ -113,7 +97,6 @@ Error ENetMultiplayerPeer::create_mesh(int p_id) { ERR_FAIL_COND_V_MSG(p_id <= 0, ERR_INVALID_PARAMETER, "The unique ID must be greater then 0"); ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); active_mode = MODE_MESH; - refuse_connections = false; unique_id = p_id; connection_status = CONNECTION_CONNECTED; return OK; @@ -145,7 +128,7 @@ bool ENetMultiplayerPeer::_poll_server() { } switch (ret) { case ENetConnection::EVENT_CONNECT: { - if (refuse_connections) { + if (is_refusing_new_connections()) { event.peer->reset(); return false; } @@ -173,7 +156,7 @@ bool ENetMultiplayerPeer::_poll_server() { emit_signal(SNAME("peer_disconnected"), id); peers.erase(id); - if (!server_relay) { + if (server_relay) { _notify_peers(id, false); } return false; @@ -423,6 +406,7 @@ void ENetMultiplayerPeer::close_connection(uint32_t wait_usec) { hosts.clear(); unique_id = 0; connection_status = CONNECTION_DISCONNECTED; + set_refuse_new_connections(false); } int ENetMultiplayerPeer::get_available_packet_count() const { @@ -451,10 +435,11 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size int packet_flags = 0; int channel = SYSCH_RELIABLE; + int transfer_channel = get_transfer_channel(); if (transfer_channel > 0) { channel = SYSCH_MAX + transfer_channel - 1; } else { - switch (transfer_mode) { + switch (get_transfer_mode()) { case Multiplayer::TRANSFER_MODE_UNRELIABLE: { packet_flags = ENET_PACKET_FLAG_UNSEQUENCED; channel = SYSCH_UNRELIABLE; @@ -545,19 +530,15 @@ int ENetMultiplayerPeer::get_unique_id() const { return unique_id; } -void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enable) { - refuse_connections = p_enable; +void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enabled) { #ifdef GODOT_ENET if (_is_active()) { for (KeyValue<int, Ref<ENetConnection>> &E : hosts) { - E.value->refuse_new_connections(p_enable); + E.value->refuse_new_connections(p_enabled); } } #endif -} - -bool ENetMultiplayerPeer::is_refusing_new_connections() const { - return refuse_connections; + MultiplayerPeer::set_refuse_new_connections(p_enabled); } void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) { diff --git a/modules/enet/enet_multiplayer_peer.h b/modules/enet/enet_multiplayer_peer.h index b5316b8292..7a60e2359c 100644 --- a/modules/enet/enet_multiplayer_peer.h +++ b/modules/enet/enet_multiplayer_peer.h @@ -65,10 +65,7 @@ private: uint32_t unique_id = 0; int target_peer = 0; - int transfer_channel = 0; - Multiplayer::TransferMode transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE; - bool refuse_connections = false; bool server_relay = true; ConnectionStatus connection_status = CONNECTION_DISCONNECTED; @@ -101,40 +98,31 @@ protected: static void _bind_methods(); public: - virtual void set_transfer_channel(int p_channel) override; - virtual int get_transfer_channel() const override; - - virtual void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - virtual Multiplayer::TransferMode get_transfer_mode() const override; virtual void set_target_peer(int p_peer) override; - virtual int get_packet_peer() const override; - Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0); - Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0); - Error create_mesh(int p_id); - Error add_mesh_peer(int p_id, Ref<ENetConnection> p_host); - - void close_connection(uint32_t wait_usec = 100); - - void disconnect_peer(int p_peer, bool now = false); - virtual void poll() override; - virtual bool is_server() const override; + // Overriden so we can instrument the DTLSServer when needed. + virtual void set_refuse_new_connections(bool p_enabled) override; - virtual int get_available_packet_count() const override; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; + virtual ConnectionStatus get_connection_status() const override; + + virtual int get_unique_id() const override; virtual int get_max_packet_size() const override; + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual ConnectionStatus get_connection_status() const override; + Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0); + Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0); + Error create_mesh(int p_id); + Error add_mesh_peer(int p_id, Ref<ENetConnection> p_host); - virtual void set_refuse_new_connections(bool p_enable) override; - virtual bool is_refusing_new_connections() const override; + void close_connection(uint32_t wait_usec = 100); - virtual int get_unique_id() const override; + void disconnect_peer(int p_peer, bool now = false); void set_bind_ip(const IPAddress &p_ip); void set_server_relay_enabled(bool p_enabled); diff --git a/modules/etcpak/image_compress_etcpak.cpp b/modules/etcpak/image_compress_etcpak.cpp index abc3c26188..aff7538fb6 100644 --- a/modules/etcpak/image_compress_etcpak.cpp +++ b/modules/etcpak/image_compress_etcpak.cpp @@ -165,9 +165,9 @@ void _compress_etcpak(EtcpakType p_compresstype, Image *r_img, float p_lossy_qua if (p_compresstype == EtcpakType::ETCPAK_TYPE_ETC1) { CompressEtc1RgbDither(src_mip_read, dest_mip_write, blocks, mip_w); } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_ETC2 || p_compresstype == EtcpakType::ETCPAK_TYPE_ETC2_RA_AS_RG) { - CompressEtc2Rgb(src_mip_read, dest_mip_write, blocks, mip_w); + CompressEtc2Rgb(src_mip_read, dest_mip_write, blocks, mip_w, true); } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_ETC2_ALPHA) { - CompressEtc2Rgba(src_mip_read, dest_mip_write, blocks, mip_w); + CompressEtc2Rgba(src_mip_read, dest_mip_write, blocks, mip_w, true); } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_DXT1) { CompressDxt1Dither(src_mip_read, dest_mip_write, blocks, mip_w); } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_DXT5 || p_compresstype == EtcpakType::ETCPAK_TYPE_DXT5_RA_AS_RG) { diff --git a/modules/fbx/doc_classes/EditorSceneImporterFBX.xml b/modules/fbx/doc_classes/EditorSceneImporterFBX.xml index da1a68c27c..6f83871772 100644 --- a/modules/fbx/doc_classes/EditorSceneImporterFBX.xml +++ b/modules/fbx/doc_classes/EditorSceneImporterFBX.xml @@ -29,8 +29,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 21ee39f3ed..94bda04d12 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -16,7 +16,6 @@ env_gdnative.Prepend(CPPPATH=["#modules/gdnative/include/"]) Export("env_gdnative") -SConscript("net/SCsub") SConscript("pluginscript/SCsub") SConscript("videodecoder/SCsub") SConscript("text/SCsub") diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py index fa985501b5..026a84a70f 100644 --- a/modules/gdnative/config.py +++ b/modules/gdnative/config.py @@ -10,14 +10,9 @@ def get_doc_classes(): return [ "GDNative", "GDNativeLibrary", - "MultiplayerPeerGDNative", "NativeScript", - "PacketPeerGDNative", "PluginScript", - "StreamPeerGDNative", "VideoStreamGDNative", - "WebRTCPeerConnectionGDNative", - "WebRTCDataChannelGDNative", ] diff --git a/modules/gdnative/doc_classes/GDNative.xml b/modules/gdnative/doc_classes/GDNative.xml index e4c5d34a2c..4bc149b119 100644 --- a/modules/gdnative/doc_classes/GDNative.xml +++ b/modules/gdnative/doc_classes/GDNative.xml @@ -30,6 +30,4 @@ <member name="library" type="GDNativeLibrary" setter="set_library" getter="get_library"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gdnative/doc_classes/GDNativeLibrary.xml b/modules/gdnative/doc_classes/GDNativeLibrary.xml index 94eae3cd06..3654870b09 100644 --- a/modules/gdnative/doc_classes/GDNativeLibrary.xml +++ b/modules/gdnative/doc_classes/GDNativeLibrary.xml @@ -45,6 +45,4 @@ On platforms that require statically linking libraries (currently only iOS), each library must have a different [code]symbol_prefix[/code]. </member> </members> - <constants> - </constants> </class> diff --git a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml b/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml deleted file mode 100644 index b88f5e7e1e..0000000000 --- a/modules/gdnative/doc_classes/MultiplayerPeerGDNative.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="MultiplayerPeerGDNative" inherits="MultiplayerPeer" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <constants> - </constants> -</class> diff --git a/modules/gdnative/doc_classes/NativeScript.xml b/modules/gdnative/doc_classes/NativeScript.xml index 397d12a3a9..9d34e89f02 100644 --- a/modules/gdnative/doc_classes/NativeScript.xml +++ b/modules/gdnative/doc_classes/NativeScript.xml @@ -52,6 +52,4 @@ <member name="script_class_name" type="String" setter="set_script_class_name" getter="get_script_class_name" default=""""> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gdnative/doc_classes/PacketPeerGDNative.xml b/modules/gdnative/doc_classes/PacketPeerGDNative.xml deleted file mode 100644 index ea9869cc58..0000000000 --- a/modules/gdnative/doc_classes/PacketPeerGDNative.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="PacketPeerGDNative" inherits="PacketPeer" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <constants> - </constants> -</class> diff --git a/modules/gdnative/doc_classes/PluginScript.xml b/modules/gdnative/doc_classes/PluginScript.xml index 8e28187482..ec80ade394 100644 --- a/modules/gdnative/doc_classes/PluginScript.xml +++ b/modules/gdnative/doc_classes/PluginScript.xml @@ -14,6 +14,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/gdnative/doc_classes/StreamPeerGDNative.xml b/modules/gdnative/doc_classes/StreamPeerGDNative.xml deleted file mode 100644 index de76277fff..0000000000 --- a/modules/gdnative/doc_classes/StreamPeerGDNative.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="StreamPeerGDNative" inherits="StreamPeer" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <constants> - </constants> -</class> diff --git a/modules/gdnative/doc_classes/VideoStreamGDNative.xml b/modules/gdnative/doc_classes/VideoStreamGDNative.xml index 8b1a3210df..dc64e8fc18 100644 --- a/modules/gdnative/doc_classes/VideoStreamGDNative.xml +++ b/modules/gdnative/doc_classes/VideoStreamGDNative.xml @@ -24,6 +24,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/gdnative/doc_classes/WebRTCDataChannelGDNative.xml b/modules/gdnative/doc_classes/WebRTCDataChannelGDNative.xml deleted file mode 100644 index f32a4f0a23..0000000000 --- a/modules/gdnative/doc_classes/WebRTCDataChannelGDNative.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="WebRTCDataChannelGDNative" inherits="WebRTCDataChannel" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <constants> - </constants> -</class> diff --git a/modules/gdnative/doc_classes/WebRTCPeerConnectionGDNative.xml b/modules/gdnative/doc_classes/WebRTCPeerConnectionGDNative.xml deleted file mode 100644 index 82f8633bb6..0000000000 --- a/modules/gdnative/doc_classes/WebRTCPeerConnectionGDNative.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="WebRTCPeerConnectionGDNative" inherits="WebRTCPeerConnection" version="4.0"> - <brief_description> - </brief_description> - <description> - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <constants> - </constants> -</class> diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 66d2dc267d..627883886c 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -5105,97 +5105,6 @@ ] }, { - "name": "net", - "type": "NET", - "version": { - "major": 4, - "minor": 0 - }, - "next": null, - "api": [ - { - "name": "godot_net_bind_stream_peer", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_stream_peer *", - "p_interface" - ] - ] - }, - { - "name": "godot_net_bind_packet_peer", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_packet_peer *", - "p_interface" - ] - ] - }, - { - "name": "godot_net_bind_multiplayer_peer", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_multiplayer_peer *", - "p_interface" - ] - ] - }, - { - "name": "godot_net_set_webrtc_library", - "return_type": "godot_error", - "arguments": [ - [ - "const godot_net_webrtc_library *", - "p_library" - ] - ] - }, - { - "name": "godot_net_bind_webrtc_peer_connection", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_webrtc_peer_connection *", - "p_interface" - ] - ] - }, - { - "name": "godot_net_bind_webrtc_data_channel", - "return_type": "void", - "arguments": [ - [ - "godot_object *", - "p_obj" - ], - [ - "const godot_net_webrtc_data_channel *", - "p_interface" - ] - ] - } - ] - }, - { "name": "text", "type": "TEXT", "version": { diff --git a/modules/gdnative/gdnative_builders.py b/modules/gdnative/gdnative_builders.py index 181fd71b82..4986b173cf 100644 --- a/modules/gdnative/gdnative_builders.py +++ b/modules/gdnative/gdnative_builders.py @@ -20,7 +20,6 @@ def _build_gdnative_api_struct_header(api): "#include <gdnative/gdnative.h>", "#include <android/godot_android.h>", "#include <nativescript/godot_nativescript.h>", - "#include <net/godot_net.h>", "#include <pluginscript/godot_pluginscript.h>", "#include <videodecoder/godot_videodecoder.h>", "#include <text/godot_text.h>", diff --git a/modules/gdnative/include/net/godot_net.h b/modules/gdnative/include/net/godot_net.h deleted file mode 100644 index 3fb7b9e1cc..0000000000 --- a/modules/gdnative/include/net/godot_net.h +++ /dev/null @@ -1,122 +0,0 @@ -/*************************************************************************/ -/* godot_net.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 GODOT_NATIVENET_H -#define GODOT_NATIVENET_H - -#include <gdnative/gdnative.h> - -#ifdef __cplusplus -extern "C" { -#endif - -// For future versions of the API we should only add new functions at the end of the structure and use the -// version info to detect whether a call is available - -// Use these to populate version in your plugin -#define GODOT_NET_API_MAJOR 3 -#define GODOT_NET_API_MINOR 1 - -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - godot_object *data; /* User reference */ - - /* This is StreamPeer */ - godot_error (*get_data)(void *user, uint8_t *p_buffer, int p_bytes); - godot_error (*get_partial_data)(void *user, uint8_t *p_buffer, int p_bytes, int *r_received); - godot_error (*put_data)(void *user, const uint8_t *p_data, int p_bytes); - godot_error (*put_partial_data)(void *user, const uint8_t *p_data, int p_bytes, int *r_sent); - - int (*get_available_bytes)(const void *user); - - void *next; /* For extension? */ -} godot_net_stream_peer; - -/* Binds a StreamPeerGDNative to the provided interface */ -void godot_net_bind_stream_peer(godot_object *p_obj, const godot_net_stream_peer *p_interface); - -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - godot_object *data; /* User reference */ - - /* This is PacketPeer */ - godot_error (*get_packet)(void *, const uint8_t **, int *); - godot_error (*put_packet)(void *, const uint8_t *, int); - godot_int (*get_available_packet_count)(const void *); - godot_int (*get_max_packet_size)(const void *); - - void *next; /* For extension? */ -} godot_net_packet_peer; - -/* Binds a PacketPeerGDNative to the provided interface */ -void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *); - -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - godot_object *data; /* User reference */ - - /* This is PacketPeer */ - godot_error (*get_packet)(void *, const uint8_t **, int *); - godot_error (*put_packet)(void *, const uint8_t *, int); - godot_int (*get_available_packet_count)(const void *); - godot_int (*get_max_packet_size)(const void *); - - /* This is MultiplayerPeer */ - void (*set_transfer_channel)(void *, godot_int); - godot_int (*get_transfer_channel)(void *); - void (*set_transfer_mode)(void *, godot_int); - godot_int (*get_transfer_mode)(const void *); - // 0 = broadcast, 1 = server, <0 = all but abs(value) - void (*set_target_peer)(void *, godot_int); - godot_int (*get_packet_peer)(const void *); - godot_bool (*is_server)(const void *); - void (*poll)(void *); - // Must be > 0, 1 is for server - int32_t (*get_unique_id)(const void *); - void (*set_refuse_new_connections)(void *, godot_bool); - godot_bool (*is_refusing_new_connections)(const void *); - godot_int (*get_connection_status)(const void *); - - void *next; /* For extension? Or maybe not... */ -} godot_net_multiplayer_peer; - -/* Binds a MultiplayerPeerGDNative to the provided interface */ -void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *); - -#ifdef __cplusplus -} -#endif - -// WebRTC Bindings -#include "net/godot_webrtc.h" - -#endif /* GODOT_NATIVENET_H */ diff --git a/modules/gdnative/include/net/godot_webrtc.h b/modules/gdnative/include/net/godot_webrtc.h deleted file mode 100644 index 52006e56ec..0000000000 --- a/modules/gdnative/include/net/godot_webrtc.h +++ /dev/null @@ -1,123 +0,0 @@ -/*************************************************************************/ -/* godot_webrtc.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 GODOT_NATIVEWEBRTC_H -#define GODOT_NATIVEWEBRTC_H - -#include <gdnative/gdnative.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define GODOT_NET_WEBRTC_API_MAJOR 4 -#define GODOT_NET_WEBRTC_API_MINOR 0 - -/* Library Interface (used to set default GDNative WebRTC implementation */ -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - /* Called when the library is unset as default interface via godot_net_set_webrtc_library */ - void (*unregistered)(); - - /* Used by WebRTCPeerConnection create when GDNative is the default implementation. */ - /* Takes a pointer to WebRTCPeerConnectionGDNative, should bind and return OK, failure if binding was unsuccessful. */ - godot_error (*create_peer_connection)(godot_object *); - - void *next; /* For extension */ -} godot_net_webrtc_library; - -/* WebRTCPeerConnection interface */ -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - godot_object *data; /* User reference */ - - /* This is WebRTCPeerConnection */ - godot_int (*get_connection_state)(const void *); - - godot_error (*initialize)(void *, const godot_dictionary *); - godot_object *(*create_data_channel)(void *, const char *p_channel_name, const godot_dictionary *); - godot_error (*create_offer)(void *); - godot_error (*create_answer)(void *); /* unused for now, should be done automatically on set_local_description */ - godot_error (*set_remote_description)(void *, const char *, const char *); - godot_error (*set_local_description)(void *, const char *, const char *); - godot_error (*add_ice_candidate)(void *, const char *, int, const char *); - godot_error (*poll)(void *); - void (*close)(void *); - - void *next; /* For extension? */ -} godot_net_webrtc_peer_connection; - -/* WebRTCDataChannel interface */ -typedef struct { - godot_gdnative_api_version version; /* version of our API */ - - godot_object *data; /* User reference */ - - /* This is PacketPeer */ - godot_error (*get_packet)(void *, const uint8_t **, int *); - godot_error (*put_packet)(void *, const uint8_t *, int); - godot_int (*get_available_packet_count)(const void *); - godot_int (*get_max_packet_size)(const void *); - - /* This is WebRTCDataChannel */ - void (*set_write_mode)(void *, godot_int); - godot_int (*get_write_mode)(const void *); - bool (*was_string_packet)(const void *); - - godot_int (*get_ready_state)(const void *); - const char *(*get_label)(const void *); - bool (*is_ordered)(const void *); - int (*get_id)(const void *); - int (*get_max_packet_life_time)(const void *); - int (*get_max_retransmits)(const void *); - const char *(*get_protocol)(const void *); - bool (*is_negotiated)(const void *); - int (*get_buffered_amount)(const void *); - - godot_error (*poll)(void *); - void (*close)(void *); - - void *next; /* For extension? */ -} godot_net_webrtc_data_channel; - -/* Set the default GDNative library */ -godot_error GDAPI godot_net_set_webrtc_library(const godot_net_webrtc_library *); -/* Binds a WebRTCPeerConnectionGDNative to the provided interface */ -void GDAPI godot_net_bind_webrtc_peer_connection(godot_object *p_obj, const godot_net_webrtc_peer_connection *); -/* Binds a WebRTCDataChannelGDNative to the provided interface */ -void GDAPI godot_net_bind_webrtc_data_channel(godot_object *p_obj, const godot_net_webrtc_data_channel *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/modules/gdnative/net/SCsub b/modules/gdnative/net/SCsub deleted file mode 100644 index b76500c003..0000000000 --- a/modules/gdnative/net/SCsub +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python - -Import("env") -Import("env_gdnative") - -env_net = env_gdnative.Clone() - -has_webrtc = env_net["module_webrtc_enabled"] -if has_webrtc: - env_net.Append(CPPDEFINES=["WEBRTC_GDNATIVE_ENABLED"]) - -env_net.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.cpp b/modules/gdnative/net/multiplayer_peer_gdnative.cpp deleted file mode 100644 index 575d5f5060..0000000000 --- a/modules/gdnative/net/multiplayer_peer_gdnative.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/*************************************************************************/ -/* multiplayer_peer_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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. */ -/*************************************************************************/ - -#include "multiplayer_peer_gdnative.h" - -MultiplayerPeerGDNative::MultiplayerPeerGDNative() { - interface = nullptr; -} - -MultiplayerPeerGDNative::~MultiplayerPeerGDNative() { -} - -void MultiplayerPeerGDNative::set_native_multiplayer_peer(const godot_net_multiplayer_peer *p_interface) { - interface = p_interface; -} - -Error MultiplayerPeerGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size); -} - -Error MultiplayerPeerGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size); -} - -int MultiplayerPeerGDNative::get_max_packet_size() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_max_packet_size(interface->data); -} - -int MultiplayerPeerGDNative::get_available_packet_count() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_available_packet_count(interface->data); -} - -/* MultiplayerPeer */ -void MultiplayerPeerGDNative::set_transfer_channel(int p_channel) { - ERR_FAIL_COND(interface == nullptr); - return interface->set_transfer_channel(interface->data, p_channel); -} - -int MultiplayerPeerGDNative::get_transfer_channel() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_transfer_channel(interface->data); -} - -void MultiplayerPeerGDNative::set_transfer_mode(Multiplayer::TransferMode p_mode) { - ERR_FAIL_COND(interface == nullptr); - interface->set_transfer_mode(interface->data, (godot_int)p_mode); -} - -Multiplayer::TransferMode MultiplayerPeerGDNative::get_transfer_mode() const { - ERR_FAIL_COND_V(interface == nullptr, Multiplayer::TRANSFER_MODE_UNRELIABLE); - return (Multiplayer::TransferMode)interface->get_transfer_mode(interface->data); -} - -void MultiplayerPeerGDNative::set_target_peer(int p_peer_id) { - ERR_FAIL_COND(interface == nullptr); - interface->set_target_peer(interface->data, p_peer_id); -} - -int MultiplayerPeerGDNative::get_packet_peer() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_packet_peer(interface->data); -} - -bool MultiplayerPeerGDNative::is_server() const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->is_server(interface->data); -} - -void MultiplayerPeerGDNative::poll() { - ERR_FAIL_COND(interface == nullptr); - interface->poll(interface->data); -} - -int MultiplayerPeerGDNative::get_unique_id() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_unique_id(interface->data); -} - -void MultiplayerPeerGDNative::set_refuse_new_connections(bool p_enable) { - ERR_FAIL_COND(interface == nullptr); - interface->set_refuse_new_connections(interface->data, p_enable); -} - -bool MultiplayerPeerGDNative::is_refusing_new_connections() const { - ERR_FAIL_COND_V(interface == nullptr, true); - return interface->is_refusing_new_connections(interface->data); -} - -MultiplayerPeer::ConnectionStatus MultiplayerPeerGDNative::get_connection_status() const { - ERR_FAIL_COND_V(interface == nullptr, CONNECTION_DISCONNECTED); - return (ConnectionStatus)interface->get_connection_status(interface->data); -} - -void MultiplayerPeerGDNative::_bind_methods() { - ADD_PROPERTY_DEFAULT("transfer_channel", 0); - ADD_PROPERTY_DEFAULT("transfer_mode", Multiplayer::TRANSFER_MODE_UNRELIABLE); - ADD_PROPERTY_DEFAULT("refuse_new_connections", true); -} - -extern "C" { - -void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *p_impl) { - ((MultiplayerPeerGDNative *)p_obj)->set_native_multiplayer_peer(p_impl); -} -} diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.h b/modules/gdnative/net/multiplayer_peer_gdnative.h deleted file mode 100644 index 33e424d284..0000000000 --- a/modules/gdnative/net/multiplayer_peer_gdnative.h +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************/ -/* multiplayer_peer_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 MULTIPLAYER_PEER_GDNATIVE_H -#define MULTIPLAYER_PEER_GDNATIVE_H - -#include "core/multiplayer/multiplayer_peer.h" -#include "modules/gdnative/gdnative.h" -#include "modules/gdnative/include/net/godot_net.h" - -class MultiplayerPeerGDNative : public MultiplayerPeer { - GDCLASS(MultiplayerPeerGDNative, MultiplayerPeer); - -protected: - static void _bind_methods(); - const godot_net_multiplayer_peer *interface; - -public: - MultiplayerPeerGDNative(); - ~MultiplayerPeerGDNative(); - - /* Sets the interface implementation from GDNative */ - void set_native_multiplayer_peer(const godot_net_multiplayer_peer *p_impl); - - /* Specific to PacketPeer */ - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const override; - virtual int get_available_packet_count() const override; - - /* Specific to MultiplayerPeer */ - virtual void set_transfer_channel(int p_channel) override; - virtual int get_transfer_channel() const override; - virtual void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - virtual Multiplayer::TransferMode get_transfer_mode() const override; - virtual void set_target_peer(int p_peer_id) override; - - virtual int get_packet_peer() const override; - - virtual bool is_server() const override; - - virtual void poll() override; - - virtual int get_unique_id() const override; - - virtual void set_refuse_new_connections(bool p_enable) override; - virtual bool is_refusing_new_connections() const override; - - virtual ConnectionStatus get_connection_status() const override; -}; - -#endif // MULTIPLAYER_PEER_GDNATIVE_H diff --git a/modules/gdnative/net/packet_peer_gdnative.cpp b/modules/gdnative/net/packet_peer_gdnative.cpp deleted file mode 100644 index 3bcdfed8ff..0000000000 --- a/modules/gdnative/net/packet_peer_gdnative.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************/ -/* packet_peer_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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. */ -/*************************************************************************/ - -#include "packet_peer_gdnative.h" - -PacketPeerGDNative::PacketPeerGDNative() { - interface = nullptr; -} - -PacketPeerGDNative::~PacketPeerGDNative() { -} - -void PacketPeerGDNative::set_native_packet_peer(const godot_net_packet_peer *p_impl) { - interface = p_impl; -} - -void PacketPeerGDNative::_bind_methods() { -} - -Error PacketPeerGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size); -} - -Error PacketPeerGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size); -} - -int PacketPeerGDNative::get_max_packet_size() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_max_packet_size(interface->data); -} - -int PacketPeerGDNative::get_available_packet_count() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_available_packet_count(interface->data); -} - -extern "C" { - -void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *p_impl) { - ((PacketPeerGDNative *)p_obj)->set_native_packet_peer(p_impl); -} -} diff --git a/modules/gdnative/net/packet_peer_gdnative.h b/modules/gdnative/net/packet_peer_gdnative.h deleted file mode 100644 index 29013f9367..0000000000 --- a/modules/gdnative/net/packet_peer_gdnative.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************/ -/* packet_peer_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 PACKET_PEER_GDNATIVE_H -#define PACKET_PEER_GDNATIVE_H - -#include "core/io/packet_peer.h" -#include "modules/gdnative/gdnative.h" -#include "modules/gdnative/include/net/godot_net.h" - -class PacketPeerGDNative : public PacketPeer { - GDCLASS(PacketPeerGDNative, PacketPeer); - -protected: - static void _bind_methods(); - const godot_net_packet_peer *interface; - -public: - PacketPeerGDNative(); - ~PacketPeerGDNative(); - - /* Sets the interface implementation from GDNative */ - void set_native_packet_peer(const godot_net_packet_peer *p_impl); - - /* Specific to PacketPeer */ - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const override; - virtual int get_available_packet_count() const override; -}; - -#endif // PACKET_PEER_GDNATIVE_H diff --git a/modules/gdnative/net/register_types.cpp b/modules/gdnative/net/register_types.cpp deleted file mode 100644 index 46c383e5ae..0000000000 --- a/modules/gdnative/net/register_types.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/*************************************************************************/ -/* register_types.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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. */ -/*************************************************************************/ - -#include "register_types.h" -#include "multiplayer_peer_gdnative.h" -#include "packet_peer_gdnative.h" -#include "stream_peer_gdnative.h" - -void register_net_types() { - GDREGISTER_CLASS(MultiplayerPeerGDNative); - GDREGISTER_CLASS(PacketPeerGDNative); - GDREGISTER_CLASS(StreamPeerGDNative); -} - -void unregister_net_types() { -} diff --git a/modules/gdnative/net/register_types.h b/modules/gdnative/net/register_types.h deleted file mode 100644 index c99c6f6fbf..0000000000 --- a/modules/gdnative/net/register_types.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************/ -/* register_types.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 NET_REGISTER_TYPES_H -#define NET_REGISTER_TYPES_H - -void register_net_types(); -void unregister_net_types(); - -#endif // NET_REGISTER_TYPES_H diff --git a/modules/gdnative/net/stream_peer_gdnative.cpp b/modules/gdnative/net/stream_peer_gdnative.cpp deleted file mode 100644 index 72ab72323d..0000000000 --- a/modules/gdnative/net/stream_peer_gdnative.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************/ -/* stream_peer_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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. */ -/*************************************************************************/ - -#include "stream_peer_gdnative.h" - -StreamPeerGDNative::StreamPeerGDNative() { - interface = nullptr; -} - -StreamPeerGDNative::~StreamPeerGDNative() { -} - -void StreamPeerGDNative::set_native_stream_peer(const godot_net_stream_peer *p_interface) { - interface = p_interface; -} - -void StreamPeerGDNative::_bind_methods() { -} - -Error StreamPeerGDNative::put_data(const uint8_t *p_data, int p_bytes) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)(interface->put_data(interface->data, p_data, p_bytes)); -} - -Error StreamPeerGDNative::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)(interface->put_partial_data(interface->data, p_data, p_bytes, &r_sent)); -} - -Error StreamPeerGDNative::get_data(uint8_t *p_buffer, int p_bytes) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)(interface->get_data(interface->data, p_buffer, p_bytes)); -} - -Error StreamPeerGDNative::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)(interface->get_partial_data(interface->data, p_buffer, p_bytes, &r_received)); -} - -int StreamPeerGDNative::get_available_bytes() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_available_bytes(interface->data); -} - -extern "C" { - -void GDAPI godot_net_bind_stream_peer(godot_object *p_obj, const godot_net_stream_peer *p_interface) { - ((StreamPeerGDNative *)p_obj)->set_native_stream_peer(p_interface); -} -} diff --git a/modules/gdnative/net/stream_peer_gdnative.h b/modules/gdnative/net/stream_peer_gdnative.h deleted file mode 100644 index dd5abceb83..0000000000 --- a/modules/gdnative/net/stream_peer_gdnative.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************/ -/* stream_peer_gdnative.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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 STREAM_PEER_GDNATIVE_H -#define STREAM_PEER_GDNATIVE_H - -#include "core/io/stream_peer.h" -#include "modules/gdnative/gdnative.h" -#include "modules/gdnative/include/net/godot_net.h" - -class StreamPeerGDNative : public StreamPeer { - GDCLASS(StreamPeerGDNative, StreamPeer); - -protected: - static void _bind_methods(); - const godot_net_stream_peer *interface; - -public: - StreamPeerGDNative(); - ~StreamPeerGDNative(); - - /* Sets the interface implementation from GDNative */ - void set_native_stream_peer(const godot_net_stream_peer *p_interface); - - /* Specific to StreamPeer */ - Error put_data(const uint8_t *p_data, int p_bytes) override; - Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) override; - Error get_data(uint8_t *p_buffer, int p_bytes) override; - Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) override; - int get_available_bytes() const override; -}; - -#endif // STREAM_PEER_GDNATIVE_H diff --git a/modules/gdnative/net/webrtc_gdnative.cpp b/modules/gdnative/net/webrtc_gdnative.cpp deleted file mode 100644 index 76ccbad009..0000000000 --- a/modules/gdnative/net/webrtc_gdnative.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************/ -/* webrtc_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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. */ -/*************************************************************************/ - -#include "modules/gdnative/gdnative.h" -#include "modules/gdnative/include/net/godot_net.h" - -#ifdef WEBRTC_GDNATIVE_ENABLED -#include "modules/webrtc/webrtc_data_channel_gdnative.h" -#include "modules/webrtc/webrtc_peer_connection_gdnative.h" -#endif - -extern "C" { - -void GDAPI godot_net_bind_webrtc_peer_connection(godot_object *p_obj, const godot_net_webrtc_peer_connection *p_impl) { -#ifdef WEBRTC_GDNATIVE_ENABLED - ((WebRTCPeerConnectionGDNative *)p_obj)->set_native_webrtc_peer_connection(p_impl); -#endif -} - -void GDAPI godot_net_bind_webrtc_data_channel(godot_object *p_obj, const godot_net_webrtc_data_channel *p_impl) { -#ifdef WEBRTC_GDNATIVE_ENABLED - ((WebRTCDataChannelGDNative *)p_obj)->set_native_webrtc_data_channel(p_impl); -#endif -} - -godot_error GDAPI godot_net_set_webrtc_library(const godot_net_webrtc_library *p_lib) { -#ifdef WEBRTC_GDNATIVE_ENABLED - return (godot_error)WebRTCPeerConnectionGDNative::set_default_library(p_lib); -#else - return (godot_error)ERR_UNAVAILABLE; -#endif -} -} diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index e4c2b20224..a4ab5663ef 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -35,7 +35,6 @@ #include "gdnative.h" #include "nativescript/register_types.h" -#include "net/register_types.h" #include "pluginscript/register_types.h" #include "videodecoder/register_types.h" @@ -265,7 +264,6 @@ void register_gdnative_types() { GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall); - register_net_types(); register_nativescript_types(); register_pluginscript_types(); register_videodecoder_types(); @@ -329,7 +327,6 @@ void unregister_gdnative_types() { unregister_videodecoder_types(); unregister_pluginscript_types(); unregister_nativescript_types(); - unregister_net_types(); memdelete(GDNativeCallRegistry::singleton); diff --git a/modules/gdscript/doc_classes/GDScript.xml b/modules/gdscript/doc_classes/GDScript.xml index 72738f027a..d45202bd40 100644 --- a/modules/gdscript/doc_classes/GDScript.xml +++ b/modules/gdscript/doc_classes/GDScript.xml @@ -30,6 +30,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index ab441d194a..6529154e5c 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -467,7 +467,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { List<StringName> global_classes; ScriptServer::get_global_class_list(&global_classes); for (const StringName &E : global_classes) { - keywords[String(E)] = usertype_color; + keywords[E] = usertype_color; } /* Autoloads. */ @@ -486,7 +486,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { List<String> core_types; gdscript->get_core_type_words(&core_types); for (const String &E : core_types) { - keywords[E] = basetype_color; + keywords[StringName(E)] = basetype_color; } /* Reserved words. */ @@ -496,9 +496,9 @@ void GDScriptSyntaxHighlighter::_update_cache() { gdscript->get_reserved_words(&keyword_list); for (const String &E : keyword_list) { if (gdscript->is_control_flow_keyword(E)) { - keywords[E] = control_flow_keyword_color; + keywords[StringName(E)] = control_flow_keyword_color; } else { - keywords[E] = keyword_color; + keywords[StringName(E)] = keyword_color; } } diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h index fabd64dab8..07f21b34ae 100644 --- a/modules/gdscript/editor/gdscript_highlighter.h +++ b/modules/gdscript/editor/gdscript_highlighter.h @@ -47,8 +47,8 @@ private: Vector<ColorRegion> color_regions; Map<int, int> color_region_cache; - Dictionary keywords; - Dictionary member_keywords; + HashMap<StringName, Color> keywords; + HashMap<StringName, Color> member_keywords; enum Type { NONE, diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index e785151a6b..23e88ae059 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -1187,12 +1187,28 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) { } } - if (!list_resolved) { + GDScriptParser::DataType variable_type; + if (list_resolved) { + variable_type.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED; + variable_type.kind = GDScriptParser::DataType::BUILTIN; + variable_type.builtin_type = Variant::INT; // Can this ever be a float or something else? + p_for->variable->set_datatype(variable_type); + } else { resolve_node(p_for->list); + if (p_for->list->datatype.has_container_element_type()) { + variable_type = p_for->list->datatype.get_container_element_type(); + variable_type.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED; + } else if (p_for->list->datatype.is_typed_container_type()) { + variable_type = p_for->list->datatype.get_typed_container_type(); + variable_type.type_source = GDScriptParser::DataType::ANNOTATED_INFERRED; + } else { + // Last resort + // TODO: Must other cases be handled? Must we mark as unsafe? + variable_type.type_source = GDScriptParser::DataType::UNDETECTED; + variable_type.kind = GDScriptParser::DataType::VARIANT; + } } - - // TODO: If list is a typed array, the variable should be an element. - // Also applicable for constant range() (so variable is int or float). + p_for->variable->set_datatype(variable_type); resolve_suite(p_for->loop); p_for->set_datatype(p_for->loop->get_datatype()); @@ -1480,8 +1496,7 @@ void GDScriptAnalyzer::resolve_parameter(GDScriptParser::ParameterNode *p_parame } if (p_parameter->datatype_specifier != nullptr) { - resolve_datatype(p_parameter->datatype_specifier); - result = p_parameter->datatype_specifier->get_datatype(); + result = resolve_datatype(p_parameter->datatype_specifier); result.is_meta_type = false; if (p_parameter->default_value != nullptr) { @@ -1739,7 +1754,6 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assig } else { // TODO: Warning in this case. mark_node_unsafe(p_assignment); - p_assignment->use_conversion_assign = true; } } } else { @@ -1767,6 +1781,15 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assig identifier->variable_source->set_datatype(id_type); } } break; + case GDScriptParser::IdentifierNode::FUNCTION_PARAMETER: { + GDScriptParser::DataType id_type = identifier->parameter_source->get_datatype(); + if (!id_type.is_hard_type()) { + id_type = assigned_value_type; + id_type.type_source = GDScriptParser::DataType::INFERRED; + id_type.is_constant = false; + identifier->parameter_source->set_datatype(id_type); + } + } break; case GDScriptParser::IdentifierNode::LOCAL_VARIABLE: { GDScriptParser::DataType id_type = identifier->variable_source->get_datatype(); if (!id_type.is_hard_type()) { @@ -2428,13 +2451,15 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod p_identifier->is_constant = true; p_identifier->reduced_value = result; p_identifier->set_datatype(type_from_variant(result, p_identifier)); - } else { + } else if (base.is_hard_type()) { push_error(vformat(R"(Cannot find constant "%s" on type "%s".)", name, base.to_string()), p_identifier); } } else { switch (base.builtin_type) { case Variant::NIL: { - push_error(vformat(R"(Invalid get index "%s" on base Nil)", name), p_identifier); + if (base.is_hard_type()) { + push_error(vformat(R"(Invalid get index "%s" on base Nil)", name), p_identifier); + } return; } case Variant::DICTIONARY: { @@ -2455,7 +2480,9 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod return; } } - push_error(vformat(R"(Cannot find property "%s" on base "%s".)", name, base.to_string()), p_identifier); + if (base.is_hard_type()) { + push_error(vformat(R"(Cannot find property "%s" on base "%s".)", name, base.to_string()), p_identifier); + } } } } diff --git a/modules/gdscript/gdscript_cache.cpp b/modules/gdscript/gdscript_cache.cpp index 07f50d14dc..8121053245 100644 --- a/modules/gdscript/gdscript_cache.cpp +++ b/modules/gdscript/gdscript_cache.cpp @@ -51,7 +51,9 @@ GDScriptParser *GDScriptParserRef::get_parser() const { Error GDScriptParserRef::raise_status(Status p_new_status) { ERR_FAIL_COND_V(parser == nullptr, ERR_INVALID_DATA); - Error result = OK; + if (result != OK) { + return result; + } while (p_new_status > status) { switch (status) { @@ -86,14 +88,6 @@ Error GDScriptParserRef::raise_status(Status p_new_status) { } } if (result != OK) { - if (parser != nullptr) { - memdelete(parser); - parser = nullptr; - } - if (analyzer != nullptr) { - memdelete(analyzer); - analyzer = nullptr; - } return result; } } diff --git a/modules/gdscript/gdscript_cache.h b/modules/gdscript/gdscript_cache.h index 943638d29f..9fb661d031 100644 --- a/modules/gdscript/gdscript_cache.h +++ b/modules/gdscript/gdscript_cache.h @@ -54,6 +54,7 @@ private: GDScriptParser *parser = nullptr; GDScriptAnalyzer *analyzer = nullptr; Status status = EMPTY; + Error result = OK; String path; friend class GDScriptCache; diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index f79e5726ce..2f8a054b2a 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -781,6 +781,9 @@ static void _find_identifiers_in_class(const GDScriptParser::ClassNode *p_class, if (p_only_functions) { continue; } + if (r_result.has(member.constant->identifier->name)) { + continue; + } option = ScriptCodeCompletionOption(member.constant->identifier->name, ScriptCodeCompletionOption::KIND_CONSTANT); if (member.constant->initializer) { option.default_value = member.constant->initializer->reduced_value; diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index d555be1e8d..025accf4ba 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -579,7 +579,7 @@ void GDScriptParser::parse_program() { } } - parse_class_body(); + parse_class_body(true); #ifdef TOOLS_ENABLED for (Map<int, GDScriptTokenizer::CommentData>::Element *E = tokenizer.get_comments().front(); E; E = E->next()) { @@ -615,9 +615,10 @@ GDScriptParser::ClassNode *GDScriptParser::parse_class() { } consume(GDScriptTokenizer::Token::COLON, R"(Expected ":" after class declaration.)"); - consume(GDScriptTokenizer::Token::NEWLINE, R"(Expected newline after class declaration.)"); - if (!consume(GDScriptTokenizer::Token::INDENT, R"(Expected indented block after class declaration.)")) { + bool multiline = match(GDScriptTokenizer::Token::NEWLINE); + + if (multiline && !consume(GDScriptTokenizer::Token::INDENT, R"(Expected indented block after class declaration.)")) { current_class = previous_class; return n_class; } @@ -630,9 +631,11 @@ GDScriptParser::ClassNode *GDScriptParser::parse_class() { end_statement("superclass"); } - parse_class_body(); + parse_class_body(multiline); - consume(GDScriptTokenizer::Token::DEDENT, R"(Missing unindent at the end of the class body.)"); + if (multiline) { + consume(GDScriptTokenizer::Token::DEDENT, R"(Missing unindent at the end of the class body.)"); + } current_class = previous_class; return n_class; @@ -747,7 +750,7 @@ void GDScriptParser::parse_class_member(T *(GDScriptParser::*p_parse_function)() } } -void GDScriptParser::parse_class_body() { +void GDScriptParser::parse_class_body(bool p_is_multiline) { bool class_end = false; while (!class_end && !is_at_end()) { switch (current.type) { @@ -793,6 +796,9 @@ void GDScriptParser::parse_class_body() { if (panic_mode) { synchronize(); } + if (!p_is_multiline) { + class_end = true; + } } } @@ -1053,7 +1059,9 @@ GDScriptParser::SignalNode *GDScriptParser::parse_signal() { SignalNode *signal = alloc_node<SignalNode>(); signal->identifier = parse_identifier(); - if (match(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) { + if (check(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) { + push_multiline(true); + advance(); do { if (check(GDScriptTokenizer::Token::PARENTHESIS_CLOSE)) { // Allow for trailing comma. @@ -1076,6 +1084,7 @@ GDScriptParser::SignalNode *GDScriptParser::parse_signal() { } } while (match(GDScriptTokenizer::Token::COMMA) && !is_at_end()); + pop_multiline(); consume(GDScriptTokenizer::Token::PARENTHESIS_CLOSE, R"*(Expected closing ")" after signal parameters.)*"); } @@ -1358,6 +1367,9 @@ GDScriptParser::SuiteNode *GDScriptParser::parse_suite(const String &p_context, int error_count = 0; do { + if (!multiline && previous.type == GDScriptTokenizer::Token::SEMICOLON && check(GDScriptTokenizer::Token::NEWLINE)) { + break; + } Node *statement = parse_statement(); if (statement == nullptr) { if (error_count++ > 100) { @@ -1398,7 +1410,7 @@ GDScriptParser::SuiteNode *GDScriptParser::parse_suite(const String &p_context, break; } - } while (multiline && !check(GDScriptTokenizer::Token::DEDENT) && !lambda_ended && !is_at_end()); + } while ((multiline || previous.type == GDScriptTokenizer::Token::SEMICOLON) && !check(GDScriptTokenizer::Token::DEDENT) && !lambda_ended && !is_at_end()); if (multiline) { if (!lambda_ended) { @@ -2592,6 +2604,10 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_subscript(ExpressionNode * subscript->base = p_previous_operand; subscript->index = parse_expression(false); + if (subscript->index == nullptr) { + push_error(R"(Expected expression after "[".)"); + } + pop_multiline(); consume(GDScriptTokenizer::Token::BRACKET_CLOSE, R"(Expected "]" after subscription index.)"); @@ -2806,6 +2822,11 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_lambda(ExpressionNode *p_p return lambda; } +GDScriptParser::ExpressionNode *GDScriptParser::parse_yield(ExpressionNode *p_previous_operand, bool p_can_assign) { + push_error(R"("yield" was removed in Godot 4.0. Use "await" instead.)"); + return nullptr; +} + GDScriptParser::ExpressionNode *GDScriptParser::parse_invalid_token(ExpressionNode *p_previous_operand, bool p_can_assign) { // Just for better error messages. GDScriptTokenizer::Token::Type invalid = previous.type; @@ -3162,7 +3183,7 @@ GDScriptParser::ParseRule *GDScriptParser::get_rule(GDScriptTokenizer::Token::Ty { nullptr, nullptr, PREC_NONE }, // TRAIT, { nullptr, nullptr, PREC_NONE }, // VAR, { nullptr, nullptr, PREC_NONE }, // VOID, - { nullptr, nullptr, PREC_NONE }, // YIELD, + { &GDScriptParser::parse_yield, nullptr, PREC_NONE }, // YIELD, // Punctuation { &GDScriptParser::parse_array, &GDScriptParser::parse_subscript, PREC_SUBSCRIPT }, // BRACKET_OPEN, { nullptr, nullptr, PREC_NONE }, // BRACKET_CLOSE, @@ -3587,6 +3608,39 @@ String GDScriptParser::DataType::to_string() const { ERR_FAIL_V_MSG("<unresolved type", "Kind set outside the enum range."); } +static Variant::Type _variant_type_to_typed_array_element_type(Variant::Type p_type) { + switch (p_type) { + case Variant::PACKED_BYTE_ARRAY: + case Variant::PACKED_INT32_ARRAY: + case Variant::PACKED_INT64_ARRAY: + return Variant::INT; + case Variant::PACKED_FLOAT32_ARRAY: + case Variant::PACKED_FLOAT64_ARRAY: + return Variant::FLOAT; + case Variant::PACKED_STRING_ARRAY: + return Variant::STRING; + case Variant::PACKED_VECTOR2_ARRAY: + return Variant::VECTOR2; + case Variant::PACKED_VECTOR3_ARRAY: + return Variant::VECTOR3; + case Variant::PACKED_COLOR_ARRAY: + return Variant::COLOR; + default: + return Variant::NIL; + } +} + +bool GDScriptParser::DataType::is_typed_container_type() const { + return kind == GDScriptParser::DataType::BUILTIN && _variant_type_to_typed_array_element_type(builtin_type) != Variant::NIL; +} + +GDScriptParser::DataType GDScriptParser::DataType::get_typed_container_type() const { + GDScriptParser::DataType type; + type.kind = GDScriptParser::DataType::BUILTIN; + type.builtin_type = _variant_type_to_typed_array_element_type(builtin_type); + return type; +} + /*---------- PRETTY PRINT FOR DEBUG ----------*/ #ifdef DEBUG_ENABLED diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 4902f0d4a6..593fb0cc5e 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -161,6 +161,10 @@ public: container_element_type = nullptr; } + bool is_typed_container_type() const; + + GDScriptParser::DataType get_typed_container_type() const; + bool operator==(const DataType &p_other) const { if (type_source == UNDETECTED || p_other.type_source == UNDETECTED) { return true; // Can be consireded equal for parsing purposes. @@ -1320,7 +1324,7 @@ private: ClassNode *parse_class(); void parse_class_name(); void parse_extends(); - void parse_class_body(); + void parse_class_body(bool p_is_multiline); template <class T> void parse_class_member(T *(GDScriptParser::*p_parse_function)(), AnnotationInfo::TargetKind p_target, const String &p_member_kind); SignalNode *parse_signal(); @@ -1384,6 +1388,7 @@ private: ExpressionNode *parse_attribute(ExpressionNode *p_previous_operand, bool p_can_assign); ExpressionNode *parse_subscript(ExpressionNode *p_previous_operand, bool p_can_assign); ExpressionNode *parse_lambda(ExpressionNode *p_previous_operand, bool p_can_assign); + ExpressionNode *parse_yield(ExpressionNode *p_previous_operand, bool p_can_assign); ExpressionNode *parse_invalid_token(ExpressionNode *p_previous_operand, bool p_can_assign); TypeNode *parse_type(bool p_allow_void = false); #ifdef TOOLS_ENABLED diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index bf21c8510a..6186d0edee 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -88,9 +88,9 @@ static String _get_var_type(const Variant *p_var) { Object *bobj = p_var->get_validated_object_with_check(was_freed); if (!bobj) { if (was_freed) { - basestr = "null instance"; - } else { basestr = "previously freed"; + } else { + basestr = "null instance"; } } else { basestr = bobj->get_class(); @@ -1233,7 +1233,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(to_type < 0 || to_type >= Variant::VARIANT_MAX); #ifdef DEBUG_ENABLED - if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + if (src->operator Object *() && !src->get_validated_object()) { err_text = "Trying to cast a freed object."; OPCODE_BREAK; } @@ -1263,7 +1263,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(!nc); #ifdef DEBUG_ENABLED - if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + if (src->operator Object *() && !src->get_validated_object()) { err_text = "Trying to cast a freed object."; OPCODE_BREAK; } @@ -1295,7 +1295,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a GD_ERR_BREAK(!base_type); #ifdef DEBUG_ENABLED - if (src->get_type() == Variant::OBJECT && !src->operator ObjectID().is_ref_counted() && ObjectDB::get_instance(src->operator ObjectID()) == nullptr) { + if (src->operator Object *() && !src->get_validated_object()) { err_text = "Trying to cast a freed object."; OPCODE_BREAK; } @@ -2138,7 +2138,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a retvalue = gdfs; - Error err = sig.connect(Callable(gdfs.ptr(), "_signal_callback"), varray(gdfs), Object::CONNECT_ONESHOT); + Error err = sig.connect(callable_bind(Callable(gdfs.ptr(), "_signal_callback"), retvalue), Object::CONNECT_ONESHOT); if (err != OK) { err_text = "Error connecting to signal: " + sig.get_name() + " during await."; OPCODE_BREAK; diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp index b6c48468f5..bd5a9f01b2 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.cpp +++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp @@ -284,6 +284,23 @@ void GDScriptLanguageProtocol::notify_client(const String &p_method, const Varia peer->res_queue.push_back(msg.utf8()); } +void GDScriptLanguageProtocol::request_client(const String &p_method, const Variant &p_params, int p_client_id) { + if (p_client_id == -1) { + ERR_FAIL_COND_MSG(latest_client_id == -1, + "GDScript LSP: Can't notify client as none was connected."); + p_client_id = latest_client_id; + } + ERR_FAIL_COND(!clients.has(p_client_id)); + Ref<LSPeer> peer = clients.get(p_client_id); + ERR_FAIL_COND(peer == nullptr); + + Dictionary message = make_request(p_method, p_params, next_server_id); + next_server_id++; + String msg = Variant(message).to_json_string(); + msg = format_output(msg); + peer->res_queue.push_back(msg.utf8()); +} + bool GDScriptLanguageProtocol::is_smart_resolve_enabled() const { return bool(_EDITOR_GET("network/language_server/enable_smart_resolve")); } diff --git a/modules/gdscript/language_server/gdscript_language_protocol.h b/modules/gdscript/language_server/gdscript_language_protocol.h index 5a2dd55c46..899446fb42 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.h +++ b/modules/gdscript/language_server/gdscript_language_protocol.h @@ -79,6 +79,8 @@ private: int latest_client_id = 0; int next_client_id = 0; + int next_server_id = 0; + Ref<GDScriptTextDocument> text_document; Ref<GDScriptWorkspace> workspace; @@ -107,6 +109,7 @@ public: void stop(); void notify_client(const String &p_method, const Variant &p_params = Variant(), int p_client_id = -1); + void request_client(const String &p_method, const Variant &p_params = Variant(), int p_client_id = -1); bool is_smart_resolve_enabled() const; bool is_goto_native_symbols_enabled() const; diff --git a/modules/gdscript/language_server/gdscript_language_server.cpp b/modules/gdscript/language_server/gdscript_language_server.cpp index c47164d95b..41a2f9e4ad 100644 --- a/modules/gdscript/language_server/gdscript_language_server.cpp +++ b/modules/gdscript/language_server/gdscript_language_server.cpp @@ -36,6 +36,7 @@ #include "editor/editor_node.h" GDScriptLanguageServer::GDScriptLanguageServer() { + _EDITOR_DEF("network/language_server/remote_host", host); _EDITOR_DEF("network/language_server/remote_port", port); _EDITOR_DEF("network/language_server/enable_smart_resolve", true); _EDITOR_DEF("network/language_server/show_native_symbols_in_editor", false); @@ -56,9 +57,10 @@ void GDScriptLanguageServer::_notification(int p_what) { } } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + String host = String(_EDITOR_GET("network/language_server/remote_host")); int port = (int)_EDITOR_GET("network/language_server/remote_port"); bool use_thread = (bool)_EDITOR_GET("network/language_server/use_thread"); - if (port != this->port || use_thread != this->use_thread) { + if (host != this->host || port != this->port || use_thread != this->use_thread) { this->stop(); this->start(); } @@ -76,9 +78,10 @@ void GDScriptLanguageServer::thread_main(void *p_userdata) { } void GDScriptLanguageServer::start() { + host = String(_EDITOR_GET("network/language_server/remote_host")); port = (int)_EDITOR_GET("network/language_server/remote_port"); use_thread = (bool)_EDITOR_GET("network/language_server/use_thread"); - if (protocol.start(port, IPAddress("127.0.0.1")) == OK) { + if (protocol.start(port, IPAddress(host)) == OK) { EditorNode::get_log()->add_message("--- GDScript language server started ---", EditorLog::MSG_TYPE_EDITOR); if (use_thread) { thread_running = true; diff --git a/modules/gdscript/language_server/gdscript_language_server.h b/modules/gdscript/language_server/gdscript_language_server.h index 29c5ddd70e..85a44a8cc1 100644 --- a/modules/gdscript/language_server/gdscript_language_server.h +++ b/modules/gdscript/language_server/gdscript_language_server.h @@ -44,6 +44,7 @@ class GDScriptLanguageServer : public EditorPlugin { bool thread_running = false; bool started = false; bool use_thread = false; + String host = "127.0.0.1"; int port = 6008; static void thread_main(void *p_userdata); diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index 1512b4bb89..86b3a3a326 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -42,6 +42,7 @@ #include "scene/resources/packed_scene.h" void GDScriptWorkspace::_bind_methods() { + ClassDB::bind_method(D_METHOD("apply_new_signal"), &GDScriptWorkspace::apply_new_signal); ClassDB::bind_method(D_METHOD("didDeleteFiles"), &GDScriptWorkspace::did_delete_files); ClassDB::bind_method(D_METHOD("symbol"), &GDScriptWorkspace::symbol); ClassDB::bind_method(D_METHOD("parse_script", "path", "content"), &GDScriptWorkspace::parse_script); @@ -52,6 +53,54 @@ void GDScriptWorkspace::_bind_methods() { ClassDB::bind_method(D_METHOD("generate_script_api", "path"), &GDScriptWorkspace::generate_script_api); } +void GDScriptWorkspace::apply_new_signal(Object *obj, String function, PackedStringArray args) { + String function_signature = "func " + function; + Ref<Script> script = obj->get_script(); + + String source = script->get_source_code(); + + if (source.find(function_signature) != -1) { + return; + } + + int first_class = source.find("\nclass "); + int start_line = 0; + if (first_class != -1) { + start_line = source.substr(0, first_class).split("\n").size(); + } else { + start_line = source.split("\n").size(); + } + + String function_body = "\n\n" + function_signature + "("; + for (int i = 0; i < args.size(); ++i) { + function_body += args[i]; + if (i < args.size() - 1) { + function_body += ", "; + } + } + function_body += ")"; + if (EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints")) { + function_body += " -> void"; + } + function_body += ":\n\tpass # Replace with function body.\n"; + + lsp::TextEdit text_edit; + + if (first_class != -1) { + function_body += "\n\n"; + } + text_edit.range.end.line = text_edit.range.start.line = start_line; + + text_edit.newText = function_body; + + String uri = get_file_uri(script->get_path()); + + lsp::ApplyWorkspaceEditParams params; + params.edit.add_edit(uri, text_edit); + + GDScriptLanguageProtocol::get_singleton()->request_client("workspace/applyEdit", params.to_json()); +} + void GDScriptWorkspace::did_delete_files(const Dictionary &p_params) { Array files = p_params["files"]; for (int i = 0; i < files.size(); ++i) { @@ -360,6 +409,9 @@ Error GDScriptWorkspace::initialize() { } } + EditorNode *editor_node = EditorNode::get_singleton(); + editor_node->connect("script_add_function_request", callable_mp(this, &GDScriptWorkspace::apply_new_signal)); + return OK; } diff --git a/modules/gdscript/language_server/gdscript_workspace.h b/modules/gdscript/language_server/gdscript_workspace.h index 9496677449..e5cd4d9824 100644 --- a/modules/gdscript/language_server/gdscript_workspace.h +++ b/modules/gdscript/language_server/gdscript_workspace.h @@ -62,6 +62,8 @@ protected: void list_script_files(const String &p_root_dir, List<String> &r_files); + void apply_new_signal(Object *obj, String function, PackedStringArray args); + public: String root; String root_uri; diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp index 9ac6c6bd4e..662382d279 100644 --- a/modules/gdscript/language_server/lsp.hpp +++ b/modules/gdscript/language_server/lsp.hpp @@ -263,6 +263,16 @@ struct WorkspaceEdit { */ Map<String, Vector<TextEdit>> changes; + _FORCE_INLINE_ void add_edit(const String &uri, const TextEdit &edit) { + if (changes.has(uri)) { + changes[uri].push_back(edit); + } else { + Vector<TextEdit> edits; + edits.push_back(edit); + changes[uri] = edits; + } + } + _FORCE_INLINE_ Dictionary to_json() const { Dictionary dict; @@ -1322,6 +1332,18 @@ struct DocumentSymbol { } }; +struct ApplyWorkspaceEditParams { + WorkspaceEdit edit; + + Dictionary to_json() { + Dictionary dict; + + dict["edit"] = edit.to_json(); + + return dict; + } +}; + struct NativeSymbolInspectParams { String native_class; String symbol_name; diff --git a/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd b/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd index 4502960105..0a4f647f57 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd +++ b/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.gd @@ -1,3 +1,3 @@ func test(): # Error here. - print(2 << 4.4) + print(2 >> 4.4) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out b/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out index 1879fc1adf..1edbf47ec0 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/bitwise_float_right_operand.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Invalid operands to operator <<, int and float. +Invalid operands to operator >>, int and float. diff --git a/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.gd b/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.gd new file mode 100644 index 0000000000..f64dce26c9 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.gd @@ -0,0 +1,9 @@ +func inferred_parameter(param = null): + if param == null: + param = Node.new() + param.name = "Ok" + print(param.name) + param.free() + +func test(): + inferred_parameter() diff --git a/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.out b/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.out new file mode 100644 index 0000000000..0e9f482af4 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/auto_inferred_type_dont_error.out @@ -0,0 +1,2 @@ +GDTEST_OK +Ok diff --git a/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.gd b/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.gd new file mode 100644 index 0000000000..569f95850f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.gd @@ -0,0 +1,2 @@ +func test(): + print(Color.html_is_valid("00ffff")) diff --git a/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.out b/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.out new file mode 100644 index 0000000000..55482c2b52 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/static_method_builtin_type.out @@ -0,0 +1,2 @@ +GDTEST_OK +true diff --git a/modules/gdscript/tests/scripts/parser/errors/brace_syntax.gd b/modules/gdscript/tests/scripts/parser/errors/brace_syntax.gd new file mode 100644 index 0000000000..ab66537c93 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/brace_syntax.gd @@ -0,0 +1,3 @@ +func test() { + print("Hello world!"); +} diff --git a/modules/gdscript/tests/scripts/parser/errors/brace_syntax.out b/modules/gdscript/tests/scripts/parser/errors/brace_syntax.out new file mode 100644 index 0000000000..2f37a740ab --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/brace_syntax.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Expected ":" after function declaration. diff --git a/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.gd b/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.gd new file mode 100644 index 0000000000..3b52f6e324 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.gd @@ -0,0 +1,2 @@ +func test(): + var escape = "invalid escape \h <- here" diff --git a/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.out b/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.out new file mode 100644 index 0000000000..32b4d004db --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/invalid_escape_sequence.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Invalid escape in string. diff --git a/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.gd b/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.gd new file mode 100644 index 0000000000..c835ce15e1 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.gd @@ -0,0 +1,5 @@ +func test(): + var amount = 50 + # C-style ternary operator is invalid in GDScript. + # The valid syntax is `"yes" if amount < 60 else "no"`, like in Python. + var ternary = amount < 60 ? "yes" : "no" diff --git a/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.out b/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.out new file mode 100644 index 0000000000..ac82d691b7 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/invalid_ternary_operator.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Unexpected "?" in source. If you want a ternary operator, use "truthy_value if true_condition else falsy_value". diff --git a/modules/gdscript/tests/scripts/parser/errors/subscript_without_index.gd b/modules/gdscript/tests/scripts/parser/errors/subscript_without_index.gd new file mode 100644 index 0000000000..c30c05e4da --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/subscript_without_index.gd @@ -0,0 +1,3 @@ +func test(): + var array = [1, 2, 3] + array[] = 4 diff --git a/modules/gdscript/tests/scripts/parser/errors/subscript_without_index.out b/modules/gdscript/tests/scripts/parser/errors/subscript_without_index.out new file mode 100644 index 0000000000..7017c7b4aa --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/subscript_without_index.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Expected expression after "[". diff --git a/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.gd b/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.gd new file mode 100644 index 0000000000..8850892f2d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.gd @@ -0,0 +1,13 @@ +# The VCS conflict marker has only 6 `=` signs instead of 7 to prevent editors like +# Visual Studio Code from recognizing it as an actual VCS conflict marker. +# Nonetheless, the GDScript parser is still expected to find and report the VCS +# conflict marker error correctly. + +<<<<<<< HEAD +Hello world +====== +Goodbye +>>>>>>> 77976da35a11db4580b80ae27e8d65caf5208086 + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.out b/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.out new file mode 100644 index 0000000000..df9dab2223 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/vcs_conflict_marker.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +Unexpected "VCS conflict marker" in class body. diff --git a/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.gd b/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.gd new file mode 100644 index 0000000000..7862eff6ec --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.gd @@ -0,0 +1,6 @@ +#GDTEST_PARSER_ERROR + +signal event + +func test(): + yield("event") diff --git a/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.out b/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.out new file mode 100644 index 0000000000..36cb699e92 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +"yield" was removed in Godot 4.0. Use "await" instead. diff --git a/modules/gdscript/tests/scripts/parser/features/export_variable.gd b/modules/gdscript/tests/scripts/parser/features/export_variable.gd index 51e7d4a8ed..1e072728fc 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_variable.gd +++ b/modules/gdscript/tests/scripts/parser/features/export_variable.gd @@ -3,9 +3,16 @@ @export_range(0, 100, 1) var example_range_step = 101 @export_range(0, 100, 1, "or_greater") var example_range_step_or_greater = 102 +@export var color: Color +@export_color_no_alpha var color_no_alpha: Color +@export_node_path(Sprite2D, Sprite3D, Control, Node) var nodepath := ^"hello" + func test(): print(example) print(example_range) print(example_range_step) print(example_range_step_or_greater) + print(color) + print(color_no_alpha) + print(nodepath) diff --git a/modules/gdscript/tests/scripts/parser/features/export_variable.out b/modules/gdscript/tests/scripts/parser/features/export_variable.out index b455196359..bae35e75c6 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_variable.out +++ b/modules/gdscript/tests/scripts/parser/features/export_variable.out @@ -3,3 +3,6 @@ GDTEST_OK 100 101 102 +(0, 0, 0, 1) +(0, 0, 0, 1) +hello diff --git a/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.gd b/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.gd new file mode 100644 index 0000000000..f5098b00ae --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.gd @@ -0,0 +1,5 @@ +func example(_number: int, _number2: int = 5, number3 := 10): + return number3 + +func test(): + print(example(3)) diff --git a/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.out b/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.out new file mode 100644 index 0000000000..404cd41fe5 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/function_default_parameter_type_inference.out @@ -0,0 +1,2 @@ +GDTEST_OK +10 diff --git a/modules/gdscript/tests/scripts/parser/features/function_many_parameters.gd b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.gd new file mode 100644 index 0000000000..01edb37cec --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.gd @@ -0,0 +1,5 @@ +func example(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29, arg30, arg31, arg32, arg33, arg34, arg35, arg36, arg37, arg38, arg39, arg40, arg41, arg42, arg43, arg44, arg45, arg46, arg47, arg48 = false, arg49 = true, arg50 = null): + print(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25, arg26, arg27, arg28, arg29, arg30, arg31, arg32, arg33, arg34, arg35, arg36, arg37, arg38, arg39, arg40, arg41, arg42, arg43, arg44, arg45, arg46, arg47, arg48, arg49, arg50) + +func test(): + example(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47) diff --git a/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out new file mode 100644 index 0000000000..3a979227d4 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/function_many_parameters.out @@ -0,0 +1,2 @@ +GDTEST_OK +123456789101112131415161718192212223242526272829303132333435363738394041424344454647falsetruenull diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd b/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd new file mode 100644 index 0000000000..c3b2506156 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd @@ -0,0 +1,4 @@ +func test(): + var my_lambda = func(x): + print(x) + my_lambda.call("hello") diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_callable.out b/modules/gdscript/tests/scripts/parser/features/lambda_callable.out new file mode 100644 index 0000000000..58774d2d3f --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_callable.out @@ -0,0 +1,2 @@ +GDTEST_OK +hello diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.gd b/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.gd new file mode 100644 index 0000000000..f081a0b6a7 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.gd @@ -0,0 +1,4 @@ +func test(): + var x = 42 + var my_lambda = func(): print(x) + my_lambda.call() # Prints "42". diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.out b/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.out new file mode 100644 index 0000000000..0982f3718c --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_capture_callable.out @@ -0,0 +1,2 @@ +GDTEST_OK +42 diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.gd b/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.gd new file mode 100644 index 0000000000..7971ca72a6 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.gd @@ -0,0 +1,10 @@ +func i_take_lambda(lambda: Callable, param: String): + lambda.call(param) + + +func test(): + var my_lambda := func this_is_lambda(x): + print("Hello") + print("This is %s" % x) + + i_take_lambda(my_lambda, "a lambda") diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.out b/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.out new file mode 100644 index 0000000000..c627187d82 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/lambda_named_callable.out @@ -0,0 +1,3 @@ +GDTEST_OK +Hello +This is a lambda diff --git a/modules/gdscript/tests/scripts/parser/features/nested_function_calls.gd b/modules/gdscript/tests/scripts/parser/features/nested_function_calls.gd new file mode 100644 index 0000000000..59cdc7d6c2 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/nested_function_calls.gd @@ -0,0 +1,5 @@ +func foo(x): + return x + 1 + +func test(): + print(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(foo(0))))))))))))))))))))))))) diff --git a/modules/gdscript/tests/scripts/parser/features/nested_function_calls.out b/modules/gdscript/tests/scripts/parser/features/nested_function_calls.out new file mode 100644 index 0000000000..28a6636a7b --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/nested_function_calls.out @@ -0,0 +1,2 @@ +GDTEST_OK +24 diff --git a/modules/gdscript/tests/scripts/parser/features/semicolon_as_terminator.gd b/modules/gdscript/tests/scripts/parser/features/semicolon_as_terminator.gd new file mode 100644 index 0000000000..0f4aebb459 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/semicolon_as_terminator.gd @@ -0,0 +1,22 @@ +#GDTEST_OK + +func test(): + a(); + b(); + c(); + d(); + e(); + +func a(): print("a"); + +func b(): print("b1"); print("b2") + +func c(): print("c1"); print("c2"); + +func d(): + print("d1"); + print("d2") + +func e(): + print("e1"); + print("e2"); diff --git a/modules/gdscript/tests/scripts/parser/features/semicolon_as_terminator.out b/modules/gdscript/tests/scripts/parser/features/semicolon_as_terminator.out new file mode 100644 index 0000000000..387cbd8fc2 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/semicolon_as_terminator.out @@ -0,0 +1,10 @@ +GDTEST_OK +a +b1 +b2 +c1 +c2 +d1 +d2 +e1 +e2 diff --git a/modules/gdscript/tests/scripts/parser/features/signal_declaration.gd b/modules/gdscript/tests/scripts/parser/features/signal_declaration.gd new file mode 100644 index 0000000000..9ad98b78a8 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/signal_declaration.gd @@ -0,0 +1,20 @@ +#GDTEST_OK + +# No parentheses. +signal a + +# No parameters. +signal b() + +# With paramters. +signal c(a, b, c) + +# With parameters multiline. +signal d( + a, + b, + c, +) + +func test(): + print("Ok") diff --git a/modules/gdscript/tests/scripts/parser/features/signal_declaration.out b/modules/gdscript/tests/scripts/parser/features/signal_declaration.out new file mode 100644 index 0000000000..0e9f482af4 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/signal_declaration.out @@ -0,0 +1,2 @@ +GDTEST_OK +Ok diff --git a/modules/gdscript/tests/scripts/parser/features/single_line_declaration.gd b/modules/gdscript/tests/scripts/parser/features/single_line_declaration.gd new file mode 100644 index 0000000000..650500663b --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/single_line_declaration.gd @@ -0,0 +1,11 @@ +#GDTEST_OK + +func test(): C.new().test("Ok"); test2() + +func test2(): print("Ok 2") + +class A: pass + +class B extends RefCounted: pass + +class C extends RefCounted: func test(x): print(x) diff --git a/modules/gdscript/tests/scripts/parser/features/single_line_declaration.out b/modules/gdscript/tests/scripts/parser/features/single_line_declaration.out new file mode 100644 index 0000000000..e021923dc2 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/single_line_declaration.out @@ -0,0 +1,3 @@ +GDTEST_OK +Ok +Ok 2 diff --git a/modules/gdscript/tests/scripts/parser/features/typed_arrays.gd b/modules/gdscript/tests/scripts/parser/features/typed_arrays.gd new file mode 100644 index 0000000000..21bf3fdfcf --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/typed_arrays.gd @@ -0,0 +1,5 @@ +func test(): + var my_array: Array[int] = [1, 2, 3] + var inferred_array := [1, 2, 3] # This is Array[int]. + print(my_array) + print(inferred_array) diff --git a/modules/gdscript/tests/scripts/parser/features/typed_arrays.out b/modules/gdscript/tests/scripts/parser/features/typed_arrays.out new file mode 100644 index 0000000000..953d54d5e0 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/typed_arrays.out @@ -0,0 +1,3 @@ +GDTEST_OK +[1, 2, 3] +[1, 2, 3] diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.gd b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.gd new file mode 100644 index 0000000000..c6645c2c34 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.gd @@ -0,0 +1,138 @@ +func test(): + var value + + # null + value = null + print(value == null) + + # bool + value = false + print(value == null) + + # int + value = 0 + print(value == null) + + # float + value = 0.0 + print(value == null) + + # String + value = "" + print(value == null) + + # Vector2 + value = Vector2() + print(value == null) + + # Vector2i + value = Vector2i() + print(value == null) + + # Rect2 + value = Rect2() + print(value == null) + + # Rect2i + value = Rect2i() + print(value == null) + + # Vector3 + value = Vector3() + print(value == null) + + # Vector3i + value = Vector3i() + print(value == null) + + # Transform2D + value = Transform2D() + print(value == null) + + # Plane + value = Plane() + print(value == null) + + # Quaternion + value = Quaternion() + print(value == null) + + # AABB + value = AABB() + print(value == null) + + # Basis + value = Basis() + print(value == null) + + # Transform3D + value = Transform3D() + print(value == null) + + # Color + value = Color() + print(value == null) + + # StringName + value = &"" + print(value == null) + + # NodePath + value = ^"" + print(value == null) + + # RID + value = RID() + print(value == null) + + # Callable + value = Callable() + print(value == null) + + # Signal + value = Signal() + print(value == null) + + # Dictionary + value = {} + print(value == null) + + # Array + value = [] + print(value == null) + + # PackedByteArray + value = PackedByteArray() + print(value == null) + + # PackedInt32Array + value = PackedInt32Array() + print(value == null) + + # PackedInt64Array + value = PackedInt64Array() + print(value == null) + + # PackedFloat32Array + value = PackedFloat32Array() + print(value == null) + + # PackedFloat64Array + value = PackedFloat64Array() + print(value == null) + + # PackedStringArray + value = PackedStringArray() + print(value == null) + + # PackedVector2Array + value = PackedVector2Array() + print(value == null) + + # PackedVector3Array + value = PackedVector3Array() + print(value == null) + + # PackedColorArray + value = PackedColorArray() + print(value == null) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.out b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.out new file mode 100644 index 0000000000..639f6027b9 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.out @@ -0,0 +1,35 @@ +GDTEST_OK +true +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.gd b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.gd new file mode 100644 index 0000000000..ee622bf22f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.gd @@ -0,0 +1,138 @@ +func test(): + var value + + # null + value = null + print(value != null) + + # bool + value = false + print(value != null) + + # int + value = 0 + print(value != null) + + # float + value = 0.0 + print(value != null) + + # String + value = "" + print(value != null) + + # Vector2 + value = Vector2() + print(value != null) + + # Vector2i + value = Vector2i() + print(value != null) + + # Rect2 + value = Rect2() + print(value != null) + + # Rect2i + value = Rect2i() + print(value != null) + + # Vector3 + value = Vector3() + print(value != null) + + # Vector3i + value = Vector3i() + print(value != null) + + # Transform2D + value = Transform2D() + print(value != null) + + # Plane + value = Plane() + print(value != null) + + # Quaternion + value = Quaternion() + print(value != null) + + # AABB + value = AABB() + print(value != null) + + # Basis + value = Basis() + print(value != null) + + # Transform3D + value = Transform3D() + print(value != null) + + # Color + value = Color() + print(value != null) + + # StringName + value = &"" + print(value != null) + + # NodePath + value = ^"" + print(value != null) + + # RID + value = RID() + print(value != null) + + # Callable + value = Callable() + print(value != null) + + # Signal + value = Signal() + print(value != null) + + # Dictionary + value = {} + print(value != null) + + # Array + value = [] + print(value != null) + + # PackedByteArray + value = PackedByteArray() + print(value != null) + + # PackedInt32Array + value = PackedInt32Array() + print(value != null) + + # PackedInt64Array + value = PackedInt64Array() + print(value != null) + + # PackedFloat32Array + value = PackedFloat32Array() + print(value != null) + + # PackedFloat64Array + value = PackedFloat64Array() + print(value != null) + + # PackedStringArray + value = PackedStringArray() + print(value != null) + + # PackedVector2Array + value = PackedVector2Array() + print(value != null) + + # PackedVector3Array + value = PackedVector3Array() + print(value != null) + + # PackedColorArray + value = PackedColorArray() + print(value != null) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.out b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.out new file mode 100644 index 0000000000..d1e332afba --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.out @@ -0,0 +1,35 @@ +GDTEST_OK +false +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-null-equals-builtin.gd b/modules/gdscript/tests/scripts/runtime/features/compare-null-equals-builtin.gd new file mode 100644 index 0000000000..7649062fda --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/compare-null-equals-builtin.gd @@ -0,0 +1,138 @@ +func test(): + var value + + # null + value = null + print(null == value) + + # bool + value = false + print(null == value) + + # int + value = 0 + print(null == value) + + # float + value = 0.0 + print(null == value) + + # String + value = "" + print(null == value) + + # Vector2 + value = Vector2() + print(null == value) + + # Vector2i + value = Vector2i() + print(null == value) + + # Rect2 + value = Rect2() + print(null == value) + + # Rect2i + value = Rect2i() + print(null == value) + + # Vector3 + value = Vector3() + print(null == value) + + # Vector3i + value = Vector3i() + print(null == value) + + # Transform2D + value = Transform2D() + print(null == value) + + # Plane + value = Plane() + print(null == value) + + # Quaternion + value = Quaternion() + print(null == value) + + # AABB + value = AABB() + print(null == value) + + # Basis + value = Basis() + print(null == value) + + # Transform3D + value = Transform3D() + print(null == value) + + # Color + value = Color() + print(null == value) + + # StringName + value = &"" + print(null == value) + + # NodePath + value = ^"" + print(null == value) + + # RID + value = RID() + print(null == value) + + # Callable + value = Callable() + print(null == value) + + # Signal + value = Signal() + print(null == value) + + # Dictionary + value = {} + print(null == value) + + # Array + value = [] + print(null == value) + + # PackedByteArray + value = PackedByteArray() + print(null == value) + + # PackedInt32Array + value = PackedInt32Array() + print(null == value) + + # PackedInt64Array + value = PackedInt64Array() + print(null == value) + + # PackedFloat32Array + value = PackedFloat32Array() + print(null == value) + + # PackedFloat64Array + value = PackedFloat64Array() + print(null == value) + + # PackedStringArray + value = PackedStringArray() + print(null == value) + + # PackedVector2Array + value = PackedVector2Array() + print(null == value) + + # PackedVector3Array + value = PackedVector3Array() + print(null == value) + + # PackedColorArray + value = PackedColorArray() + print(null == value) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-null-equals-builtin.out b/modules/gdscript/tests/scripts/runtime/features/compare-null-equals-builtin.out new file mode 100644 index 0000000000..639f6027b9 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/compare-null-equals-builtin.out @@ -0,0 +1,35 @@ +GDTEST_OK +true +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false +false diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-null-not-equals-builtin.gd b/modules/gdscript/tests/scripts/runtime/features/compare-null-not-equals-builtin.gd new file mode 100644 index 0000000000..8d5f9df1b8 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/compare-null-not-equals-builtin.gd @@ -0,0 +1,138 @@ +func test(): + var value + + # null + value = null + print(null != value) + + # bool + value = false + print(null != value) + + # int + value = 0 + print(null != value) + + # float + value = 0.0 + print(null != value) + + # String + value = "" + print(null != value) + + # Vector2 + value = Vector2() + print(null != value) + + # Vector2i + value = Vector2i() + print(null != value) + + # Rect2 + value = Rect2() + print(null != value) + + # Rect2i + value = Rect2i() + print(null != value) + + # Vector3 + value = Vector3() + print(null != value) + + # Vector3i + value = Vector3i() + print(null != value) + + # Transform2D + value = Transform2D() + print(null != value) + + # Plane + value = Plane() + print(null != value) + + # Quaternion + value = Quaternion() + print(null != value) + + # AABB + value = AABB() + print(null != value) + + # Basis + value = Basis() + print(null != value) + + # Transform3D + value = Transform3D() + print(null != value) + + # Color + value = Color() + print(null != value) + + # StringName + value = &"" + print(null != value) + + # NodePath + value = ^"" + print(null != value) + + # RID + value = RID() + print(null != value) + + # Callable + value = Callable() + print(null != value) + + # Signal + value = Signal() + print(null != value) + + # Dictionary + value = {} + print(null != value) + + # Array + value = [] + print(null != value) + + # PackedByteArray + value = PackedByteArray() + print(null != value) + + # PackedInt32Array + value = PackedInt32Array() + print(null != value) + + # PackedInt64Array + value = PackedInt64Array() + print(null != value) + + # PackedFloat32Array + value = PackedFloat32Array() + print(null != value) + + # PackedFloat64Array + value = PackedFloat64Array() + print(null != value) + + # PackedStringArray + value = PackedStringArray() + print(null != value) + + # PackedVector2Array + value = PackedVector2Array() + print(null != value) + + # PackedVector3Array + value = PackedVector3Array() + print(null != value) + + # PackedColorArray + value = PackedColorArray() + print(null != value) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-null-not-equals-builtin.out b/modules/gdscript/tests/scripts/runtime/features/compare-null-not-equals-builtin.out new file mode 100644 index 0000000000..d1e332afba --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/compare-null-not-equals-builtin.out @@ -0,0 +1,35 @@ +GDTEST_OK +false +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true +true diff --git a/modules/gdscript/tests/scripts/runtime/features/recursion.gd b/modules/gdscript/tests/scripts/runtime/features/recursion.gd new file mode 100644 index 0000000000..a35485022e --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/recursion.gd @@ -0,0 +1,19 @@ +func is_prime(number: int, divisor: int = 2) -> bool: + print(divisor) + if number <= 2: + return (number == 2) + elif number % divisor == 0: + return false + elif divisor * divisor > number: + return true + + return is_prime(number, divisor + 1) + +func test(): + # Not a prime number. + print(is_prime(989)) + + print() + + # Largest prime number below 10000. + print(is_prime(9973)) diff --git a/modules/gdscript/tests/scripts/runtime/features/recursion.out b/modules/gdscript/tests/scripts/runtime/features/recursion.out new file mode 100644 index 0000000000..2bd8f24988 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/recursion.out @@ -0,0 +1,125 @@ +GDTEST_OK +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +false + +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +true diff --git a/modules/glslang/SCsub b/modules/glslang/SCsub index 182272ffc7..1954a32697 100644 --- a/modules/glslang/SCsub +++ b/modules/glslang/SCsub @@ -13,46 +13,47 @@ if env["builtin_glslang"]: thirdparty_dir = "#thirdparty/glslang/" thirdparty_sources = [ "glslang/CInterface/glslang_c_interface.cpp", - "glslang/MachineIndependent/RemoveTree.cpp", - "glslang/MachineIndependent/ParseHelper.cpp", - "glslang/MachineIndependent/iomapper.cpp", - "glslang/MachineIndependent/propagateNoContraction.cpp", - "glslang/MachineIndependent/Intermediate.cpp", - "glslang/MachineIndependent/linkValidate.cpp", "glslang/MachineIndependent/attribute.cpp", - "glslang/MachineIndependent/Scan.cpp", - "glslang/MachineIndependent/Initialize.cpp", "glslang/MachineIndependent/Constant.cpp", - "glslang/MachineIndependent/reflection.cpp", + "glslang/MachineIndependent/glslang_tab.cpp", + "glslang/MachineIndependent/InfoSink.cpp", + "glslang/MachineIndependent/Initialize.cpp", + "glslang/MachineIndependent/Intermediate.cpp", + "glslang/MachineIndependent/intermOut.cpp", + "glslang/MachineIndependent/IntermTraverse.cpp", + "glslang/MachineIndependent/iomapper.cpp", "glslang/MachineIndependent/limits.cpp", - "glslang/MachineIndependent/preprocessor/PpScanner.cpp", - "glslang/MachineIndependent/preprocessor/PpTokens.cpp", + "glslang/MachineIndependent/linkValidate.cpp", + "glslang/MachineIndependent/parseConst.cpp", + "glslang/MachineIndependent/ParseContextBase.cpp", + "glslang/MachineIndependent/ParseHelper.cpp", + "glslang/MachineIndependent/PoolAlloc.cpp", "glslang/MachineIndependent/preprocessor/PpAtom.cpp", "glslang/MachineIndependent/preprocessor/PpContext.cpp", "glslang/MachineIndependent/preprocessor/Pp.cpp", - "glslang/MachineIndependent/InfoSink.cpp", - "glslang/MachineIndependent/intermOut.cpp", + "glslang/MachineIndependent/preprocessor/PpScanner.cpp", + "glslang/MachineIndependent/preprocessor/PpTokens.cpp", + "glslang/MachineIndependent/propagateNoContraction.cpp", + "glslang/MachineIndependent/reflection.cpp", + "glslang/MachineIndependent/RemoveTree.cpp", + "glslang/MachineIndependent/Scan.cpp", + "glslang/MachineIndependent/ShaderLang.cpp", + "glslang/MachineIndependent/SpirvIntrinsics.cpp", "glslang/MachineIndependent/SymbolTable.cpp", - "glslang/MachineIndependent/glslang_tab.cpp", "glslang/MachineIndependent/Versions.cpp", - "glslang/MachineIndependent/ShaderLang.cpp", - "glslang/MachineIndependent/parseConst.cpp", - "glslang/MachineIndependent/PoolAlloc.cpp", - "glslang/MachineIndependent/ParseContextBase.cpp", - "glslang/MachineIndependent/IntermTraverse.cpp", - "glslang/GenericCodeGen/Link.cpp", "glslang/GenericCodeGen/CodeGen.cpp", + "glslang/GenericCodeGen/Link.cpp", "OGLCompilersDLL/InitializeDll.cpp", "SPIRV/CInterface/spirv_c_interface.cpp", - "SPIRV/InReadableOrder.cpp", - "SPIRV/GlslangToSpv.cpp", - "SPIRV/SpvBuilder.cpp", - "SPIRV/SpvTools.cpp", "SPIRV/disassemble.cpp", "SPIRV/doc.cpp", - "SPIRV/SPVRemapper.cpp", - "SPIRV/SpvPostProcess.cpp", + "SPIRV/GlslangToSpv.cpp", + "SPIRV/InReadableOrder.cpp", "SPIRV/Logger.cpp", + "SPIRV/SpvBuilder.cpp", + "SPIRV/SpvPostProcess.cpp", + "SPIRV/SPVRemapper.cpp", + "SPIRV/SpvTools.cpp", "StandAlone/ResourceLimits.cpp", ] diff --git a/modules/gltf/doc_classes/EditorSceneImporterGLTF.xml b/modules/gltf/doc_classes/EditorSceneImporterGLTF.xml index e717b30f73..c85fce7b9d 100644 --- a/modules/gltf/doc_classes/EditorSceneImporterGLTF.xml +++ b/modules/gltf/doc_classes/EditorSceneImporterGLTF.xml @@ -6,8 +6,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFAccessor.xml b/modules/gltf/doc_classes/GLTFAccessor.xml index 41a318ce19..ae81cae81a 100644 --- a/modules/gltf/doc_classes/GLTFAccessor.xml +++ b/modules/gltf/doc_classes/GLTFAccessor.xml @@ -6,8 +6,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="buffer_view" type="int" setter="set_buffer_view" getter="get_buffer_view" default="0"> </member> @@ -38,6 +36,4 @@ <member name="type" type="int" setter="set_type" getter="get_type" default="0"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFAnimation.xml b/modules/gltf/doc_classes/GLTFAnimation.xml index 5c1fa02f11..70480c2b38 100644 --- a/modules/gltf/doc_classes/GLTFAnimation.xml +++ b/modules/gltf/doc_classes/GLTFAnimation.xml @@ -6,12 +6,8 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="loop" type="bool" setter="set_loop" getter="get_loop" default="false"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFBufferView.xml b/modules/gltf/doc_classes/GLTFBufferView.xml index edaad85e0a..f58aa46508 100644 --- a/modules/gltf/doc_classes/GLTFBufferView.xml +++ b/modules/gltf/doc_classes/GLTFBufferView.xml @@ -6,8 +6,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="buffer" type="int" setter="set_buffer" getter="get_buffer" default="-1"> </member> @@ -20,6 +18,4 @@ <member name="indices" type="bool" setter="set_indices" getter="get_indices" default="false"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFCamera.xml b/modules/gltf/doc_classes/GLTFCamera.xml index ec25d84756..3682df5951 100644 --- a/modules/gltf/doc_classes/GLTFCamera.xml +++ b/modules/gltf/doc_classes/GLTFCamera.xml @@ -6,8 +6,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="depth_far" type="float" setter="set_depth_far" getter="get_depth_far" default="4000.0"> </member> @@ -18,6 +16,4 @@ <member name="perspective" type="bool" setter="set_perspective" getter="get_perspective" default="true"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFDocument.xml b/modules/gltf/doc_classes/GLTFDocument.xml index f8e0007684..16e649f390 100644 --- a/modules/gltf/doc_classes/GLTFDocument.xml +++ b/modules/gltf/doc_classes/GLTFDocument.xml @@ -30,6 +30,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFLight.xml b/modules/gltf/doc_classes/GLTFLight.xml index 2eb5ee9070..b4f03cd1ed 100644 --- a/modules/gltf/doc_classes/GLTFLight.xml +++ b/modules/gltf/doc_classes/GLTFLight.xml @@ -6,22 +6,26 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> - <member name="color" type="Color" setter="set_color" getter="get_color" default="Color(0, 0, 0, 1)"> + <member name="color" type="Color" setter="set_color" getter="get_color" default="Color(1, 1, 1, 1)"> + The [Color] of the light. Defaults to white. A black color causes the light to have no effect. </member> <member name="inner_cone_angle" type="float" setter="set_inner_cone_angle" getter="get_inner_cone_angle" default="0.0"> + The inner angle of the cone in a spotlight. Must be less than or equal to the outer cone angle. + Within this angle, the light is at full brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. When creating a Godot [SpotLight3D], the ratio between the inner and outer cone angles is used to calculate the attenuation of the light. </member> - <member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="0.0"> + <member name="intensity" type="float" setter="set_intensity" getter="get_intensity" default="1.0"> + The intensity of the light. This is expressed in candelas (lumens per steradian) for point and spot lights, and lux (lumens per m²) for directional lights. When creating a Godot light, this value is converted to a unitless multiplier. </member> <member name="light_type" type="String" setter="set_light_type" getter="get_light_type" default=""""> + The type of the light. The values accepted by Godot are "point", "spot", and "directional", which correspond to Godot's [OmniLight3D], [SpotLight3D], and [DirectionalLight3D] respectively. </member> - <member name="outer_cone_angle" type="float" setter="set_outer_cone_angle" getter="get_outer_cone_angle" default="0.0"> + <member name="outer_cone_angle" type="float" setter="set_outer_cone_angle" getter="get_outer_cone_angle" default="0.785398"> + The outer angle of the cone in a spotlight. Must be greater than or equal to the inner angle. + At this angle, the light drops off to zero brightness. Between the inner and outer cone angles, there is a transition from full brightness to zero brightness. If this angle is a half turn, then the spotlight emits in all directions. When creating a Godot [SpotLight3D], the outer cone angle is used as the angle of the spotlight. </member> - <member name="range" type="float" setter="set_range" getter="get_range" default="0.0"> + <member name="range" type="float" setter="set_range" getter="get_range" default="inf"> + The range of the light, beyond which the light has no effect. GLTF lights with no range defined behave like physical lights (which have infinite range). When creating a Godot light, the range is clamped to 4096. </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFMesh.xml b/modules/gltf/doc_classes/GLTFMesh.xml index fd7e4a169e..51e9fc032a 100644 --- a/modules/gltf/doc_classes/GLTFMesh.xml +++ b/modules/gltf/doc_classes/GLTFMesh.xml @@ -6,14 +6,10 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="blend_weights" type="PackedFloat32Array" setter="set_blend_weights" getter="get_blend_weights" default="PackedFloat32Array()"> </member> <member name="mesh" type="EditorSceneImporterMesh" setter="set_mesh" getter="get_mesh"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFNode.xml b/modules/gltf/doc_classes/GLTFNode.xml index 95d7283398..f27965ea07 100644 --- a/modules/gltf/doc_classes/GLTFNode.xml +++ b/modules/gltf/doc_classes/GLTFNode.xml @@ -6,8 +6,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="camera" type="int" setter="set_camera" getter="get_camera" default="-1"> </member> @@ -36,6 +34,4 @@ <member name="xform" type="Transform3D" setter="set_xform" getter="get_xform" default="Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFSkeleton.xml b/modules/gltf/doc_classes/GLTFSkeleton.xml index 6e83cec252..037c3545a6 100644 --- a/modules/gltf/doc_classes/GLTFSkeleton.xml +++ b/modules/gltf/doc_classes/GLTFSkeleton.xml @@ -52,6 +52,4 @@ <member name="roots" type="PackedInt32Array" setter="set_roots" getter="get_roots" default="PackedInt32Array()"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFSkin.xml b/modules/gltf/doc_classes/GLTFSkin.xml index 107ca960cd..ad4f017584 100644 --- a/modules/gltf/doc_classes/GLTFSkin.xml +++ b/modules/gltf/doc_classes/GLTFSkin.xml @@ -57,6 +57,4 @@ <member name="skin_root" type="int" setter="set_skin_root" getter="get_skin_root" default="-1"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFSpecGloss.xml b/modules/gltf/doc_classes/GLTFSpecGloss.xml index 6e9c419649..6b8f86ed1c 100644 --- a/modules/gltf/doc_classes/GLTFSpecGloss.xml +++ b/modules/gltf/doc_classes/GLTFSpecGloss.xml @@ -6,8 +6,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="diffuse_factor" type="Color" setter="set_diffuse_factor" getter="get_diffuse_factor" default="Color(1, 1, 1, 1)"> </member> @@ -20,6 +18,4 @@ <member name="specular_factor" type="Color" setter="set_specular_factor" getter="get_specular_factor" default="Color(1, 1, 1, 1)"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFState.xml b/modules/gltf/doc_classes/GLTFState.xml index ae976fc04c..6d03d0ecf8 100644 --- a/modules/gltf/doc_classes/GLTFState.xml +++ b/modules/gltf/doc_classes/GLTFState.xml @@ -209,6 +209,4 @@ <member name="use_named_skin_binds" type="bool" setter="set_use_named_skin_binds" getter="get_use_named_skin_binds" default="false"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/doc_classes/GLTFTexture.xml b/modules/gltf/doc_classes/GLTFTexture.xml index 33bd8fddeb..7c88d2318e 100644 --- a/modules/gltf/doc_classes/GLTFTexture.xml +++ b/modules/gltf/doc_classes/GLTFTexture.xml @@ -6,12 +6,8 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="src_image" type="int" setter="set_src_image" getter="get_src_image" default="0"> </member> </members> - <constants> - </constants> </class> diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index d4f4221663..97367b15df 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -5074,7 +5074,7 @@ Node3D *GLTFDocument::_generate_light(Ref<GLTFState> state, Node *scene_parent, const float range = CLAMP(l->range, 0, 4096); // Doubling the range will double the effective brightness, so we need double attenuation (half brightness). // We want to have double intensity give double brightness, so we need half the attenuation. - const float attenuation = range / intensity; + const float attenuation = range / (intensity * 2048); if (l->light_type == "point") { OmniLight3D *light = memnew(OmniLight3D); light->set_param(OmniLight3D::PARAM_ATTENUATION, attenuation); @@ -5150,13 +5150,13 @@ GLTFLightIndex GLTFDocument::_convert_light(Ref<GLTFState> state, Light3D *p_lig OmniLight3D *light = cast_to<OmniLight3D>(p_light); l->range = light->get_param(OmniLight3D::PARAM_RANGE); float attenuation = p_light->get_param(OmniLight3D::PARAM_ATTENUATION); - l->intensity = l->range / attenuation; + l->intensity = l->range / (attenuation * 2048); } else if (cast_to<SpotLight3D>(p_light)) { l->light_type = "spot"; SpotLight3D *light = cast_to<SpotLight3D>(p_light); l->range = light->get_param(SpotLight3D::PARAM_RANGE); float attenuation = light->get_param(SpotLight3D::PARAM_ATTENUATION); - l->intensity = l->range / attenuation; + l->intensity = l->range / (attenuation * 2048); l->outer_cone_angle = Math::deg2rad(light->get_param(SpotLight3D::PARAM_SPOT_ANGLE)); // This equation is the inverse of the import equation (which has a desmos link). @@ -6744,6 +6744,8 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) { Error GLTFDocument::save_scene(Node *p_node, const String &p_path, const String &p_src_path, uint32_t p_flags, float p_bake_fps, Ref<GLTFState> r_state) { + ERR_FAIL_NULL_V(p_node, ERR_INVALID_PARAMETER); + Ref<GLTFDocument> gltf_document; gltf_document.instantiate(); if (r_state == Ref<GLTFState>()) { diff --git a/modules/gltf/gltf_light.h b/modules/gltf/gltf_light.h index 079fb18151..62a20d2f16 100644 --- a/modules/gltf/gltf_light.h +++ b/modules/gltf/gltf_light.h @@ -42,12 +42,12 @@ protected: static void _bind_methods(); private: - Color color; - float intensity = 0.0f; + Color color = Color(1.0f, 1.0f, 1.0f); + float intensity = 1.0f; String light_type; - float range = 0.0f; + float range = INFINITY; float inner_cone_angle = 0.0f; - float outer_cone_angle = 0.0f; + float outer_cone_angle = Math_TAU / 8.0f; public: Color get_color(); diff --git a/modules/lightmapper_rd/lm_compute.glsl b/modules/lightmapper_rd/lm_compute.glsl index a71652d5c4..25b334c5eb 100644 --- a/modules/lightmapper_rd/lm_compute.glsl +++ b/modules/lightmapper_rd/lm_compute.glsl @@ -115,7 +115,12 @@ bool ray_hits_triangle(vec3 from, vec3 dir, float max_dist, vec3 p0, vec3 p1, ve return (r_distance > params.bias) && (r_distance < max_dist) && all(greaterThanEqual(r_barycentric, vec3(0.0))); } -bool trace_ray(vec3 p_from, vec3 p_to +const uint RAY_MISS = 0; +const uint RAY_FRONT = 1; +const uint RAY_BACK = 2; +const uint RAY_ANY = 3; + +uint trace_ray(vec3 p_from, vec3 p_to #if defined(MODE_BOUNCE_LIGHT) || defined(MODE_LIGHT_PROBES) , out uint r_triangle, out vec3 r_barycentric @@ -125,6 +130,7 @@ bool trace_ray(vec3 p_from, vec3 p_to out float r_distance, out vec3 r_normal #endif ) { + /* world coords */ vec3 rel = p_to - p_from; @@ -150,10 +156,7 @@ bool trace_ray(vec3 p_from, vec3 p_to while (all(greaterThanEqual(icell, ivec3(0))) && all(lessThan(icell, ivec3(params.grid_size))) && iters < 1000) { uvec2 cell_data = texelFetch(usampler3D(grid, linear_sampler), icell, 0).xy; if (cell_data.x > 0) { //triangles here - bool hit = false; -#if defined(MODE_UNOCCLUDE) - bool hit_backface = false; -#endif + uint hit = RAY_MISS; float best_distance = 1e20; for (uint i = 0; i < cell_data.x; i++) { @@ -173,57 +176,46 @@ bool trace_ray(vec3 p_from, vec3 p_to vec3 vtx0 = vertices.data[triangle.indices.x].position; vec3 vtx1 = vertices.data[triangle.indices.y].position; vec3 vtx2 = vertices.data[triangle.indices.z].position; -#if defined(MODE_UNOCCLUDE) +#if defined(MODE_UNOCCLUDE) || defined(MODE_BOUNCE_LIGHT) || defined(MODE_LIGHT_PROBES) vec3 normal = -normalize(cross((vtx0 - vtx1), (vtx0 - vtx2))); bool backface = dot(normal, dir) >= 0.0; #endif + float distance; vec3 barycentric; if (ray_hits_triangle(p_from, dir, rel_len, vtx0, vtx1, vtx2, distance, barycentric)) { #ifdef MODE_DIRECT_LIGHT - return true; //any hit good + return RAY_ANY; //any hit good #endif -#if defined(MODE_UNOCCLUDE) +#if defined(MODE_UNOCCLUDE) || defined(MODE_BOUNCE_LIGHT) || defined(MODE_LIGHT_PROBES) if (!backface) { // the case of meshes having both a front and back face in the same plane is more common than // expected, so if this is a front-face, bias it closer to the ray origin, so it always wins over the back-face distance = max(params.bias, distance - params.bias); } - hit = true; - if (distance < best_distance) { - hit_backface = backface; + hit = backface ? RAY_BACK : RAY_FRONT; best_distance = distance; +#if defined(MODE_UNOCCLUDE) r_distance = distance; r_normal = normal; - } - #endif - #if defined(MODE_BOUNCE_LIGHT) || defined(MODE_LIGHT_PROBES) - - hit = true; - if (distance < best_distance) { - best_distance = distance; r_triangle = tidx; r_barycentric = barycentric; +#endif } #endif } } -#if defined(MODE_UNOCCLUDE) +#if defined(MODE_UNOCCLUDE) || defined(MODE_BOUNCE_LIGHT) || defined(MODE_LIGHT_PROBES) - if (hit) { - return hit_backface; - } -#endif -#if defined(MODE_BOUNCE_LIGHT) || defined(MODE_LIGHT_PROBES) - if (hit) { - return true; + if (hit != RAY_MISS) { + return hit; } #endif } @@ -239,7 +231,7 @@ bool trace_ray(vec3 p_from, vec3 p_to iters++; } - return false; + return RAY_MISS; } const float PI = 3.14159265f; @@ -339,7 +331,7 @@ void main() { continue; //no need to do anything } - if (!trace_ray(position + light_dir * params.bias, light_pos)) { + if (trace_ray(position + light_dir * params.bias, light_pos) == RAY_MISS) { vec3 light = lights.data[i].color * lights.data[i].energy * attenuation; if (lights.data[i].static_bake) { static_light += light; @@ -410,6 +402,7 @@ void main() { vec4(0.0, 0.0, 0.0, 1.0)); #endif vec3 light_average = vec3(0.0); + float active_rays = 0.0; for (uint i = params.ray_from; i < params.ray_to; i++) { vec3 ray_dir = normal_mat * vogel_hemisphere(i, params.ray_count, quick_hash(vec2(atlas_pos))); @@ -417,7 +410,8 @@ void main() { vec3 barycentric; vec3 light = vec3(0.0); - if (trace_ray(position + ray_dir * params.bias, position + ray_dir * length(params.world_size), tidx, barycentric)) { + uint trace_result = trace_ray(position + ray_dir * params.bias, position + ray_dir * length(params.world_size), tidx, barycentric); + if (trace_result == RAY_FRONT) { //hit a triangle vec2 uv0 = vertices.data[triangles.data[tidx].indices.x].uv; vec2 uv1 = vertices.data[triangles.data[tidx].indices.y].uv; @@ -425,7 +419,8 @@ void main() { vec3 uvw = vec3(barycentric.x * uv0 + barycentric.y * uv1 + barycentric.z * uv2, float(triangles.data[tidx].slice)); light = textureLod(sampler2DArray(source_light, linear_sampler), uvw, 0.0).rgb; - } else if (params.env_transform[0][3] == 0.0) { // Use env_transform[0][3] to indicate when we are computing the first bounce + active_rays += 1.0; + } else if (trace_result == RAY_MISS && params.env_transform[0][3] == 0.0) { // Use env_transform[0][3] to indicate when we are computing the first bounce // Did not hit a triangle, reach out for the sky vec3 sky_dir = normalize(mat3(params.env_transform) * ray_dir); @@ -439,6 +434,7 @@ void main() { st /= vec2(PI * 2.0, PI); light = textureLod(sampler2D(environment, linear_sampler), st, 0.0).rgb; + active_rays += 1.0; } light_average += light; @@ -462,7 +458,9 @@ void main() { if (params.ray_from == 0) { light_total = vec3(0.0); } else { - light_total = imageLoad(bounce_accum, ivec3(atlas_pos, params.atlas_slice)).rgb; + vec4 accum = imageLoad(bounce_accum, ivec3(atlas_pos, params.atlas_slice)); + light_total = accum.rgb; + active_rays += accum.a; } light_total += light_average; @@ -477,7 +475,9 @@ void main() { #endif if (params.ray_to == params.ray_count) { - light_total /= float(params.ray_count); + if (active_rays > 0) { + light_total /= active_rays; + } imageStore(dest_light, ivec3(atlas_pos, params.atlas_slice), vec4(light_total, 1.0)); #ifndef USE_SH_LIGHTMAPS vec4 accum = imageLoad(accum_light, ivec3(atlas_pos, params.atlas_slice)); @@ -485,7 +485,7 @@ void main() { imageStore(accum_light, ivec3(atlas_pos, params.atlas_slice), accum); #endif } else { - imageStore(bounce_accum, ivec3(atlas_pos, params.atlas_slice), vec4(light_total, 1.0)); + imageStore(bounce_accum, ivec3(atlas_pos, params.atlas_slice), vec4(light_total, active_rays)); } #endif @@ -518,7 +518,7 @@ void main() { float d; vec3 norm; - if (trace_ray(base_pos, ray_to, d, norm)) { + if (trace_ray(base_pos, ray_to, d, norm) == RAY_BACK) { if (d < min_d) { vertex_pos = base_pos + rays[i] * d + norm * params.bias * 10.0; //this bias needs to be greater than the regular bias, because otherwise later, rays will go the other side when pointing back. min_d = d; @@ -558,7 +558,8 @@ void main() { vec3 barycentric; vec3 light; - if (trace_ray(position + ray_dir * params.bias, position + ray_dir * length(params.world_size), tidx, barycentric)) { + uint trace_result = trace_ray(position + ray_dir * params.bias, position + ray_dir * length(params.world_size), tidx, barycentric); + if (trace_result == RAY_FRONT) { vec2 uv0 = vertices.data[triangles.data[tidx].indices.x].uv; vec2 uv1 = vertices.data[triangles.data[tidx].indices.y].uv; vec2 uv2 = vertices.data[triangles.data[tidx].indices.z].uv; @@ -566,7 +567,7 @@ void main() { light = textureLod(sampler2DArray(source_light, linear_sampler), uvw, 0.0).rgb; light += textureLod(sampler2DArray(source_direct_light, linear_sampler), uvw, 0.0).rgb; - } else { + } else if (trace_result == RAY_MISS) { //did not hit a triangle, reach out for the sky vec3 sky_dir = normalize(mat3(params.env_transform) * ray_dir); diff --git a/modules/minimp3/doc_classes/AudioStreamMP3.xml b/modules/minimp3/doc_classes/AudioStreamMP3.xml index 5507329a18..e4f56614ee 100644 --- a/modules/minimp3/doc_classes/AudioStreamMP3.xml +++ b/modules/minimp3/doc_classes/AudioStreamMP3.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="data" type="PackedByteArray" setter="set_data" getter="get_data" default="PackedByteArray()"> Contains the audio data in bytes. @@ -21,6 +19,4 @@ Time in seconds at which the stream starts after being looped. </member> </members> - <constants> - </constants> </class> diff --git a/modules/mobile_vr/doc_classes/MobileVRInterface.xml b/modules/mobile_vr/doc_classes/MobileVRInterface.xml index 120535bd41..04ba82ef51 100644 --- a/modules/mobile_vr/doc_classes/MobileVRInterface.xml +++ b/modules/mobile_vr/doc_classes/MobileVRInterface.xml @@ -15,8 +15,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="display_to_lens" type="float" setter="set_display_to_lens" getter="get_display_to_lens" default="4.0"> The distance between the display and the lenses inside of the device in centimeters. @@ -40,6 +38,4 @@ The oversample setting. Because of the lens distortion we have to render our buffers at a higher resolution then the screen can natively handle. A value between 1.5 and 2.0 often provides good results but at the cost of performance. </member> </members> - <constants> - </constants> </class> diff --git a/modules/mobile_vr/mobile_vr_interface.cpp b/modules/mobile_vr/mobile_vr_interface.cpp index bbf1db689d..fc1a118e4f 100644 --- a/modules/mobile_vr/mobile_vr_interface.cpp +++ b/modules/mobile_vr/mobile_vr_interface.cpp @@ -244,59 +244,59 @@ void MobileVRInterface::_bind_methods() { 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) { +void MobileVRInterface::set_eye_height(const double p_eye_height) { eye_height = p_eye_height; } -real_t MobileVRInterface::get_eye_height() const { +double MobileVRInterface::get_eye_height() const { return eye_height; } -void MobileVRInterface::set_iod(const real_t p_iod) { +void MobileVRInterface::set_iod(const double p_iod) { intraocular_dist = p_iod; }; -real_t MobileVRInterface::get_iod() const { +double MobileVRInterface::get_iod() const { return intraocular_dist; }; -void MobileVRInterface::set_display_width(const real_t p_display_width) { +void MobileVRInterface::set_display_width(const double p_display_width) { display_width = p_display_width; }; -real_t MobileVRInterface::get_display_width() const { +double MobileVRInterface::get_display_width() const { return display_width; }; -void MobileVRInterface::set_display_to_lens(const real_t p_display_to_lens) { +void MobileVRInterface::set_display_to_lens(const double p_display_to_lens) { display_to_lens = p_display_to_lens; }; -real_t MobileVRInterface::get_display_to_lens() const { +double MobileVRInterface::get_display_to_lens() const { return display_to_lens; }; -void MobileVRInterface::set_oversample(const real_t p_oversample) { +void MobileVRInterface::set_oversample(const double p_oversample) { oversample = p_oversample; }; -real_t MobileVRInterface::get_oversample() const { +double MobileVRInterface::get_oversample() const { return oversample; }; -void MobileVRInterface::set_k1(const real_t p_k1) { +void MobileVRInterface::set_k1(const double p_k1) { k1 = p_k1; }; -real_t MobileVRInterface::get_k1() const { +double MobileVRInterface::get_k1() const { return k1; }; -void MobileVRInterface::set_k2(const real_t p_k2) { +void MobileVRInterface::set_k2(const double p_k2) { k2 = p_k2; }; -real_t MobileVRInterface::get_k2() const { +double MobileVRInterface::get_k2() const { return k2; }; @@ -422,7 +422,7 @@ Transform3D MobileVRInterface::get_transform_for_view(uint32_t p_view, const Tra return transform_for_eye; }; -CameraMatrix MobileVRInterface::get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) { +CameraMatrix MobileVRInterface::get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) { _THREAD_SAFE_METHOD_ CameraMatrix eye; diff --git a/modules/mobile_vr/mobile_vr_interface.h b/modules/mobile_vr/mobile_vr_interface.h index 48b76ec187..a843e1188b 100644 --- a/modules/mobile_vr/mobile_vr_interface.h +++ b/modules/mobile_vr/mobile_vr_interface.h @@ -56,17 +56,17 @@ private: Basis orientation; // Just set some defaults for these. At some point we need to look at adding a lookup table for common device + headset combos and/or support reading cardboard QR codes - float eye_height = 1.85; + double eye_height = 1.85; uint64_t last_ticks = 0; - real_t intraocular_dist = 6.0; - real_t display_width = 14.5; - real_t display_to_lens = 4.0; - real_t oversample = 1.5; + double intraocular_dist = 6.0; + double display_width = 14.5; + double display_to_lens = 4.0; + double oversample = 1.5; - real_t k1 = 0.215; - real_t k2 = 0.215; - real_t aspect = 1.0; + double k1 = 0.215; + double k2 = 0.215; + double aspect = 1.0; /* logic for processing our sensor data, this was originally in our positional tracker logic but I think @@ -110,26 +110,26 @@ protected: static void _bind_methods(); public: - void set_eye_height(const real_t p_eye_height); - real_t get_eye_height() const; + void set_eye_height(const double p_eye_height); + double get_eye_height() const; - void set_iod(const real_t p_iod); - real_t get_iod() const; + void set_iod(const double p_iod); + double get_iod() const; - void set_display_width(const real_t p_display_width); - real_t get_display_width() const; + void set_display_width(const double p_display_width); + double get_display_width() const; - void set_display_to_lens(const real_t p_display_to_lens); - real_t get_display_to_lens() const; + void set_display_to_lens(const double p_display_to_lens); + double get_display_to_lens() const; - void set_oversample(const real_t p_oversample); - real_t get_oversample() const; + void set_oversample(const double p_oversample); + double get_oversample() const; - void set_k1(const real_t p_k1); - real_t get_k1() const; + void set_k1(const double p_k1); + double get_k1() const; - void set_k2(const real_t p_k2); - real_t get_k2() const; + void set_k2(const double p_k2); + double get_k2() const; virtual StringName get_name() const override; virtual uint32_t get_capabilities() const override; @@ -144,7 +144,7 @@ public: virtual uint32_t get_view_count() override; virtual Transform3D get_camera_transform() override; virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override; - virtual CameraMatrix get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) override; + virtual CameraMatrix get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) override; virtual Vector<BlitToScreen> commit_views(RID p_render_target, const Rect2 &p_screen_rect) override; virtual void process() override; diff --git a/modules/mobile_vr/register_types.cpp b/modules/mobile_vr/register_types.cpp index 47d1fe482c..233c16531a 100644 --- a/modules/mobile_vr/register_types.cpp +++ b/modules/mobile_vr/register_types.cpp @@ -32,15 +32,30 @@ #include "mobile_vr_interface.h" +Ref<MobileVRInterface> mobile_vr; + void register_mobile_vr_types() { GDREGISTER_CLASS(MobileVRInterface); if (XRServer::get_singleton()) { - Ref<MobileVRInterface> mobile_vr; mobile_vr.instantiate(); XRServer::get_singleton()->add_interface(mobile_vr); } } void unregister_mobile_vr_types() { + if (mobile_vr.is_valid()) { + // uninitialise our interface if it is initialised + if (mobile_vr->is_initialized()) { + mobile_vr->uninitialize(); + } + + // unregister our interface from the XR server + if (XRServer::get_singleton()) { + XRServer::get_singleton()->remove_interface(mobile_vr); + } + + // and release + mobile_vr.unref(); + } } diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 17846eb281..6cc7ddb424 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -2891,12 +2891,24 @@ int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, Manage ERR_FAIL_COND_V_MSG(elem_variant_type == Variant::NIL, -1, "Unknown array element type."); - int hint_res = _try_get_member_export_hint(p_member, elem_type, elem_variant_type, /* allow_generics: */ false, elem_hint, elem_hint_string); + bool preset_hint = false; + if (elem_variant_type == Variant::STRING) { + MonoObject *attr = p_member->get_attribute(CACHED_CLASS(ExportAttribute)); + if (PropertyHint(CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr)) == PROPERTY_HINT_ENUM) { + r_hint_string = itos(elem_variant_type) + "/" + itos(PROPERTY_HINT_ENUM) + ":" + CACHED_FIELD(ExportAttribute, hintString)->get_string_value(attr); + preset_hint = true; + } + } + + if (!preset_hint) { + int hint_res = _try_get_member_export_hint(p_member, elem_type, elem_variant_type, /* allow_generics: */ false, elem_hint, elem_hint_string); - ERR_FAIL_COND_V_MSG(hint_res == -1, -1, "Error while trying to determine information about the array element type."); + ERR_FAIL_COND_V_MSG(hint_res == -1, -1, "Error while trying to determine information about the array element type."); + + // Format: type/hint:hint_string + r_hint_string = itos(elem_variant_type) + "/" + itos(elem_hint) + ":" + elem_hint_string; + } - // Format: type/hint:hint_string - r_hint_string = itos(elem_variant_type) + "/" + itos(elem_hint) + ":" + elem_hint_string; r_hint = PROPERTY_HINT_TYPE_STRING; } else if (p_allow_generics && p_variant_type == Variant::DICTIONARY) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs index 8b12537f7f..70a2cf5695 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs @@ -67,6 +67,16 @@ namespace Godot } /// <summary> + /// Returns the center of the <see cref="AABB"/>, which is equal + /// to <see cref="Position"/> + (<see cref="Size"/> / 2). + /// </summary> + /// <returns>The center.</returns> + public Vector3 GetCenter() + { + return _position + (_size * 0.5f); + } + + /// <summary> /// Returns <see langword="true"/> if this <see cref="AABB"/> completely encloses another one. /// </summary> /// <param name="with">The other <see cref="AABB"/> that may be enclosed.</param> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs index 658582960f..1dc21b6303 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs @@ -78,7 +78,8 @@ namespace Godot /// </example> /// <seealso cref="GetNode{T}(NodePath)"/> /// <param name="path">The path to the node to fetch.</param> - /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam>/// ///////// <returns> + /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> + /// <returns> /// The <see cref="Node"/> at the given <paramref name="path"/>, or <see langword="null"/> if not found. /// </returns> public T GetNodeOrNull<T>(NodePath path) where T : class @@ -97,7 +98,8 @@ namespace Godot /// <exception cref="InvalidCastException"> /// Thrown when the given the fetched node can't be casted to the given type <typeparamref name="T"/>. /// </exception> - /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam>/// ///////// <returns> + /// <typeparam name="T">The type to cast to. Should be a descendant of <see cref="Node"/>.</typeparam> + /// <returns> /// The child <see cref="Node"/> at the given index <paramref name="idx"/>. /// </returns> public T GetChild<T>(int idx) where T : class diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs index 1d001fba2d..af94484577 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs @@ -165,6 +165,16 @@ namespace Godot } /// <summary> + /// Returns the center of the <see cref="Rect2"/>, which is equal + /// to <see cref="Position"/> + (<see cref="Size"/> / 2). + /// </summary> + /// <returns>The center.</returns> + public Vector2 GetCenter() + { + return _position + (_size * 0.5f); + } + + /// <summary> /// Returns a copy of the <see cref="Rect2"/> grown by the specified amount /// on all sides. /// </summary> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs index 250b0d0baf..03f406a910 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs @@ -151,7 +151,7 @@ namespace Godot } /// <summary> - /// Returns the area of the <see cref="Rect2"/>. + /// Returns the area of the <see cref="Rect2i"/>. /// </summary> /// <returns>The area.</returns> public int GetArea() @@ -160,6 +160,18 @@ namespace Godot } /// <summary> + /// Returns the center of the <see cref="Rect2i"/>, which is equal + /// to <see cref="Position"/> + (<see cref="Size"/> / 2). + /// If <see cref="Size"/> is an odd number, the returned center + /// value will be rounded towards <see cref="Position"/>. + /// </summary> + /// <returns>The center.</returns> + public Vector2i GetCenter() + { + return _position + (_size / 2); + } + + /// <summary> /// Returns a copy of the <see cref="Rect2i"/> grown by the specified amount /// on all sides. /// </summary> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index daea09ba72..c82c5f4588 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -361,6 +361,7 @@ namespace Godot /// <seealso cref="XformInv(Vector2)"/> /// <param name="v">A vector to transform.</param> /// <returns>The transformed vector.</returns> + [Obsolete("Xform is deprecated. Use the multiplication operator (Transform2D * Vector2) instead.")] public Vector2 Xform(Vector2 v) { return new Vector2(Tdotx(v), Tdoty(v)) + origin; @@ -372,6 +373,7 @@ namespace Godot /// <seealso cref="Xform(Vector2)"/> /// <param name="v">A vector to inversely transform.</param> /// <returns>The inversely transformed vector.</returns> + [Obsolete("XformInv is deprecated. Use the multiplication operator (Vector2 * Transform2D) instead.")] public Vector2 XformInv(Vector2 v) { Vector2 vInv = v - origin; @@ -447,7 +449,7 @@ namespace Godot public static Transform2D operator *(Transform2D left, Transform2D right) { - left.origin = left.Xform(right.origin); + left.origin = left * right.origin; real_t x0 = left.Tdotx(right.x); real_t x1 = left.Tdoty(right.x); @@ -462,6 +464,96 @@ namespace Godot return left; } + /// <summary> + /// Returns a Vector2 transformed (multiplied) by transformation matrix. + /// </summary> + /// <param name="transform">The transformation to apply.</param> + /// <param name="vector">A Vector2 to transform.</param> + /// <returns>The transformed Vector2.</returns> + public static Vector2 operator *(Transform2D transform, Vector2 vector) + { + return new Vector2(transform.Tdotx(vector), transform.Tdoty(vector)) + transform.origin; + } + + /// <summary> + /// Returns a Vector2 transformed (multiplied) by the inverse transformation matrix. + /// </summary> + /// <param name="vector">A Vector2 to inversely transform.</param> + /// <param name="transform">The transformation to apply.</param> + /// <returns>The inversely transformed Vector2.</returns> + public static Vector2 operator *(Vector2 vector, Transform2D transform) + { + Vector2 vInv = vector - transform.origin; + return new Vector2(transform.x.Dot(vInv), transform.y.Dot(vInv)); + } + + /// <summary> + /// Returns a Rect2 transformed (multiplied) by transformation matrix. + /// </summary> + /// <param name="transform">The transformation to apply.</param> + /// <param name="rect">A Rect2 to transform.</param> + /// <returns>The transformed Rect2.</returns> + public static Rect2 operator *(Transform2D transform, Rect2 rect) + { + Vector2 pos = transform * rect.Position; + Vector2 toX = transform.x * rect.Size.x; + Vector2 toY = transform.y * rect.Size.y; + + return new Rect2(pos, rect.Size).Expand(pos + toX).Expand(pos + toY).Expand(pos + toX + toY); + } + + /// <summary> + /// Returns a Rect2 transformed (multiplied) by the inverse transformation matrix. + /// </summary> + /// <param name="rect">A Rect2 to inversely transform.</param> + /// <param name="transform">The transformation to apply.</param> + /// <returns>The inversely transformed Rect2.</returns> + public static Rect2 operator *(Rect2 rect, Transform2D transform) + { + Vector2 pos = rect.Position * transform; + Vector2 to1 = new Vector2(rect.Position.x, rect.Position.y + rect.Size.y) * transform; + Vector2 to2 = new Vector2(rect.Position.x + rect.Size.x, rect.Position.y + rect.Size.y) * transform; + Vector2 to3 = new Vector2(rect.Position.x + rect.Size.x, rect.Position.y) * transform; + + return new Rect2(pos, rect.Size).Expand(to1).Expand(to2).Expand(to3); + } + + /// <summary> + /// Returns a copy of the given Vector2[] transformed (multiplied) by transformation matrix. + /// </summary> + /// <param name="transform">The transformation to apply.</param> + /// <param name="array">A Vector2[] to transform.</param> + /// <returns>The transformed copy of the Vector2[].</returns> + public static Vector2[] operator *(Transform2D transform, Vector2[] array) + { + Vector2[] newArray = new Vector2[array.Length]; + + for (int i = 0; i < array.Length; i++) + { + newArray[i] = transform * array[i]; + } + + return newArray; + } + + /// <summary> + /// Returns a copy of the given Vector2[] transformed (multiplied) by the inverse transformation matrix. + /// </summary> + /// <param name="array">A Vector2[] to inversely transform.</param> + /// <param name="transform">The transformation to apply.</param> + /// <returns>The inversely transformed copy of the Vector2[].</returns> + public static Vector2[] operator *(Vector2[] array, Transform2D transform) + { + Vector2[] newArray = new Vector2[array.Length]; + + for (int i = 0; i < array.Length; i++) + { + newArray[i] = array[i] * transform; + } + + return newArray; + } + public static bool operator ==(Transform2D left, Transform2D right) { return left.Equals(right); diff --git a/modules/ogg/doc_classes/OGGPacketSequence.xml b/modules/ogg/doc_classes/OGGPacketSequence.xml index 9d3789cb07..deac5b67e2 100644 --- a/modules/ogg/doc_classes/OGGPacketSequence.xml +++ b/modules/ogg/doc_classes/OGGPacketSequence.xml @@ -27,6 +27,4 @@ Holds sample rate information about this sequence. Must be set by another class that actually understands the codec. </member> </members> - <constants> - </constants> </class> diff --git a/modules/ogg/doc_classes/OGGPacketSequencePlayback.xml b/modules/ogg/doc_classes/OGGPacketSequencePlayback.xml index 49e32f0d6e..86dee15567 100644 --- a/modules/ogg/doc_classes/OGGPacketSequencePlayback.xml +++ b/modules/ogg/doc_classes/OGGPacketSequencePlayback.xml @@ -6,8 +6,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/opensimplex/doc_classes/NoiseTexture.xml b/modules/opensimplex/doc_classes/NoiseTexture.xml index 2ae7f8cad9..8a10411cf6 100644 --- a/modules/opensimplex/doc_classes/NoiseTexture.xml +++ b/modules/opensimplex/doc_classes/NoiseTexture.xml @@ -16,8 +16,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="as_normal_map" type="bool" setter="set_as_normal_map" getter="is_normal_map" default="false"> If [code]true[/code], the resulting texture contains a normal map created from the original noise interpreted as a bump map. @@ -42,6 +40,4 @@ Width of the generated texture. </member> </members> - <constants> - </constants> </class> diff --git a/modules/opensimplex/doc_classes/OpenSimplexNoise.xml b/modules/opensimplex/doc_classes/OpenSimplexNoise.xml index c470f3e1ab..604b07b645 100644 --- a/modules/opensimplex/doc_classes/OpenSimplexNoise.xml +++ b/modules/opensimplex/doc_classes/OpenSimplexNoise.xml @@ -109,6 +109,4 @@ Seed used to generate random values, different seeds will generate different noise maps. </member> </members> - <constants> - </constants> </class> diff --git a/modules/raycast/SCsub b/modules/raycast/SCsub index 1fdc8fe1b3..4820cf7608 100644 --- a/modules/raycast/SCsub +++ b/modules/raycast/SCsub @@ -79,6 +79,7 @@ if env["builtin_embree"]: env.Append(LIBS=["psapi"]) env_thirdparty = env_raycast.Clone() + env_thirdparty.force_optimization_on_debug() env_thirdparty.disable_warnings() env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources) diff --git a/modules/raycast/raycast_occlusion_cull.cpp b/modules/raycast/raycast_occlusion_cull.cpp index 88c0145ebc..a55b81c05d 100644 --- a/modules/raycast/raycast_occlusion_cull.cpp +++ b/modules/raycast/raycast_occlusion_cull.cpp @@ -66,28 +66,45 @@ void RaycastOcclusionCull::RaycastHZBuffer::resize(const Size2i &p_size) { void RaycastOcclusionCull::RaycastHZBuffer::update_camera_rays(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, ThreadWorkPool &p_thread_work_pool) { CameraRayThreadData td; - td.camera_matrix = p_cam_projection; - td.camera_transform = p_cam_transform; - td.camera_orthogonal = p_cam_orthogonal; td.thread_count = p_thread_work_pool.get_thread_count(); + td.z_near = p_cam_projection.get_z_near(); + td.z_far = p_cam_projection.get_z_far() * 1.05f; + td.camera_pos = p_cam_transform.origin; + td.camera_dir = -p_cam_transform.basis.get_axis(2); + td.camera_orthogonal = p_cam_orthogonal; + + CameraMatrix inv_camera_matrix = p_cam_projection.inverse(); + Vector3 camera_corner_proj = Vector3(-1.0f, -1.0f, -1.0f); + Vector3 camera_corner_view = inv_camera_matrix.xform(camera_corner_proj); + td.pixel_corner = p_cam_transform.xform(camera_corner_view); + + Vector3 top_corner_proj = Vector3(-1.0f, 1.0f, -1.0f); + Vector3 top_corner_view = inv_camera_matrix.xform(top_corner_proj); + Vector3 top_corner_world = p_cam_transform.xform(top_corner_view); + + Vector3 left_corner_proj = Vector3(1.0f, -1.0f, -1.0f); + Vector3 left_corner_view = inv_camera_matrix.xform(left_corner_proj); + Vector3 left_corner_world = p_cam_transform.xform(left_corner_view); + + td.pixel_u_interp = left_corner_world - td.pixel_corner; + td.pixel_v_interp = top_corner_world - td.pixel_corner; + + debug_tex_range = td.z_far; + p_thread_work_pool.do_work(td.thread_count, this, &RaycastHZBuffer::_camera_rays_threaded, &td); } -void RaycastOcclusionCull::RaycastHZBuffer::_camera_rays_threaded(uint32_t p_thread, RaycastOcclusionCull::RaycastHZBuffer::CameraRayThreadData *p_data) { +void RaycastOcclusionCull::RaycastHZBuffer::_camera_rays_threaded(uint32_t p_thread, const CameraRayThreadData *p_data) { uint32_t packs_total = camera_rays.size(); uint32_t total_threads = p_data->thread_count; uint32_t from = p_thread * packs_total / total_threads; uint32_t to = (p_thread + 1 == total_threads) ? packs_total : ((p_thread + 1) * packs_total / total_threads); - _generate_camera_rays(p_data->camera_transform, p_data->camera_matrix, p_data->camera_orthogonal, from, to); + _generate_camera_rays(p_data, from, to); } -void RaycastOcclusionCull::RaycastHZBuffer::_generate_camera_rays(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, int p_from, int p_to) { - Size2i buffer_size = sizes[0]; - - CameraMatrix inv_camera_matrix = p_cam_projection.inverse(); - float z_far = p_cam_projection.get_z_far() * 1.05f; - debug_tex_range = z_far; +void RaycastOcclusionCull::RaycastHZBuffer::_generate_camera_rays(const CameraRayThreadData *p_data, int p_from, int p_to) { + const Size2i &buffer_size = sizes[0]; RayPacket *ray_packets = camera_rays.ptr(); uint32_t *ray_masks = camera_ray_masks.ptr(); @@ -98,56 +115,52 @@ void RaycastOcclusionCull::RaycastHZBuffer::_generate_camera_rays(const Transfor int tile_y = (i / packs_size.x) * TILE_SIZE; for (int j = 0; j < TILE_RAYS; j++) { - float x = tile_x + j % TILE_SIZE; - float y = tile_y + j / TILE_SIZE; - - ray_masks[i * TILE_RAYS + j] = ~0U; + int x = tile_x + j % TILE_SIZE; + int y = tile_y + j / TILE_SIZE; if (x >= buffer_size.x || y >= buffer_size.y) { ray_masks[i * TILE_RAYS + j] = 0U; - } else { - float u = x / (buffer_size.x - 1); - float v = y / (buffer_size.y - 1); - u = u * 2.0f - 1.0f; - v = v * 2.0f - 1.0f; - - Plane pixel_proj = Plane(u, v, -1.0, 1.0); - Plane pixel_view = inv_camera_matrix.xform4(pixel_proj); - Vector3 pixel_world = p_cam_transform.xform(pixel_view.normal); - - Vector3 dir; - if (p_cam_orthogonal) { - dir = -p_cam_transform.basis.get_axis(2); - } else { - dir = (pixel_world - p_cam_transform.origin).normalized(); - } - - packet.ray.org_x[j] = pixel_world.x; - packet.ray.org_y[j] = pixel_world.y; - packet.ray.org_z[j] = pixel_world.z; + continue; + } - packet.ray.dir_x[j] = dir.x; - packet.ray.dir_y[j] = dir.y; - packet.ray.dir_z[j] = dir.z; + ray_masks[i * TILE_RAYS + j] = ~0U; - packet.ray.tnear[j] = 0.0f; + float u = (float(x) + 0.5f) / buffer_size.x; + float v = (float(y) + 0.5f) / buffer_size.y; + Vector3 pixel_pos = p_data->pixel_corner + u * p_data->pixel_u_interp + v * p_data->pixel_v_interp; - packet.ray.time[j] = 0.0f; + packet.ray.tnear[j] = p_data->z_near; - packet.ray.flags[j] = 0; - packet.ray.mask[j] = -1; - packet.hit.geomID[j] = RTC_INVALID_GEOMETRY_ID; + Vector3 dir; + if (p_data->camera_orthogonal) { + dir = -p_data->camera_dir; + packet.ray.org_x[j] = pixel_pos.x - dir.x * p_data->z_near; + packet.ray.org_y[j] = pixel_pos.y - dir.y * p_data->z_near; + packet.ray.org_z[j] = pixel_pos.z - dir.z * p_data->z_near; + } else { + dir = (pixel_pos - p_data->camera_pos).normalized(); + packet.ray.org_x[j] = p_data->camera_pos.x; + packet.ray.org_y[j] = p_data->camera_pos.y; + packet.ray.org_z[j] = p_data->camera_pos.z; + packet.ray.tnear[j] /= dir.dot(p_data->camera_dir); } - packet.ray.tfar[j] = z_far; + packet.ray.dir_x[j] = dir.x; + packet.ray.dir_y[j] = dir.y; + packet.ray.dir_z[j] = dir.z; + + packet.ray.tfar[j] = p_data->z_far; + packet.ray.time[j] = 0.0f; + + packet.ray.flags[j] = 0; + packet.ray.mask[j] = -1; + packet.hit.geomID[j] = RTC_INVALID_GEOMETRY_ID; } } } -void RaycastOcclusionCull::RaycastHZBuffer::sort_rays() { - if (is_empty()) { - return; - } +void RaycastOcclusionCull::RaycastHZBuffer::sort_rays(const Vector3 &p_camera_dir, bool p_orthogonal) { + ERR_FAIL_COND(is_empty()); Size2i buffer_size = sizes[0]; for (int i = 0; i < packs_size.y; i++) { @@ -161,7 +174,17 @@ void RaycastOcclusionCull::RaycastHZBuffer::sort_rays() { } int k = tile_i * TILE_SIZE + tile_j; int packet_index = i * packs_size.x + j; - mips[0][y * buffer_size.x + x] = camera_rays[packet_index].ray.tfar[k]; + float d = camera_rays[packet_index].ray.tfar[k]; + + if (!p_orthogonal) { + const float &dir_x = camera_rays[packet_index].ray.dir_x[k]; + const float &dir_y = camera_rays[packet_index].ray.dir_y[k]; + const float &dir_z = camera_rays[packet_index].ray.dir_z[k]; + float cos_theta = p_camera_dir.x * dir_x + p_camera_dir.y * dir_y + p_camera_dir.z * dir_z; + d *= cos_theta; + } + + mips[0][y * buffer_size.x + x] = d; } } } @@ -514,7 +537,7 @@ void RaycastOcclusionCull::buffer_update(RID p_buffer, const Transform3D &p_cam_ buffer.update_camera_rays(p_cam_transform, p_cam_projection, p_cam_orthogonal, p_thread_pool); scenario.raycast(buffer.camera_rays, buffer.camera_ray_masks, p_thread_pool); - buffer.sort_rays(); + buffer.sort_rays(-p_cam_transform.basis.get_axis(2), p_cam_orthogonal); buffer.update_mips(); } diff --git a/modules/raycast/raycast_occlusion_cull.h b/modules/raycast/raycast_occlusion_cull.h index 85710a790c..cc87a6342c 100644 --- a/modules/raycast/raycast_occlusion_cull.h +++ b/modules/raycast/raycast_occlusion_cull.h @@ -51,15 +51,20 @@ public: Size2i packs_size; struct CameraRayThreadData { - CameraMatrix camera_matrix; - Transform3D camera_transform; - bool camera_orthogonal; int thread_count; + float z_near; + float z_far; + Vector3 camera_dir; + Vector3 camera_pos; + Vector3 pixel_corner; + Vector3 pixel_u_interp; + Vector3 pixel_v_interp; + bool camera_orthogonal; Size2i buffer_size; }; - void _camera_rays_threaded(uint32_t p_thread, CameraRayThreadData *p_data); - void _generate_camera_rays(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, int p_from, int p_to); + void _camera_rays_threaded(uint32_t p_thread, const CameraRayThreadData *p_data); + void _generate_camera_rays(const CameraRayThreadData *p_data, int p_from, int p_to); public: LocalVector<RayPacket> camera_rays; @@ -68,7 +73,7 @@ public: virtual void clear() override; virtual void resize(const Size2i &p_size) override; - void sort_rays(); + void sort_rays(const Vector3 &p_camera_dir, bool p_orthogonal); void update_camera_rays(const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_orthogonal, ThreadWorkPool &p_thread_work_pool); }; diff --git a/modules/regex/doc_classes/RegEx.xml b/modules/regex/doc_classes/RegEx.xml index 9c84974ff6..2ae2e53b02 100644 --- a/modules/regex/doc_classes/RegEx.xml +++ b/modules/regex/doc_classes/RegEx.xml @@ -116,6 +116,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/regex/doc_classes/RegExMatch.xml b/modules/regex/doc_classes/RegExMatch.xml index 3cde2836cc..20680b41fd 100644 --- a/modules/regex/doc_classes/RegExMatch.xml +++ b/modules/regex/doc_classes/RegExMatch.xml @@ -51,6 +51,4 @@ The source string used with the search pattern to find this matching result. </member> </members> - <constants> - </constants> </class> diff --git a/modules/text_server_adv/SCsub b/modules/text_server_adv/SCsub index 6691f86e60..7cd4db6f67 100644 --- a/modules/text_server_adv/SCsub +++ b/modules/text_server_adv/SCsub @@ -64,6 +64,7 @@ if env["builtin_harfbuzz"]: #'src/hb-gobject-structs.cc', "src/hb-icu.cc", "src/hb-map.cc", + "src/hb-ms-feature-ranges.cc", "src/hb-number.cc", "src/hb-ot-cff1-table.cc", "src/hb-ot-cff2-table.cc", diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index 22706f9b6a..c93f353cea 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -131,20 +131,6 @@ hb_position_t TextServerAdvanced::hb_bmp_get_glyph_h_kerning(hb_font_t *p_font, return bm_font->face->kerning_map[Vector2i(p_left_glyph, p_right_glyph)].x * 64; } -hb_position_t TextServerAdvanced::hb_bmp_get_glyph_v_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data) { - const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(p_font_data); - - if (!bm_font->face) { - return 0; - } - - if (!bm_font->face->kerning_map.has(Vector2i(p_left_glyph, p_right_glyph))) { - return 0; - } - - return bm_font->face->kerning_map[Vector2i(p_left_glyph, p_right_glyph)].y * 64; -} - hb_bool_t TextServerAdvanced::hb_bmp_get_glyph_v_origin(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_position_t *r_x, hb_position_t *r_y, void *p_user_data) { const hb_bmp_font_t *bm_font = reinterpret_cast<const hb_bmp_font_t *>(p_font_data); @@ -205,7 +191,6 @@ void TextServerAdvanced::hb_bmp_create_font_funcs() { hb_font_funcs_set_glyph_v_advance_func(funcs, hb_bmp_get_glyph_v_advance, nullptr, nullptr); hb_font_funcs_set_glyph_v_origin_func(funcs, hb_bmp_get_glyph_v_origin, nullptr, nullptr); hb_font_funcs_set_glyph_h_kerning_func(funcs, hb_bmp_get_glyph_h_kerning, nullptr, nullptr); - hb_font_funcs_set_glyph_v_kerning_func(funcs, hb_bmp_get_glyph_v_kerning, nullptr, nullptr); hb_font_funcs_set_glyph_extents_func(funcs, hb_bmp_get_glyph_extents, nullptr, nullptr); hb_font_funcs_make_immutable(funcs); @@ -3588,6 +3573,7 @@ void TextServerAdvanced::shaped_text_overrun_trim_to_width(RID p_shaped_line, re shaped_text_shape(p_shaped_line); } + sd->text_trimmed = false; sd->overrun_trim_data.ellipsis_glyph_buf.clear(); bool add_ellipsis = (p_trim_flags & OVERRUN_ADD_ELLIPSIS) == OVERRUN_ADD_ELLIPSIS; @@ -3804,7 +3790,12 @@ bool TextServerAdvanced::shaped_text_update_breaks(RID p_shaped) { gl.font_rid = sd_glyphs[i].font_rid; gl.font_size = sd_glyphs[i].font_size; gl.flags = GRAPHEME_IS_BREAK_SOFT | GRAPHEME_IS_VIRTUAL; - sd->glyphs.insert(i + sd_glyphs[i].count, gl); // Insert after. + if (sd->glyphs[i].flags & GRAPHEME_IS_RTL) { + gl.flags |= GRAPHEME_IS_RTL; + sd->glyphs.insert(i, gl); // Insert before. + } else { + sd->glyphs.insert(i + sd_glyphs[i].count, gl); // Insert after. + } // Update write pointer and size. sd_size = sd->glyphs.size(); @@ -3998,7 +3989,12 @@ bool TextServerAdvanced::shaped_text_update_justification_ops(RID p_shaped) { gl.font_rid = sd->glyphs[i].font_rid; gl.font_size = sd->glyphs[i].font_size; gl.flags = GRAPHEME_IS_SPACE | GRAPHEME_IS_VIRTUAL; - sd->glyphs.insert(i + sd->glyphs[i].count, gl); // Insert after. + if (sd->glyphs[i].flags & GRAPHEME_IS_RTL) { + gl.flags |= GRAPHEME_IS_RTL; + sd->glyphs.insert(i, gl); // Insert before. + } else { + sd->glyphs.insert(i + sd->glyphs[i].count, gl); // Insert after. + } i += sd->glyphs[i].count; continue; } @@ -4147,7 +4143,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star } } if (p_direction == HB_DIRECTION_RTL || p_direction == HB_DIRECTION_BTT) { - w[last_cluster_index].flags |= TextServer::GRAPHEME_IS_RTL; + w[last_cluster_index].flags |= GRAPHEME_IS_RTL; } if (last_cluster_valid) { w[last_cluster_index].flags |= GRAPHEME_IS_VALID; @@ -4169,6 +4165,10 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star gl.font_rid = p_fonts[p_fb_index]; gl.font_size = fs; + if (glyph_info[i].mask & HB_GLYPH_FLAG_DEFINED) { + gl.flags |= GRAPHEME_IS_CONNECTED; + } + gl.index = glyph_info[i].codepoint; if (gl.index != 0) { real_t scale = font_get_scale(f, fs); @@ -4187,9 +4187,9 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star } if (p_sd->preserve_control) { - last_cluster_valid = last_cluster_valid && ((glyph_info[i].codepoint != 0) || is_whitespace(p_sd->text[glyph_info[i].cluster]) || is_linebreak(p_sd->text[glyph_info[i].cluster])); + last_cluster_valid = last_cluster_valid && ((glyph_info[i].codepoint != 0) || (p_sd->text[glyph_info[i].cluster] == 0x0009) || (u_isblank(p_sd->text[glyph_info[i].cluster]) && (gl.advance != 0)) || (!u_isblank(p_sd->text[glyph_info[i].cluster]) && is_linebreak(p_sd->text[glyph_info[i].cluster]))); } else { - last_cluster_valid = last_cluster_valid && ((glyph_info[i].codepoint != 0) || !u_isgraph(p_sd->text[glyph_info[i].cluster])); + last_cluster_valid = last_cluster_valid && ((glyph_info[i].codepoint != 0) || (p_sd->text[glyph_info[i].cluster] == 0x0009) || (u_isblank(p_sd->text[glyph_info[i].cluster]) && (gl.advance != 0)) || (!u_isblank(p_sd->text[glyph_info[i].cluster]) && !u_isgraph(p_sd->text[glyph_info[i].cluster]))); } } if (p_direction == HB_DIRECTION_LTR || p_direction == HB_DIRECTION_TTB) { @@ -4199,7 +4199,7 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int32_t p_star } w[last_cluster_index].count = glyph_count - last_cluster_index; if (p_direction == HB_DIRECTION_RTL || p_direction == HB_DIRECTION_BTT) { - w[last_cluster_index].flags |= TextServer::GRAPHEME_IS_RTL; + w[last_cluster_index].flags |= GRAPHEME_IS_RTL; } if (last_cluster_valid) { w[last_cluster_index].flags |= GRAPHEME_IS_VALID; diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 5989035800..fc0e7a09a7 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -269,7 +269,6 @@ class TextServerAdvanced : public TextServer { static hb_position_t hb_bmp_get_glyph_h_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data); static hb_position_t hb_bmp_get_glyph_v_advance(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, void *p_user_data); static hb_position_t hb_bmp_get_glyph_h_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data); - static hb_position_t hb_bmp_get_glyph_v_kerning(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_left_glyph, hb_codepoint_t p_right_glyph, void *p_user_data); static hb_bool_t hb_bmp_get_glyph_v_origin(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_position_t *r_x, hb_position_t *r_y, void *p_user_data); static hb_bool_t hb_bmp_get_glyph_extents(hb_font_t *p_font, void *p_font_data, hb_codepoint_t p_glyph, hb_glyph_extents_t *r_extents, void *p_user_data); static hb_bool_t hb_bmp_get_font_h_extents(hb_font_t *p_font, void *p_font_data, hb_font_extents_t *r_metrics, void *p_user_data); diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index 8a1bd93c65..1323aa80ce 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -2683,6 +2683,7 @@ void TextServerFallback::shaped_text_overrun_trim_to_width(RID p_shaped_line, re shaped_text_shape(p_shaped_line); } + sd->text_trimmed = false; sd->overrun_trim_data.ellipsis_glyph_buf.clear(); bool add_ellipsis = (p_trim_flags & OVERRUN_ADD_ELLIPSIS) == OVERRUN_ADD_ELLIPSIS; diff --git a/modules/theora/doc_classes/VideoStreamTheora.xml b/modules/theora/doc_classes/VideoStreamTheora.xml index e7bf9b202d..2dfcd27dff 100644 --- a/modules/theora/doc_classes/VideoStreamTheora.xml +++ b/modules/theora/doc_classes/VideoStreamTheora.xml @@ -24,6 +24,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScript.xml b/modules/visual_script/doc_classes/VisualScript.xml index 2327fc0009..372d46bc10 100644 --- a/modules/visual_script/doc_classes/VisualScript.xml +++ b/modules/visual_script/doc_classes/VisualScript.xml @@ -354,6 +354,4 @@ </description> </signal> </signals> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml b/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml index 4d07f878a2..ed5b814bb7 100644 --- a/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml +++ b/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type" default="0"> The type to get the constant from. @@ -18,6 +16,4 @@ The name of the constant to return. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml index 55d0b392fa..942d92311b 100644 --- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml +++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml @@ -9,8 +9,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="function" type="int" setter="set_func" getter="get_func" enum="VisualScriptBuiltinFunc.BuiltinFunc" default="0"> The function to be executed. @@ -181,32 +179,34 @@ <constant name="TEXT_PRINTRAW" value="55" enum="BuiltinFunc"> Print the given string to the standard output, without adding a newline. </constant> - <constant name="VAR_TO_STR" value="56" enum="BuiltinFunc"> + <constant name="TEXT_PRINT_VERBOSE" value="56" enum="BuiltinFunc"> + </constant> + <constant name="VAR_TO_STR" value="57" enum="BuiltinFunc"> Serialize a [Variant] to a string. </constant> - <constant name="STR_TO_VAR" value="57" enum="BuiltinFunc"> + <constant name="STR_TO_VAR" value="58" enum="BuiltinFunc"> Deserialize a [Variant] from a string serialized using [constant VAR_TO_STR]. </constant> - <constant name="VAR_TO_BYTES" value="58" enum="BuiltinFunc"> + <constant name="VAR_TO_BYTES" value="59" enum="BuiltinFunc"> Serialize a [Variant] to a [PackedByteArray]. </constant> - <constant name="BYTES_TO_VAR" value="59" enum="BuiltinFunc"> + <constant name="BYTES_TO_VAR" value="60" enum="BuiltinFunc"> Deserialize a [Variant] from a [PackedByteArray] serialized using [constant VAR_TO_BYTES]. </constant> - <constant name="MATH_SMOOTHSTEP" value="60" enum="BuiltinFunc"> + <constant name="MATH_SMOOTHSTEP" value="61" enum="BuiltinFunc"> Return a number smoothly interpolated between the first two inputs, based on the third input. Similar to [constant MATH_LERP], but interpolates faster at the beginning and slower at the end. Using Hermite interpolation formula: [codeblock] var t = clamp((weight - from) / (to - from), 0.0, 1.0) return t * t * (3.0 - 2.0 * t) [/codeblock] </constant> - <constant name="MATH_POSMOD" value="61" enum="BuiltinFunc"> + <constant name="MATH_POSMOD" value="62" enum="BuiltinFunc"> </constant> - <constant name="MATH_LERP_ANGLE" value="62" enum="BuiltinFunc"> + <constant name="MATH_LERP_ANGLE" value="63" enum="BuiltinFunc"> </constant> - <constant name="TEXT_ORD" value="63" enum="BuiltinFunc"> + <constant name="TEXT_ORD" value="64" enum="BuiltinFunc"> </constant> - <constant name="FUNC_MAX" value="64" enum="BuiltinFunc"> + <constant name="FUNC_MAX" value="65" enum="BuiltinFunc"> Represents the size of the [enum BuiltinFunc] enum. </constant> </constants> diff --git a/modules/visual_script/doc_classes/VisualScriptClassConstant.xml b/modules/visual_script/doc_classes/VisualScriptClassConstant.xml index d6b96957f5..ae32500d2f 100644 --- a/modules/visual_script/doc_classes/VisualScriptClassConstant.xml +++ b/modules/visual_script/doc_classes/VisualScriptClassConstant.xml @@ -12,8 +12,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&"Object""> The constant's parent class. @@ -22,6 +20,4 @@ The constant to return. See the given class for its available constants. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptComment.xml b/modules/visual_script/doc_classes/VisualScriptComment.xml index 02cec97b27..5024aae384 100644 --- a/modules/visual_script/doc_classes/VisualScriptComment.xml +++ b/modules/visual_script/doc_classes/VisualScriptComment.xml @@ -9,8 +9,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="description" type="String" setter="set_description" getter="get_description" default=""""> The text inside the comment node. @@ -22,6 +20,4 @@ The comment node's title. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptComposeArray.xml b/modules/visual_script/doc_classes/VisualScriptComposeArray.xml index dec182abf6..ed065759c5 100644 --- a/modules/visual_script/doc_classes/VisualScriptComposeArray.xml +++ b/modules/visual_script/doc_classes/VisualScriptComposeArray.xml @@ -8,8 +8,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptCondition.xml b/modules/visual_script/doc_classes/VisualScriptCondition.xml index a9981c1f57..a5dd8c7c1b 100644 --- a/modules/visual_script/doc_classes/VisualScriptCondition.xml +++ b/modules/visual_script/doc_classes/VisualScriptCondition.xml @@ -15,8 +15,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptConstant.xml b/modules/visual_script/doc_classes/VisualScriptConstant.xml index 69676c4bba..388c2bddde 100644 --- a/modules/visual_script/doc_classes/VisualScriptConstant.xml +++ b/modules/visual_script/doc_classes/VisualScriptConstant.xml @@ -12,8 +12,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="type" type="int" setter="set_constant_type" getter="get_constant_type" enum="Variant.Type" default="0"> The constant's type. @@ -22,6 +20,4 @@ The constant's value. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptConstructor.xml b/modules/visual_script/doc_classes/VisualScriptConstructor.xml index 4743594ec3..4a3d10aa8e 100644 --- a/modules/visual_script/doc_classes/VisualScriptConstructor.xml +++ b/modules/visual_script/doc_classes/VisualScriptConstructor.xml @@ -32,6 +32,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml b/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml index 530c80530e..fd9a91c2a5 100644 --- a/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml +++ b/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml @@ -8,13 +8,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="type" type="int" setter="set_deconstruct_type" getter="get_deconstruct_type" enum="Variant.Type" default="0"> The type to deconstruct. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml b/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml index df3121d093..e102e02aa9 100644 --- a/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml +++ b/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml @@ -12,13 +12,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="signal" type="StringName" setter="set_signal" getter="get_signal" default="&"""> The signal to emit. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml b/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml index 8b7fd3a612..468cae852f 100644 --- a/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml +++ b/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml @@ -8,13 +8,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="constant" type="String" setter="set_singleton" getter="get_singleton" default=""""> The singleton's name. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptExpression.xml b/modules/visual_script/doc_classes/VisualScriptExpression.xml index 223adbbb96..15e16a15f0 100644 --- a/modules/visual_script/doc_classes/VisualScriptExpression.xml +++ b/modules/visual_script/doc_classes/VisualScriptExpression.xml @@ -8,8 +8,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptFunction.xml b/modules/visual_script/doc_classes/VisualScriptFunction.xml index 652418bd64..e0ca9eb280 100644 --- a/modules/visual_script/doc_classes/VisualScriptFunction.xml +++ b/modules/visual_script/doc_classes/VisualScriptFunction.xml @@ -8,8 +8,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml index f0b666e57a..a98cb79106 100644 --- a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml +++ b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> The script to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE]. diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml index 18c3826df8..0d7833446d 100644 --- a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml +++ b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml @@ -32,6 +32,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml index 87fdfd4e53..c6b5b22590 100644 --- a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml +++ b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml @@ -8,13 +8,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="constant" type="int" setter="set_global_constant" getter="get_global_constant" default="0"> The constant to be used. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml index b348048298..78fd17c5fc 100644 --- a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml +++ b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml @@ -8,8 +8,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml index d7fe7340ad..0e5e832c65 100644 --- a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml +++ b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml @@ -8,8 +8,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptInputAction.xml b/modules/visual_script/doc_classes/VisualScriptInputAction.xml index d6fa111500..eb06d52314 100644 --- a/modules/visual_script/doc_classes/VisualScriptInputAction.xml +++ b/modules/visual_script/doc_classes/VisualScriptInputAction.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="action" type="StringName" setter="set_action_name" getter="get_action_name" default="&"""> Name of the action. diff --git a/modules/visual_script/doc_classes/VisualScriptIterator.xml b/modules/visual_script/doc_classes/VisualScriptIterator.xml index 1d4ab4daa9..d8305728c6 100644 --- a/modules/visual_script/doc_classes/VisualScriptIterator.xml +++ b/modules/visual_script/doc_classes/VisualScriptIterator.xml @@ -15,8 +15,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptLists.xml b/modules/visual_script/doc_classes/VisualScriptLists.xml index d5bff1341a..373e3c7191 100644 --- a/modules/visual_script/doc_classes/VisualScriptLists.xml +++ b/modules/visual_script/doc_classes/VisualScriptLists.xml @@ -74,6 +74,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptLocalVar.xml b/modules/visual_script/doc_classes/VisualScriptLocalVar.xml index 185f0f1ffb..29dbddcdf4 100644 --- a/modules/visual_script/doc_classes/VisualScriptLocalVar.xml +++ b/modules/visual_script/doc_classes/VisualScriptLocalVar.xml @@ -12,8 +12,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="type" type="int" setter="set_var_type" getter="get_var_type" enum="Variant.Type" default="0"> The local variable's type. @@ -22,6 +20,4 @@ The local variable's name. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml b/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml index 865f0153c9..96de8ebfdd 100644 --- a/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml +++ b/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml @@ -14,8 +14,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="type" type="int" setter="set_var_type" getter="get_var_type" enum="Variant.Type" default="0"> The local variable's type. @@ -24,6 +22,4 @@ The local variable's name. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptMathConstant.xml b/modules/visual_script/doc_classes/VisualScriptMathConstant.xml index 18a1f030bc..f559083c80 100644 --- a/modules/visual_script/doc_classes/VisualScriptMathConstant.xml +++ b/modules/visual_script/doc_classes/VisualScriptMathConstant.xml @@ -12,8 +12,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="constant" type="int" setter="set_math_constant" getter="get_math_constant" enum="VisualScriptMathConstant.MathConstant" default="0"> The math constant. diff --git a/modules/visual_script/doc_classes/VisualScriptNode.xml b/modules/visual_script/doc_classes/VisualScriptNode.xml index 23574a5ea8..d080d9eac1 100644 --- a/modules/visual_script/doc_classes/VisualScriptNode.xml +++ b/modules/visual_script/doc_classes/VisualScriptNode.xml @@ -44,6 +44,4 @@ </description> </signal> </signals> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptOperator.xml b/modules/visual_script/doc_classes/VisualScriptOperator.xml index cbbefa7f71..73d28899f6 100644 --- a/modules/visual_script/doc_classes/VisualScriptOperator.xml +++ b/modules/visual_script/doc_classes/VisualScriptOperator.xml @@ -12,8 +12,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="operator" type="int" setter="set_operator" getter="get_operator" enum="Variant.Operator" default="6"> The operation to be performed. See [enum Variant.Operator] for available options. @@ -22,6 +20,4 @@ The type of the values for this operation. See [enum Variant.Type] for available options. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptPreload.xml b/modules/visual_script/doc_classes/VisualScriptPreload.xml index e11af6c805..e3d60c77bb 100644 --- a/modules/visual_script/doc_classes/VisualScriptPreload.xml +++ b/modules/visual_script/doc_classes/VisualScriptPreload.xml @@ -12,13 +12,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="resource" type="Resource" setter="set_preload" getter="get_preload"> The [Resource] to load. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml index c1bf443ea3..e9f30cb605 100644 --- a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml +++ b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> The script to be used when [member set_mode] is set to [constant CALL_MODE_INSTANCE]. diff --git a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml index 75d6a63469..96261d2c5e 100644 --- a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml +++ b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="assign_op" type="int" setter="set_assign_op" getter="get_assign_op" enum="VisualScriptPropertySet.AssignOp" default="0"> The additional operation to perform when assigning. See [enum AssignOp] for options. diff --git a/modules/visual_script/doc_classes/VisualScriptResourcePath.xml b/modules/visual_script/doc_classes/VisualScriptResourcePath.xml index ea891be05f..77e97a7219 100644 --- a/modules/visual_script/doc_classes/VisualScriptResourcePath.xml +++ b/modules/visual_script/doc_classes/VisualScriptResourcePath.xml @@ -6,12 +6,8 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="path" type="String" setter="set_resource_path" getter="get_resource_path" default=""""> </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptReturn.xml b/modules/visual_script/doc_classes/VisualScriptReturn.xml index 502628925d..2193f45dc8 100644 --- a/modules/visual_script/doc_classes/VisualScriptReturn.xml +++ b/modules/visual_script/doc_classes/VisualScriptReturn.xml @@ -13,8 +13,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="return_enabled" type="bool" setter="set_enable_return_value" getter="is_return_value_enabled" default="false"> If [code]true[/code], the [code]return[/code] input port is available. @@ -23,6 +21,4 @@ The return value's data type. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptSceneNode.xml b/modules/visual_script/doc_classes/VisualScriptSceneNode.xml index ffe187a00e..ac672d9b3f 100644 --- a/modules/visual_script/doc_classes/VisualScriptSceneNode.xml +++ b/modules/visual_script/doc_classes/VisualScriptSceneNode.xml @@ -12,13 +12,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="node_path" type="NodePath" setter="set_node_path" getter="get_node_path" default="NodePath(".")"> The node's path in the scene tree. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml index 8cddd02c77..fc383593c5 100644 --- a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml +++ b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml @@ -8,8 +8,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptSelect.xml b/modules/visual_script/doc_classes/VisualScriptSelect.xml index 1dbc066e32..d536e623f7 100644 --- a/modules/visual_script/doc_classes/VisualScriptSelect.xml +++ b/modules/visual_script/doc_classes/VisualScriptSelect.xml @@ -14,13 +14,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="type" type="int" setter="set_typed" getter="get_typed" enum="Variant.Type" default="0"> The input variables' type. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptSelf.xml b/modules/visual_script/doc_classes/VisualScriptSelf.xml index bb24f158c1..3c2bd16302 100644 --- a/modules/visual_script/doc_classes/VisualScriptSelf.xml +++ b/modules/visual_script/doc_classes/VisualScriptSelf.xml @@ -12,8 +12,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptSequence.xml b/modules/visual_script/doc_classes/VisualScriptSequence.xml index 664722574d..32dcbb9837 100644 --- a/modules/visual_script/doc_classes/VisualScriptSequence.xml +++ b/modules/visual_script/doc_classes/VisualScriptSequence.xml @@ -14,13 +14,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="steps" type="int" setter="set_steps" getter="get_steps" default="1"> The number of steps in the sequence. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptSubCall.xml b/modules/visual_script/doc_classes/VisualScriptSubCall.xml index f54887b09c..fdf0e24d3e 100644 --- a/modules/visual_script/doc_classes/VisualScriptSubCall.xml +++ b/modules/visual_script/doc_classes/VisualScriptSubCall.xml @@ -8,8 +8,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptSwitch.xml b/modules/visual_script/doc_classes/VisualScriptSwitch.xml index 74504948f0..8e176b56f0 100644 --- a/modules/visual_script/doc_classes/VisualScriptSwitch.xml +++ b/modules/visual_script/doc_classes/VisualScriptSwitch.xml @@ -17,8 +17,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml index 5dd1ad3421..ee8e2ad31e 100644 --- a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml +++ b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="base_script" type="String" setter="set_base_script" getter="get_base_script" default=""""> The target script class to be converted to. If none, only the [member base_type] will be used. @@ -18,6 +16,4 @@ The target type to be converted to. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml b/modules/visual_script/doc_classes/VisualScriptVariableGet.xml index df20ac53f2..e29765d616 100644 --- a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml +++ b/modules/visual_script/doc_classes/VisualScriptVariableGet.xml @@ -12,13 +12,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="var_name" type="StringName" setter="set_variable" getter="get_variable" default="&"""> The variable's name. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml b/modules/visual_script/doc_classes/VisualScriptVariableSet.xml index eb8ebbe338..b2cc70d62e 100644 --- a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml +++ b/modules/visual_script/doc_classes/VisualScriptVariableSet.xml @@ -13,13 +13,9 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="var_name" type="StringName" setter="set_variable" getter="get_variable" default="&"""> The variable's name. </member> </members> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptWhile.xml b/modules/visual_script/doc_classes/VisualScriptWhile.xml index f187957ad2..f090568608 100644 --- a/modules/visual_script/doc_classes/VisualScriptWhile.xml +++ b/modules/visual_script/doc_classes/VisualScriptWhile.xml @@ -14,8 +14,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/visual_script/doc_classes/VisualScriptYield.xml b/modules/visual_script/doc_classes/VisualScriptYield.xml index b04ab7b014..bb7fd8bfb5 100644 --- a/modules/visual_script/doc_classes/VisualScriptYield.xml +++ b/modules/visual_script/doc_classes/VisualScriptYield.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="mode" type="int" setter="set_yield_mode" getter="get_yield_mode" enum="VisualScriptYield.YieldMode" default="1"> The mode to use for yielding. See [enum YieldMode] for available options. diff --git a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml index c6c3188d08..ad6a7fb4e2 100644 --- a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml +++ b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml @@ -8,8 +8,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="base_type" type="StringName" setter="set_base_type" getter="get_base_type" default="&"Object""> The base type to be used when [member call_mode] is set to [constant CALL_MODE_INSTANCE]. diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 2bd7220d15..7e01031128 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -94,6 +94,7 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX "print", "printerr", "printraw", + "print_verbose", "var2str", "str2var", "var2bytes", @@ -129,6 +130,7 @@ bool VisualScriptBuiltinFunc::has_input_sequence_port() const { case TEXT_PRINT: case TEXT_PRINTERR: case TEXT_PRINTRAW: + case TEXT_PRINT_VERBOSE: case MATH_SEED: return true; default: @@ -177,6 +179,7 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { case TEXT_PRINT: case TEXT_PRINTERR: case TEXT_PRINTRAW: + case TEXT_PRINT_VERBOSE: case VAR_TO_STR: case STR_TO_VAR: case TYPE_EXISTS: @@ -223,6 +226,7 @@ int VisualScriptBuiltinFunc::get_output_value_port_count() const { case TEXT_PRINT: case TEXT_PRINTERR: case TEXT_PRINTRAW: + case TEXT_PRINT_VERBOSE: case MATH_SEED: return 0; case MATH_RANDSEED: @@ -424,7 +428,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const case TEXT_STR: case TEXT_PRINT: case TEXT_PRINTERR: - case TEXT_PRINTRAW: { + case TEXT_PRINTRAW: + case TEXT_PRINT_VERBOSE: { return PropertyInfo(Variant::NIL, "value"); } break; case STR_TO_VAR: { @@ -572,6 +577,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons } break; case TEXT_PRINTRAW: { } break; + case TEXT_PRINT_VERBOSE: { + } break; case VAR_TO_STR: { t = Variant::STRING; } break; @@ -1020,6 +1027,10 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in OS::get_singleton()->print("%s", str.utf8().get_data()); } break; + case VisualScriptBuiltinFunc::TEXT_PRINT_VERBOSE: { + String str = *p_inputs[0]; + print_verbose(str); + } break; case VisualScriptBuiltinFunc::VAR_TO_STR: { String vars; VariantWriter::write_to_string(*p_inputs[0], vars); @@ -1208,6 +1219,7 @@ void VisualScriptBuiltinFunc::_bind_methods() { BIND_ENUM_CONSTANT(TEXT_PRINT); BIND_ENUM_CONSTANT(TEXT_PRINTERR); BIND_ENUM_CONSTANT(TEXT_PRINTRAW); + BIND_ENUM_CONSTANT(TEXT_PRINT_VERBOSE); BIND_ENUM_CONSTANT(VAR_TO_STR); BIND_ENUM_CONSTANT(STR_TO_VAR); BIND_ENUM_CONSTANT(VAR_TO_BYTES); @@ -1300,6 +1312,7 @@ void register_visual_script_builtin_func_node() { VisualScriptLanguage::singleton->add_register_func("functions/built_in/print", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/printerr", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTERR>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/printraw", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTRAW>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/print_verbose", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT_VERBOSE>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2str", create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_STR>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/str2var", create_builtin_func_node<VisualScriptBuiltinFunc::STR_TO_VAR>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/var2bytes", create_builtin_func_node<VisualScriptBuiltinFunc::VAR_TO_BYTES>); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 26abc1e479..f9eb7e983f 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -94,6 +94,7 @@ public: TEXT_PRINT, TEXT_PRINTERR, TEXT_PRINTRAW, + TEXT_PRINT_VERBOSE, VAR_TO_STR, STR_TO_VAR, VAR_TO_BYTES, diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index eee9e8f32b..0a6bcedf31 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -2546,16 +2546,11 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { error_line = p_line; } - List<StringName> functions; - script->get_function_list(&functions); - for (const StringName &E : functions) { - if (script->has_node(p_line)) { - _update_graph(); - _update_members(); + if (script->has_node(p_line)) { + _update_graph(); + _update_members(); - call_deferred(SNAME("call_deferred"), "_center_on_node", E, p_line); //editor might be just created and size might not exist yet - return; - } + call_deferred(SNAME("call_deferred"), "_center_on_node", p_line); // The editor might be just created and size might not exist yet. } } @@ -3592,6 +3587,11 @@ void VisualScriptEditor::_hide_timer() { hint_text->hide(); } +void VisualScriptEditor::_toggle_scripts_pressed() { + ScriptEditor::get_singleton()->toggle_scripts_panel(); + update_toggle_scripts_button(); +} + void VisualScriptEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { @@ -3606,6 +3606,8 @@ void VisualScriptEditor::_notification(int p_what) { return; } + update_toggle_scripts_button(); + edit_variable_edit->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); edit_signal_edit->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); func_input_scroll->add_theme_style_override("bg", get_theme_stylebox(SNAME("bg"), SNAME("Tree"))); @@ -3650,6 +3652,7 @@ void VisualScriptEditor::_notification(int p_what) { } } break; case NOTIFICATION_VISIBILITY_CHANGED: { + update_toggle_scripts_button(); members_section->set_visible(is_visible_in_tree()); } break; } @@ -4232,6 +4235,15 @@ void VisualScriptEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_h void VisualScriptEditor::set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) { } +void VisualScriptEditor::update_toggle_scripts_button() { + if (is_layout_rtl()) { + toggle_scripts_button->set_icon(Control::get_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Forward") : SNAME("Back"), SNAME("EditorIcons"))); + } else { + toggle_scripts_button->set_icon(Control::get_theme_icon(ScriptEditor::get_singleton()->is_scripts_panel_toggled() ? SNAME("Back") : SNAME("Forward"), SNAME("EditorIcons"))); + } + toggle_scripts_button->set_tooltip(vformat("%s (%s)", TTR("Toggle Scripts Panel"), ED_GET_SHORTCUT("script_editor/toggle_scripts_panel")->get_as_text())); +} + void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node); ClassDB::bind_method("_update_graph", &VisualScriptEditor::_update_graph, DEFVAL(-1)); @@ -4333,6 +4345,16 @@ VisualScriptEditor::VisualScriptEditor() { graph->hide(); graph->connect("scroll_offset_changed", callable_mp(this, &VisualScriptEditor::_graph_ofs_changed)); + status_bar = memnew(HBoxContainer); + add_child(status_bar); + status_bar->set_h_size_flags(SIZE_EXPAND_FILL); + status_bar->set_custom_minimum_size(Size2(0, 24 * EDSCALE)); + + toggle_scripts_button = memnew(Button); + toggle_scripts_button->set_flat(true); + toggle_scripts_button->connect("pressed", callable_mp(this, &VisualScriptEditor::_toggle_scripts_pressed)); + status_bar->add_child(toggle_scripts_button); + /// Add Buttons to Top Bar/Zoom bar. HBoxContainer *graph_hbc = graph->get_zoom_hbox(); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index ab32aae7aa..19f5aabac9 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -93,6 +93,8 @@ class VisualScriptEditor : public ScriptEditorBase { ConfirmationDialog *function_create_dialog; GraphEdit *graph; + HBoxContainer *status_bar; + Button *toggle_scripts_button; VisualScriptEditorSignalEdit *signal_editor; @@ -281,6 +283,8 @@ class VisualScriptEditor : public ScriptEditorBase { void _member_rmb_selected(const Vector2 &p_pos); void _member_option(int p_option); + void _toggle_scripts_pressed(); + protected: void _notification(int p_what); static void _bind_methods(); @@ -330,6 +334,8 @@ public: static void free_clipboard(); + void update_toggle_scripts_button() override; + VisualScriptEditor(); ~VisualScriptEditor(); }; diff --git a/modules/vorbis/doc_classes/AudioStreamOGGVorbis.xml b/modules/vorbis/doc_classes/AudioStreamOGGVorbis.xml index a680a2f999..4cd278fe83 100644 --- a/modules/vorbis/doc_classes/AudioStreamOGGVorbis.xml +++ b/modules/vorbis/doc_classes/AudioStreamOGGVorbis.xml @@ -6,8 +6,6 @@ </description> <tutorials> </tutorials> - <methods> - </methods> <members> <member name="loop" type="bool" setter="set_loop" getter="has_loop" default="false"> If [code]true[/code], the stream will automatically loop when it reaches the end. @@ -19,6 +17,4 @@ Contains the raw OGG data for this stream. </member> </members> - <constants> - </constants> </class> diff --git a/modules/vorbis/doc_classes/AudioStreamPlaybackOGGVorbis.xml b/modules/vorbis/doc_classes/AudioStreamPlaybackOGGVorbis.xml index 3120f2a9e6..05c70d88da 100644 --- a/modules/vorbis/doc_classes/AudioStreamPlaybackOGGVorbis.xml +++ b/modules/vorbis/doc_classes/AudioStreamPlaybackOGGVorbis.xml @@ -6,8 +6,4 @@ </description> <tutorials> </tutorials> - <methods> - </methods> - <constants> - </constants> </class> diff --git a/modules/webm/doc_classes/VideoStreamWebm.xml b/modules/webm/doc_classes/VideoStreamWebm.xml index 3b9acfd873..e04d02d6ab 100644 --- a/modules/webm/doc_classes/VideoStreamWebm.xml +++ b/modules/webm/doc_classes/VideoStreamWebm.xml @@ -25,6 +25,4 @@ </description> </method> </methods> - <constants> - </constants> </class> diff --git a/modules/webrtc/SCsub b/modules/webrtc/SCsub index 31b8a73bf2..e6b9959840 100644 --- a/modules/webrtc/SCsub +++ b/modules/webrtc/SCsub @@ -4,11 +4,6 @@ Import("env") Import("env_modules") env_webrtc = env_modules.Clone() -use_gdnative = env_webrtc["module_gdnative_enabled"] - -if use_gdnative: # GDNative is retained in Javascript for export compatibility - env_webrtc.Append(CPPDEFINES=["WEBRTC_GDNATIVE_ENABLED"]) - env_webrtc.Prepend(CPPPATH=["#modules/gdnative/include/"]) if env["platform"] == "javascript": # Our JavaScript/C++ interface. diff --git a/modules/webrtc/config.py b/modules/webrtc/config.py index 3281415f38..4ad918833a 100644 --- a/modules/webrtc/config.py +++ b/modules/webrtc/config.py @@ -11,6 +11,8 @@ def get_doc_classes(): "WebRTCPeerConnection", "WebRTCDataChannel", "WebRTCMultiplayerPeer", + "WebRTCPeerConnectionExtension", + "WebRTCDataChannelExtension", ] diff --git a/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml b/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml new file mode 100644 index 0000000000..26a4391b83 --- /dev/null +++ b/modules/webrtc/doc_classes/WebRTCDataChannelExtension.xml @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="WebRTCDataChannelExtension" inherits="WebRTCDataChannel" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="_close" qualifiers="virtual"> + <return type="void" /> + <description> + </description> + </method> + <method name="_get_available_packet_count" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_buffered_amount" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_id" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_label" qualifiers="virtual const"> + <return type="String" /> + <description> + </description> + </method> + <method name="_get_max_packet_life_time" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_max_packet_size" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_max_retransmits" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_packet" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="r_buffer" type="const void*" /> + <argument index="1" name="r_buffer_size" type="int32_t*" /> + <description> + </description> + </method> + <method name="_get_protocol" qualifiers="virtual const"> + <return type="String" /> + <description> + </description> + </method> + <method name="_get_ready_state" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_write_mode" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_is_negotiated" qualifiers="virtual const"> + <return type="bool" /> + <description> + </description> + </method> + <method name="_is_ordered" qualifiers="virtual const"> + <return type="bool" /> + <description> + </description> + </method> + <method name="_poll" qualifiers="virtual"> + <return type="int" /> + <description> + </description> + </method> + <method name="_put_packet" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_buffer" type="const void*" /> + <argument index="1" name="p_buffer_size" type="int" /> + <description> + </description> + </method> + <method name="_set_write_mode" qualifiers="virtual"> + <return type="void" /> + <argument index="0" name="p_write_mode" type="int" /> + <description> + </description> + </method> + <method name="_was_string_packet" qualifiers="virtual const"> + <return type="bool" /> + <description> + </description> + </method> + </methods> +</class> diff --git a/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml index 43a8e20ef7..a8360a4d45 100644 --- a/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml +++ b/modules/webrtc/doc_classes/WebRTCMultiplayerPeer.xml @@ -7,6 +7,7 @@ This class constructs a full mesh of [WebRTCPeerConnection] (one connection for each peer) that can be used as a [member MultiplayerAPI.multiplayer_peer]. You can add each [WebRTCPeerConnection] via [method add_peer] or remove them via [method remove_peer]. Peers must be added in [constant WebRTCPeerConnection.STATE_NEW] state to allow it to create the appropriate channels. This class will not create offers nor set descriptions, it will only poll them, and notify connections and disconnections. [signal MultiplayerPeer.connection_succeeded] and [signal MultiplayerPeer.server_disconnected] will not be emitted unless [code]server_compatibility[/code] is [code]true[/code] in [method initialize]. Beside that data transfer works like in a [MultiplayerPeer]. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> </tutorials> @@ -67,10 +68,4 @@ </description> </method> </methods> - <members> - <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="TransferMode" default="2" /> - </members> - <constants> - </constants> </class> diff --git a/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml b/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml new file mode 100644 index 0000000000..d296fcd6e7 --- /dev/null +++ b/modules/webrtc/doc_classes/WebRTCPeerConnectionExtension.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="WebRTCPeerConnectionExtension" inherits="WebRTCPeerConnection" version="4.0"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <methods> + <method name="_add_ice_candidate" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_sdp_mid_name" type="String" /> + <argument index="1" name="p_sdp_mline_index" type="int" /> + <argument index="2" name="p_sdp_name" type="String" /> + <description> + </description> + </method> + <method name="_close" qualifiers="virtual"> + <return type="void" /> + <description> + </description> + </method> + <method name="_create_data_channel" qualifiers="virtual"> + <return type="Object" /> + <argument index="0" name="p_label" type="String" /> + <argument index="1" name="p_config" type="Dictionary" /> + <description> + </description> + </method> + <method name="_create_offer" qualifiers="virtual"> + <return type="int" /> + <description> + </description> + </method> + <method name="_get_connection_state" qualifiers="virtual const"> + <return type="int" /> + <description> + </description> + </method> + <method name="_initialize" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_config" type="Dictionary" /> + <description> + </description> + </method> + <method name="_poll" qualifiers="virtual"> + <return type="int" /> + <description> + </description> + </method> + <method name="_set_local_description" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_type" type="String" /> + <argument index="1" name="p_sdp" type="String" /> + <description> + </description> + </method> + <method name="_set_remote_description" qualifiers="virtual"> + <return type="int" /> + <argument index="0" name="p_type" type="String" /> + <argument index="1" name="p_sdp" type="String" /> + <description> + </description> + </method> + <method name="make_default"> + <return type="void" /> + <description> + </description> + </method> + </methods> +</class> diff --git a/modules/webrtc/register_types.cpp b/modules/webrtc/register_types.cpp index 63ecc03a4c..8110e4a048 100644 --- a/modules/webrtc/register_types.cpp +++ b/modules/webrtc/register_types.cpp @@ -31,17 +31,11 @@ #include "register_types.h" #include "core/config/project_settings.h" #include "webrtc_data_channel.h" +#include "webrtc_multiplayer_peer.h" #include "webrtc_peer_connection.h" -#ifdef JAVASCRIPT_ENABLED -#include "emscripten.h" -#include "webrtc_peer_connection_js.h" -#endif -#ifdef WEBRTC_GDNATIVE_ENABLED -#include "webrtc_data_channel_gdnative.h" -#include "webrtc_peer_connection_gdnative.h" -#endif -#include "webrtc_multiplayer_peer.h" +#include "webrtc_data_channel_extension.h" +#include "webrtc_peer_connection_extension.h" void register_webrtc_types() { #define _SET_HINT(NAME, _VAL_, _MAX_) \ @@ -50,18 +44,12 @@ void register_webrtc_types() { _SET_HINT(WRTC_IN_BUF, 64, 4096); -#ifdef JAVASCRIPT_ENABLED - WebRTCPeerConnectionJS::make_default(); -#elif defined(WEBRTC_GDNATIVE_ENABLED) - WebRTCPeerConnectionGDNative::make_default(); -#endif - ClassDB::register_custom_instance_class<WebRTCPeerConnection>(); -#ifdef WEBRTC_GDNATIVE_ENABLED - GDREGISTER_CLASS(WebRTCPeerConnectionGDNative); - GDREGISTER_CLASS(WebRTCDataChannelGDNative); -#endif + GDREGISTER_CLASS(WebRTCPeerConnectionExtension); + GDREGISTER_VIRTUAL_CLASS(WebRTCDataChannel); + GDREGISTER_CLASS(WebRTCDataChannelExtension); + GDREGISTER_CLASS(WebRTCMultiplayerPeer); } diff --git a/modules/webrtc/webrtc_data_channel_extension.cpp b/modules/webrtc/webrtc_data_channel_extension.cpp new file mode 100644 index 0000000000..ae346f6d8e --- /dev/null +++ b/modules/webrtc/webrtc_data_channel_extension.cpp @@ -0,0 +1,215 @@ +/*************************************************************************/ +/* webrtc_data_channel_extension.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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. */ +/*************************************************************************/ + +#include "webrtc_data_channel_extension.h" + +void WebRTCDataChannelExtension::_bind_methods() { + ADD_PROPERTY_DEFAULT("write_mode", WRITE_MODE_BINARY); + + GDVIRTUAL_BIND(_get_packet, "r_buffer", "r_buffer_size"); + GDVIRTUAL_BIND(_put_packet, "p_buffer", "p_buffer_size"); + GDVIRTUAL_BIND(_get_available_packet_count); + GDVIRTUAL_BIND(_get_max_packet_size); + + GDVIRTUAL_BIND(_poll); + GDVIRTUAL_BIND(_close); + + GDVIRTUAL_BIND(_set_write_mode, "p_write_mode"); + GDVIRTUAL_BIND(_get_write_mode); + + GDVIRTUAL_BIND(_was_string_packet); + GDVIRTUAL_BIND(_get_ready_state); + GDVIRTUAL_BIND(_get_label); + GDVIRTUAL_BIND(_is_ordered); + GDVIRTUAL_BIND(_get_id); + GDVIRTUAL_BIND(_get_max_packet_life_time); + GDVIRTUAL_BIND(_get_max_retransmits); + GDVIRTUAL_BIND(_get_protocol); + GDVIRTUAL_BIND(_is_negotiated); + GDVIRTUAL_BIND(_get_buffered_amount); +} + +int WebRTCDataChannelExtension::get_available_packet_count() const { + int count; + if (GDVIRTUAL_CALL(_get_available_packet_count, count)) { + return count; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_available_packet_count is unimplemented!"); + return -1; +} + +Error WebRTCDataChannelExtension::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { + int err; + if (GDVIRTUAL_CALL(_get_packet, r_buffer, &r_buffer_size, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_packet_native is unimplemented!"); + return FAILED; +} + +Error WebRTCDataChannelExtension::put_packet(const uint8_t *p_buffer, int p_buffer_size) { + int err; + if (GDVIRTUAL_CALL(_put_packet, p_buffer, p_buffer_size, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_put_packet_native is unimplemented!"); + return FAILED; +} + +int WebRTCDataChannelExtension::get_max_packet_size() const { + int size; + if (GDVIRTUAL_CALL(_get_max_packet_size, size)) { + return size; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_size is unimplemented!"); + return 0; +} + +Error WebRTCDataChannelExtension::poll() { + int err; + if (GDVIRTUAL_CALL(_poll, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_poll is unimplemented!"); + return ERR_UNCONFIGURED; +} + +void WebRTCDataChannelExtension::close() { + if (GDVIRTUAL_CALL(_close)) { + return; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_close is unimplemented!"); +} + +void WebRTCDataChannelExtension::set_write_mode(WriteMode p_mode) { + if (GDVIRTUAL_CALL(_set_write_mode, p_mode)) { + return; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_set_write_mode is unimplemented!"); +} + +WebRTCDataChannel::WriteMode WebRTCDataChannelExtension::get_write_mode() const { + int mode; + if (GDVIRTUAL_CALL(_get_write_mode, mode)) { + return (WriteMode)mode; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_write_mode is unimplemented!"); + return WRITE_MODE_BINARY; +} + +bool WebRTCDataChannelExtension::was_string_packet() const { + bool was_string; + if (GDVIRTUAL_CALL(_was_string_packet, was_string)) { + return was_string; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_was_string_packet is unimplemented!"); + return false; +} + +WebRTCDataChannel::ChannelState WebRTCDataChannelExtension::get_ready_state() const { + int state; + if (GDVIRTUAL_CALL(_get_ready_state, state)) { + return (ChannelState)state; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_ready_state is unimplemented!"); + return STATE_CLOSED; +} + +String WebRTCDataChannelExtension::get_label() const { + String label; + if (GDVIRTUAL_CALL(_get_label, label)) { + return label; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_label is unimplemented!"); + return label; +} + +bool WebRTCDataChannelExtension::is_ordered() const { + bool ordered; + if (GDVIRTUAL_CALL(_is_ordered, ordered)) { + return ordered; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_ordered is unimplemented!"); + return false; +} + +int WebRTCDataChannelExtension::get_id() const { + int id; + if (GDVIRTUAL_CALL(_get_id, id)) { + return id; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_id is unimplemented!"); + return -1; +} + +int WebRTCDataChannelExtension::get_max_packet_life_time() const { + int lifetime; + if (GDVIRTUAL_CALL(_get_max_packet_life_time, lifetime)) { + return lifetime; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_packet_life_time is unimplemented!"); + return -1; +} + +int WebRTCDataChannelExtension::get_max_retransmits() const { + int retransmits; + if (GDVIRTUAL_CALL(_get_max_retransmits, retransmits)) { + return retransmits; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_max_retransmits is unimplemented!"); + return -1; +} + +String WebRTCDataChannelExtension::get_protocol() const { + String protocol; + if (GDVIRTUAL_CALL(_get_protocol, protocol)) { + return protocol; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_protocol is unimplemented!"); + return protocol; +} + +bool WebRTCDataChannelExtension::is_negotiated() const { + bool negotiated; + if (GDVIRTUAL_CALL(_is_negotiated, negotiated)) { + return negotiated; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_is_negotiated is unimplemented!"); + return false; +} + +int WebRTCDataChannelExtension::get_buffered_amount() const { + int amount; + if (GDVIRTUAL_CALL(_get_buffered_amount, amount)) { + return amount; + } + WARN_PRINT_ONCE("WebRTCDataChannelExtension::_get_buffered_amount is unimplemented!"); + return -1; +} diff --git a/modules/webrtc/webrtc_data_channel_gdnative.h b/modules/webrtc/webrtc_data_channel_extension.h index 5c80edd48c..eec96b4c62 100644 --- a/modules/webrtc/webrtc_data_channel_gdnative.h +++ b/modules/webrtc/webrtc_data_channel_extension.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* webrtc_data_channel_gdnative.h */ +/* webrtc_data_channel_extension.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,26 +28,22 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef WEBRTC_DATA_CHANNEL_GDNATIVE_H -#define WEBRTC_DATA_CHANNEL_GDNATIVE_H +#ifndef WEBRTC_DATA_CHANNEL_EXTENSION_H +#define WEBRTC_DATA_CHANNEL_EXTENSION_H -#ifdef WEBRTC_GDNATIVE_ENABLED - -#include "modules/gdnative/include/net/godot_net.h" #include "webrtc_data_channel.h" -class WebRTCDataChannelGDNative : public WebRTCDataChannel { - GDCLASS(WebRTCDataChannelGDNative, WebRTCDataChannel); +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" +#include "core/variant/native_ptr.h" + +class WebRTCDataChannelExtension : public WebRTCDataChannel { + GDCLASS(WebRTCDataChannelExtension, WebRTCDataChannel); protected: static void _bind_methods(); -private: - const godot_net_webrtc_data_channel *interface; - public: - void set_native_webrtc_data_channel(const godot_net_webrtc_data_channel *p_impl); - virtual void set_write_mode(WriteMode mode) override; virtual WriteMode get_write_mode() const override; virtual bool was_string_packet() const override; @@ -72,10 +68,31 @@ public: virtual int get_max_packet_size() const override; - WebRTCDataChannelGDNative(); - ~WebRTCDataChannelGDNative(); -}; + /** GDExtension **/ + GDVIRTUAL0RC(int, _get_available_packet_count); + GDVIRTUAL2R(int, _get_packet, GDNativeConstPtr<const uint8_t *>, GDNativePtr<int>); + GDVIRTUAL2R(int, _put_packet, GDNativeConstPtr<const uint8_t>, int); + GDVIRTUAL0RC(int, _get_max_packet_size); -#endif // WEBRTC_GDNATIVE_ENABLED + GDVIRTUAL0R(int, _poll); + GDVIRTUAL0(_close); + + GDVIRTUAL1(_set_write_mode, int); + GDVIRTUAL0RC(int, _get_write_mode); + + GDVIRTUAL0RC(bool, _was_string_packet); + + GDVIRTUAL0RC(int, _get_ready_state); + GDVIRTUAL0RC(String, _get_label); + GDVIRTUAL0RC(bool, _is_ordered); + GDVIRTUAL0RC(int, _get_id); + GDVIRTUAL0RC(int, _get_max_packet_life_time); + GDVIRTUAL0RC(int, _get_max_retransmits); + GDVIRTUAL0RC(String, _get_protocol); + GDVIRTUAL0RC(bool, _is_negotiated); + GDVIRTUAL0RC(int, _get_buffered_amount); + + WebRTCDataChannelExtension() {} +}; -#endif // WEBRTC_DATA_CHANNEL_GDNATIVE_H +#endif // WEBRTC_DATA_CHANNEL_EXTENSION_H diff --git a/modules/webrtc/webrtc_data_channel_gdnative.cpp b/modules/webrtc/webrtc_data_channel_gdnative.cpp deleted file mode 100644 index 10a3367557..0000000000 --- a/modules/webrtc/webrtc_data_channel_gdnative.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/*************************************************************************/ -/* webrtc_data_channel_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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. */ -/*************************************************************************/ - -#ifdef WEBRTC_GDNATIVE_ENABLED - -#include "webrtc_data_channel_gdnative.h" - -#include "core/io/resource_loader.h" -#include "modules/gdnative/nativescript/nativescript.h" - -void WebRTCDataChannelGDNative::_bind_methods() { - ADD_PROPERTY_DEFAULT("write_mode", WRITE_MODE_BINARY); -} - -WebRTCDataChannelGDNative::WebRTCDataChannelGDNative() { - interface = nullptr; -} - -WebRTCDataChannelGDNative::~WebRTCDataChannelGDNative() { -} - -Error WebRTCDataChannelGDNative::poll() { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->poll(interface->data); -} - -void WebRTCDataChannelGDNative::close() { - ERR_FAIL_COND(interface == nullptr); - interface->close(interface->data); -} - -void WebRTCDataChannelGDNative::set_write_mode(WriteMode p_mode) { - ERR_FAIL_COND(interface == nullptr); - interface->set_write_mode(interface->data, p_mode); -} - -WebRTCDataChannel::WriteMode WebRTCDataChannelGDNative::get_write_mode() const { - ERR_FAIL_COND_V(interface == nullptr, WRITE_MODE_BINARY); - return (WriteMode)interface->get_write_mode(interface->data); -} - -bool WebRTCDataChannelGDNative::was_string_packet() const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->was_string_packet(interface->data); -} - -WebRTCDataChannel::ChannelState WebRTCDataChannelGDNative::get_ready_state() const { - ERR_FAIL_COND_V(interface == nullptr, STATE_CLOSED); - return (ChannelState)interface->get_ready_state(interface->data); -} - -String WebRTCDataChannelGDNative::get_label() const { - ERR_FAIL_COND_V(interface == nullptr, ""); - return String(interface->get_label(interface->data)); -} - -bool WebRTCDataChannelGDNative::is_ordered() const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->is_ordered(interface->data); -} - -int WebRTCDataChannelGDNative::get_id() const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->get_id(interface->data); -} - -int WebRTCDataChannelGDNative::get_max_packet_life_time() const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->get_max_packet_life_time(interface->data); -} - -int WebRTCDataChannelGDNative::get_max_retransmits() const { - ERR_FAIL_COND_V(interface == nullptr, -1); - return interface->get_max_retransmits(interface->data); -} - -String WebRTCDataChannelGDNative::get_protocol() const { - ERR_FAIL_COND_V(interface == nullptr, ""); - return String(interface->get_protocol(interface->data)); -} - -bool WebRTCDataChannelGDNative::is_negotiated() const { - ERR_FAIL_COND_V(interface == nullptr, false); - return interface->is_negotiated(interface->data); -} - -int WebRTCDataChannelGDNative::get_buffered_amount() const { - ERR_FAIL_COND_V(interface == NULL, 0); - return interface->get_buffered_amount(interface->data); -} - -Error WebRTCDataChannelGDNative::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->get_packet(interface->data, r_buffer, &r_buffer_size); -} - -Error WebRTCDataChannelGDNative::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->put_packet(interface->data, p_buffer, p_buffer_size); -} - -int WebRTCDataChannelGDNative::get_max_packet_size() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_max_packet_size(interface->data); -} - -int WebRTCDataChannelGDNative::get_available_packet_count() const { - ERR_FAIL_COND_V(interface == nullptr, 0); - return interface->get_available_packet_count(interface->data); -} - -void WebRTCDataChannelGDNative::set_native_webrtc_data_channel(const godot_net_webrtc_data_channel *p_impl) { - interface = p_impl; -} - -#endif // WEBRTC_GDNATIVE_ENABLED diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index d60d694df1..48117f05f2 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -43,22 +43,6 @@ void WebRTCMultiplayerPeer::_bind_methods() { ClassDB::bind_method(D_METHOD("close"), &WebRTCMultiplayerPeer::close); } -void WebRTCMultiplayerPeer::set_transfer_channel(int p_channel) { - transfer_channel = p_channel; -} - -int WebRTCMultiplayerPeer::get_transfer_channel() const { - return transfer_channel; -} - -void WebRTCMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) { - transfer_mode = p_mode; -} - -Multiplayer::TransferMode WebRTCMultiplayerPeer::get_transfer_mode() const { - return transfer_mode; -} - void WebRTCMultiplayerPeer::set_target_peer(int p_peer_id) { target_peer = p_peer_id; } @@ -188,14 +172,6 @@ void WebRTCMultiplayerPeer::_find_next_peer() { next_packet_peer = 0; } -void WebRTCMultiplayerPeer::set_refuse_new_connections(bool p_enable) { - refuse_connections = p_enable; -} - -bool WebRTCMultiplayerPeer::is_refusing_new_connections() const { - return refuse_connections; -} - MultiplayerPeer::ConnectionStatus WebRTCMultiplayerPeer::get_connection_status() const { return connection_status; } @@ -279,7 +255,7 @@ Dictionary WebRTCMultiplayerPeer::get_peers() { Error WebRTCMultiplayerPeer::add_peer(Ref<WebRTCPeerConnection> p_peer, int p_peer_id, int p_unreliable_lifetime) { ERR_FAIL_COND_V(p_peer_id < 0 || p_peer_id > ~(1 << 31), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_unreliable_lifetime < 0, ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(refuse_connections, ERR_UNAUTHORIZED); + ERR_FAIL_COND_V(is_refusing_new_connections(), ERR_UNAUTHORIZED); // Peer must be valid, and in new state (to create data channels) ERR_FAIL_COND_V(!p_peer.is_valid(), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_peer->get_connection_state() != WebRTCPeerConnection::STATE_NEW, ERR_INVALID_PARAMETER); @@ -352,9 +328,9 @@ Error WebRTCMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_ Error WebRTCMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V(connection_status == CONNECTION_DISCONNECTED, ERR_UNCONFIGURED); - int ch = transfer_channel; + int ch = get_transfer_channel(); if (ch == 0) { - switch (transfer_mode) { + switch (get_transfer_mode()) { case Multiplayer::TRANSFER_MODE_RELIABLE: ch = CH_RELIABLE; break; diff --git a/modules/webrtc/webrtc_multiplayer_peer.h b/modules/webrtc/webrtc_multiplayer_peer.h index 80a6491492..4a7e9ad7c8 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.h +++ b/modules/webrtc/webrtc_multiplayer_peer.h @@ -65,10 +65,7 @@ private: uint32_t unique_id = 0; int target_peer = 0; int client_count = 0; - bool refuse_connections = false; ConnectionStatus connection_status = CONNECTION_DISCONNECTED; - int transfer_channel = 0; - Multiplayer::TransferMode transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE; int next_packet_peer = 0; bool server_compat = false; @@ -97,10 +94,6 @@ public: int get_max_packet_size() const override; // MultiplayerPeer - void set_transfer_channel(int p_channel) override; - int get_transfer_channel() const override; - void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - Multiplayer::TransferMode get_transfer_mode() const override; void set_target_peer(int p_peer_id) override; int get_unique_id() const override; @@ -110,9 +103,6 @@ public: void poll() override; - void set_refuse_new_connections(bool p_enable) override; - bool is_refusing_new_connections() const override; - ConnectionStatus get_connection_status() const override; }; diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp index 3e2938bf7d..ad28aa76c7 100644 --- a/modules/webrtc/webrtc_peer_connection.cpp +++ b/modules/webrtc/webrtc_peer_connection.cpp @@ -30,17 +30,29 @@ #include "webrtc_peer_connection.h" -WebRTCPeerConnection *(*WebRTCPeerConnection::_create)() = nullptr; +#ifdef JAVASCRIPT_ENABLED +#include "webrtc_peer_connection_js.h" +#else +#include "webrtc_peer_connection_extension.h" +#endif -Ref<WebRTCPeerConnection> WebRTCPeerConnection::create_ref() { - return create(); +StringName WebRTCPeerConnection::default_extension; + +void WebRTCPeerConnection::set_default_extension(const StringName &p_extension) { + default_extension = p_extension; } WebRTCPeerConnection *WebRTCPeerConnection::create() { - if (!_create) { - return nullptr; +#ifdef JAVASCRIPT_ENABLED + return memnew(WebRTCPeerConnectionJS); +#else + if (default_extension == String()) { + WARN_PRINT_ONCE("No default WebRTC extension configured."); + return memnew(WebRTCPeerConnectionExtension); } - return _create(); + Object *obj = ClassDB::instantiate(default_extension); + return Object::cast_to<WebRTCPeerConnectionExtension>(obj); +#endif } void WebRTCPeerConnection::_bind_methods() { diff --git a/modules/webrtc/webrtc_peer_connection.h b/modules/webrtc/webrtc_peer_connection.h index fcfb9ae9ae..e2ef3e55ad 100644 --- a/modules/webrtc/webrtc_peer_connection.h +++ b/modules/webrtc/webrtc_peer_connection.h @@ -47,11 +47,15 @@ public: STATE_CLOSED }; +private: + static StringName default_extension; + protected: static void _bind_methods(); - static WebRTCPeerConnection *(*_create)(); public: + static void set_default_extension(const StringName &p_name); + virtual ConnectionState get_connection_state() const = 0; virtual Error initialize(Dictionary p_config = Dictionary()) = 0; @@ -63,7 +67,6 @@ public: virtual Error poll() = 0; virtual void close() = 0; - static Ref<WebRTCPeerConnection> create_ref(); static WebRTCPeerConnection *create(); WebRTCPeerConnection(); diff --git a/modules/webrtc/webrtc_peer_connection_extension.cpp b/modules/webrtc/webrtc_peer_connection_extension.cpp new file mode 100644 index 0000000000..33288e66d6 --- /dev/null +++ b/modules/webrtc/webrtc_peer_connection_extension.cpp @@ -0,0 +1,131 @@ +/*************************************************************************/ +/* webrtc_peer_connection_extension.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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. */ +/*************************************************************************/ + +#include "webrtc_peer_connection_extension.h" + +void WebRTCPeerConnectionExtension::_bind_methods() { + ClassDB::bind_method(D_METHOD("make_default"), &WebRTCPeerConnectionExtension::make_default); + + GDVIRTUAL_BIND(_get_connection_state); + GDVIRTUAL_BIND(_initialize, "p_config"); + GDVIRTUAL_BIND(_create_data_channel, "p_label", "p_config"); + GDVIRTUAL_BIND(_create_offer); + GDVIRTUAL_BIND(_set_remote_description, "p_type", "p_sdp"); + GDVIRTUAL_BIND(_set_local_description, "p_type", "p_sdp"); + GDVIRTUAL_BIND(_add_ice_candidate, "p_sdp_mid_name", "p_sdp_mline_index", "p_sdp_name"); + GDVIRTUAL_BIND(_poll); + GDVIRTUAL_BIND(_close); +} + +void WebRTCPeerConnectionExtension::make_default() { + ERR_FAIL_COND_MSG(!_get_extension(), vformat("Can't make %s the default without extending it.", get_class())); + WebRTCPeerConnection::set_default_extension(get_class()); +} + +WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionExtension::get_connection_state() const { + int state; + if (GDVIRTUAL_CALL(_get_connection_state, state)) { + return (ConnectionState)state; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_get_connection_state is unimplemented!"); + return STATE_DISCONNECTED; +} + +Error WebRTCPeerConnectionExtension::initialize(Dictionary p_config) { + int err; + if (GDVIRTUAL_CALL(_initialize, p_config, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_initialize is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Ref<WebRTCDataChannel> WebRTCPeerConnectionExtension::create_data_channel(String p_label, Dictionary p_options) { + Object *ret = nullptr; + if (GDVIRTUAL_CALL(_create_data_channel, p_label, p_options, ret)) { + WebRTCDataChannel *ch = Object::cast_to<WebRTCDataChannel>(ret); + ERR_FAIL_COND_V_MSG(ret && !ch, nullptr, "Returned object must be an instance of WebRTCDataChannel."); + return ch; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_data_channel is unimplemented!"); + return nullptr; +} + +Error WebRTCPeerConnectionExtension::create_offer() { + int err; + if (GDVIRTUAL_CALL(_create_offer, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_create_offer is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Error WebRTCPeerConnectionExtension::set_local_description(String p_type, String p_sdp) { + int err; + if (GDVIRTUAL_CALL(_set_local_description, p_type, p_sdp, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_local_description is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Error WebRTCPeerConnectionExtension::set_remote_description(String p_type, String p_sdp) { + int err; + if (GDVIRTUAL_CALL(_set_remote_description, p_type, p_sdp, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_set_remote_description is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Error WebRTCPeerConnectionExtension::add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) { + int err; + if (GDVIRTUAL_CALL(_add_ice_candidate, p_sdp_mid_name, p_sdp_mline_index, p_sdp_name, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_add_ice_candidate is unimplemented!"); + return ERR_UNCONFIGURED; +} + +Error WebRTCPeerConnectionExtension::poll() { + int err; + if (GDVIRTUAL_CALL(_poll, err)) { + return (Error)err; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_poll is unimplemented!"); + return ERR_UNCONFIGURED; +} + +void WebRTCPeerConnectionExtension::close() { + if (GDVIRTUAL_CALL(_close)) { + return; + } + WARN_PRINT_ONCE("WebRTCPeerConnectionExtension::_close is unimplemented!"); +} diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.h b/modules/webrtc/webrtc_peer_connection_extension.h index 578af0202f..b3c2039fc1 100644 --- a/modules/webrtc/webrtc_peer_connection_gdnative.h +++ b/modules/webrtc/webrtc_peer_connection_extension.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* webrtc_peer_connection_gdnative.h */ +/* webrtc_peer_connection_extension.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,30 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef WEBRTC_PEER_CONNECTION_GDNATIVE_H -#define WEBRTC_PEER_CONNECTION_GDNATIVE_H +#ifndef WEBRTC_PEER_CONNECTION_EXTENSION_H +#define WEBRTC_PEER_CONNECTION_EXTENSION_H -#ifdef WEBRTC_GDNATIVE_ENABLED - -#include "modules/gdnative/include/net/godot_net.h" #include "webrtc_peer_connection.h" -class WebRTCPeerConnectionGDNative : public WebRTCPeerConnection { - GDCLASS(WebRTCPeerConnectionGDNative, WebRTCPeerConnection); +#include "core/object/gdvirtual.gen.inc" +#include "core/object/script_language.h" +#include "core/variant/native_ptr.h" + +class WebRTCPeerConnectionExtension : public WebRTCPeerConnection { + GDCLASS(WebRTCPeerConnectionExtension, WebRTCPeerConnection); protected: static void _bind_methods(); - static WebRTCPeerConnection *_create(); - -private: - static const godot_net_webrtc_library *default_library; - const godot_net_webrtc_peer_connection *interface; public: - static Error set_default_library(const godot_net_webrtc_library *p_library); - static void make_default() { WebRTCPeerConnection::_create = WebRTCPeerConnectionGDNative::_create; } - - void set_native_webrtc_peer_connection(const godot_net_webrtc_peer_connection *p_impl); + void make_default(); virtual ConnectionState get_connection_state() const override; @@ -60,14 +53,22 @@ public: virtual Error create_offer() override; virtual Error set_remote_description(String type, String sdp) override; virtual Error set_local_description(String type, String sdp) override; - virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) override; + virtual Error add_ice_candidate(String p_sdp_mid_name, int p_sdp_mline_index, String p_sdp_name) override; virtual Error poll() override; virtual void close() override; - WebRTCPeerConnectionGDNative(); - ~WebRTCPeerConnectionGDNative(); -}; + /** GDExtension **/ + GDVIRTUAL0RC(int, _get_connection_state); + GDVIRTUAL1R(int, _initialize, Dictionary); + GDVIRTUAL2R(Object *, _create_data_channel, String, Dictionary); + GDVIRTUAL0R(int, _create_offer); + GDVIRTUAL2R(int, _set_remote_description, String, String); + GDVIRTUAL2R(int, _set_local_description, String, String); + GDVIRTUAL3R(int, _add_ice_candidate, String, int, String); + GDVIRTUAL0R(int, _poll); + GDVIRTUAL0(_close); -#endif // WEBRTC_GDNATIVE_ENABLED + WebRTCPeerConnectionExtension() {} +}; -#endif // WEBRTC_PEER_CONNECTION_GDNATIVE_H +#endif // WEBRTC_PEER_CONNECTION_EXTENSION_H diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.cpp b/modules/webrtc/webrtc_peer_connection_gdnative.cpp deleted file mode 100644 index dcf78dfb73..0000000000 --- a/modules/webrtc/webrtc_peer_connection_gdnative.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/*************************************************************************/ -/* webrtc_peer_connection_gdnative.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 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. */ -/*************************************************************************/ - -#ifdef WEBRTC_GDNATIVE_ENABLED - -#include "webrtc_peer_connection_gdnative.h" - -#include "core/io/resource_loader.h" -#include "modules/gdnative/nativescript/nativescript.h" -#include "webrtc_data_channel_gdnative.h" - -const godot_net_webrtc_library *WebRTCPeerConnectionGDNative::default_library = nullptr; - -Error WebRTCPeerConnectionGDNative::set_default_library(const godot_net_webrtc_library *p_lib) { - if (default_library) { - const godot_net_webrtc_library *old = default_library; - default_library = nullptr; - old->unregistered(); - } - default_library = p_lib; - return OK; // Maybe add version check and fail accordingly -} - -WebRTCPeerConnection *WebRTCPeerConnectionGDNative::_create() { - WebRTCPeerConnectionGDNative *obj = memnew(WebRTCPeerConnectionGDNative); - ERR_FAIL_COND_V_MSG(!default_library, obj, "Default GDNative WebRTC implementation not defined."); - - // Call GDNative constructor - Error err = (Error)default_library->create_peer_connection(obj); - ERR_FAIL_COND_V_MSG(err != OK, obj, "GDNative default library constructor returned an error."); - - return obj; -} - -void WebRTCPeerConnectionGDNative::_bind_methods() { -} - -WebRTCPeerConnectionGDNative::WebRTCPeerConnectionGDNative() { - interface = nullptr; -} - -WebRTCPeerConnectionGDNative::~WebRTCPeerConnectionGDNative() { -} - -Error WebRTCPeerConnectionGDNative::initialize(Dictionary p_config) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->initialize(interface->data, (const godot_dictionary *)&p_config); -} - -Ref<WebRTCDataChannel> WebRTCPeerConnectionGDNative::create_data_channel(String p_label, Dictionary p_options) { - ERR_FAIL_COND_V(interface == nullptr, nullptr); - return (WebRTCDataChannel *)interface->create_data_channel(interface->data, p_label.utf8().get_data(), (const godot_dictionary *)&p_options); -} - -Error WebRTCPeerConnectionGDNative::create_offer() { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->create_offer(interface->data); -} - -Error WebRTCPeerConnectionGDNative::set_local_description(String p_type, String p_sdp) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->set_local_description(interface->data, p_type.utf8().get_data(), p_sdp.utf8().get_data()); -} - -Error WebRTCPeerConnectionGDNative::set_remote_description(String p_type, String p_sdp) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->set_remote_description(interface->data, p_type.utf8().get_data(), p_sdp.utf8().get_data()); -} - -Error WebRTCPeerConnectionGDNative::add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->add_ice_candidate(interface->data, sdpMidName.utf8().get_data(), sdpMlineIndexName, sdpName.utf8().get_data()); -} - -Error WebRTCPeerConnectionGDNative::poll() { - ERR_FAIL_COND_V(interface == nullptr, ERR_UNCONFIGURED); - return (Error)interface->poll(interface->data); -} - -void WebRTCPeerConnectionGDNative::close() { - ERR_FAIL_COND(interface == nullptr); - interface->close(interface->data); -} - -WebRTCPeerConnection::ConnectionState WebRTCPeerConnectionGDNative::get_connection_state() const { - ERR_FAIL_COND_V(interface == nullptr, STATE_DISCONNECTED); - return (ConnectionState)interface->get_connection_state(interface->data); -} - -void WebRTCPeerConnectionGDNative::set_native_webrtc_peer_connection(const godot_net_webrtc_peer_connection *p_impl) { - interface = p_impl; -} - -#endif // WEBRTC_GDNATIVE_ENABLED diff --git a/modules/webrtc/webrtc_peer_connection_js.h b/modules/webrtc/webrtc_peer_connection_js.h index 0272e67f6f..d2beccaf03 100644 --- a/modules/webrtc/webrtc_peer_connection_js.h +++ b/modules/webrtc/webrtc_peer_connection_js.h @@ -63,9 +63,6 @@ private: static void _on_error(void *p_obj); public: - static WebRTCPeerConnection *_create() { return memnew(WebRTCPeerConnectionJS); } - static void make_default() { WebRTCPeerConnection::_create = WebRTCPeerConnectionJS::_create; } - virtual ConnectionState get_connection_state() const; virtual Error initialize(Dictionary configuration = Dictionary()); diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml index b5202469f1..4b515c12a1 100644 --- a/modules/websocket/doc_classes/WebSocketClient.xml +++ b/modules/websocket/doc_classes/WebSocketClient.xml @@ -8,6 +8,7 @@ This client can be optionally used as a multiplayer peer for the [MultiplayerAPI]. After starting the client ([method connect_to_url]), you will need to [method MultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). You will receive appropriate signals when connecting, disconnecting, or when new data is available. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> </tutorials> @@ -90,6 +91,4 @@ </description> </signal> </signals> - <constants> - </constants> </class> diff --git a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml index c7a0ca100f..8d8ab220e2 100644 --- a/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml +++ b/modules/websocket/doc_classes/WebSocketMultiplayerPeer.xml @@ -5,6 +5,7 @@ </brief_description> <description> Base class for WebSocket server and client, allowing them to be used as multiplayer peer for the [MultiplayerAPI]. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> </tutorials> @@ -30,10 +31,6 @@ </description> </method> </methods> - <members> - <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="TransferMode" default="2" /> - </members> <signals> <signal name="peer_packet"> <argument index="0" name="peer_source" type="int" /> @@ -43,6 +40,4 @@ </description> </signal> </signals> - <constants> - </constants> </class> diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml index b66a1054ab..f901b089ea 100644 --- a/modules/websocket/doc_classes/WebSocketServer.xml +++ b/modules/websocket/doc_classes/WebSocketServer.xml @@ -7,6 +7,7 @@ This class implements a WebSocket server that can also support the high-level multiplayer API. After starting the server ([method listen]), you will need to [method MultiplayerPeer.poll] it at regular intervals (e.g. inside [method Node._process]). When clients connect, disconnect, or send data, you will receive the appropriate signal. [b]Note:[/b] Not available in HTML5 exports. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> </tutorials> @@ -116,6 +117,4 @@ </description> </signal> </signals> - <constants> - </constants> </class> diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index 7464cf2bf5..3a27855a5e 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -105,23 +105,6 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer // // MultiplayerPeer // -void WebSocketMultiplayerPeer::set_transfer_channel(int p_channel) { - // Websocket does not have channels. -} - -int WebSocketMultiplayerPeer::get_transfer_channel() const { - return 0; -} - -void WebSocketMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) { - // Websocket uses TCP, reliable -} - -Multiplayer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const { - // Websocket uses TCP, reliable - return Multiplayer::TRANSFER_MODE_RELIABLE; -} - void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) { _target_peer = p_target_peer; } @@ -137,14 +120,6 @@ int WebSocketMultiplayerPeer::get_unique_id() const { return _peer_id; } -void WebSocketMultiplayerPeer::set_refuse_new_connections(bool p_enable) { - _refusing = p_enable; -} - -bool WebSocketMultiplayerPeer::is_refusing_new_connections() const { - return _refusing; -} - void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_type, int32_t p_peer_id) { ERR_FAIL_COND(!p_peer.is_valid()); ERR_FAIL_COND(!p_peer->is_connected_to_host()); diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h index d97a599fe9..380edf67ed 100644 --- a/modules/websocket/websocket_multiplayer_peer.h +++ b/modules/websocket/websocket_multiplayer_peer.h @@ -68,7 +68,6 @@ protected: bool _is_multiplayer = false; int _target_peer = 0; int _peer_id = 0; - int _refusing = false; static void _bind_methods(); @@ -78,15 +77,9 @@ protected: public: /* MultiplayerPeer */ - void set_transfer_channel(int p_channel) override; - int get_transfer_channel() const override; - void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - Multiplayer::TransferMode get_transfer_mode() const override; void set_target_peer(int p_target_peer) override; int get_packet_peer() const override; int get_unique_id() const override; - void set_refuse_new_connections(bool p_enable) override; - bool is_refusing_new_connections() const override; /* PacketPeer */ virtual int get_available_packet_count() const override; diff --git a/modules/webxr/doc_classes/WebXRInterface.xml b/modules/webxr/doc_classes/WebXRInterface.xml index ff7c46bbae..16d671c9e9 100644 --- a/modules/webxr/doc_classes/WebXRInterface.xml +++ b/modules/webxr/doc_classes/WebXRInterface.xml @@ -239,6 +239,4 @@ </description> </signal> </signals> - <constants> - </constants> </class> diff --git a/modules/webxr/register_types.cpp b/modules/webxr/register_types.cpp index 078a6547cf..16b483c39e 100644 --- a/modules/webxr/register_types.cpp +++ b/modules/webxr/register_types.cpp @@ -33,15 +33,34 @@ #include "webxr_interface.h" #include "webxr_interface_js.h" +#ifdef JAVASCRIPT_ENABLED +Ref<WebXRInterfaceJS> webxr; +#endif + void register_webxr_types() { GDREGISTER_VIRTUAL_CLASS(WebXRInterface); #ifdef JAVASCRIPT_ENABLED - Ref<WebXRInterfaceJS> webxr; webxr.instantiate(); XRServer::get_singleton()->add_interface(webxr); #endif } void unregister_webxr_types() { +#ifdef JAVASCRIPT_ENABLED + if (webxr.is_valid()) { + // uninitialise our interface if it is initialised + if (webxr->is_initialized()) { + webxr->uninitialize(); + } + + // unregister our interface from the XR server + if (XRServer::get_singleton()) { + XRServer::get_singleton()->remove_interface(webxr); + } + + // and release + webxr.unref(); + } +#endif } diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 2d699961ae..10c17aa672 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -341,7 +341,7 @@ Transform3D WebXRInterfaceJS::get_transform_for_view(uint32_t p_view, const Tran return p_cam_transform * xr_server->get_reference_frame() * transform_for_eye; }; -CameraMatrix WebXRInterfaceJS::get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) { +CameraMatrix WebXRInterfaceJS::get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) { CameraMatrix eye; float *js_matrix = godot_webxr_get_projection_for_eye(p_view + 1); diff --git a/modules/webxr/webxr_interface_js.h b/modules/webxr/webxr_interface_js.h index 82307190db..eb77f35f39 100644 --- a/modules/webxr/webxr_interface_js.h +++ b/modules/webxr/webxr_interface_js.h @@ -86,7 +86,7 @@ public: virtual uint32_t get_view_count() override; virtual Transform3D get_camera_transform() override; virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override; - virtual CameraMatrix get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) override; + virtual CameraMatrix get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) override; virtual Vector<BlitToScreen> commit_views(RID p_render_target, const Rect2 &p_screen_rect) override; virtual void process() override; |