diff molko/main.c @ 197:852d0b7817ce

rpg: map, extreme cleanup, closes #2508 @4h
author David Demelier <markand@malikania.fr>
date Mon, 09 Nov 2020 10:37:36 +0100
parents 629f55f3961e
children
line wrap: on
line diff
--- a/molko/main.c	Mon Nov 09 10:36:39 2020 +0100
+++ b/molko/main.c	Mon Nov 09 10:37:36 2020 +0100
@@ -16,105 +16,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <setjmp.h>
-#include <stdnoreturn.h>
-
-#include <core/clock.h>
-#include <core/core.h>
-#include <core/event.h>
-#include <core/game.h>
-#include <core/panic.h>
-#include <core/state.h>
-#include <core/sys.h>
-#include <core/util.h>
-#include <core/window.h>
-
-#include <ui/theme.h>
-#include <ui/ui.h>
-
-#include <rpg/rpg.h>
-
-#include <adventure/state/panic.h>
-#include <adventure/state/splashscreen.h>
-#include <adventure/state/mainmenu.h>
-
-#define WINDOW_WIDTH 1280
-#define WINDOW_HEIGHT 720
-
-static struct {
-	struct state splash;
-	struct state mainmenu;
-	struct state panic;
-} states;
-
-static jmp_buf panic_buf;
-
-static noreturn void
-unrecoverable(void)
-{
-	longjmp(panic_buf, 1);
-}
-
-static void
-init(void)
-{
-	if (!core_init() || !ui_init() || !rpg_init())
-		panic();
-	if (!window_open("Molko's Adventure", WINDOW_WIDTH, WINDOW_HEIGHT))
-		panic();
-
-	/*
-	 * From here, we can setup our panic state which requires a window
-	 * to be running.
-	 */
-
-	/* Init unrecoverable panic state. */
-	panic_state(&states.panic);
-	panic_handler = unrecoverable;
-
-	/* Init states. */
-	splashscreen_state(&states.splash, &states.mainmenu);
-	mainmenu_state(&states.mainmenu);
-
-	game_switch(&states.splash, true);
-}
-
-static void
-run(void)
-{
-	struct clock clock = { 0 };
-
-	while (game.state) {
-		unsigned int elapsed = clock_elapsed(&clock);
-
-		clock_start(&clock);
-
-		for (union event ev; event_poll(&ev); ) {
-			switch (ev.type) {
-			case EVENT_QUIT:
-				return;
-			default:
-				game_handle(&ev);
-				break;
-			}
-		}
-
-		game_update(elapsed);
-		game_draw();
-
-		if ((elapsed = clock_elapsed(&clock)) < 20)
-			delay(20 - elapsed);
-	}
-}
-
-static void
-close(void)
-{
-	window_finish();
-	rpg_finish();
-	ui_finish();
-	core_finish();
-}
+#include <adventure/molko.h>
 
 int
 main(int argc, char **argv)
@@ -122,20 +24,9 @@
 	(void)argc;
 	(void)argv;
 
-	if (setjmp(panic_buf) == 0) {
-		/* Initial game run. */
-		init();
-		run();
-	} else {
-		/* Clear event queue to avoid accidental key presses. */
-		for (union event ev; event_poll(&ev); )
-			continue;
-
-		game_switch(&states.panic, true);
-		run();
-	}
-
-	close();
+	molko_init();
+	molko_run();
+	molko_finish();
 
 	return 0;
 }