Skip to content

Commit 90e268b

Browse files
authored
Merge pull request #17 from fachu-09/main
Added basic module
2 parents ee2cd43 + 6c238f1 commit 90e268b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/tests.zig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,30 @@ test "zflecs.struct-dtor-hook" {
517517
// commented out since the cleanup is never called to free the ArrayList
518518
// memory.
519519
}
520+
fn module(world: *ecs.world_t) callconv(.C) void {
521+
var desc = ecs.component_desc_t{ .entity = 0, .type = .{ .size = 0, .alignment = 0 } };
522+
_ = ecs.module_init(world, "SimpleModule", &desc);
523+
524+
ecs.COMPONENT(world, Position);
525+
ecs.COMPONENT(world, Velocity);
526+
}
527+
test "zflecs-module" {
528+
const world = ecs.init();
529+
defer _ = ecs.fini(world);
530+
531+
const module_id = ecs.import_c(world, module, "SimpleModule");
532+
533+
try expect(module_id != 0);
534+
535+
_ = ecs.ADD_SYSTEM(world, "move system", ecs.OnUpdate, move_system);
536+
537+
const bob = ecs.new_entity(world, "Bob");
538+
_ = ecs.set(world, bob, Position, .{ .x = 0, .y = 0 });
539+
_ = ecs.set(world, bob, Velocity, .{ .x = 1, .y = 2 });
540+
541+
_ = ecs.progress(world, 0);
542+
_ = ecs.progress(world, 0);
543+
544+
const p = ecs.get(world, bob, Position).?;
545+
print("Bob's position is ({d}, {d})\n", .{ p.x, p.y });
546+
}

src/zflecs.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,6 +3117,11 @@ pub fn delete_children(world: *world_t, parent: entity_t) void {
31173117
pub const import_c = ecs_import_c;
31183118
extern fn ecs_import_c(world: *world_t, module: module_action_t, module_name_c: [*:0]const u8) entity_t;
31193119

3120+
/// `pub fn module_init(world: *world_t, c_name: [*:0]const u8, desc: *component_desc_t) entity_t`
3121+
pub const module_init = ecs_module_init;
3122+
extern fn ecs_module_init(world: *world_t, c_name: [*:0]const u8, desc: *component_desc_t) entity_t;
3123+
3124+
31203125
//--------------------------------------------------------------------------------------------------
31213126
//
31223127
// FLECS_STATS

0 commit comments

Comments
 (0)