changeset 156:c3a40062acc2

misc: create more generic startup function, closes #2500
author David Demelier <markand@malikania.fr>
date Fri, 16 Oct 2020 13:54:31 +0200
parents 13b7a1a4a72c
children fb306ed990f8
files examples/example-action.c examples/example-debug.c examples/example-drawable.c examples/example-font.c examples/example-inventory.c examples/example-label.c examples/example-message.c examples/example-sound.c examples/example-trace.c examples/example-ui.c libadventure/adventure/panic_state.h libcore/CMakeLists.txt libcore/core/core.c libcore/core/core.h libcore/core/sys.h libcore/core/window.c libcore/core/window.h librpg/CMakeLists.txt librpg/rpg/rpg.c librpg/rpg/rpg.h libui/CMakeLists.txt libui/ui/theme.h libui/ui/ui.c libui/ui/ui.h molko/main.c
diffstat 25 files changed, 346 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/examples/example-action.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-action.c	Fri Oct 16 13:54:31 2020 +0200
@@ -20,6 +20,7 @@
 
 #include <core/action.h>
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/image.h>
 #include <core/maths.h>
@@ -33,8 +34,10 @@
 #include <core/window.h>
 
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #include <rpg/message.h>
+#include <rpg/rpg.h>
 
 #include <assets/sprites/chest.h>
 #include <assets/sprites/people.h>
@@ -315,9 +318,9 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Action", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init() || !rpg_init())
+		panic();
+	if (!window_open("Example - Action", W, H))
 		panic();
 
 	guide_init();
@@ -365,9 +368,10 @@
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	rpg_finish();
+	ui_finish();
+	core_finish();
 }
 
 int
--- a/examples/example-debug.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-debug.c	Fri Oct 16 13:54:31 2020 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/sys.h>
 #include <core/window.h>
@@ -27,6 +28,7 @@
 
 #include <ui/debug.h>
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #define W 1280
 #define H 720
@@ -34,9 +36,9 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Debug", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init())
+		panic();
+	if (!window_open("Example - Debug", W, H))
 		panic();
 
 	debug_options.enable = true;
@@ -84,9 +86,9 @@
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	ui_finish();
+	core_finish();
 }
 
 int
--- a/examples/example-drawable.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-drawable.c	Fri Oct 16 13:54:31 2020 +0200
@@ -20,6 +20,7 @@
 
 #include <core/animation.h>
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/drawable.h>
 #include <core/key.h>
@@ -34,6 +35,7 @@
 
 #include <ui/label.h>
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #include <assets/sprites/explosion.h>
 
@@ -66,9 +68,9 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Drawable", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init())
+		panic();
+	if (!window_open("Example - Drawable", W, H))
 		panic();
 
 	/* 0: Explosion animation. */
@@ -153,7 +155,9 @@
 static void
 quit(void)
 {
-	
+	window_finish();
+	ui_finish();
+	core_finish();
 }
 
 int
--- a/examples/example-font.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-font.c	Fri Oct 16 13:54:31 2020 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/font.h>
 #include <core/painter.h>
@@ -27,6 +28,7 @@
 #include <core/window.h>
 
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #define W       (1280)
 #define H       (720)
@@ -46,9 +48,9 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Font", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init())
+		panic();
+	if (!window_open("Example - Font", W, H))
 		panic();
 }
 
@@ -118,9 +120,9 @@
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	ui_finish();
+	core_finish();
 }
 
 int
--- a/examples/example-inventory.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-inventory.c	Fri Oct 16 13:54:31 2020 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/image.h>
 #include <core/painter.h>
@@ -27,10 +28,12 @@
 #include <core/window.h>
 
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #include <rpg/item.h>
 #include <rpg/inventory.h>
 #include <rpg/inventory_dialog.h>
+#include <rpg/rpg.h>
 
 /* https://shikashiassets.itch.io/shikashis-fantasy-icons-pack */
 #include <assets/images/fish.h>
@@ -78,9 +81,9 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Inventory", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init() || !rpg_init())
+		panic();
+	if (!window_open("Example - Inventory", W, H))
 		panic();
 
 	for (size_t i = 0; i < NELEM(items); ++i) {
@@ -94,9 +97,10 @@
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	rpg_finish();
+	ui_finish();
+	core_finish();
 }
 
 static void
--- a/examples/example-label.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-label.c	Fri Oct 16 13:54:31 2020 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/painter.h>
 #include <core/panic.h>
@@ -27,6 +28,7 @@
 #include <ui/align.h>
 #include <ui/label.h>
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #define W       (1280)
 #define H       (720)
