-
-
Notifications
You must be signed in to change notification settings - Fork 23.8k
PhysicsDirectSpaceState2D/3D: reusable strongly typed results
#113970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
PhysicsDirectSpaceState2D/3D: reusable strongly typed results
#113970
Conversation
a8367c9 to
bdbead3
Compare
5d1900b to
e3d2154
Compare
e3d2154 to
747916a
Compare
747916a to
bd00fab
Compare
|
Thank you for your contribution! This is a pretty majorly breaking change, is there a proposal to track this or to evaluate support? This would benefit from having a proper proposal created here to discuss the details and evaluate support for this, as it would be something that would need good support to justify the changes and the need for them I'd say backwards compatibility needs to be maintained by creating new methods instead of replacing the existing ones, as this would be very disruptive to anyone using the existing interfaces |
This PR refactors the query methods in
PhysicsDirectSpaceState2D/3Dto use strongly typed result objects instead of allocating result containers on every call. This aligns the API withbody_test_motion()inPhysicsServer2D/3Dand improves performance, though it is backward-incompatible.API changes
Dictionary intersect_ray(parameters: PhysicsRayQueryParameters2D)bool intersect_ray(parameters: PhysicsRayQueryParameters2D, result: PhysicsRayIntersectionResult2D)Array[Dictionary] intersect_point(parameters: PhysicsPointQueryParameters2D, max_results: int)bool intersect_point(parameters: PhysicsPointQueryParameters2D, result: PhysicsPointIntersectionResult2D)Array[Dictionary] intersect_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int)bool intersect_shape(parameters: PhysicsShapeQueryParameters2D, result: PhysicsShapeIntersectionResult2D)PackedFloat32Array cast_motion(parameters: PhysicsShapeQueryParameters2D)bool cast_motion(parameters: PhysicsShapeQueryParameters2D, result: PhysicsShapeCastResult2D)Array[Vector3] collide_shape(parameters: PhysicsShapeQueryParameters2D, max_results: int)bool collide_shape(parameters: PhysicsShapeQueryParameters2D, result: PhysicsShapeCollisionResult2D)Dictionary get_rest_info(parameters: PhysicsShapeQueryParameters2D)bool get_rest_info(parameters: PhysicsShapeQueryParameters2D, result: PhysicsShapeRestInfoResult2D)Equivalent changes are applied to the 3D.
New classes
PhysicsRayIntersectionResult2D/3DPhysicsPointIntersectionResult2D/3DPhysicsShapeIntersectionResult2D/3DPhysicsShapeCastResult2D/3DPhysicsShapeCollisionResult2D/3DPhysicsShapeRestInfoResult2D/3DMotivation
The new typed result objects eliminate the need to manually declare types when accessing fields:
Old usage required explicit type annotations:
Result objects can be created once and reused:
Avoids per-call result allocation and improves performance.
This matches the
PhysicsTestMotionResult2D/3DandPhysicsTestMotionParameters2D/3Dpattern already used bybody_test_motion().Crude microbenchmark comparisons (3D)
intersect_ray()intersect_point()intersect_shape()cast_motion()collide_shape()get_rest_info()Notes