Skip to content

Commit

Permalink
v4
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Apr 30, 2024
1 parent 51a7f8f commit cf1a8ef
Show file tree
Hide file tree
Showing 751 changed files with 199,372 additions and 191,795 deletions.
119 changes: 81 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,41 +339,21 @@ jobs:
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_MODULE
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_MODULE
- name: FLECS_SNAPSHOT
run: |
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_SNAPSHOT
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_SNAPSHOT
- name: FLECS_STATS
run: |
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_STATS
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_STATS
- name: FLECS_PARSER
run: |
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_PARSER
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_PARSER
- name: FLECS_PLECS
- name: FLECS_SCRIPT
run: |
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_PLECS
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_PLECS
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_SCRIPT
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_SCRIPT
- name: FLECS_META
run: |
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_META
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_META
- name: FLECS_META_C
run: |
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_META_C
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_META_C
- name: FLECS_EXPR
run: |
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_EXPR
bake rebuild --strict --cfg release -D FLECS_CUSTOM_BUILD -D FLECS_EXPR
- name: FLECS_JSON
run: |
bake rebuild --strict -D FLECS_CUSTOM_BUILD -D FLECS_JSON
Expand Down Expand Up @@ -488,15 +468,21 @@ jobs:
- name: build flecs
run: bake --strict

- name: test api
run: bake run test/api -- -j 8
- name: test core
run: bake run test/core -- -j 8

- name: test query
run: bake run test/query -- -j 8

- name: test addons
run: bake run test/addons -- -j 8

- name: test meta
run: bake run test/meta -- -j 8

- name: test script
run: bake run test/script -- -j 8

- name: test collections
run: bake run test/collections -- -j 8

Expand Down Expand Up @@ -550,7 +536,7 @@ jobs:
run: bake --strict

- name: test c++
run: bake run test/cpp_api -- -j 8
run: bake run test/cpp -- -j 8

test-cpp-macos:
needs: [build-macos]
Expand Down Expand Up @@ -590,7 +576,7 @@ jobs:
run: bake --strict

- name: test c++
run: bake run test/cpp_api -- -j 8
run: bake run test/cpp -- -j 8

test-windows:
needs: build-windows
Expand All @@ -613,20 +599,23 @@ jobs:
- name: build flecs
run: bake/bake

- name: test api
run: bake/bake run test\api -- -j 8
- name: test core
run: bake/bake run test\core -- -j 8

- name: test addons
run: bake/bake run test\addons -- -j 8

- name: test meta
run: bake/bake run test\meta -- -j 8

- name: test script
run: bake/bake run test\script -- -j 8

- name: test collections
run: bake/bake run test\collections -- -j 8

- name: test c++
run: bake/bake run test\cpp_api -- -j 8
run: bake/bake run test\cpp -- -j 8

test-msys:
runs-on: windows-latest
Expand Down Expand Up @@ -669,24 +658,30 @@ jobs:
bake/bake setup
- name: build flecs
run: bake/bake --strict
run: bake/bake --strict --trace

- name: test core
run: bake/bake run test/core -- -j 8

- name: test api
run: bake/bake run test/api -- -j 8
- name: test query
run: bake/bake run test/query -- -j 8

- name: test addons
run: bake/bake run test/addons -- -j 8

- name: test meta
run: bake/bake run test/meta -- -j 8

- name: test script
run: bake/bake run test/script -- -j 8

- name: test collections
run: bake/bake run test/collections -- -j 8

- name: test c++
run: bake/bake run test/cpp_api -- -j 8
run: bake/bake run test/cpp -- -j 8

