diff options
| -rw-r--r-- | Makefile | 6 | ||||
| -rwxr-xr-x | build.sh | 14 | ||||
| -rw-r--r-- | src/engine.c | 40 |
3 files changed, 58 insertions, 2 deletions
@@ -59,6 +59,12 @@ $(OBJDIR)/kontile.o: $(SRCDIR)/impl/kontile.c $(KONDIR)/kontile.h $(KONDIR)/kons $(OBJDIR)/konassets.o: $(SRCDIR)/impl/konassets.c $(KONDIR)/konassets.h $(KONDIR)/konpack.h $(KONDIR)/konsofren.h $(EXTDIR)/*.h $(COMPILE) $(SRCDIR)/impl/konassets.c -o $@ +$(OBJDIR)/konui.o: $(SRCDIR)/impl/konui.c $(KONDIR)/konui.h $(KONDIR)/konfont.h $(KONDIR)/konsofren.h $(KONDIR)/konwinlib.h + $(COMPILE) $(SRCDIR)/impl/konui.c -o $@ + +$(OBJDIR)/kondebug.o: $(SRCDIR)/impl/kondebug.c $(KONDIR)/kondebug.h $(KONDIR)/konassets.h $(KONDIR)/konfont.h $(KONDIR)/konsofren.h $(KONDIR)/kontime.h + $(COMPILE) $(SRCDIR)/impl/kondebug.c -o $@ + $(OBJDIR)/konaudio.o: $(SRCDIR)/impl/konaudio.c $(KONDIR)/konaudio.h $(KONDIR)/konassets.h $(EXTDIR)/miniaudio.h $(COMPILE) $(SRCDIR)/impl/konaudio.c -o $@ @@ -12,7 +12,7 @@ developer=0 usage() { echo "usage: build.sh [-d] [-D] [-p platform] [-m module,...] [-o objdir] [target ...]" - echo "modules: font toml tile pack assets image audio" + echo "modules: font toml tile pack ui debug assets image audio" echo "platforms: native linux bsd windows" echo "targets: all run clean tools pack" exit 1 @@ -77,7 +77,7 @@ addobj() for m in $modules; do DEFS="$DEFS -DKON_MODULE_$(echo "$m" | tr 'a-z' 'A-Z')" case $m in - font|toml|tile|pack) addobj "kon$m" ;; + font|toml|tile|pack|ui|debug) addobj "kon$m" ;; assets) addobj konassets ;; image) addobj stb_image ;; audio) @@ -95,6 +95,16 @@ done case " $modules " in *" assets "*) addobj konpack ;; esac +case " $modules " in +*" ui "*) addobj konfont ;; +esac +case " $modules " in +*" debug "*) addobj konfont; addobj konassets; addobj konpack ;; +esac + +case " $modules " in +*" debug "*) [ $developer = 1 ] || echo "note: debug module does nothing without -d or -D" ;; +esac OBJDIR=$objdir export CC EXE LDLIBS MODEFLAGS DEFS OBJDIR MODOBJS 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(); |
