Skip to content
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

zflecs: C or zig style? Yes #379

Open
Pyrolistical opened this issue Aug 17, 2023 · 3 comments
Open

zflecs: C or zig style? Yes #379

Pyrolistical opened this issue Aug 17, 2023 · 3 comments

Comments

@Pyrolistical
Copy link
Contributor

Pyrolistical commented Aug 17, 2023

In #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?

@michal-z
Copy link
Collaborator

Yes, this direction seems fine to me.

@Olle-Lukowski
Copy link

I am curious, do you need any help with this? I am willing to contribute to get this done, since I am going to use zflecs for my game engine.

@Pyrolistical
Copy link
Contributor Author

You can lead this effort. I'm not working on this at the moment

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

No branches or pull requests

3 participants