diff --git a/.gitignore b/.gitignore index 9bf26cb..a638545 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.a *.lib *-test-* +*_test *.exe *.pdb *.o diff --git a/dub.sdl b/dub.sdl index d9c2fa6..85ad1af 100644 --- a/dub.sdl +++ b/dub.sdl @@ -6,5 +6,7 @@ license "LGPL-3.0" targetType "none" dependency "gameengine:engine" version="*" dependency "gameengine:rsdl" version="*" +dependency "gameengine:test" version="*" subPackage "engine" -subPackage "renderer/rsdl" \ No newline at end of file +subPackage "renderer/rsdl" +subPackage "test" \ No newline at end of file diff --git a/engine/dub.sdl b/engine/dub.sdl index a205d97..785a1fd 100644 --- a/engine/dub.sdl +++ b/engine/dub.sdl @@ -1,4 +1,4 @@ name "engine" license "LGPL-3.0" -targetType "dynamicLibrary" +targetType "library" targetName "gameengine" \ No newline at end of file diff --git a/engine/source/core/engine.d b/engine/source/core/engine.d index ff834d6..8c04ac3 100644 --- a/engine/source/core/engine.d +++ b/engine/source/core/engine.d @@ -1,44 +1,64 @@ module gameengine.core.engine; -import gameengine.renderer; +import gameengine.graphics.drawable; +import gameengine.renderer.renderer; import gameengine.node.node; -import core.time; +import std.datetime.stopwatch; + +import std.stdio; +import std.format; class Engine { - this(IRenderer* renderer) { + this(Renderer renderer) { this.renderer = renderer; - previousProcessTick = MonoTime.currTime(); - previousPhysicsProcessTick = MonoTime.currTime(); + previousProcessTick = 0.00001f; + previousPhysicsProcessTick = 0.00001f; + + watch.start(); + } + + ~this() { + watch.stop(); } void runNodeProcesses() { - MonoTime currentTime = MonoTime.currTime(); + // TODO: fix delta then adapt for runNodePhysicsProcesses + float current = watch.peek.total!"msecs" / 1_000; + float delta = (current - previousProcessTick); - Duration difference = currentTime - previousProcessTick; - - float delta = difference.total!"hnsecs" / 10_000_000.0; - - // Temp - debug { import std.stdio : writeln; import std.format; try { writeln(format("%f", delta)); } catch (Exception) {} } foreach (Node* node ; nodeList) { node.process(delta); } - this.previousProcessTick = MonoTime.currTime(); + this.previousProcessTick = watch.peek.total!"msecs" / 1_000; } void runNodePhysicsProcesses() { // Schade! - this.previousPhysicsProcessTick = MonoTime.currTime(); + float current = watch.peek.total!"msecs" / 1_000; + float delta = (current - previousProcessTick); + + foreach (Node* node ; nodeList) { + node.physicsProcess(delta); + } + + this.previousPhysicsProcessTick = watch.peek.total!"msecs" / 1_000; } - void drawNodes() {} + void drawNodes() { + foreach (Node* node; nodeList) { + if (Drawable* drawNode = cast(Drawable*) node) { + drawNode.draw(&renderer); + } + } + } string engineVersion() const { return "0.0.0"; } - private IRenderer* renderer; - private MonoTime previousProcessTick; - private MonoTime previousPhysicsProcessTick; + private Renderer renderer; + private StopWatch watch; + private float previousProcessTick; + private float previousPhysicsProcessTick; private Node*[] nodeList; } \ No newline at end of file diff --git a/engine/source/graphics/drawable.d b/engine/source/graphics/drawable.d index fdb60e3..6f4ff5b 100644 --- a/engine/source/graphics/drawable.d +++ b/engine/source/graphics/drawable.d @@ -1,6 +1,6 @@ module gameengine.graphics.drawable; -import gameengine.renderer; +import gameengine.renderer.renderer; abstract class Drawable { - abstract void draw(IRenderer* renderer); + abstract void draw(Renderer* renderer); } \ No newline at end of file diff --git a/engine/source/renderer.d b/engine/source/renderer.d deleted file mode 100644 index 3624e05..0000000 --- a/engine/source/renderer.d +++ /dev/null @@ -1,5 +0,0 @@ -module gameengine.renderer; - -interface IRenderer { - void setWindowTitle(string str); -} \ No newline at end of file diff --git a/engine/source/renderer/renderer.d b/engine/source/renderer/renderer.d new file mode 100644 index 0000000..d0efe06 --- /dev/null +++ b/engine/source/renderer/renderer.d @@ -0,0 +1,5 @@ +module gameengine.renderer.renderer; + +abstract class Renderer { + void setWindowTitle(string str); +} \ No newline at end of file diff --git a/renderer/rsdl/dub.sdl b/renderer/rsdl/dub.sdl index 2700496..ef193a0 100644 --- a/renderer/rsdl/dub.sdl +++ b/renderer/rsdl/dub.sdl @@ -1,6 +1,6 @@ name "rsdl" dependency "gameengine:engine" version=">=0.0.0" dependency "bindbc-sdl" version="~>1.3.5" -targetType "dynamicLibrary" +targetType "library" targetName "gameengine_rsdl" sourcePaths "./" "../../engine/source" diff --git a/renderer/rsdl/source/gameengine_rsdl/package.d b/renderer/rsdl/source/gameengine_rsdl/package.d new file mode 100644 index 0000000..5dd1e9a --- /dev/null +++ b/renderer/rsdl/source/gameengine_rsdl/package.d @@ -0,0 +1,7 @@ +module gameengine_rsdl; + +import gameengine.renderer.renderer; + +class RSDL : Renderer { + override void setWindowTitle(string title) {} +} \ No newline at end of file diff --git a/renderer/rsdl/source/rsdl.d b/renderer/rsdl/source/rsdl.d deleted file mode 100644 index 43d1634..0000000 --- a/renderer/rsdl/source/rsdl.d +++ /dev/null @@ -1,7 +0,0 @@ -module gameengine.renderer.sdl; - -import gameengine.renderer; - -class RSDL : IRenderer { - -} \ No newline at end of file diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..8397f9a --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,16 @@ +.dub +docs.json +__dummy.html +docs/ +/test +test.so +test.dylib +test.dll +test.a +test.lib +test-test-* +*.exe +*.pdb +*.o +*.obj +*.lst diff --git a/test/dub.sdl b/test/dub.sdl new file mode 100644 index 0000000..e17d96b --- /dev/null +++ b/test/dub.sdl @@ -0,0 +1,9 @@ +name "test" +description "Test of the game engine" +authors "Tulpenkiste" +copyright "Copyright © 2023, Tulpenkiste" +license "GPL-3.0" +targetType "executable" +dependency "gameengine:engine" version="*" +dependency "gameengine:rsdl" version="*" +sourcePaths "./" "../engine/source" "../../renderer/rsdl/source" \ No newline at end of file diff --git a/test/source/app.d b/test/source/app.d new file mode 100644 index 0000000..c2713a8 --- /dev/null +++ b/test/source/app.d @@ -0,0 +1,17 @@ +import std.stdio; + +import gameengine.core.engine; +import gameengine.renderer.renderer; +import gameengine_rsdl; + +import core.thread; + +void main() { + Renderer renderer = new RSDL(); + Engine engine = new Engine(renderer); + + while (true) { + engine.runNodeProcesses(); + Thread.sleep(1.msecs); + } +}