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 doesn't support addons #435

Open
hacklash opened this issue Oct 31, 2023 · 1 comment
Open

Zflecs doesn't support addons #435

hacklash opened this issue Oct 31, 2023 · 1 comment

Comments

@hacklash
Copy link

I'm trying to use the flecs explorer, but it seems impossible with the current state of zflecs.
I need the ecs_singleton_set function from the addons
I tried to workaround this by just using set / ecs_set, but I don't see how to do it with ecs_id() implemented as a c macro

@andreakarasho
Copy link

That's my workaround:

const std = @import("std");
const ecs = @import("zflecs");

pub const ecs_app_desc_t = extern struct {
    target_fps: f32 = 0,
    delta_time: f32 = 0,
    threads: c_int = 0,
    frames: c_int = 0,
    enable_rest: bool = false,
    enable_monitor: bool = false,
    init: ?*anyopaque = null,
    ctx: ?*anyopaque = null,
};

extern "c" fn ecs_app_run(world: *ecs.world_t, app_desc: *ecs_app_desc_t) c_int;
pub inline fn app_run(world: *ecs.world_t, app_desc: *ecs_app_desc_t) i32 {
    return ecs_app_run(world, app_desc);
}

pub inline fn singleton(world: *ecs.world_t, comptime T: type, val: T) ecs.entity_t {
    return ecs.set(world, ecs.id(T), T, val);
}

pub inline fn get_singleton_mut(world: *ecs.world_t, comptime T: type) ?*T {
    return ecs.get_mut(world, ecs.id(T), T);
}
var app_desc = flecs_addon.ecs_app_desc_t{
        .enable_rest = true,
    };

const result = flecs_addon.app_run(world, &app_desc);

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

2 participants