hibiscus/engine/source/core/engine.d

67 lines
1.6 KiB
D
Raw Normal View History

2023-05-22 20:22:13 +00:00
module hibis.core.engine;
2023-05-20 18:37:04 +00:00
2023-05-22 20:22:13 +00:00
import hibis.graphics.drawable;
import hibis.renderer.renderer;
import hibis.logging.types;
import hibis.callback;
import hibis.node.node;
2023-05-20 21:27:42 +00:00
import std.datetime.stopwatch;
import std.stdio;
import std.format;
2023-05-20 18:37:04 +00:00
class Engine {
2023-05-21 21:20:09 +00:00
this(Renderer renderer, LoggerCallback logger) {
2023-05-20 18:37:04 +00:00
this.renderer = renderer;
2023-05-21 21:20:09 +00:00
this.loggerCallback = logger;
2023-05-20 21:27:42 +00:00
previousProcessTick = 0.00001f;
previousPhysicsProcessTick = 0.00001f;
2023-05-20 18:37:04 +00:00
2023-05-20 21:27:42 +00:00
watch.start();
2023-05-21 21:20:09 +00:00
this.loggerCallback(LoggingSeverity.Information, "Started ge!");
2023-05-20 21:27:42 +00:00
}
2023-05-20 18:37:04 +00:00
2023-05-20 21:27:42 +00:00
~this() {
watch.stop();
}
2023-05-20 18:37:04 +00:00
2023-05-20 21:27:42 +00:00
void runNodeProcesses() {
// TODO: fix delta then adapt for runNodePhysicsProcesses
2023-05-21 20:55:02 +00:00
const float current = watch.peek.total!"msecs" / 1_000;
2023-05-20 21:27:42 +00:00
float delta = (current - previousProcessTick);
2023-05-20 18:37:04 +00:00
foreach (Node* node ; nodeList) {
node.process(delta);
}
2023-05-20 21:27:42 +00:00
this.previousProcessTick = watch.peek.total!"msecs" / 1_000;
2023-05-20 18:37:04 +00:00
}
void runNodePhysicsProcesses() {
// Schade! Have the wrong function content while I figure out how std.datetime.watch works
2023-05-21 20:55:02 +00:00
const float current = watch.peek.total!"msecs" / 1_000;
2023-05-20 21:27:42 +00:00
float delta = (current - previousProcessTick);
foreach (Node* node ; nodeList) {
node.physicsProcess(delta);
}
this.previousPhysicsProcessTick = watch.peek.total!"msecs" / 1_000;
2023-05-20 18:37:04 +00:00
}
2023-05-20 21:27:42 +00:00
void drawNodes() {
foreach (Node* node; nodeList) {
if (Drawable* drawNode = cast(Drawable*) node) {
drawNode.draw(&renderer);
}
}
}
2023-05-20 18:37:04 +00:00
2023-05-20 21:27:42 +00:00
private Renderer renderer;
private StopWatch watch;
private float previousProcessTick;
private float previousPhysicsProcessTick;
2023-05-20 18:37:04 +00:00
private Node*[] nodeList;
2023-05-21 21:20:09 +00:00
private LoggerCallback loggerCallback;
2023-05-20 18:37:04 +00:00
}