Finish dlang rewrite
This commit is contained in:
parent
ac98291a9c
commit
cf60b9ace5
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -7,6 +7,7 @@
|
||||||
*.a
|
*.a
|
||||||
*.lib
|
*.lib
|
||||||
*-test-*
|
*-test-*
|
||||||
|
*_test
|
||||||
*.exe
|
*.exe
|
||||||
*.pdb
|
*.pdb
|
||||||
*.o
|
*.o
|
||||||
|
|
2
dub.sdl
2
dub.sdl
|
@ -6,5 +6,7 @@ license "LGPL-3.0"
|
||||||
targetType "none"
|
targetType "none"
|
||||||
dependency "gameengine:engine" version="*"
|
dependency "gameengine:engine" version="*"
|
||||||
dependency "gameengine:rsdl" version="*"
|
dependency "gameengine:rsdl" version="*"
|
||||||
|
dependency "gameengine:test" version="*"
|
||||||
subPackage "engine"
|
subPackage "engine"
|
||||||
subPackage "renderer/rsdl"
|
subPackage "renderer/rsdl"
|
||||||
|
subPackage "test"
|
|
@ -1,4 +1,4 @@
|
||||||
name "engine"
|
name "engine"
|
||||||
license "LGPL-3.0"
|
license "LGPL-3.0"
|
||||||
targetType "dynamicLibrary"
|
targetType "library"
|
||||||
targetName "gameengine"
|
targetName "gameengine"
|
|
@ -1,44 +1,64 @@
|
||||||
module gameengine.core.engine;
|
module gameengine.core.engine;
|
||||||
|
|
||||||
import gameengine.renderer;
|
import gameengine.graphics.drawable;
|
||||||
|
import gameengine.renderer.renderer;
|
||||||
import gameengine.node.node;
|
import gameengine.node.node;
|
||||||
import core.time;
|
import std.datetime.stopwatch;
|
||||||
|
|
||||||
|
import std.stdio;
|
||||||
|
import std.format;
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
this(IRenderer* renderer) {
|
this(Renderer renderer) {
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
previousProcessTick = MonoTime.currTime();
|
previousProcessTick = 0.00001f;
|
||||||
previousPhysicsProcessTick = MonoTime.currTime();
|
previousPhysicsProcessTick = 0.00001f;
|
||||||
|
|
||||||
|
watch.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
~this() {
|
||||||
|
watch.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void runNodeProcesses() {
|
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) {
|
foreach (Node* node ; nodeList) {
|
||||||
node.process(delta);
|
node.process(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.previousProcessTick = MonoTime.currTime();
|
this.previousProcessTick = watch.peek.total!"msecs" / 1_000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void runNodePhysicsProcesses() {
|
void runNodePhysicsProcesses() {
|
||||||
// Schade!
|
// Schade!
|
||||||
this.previousPhysicsProcessTick = MonoTime.currTime();
|
float current = watch.peek.total!"msecs" / 1_000;
|
||||||
|
float delta = (current - previousProcessTick);
|
||||||
|
|
||||||
|
foreach (Node* node ; nodeList) {
|
||||||
|
node.physicsProcess(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawNodes() {}
|
this.previousPhysicsProcessTick = watch.peek.total!"msecs" / 1_000;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawNodes() {
|
||||||
|
foreach (Node* node; nodeList) {
|
||||||
|
if (Drawable* drawNode = cast(Drawable*) node) {
|
||||||
|
drawNode.draw(&renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string engineVersion() const { return "0.0.0"; }
|
string engineVersion() const { return "0.0.0"; }
|
||||||
|
|
||||||
private IRenderer* renderer;
|
private Renderer renderer;
|
||||||
private MonoTime previousProcessTick;
|
private StopWatch watch;
|
||||||
private MonoTime previousPhysicsProcessTick;
|
private float previousProcessTick;
|
||||||
|
private float previousPhysicsProcessTick;
|
||||||
|
|
||||||
private Node*[] nodeList;
|
private Node*[] nodeList;
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
module gameengine.graphics.drawable;
|
module gameengine.graphics.drawable;
|
||||||
import gameengine.renderer;
|
import gameengine.renderer.renderer;
|
||||||
|
|
||||||
abstract class Drawable {
|
abstract class Drawable {
|
||||||
abstract void draw(IRenderer* renderer);
|
abstract void draw(Renderer* renderer);
|
||||||
}
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
module gameengine.renderer;
|
|
||||||
|
|
||||||
interface IRenderer {
|
|
||||||
void setWindowTitle(string str);
|
|
||||||
}
|
|
5
engine/source/renderer/renderer.d
Normal file
5
engine/source/renderer/renderer.d
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module gameengine.renderer.renderer;
|
||||||
|
|
||||||
|
abstract class Renderer {
|
||||||
|
void setWindowTitle(string str);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
name "rsdl"
|
name "rsdl"
|
||||||
dependency "gameengine:engine" version=">=0.0.0"
|
dependency "gameengine:engine" version=">=0.0.0"
|
||||||
dependency "bindbc-sdl" version="~>1.3.5"
|
dependency "bindbc-sdl" version="~>1.3.5"
|
||||||
targetType "dynamicLibrary"
|
targetType "library"
|
||||||
targetName "gameengine_rsdl"
|
targetName "gameengine_rsdl"
|
||||||
sourcePaths "./" "../../engine/source"
|
sourcePaths "./" "../../engine/source"
|
||||||
|
|
7
renderer/rsdl/source/gameengine_rsdl/package.d
Normal file
7
renderer/rsdl/source/gameengine_rsdl/package.d
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
module gameengine_rsdl;
|
||||||
|
|
||||||
|
import gameengine.renderer.renderer;
|
||||||
|
|
||||||
|
class RSDL : Renderer {
|
||||||
|
override void setWindowTitle(string title) {}
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
module gameengine.renderer.sdl;
|
|
||||||
|
|
||||||
import gameengine.renderer;
|
|
||||||
|
|
||||||
class RSDL : IRenderer {
|
|
||||||
|
|
||||||
}
|
|
16
test/.gitignore
vendored
Normal file
16
test/.gitignore
vendored
Normal file
|
@ -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
|
9
test/dub.sdl
Normal file
9
test/dub.sdl
Normal file
|
@ -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"
|
17
test/source/app.d
Normal file
17
test/source/app.d
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue