67 lines
1.6 KiB
D
67 lines
1.6 KiB
D
module hibis.core.engine;
|
|
|
|
import hibis.graphics.drawable;
|
|
import hibis.renderer.renderer;
|
|
import hibis.logging.types;
|
|
import hibis.callback;
|
|
import hibis.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 Hibis!");
|
|
}
|
|
|
|
~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! Have the wrong function content while I figure out how std.datetime.watch works
|
|
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;
|
|
} |