diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-02-28 14:08:49 -0800 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-02-28 14:08:49 -0800 |
| commit | 8412efda977c1c76885eae1d0b4a721cf71162f2 (patch) | |
| tree | 4ff20bc346fd24aeb5881ea06855d7bea5f5d162 /core/src/main/java/coffee/liz/dyl | |
| parent | 87c8a1e15e399d29f42b41a4ccb66a84c5f6bb9a (diff) | |
| download | dyl-8412efda977c1c76885eae1d0b4a721cf71162f2.tar.gz dyl-8412efda977c1c76885eae1d0b4a721cf71162f2.zip | |
Upgrading JDK and adding Observable interface
Diffstat (limited to 'core/src/main/java/coffee/liz/dyl')
3 files changed, 51 insertions, 2 deletions
diff --git a/core/src/main/java/coffee/liz/dyl/components/StressComponent.java b/core/src/main/java/coffee/liz/dyl/components/StressComponent.java new file mode 100644 index 0000000..f22dfaa --- /dev/null +++ b/core/src/main/java/coffee/liz/dyl/components/StressComponent.java @@ -0,0 +1,16 @@ +package coffee.liz.dyl.components; + +import coffee.liz.ecs.model.Component; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; + +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +@RequiredArgsConstructor +public class StressComponent implements Component { + private final String componentData; + public StressComponent() { + componentData = IntStream.range(0, 10).mapToObj(Integer::toString).collect(Collectors.joining()); + } +} diff --git a/core/src/main/java/coffee/liz/dyl/systems/StressSystem.java b/core/src/main/java/coffee/liz/dyl/systems/StressSystem.java new file mode 100644 index 0000000..850a9f3 --- /dev/null +++ b/core/src/main/java/coffee/liz/dyl/systems/StressSystem.java @@ -0,0 +1,31 @@ +package coffee.liz.dyl.systems; + +import coffee.liz.dyl.FrameState; +import coffee.liz.dyl.components.StressComponent; +import coffee.liz.dyl.components.Velocity; +import coffee.liz.ecs.math.Vec2f; +import coffee.liz.ecs.model.System; +import coffee.liz.ecs.model.World; + +import java.util.Collection; +import java.util.List; + +public class StressSystem implements System<FrameState> { + + @Override + public Collection<Class<? extends System<FrameState>>> getDependencies() { + return List.of(); + } + + @Override + public void update(World<FrameState> world, FrameState state, float deltaSeconds) { + world.queryable().allOf().forEach(e -> { + if (Math.random() > 0.5) { + e.add(new StressComponent()); + e.add(new Velocity(new Vec2f(0.5f - (float) Math.random(), 0.5f - (float) Math.random()))); + } else if (e.has(StressComponent.class)){ + e.remove(StressComponent.class); + } + }); + } +} diff --git a/core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java b/core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java index c3e1c2d..475694e 100644 --- a/core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java +++ b/core/src/main/java/coffee/liz/dyl/world/DylGameWorld.java @@ -7,6 +7,7 @@ import coffee.liz.dyl.entities.PlayerFactory; import coffee.liz.dyl.systems.InputSystem; import coffee.liz.dyl.systems.IntegrationSystem; import coffee.liz.dyl.systems.RenderSystem; +import coffee.liz.dyl.systems.StressSystem; import coffee.liz.ecs.DAGWorld; import coffee.liz.ecs.math.Vec2f; import coffee.liz.ecs.math.Vec2i; @@ -16,9 +17,10 @@ public class DylGameWorld extends DAGWorld<FrameState> { super( new InputSystem(), new IntegrationSystem(), - new RenderSystem(game.getBatch(), game.getViewport()) + new RenderSystem(game.getBatch(), game.getViewport()), + new StressSystem() ); - for (int i = 0; i < 8000; i++) { + for (int i = 0; i < 16_000; i++) { PlayerFactory.addTo(this) .add(new BoundingBox(new Vec2f(i / 200f, i/ 200f), new Vec2i(1, 1), 1)); } |