@@ -95,9 +97,9 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Label", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init())
+		panic();
+	if (!window_open("Example - Label", W, H))
 		panic();
 
 	for (size_t i = 0; i < NELEM(table); ++i) {
@@ -111,9 +113,9 @@
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	ui_finish();
+	core_finish();
 }
 
 static void
--- a/examples/example-message.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-message.c	Fri Oct 16 13:54:31 2020 +0200
@@ -19,6 +19,7 @@
 #include <string.h>
 
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/painter.h>
 #include <core/panic.h>
@@ -28,8 +29,10 @@
 
 #include <ui/frame.h>
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #include <rpg/message.h>
+#include <rpg/rpg.h>
 
 #define W       (1280)
 #define H       (720)
@@ -42,18 +45,19 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Message", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init() || !rpg_init())
+		panic();
+	if (!window_open("Example - Message", W, H))
 		panic();
 }
 
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	rpg_finish();
+	ui_finish();
+	core_finish();
 }
 
 static void
--- a/examples/example-sound.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-sound.c	Fri Oct 16 13:54:31 2020 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/painter.h>
 #include <core/panic.h>
@@ -27,6 +28,7 @@
 
 #include <ui/label.h>
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 /* https://freesound.org/people/VABsounds/sounds/423658 */
 #include <assets/sounds/vabsounds-romance.h>
@@ -45,11 +47,10 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Sound", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init())
 		panic();
-
+	if (!window_open("Example - Sound", W, H))
+		panic();
 	if (!sound_openmem(&sound, sounds_vabsounds_romance, sizeof (sounds_vabsounds_romance)))
 		panic();
 }
@@ -57,9 +58,9 @@
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	ui_finish();
+	core_finish();
 }
 
 static void
--- a/examples/example-trace.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-trace.c	Fri Oct 16 13:54:31 2020 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/sys.h>
 #include <core/window.h>
@@ -26,6 +27,7 @@
 #include <core/util.h>
 
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #include <adventure/trace_hud.h>
 
@@ -35,9 +37,9 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - Trace", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init())
+		panic();
+	if (!window_open("Example - Trace", W, H))
 		panic();
 
 	trace_handler = trace_hud_handler;
@@ -92,9 +94,9 @@
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	ui_finish();
+	core_finish();
 }
 
 int
--- a/examples/example-ui.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/examples/example-ui.c	Fri Oct 16 13:54:31 2020 +0200
@@ -18,6 +18,7 @@
 
 #include <core/action.h>
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/maths.h>
 #include <core/panic.h>
@@ -32,6 +33,7 @@
 #include <ui/frame.h>
 #include <ui/label.h>
 #include <ui/theme.h>
+#include <ui/ui.h>
 
 #define W               (1280)
 #define H               (720)
@@ -126,9 +128,9 @@
 static void
 init(void)
 {
-	if (!sys_init() ||
-	    !window_init("Example - UI", W, H) ||
-	    !theme_init())
+	if (!core_init() || !ui_init())
+		panic();
+	if (!window_open("Example - UI", W, H))
 		panic();
 }
 
@@ -283,9 +285,9 @@
 static void
 quit(void)
 {
-	theme_finish();
 	window_finish();
-	sys_finish();
+	ui_finish();
+	core_finish();
 }
 
 int
--- a/libadventure/adventure/panic_state.h	Fri Oct 16 13:15:04 2020 +0200
+++ b/libadventure/adventure/panic_state.h	Fri Oct 16 13:54:31 2020 +0200
@@ -36,8 +36,9 @@
  * memory allocation errors.
  *
  * \note You must still initialize the system before.
- * \see \ref sys_init
- * \see \ref window_init
+ * \see \ref core_init
+ * \see \ref ui_init
+ * \see \ref window_open
  */
 void
 panic_state_init(void);
--- a/libcore/CMakeLists.txt	Fri Oct 16 13:15:04 2020 +0200
+++ b/libcore/CMakeLists.txt	Fri Oct 16 13:54:31 2020 +0200
@@ -27,6 +27,8 @@
 	${libcore_SOURCE_DIR}/core/clock.c
 	${libcore_SOURCE_DIR}/core/clock.h
 	${libcore_SOURCE_DIR}/core/color.h
+	${libcore_SOURCE_DIR}/core/core.c
+	${libcore_SOURCE_DIR}/core/core.h
 	${libcore_SOURCE_DIR}/core/drawable.c
 	${libcore_SOURCE_DIR}/core/drawable.h
 	${libcore_SOURCE_DIR}/core/error.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libcore/core/core.c	Fri Oct 16 13:54:31 2020 +0200
