Skip to content

Comments

Fix: make AllowedDOFs non-exhaustive to support bitmasking#24

Merged
hazeycode merged 1 commit intozig-gamedev:mainfrom
krist7599555:patch-1
Feb 11, 2026
Merged

Fix: make AllowedDOFs non-exhaustive to support bitmasking#24
hazeycode merged 1 commit intozig-gamedev:mainfrom
krist7599555:patch-1

Conversation

@krist7599555
Copy link
Contributor

The current implementation uses an exhaustive enum which prevents bitwise combinations. Combining flags results in values (like 23) that don't have a matching tag, causing a compile error:

error: enum 'zphysics.AllowedDOFs' has no tag with value '23'

Fixed by adding _, to the enum definition to make it non-exhaustive, allowing arbitrary bitmask combinations.

Example usage:

BodyInterface.createAndAddBody(.{
  .allowed_DOFs = @enumFromInt(
    @intFromEnum(zphy.AllowedDOFs.translation_x) |
    @intFromEnum(zphy.AllowedDOFs.translation_y) |
    @intFromEnum(zphy.AllowedDOFs.translation_z) |
    @intFromEnum(zphy.AllowedDOFs.rotation_y)
}, ...)

The current implementation uses an exhaustive enum which prevents bitwise 
combinations. Combining flags results in values (like 23) that don't have 
a matching tag, causing a compile error:

> error: enum 'zphysics.AllowedDOFs' has no tag with value '23'

Fixed by adding `_,` to the enum definition to make it non-exhaustive, 
allowing arbitrary bitmask combinations.

Example usage:
```zig
BodyInterface.createAndAddBody(.{
  .allowed_DOFs = @enumFromInt(
    @intFromEnum(zphy.AllowedDOFs.translation_x) |
    @intFromEnum(zphy.AllowedDOFs.translation_y) |
    @intFromEnum(zphy.AllowedDOFs.translation_z) |
    @intFromEnum(zphy.AllowedDOFs.rotation_y)
}, ...)
```
Copy link
Member

@hazeycode hazeycode left a comment

Choose a reason for hiding this comment

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

Thanks!

@hazeycode hazeycode merged commit 9797d7b into zig-gamedev:main Feb 11, 2026
3 checks passed
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.

2 participants