-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
In zig-gamedev/zig-gamedev#261, in regards to the zflecs style @michal-z said
Also, it will be easier for the users to follow flecs C code and port it to zig.
I believe we can achieve both in most (if not all) cases.
For example,
// current C style
fn move(it: *ecs.iter_t) callconv(.C) void {
const p = ecs.field(it, Position, 1).?;
const v = ecs.field(it, Velocity, 2).?;
...
// ziggified style
fn move(it: *ecs.iter_t) callconv(.C) void {
const p = it.field(Position, 1).?;
const v = it.field(Velocity, 2).?;
...
We can keep both as the ziggified style only requires duplicating fn field
into the iter_t
struct.
Another example,
// current C style
const world = ecs.init();
defer _ = ecs.fini(world);
ecs.COMPONENT(world, Position);
const bob = ecs.new_entity(world, "Bob");
_ = ecs.set(world, bob, Position, .{ .x = 0, .y = 0 });
// ziggified style
const World = ecs;
const world = World.init();
defer _ = world.fini();
world.COMPONENT(Position);
const bob = world.new_entity("Bob");
_ = world.set(bob, Position, .{ .x = 0, .y = 0 });
To achieve that, I believe we only need to make zflecs.zig
a top-level struct of type World
, but also keep non-world static functions like fn field
and other constants.
World
would hold the pointer to world_t
.
Is this desired direction zflecs should head in?
distantforest1 and balvaldyr
Metadata
Metadata
Assignees
Labels
No labels