{"id":21653616,"url":"https://github.com/karnkaul/decf","last_synced_at":"2025-03-20T04:31:58.709Z","repository":{"id":133375078,"uuid":"339632368","full_name":"karnkaul/decf","owner":"karnkaul","description":"Dumb simple Entity-Component framework in C++17","archived":false,"fork":false,"pushed_at":"2021-11-05T04:51:12.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-25T06:11:21.117Z","etag":null,"topics":["cpp","cpp17","cpp17-library","ecs","entity-framework"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karnkaul.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":"2021-02-17T06:32:09.000Z","updated_at":"2021-11-05T04:51:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"64737476-cae2-4b0d-aaad-f8cd6d753b3f","html_url":"https://github.com/karnkaul/decf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karnkaul%2Fdecf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karnkaul%2Fdecf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karnkaul%2Fdecf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karnkaul%2Fdecf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karnkaul","download_url":"https://codeload.github.com/karnkaul/decf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244552047,"owners_count":20470983,"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":["cpp","cpp17","cpp17-library","ecs","entity-framework"],"created_at":"2024-11-25T08:19:34.098Z","updated_at":"2025-03-20T04:31:58.702Z","avatar_url":"https://github.com/karnkaul.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Dumb Entity-Component (Framework)\n\n[![Build status](https://ci.appveyor.com/api/projects/status/aa5hi5i22dyeskv7?svg=true)](https://ci.appveyor.com/project/karnkaul/decf)\n\nThis is a \"dumb simple\" Entity-Component framework.\n\n### Features\n\n- Lightweight strongly-typed 64-bit unsigned int wrapper as `entity`\n- Type-erased storage of any moveable type `T` as components\n- Supports one instance of any `T` attached to any `entity`\n- Performant `attach\u003cT\u003e` / `detach\u003cT\u003e`\n- Highly performant `O(1)` lookup for `find\u003cT\u003e` / `get\u003cT\u003e`\n- Optimised, performant `view\u003cT...\u003e()`\n\n**Public KT submodules**\n\n- [`enum_flags`](https://github.com/karnkaul/enum-flags.git): `enum class` wrapper over `std::bitset`\n\n### Usage\n\n**Requirements**\n\n- CMake\n- C++17 compiler (and stdlib)\n\n**Steps**\n\n1. Clone repo to appropriate subdirectory, say `dumb_ec`\n1. Add library to project via: `add_subdirectory(dumb_ec)` and `target_link_libraries(foo decf::dec)`\n1. Use via: `#include \u003cdumb_ecf/registry.hpp\u003e`\n\n**Example**\n\n```cpp\n// ...\n#include \u003cdumb_ecf/registry.hpp\u003e\n\nstruct foo {\n  int i;\n  char c;\n\n  foo(int i = 0, char c = ' ') : i(i), c(c) {\n  }\n};\n\n// ...\n\nstd::unordered_set\u003centity\u003e spawned;\ndecf::registry registry;   // Multiple instances can coexist\n\nauto [e0, c0] = registry.spawn\u003cstd::string\u003e(\"ent0\");\nauto\u0026 [name] = c0;  // tuple\u003cT\u0026\u003e =\u003e structured binding\nname = \"ent0\";\nspawned.insert(e0); // std::hash\u003cEntity\u003e specialized\n\nauto [e1, _] = registry.spawn\u003cfoo\u003e(\"ent1\", 42, 'x'); // Args forwarded as T{args...}\nspawned.insert(e1);\n\nauto [e2, c2] = registry.spawn\u003cint, char\u003e(\"ent2\");  // Multiple attachments (no args possible)\nauto\u0026 [i, c] = c2;  // tuple\u003cT\u0026, U\u0026\u003e =\u003e structured binding\ni = registry.get\u003cfoo\u003e(e1).i;  // assumes foo is attached to e1\nif (auto f = registry.find\u003cfoo\u003e(e1)) {  // returns pointer (nullptr if not present)\n  c = f-\u003ec;\n}\n\nif (registry.contains(e0)) {\n  std::cout \u003c\u003c registry.name(e0) \u003c\u003c \" destroyed\\n\";\n  ensure(registry.destroy(e0));   // assuming ensure() to behave like assert(), regardless of _DEBUG\n}\n\nif (auto f = registry.attach\u003cfoo\u003e(e1)) {  // Returns nullptr if entity doesn't exist\n  *f = {-1, 'z'};\n}\nensure(registry.detach\u003cchar\u003e(e2));\n\nauto [e3, _] = registry.spawn\u003cfoo, int\u003e(\"ent3\");\nspawned.insert(e3);\nregistry.enable(e3, false);\nauto view = registry.view\u003cfoo\u003e(decf::flag_t::disabled, {});  // enabled entities with foo attached (default)\nview = registry.view\u003cfoo\u003e(decf::flag_t::disabled, decf::flag_t::disabled);  // disabled entities with foo attached\nview = registry.view\u003cfoo\u003e({}, {});  // all entities with foo attached\n\nauto view2 = registry.view\u003cfoo, int\u003e(); // enabled entities with foo and int attached\nfor (auto\u0026 [e, c] : view2) {\n  auto\u0026 [f, i] = c;\n  // ...\n}\n\nfor (auto const\u0026 e : spawned) {\n  if (registry.contains(e)) {\n    std::cout \u003c\u003c registry.name(e) \u003c\u003c \" destroyed\\n\";\n    ensure(registry.destroy(e));\n  }\n}\n```\n\n### Contributing\n\nPull/merge requests are welcome.\n\n**[Original Repository](https://github.com/karnkaul/decf)**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarnkaul%2Fdecf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarnkaul%2Fdecf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarnkaul%2Fdecf/lists"}