Ensure EntityHolder is unique

This change is required for new versions of Zig
to consider the EntityHolder struct to be unique.
This is done by capturing the ctx and type in a
compile time context.

See also: https://github.com/ziglang/zig/pull/19190
main
copygirl 1 month ago
parent bde3ec33e5
commit 99ae978f20
  1. 5
      src/context.zig

@ -23,8 +23,11 @@ pub fn Context(comptime ctx: anytype) type {
/// Returns a pointer unique to this `Context` and the provided type
/// that holds an entity ID. Useful for associating types to entities.
pub fn lookupMut(comptime T: type) *c.ecs_entity_t {
_ = T; // Only necessary to create a unique type.
const EntityHolder = struct {
comptime {
// Capture `ctx` and `T` to create a unique struct.
_ = .{ ctx, T };
}
pub var id: c.ecs_entity_t = 0;
};
return &EntityHolder.id;

Loading…
Cancel
Save