Skip to content

Commit

Permalink
Merge pull request #7 from zig-gamedev/4.0-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hazeycode authored Jan 18, 2025
2 parents fcde2da + 8f38706 commit b9db7d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ test "zflecs.helloworld" {
ecs.TAG(world, Apples);

{
ecs.ADD_SYSTEM_WITH_FILTERS(world, "move system", ecs.OnUpdate, move, &.{
_ = ecs.ADD_SYSTEM_WITH_FILTERS(world, "move system", ecs.OnUpdate, move, &.{
.{ .id = ecs.id(Position) },
.{ .id = ecs.id(Velocity) },
});
Expand Down Expand Up @@ -361,8 +361,8 @@ test "zflecs.helloworld_systemcomptime" {
ecs.TAG(world, Eats);
ecs.TAG(world, Apples);

ecs.ADD_SYSTEM(world, "move system", ecs.OnUpdate, move_system);
ecs.ADD_SYSTEM(world, "move system with iterator", ecs.OnUpdate, move_system_with_it);
_ = ecs.ADD_SYSTEM(world, "move system", ecs.OnUpdate, move_system);
_ = ecs.ADD_SYSTEM(world, "move system with iterator", ecs.OnUpdate, move_system_with_it);

const bob = ecs.new_entity(world, "Bob");
_ = ecs.set(world, bob, Position, .{ .x = 0, .y = 0 });
Expand Down Expand Up @@ -502,7 +502,7 @@ test "zflecs.struct-dtor-hook" {
}
}.chatSystem;
system_desc.query.terms[0] = .{ .id = ecs.id(Chat) };
ecs.SYSTEM(world, "Chat system", ecs.OnUpdate, &system_desc);
_ = ecs.SYSTEM(world, "Chat system", ecs.OnUpdate, &system_desc);
}

const chat_entity = ecs.new_entity(world, "Chat entity");
Expand Down
43 changes: 24 additions & 19 deletions src/zflecs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ pub const EcsAperiodicComponentMonitors = 1 << 2;
pub const EcsAperiodicEmptyQueries = 1 << 4;

// Extern declarations
extern const EcsQuery: entity_t;
extern const EcsObserver: entity_t;
extern const EcsSystem: entity_t;
extern const EcsWildcard: entity_t;
extern const EcsAny: entity_t;
extern const EcsTransitive: entity_t;
Expand Down Expand Up @@ -223,6 +226,9 @@ extern const EcsPredLookup: entity_t;
extern const EcsIsA: entity_t;
extern const EcsDependsOn: entity_t;

pub var Query: entity_t = undefined;
pub var Observer: entity_t = undefined;
pub var System: entity_t = undefined;
pub var Wildcard: entity_t = undefined;
pub var Any: entity_t = undefined;
pub var Transitive: entity_t = undefined;
Expand Down Expand Up @@ -1175,6 +1181,9 @@ pub fn init() *world_t {
component_ids_hm.ensureTotalCapacity(32) catch @panic("OOM");
const world = ecs_init();

Query = EcsQuery;
Observer = EcsObserver;
System = EcsSystem;
Wildcard = EcsWildcard;
Any = EcsAny;
Transitive = EcsTransitive;
Expand Down Expand Up @@ -1498,9 +1507,9 @@ extern fn ecs_add_id(world: *world_t, entity: entity_t, id: id_t) void;
pub const remove_id = ecs_remove_id;
extern fn ecs_remove_id(world: *world_t, entity: entity_t, id: id_t) void;

/// `pub fn override_id(world: *world_t, entity: entity_t, id: id_t) void`
pub const override_id = ecs_override_id;
extern fn ecs_override_id(world: *world_t, entity: entity_t, id: id_t) void;
/// `pub fn auto_override_id(world: *world_t, entity: entity_t, id: id_t) void`
pub const auto_override_id = ecs_auto_override_id;
extern fn ecs_auto_override_id(world: *world_t, entity: entity_t, id: id_t) void;

/// `pub fn clear(world: *world_t, entity: entity_t) void`
pub const clear = ecs_clear;
Expand Down Expand Up @@ -2039,10 +2048,6 @@ extern fn ecs_enqueue(world: *world_t, desc: *event_desc_t) void;
pub const observer_init = ecs_observer_init;
extern fn ecs_observer_init(world: *world_t, desc: *const observer_desc_t) entity_t;

/// `pub fn observer_default_run_action(it: *iter_t) bool`
pub const observer_default_run_action = ecs_observer_default_run_action;
extern fn ecs_observer_default_run_action(it: *iter_t) bool;

/// `pub fn observer_get_ctx(world: *const world_t, observer: entity_t) ?*anyopaque`
pub const observer_get_ctx = ecs_observer_get_ctx;
extern fn ecs_observer_get_ctx(world: *const world_t, observer: entity_t) ?*anyopaque;
Expand Down Expand Up @@ -2466,7 +2471,7 @@ pub fn SYSTEM(
name: [*:0]const u8,
phase: entity_t,
system_desc: *system_desc_t,
) void {
) entity_t {
var entity_desc = entity_desc_t{};
entity_desc.id = new_id(world);
entity_desc.name = name;
Expand All @@ -2475,20 +2480,20 @@ pub fn SYSTEM(
entity_desc.add = &.{ first, second, 0 };

system_desc.entity = entity_init(world, &entity_desc);
_ = system_init(world, system_desc);
return system_init(world, system_desc);
}

pub fn OBSERVER(
world: *world_t,
name: [*:0]const u8,
observer_desc: *observer_desc_t,
) void {
) entity_t {
var entity_desc = entity_desc_t{};
entity_desc.id = new_id(world);
entity_desc.name = name;

observer_desc.entity = entity_init(world, &entity_desc);
_ = observer_init(world, observer_desc);
return observer_init(world, observer_desc);
}

/// Implements a flecs system from function parameters.
Expand Down Expand Up @@ -2575,9 +2580,9 @@ pub fn ADD_SYSTEM(
name: [*:0]const u8,
phase: entity_t,
comptime fn_system: anytype,
) void {
) entity_t {
var desc = SYSTEM_DESC(fn_system);
SYSTEM(world, name, phase, &desc);
return SYSTEM(world, name, phase, &desc);
}

/// Creates a system description and adds it to the world, from function parameters
Expand All @@ -2588,9 +2593,9 @@ pub fn ADD_SYSTEM_WITH_FILTERS(
phase: entity_t,
comptime fn_system: anytype,
filters: []const term_t,
) void {
) entity_t {
var desc = SYSTEM_DESC_WITH_FILTERS(fn_system, filters);
SYSTEM(world, name, phase, &desc);
return SYSTEM(world, name, phase, &desc);
}

pub fn new_entity(world: *world_t, name: [*:0]const u8) entity_t {
Expand All @@ -2600,7 +2605,7 @@ pub fn new_entity(world: *world_t, name: [*:0]const u8) entity_t {
pub fn new_prefab(world: *world_t, name: [*:0]const u8) entity_t {
return entity_init(world, &.{
.name = name,
.add = [_]id_t{EcsPrefab} ++ [_]id_t{0} ** (FLECS_ID_DESC_MAX - 1),
.add = @ptrCast(&[_]id_t{EcsPrefab} ++ [_]id_t{0} ** (FLECS_ID_DESC_MAX - 1)),
});
}

Expand Down Expand Up @@ -2693,7 +2698,7 @@ pub fn remove(world: *world_t, entity: entity_t, comptime T: type) void {
}

pub fn override(world: *world_t, entity: entity_t, comptime T: type) void {
ecs_override_id(world, entity, id(T));
ecs_auto_override_id(world, entity, id(T));
}

pub fn modified(world: *world_t, entity: entity_t, comptime T: type) void {
Expand Down Expand Up @@ -2939,11 +2944,11 @@ extern fn ecs_import_c(world: *world_t, module: module_action_t, module_name_c:

//--------------------------------------------------------------------------------------------------
//
// FLECS_MONITOR
// FLECS_STATS
//
//--------------------------------------------------------------------------------------------------

pub extern fn FlecsMonitorImport(world: *world_t) void;
pub extern fn FlecsStatsImport(world: *world_t) void;
//--------------------------------------------------------------------------------------------------
//
// FLECS_REST
Expand Down

0 comments on commit b9db7d8

Please sign in to comment.