This repository has been archived on 2023-12-12. You can view files and clone it, but cannot push or open issues or pull requests.
game-project/source/game.d
Ludovic 'Archivist' Lagouardette fc534fd8e1 Handle rendering of Rigids
2023-10-02 15:03:07 +02:00

79 lines
No EOL
2.7 KiB
D

import std.stdio: writeln;
import std.exception;
import raylib;
import grimoire;
import utils.log;
import std.string : toStringz;
import std.format;
import std.conv : to;
import core.time;
import toki.symbols;
import world.screen;
extern(C) __gshared string[] rt_options = [ "gcopt=initReserve:128 minPoolSize:256 parallel:2 profile:1" ];
int main(string[] args) {
try {
InitWindow(800,600,"Unnamed project");
log(LogLevel.INFOHIGH, "Window Initialized...");
Screen.x = Screen.y = 0;
Screen.width = Screen.px_width = 800;
Screen.height = Screen.px_height = 600;
log(LogLevel.INFOHIGH, "Readying the engine...");
GrEngine engine = new GrEngine();
auto grstd = grLoadStdLibrary();
auto grloglib = getLogLibrary();
engine.addLibrary(grstd);
engine.addLibrary(grloglib);
log(LogLevel.INFOHIGH, "Readying the compiler...");
GrCompiler compiler = new GrCompiler();
compiler.addLibrary(grstd);
compiler.addLibrary(grloglib);
compiler.addFile("./assets/scripts/dummy.gr");
log(LogLevel.INFOHIGH, "Compiling Scripts...");
auto bytecode = compiler.compile(GrOption.symbols);
if(! bytecode) {
throw new Exception(compiler.getError().prettify(GrLocale.en_US));
}
log(LogLevel.INFOHIGH, "Booting Scripts...");
engine.load(bytecode);
log(LogLevel.INFOHIGH, "Go Hot Dog, Go...");
engine.process();
auto reference = MonoTime.currTime();
auto deltaTime = 1f/60f;
while(! WindowShouldClose()) {
if(engine.isPanicking()) {
throw new Exception(engine.panicMessage());
}
log(LogLevel.INFOLOW, format("Frame begin %fs...", deltaTime));
log(LogLevel.INFOLOW, "Processing inputs...");
log(LogLevel.INFOLOW, "Processing coros...");
engine.process();
log(LogLevel.INFOLOW, "Processing changes...");
log(LogLevel.INFOLOW, "Render start...");
BeginDrawing();{
ClearBackground(Colors.WHITE);
DrawFPS(0,0);
auto pos = GetMousePosition();
DrawText(toStringz(format("%f, %f", pos.x, pos.y)), 0, 24, 20, Colors.GREEN);
}EndDrawing();
auto new_reference = MonoTime.currTime();
deltaTime = (new_reference - reference).total!("hnsecs")/10_000_000.0;
reference = new_reference;
}
CloseWindow();
return 0;
}
catch(Exception e) {
log(LogLevel.ERROR, e.msg);
foreach (trace; e.info)
log(LogLevel.ERROR, format("at: %s", trace));
}
return 1;
}