{"id":26491989,"url":"https://github.com/zig-gamedev/zflecs","last_synced_at":"2025-03-20T08:51:37.274Z","repository":{"id":270752682,"uuid":"882829532","full_name":"zig-gamedev/zflecs","owner":"zig-gamedev","description":"Zig build package and bindings for https://github.com/SanderMertens/flecs","archived":false,"fork":false,"pushed_at":"2025-03-05T18:01:27.000Z","size":765,"stargazers_count":12,"open_issues_count":6,"forks_count":9,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-05T19:19:39.289Z","etag":null,"topics":["bindings","ecs","flecs","gamedev","zig"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zig-gamedev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-03T21:30:16.000Z","updated_at":"2025-03-05T18:01:32.000Z","dependencies_parsed_at":"2025-01-25T15:23:15.194Z","dependency_job_id":"d682bd64-d52f-4721-9975-a35fa769b44d","html_url":"https://github.com/zig-gamedev/zflecs","commit_stats":null,"previous_names":["zig-gamedev/zflecs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzflecs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzflecs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzflecs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzflecs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zig-gamedev","download_url":"https://codeload.github.com/zig-gamedev/zflecs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244583172,"owners_count":20476233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bindings","ecs","flecs","gamedev","zig"],"created_at":"2025-03-20T08:51:36.581Z","updated_at":"2025-03-20T08:51:37.267Z","avatar_url":"https://github.com/zig-gamedev.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [zflecs](https://github.com/zig-gamedev/zflecs)\n\nZig build package and bindings for [flecs](https://github.com/SanderMertens/flecs) ECS v4.0.4\n\n## Getting started\n\nExample`build.zig`:\n\n```zig\npub fn build(b: *std.Build) void {\n    const exe = b.addExecutable(.{ ... });\n\n    const zflecs = b.dependency(\"zflecs\", .{});\n    exe.root_module.addImport(\"zflecs\", zflecs.module(\"root\"));\n    exe.linkLibrary(zflecs.artifact(\"flecs\"));\n}\n```\n\nNow in your code you may import and use `zflecs`:\n\n```zig\nconst std = @import(\"std\");\nconst ecs = @import(\"zflecs\");\n\nconst Position = struct { x: f32, y: f32 };\nconst Velocity = struct { x: f32, y: f32 };\nconst Eats = struct {};\nconst Apples = struct {};\n\nfn move_system(positions: []Position, velocities: []const Velocity) void {\n    for (positions, velocities) |*p, v| {\n        p.x += v.x;\n        p.y += v.y;\n    }\n}\n\n//Optionally, systems can receive the components iterator (usually not necessary)\nfn move_system_with_it(it: *ecs.iter_t, positions: []Position, velocities: []const Velocity) void {\n    const type_str = ecs.table_str(it.world, it.table).?;\n    std.debug.print(\"Move entities with [{s}]\\n\", .{type_str});\n    defer ecs.os.free(type_str);\n\n    for (positions, velocities) |*p, v| {\n        p.x += v.x;\n        p.y += v.y;\n    }\n}\n\npub fn main() !void {\n    const world = ecs.init();\n    defer _ = ecs.fini(world);\n\n    ecs.COMPONENT(world, Position);\n    ecs.COMPONENT(world, Velocity);\n\n    ecs.TAG(world, Eats);\n    ecs.TAG(world, Apples);\n\n    ecs.ADD_SYSTEM(world, \"move system\", ecs.OnUpdate, move_system);\n    ecs.ADD_SYSTEM(world, \"move system with iterator\", ecs.OnUpdate, move_system_with_it);\n\n    const bob = ecs.new_entity(world, \"Bob\");\n    _ = ecs.set(world, bob, Position, .{ .x = 0, .y = 0 });\n    _ = ecs.set(world, bob, Velocity, .{ .x = 1, .y = 2 });\n    ecs.add_pair(world, bob, ecs.id(Eats), ecs.id(Apples));\n\n    _ = ecs.progress(world, 0);\n    _ = ecs.progress(world, 0);\n\n    const p = ecs.get(world, bob, Position).?;\n    std.debug.print(\"Bob's position is ({d}, {d})\\n\", .{ p.x, p.y });\n}\n```\n\n`zig build run` should result in:\n\n```\nMove entities with [main.Position, main.Velocity, (Identifier,Name), (main.Eats,main.Apples)]\nMove entities with [main.Position, main.Velocity, (Identifier,Name), (main.Eats,main.Apples)]\nBob's position is (4, 8)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzflecs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzig-gamedev%2Fzflecs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzflecs/lists"}