64 lines
1.3 KiB
D
64 lines
1.3 KiB
D
module gameengine.core.engine;
|
|
|
|
import gameengine.graphics.drawable;
|
|
import gameengine.renderer.renderer;
|
|
import gameengine.node.node;
|
|
import std.datetime.stopwatch;
|
|
|
|
import std.stdio;
|
|
import std.format;
|
|
|
|
class Engine {
|
|
this(Renderer renderer) {
|
|
this.renderer = renderer;
|
|
previousProcessTick = 0.00001f;
|
|
previousPhysicsProcessTick = 0.00001f;
|
|
|
|
watch.start();
|
|
}
|
|
|
|
~this() {
|
|
watch.stop();
|
|
}
|
|
|
|
void runNodeProcesses() {
|
|
// TODO: fix delta then adapt for runNodePhysicsProcesses
|
|
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!
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
string engineVersion() const { return "0.0.0"; }
|
|
|
|
private Renderer renderer;
|
|
private StopWatch watch;
|
|
private float previousProcessTick;
|
|
private float previousPhysicsProcessTick;
|
|
|
|
private Node*[] nodeList;
|
|
} |