{"id":13626672,"url":"https://github.com/prime31/zig-ecs","last_synced_at":"2025-04-08T13:06:40.508Z","repository":{"id":43845981,"uuid":"268424226","full_name":"prime31/zig-ecs","owner":"prime31","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-13T21:04:01.000Z","size":261,"stargazers_count":323,"open_issues_count":4,"forks_count":45,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T12:04:17.764Z","etag":null,"topics":["zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/prime31.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":"2020-06-01T04:23:04.000Z","updated_at":"2025-04-01T11:36:21.000Z","dependencies_parsed_at":"2022-09-12T05:40:37.967Z","dependency_job_id":"587b85ff-018a-4492-bc0c-9637991b48b5","html_url":"https://github.com/prime31/zig-ecs","commit_stats":{"total_commits":170,"total_committers":25,"mean_commits":6.8,"dds":"0.45882352941176474","last_synced_commit":"b47670da5fc32ec200d63bb0b0a6c93640fca602"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prime31%2Fzig-ecs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prime31%2Fzig-ecs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prime31%2Fzig-ecs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prime31%2Fzig-ecs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prime31","download_url":"https://codeload.github.com/prime31/zig-ecs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247847608,"owners_count":21006099,"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":["zig"],"created_at":"2024-08-01T21:02:26.141Z","updated_at":"2025-04-08T13:06:40.483Z","avatar_url":"https://github.com/prime31.png","language":"Zig","readme":"# Zig ECS\nZig ECS is a zig port of the fantasic [Entt](https://github.com/skypjack/entt). Entt is _highly_ templated C++ code which depending on your opinion is either a good thing or satan itself in code form. Zig doesn't have the same concept as C++ templates so the templated code was changed over to use Zig's generics and compile time metaprogramming.\n\n## What does a zigified Entt look like?\nBelow are examples of a View and a Group, the two main ways to work with entities in the ecs along with the scaffolding code.\n\nDeclare some structs to work with:\n```zig\npub const Velocity = struct { x: f32, y: f32 };\npub const Position = struct { x: f32, y: f32 };\n```\n\nSetup the Registry, which holds the entity data and is where we run our queries:\n```zig\nvar reg = ecs.Registry.init(std.testing.allocator);\n```\n\nCreate a couple entities and add some components to them\n```zig\nconst entity = reg.create();\nreg.add(entity, Position{ .x = 0, .y = 0 });\nreg.add(entity, Velocity{ .x = 5, .y = 7 });\n...\n```\n\nCreate and iterate a View that matches all entities with a `Velocity` and `Position` component:\n```zig\nvar view = reg.view(.{ Velocity, Position }, .{});\n\nvar iter = view.entityIterator();\nwhile (iter.next()) |entity| {\n    const pos = view.getConst(Position, entity); // readonly copy\n    var vel = view.get(Velocity, entity); // mutable\n}\n```\n\nThe same example using an owning Group and iterating with `each`:\n```zig\nvar group = reg.group(.{ Velocity, Position }, .{}, .{});\ngroup.each(each);\n\nfn each(e: struct { vel: *Velocity, pos: *Position }) void {\n    e.pos.*.x += e.vel.x;\n    e.pos.*.y += e.vel.y;\n}\n```\n\n## Component Storage Overview\n- **View**: stores no data in the ECS. Iterates on the fly with no cache to speed up iteration. Start with a `View` for most things and you can always upgrade to a `Group`/`OwningGroup` if you need more speed.\n- **Group**: stores and maintains an accurate list of all the entities matching the query. This query cache speeds up iteration since it already knows exactly which entities match the query. The downside is that it requires memory and cpu cycles to keep the cache up-to-date.\n- **OwningGroup**: for any components in an `OwningGroup` the actual component storage containers are constantly reordered as entities are added/removed from the `Registry`. This allows direct iteration with no gaps of the component data. An `OwningGroup` does not require much extra memory but it is more cpu intensive if there is a lot of component churn (adding/removing of the owned components).\n","funding_links":[],"categories":["Zig","[ECS Libraries](#contents)"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprime31%2Fzig-ecs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprime31%2Fzig-ecs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprime31%2Fzig-ecs/lists"}