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..43f3b35c7 --- /dev/null +++ b/src/main/java/com/cleanroommc/kirino/ecs/system/graph/DirectAcyclicGraph.java @@ -0,0 +1,30 @@ +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; + +@SuppressWarnings("UnstableApiUsage") +public class DirectAcyclicGraph { + 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); + } + +} 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() { }