test-sanitized-api:
test-sanitized-core:
needs: [ build-linux ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
Expand All @@ -708,7 +703,31 @@ jobs:

- name: run tests
run: |
bake run test/api --cfg sanitize -- -j 8
bake run test/core --cfg sanitize -- -j 8
test-sanitized-query:
needs: [ build-linux ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04 ]

steps:
- uses: actions/checkout@v4
- name: install bake
run: |
git clone https://github.com/SanderMertens/bake
make -C bake/build-$(uname)
bake/bake setup
- name: build flecs
run: bake --strict

- name: run tests
run: |
bake run test/query --cfg sanitize -- -j 8
test-sanitized-addons:
needs: [ build-linux ]
Expand Down Expand Up @@ -758,6 +777,30 @@ jobs:
run: |
bake run test/meta --cfg sanitize -- -j 8
test-sanitized-script:
needs: [ build-linux ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04 ]

steps:
- uses: actions/checkout@v4
- name: install bake
run: |
git clone https://github.com/SanderMertens/bake
make -C bake/build-$(uname)
bake/bake setup
- name: build flecs
run: bake --strict

- name: run tests
run: |
bake run test/script --cfg sanitize -- -j 8
test-sanitized-collections:
needs: [ build-linux ]
runs-on: ${{ matrix.os }}
Expand All @@ -782,7 +825,7 @@ jobs:
run: |
bake run test/collections --cfg sanitize -- -j 8
test-sanitized-cpp_api:
test-sanitized-cpp:
needs: [ build-linux ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
Expand All @@ -804,7 +847,7 @@ jobs:

- name: run tests
run: |
bake run test/cpp_api --cfg sanitize -- -j 8
bake run test/cpp --cfg sanitize -- -j 8
test-cmake:
needs: [ build-linux, build-macos ]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ typedef struct {
} Position, Velocity;

void Move(ecs_iter_t *it) {
Position *p = ecs_field(it, Position, 1);
Velocity *v = ecs_field(it, Velocity, 2);
Position *p = ecs_field(it, Position, 0);
Velocity *v = ecs_field(it, Velocity, 1);

for (int i = 0; i < it->count; i++) {
p[i].x += v[i].x;
Expand All @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) {

ECS_SYSTEM(ecs, Move, EcsOnUpdate, Position, Velocity);

ecs_entity_t e = ecs_new_id(ecs);
ecs_entity_t e = ecs_new(ecs);
ecs_set(ecs, e, Position, {10, 20});
ecs_set(ecs, e, Velocity, {1, 2});

Expand Down Expand Up @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) {
});
auto e = ecs.entity()
.set([](Position& p, Velocity& v) {
.insert([](Position& p, Velocity& v) {
p = {10, 20};
v = {1, 2};
});
Expand Down
2 changes: 1 addition & 1 deletion docs/DesignWithFlecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ There is a misconception that ECS components can only be plain data types, and s
Queries are the primary method in Flecs for finding the entities for a set of components (or more specifically: a component expression). Queries are easy to use, but there a few things to keep in mind.

### Use the right query
Flecs has cached queries and uncached queries. Cached queries (`ecs_query_t` and `flecs::query`) are expensive to create but very cheap to iterate. Uncached queries (`ecs_filter_t`, `flecs::filter`) are fast to create, but more expensive to iterate. If you need to do a quick ad-hoc query for which you couldn't know in advance what you had to query for, an uncached query is the best option. If you have a query that you know in advance and need to iterate many times, a cached query is preferred.
Flecs has cached queries and uncached queries. Cached queries (`ecs_query_cache_t` and `flecs::query`) are expensive to create but very cheap to iterate. Uncached queries (`ecs_query_t`, `flecs::query`) are fast to create, but more expensive to iterate. If you need to do a quick ad-hoc query for which you couldn't know in advance what you had to query for, an uncached query is the best option. If you have a query that you know in advance and need to iterate many times, a cached query is preferred.

Another difference is that uncached queries can be created from systems, while cached queries cannot. If you need a cached query in a system, it has to be created in advance and passed into the system, either by setting it as system context, adding a component to the system with the query, or passing it in the lambda capture list (C++ only). Systems themselves use cached queries.

Expand Down
Loading

0 comments on commit cf1a8ef

Please sign in to comment.