module gameengine.core.engine; import gameengine.graphics.drawable; import gameengine.renderer.renderer; import gameengine.logging.types; import gameengine.callback; import gameengine.node.node; import std.datetime.stopwatch; import std.stdio; import std.format; class Engine { this(Renderer renderer, LoggerCallback logger) { this.renderer = renderer; this.loggerCallback = logger; previousProcessTick = 0.00001f; previousPhysicsProcessTick = 0.00001f; watch.start(); this.loggerCallback(LoggingSeverity.Information, "Started ge!"); } ~this() { watch.stop(); } void runNodeProcesses() { // TODO: fix delta then adapt for runNodePhysicsProcesses const float current = watch.peek.total!"msecs" / 1_000; float delta = (current - previousProcessTick); foreach (Node* node ; nodeList) { node.process(delta); } this.previousProcessTick = watch.peek.total!"msecs" / 1_000; } void runNodePhysicsProcesses() { // Schade! const float current = watch.peek.total!"msecs" / 1_000; float delta = (current - previousProcessTick); foreach (Node* node ; nodeList) { node.physicsProcess(delta); } this.previousPhysicsProcessTick = watch.peek.total!"msecs" / 1_000; } void drawNodes() { foreach (Node* node; nodeList) { if (Drawable* drawNode = cast(Drawable*) node) { drawNode.draw(&renderer); } } } private Renderer renderer; private StopWatch watch; private float previousProcessTick; private float previousPhysicsProcessTick; private Node*[] nodeList; private LoggerCallback loggerCallback; }