|
|
@ -42,13 +42,21 @@ pub fn Context(comptime ctx: anytype) type { |
|
|
|
pub const Pair = @import("./pair.zig").Pair(ctx); |
|
|
|
pub const Pair = @import("./pair.zig").Pair(ctx); |
|
|
|
pub const World = @import("./world.zig").World(ctx); |
|
|
|
pub const World = @import("./world.zig").World(ctx); |
|
|
|
|
|
|
|
|
|
|
|
/// Returns a pointer unique to this context and the provided type |
|
|
|
/// Looks up an entity ID unique to this `Context` for the provided |
|
|
|
|
|
|
|
/// type that has been registered previously, typically done by |
|
|
|
|
|
|
|
/// calling functions such as `World.component(...)`. |
|
|
|
|
|
|
|
pub fn lookup(comptime T: type) c.ecs_entity_t { |
|
|
|
|
|
|
|
return lookupMut(T).*; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns a pointer unique to this `Context` and the provided type |
|
|
|
/// that holds an entity ID. Useful for associating types to entities. |
|
|
|
/// that holds an entity ID. Useful for associating types to entities. |
|
|
|
pub fn lookup(comptime T: type) *c.ecs_entity_t { |
|
|
|
pub fn lookupMut(comptime T: type) *c.ecs_entity_t { |
|
|
|
_ = T; // Only necessary to create a unique type. |
|
|
|
_ = T; // Only necessary to create a unique type. |
|
|
|
return &(struct { |
|
|
|
const EntityHolder = struct { |
|
|
|
pub var id: c.ecs_entity_t = 0; |
|
|
|
pub var id: c.ecs_entity_t = 0; |
|
|
|
}).id; |
|
|
|
}; |
|
|
|
|
|
|
|
return &EntityHolder.id; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Converts the specified value to an `ecs_entity_t`. |
|
|
|
/// Converts the specified value to an `ecs_entity_t`. |
|
|
@ -67,7 +75,7 @@ pub fn Context(comptime ctx: anytype) type { |
|
|
|
c.ecs_entity_t => value, |
|
|
|
c.ecs_entity_t => value, |
|
|
|
Entity => value.raw, |
|
|
|
Entity => value.raw, |
|
|
|
?Entity => if (value) |v| v.raw else 0, |
|
|
|
?Entity => if (value) |v| v.raw else 0, |
|
|
|
type => lookup(value).*, |
|
|
|
type => lookup(value), |
|
|
|
else => @compileError("Value of type " ++ @typeName(@TypeOf(value)) ++ " can't be converted to Entity"), |
|
|
|
else => @compileError("Value of type " ++ @typeName(@TypeOf(value)) ++ " can't be converted to Entity"), |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
@ -105,7 +113,7 @@ pub fn Context(comptime ctx: anytype) type { |
|
|
|
// c.ecs_entity_t => value, |
|
|
|
// c.ecs_entity_t => value, |
|
|
|
Entity => value.raw, |
|
|
|
Entity => value.raw, |
|
|
|
?Entity => if (value) |v| v.raw else 0, |
|
|
|
?Entity => if (value) |v| v.raw else 0, |
|
|
|
type => lookup(value).*, |
|
|
|
type => lookup(value), |
|
|
|
else => @compileError("Value of type " ++ @typeName(T) ++ " can't be converted to Id"), |
|
|
|
else => @compileError("Value of type " ++ @typeName(T) ++ " can't be converted to Id"), |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|