diff options
Diffstat (limited to 'servers/physics_server_3d.cpp')
-rw-r--r-- | servers/physics_server_3d.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index f25db22e66..6dd5be9ea8 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -32,6 +32,7 @@ #include "core/config/project_settings.h" #include "core/string/print_string.h" +#include "core/variant/typed_array.h" void PhysicsServer3DRenderingServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) { GDVIRTUAL_REQUIRED_CALL(_set_vertex, p_vertex_id, p_vector3); @@ -366,8 +367,8 @@ Dictionary PhysicsDirectSpaceState3D::_intersect_ray(const Ref<PhysicsRayQueryPa return d; } -Array PhysicsDirectSpaceState3D::_intersect_point(const Ref<PhysicsPointQueryParameters3D> &p_point_query, int p_max_results) { - ERR_FAIL_COND_V(p_point_query.is_null(), Array()); +TypedArray<Dictionary> PhysicsDirectSpaceState3D::_intersect_point(const Ref<PhysicsPointQueryParameters3D> &p_point_query, int p_max_results) { + ERR_FAIL_COND_V(p_point_query.is_null(), TypedArray<Dictionary>()); Vector<ShapeResult> ret; ret.resize(p_max_results); @@ -375,10 +376,10 @@ Array PhysicsDirectSpaceState3D::_intersect_point(const Ref<PhysicsPointQueryPar int rc = intersect_point(p_point_query->get_parameters(), ret.ptrw(), ret.size()); if (rc == 0) { - return Array(); + return TypedArray<Dictionary>(); } - Array r; + TypedArray<Dictionary> r; r.resize(rc); for (int i = 0; i < rc; i++) { Dictionary d; @@ -391,13 +392,13 @@ Array PhysicsDirectSpaceState3D::_intersect_point(const Ref<PhysicsPointQueryPar return r; } -Array PhysicsDirectSpaceState3D::_intersect_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) { - ERR_FAIL_COND_V(!p_shape_query.is_valid(), Array()); +TypedArray<Dictionary> PhysicsDirectSpaceState3D::_intersect_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) { + ERR_FAIL_COND_V(!p_shape_query.is_valid(), TypedArray<Dictionary>()); Vector<ShapeResult> sr; sr.resize(p_max_results); int rc = intersect_shape(p_shape_query->get_parameters(), sr.ptrw(), sr.size()); - Array ret; + TypedArray<Dictionary> ret; ret.resize(rc); for (int i = 0; i < rc; i++) { Dictionary d; @@ -411,22 +412,22 @@ Array PhysicsDirectSpaceState3D::_intersect_shape(const Ref<PhysicsShapeQueryPar return ret; } -Array PhysicsDirectSpaceState3D::_cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query) { - ERR_FAIL_COND_V(!p_shape_query.is_valid(), Array()); +Vector<real_t> PhysicsDirectSpaceState3D::_cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query) { + ERR_FAIL_COND_V(!p_shape_query.is_valid(), Vector<real_t>()); real_t closest_safe = 1.0f, closest_unsafe = 1.0f; bool res = cast_motion(p_shape_query->get_parameters(), closest_safe, closest_unsafe); if (!res) { - return Array(); + return Vector<real_t>(); } - Array ret; + Vector<real_t> ret; ret.resize(2); - ret[0] = closest_safe; - ret[1] = closest_unsafe; + ret.write[0] = closest_safe; + ret.write[1] = closest_unsafe; return ret; } -Array PhysicsDirectSpaceState3D::_collide_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) { +TypedArray<PackedVector2Array> PhysicsDirectSpaceState3D::_collide_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results) { ERR_FAIL_COND_V(!p_shape_query.is_valid(), Array()); Vector<Vector3> ret; @@ -434,9 +435,9 @@ Array PhysicsDirectSpaceState3D::_collide_shape(const Ref<PhysicsShapeQueryParam int rc = 0; bool res = collide_shape(p_shape_query->get_parameters(), ret.ptrw(), p_max_results, rc); if (!res) { - return Array(); + return TypedArray<PackedVector2Array>(); } - Array r; + TypedArray<PackedVector2Array> r; r.resize(rc * 2); for (int i = 0; i < rc * 2; i++) { r[i] = ret[i]; @@ -750,6 +751,9 @@ void PhysicsServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("body_set_collision_mask", "body", "mask"), &PhysicsServer3D::body_set_collision_mask); ClassDB::bind_method(D_METHOD("body_get_collision_mask", "body"), &PhysicsServer3D::body_get_collision_mask); + ClassDB::bind_method(D_METHOD("body_set_collision_priority", "body", "priority"), &PhysicsServer3D::body_set_collision_priority); + ClassDB::bind_method(D_METHOD("body_get_collision_priority", "body"), &PhysicsServer3D::body_get_collision_priority); + ClassDB::bind_method(D_METHOD("body_add_shape", "body", "shape", "transform", "disabled"), &PhysicsServer3D::body_add_shape, DEFVAL(Transform3D()), DEFVAL(false)); ClassDB::bind_method(D_METHOD("body_set_shape", "body", "shape_idx", "shape"), &PhysicsServer3D::body_set_shape); ClassDB::bind_method(D_METHOD("body_set_shape_transform", "body", "shape_idx", "transform"), &PhysicsServer3D::body_set_shape_transform); |