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.graphics.drawable;
|
||||||
import gameengine.renderer.renderer;
|
import gameengine.renderer.renderer;
|
||||||
|
import gameengine.logging.types;
|
||||||
|
import gameengine.callback;
|
||||||
import gameengine.node.node;
|
import gameengine.node.node;
|
||||||
import std.datetime.stopwatch;
|
import std.datetime.stopwatch;
|
||||||
|
|
||||||
|
@ -9,12 +11,14 @@ import std.stdio;
|
||||||
import std.format;
|
import std.format;
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
this(Renderer renderer) {
|
this(Renderer renderer, LoggerCallback logger) {
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
this.loggerCallback = logger;
|
||||||
previousProcessTick = 0.00001f;
|
previousProcessTick = 0.00001f;
|
||||||
previousPhysicsProcessTick = 0.00001f;
|
previousPhysicsProcessTick = 0.00001f;
|
||||||
|
|
||||||
watch.start();
|
watch.start();
|
||||||
|
this.loggerCallback(LoggingSeverity.Information, "Started ge!");
|
||||||
}
|
}
|
||||||
|
|
||||||
~this() {
|
~this() {
|
||||||
|
@ -59,4 +63,5 @@ class Engine {
|
||||||
private float previousPhysicsProcessTick;
|
private float previousPhysicsProcessTick;
|
||||||
|
|
||||||
private Node*[] nodeList;
|
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.stdio;
|
||||||
|
import std.format;
|
||||||
|
import std.conv;
|
||||||
|
|
||||||
import gameengine.core.engine;
|
import gameengine.core.engine;
|
||||||
import gameengine.math.types;
|
import gameengine.math.types;
|
||||||
import gameengine.renderer.renderer;
|
import gameengine.renderer.renderer;
|
||||||
|
import gameengine.logging.types;
|
||||||
|
import gameengine.callback;
|
||||||
import gameengine_rsdl;
|
import gameengine_rsdl;
|
||||||
|
|
||||||
import core.thread;
|
import core.thread;
|
||||||
|
|
||||||
|
void logger(LoggingSeverity severity, string message) {
|
||||||
|
writeln(format("[%s]: %s", to!string(severity), message));
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
Renderer renderer = new RSDL("test", IntVec2(800, 600));
|
Renderer renderer = new RSDL("test", IntVec2(800, 600));
|
||||||
Engine engine = new Engine(renderer);
|
Engine engine = new Engine(renderer, &logger);
|
||||||
|
|
||||||
ubyte red = 0;
|
ubyte red = 0;
|
||||||
bool increase = true;
|
bool increase = true;
|
||||||
|
|
Loading…
Reference in a new issue