diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2026-01-31 13:08:16 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2026-01-31 15:37:21 -0800 |
| commit | d8b40e4240fb7f8c62fcd60c567ab386024741d3 (patch) | |
| tree | b1028192a41f417820c9240cad1d12dd4c39f312 /core/src/test | |
| parent | 2e3d0963650d5f01163ffca1049a9886aa7489fa (diff) | |
| download | the-abstraction-engine-v2-d8b40e4240fb7f8c62fcd60c567ab386024741d3.tar.gz the-abstraction-engine-v2-d8b40e4240fb7f8c62fcd60c567ab386024741d3.zip | |
A sokoban inspired grid push demo
Diffstat (limited to 'core/src/test')
| -rw-r--r-- | core/src/test/java/coffee/liz/ecs/DAGWorldTest.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/core/src/test/java/coffee/liz/ecs/DAGWorldTest.java b/core/src/test/java/coffee/liz/ecs/DAGWorldTest.java index 2f948d0..a656d28 100644 --- a/core/src/test/java/coffee/liz/ecs/DAGWorldTest.java +++ b/core/src/test/java/coffee/liz/ecs/DAGWorldTest.java @@ -80,6 +80,24 @@ final class DAGWorldTest { } @Test + public void queryFindsComponentsAddedByEarlierSystemInSameTick() { + final List<Set<Entity>> queryResults = new CopyOnWriteArrayList<>(); + + final Map<Class<? extends System<String>>, System<String>> systems = new LinkedHashMap<>(); + systems.put(ComponentAdderSystem.class, new ComponentAdderSystem()); + systems.put(ComponentReaderSystem.class, new ComponentReaderSystem(queryResults)); + final DAGWorld<String> world = new DAGWorld<>(systems); + + final Entity entity = world.createEntity(); + entity.add(new PositionComponent()); + + world.update("state", Duration.ZERO); + + assertEquals(1, queryResults.size()); + assertEquals(Set.of(entity), queryResults.getFirst()); + } + + @Test public void circularDependencyDetectionThrowsIllegalStateException() { final Map<Class<? extends System<String>>, System<String>> systems = new LinkedHashMap<>(); final SystemCycleA systemA = new SystemCycleA(); @@ -161,4 +179,31 @@ final class DAGWorldTest { public void update(final World<String> world, final String state, final Duration duration) { } } + + private static final class ComponentAdderSystem implements System<String> { + @Override + public Collection<Class<? extends System<String>>> getDependencies() { + return List.of(); + } + + @Override + public void update(final World<String> world, final String state, final Duration duration) { + world.query(Set.of(PositionComponent.class)).forEach(e -> e.add(new VelocityComponent())); + } + } + + @RequiredArgsConstructor + private static final class ComponentReaderSystem implements System<String> { + private final List<Set<Entity>> queryResults; + + @Override + public Collection<Class<? extends System<String>>> getDependencies() { + return Set.of(ComponentAdderSystem.class); + } + + @Override + public void update(final World<String> world, final String state, final Duration duration) { + queryResults.add(world.query(Set.of(VelocityComponent.class, PositionComponent.class))); + } + } } |
