changeset 276:8d41e317c07b

adventure: enable trace_hud
author David Demelier <markand@malikania.fr>
date Sun, 13 Dec 2020 11:10:35 +0100
parents f89a53abb314
children 1d10983fc0d7
files libmlk-adventure/adventure/mapscene/mapscene.c libmlk-adventure/adventure/molko.c libmlk-adventure/adventure/state/map.c libmlk-adventure/adventure/trace_hud.c libmlk-adventure/adventure/trace_hud.h
diffstat 5 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libmlk-adventure/adventure/mapscene/mapscene.c	Sun Dec 13 11:01:18 2020 +0100
+++ b/libmlk-adventure/adventure/mapscene/mapscene.c	Sun Dec 13 11:10:35 2020 +0100
@@ -30,6 +30,8 @@
 #include <adventure/action/teleport.h>
 #include <adventure/action/spawner.h>
 
+#include <adventure/trace_hud.h>
+
 #include "mapscene.h"
 
 #define SEARCH(key, array, size, cmp) \
@@ -139,4 +141,7 @@
 	/* Same layout, can use cmp_title as well. */
 	if ((ld = SEARCH(m->title, mapscenes, sizeof (*ld), cmp_title)))
 		ld->load(m);
+
+	/* Add the trace hud. */
+	action_stack_add(&m->astack_par, trace_hud_action());
 }
--- a/libmlk-adventure/adventure/molko.c	Sun Dec 13 11:01:18 2020 +0100
+++ b/libmlk-adventure/adventure/molko.c	Sun Dec 13 11:10:35 2020 +0100
@@ -27,9 +27,10 @@
 #include <core/event.h>
 #include <core/image.h>
 #include <core/panic.h>
+#include <core/sys.h>
+#include <core/trace.h>
 #include <core/translate.h>
 #include <core/util.h>
-#include <core/sys.h>
 #include <core/window.h>
 
 #include <ui/ui.h>
@@ -43,6 +44,7 @@
 
 #include "assets.h"
 #include "molko.h"
+#include "trace_hud.h"
 
 #define WINDOW_WIDTH    1280
 #define WINDOW_HEIGHT   720
@@ -78,6 +80,7 @@
 	/* Init unrecoverable panic state. */
 	molko.panic = panic_state_new();
 	panic_handler = crash;
+	trace_handler = trace_hud_handler;
 
 	/* Init other stuff. */
 	assets_init();
--- a/libmlk-adventure/adventure/state/map.c	Sun Dec 13 11:01:18 2020 +0100
+++ b/libmlk-adventure/adventure/state/map.c	Sun Dec 13 11:10:35 2020 +0100
@@ -70,6 +70,8 @@
 	if (self->origin_y >= 0)
 		self->map.player_y = self->origin_y;
 
+	mapscene_load(&self->map);
+
 	if (!map_init(&self->map))
 		panic();
 }
--- a/libmlk-adventure/adventure/trace_hud.c	Sun Dec 13 11:01:18 2020 +0100
+++ b/libmlk-adventure/adventure/trace_hud.c	Sun Dec 13 11:10:35 2020 +0100
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <core/action.h>
 #include <core/font.h>
 #include <core/trace.h>
 #include <core/window.h>
@@ -113,3 +114,32 @@
 {
 	memset(&data, 0, sizeof (data));
 }
+
+static bool
+update(struct action *a, unsigned int ticks)
+{
+	(void)a;
+
+	trace_hud_update(ticks);
+
+	return false;
+}
+
+static void
+draw(struct action *a)
+{
+	(void)a;
+
+	trace_hud_draw();
+}
+
+struct action *
+trace_hud_action(void)
+{
+	static struct action a = {
+		.update = update,
+		.draw = draw
+	};
+
+	return &a;
+}
--- a/libmlk-adventure/adventure/trace_hud.h	Sun Dec 13 11:01:18 2020 +0100
+++ b/libmlk-adventure/adventure/trace_hud.h	Sun Dec 13 11:10:35 2020 +0100
@@ -21,6 +21,7 @@
 
 #define TRACE_HUD_TIMEOUT_DEFAULT (3000)
 
+struct action;
 struct theme;
 
 struct trace_hud {
@@ -42,4 +43,7 @@
 void
 trace_hud_clear(void);
 
+struct action *
+trace_hud_action(void);
+
 #endif /* !MOLKO_ADVENTURE_TRACE_HUD_H */