-
Notifications
You must be signed in to change notification settings - Fork 10
Remove usingnamespace, add new interface system, rework IDs, and misc fixes #12
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
Conversation
- Use non-exhaustive enums for BodyId and SubShapeId - Add activateBodies/deactivateBodies The ID change was motivated by needing to implement toJph for JPC_BodyID, which wasn't possible without making the IDs distinct types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated physics_test_wgpu sample app to test. Works well. Nice!
I've also updated the monolith sample app. It works great but I tripped up on something for a while... |
- Introduce a new system for interfaces: - They are defined as structs that are composed as the first member of the implementation - `initInterface` is used to build VTable default values at comptime automatically - Enhance the DebugRenderer test to verify that the render functions are called - Change the signature of DestroyTriangleBatch to pass non-const user pointer - Make all vtable functions non-optional, to improve error messages when `pub` is missing - Fix up test output when PRINT_OUTPUT is enabled - Move defines to a common build function - Add -Dverbose to set PRINT_OUTPUT
…lease enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit. - Remove the vtable header from ContactListener (it's called manually, not used as an actual vtable)
There was a problem hiding this 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 modernizes the codebase by removing the deprecated usingnamespace
feature and introducing a new interface system based on struct composition, while also reworking IDs to use distinct struct types and adding various fixes and enhancements.
- Replaces
usingnamespace
with a new interface system using struct composition and vtable initialization - Changes
JPC_BodyID
andJPC_SubShapeID
from simple typedefs to struct wrappers with anid
field - Adds new functions for batch body activation/deactivation and enhances the debug renderer test coverage
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
libs/JoltC/JoltPhysicsC_Tests.c | Updates test code to use new struct-based ID system and adds debug renderer destroy callback |
libs/JoltC/JoltPhysicsC_Extensions.cpp | Modifies ID assignment to use struct field access |
libs/JoltC/JoltPhysicsC.h | Defines new ID struct types and adds batch activation/deactivation functions |
libs/JoltC/JoltPhysicsC.cpp | Implements ID struct conversions and new batch body operations |
build.zig.zon | Sets minimum Zig version requirement |
build.zig | Refactors build configuration and adds verbose test option |
.zigversion | Removes fixed version file |
.github/workflows/main.yml | Updates CI to use latest Zig setup action |
I tested this against the sample apps and now I get helpful errors as expected for missing or non-pub methods. Nice work! |
usingnamespace
has been removed in zig master, which motivated the bulk of this change.initInterface
is used to build VTable default values at comptime automaticallyinit
function which callsinitInterface
with the appropriate typesMethods
was doing before in most cases.JPC_BodyID
andJPC_SubShapeID
BodyId
andSubShapeId
activateBodies
/deactivateBodies
The ID change was motivated by needing to implement
toJph
forJPC_BodyID
, which wasn't possible without making the IDs distinct types.I spent some time working out different ways to replace the
usingnamespace
usage, and I'm pretty happy with what I landed on (it's somewhat similar to theMixin
example here: ziglang/zig#20663). If there are existing projects where this new system isn't workable, please post your use case here.Upgrade guide:
Calling Super-class Methods
Interfaces
Before:
After:
There is no longer a need to build the vtable yourself, as this is done at comptime by iterating the methods on the implementation.
You can also pass the first member of the implementation directly to the functions that take that interface, without any additional casting.
If you forget / typo the name of a non-optional vtable function, you get a helpful compile-time error: