Skip to content

C or zig style? Yes #1

@Pyrolistical

Description

@Pyrolistical

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions