summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/engine.c b/src/engine.c
index 92fdf0f..5788fb5 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -2,6 +2,12 @@
#include "konsofren.h"
#include "kontime.h"
+#ifdef KON_MODULE_DEBUG
+#include "konassets.h"
+#include "konfont.h"
+#include "kondebug.h"
+#endif
+
#define GAME_WIDTH 320
#define GAME_HEIGHT 180
@@ -13,6 +19,11 @@ typedef struct app {
kon_light_t light;
kon_time last;
float angle;
+#ifdef KON_MODULE_DEBUG
+ kon_assets_t *assets;
+ kon_font_t *font;
+ kon_debug_t *debug;
+#endif
} app_t;
static void frame(void *data)
@@ -24,6 +35,9 @@ static void frame(void *data)
kon_mat4_t model, viewProjection;
while (kon_pollEvent(app->window, &ev)) {
+#ifdef KON_MODULE_DEBUG
+ if (kon_debugFeedEvent(app->debug, &ev)) continue;
+#endif
if (ev.type == KON_EVENT_RESIZE) {
kon_resizeDisplay(display, ev.width, ev.height);
}
@@ -45,6 +59,10 @@ static void frame(void *data)
kon_drawMesh(display->game, viewProjection, model, &kon_cubeMesh, &app->material, &app->light, KON_RENDER_DEFAULT);
kon_presentDisplay(display);
+#ifdef KON_MODULE_DEBUG
+ kon_debugFrame(app->debug);
+ kon_debugDraw(app->debug, display->screen);
+#endif
kon_blitPixels(app->window, display->screen->data, display->screen->width, display->screen->height);
kon_sleep(0.008);
}
@@ -57,7 +75,11 @@ int main(void)
app.window = kon_createWindow("engine", 0, 0, 800, 600, KON_WINDOW_CENTER | KON_WINDOW_RESIZABLE);
if (!app.window) return 1;
+#ifdef KON_DEVELOPER
+ kon_setExitKey(app.window, KON_KEY_F10);
+#else
kon_setExitKey(app.window, KON_KEY_ESCAPE);
+#endif
app.display = kon_createDisplay(GAME_WIDTH, GAME_HEIGHT, 800, 600);
if (!app.display) return 1;
@@ -68,8 +90,26 @@ int main(void)
app.light = kon_lightDefault();
app.last = kon_getTime();
+#ifdef KON_MODULE_DEBUG
+ app.assets = kon_assetsCreate(NULL, "assets");
+ {
+ kon_blob_t *ttf = kon_assetBlob(app.assets, "font.ttf");
+
+ if (ttf) app.font = kon_loadFont(ttf->data, ttf->size, 14.0f);
+ app.debug = kon_debugCreate(app.font);
+ kon_debugSetAssets(app.debug, app.assets);
+ kon_debugLog(app.debug, ttf ? "loaded font.ttf" : "put a font.ttf in assets/ for the console");
+ }
+#endif
+
kon_runMainLoop(app.window, frame, &app);
+#ifdef KON_MODULE_DEBUG
+ kon_debugDestroy(app.debug);
+ kon_freeFont(app.font);
+ kon_assetsDestroy(app.assets);
+#endif
+
kon_freeDisplay(app.display);
kon_destroyWindow(app.window);
kon_deinit();