From 5ed96bbb722ab9c48203acc532403c86389f4529 Mon Sep 17 00:00:00 2001 From: tulpenkiste Date: Sun, 21 May 2023 22:20:09 +0100 Subject: [PATCH] Add logging function callback --- engine/source/callback.d | 5 +++++ engine/source/core/engine.d | 7 ++++++- engine/source/logging/types.d | 9 +++++++++ test/source/app.d | 10 +++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 engine/source/callback.d create mode 100644 engine/source/logging/types.d diff --git a/engine/source/callback.d b/engine/source/callback.d new file mode 100644 index 0000000..61ea62f --- /dev/null +++ b/engine/source/callback.d @@ -0,0 +1,5 @@ +module gameengine.callback; + +import gameengine.logging.types; + +alias LoggerCallback = void function(LoggingSeverity severity, string message); \ No newline at end of file diff --git a/engine/source/core/engine.d b/engine/source/core/engine.d index 4267d22..9815cc2 100644 --- a/engine/source/core/engine.d +++ b/engine/source/core/engine.d @@ -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; } \ No newline at end of file diff --git a/engine/source/logging/types.d b/engine/source/logging/types.d new file mode 100644 index 0000000..75e89be --- /dev/null +++ b/engine/source/logging/types.d @@ -0,0 +1,9 @@ +module gameengine.logging.types; + +enum LoggingSeverity { + Message = 0, + Information, + Warning, + Error, + Fatal +} \ No newline at end of file diff --git a/test/source/app.d b/test/source/app.d index 70b9787..64dbc10 100644 --- a/test/source/app.d +++ b/test/source/app.d @@ -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;