Skip to content

Comments

Add BodyInterface methods, fixup usage of deprecated std.Build APIs #19

Merged
hazeycode merged 4 commits intozig-gamedev:mainfrom
kcbanner:body_interface_methods
Jan 18, 2026
Merged

Add BodyInterface methods, fixup usage of deprecated std.Build APIs #19
hazeycode merged 4 commits intozig-gamedev:mainfrom
kcbanner:body_interface_methods

Conversation

@kcbanner
Copy link
Collaborator

@kcbanner kcbanner commented Jan 3, 2026

  • Add destroyBodies / removeBodies / setShape
  • Fixup AddState to allow zero (which is a valid result returned by AddBodiesPrepare when length is zero)
  • Remove redundant semicolons in _JPC_REFTARGET_HEADER_ALIGN_16 macros
  • Use @Splat(...) where possible instead of **
  • Fixup usage of deprecated std.Build APIs

The build API changes are required for zig 0.16.x compatibility, but they also compile against 0.15.2.

- Fixup AddState to allow zero (which is a valid result returned by AddBodiesPrepare when length is zero)
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and setShape methods to BodyInterface
  • Changed AddState to *allowzero opaque {} to support zero-length array operations
  • Updated build.zig to use root_module API instead of deprecated direct methods
  • Modernized Zig code with @splat instead of ** N pattern

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.

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);
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
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);
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
);
}

pub fn removeBodies(body_iface: *BodyInterface, body_ids: []BodyId) void {
Copy link

Copilot AI Jan 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hazeycode merged commit cef4738 into zig-gamedev:main Jan 18, 2026
3 checks passed
@OndraVoves
Copy link

@hazeycode Thx ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants