Mercurial > molko
changeset 117:445035ace840
core: fix panic handling early
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 03 Oct 2020 19:03:22 +0200 |
parents | 0a6683615c73 |
children | 3411daa26432 |
files | src/adventure/panic_state.c src/core/game.c src/core/panic.c src/molko/main.c |
diffstat | 4 files changed, 23 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/src/adventure/panic_state.c Sat Oct 03 18:32:01 2020 +0200 +++ b/src/adventure/panic_state.c Sat Oct 03 19:03:22 2020 +0200 @@ -31,14 +31,14 @@ #include <window.h> #include <map_state.h> +#include <assets/fonts/Lato-Regular.h> + #include "panic_state.h" #define BACKGROUND 0x4f5070ff #define FOREGROUND 0xffffffff -#define FONT "fonts/Lato-Regular.ttf" -#define FONT_SZ 16 - +#define SIZE 16 #define PADDING 20 #define OUT "molko-adventure.txt" @@ -222,6 +222,6 @@ * useful information to the screen so as last resort print them * on the console. */ - if (!(font_open(&data.font, sys_datapath(FONT), FONT_SZ))) + if (!(font_openmem(&data.font, Lato_Regular, sizeof (Lato_Regular), SIZE))) die("%s", error()); }
--- a/src/core/game.c Sat Oct 03 18:32:01 2020 +0200 +++ b/src/core/game.c Sat Oct 03 19:03:22 2020 +0200 @@ -88,7 +88,6 @@ game.actions[i].draw(&game.actions[i]); } - void game_switch(struct state *state, bool quick) {
--- a/src/core/panic.c Sat Oct 03 18:32:01 2020 +0200 +++ b/src/core/panic.c Sat Oct 03 19:03:22 2020 +0200 @@ -26,7 +26,7 @@ static noreturn void terminate(void) { - fprintf(stderr, "%s", error()); + fprintf(stderr, "abort: %s", error()); exit(1); }
--- a/src/molko/main.c Sat Oct 03 18:32:01 2020 +0200 +++ b/src/molko/main.c Sat Oct 03 19:03:22 2020 +0200 @@ -17,44 +17,24 @@ */ #include <setjmp.h> -#include <stdio.h> -#include <stdlib.h> #include <stdnoreturn.h> -#include <string.h> -#include <button.h> -#include <checkbox.h> #include <clock.h> -#include <debug.h> -#include <error.h> #include <event.h> -#include <font.h> -#include <frame.h> #include <game.h> -#include <image.h> -#include <inhibit.h> -#include <label.h> -#include <label.h> -#include <map.h> -#include <map_state.h> -#include <message.h> -#include <painter.h> #include <panic.h> -#include <panic_state.h> -#include <script.h> -#include <splashscreen_state.h> -#include <sprite.h> #include <sys.h> #include <theme.h> #include <util.h> -#include <wait.h> #include <window.h> +#include <panic_state.h> +#include <splashscreen_state.h> + #define WINDOW_WIDTH 1280 #define WINDOW_HEIGHT 720 static jmp_buf panic_buf; -static struct font debug_font; static noreturn void unrecoverable(void) @@ -69,13 +49,19 @@ panic(); if (!window_init("Molko's Adventure", WINDOW_WIDTH, WINDOW_HEIGHT)) panic(); - if (!theme_init()) - panic(); + + /* + * From here, we can setup our panic state which requires a window + * to be running. + */ /* Init unrecoverable panic state. */ panic_state_init(); panic_handler = unrecoverable; + if (!theme_init()) + panic(); + /* Default state is splash screen */ game_switch(&splashscreen_state, true); } @@ -84,21 +70,8 @@ run(void) { struct clock clock = { 0 }; - struct frame mainmenu = { - .x = 10, - .y = 10, - .w = 200, - .h = 64 - }; - struct checkbox cb = { - .label = "Play hard mode", - .x = 20, - .y = 20, - .w = 200, - .h = 16 - }; - for (;;) { + while (game.state) { unsigned int elapsed = clock_elapsed(&clock); clock_start(&clock); @@ -108,18 +81,13 @@ case EVENT_QUIT: return; default: - checkbox_handle(&cb, &ev); + game_handle(&ev); break; } } - painter_set_color(0xffffffff); - painter_clear(); - - theme_draw_frame(NULL, &(const struct frame){ .x=10, .y=10, .w=500, .h=500 }); - checkbox_draw(&cb); - - painter_present(); + game_update(elapsed); + game_draw(); if ((elapsed = clock_elapsed(&clock)) < 20) delay(20 - elapsed); @@ -139,12 +107,11 @@ (void)argc; (void)argv; - init(); - - if (setjmp(panic_buf) == 0) + if (setjmp(panic_buf) == 0) { /* Initial game run. */ + init(); run(); - else { + } else { /* Clear event queue to avoid accidental key presses. */ for (union event ev; event_poll(&ev); ) continue;