Add logging function callback
This commit is contained in:
parent
982321ee38
commit
5ed96bbb72
5
engine/source/callback.d
Normal file
5
engine/source/callback.d
Normal file
|
@ -0,0 +1,5 @@
|
|||
module gameengine.callback;
|
||||
|
||||
import gameengine.logging.types;
|
||||
|
||||
alias LoggerCallback = void function(LoggingSeverity severity, string message);
|
|
@ -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;
|
||||
}
|
9
engine/source/logging/types.d
Normal file
9
engine/source/logging/types.d
Normal file
|
@ -0,0 +1,9 @@
|
|||
module gameengine.logging.types;
|
||||
|
||||
enum LoggingSeverity {
|
||||
Message = 0,
|
||||
Information,
|
||||
Warning,
|
||||
Error,
|
||||
Fatal
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue