Add logging function callback

This commit is contained in:
Tulpen 2023-05-21 22:20:09 +01:00
parent 982321ee38
commit 5ed96bbb72
4 changed files with 29 additions and 2 deletions

5
engine/source/callback.d Normal file
View file

@ -0,0 +1,5 @@
module gameengine.callback;
import gameengine.logging.types;
alias LoggerCallback = void function(LoggingSeverity severity, string message);

View file

@ -2,6 +2,8 @@ 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;
@ -9,12 +11,14 @@ import std.stdio;
import std.format;
class Engine {
this(Renderer renderer) {
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() {
@ -59,4 +63,5 @@ class Engine {
private float previousPhysicsProcessTick;
private Node*[] nodeList;
private LoggerCallback loggerCallback;
}

View file

@ -0,0 +1,9 @@
module gameengine.logging.types;
enum LoggingSeverity {
Message = 0,
Information,
Warning,
Error,
Fatal
}

View file

@ -1,15 +1,23 @@
import std.stdio;
import std.format;
import std.conv;
import gameengine.core.engine;
import gameengine.math.types;
import gameengine.renderer.renderer;
import gameengine.logging.types;
import gameengine.callback;
import gameengine_rsdl;
import core.thread;
void logger(LoggingSeverity severity, string message) {
writeln(format("[%s]: %s", to!string(severity), message));
}
void main() {
Renderer renderer = new RSDL("test", IntVec2(800, 600));
Engine engine = new Engine(renderer);
Engine engine = new Engine(renderer, &logger);
ubyte red = 0;
bool increase = true;