@@ -0,0 +1,32 @@
+/*
+ * core.c -- libcore convenient header
+ *
+ * Copyright (c) 2020 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "core.h"
+#include "sys.h"
+
+bool
+core_init(void)
+{
+	return sys_init();
+}
+
+void
+core_finish(void)
+{
+	sys_finish();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libcore/core/core.h	Fri Oct 16 13:54:31 2020 +0200
@@ -0,0 +1,43 @@
+/*
+ * core.h -- libcore convenient header
+ *
+ * Copyright (c) 2020 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef MOLKO_CORE_H
+#define MOLKO_CORE_H
+
+/**
+ * \file core.h
+ * \brief libcore convenient header.
+ */
+
+#include <stdbool.h>
+
+/**
+ * Initialize the core library.
+ *
+ * \return False on errors.
+ */
+bool
+core_init(void);
+
+/**
+ * Close the core library.
+ */
+void
+core_finish(void);
+
+#endif /* !MOLKO_CORE_H */
--- a/libcore/core/sys.h	Fri Oct 16 13:15:04 2020 +0200
+++ b/libcore/core/sys.h	Fri Oct 16 13:54:31 2020 +0200
@@ -28,8 +28,15 @@
 #include <stdarg.h>
 #include <stdbool.h>
 
+#include "plat.h"
+
 /**
- * Initialize the system, should be called in the beginning of the main.
+ * Initialize the system.
+ *
+ * This function is automatically called from \ref core_init and thus not
+ * necessary from user.
+ *
+ * \return False on error.
  */
 bool
 sys_init(void);
@@ -50,7 +57,7 @@
  * \note This function returns pointer to static string.
  */
 const char *
-sys_datapath(const char *fmt, ...);
+sys_datapath(const char *fmt, ...) PLAT_PRINTF(1, 2);
 
 /**
  * Similar to \a sys_datapath.
@@ -61,7 +68,7 @@
  * \note This function returns pointer to static string.
  */
 const char *
-sys_datapathv(const char *fmt, va_list ap);
+sys_datapathv(const char *fmt, va_list ap) PLAT_PRINTF(1, 0);
 
 /**
  * Compute the path to the save file for the given game state.
@@ -76,6 +83,9 @@
 
 /**
  * Close the system.
+ *
+ * This function is automatically called from \ref core_finish and thus not
+ * necessary from user.
  */
 void
 sys_finish(void);
--- a/libcore/core/window.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/libcore/core/window.c	Fri Oct 16 13:54:31 2020 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <assert.h>
+#include <string.h>
 
 #include <SDL.h>
 
@@ -34,7 +35,7 @@
 };
 
 bool
-window_init(const char *title, unsigned int w, unsigned int h)
+window_open(const char *title, unsigned int w, unsigned int h)
 {
 	assert(title);
 
@@ -57,4 +58,6 @@
 		SDL_DestroyRenderer(handle.renderer);
 	if (handle.win)
 		SDL_DestroyWindow(handle.win);
+
+	memset(&handle, 0, sizeof (handle));
 }
--- a/libcore/core/window.h	Fri Oct 16 13:15:04 2020 +0200
+++ b/libcore/core/window.h	Fri Oct 16 13:54:31 2020 +0200
@@ -51,7 +51,7 @@
  * \return true on success
  */
 bool
