Add BodyInterface methods, fixup usage of deprecated std.Build APIs #19
Add BodyInterface methods, fixup usage of deprecated std.Build APIs #19hazeycode merged 4 commits intozig-gamedev:mainfrom
Conversation
- Fixup AddState to allow zero (which is a valid result returned by AddBodiesPrepare when length is zero)
- Use @Splat(...) where possible instead of **
There was a problem hiding this comment.
Pull request overview
This PR adds new batch operation methods to the BodyInterface API and updates the build system for Zig 0.16.x compatibility. The changes modernize the codebase by using @splat for array initialization and updating deprecated std.Build APIs.
Key changes:
- Added
destroyBodies,removeBodies, andsetShapemethods to BodyInterface - Changed
AddStateto*allowzero opaque {}to support zero-length array operations - Updated build.zig to use
root_moduleAPI instead of deprecated direct methods - Modernized Zig code with
@splatinstead of** Npattern
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/zphysics.zig | Added three new BodyInterface methods, updated AddState to allow zero pointer, and replaced array initialization syntax with @Splat |
| libs/JoltC/JoltPhysicsC.h | Added C API declarations for new batch operations, removed trailing semicolons from macro definitions |
| libs/JoltC/JoltPhysicsC.cpp | Implemented C bindings for new methods, removed assert checks on AddState conversions to support zero values |
| build.zig | Updated to use root_module API for include paths, library linking, and source files; changed want_lto to lto for Zig 0.16.x compatibility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
libs/JoltC/JoltPhysicsC.h
Outdated
| JPC_BodyInterface_DestroyBody(JPC_BodyInterface *in_iface, JPC_BodyID in_body_id); | ||
|
|
||
| JPC_API void | ||
| JPC_BodyInterface_DestroyBodies(JPC_BodyInterface *in_iface, JPC_BodyID* in_body_ids, int in_num_bodies); |
There was a problem hiding this comment.
The in_body_ids parameter should be declared as const JPC_BodyID* instead of JPC_BodyID* for consistency with similar batch operations like JPC_BodyInterface_ActivateBodies and JPC_BodyInterface_DeactivateBodies, which take const pointers since these operations don't modify the input array.
| JPC_BodyInterface_DestroyBodies(JPC_BodyInterface *in_iface, JPC_BodyID* in_body_ids, int in_num_bodies); | |
| JPC_BodyInterface_DestroyBodies(JPC_BodyInterface *in_iface, const JPC_BodyID* in_body_ids, int in_num_bodies); |
| JPC_BodyInterface_RemoveBody(JPC_BodyInterface *in_iface, JPC_BodyID in_body_id); | ||
|
|
||
| JPC_API void | ||
| JPC_BodyInterface_RemoveBodies(JPC_BodyInterface *in_iface, JPC_BodyID* in_body_ids, int in_num_bodies); |
There was a problem hiding this comment.
The in_body_ids parameter should be declared as const JPC_BodyID* instead of JPC_BodyID* for consistency with similar batch operations like JPC_BodyInterface_ActivateBodies and JPC_BodyInterface_DeactivateBodies, which take const pointers since these operations don't modify the input array.
There was a problem hiding this comment.
This is incorrect, as per the RemoveBodies docs, https://jrouwe.github.io/JoltPhysics/class_body_interface.html#a4e0007d53ba413e916a527b870b35a87:
ioBodies may be shuffled around by this function.
src/zphysics.zig
Outdated
| ); | ||
| } | ||
|
|
||
| pub fn destroyBodies(body_iface: *BodyInterface, body_ids: []BodyId) void { |
There was a problem hiding this comment.
The body_ids parameter should be []const BodyId instead of []BodyId for consistency with similar batch operations like activateBodies and deactivateBodies. The underlying C API declares the parameter as const JPC_BodyID*, indicating the array should not be modified.
| ); | ||
| } | ||
|
|
||
| pub fn removeBodies(body_iface: *BodyInterface, body_ids: []BodyId) void { |
There was a problem hiding this comment.
The body_ids parameter should be []const BodyId instead of []BodyId for consistency with similar batch operations like activateBodies and deactivateBodies. The underlying C API declares the parameter as const JPC_BodyID*, indicating the array should not be modified.
There was a problem hiding this comment.
This is incorrect, as per the RemoveBodies docs, https://jrouwe.github.io/JoltPhysics/class_body_interface.html#a4e0007d53ba413e916a527b870b35a87:
ioBodies may be shuffled around by this function.
|
@hazeycode Thx ;) |
The build API changes are required for zig 0.16.x compatibility, but they also compile against 0.15.2.