diff examples/example-battle/registry.c @ 263:cd5bdb995052

cmake: create a new libmlk-data library
author David Demelier <markand@malikania.fr>
date Tue, 08 Dec 2020 17:00:03 +0100
parents bfde372bf152
children 08ab73b32832
line wrap: on
line diff
--- a/examples/example-battle/registry.c	Mon Dec 07 23:21:05 2020 +0100
+++ b/examples/example-battle/registry.c	Tue Dec 08 17:00:03 2020 +0100
@@ -21,63 +21,52 @@
 #include <core/image.h>
 #include <core/panic.h>
 #include <core/util.h>
-
-#include <assets/images/battle-background.h>
-#include <assets/images/black-cat.h>
-#include <assets/images/haunted-wood.h>
-
-#include <assets/sprites/cursor.h>
-#include <assets/sprites/explosion.h>
-#include <assets/sprites/john-sword.h>
-#include <assets/sprites/john-walk.h>
-
-#include <assets/sounds/fire.h>
+#include <core/sys.h>
 
 #include "registry.h"
 
+#define PATH(r) util_pathf("%s/mlk-adventure/%s", sys_dir(SYS_DIR_DATA), r)
+
 struct texture registry_images[REGISTRY_IMAGE_NUM];
 struct texture registry_textures[REGISTRY_TEXTURE_NUM];
 struct sprite registry_sprites[REGISTRY_TEXTURE_NUM];
 struct sound registry_sounds[REGISTRY_SOUND_NUM];
 
-#define REGISTRY_IMAGE(i, ptr) \
-	{ (i), (ptr), sizeof ((ptr)) }
+#define REGISTRY_IMAGE(i, path) \
+	{ (i), (path) }
 
 static const struct {
 	enum registry_image index;
-	const void *data;
-	size_t datasz;
+	const char *path;
 } images[] = {
-	REGISTRY_IMAGE(REGISTRY_IMAGE_BATTLE_BACKGROUND, images_battle_background)
+	REGISTRY_IMAGE(REGISTRY_IMAGE_BATTLE_BACKGROUND, "images/battle-background.png")
 };
 
-#define REGISTRY_TEXTURE(s, ptr, cw, ch) \
-	{ (s), (ptr), sizeof ((ptr)), (cw), (ch) }
+#define REGISTRY_TEXTURE(s, path, cw, ch) \
+	{ (s), (path), (cw), (ch) }
 
 static const struct {
 	enum registry_texture index;
-	const void *data;
-	size_t datasz;
+	const char *path;
 	unsigned int cellw;
 	unsigned int cellh;
 } textures[] = {
-	REGISTRY_TEXTURE(REGISTRY_TEXTURE_CURSOR, sprites_cursor, 24, 24),
-	REGISTRY_TEXTURE(REGISTRY_TEXTURE_EXPLOSION, sprites_explosion, 256, 256),
-	REGISTRY_TEXTURE(REGISTRY_TEXTURE_JOHN_SWORD, sprites_john_sword, 256, 256),
-	REGISTRY_TEXTURE(REGISTRY_TEXTURE_JOHN_WALK, sprites_john_walk, 256, 256),
-	REGISTRY_TEXTURE(REGISTRY_TEXTURE_HAUNTED_WOOD, images_haunted_wood, 0, 0),
-	REGISTRY_TEXTURE(REGISTRY_TEXTURE_BLACK_CAT, images_black_cat, 0, 0)
+	REGISTRY_TEXTURE(REGISTRY_TEXTURE_CURSOR, "sprites/cursor.png", 24, 24),
+	REGISTRY_TEXTURE(REGISTRY_TEXTURE_EXPLOSION, "sprites/explosion.png", 256, 256),
+	REGISTRY_TEXTURE(REGISTRY_TEXTURE_JOHN_SWORD, "sprites/john-sword.png", 256, 256),
+	REGISTRY_TEXTURE(REGISTRY_TEXTURE_JOHN_WALK, "sprites/john-walk.png", 256, 256),
+	REGISTRY_TEXTURE(REGISTRY_TEXTURE_HAUNTED_WOOD, "images/haunted-wood.png", 0, 0),
+	REGISTRY_TEXTURE(REGISTRY_TEXTURE_BLACK_CAT, "images/black-cat.png", 0, 0)
 };
 
-#define REGISTRY_SOUND(s, ptr) \
-	{ (s), (ptr), sizeof ((ptr)) }
+#define REGISTRY_SOUND(s, path) \
+	{ (s), (path) }
 
 static const struct {
 	enum registry_sound index;
-	const void *data;
-	size_t datasz;
+	const char *path;
 } sounds[] = {
-	REGISTRY_SOUND(REGISTRY_SOUND_FIRE, sounds_fire)
+	REGISTRY_SOUND(REGISTRY_SOUND_FIRE, "sounds/fire.wav")
 };
 
 static void
@@ -86,7 +75,7 @@
 	for (size_t i = 0; i < UTIL_SIZE(images); ++i) {
 		struct texture *texture = &registry_images[images[i].index];
 
-		if (!image_openmem(texture, images[i].data, images[i].datasz))
+		if (!image_open(texture, PATH(images[i].path)))
 			panic();
 	}
 }
@@ -98,7 +87,7 @@
 		struct texture *texture = &registry_textures[textures[i].index];
 		struct sprite *sprite = &registry_sprites[textures[i].index];
 
-		if (!image_openmem(texture, textures[i].data, textures[i].datasz))
+		if (!image_open(texture, PATH(textures[i].path)))
 			panic();
 
 		if (textures[i].cellw == 0 || textures[i].cellh == 0)
@@ -114,7 +103,7 @@
 	for (size_t i = 0; i < UTIL_SIZE(sounds); ++i) {
 		struct sound *sound = &registry_sounds[sounds[i].index];
 
-		if (!sound_openmem(sound, sounds[i].data, sounds[i].datasz))
+		if (!sound_open(sound, PATH(sounds[i].path)))
 			panic();
 	}
 }