{"id":20806492,"url":"https://github.com/elipzis/ecs","last_synced_at":"2025-07-08T06:38:54.290Z","repository":{"id":237720385,"uuid":"791912238","full_name":"elipZis/ecs","owner":"elipZis","description":"⚙️ A simple, type-based Entity Component System","archived":false,"fork":false,"pushed_at":"2024-06-11T10:35:12.000Z","size":55,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T06:23:52.542Z","etag":null,"topics":["component","ecs","entity","entity-component-system","go","golang","system"],"latest_commit_sha":null,"homepage":"","language":"Go","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/elipZis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-04-25T15:59:01.000Z","updated_at":"2024-06-11T10:35:15.000Z","dependencies_parsed_at":"2024-06-11T11:54:52.352Z","dependency_job_id":"10b6aca7-16ee-4f2d-ba78-92fc5a599e27","html_url":"https://github.com/elipZis/ecs","commit_stats":null,"previous_names":["elipzis/ecs"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipZis%2Fecs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipZis%2Fecs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipZis%2Fecs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elipZis%2Fecs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elipZis","download_url":"https://codeload.github.com/elipZis/ecs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252811685,"owners_count":21807993,"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":["component","ecs","entity","entity-component-system","go","golang","system"],"created_at":"2024-11-17T19:20:21.564Z","updated_at":"2025-05-07T04:25:06.903Z","avatar_url":"https://github.com/elipZis.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Entity Component System\n\nA very simple, reflect.Type-based, opinionated ECS for quick usage (but without optimization).\n\n## Installation\n\n`go get github.com/elipZis/ecs`\n\n## Usage\n\nCreate a new world with `world := ecs.New()`. This is your starting point.\n\n### Components\n\nComponents can be any struct you define, for example\n\n```go\ntype PositionComponent struct {\n    X int\n    Y int\n}\n\ntype VelocityComponent struct {\n    DX int\n    DY int\n}\n```\n\nYou can create components on their own or embedded in other structs\n\n```go\ntype Player struct {\n    PositionComponent\n    VelocityComponent\n    OtherComponent\n    \n    name string\n}\n```\n\n### Systems\n\nA system must embed the `EntitySystem` and implement the `System` interface `Run(ecs *ecs.ECS, dt time.Duration)` function:\n\n```go\ntype MoveSystem struct {\n   EntitySystem\n}\n\nfunc (this *MoveSystem) Run(ecs *ecs.ECS, dt time.Duration) {\n   ...\n}\n\n```\n\nAdd systems to the world via e.g. `world.AddSystem(\u0026MoveSystem{}, \u0026PositionComponent{}, \u0026VelocityComponent{})`\n\n* First is the function to run\n* Following are N component types to listen on\n  * The system will only be invoked, if the registered component types match those of an entity\n\n**Note: Systems must be registered before entities!**\n\n#### Priority\n\nBy default all systems have a priority of 0. \nIf you want to order systems, you can implement\n\n```go\nPriority() int\n```\n\nThe higher the number, the earlier the system is called.\n\n#### Components \u0026 Entities\n\nInside a system you can access the ECS itself and you can get all components. \nThe entity system itself knows about all their own entity ids and can iterate on these. For example:\n\n```go\nfunc (this *MoveSystem) Run(ecs *ECS, dt time.Duration) {\n\tpos := ecs.GetComponents(PositionComponent{})\n\tvel := ecs.GetComponents(VelocityComponent{})\n\n\tfor _, entityId := range this.entities {\n\t\tp := pos[entityId].(*PositionComponent)\n\t\tv := vel[entityId].(*VelocityComponent)\n\t\tp.X += v.DX\n\t\tp.Y += v.DY\n\t}\n}\n```\n\nor\n\n```go\nfunc (this *MoveSystem) Run(ecs *ECS, dt time.Duration) {\n    positions := ecs.GetComponentsFor[*component.PositionComponent](e)\n    velocities := ecs.GetComponents(VelocityComponent{})\n    \n    for _, entityId := range this.entities {\n        p := positions[entityId]\n        v := velocities[entityId]\n        p.X += v.DX\n        p.Y += v.DY\n    }\n}\n```\n\nThere are several helper functions to provide access to the different components, context, entities etc.\n\n### Entities\n\nTo create and register a new entity, call \n\n```go\nworld.CreateEntity(\u0026player.PositionComponent, \u0026player.VelocityComponent, \u0026player.OtherComponent)\n```\n\nIt returns the entity with id and components, unique to this world.\n\nThe entity and their components will be injected into all systems, intersecting the component type combination. More is ok, less does not match!\n\n#### Remove Entity\n\nTo remove an entity, call e.g. `ecs.RemoveEntity(id uint64)` on the world or in a system.\nIf you remove an entity, it will be marked to be removed before the next iteration.\n\nTo immediately remove an entity, with consequences for subsequent systems, call `ecs.RemoveEntityNow(id uint64)`.\n\n### Context\n\nVia `world.AddContext(...)` you can add anything as context, available globally to all systems to query for via `world.GetContext(...)`.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first\nto discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## Notes\n\nThis package is heavily inspired by\n\n- https://github.com/EngoEngine/ecs\n- https://github.com/amethyst/legion\n\nKudos, shout-out and thanks to them 🙏\n\n## Credits\n\n- [elipZis GmbH](https://elipZis.com)\n- [NeA](https://github.com/nea)\n- [All Contributors](https://github.com/elipZis/laravel-cacheable-model/contributors)\n\n## Disclaimer\n\nThis source and the whole package comes without a warranty. It may or may not harm your computer. Please use with care. \nAny damage cannot be related back to the author. The source has been tested on a virtual environment and scanned for viruses and has passed all tests.\nIt is not optimized for production, speed or memory consumption but just a personal open-source package.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felipzis%2Fecs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felipzis%2Fecs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felipzis%2Fecs/lists"}