From cddd4643cd0274f3c49c9334c3bec472932eea13 Mon Sep 17 00:00:00 2001 From: d3f0k0 Date: Wed, 15 Oct 2025 12:57:59 +0700 Subject: [PATCH 1/2] Starting on Direct Acyclic Graph --- .../ecs/system/graph/DirectAcyclicGraph.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java diff --git a/src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java new file mode 100644 index 000000000..53440dfe7 --- /dev/null +++ b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java @@ -0,0 +1,35 @@ +package com.cleanroommc.kirino.ecs.system.graph; + +import com.google.common.graph.MutableNetwork; +import com.google.common.graph.NetworkBuilder; +import com.google.common.graph.Traverser; + +// I know, its beta after all +@SuppressWarnings("UnstableApiUsage") +public class DirectAcyclicGraph { + private final MutableNetwork graph; + + public DirectAcyclicGraph() { + this.graph = NetworkBuilder.directed() + .allowsSelfLoops(false) + .allowsParallelEdges(true) + .build(); + } + public void addEdge(Node from, Node to, Edge edge) { + Traverser.forGraph(graph.asGraph()).breadthFirst(to).forEach((node) -> { + if (node == from) { + throw new IllegalArgumentException("Connecting node" + from + "to" + to + "create a cycle!"); + } + }); + graph.addEdge(from, to, edge); + } + + public void addNode(Node node) { + graph.addNode(node); + } + + public void execute() { + + } + +} From 3afe1abcbdd2b9422119c9114739512f420c8353 Mon Sep 17 00:00:00 2001 From: d3f0k0 Date: Wed, 15 Oct 2025 17:12:37 +0700 Subject: [PATCH 2/2] SystemExeGraph extends DAG with execute impl --- .../kirino/ecs/system/graph/DirectAcyclicGraph.java | 7 +------ .../com/cleanroommc/kirino/ecs/system/graph/Edge.java | 3 +++ .../kirino/ecs/system/graph/SystemExeGraph.java | 10 +++++++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java index 53440dfe7..43f3b35c7 100644 --- a/src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java +++ b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java @@ -4,10 +4,9 @@ import com.google.common.graph.NetworkBuilder; import com.google.common.graph.Traverser; -// I know, its beta after all @SuppressWarnings("UnstableApiUsage") public class DirectAcyclicGraph { - private final MutableNetwork graph; + final MutableNetwork graph; public DirectAcyclicGraph() { this.graph = NetworkBuilder.directed() @@ -28,8 +27,4 @@ public void addNode(Node node) { graph.addNode(node); } - public void execute() { - - } - } diff --git a/src/main/java/com/cleanroommc/kirino/ecs/system/graph/Edge.java b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/Edge.java index 77c7fb029..6bfcdf743 100644 --- a/src/main/java/com/cleanroommc/kirino/ecs/system/graph/Edge.java +++ b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/Edge.java @@ -1,4 +1,7 @@ package com.cleanroommc.kirino.ecs.system.graph; public class Edge { + public void function() { + + } } diff --git a/src/main/java/com/cleanroommc/kirino/ecs/system/graph/SystemExeGraph.java b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/SystemExeGraph.java index 13309d758..7b17fbb05 100644 --- a/src/main/java/com/cleanroommc/kirino/ecs/system/graph/SystemExeGraph.java +++ b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/SystemExeGraph.java @@ -1,6 +1,14 @@ package com.cleanroommc.kirino.ecs.system.graph; -public class SystemExeGraph { +import com.cleanroommc.kirino.ecs.job.JobScheduler; +import com.google.common.graph.Traverser; + +public class SystemExeGraph extends DirectAcyclicGraph { + + public SystemExeGraph() { + super(); + } + public void execute() { }