-window_init(const char *title, unsigned int width, unsigned int height);
+window_open(const char *title, unsigned int width, unsigned int height);
 
 /**
  * Close the window and destroy associated resources.
--- a/librpg/CMakeLists.txt	Fri Oct 16 13:15:04 2020 +0200
+++ b/librpg/CMakeLists.txt	Fri Oct 16 13:54:31 2020 +0200
@@ -31,6 +31,8 @@
 	${librpg_SOURCE_DIR}/rpg/map_state.h
 	${librpg_SOURCE_DIR}/rpg/message.c
 	${librpg_SOURCE_DIR}/rpg/message.h
+	${librpg_SOURCE_DIR}/rpg/rpg.c
+	${librpg_SOURCE_DIR}/rpg/rpg.h
 	${librpg_SOURCE_DIR}/rpg/walksprite.c
 	${librpg_SOURCE_DIR}/rpg/walksprite.h
 )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/librpg/rpg/rpg.c	Fri Oct 16 13:54:31 2020 +0200
@@ -0,0 +1,34 @@
+/*
+ * rpg.c -- librpg convenient header
+ *
+ * Copyright (c) 2020 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "rpg.h"
+
+bool
+rpg_init(void)
+{
+	/* Currently empty, placeholder for future. */
+	return true;
+}
+
+/**
+ * Close the rpg library.
+ */
+void
+rpg_finish(void)
+{
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/librpg/rpg/rpg.h	Fri Oct 16 13:54:31 2020 +0200
@@ -0,0 +1,43 @@
+/*
+ * rpg.h -- librpg convenient header
+ *
+ * Copyright (c) 2020 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef MOLKO_RPG_H
+#define MOLKO_RPG_H
+
+/**
+ * \file rpg.h
+ * \brief librpg convenient header
+ */
+
+#include <stdbool.h>
+
+/**
+ * Initialize the rpg library.
+ *
+ * \return False on errors.
+ */
+bool
+rpg_init(void);
+
+/**
+ * Close the rpg library.
+ */
+void
+rpg_finish(void);
+
+#endif /* !MOLKO_RPG_H */
--- a/libui/CMakeLists.txt	Fri Oct 16 13:15:04 2020 +0200
+++ b/libui/CMakeLists.txt	Fri Oct 16 13:54:31 2020 +0200
@@ -40,6 +40,8 @@
 	${libui_SOURCE_DIR}/ui/label.h
 	${libui_SOURCE_DIR}/ui/theme.c
 	${libui_SOURCE_DIR}/ui/theme.h
+	${libui_SOURCE_DIR}/ui/ui.c
+	${libui_SOURCE_DIR}/ui/ui.h
 )
 
 molko_define_library(
--- a/libui/ui/theme.h	Fri Oct 16 13:15:04 2020 +0200
+++ b/libui/ui/theme.h	Fri Oct 16 13:54:31 2020 +0200
@@ -107,8 +107,10 @@
 /**
  * Initialize the theming system.
  *
- * \return false on errors
- * \warning This function must be called before any other theme functions.
+ * This function is automatically called from \ref ui_init and thus not
+ * necessary from user.
+ *
+ * \return False on error.
  */
 bool
 theme_init(void);
@@ -178,7 +180,8 @@
 theme_draw_checkbox(struct theme *t, const struct checkbox *cb);
 
 /**
- * Close associated resources.
+ * This function is automatically called from \ref ui_finish and thus not
+ * necessary from user.
  */
 void
 theme_finish(void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libui/ui/ui.c	Fri Oct 16 13:54:31 2020 +0200
@@ -0,0 +1,32 @@
+/*
+ * ui.c -- libui convenient header
+ *
+ * Copyright (c) 2020 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "ui.h"
+#include "theme.h"
+
+bool
+ui_init(void)
+{
+	return theme_init();
+}
+
+void
+ui_finish(void)
+{
+	theme_finish();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libui/ui/ui.h	Fri Oct 16 13:54:31 2020 +0200
@@ -0,0 +1,43 @@
+/*
+ * ui.h -- libui convenient header
+ *
+ * Copyright (c) 2020 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef MOLKO_UI_H
+#define MOLKO_UI_H
+
+/**
+ * \file ui.h
+ * \brief libui convenient header.
+ */
+
+#include <stdbool.h>
+
+/**
+ * Initialize the ui library.
+ *
+ * \return False on errors.
+ */
+bool
+ui_init(void);
+
+/**
+ * Close the ui library.
+ */
+void
+ui_finish(void);
+
+#endif /* !MOLKO_UI_H */
--- a/molko/main.c	Fri Oct 16 13:15:04 2020 +0200
+++ b/molko/main.c	Fri Oct 16 13:54:31 2020 +0200
@@ -20,6 +20,7 @@
 #include <stdnoreturn.h>
 
 #include <core/clock.h>
+#include <core/core.h>
 #include <core/event.h>
 #include <core/game.h>
 #include <core/panic.h>
@@ -28,6 +29,9 @@
 #include <core/window.h>
 
 #include <ui/theme.h>
+#include <ui/ui.h>
+
+#include <rpg/rpg.h>
 
 #include <adventure/panic_state.h>
 #include <adventure/splashscreen_state.h>
@@ -46,9 +50,9 @@
 static void
 init(void)
 {
-	if (!sys_init())
+	if (!core_init() || !ui_init() || !rpg_init())
 		panic();
-	if (!window_init("Molko's Adventure", WINDOW_WIDTH, WINDOW_HEIGHT))
+	if (!window_open("Molko's Adventure", WINDOW_WIDTH, WINDOW_HEIGHT))
 		panic();
 
 	/*
@@ -99,7 +103,9 @@
 close(void)
 {
 	window_finish();
-	sys_finish();
+	rpg_finish();
+	ui_finish();
+	core_finish();
 }
 
 int