Skip to content

Commit b9db7d8

Browse files
authored
Merge pull request #7 from zig-gamedev/4.0-fixes
2 parents fcde2da + 8f38706 commit b9db7d8

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

src/tests.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ test "zflecs.helloworld" {
312312
ecs.TAG(world, Apples);
313313

314314
{
315-
ecs.ADD_SYSTEM_WITH_FILTERS(world, "move system", ecs.OnUpdate, move, &.{
315+
_ = ecs.ADD_SYSTEM_WITH_FILTERS(world, "move system", ecs.OnUpdate, move, &.{
316316
.{ .id = ecs.id(Position) },
317317
.{ .id = ecs.id(Velocity) },
318318
});
@@ -361,8 +361,8 @@ test "zflecs.helloworld_systemcomptime" {
361361
ecs.TAG(world, Eats);
362362
ecs.TAG(world, Apples);
363363

364-
ecs.ADD_SYSTEM(world, "move system", ecs.OnUpdate, move_system);
365-
ecs.ADD_SYSTEM(world, "move system with iterator", ecs.OnUpdate, move_system_with_it);
364+
_ = ecs.ADD_SYSTEM(world, "move system", ecs.OnUpdate, move_system);
365+
_ = ecs.ADD_SYSTEM(world, "move system with iterator", ecs.OnUpdate, move_system_with_it);
366366

367367
const bob = ecs.new_entity(world, "Bob");
368368
_ = ecs.set(world, bob, Position, .{ .x = 0, .y = 0 });
@@ -502,7 +502,7 @@ test "zflecs.struct-dtor-hook" {
502502
}
503503
}.chatSystem;
504504
system_desc.query.terms[0] = .{ .id = ecs.id(Chat) };
505-
ecs.SYSTEM(world, "Chat system", ecs.OnUpdate, &system_desc);
505+
_ = ecs.SYSTEM(world, "Chat system", ecs.OnUpdate, &system_desc);
506506
}
507507

508508
const chat_entity = ecs.new_entity(world, "Chat entity");

src/zflecs.zig

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ pub const EcsAperiodicComponentMonitors = 1 << 2;
161161
pub const EcsAperiodicEmptyQueries = 1 << 4;
162162

163163
// Extern declarations
164+
extern const EcsQuery: entity_t;
165+
extern const EcsObserver: entity_t;
166+
extern const EcsSystem: entity_t;
164167
extern const EcsWildcard: entity_t;
165168
extern const EcsAny: entity_t;
166169
extern const EcsTransitive: entity_t;
@@ -223,6 +226,9 @@ extern const EcsPredLookup: entity_t;
223226
extern const EcsIsA: entity_t;
224227
extern const EcsDependsOn: entity_t;
225228

229+
pub var Query: entity_t = undefined;
230+
pub var Observer: entity_t = undefined;
231+
pub var System: entity_t = undefined;
226232
pub var Wildcard: entity_t = undefined;
227233
pub var Any: entity_t = undefined;
228234
pub var Transitive: entity_t = undefined;
@@ -1175,6 +1181,9 @@ pub fn init() *world_t {
11751181
component_ids_hm.ensureTotalCapacity(32) catch @panic("OOM");
11761182
const world = ecs_init();
11771183

1184+
Query = EcsQuery;
1185+
Observer = EcsObserver;
1186+
System = EcsSystem;
11781187
Wildcard = EcsWildcard;
11791188
Any = EcsAny;
11801189
Transitive = EcsTransitive;
@@ -1498,9 +1507,9 @@ extern fn ecs_add_id(world: *world_t, entity: entity_t, id: id_t) void;
14981507
pub const remove_id = ecs_remove_id;
14991508
extern fn ecs_remove_id(world: *world_t, entity: entity_t, id: id_t) void;
15001509

1501-
/// `pub fn override_id(world: *world_t, entity: entity_t, id: id_t) void`
1502-
pub const override_id = ecs_override_id;
1503-
extern fn ecs_override_id(world: *world_t, entity: entity_t, id: id_t) void;
1510+
/// `pub fn auto_override_id(world: *world_t, entity: entity_t, id: id_t) void`
1511+
pub const auto_override_id = ecs_auto_override_id;
1512+
extern fn ecs_auto_override_id(world: *world_t, entity: entity_t, id: id_t) void;
15041513

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

2042-
/// `pub fn observer_default_run_action(it: *iter_t) bool`
2043-
pub const observer_default_run_action = ecs_observer_default_run_action;
2044-
extern fn ecs_observer_default_run_action(it: *iter_t) bool;
2045-
20462051
/// `pub fn observer_get_ctx(world: *const world_t, observer: entity_t) ?*anyopaque`
20472052
pub const observer_get_ctx = ecs_observer_get_ctx;
20482053
extern fn ecs_observer_get_ctx(world: *const world_t, observer: entity_t) ?*anyopaque;
@@ -2466,7 +2471,7 @@ pub fn SYSTEM(
24662471
name: [*:0]const u8,
24672472
phase: entity_t,
24682473
system_desc: *system_desc_t,
2469-
) void {
2474+
) entity_t {
24702475
var entity_desc = entity_desc_t{};
24712476
entity_desc.id = new_id(world);
24722477
entity_desc.name = name;
@@ -2475,20 +2480,20 @@ pub fn SYSTEM(
24752480
entity_desc.add = &.{ first, second, 0 };
24762481

24772482
system_desc.entity = entity_init(world, &entity_desc);
2478-
_ = system_init(world, system_desc);
2483+
return system_init(world, system_desc);
24792484
}
24802485

24812486
pub fn OBSERVER(
24822487
world: *world_t,
24832488
name: [*:0]const u8,
24842489
observer_desc: *observer_desc_t,
2485-
) void {
2490+
) entity_t {
24862491
var entity_desc = entity_desc_t{};
24872492
entity_desc.id = new_id(world);
24882493
entity_desc.name = name;
24892494

24902495
observer_desc.entity = entity_init(world, &entity_desc);
2491-
_ = observer_init(world, observer_desc);
2496+
return observer_init(world, observer_desc);
24922497
}
24932498

24942499
/// Implements a flecs system from function parameters.
@@ -2575,9 +2580,9 @@ pub fn ADD_SYSTEM(
25752580
name: [*:0]const u8,
25762581
phase: entity_t,
25772582
comptime fn_system: anytype,
2578-
) void {
2583+
) entity_t {
25792584
var desc = SYSTEM_DESC(fn_system);
2580-
SYSTEM(world, name, phase, &desc);
2585+
return SYSTEM(world, name, phase, &desc);
25812586
}
25822587

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

25962601
pub fn new_entity(world: *world_t, name: [*:0]const u8) entity_t {
@@ -2600,7 +2605,7 @@ pub fn new_entity(world: *world_t, name: [*:0]const u8) entity_t {
26002605
pub fn new_prefab(world: *world_t, name: [*:0]const u8) entity_t {
26012606
return entity_init(world, &.{
26022607
.name = name,
2603-
.add = [_]id_t{EcsPrefab} ++ [_]id_t{0} ** (FLECS_ID_DESC_MAX - 1),
2608+
.add = @ptrCast(&[_]id_t{EcsPrefab} ++ [_]id_t{0} ** (FLECS_ID_DESC_MAX - 1)),
26042609
});
26052610
}
26062611

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

26952700
pub fn override(world: *world_t, entity: entity_t, comptime T: type) void {
2696-
ecs_override_id(world, entity, id(T));
2701+
ecs_auto_override_id(world, entity, id(T));
26972702
}
26982703

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

29402945
//--------------------------------------------------------------------------------------------------
29412946
//
2942-
// FLECS_MONITOR
2947+
// FLECS_STATS
29432948
//
29442949
//--------------------------------------------------------------------------------------------------
29452950

2946-
pub extern fn FlecsMonitorImport(world: *world_t) void;
2951+
pub extern fn FlecsStatsImport(world: *world_t) void;
29472952
//--------------------------------------------------------------------------------------------------
29482953
//
29492954
// FLECS_REST

0 commit comments

Comments
 (0)