changeset 474:ca30ff96bbe0

core: util -> mlk_util
author David Demelier <markand@malikania.fr>
date Mon, 27 Feb 2023 12:41:53 +0100
parents 02b16dd49b54
children 1a1265445157
files examples/example-animation/example-animation.c examples/example-audio/example-audio.c examples/example-battle/example-battle.c examples/example-cursor/example-cursor.c examples/example-debug/example-debug.c examples/example-drawable/example-drawable.c examples/example-font/example-font.c examples/example-gridmenu/example-gridmenu.c examples/example-label/example-label.c examples/example-message/example-message.c examples/example-notify/example-notify.c examples/example-sprite/example-sprite.c examples/example-trace/example-trace.c examples/example-ui/example-ui.c libmlk-core/mlk/core/game.c libmlk-core/mlk/core/util.c libmlk-core/mlk/core/util.h libmlk-core/mlk/core/window.c libmlk-example/mlk/example/registry.c libmlk-rpg/mlk/rpg/battle-bar-default.c libmlk-rpg/mlk/rpg/battle.c libmlk-rpg/mlk/rpg/map-file.c libmlk-rpg/mlk/rpg/save.c libmlk-rpg/mlk/rpg/selection.c libmlk-rpg/mlk/rpg/tileset-file.c libmlk-ui/mlk/ui/theme.c tests/test-save-quest.c tests/test-state.c tests/test-util.c
diffstat 29 files changed, 52 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/examples/example-animation/example-animation.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-animation/example-animation.c	Mon Feb 27 12:41:53 2023 +0100
@@ -122,7 +122,7 @@
 	mlk_sprite_init(&sprite, &numbers, 48, 48);
 	mlk_animation_init(&animation, &sprite, 1000);
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-audio/example-audio.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-audio/example-audio.c	Mon Feb 27 12:41:53 2023 +0100
@@ -135,7 +135,7 @@
 		.draw = draw
 	};
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 
--- a/examples/example-battle/example-battle.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-battle/example-battle.c	Mon Feb 27 12:41:53 2023 +0100
@@ -201,18 +201,18 @@
 static void
 prepare_to_fight(void)
 {
-	mlk_action_stack_init(&action_stack, actions, UTIL_SIZE(actions));
-	mlk_drawable_stack_init(&drawable_stack, drawables, UTIL_SIZE(drawables));
+	mlk_action_stack_init(&action_stack, actions, MLK_UTIL_SIZE(actions));
+	mlk_drawable_stack_init(&drawable_stack, drawables, MLK_UTIL_SIZE(drawables));
 
 	battle_init(&bt);
 	battle_bar_default_init(&default_bar);
 	battle_bar_default(&default_bar, &bar);
 
 	bt.team = entities_team;
-	bt.teamsz = UTIL_SIZE(entities_team);
+	bt.teamsz = MLK_UTIL_SIZE(entities_team);
 
 	bt.enemies = entities_enemies;
-	bt.enemiesz = UTIL_SIZE(entities_enemies);
+	bt.enemiesz = MLK_UTIL_SIZE(entities_enemies);
 
 	/* Black cat is near the previous monster. */
 	entities_team[0] = &entities[1].entity;
@@ -318,7 +318,7 @@
 static void
 run(void)
 {
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&empty_state);
 	mlk_game_loop();
 }
--- a/examples/example-cursor/example-cursor.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-cursor/example-cursor.c	Mon Feb 27 12:41:53 2023 +0100
@@ -123,7 +123,7 @@
 
 	change(cursor);
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-debug/example-debug.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-debug/example-debug.c	Mon Feb 27 12:41:53 2023 +0100
@@ -87,7 +87,7 @@
 		.draw = draw
 	};
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-drawable/example-drawable.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-drawable/example-drawable.c	Mon Feb 27 12:41:53 2023 +0100
@@ -181,9 +181,9 @@
 		.draw = draw
 	};
 
-	mlk_drawable_stack_init(&stack, drawables, UTIL_SIZE(drawables));
+	mlk_drawable_stack_init(&stack, drawables, MLK_UTIL_SIZE(drawables));
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-font/example-font.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-font/example-font.c	Mon Feb 27 12:41:53 2023 +0100
@@ -72,7 +72,7 @@
 				ci--;
 			break;
 		case MLK_KEY_RIGHT:
-			if ((size_t)ci < UTIL_SIZE(colors))
+			if ((size_t)ci < MLK_UTIL_SIZE(colors))
 				ci++;
 			break;
 		case MLK_KEY_SPACE:
@@ -121,7 +121,7 @@
 		.draw = draw
 	};
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-gridmenu/example-gridmenu.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-gridmenu/example-gridmenu.c	Mon Feb 27 12:41:53 2023 +0100
@@ -110,12 +110,12 @@
 		.draw = draw,
 	};
 
-	gridmenu_init(&menu, 3, 2, items, UTIL_SIZE(items));
+	gridmenu_init(&menu, 3, 2, items, MLK_UTIL_SIZE(items));
 	gridmenu_resize(&menu, 0, 0, 300, 100);
 
 	align(ALIGN_CENTER, &menu.x, &menu.y, menu.w, menu.h, 0, 0, W, H);
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-label/example-label.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-label/example-label.c	Mon Feb 27 12:41:53 2023 +0100
@@ -111,7 +111,7 @@
 	if (window_open("Example - Label", W, H) < 0)
 		mlk_panic();
 
-	for (size_t i = 0; i < UTIL_SIZE(table); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(table); ++i) {
 		struct label *l = &table[i].label;
 		unsigned int w, h;
 
@@ -154,7 +154,7 @@
 	mlk_painter_set_color(0x4f8fbaff);
 	mlk_painter_clear();
 
-	for (size_t i = 0; i < UTIL_SIZE(table); ++i)
+	for (size_t i = 0; i < MLK_UTIL_SIZE(table); ++i)
 		label_draw(&table[i].label);
 
 	label_draw(&mlabel);
@@ -169,7 +169,7 @@
 		.draw = draw
 	};
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-message/example-message.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-message/example-message.c	Mon Feb 27 12:41:53 2023 +0100
@@ -104,7 +104,7 @@
 
 	message_start(msg);
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-notify/example-notify.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-notify/example-notify.c	Mon Feb 27 12:41:53 2023 +0100
@@ -106,7 +106,7 @@
 		.draw = draw
 	};
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-sprite/example-sprite.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-sprite/example-sprite.c	Mon Feb 27 12:41:53 2023 +0100
@@ -138,7 +138,7 @@
 
 	changed();
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-trace/example-trace.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-trace/example-trace.c	Mon Feb 27 12:41:53 2023 +0100
@@ -103,7 +103,7 @@
 		.draw = draw
 	};
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/examples/example-ui/example-ui.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/examples/example-ui/example-ui.c	Mon Feb 27 12:41:53 2023 +0100
@@ -261,7 +261,7 @@
 
 	resize();
 
-	mlk_game_init(states, UTIL_SIZE(states));
+	mlk_game_init(states, MLK_UTIL_SIZE(states));
 	mlk_game_push(&state);
 	mlk_game_loop();
 }
--- a/libmlk-core/mlk/core/game.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-core/mlk/core/game.c	Mon Feb 27 12:41:53 2023 +0100
@@ -122,7 +122,7 @@
 		 * a little to save CPU cycles.
 		 */
 		if ((elapsed = mlk_clock_elapsed(&clock)) < frametime)
-			util_delay(frametime - elapsed);
+			mlk_util_delay(frametime - elapsed);
 
 		elapsed = mlk_clock_elapsed(&clock);
 	}
--- a/libmlk-core/mlk/core/util.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-core/mlk/core/util.c	Mon Feb 27 12:41:53 2023 +0100
@@ -27,13 +27,13 @@
 #include "util.h"
 
 void
-util_delay(unsigned int ms)
+mlk_util_delay(unsigned int ms)
 {
 	SDL_Delay(ms);
 }
 
 const char *
-util_pathf(const char *fmt, ...)
+mlk_util_pathf(const char *fmt, ...)
 {
 	static char path[PATH_MAX];
 	va_list ap;
@@ -46,7 +46,7 @@
 }
 
 unsigned int
-util_nrand(unsigned int lower, unsigned int upper)
+mlk_util_nrand(unsigned int lower, unsigned int upper)
 {
 	assert(upper <= RAND_MAX);
 
--- a/libmlk-core/mlk/core/util.h	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-core/mlk/core/util.h	Mon Feb 27 12:41:53 2023 +0100
@@ -21,18 +21,18 @@
 
 #include "core.h"
 
-#define UTIL_SIZE(x) sizeof ((x)) / sizeof ((x)[0])
+#define MLK_UTIL_SIZE(x) (sizeof ((x)) / sizeof ((x)[0]))
 
 MLK_CORE_BEGIN_DECLS
 
 void
-util_delay(unsigned int);
+mlk_util_delay(unsigned int);
 
 const char *
-util_pathf(const char *, ...);
+mlk_util_pathf(const char *, ...);
 
 unsigned int
-util_nrand(unsigned int, unsigned int);
+mlk_util_nrand(unsigned int, unsigned int);
 
 MLK_CORE_END_DECLS
 
--- a/libmlk-core/mlk/core/window.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-core/mlk/core/window.c	Mon Feb 27 12:41:53 2023 +0100
@@ -61,7 +61,7 @@
 static void
 finish_cursors(void)
 {
-	for (size_t i = 0; i < UTIL_SIZE(cursors); ++i)
+	for (size_t i = 0; i < MLK_UTIL_SIZE(cursors); ++i)
 		if (cursors[i])
 			SDL_FreeCursor(cursors[i]);
 }
--- a/libmlk-example/mlk/example/registry.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-example/mlk/example/registry.c	Mon Feb 27 12:41:53 2023 +0100
@@ -84,7 +84,7 @@
 static void
 load_images(void)
 {
-	for (size_t i = 0; i < UTIL_SIZE(images); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(images); ++i) {
 		struct mlk_texture *texture = &registry_images[images[i].index];
 
 		if (mlk_image_openmem(texture, images[i].data, images[i].datasz) < 0)
@@ -95,7 +95,7 @@
 static void
 load_textures_and_sprites(void)
 {
-	for (size_t i = 0; i < UTIL_SIZE(textures); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(textures); ++i) {
 		struct mlk_texture *texture = &registry_textures[textures[i].index];
 		struct mlk_sprite *sprite = &registry_sprites[textures[i].index];
 
@@ -112,7 +112,7 @@
 static void
 load_sounds(void)
 {
-	for (size_t i = 0; i < UTIL_SIZE(sounds); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(sounds); ++i) {
 		struct mlk_sound *sound = &registry_sounds[sounds[i].index];
 
 		if (mlk_sound_openmem(sound, sounds[i].data, sounds[i].datasz) < 0)
@@ -131,10 +131,10 @@
 void
 registry_finish(void)
 {
-	for (size_t i = 0; i < UTIL_SIZE(registry_images); ++i)
+	for (size_t i = 0; i < MLK_UTIL_SIZE(registry_images); ++i)
 		mlk_texture_finish(&registry_images[i]);
-	for (size_t i = 0; i < UTIL_SIZE(registry_textures); ++i)
+	for (size_t i = 0; i < MLK_UTIL_SIZE(registry_textures); ++i)
 		mlk_texture_finish(&registry_textures[i]);
-	for (size_t i = 0; i < UTIL_SIZE(registry_sounds); ++i)
+	for (size_t i = 0; i < MLK_UTIL_SIZE(registry_sounds); ++i)
 		mlk_sound_finish(&registry_sounds[i]);
 }
--- a/libmlk-rpg/mlk/rpg/battle-bar-default.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/battle-bar-default.c	Mon Feb 27 12:41:53 2023 +0100
@@ -371,7 +371,7 @@
 		.h = geo->h
 	});
 
-	for (size_t i = 0; i < UTIL_SIZE(buttons); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(buttons); ++i) {
 		buttons[i].label.theme = theme;
 
 		label_query(&buttons[i].label, &buttons[i].w, &buttons[i].h);
--- a/libmlk-rpg/mlk/rpg/battle.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/battle.c	Mon Feb 27 12:41:53 2023 +0100
@@ -101,7 +101,7 @@
 	struct battle_entity *ret = NULL, *et = NULL;
 
 	do {
-		et = group[util_nrand(0, groupsz - 1)];
+		et = group[mlk_util_nrand(0, groupsz - 1)];
 
 		if (et && et->ch)
 			ret = et;
--- a/libmlk-rpg/mlk/rpg/map-file.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/map-file.c	Mon Feb 27 12:41:53 2023 +0100
@@ -211,7 +211,7 @@
 		{ "layer",      parse_layer             },
 	};
 
-	for (size_t i = 0; i < UTIL_SIZE(props); ++i)
+	for (size_t i = 0; i < MLK_UTIL_SIZE(props); ++i)
 		if (strncmp(line, props[i].property, strlen(props[i].property)) == 0)
 			return props[i].read(ctx, line);
 
--- a/libmlk-rpg/mlk/rpg/save.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/save.c	Mon Feb 27 12:41:53 2023 +0100
@@ -50,7 +50,7 @@
 static const char *
 path(unsigned int idx)
 {
-	return util_pathf("%s%u.db", mlk_sys_dir(MLK_SYS_DIR_SAVE), idx);
+	return mlk_util_pathf("%s%u.db", mlk_sys_dir(MLK_SYS_DIR_SAVE), idx);
 }
 
 static int
@@ -71,7 +71,7 @@
 	};
 
 	/* Ensure create and update dates are present. */
-	for (size_t i = 0; i < UTIL_SIZE(table); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(table); ++i) {
 		if (property_load(&table[i].prop, db) < 0) {
 			sqlite3_close(db->handle);
 			return errorf("database not initialized correctly");
--- a/libmlk-rpg/mlk/rpg/selection.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/selection.c	Mon Feb 27 12:41:53 2023 +0100
@@ -28,7 +28,7 @@
 random(struct selection *slt, struct battle_entity **entities, size_t entitiesz)
 {
 	do {
-		slt->index_character = util_nrand(0, entitiesz);
+		slt->index_character = mlk_util_nrand(0, entitiesz);
 	} while (!battle_entity_ok(entities[slt->index_character]));
 }
 
--- a/libmlk-rpg/mlk/rpg/tileset-file.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-rpg/mlk/rpg/tileset-file.c	Mon Feb 27 12:41:53 2023 +0100
@@ -193,7 +193,7 @@
 	while (fscanf(ctx->fp, "%hu|" MAX_F(FILENAME_MAX) "|%u", &id, filename, &delay) == 3) {
 		anim = mlk_alloc_pool_new(&ctx->tf->anims[0]);
 
-		if (mlk_image_open(&anim->texture, util_pathf("%s/%s", ctx->basedir, filename)) < 0)
+		if (mlk_image_open(&anim->texture, mlk_util_pathf("%s/%s", ctx->basedir, filename)) < 0)
 			return -1;
 
 		mlk_sprite_init(&anim->sprite, &anim->texture, ctx->tilewidth, ctx->tileheight);
@@ -236,7 +236,7 @@
 	if (!(p = strchr(line, '|')))
 		return errorf("could not parse image");
 
-	if (mlk_image_open(&ctx->tf->image, util_pathf("%s/%s", ctx->basedir, p + 1)) < 0)
+	if (mlk_image_open(&ctx->tf->image, mlk_util_pathf("%s/%s", ctx->basedir, p + 1)) < 0)
 		return -1;
 
 	mlk_sprite_init(&ctx->tf->sprite, &ctx->tf->image, ctx->tilewidth, ctx->tileheight);
@@ -259,7 +259,7 @@
 		{ "image",      parse_image             }
 	};
 
-	for (size_t i = 0; i < UTIL_SIZE(props); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(props); ++i) {
 		if (strncmp(line, props[i].property, strlen(props[i].property)) == 0)
 			return props[i].read(ctx, line);
 	}
--- a/libmlk-ui/mlk/ui/theme.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/libmlk-ui/mlk/ui/theme.c	Mon Feb 27 12:41:53 2023 +0100
@@ -75,7 +75,7 @@
 theme_init(void)
 {
 	/* Open all fonts. */
-	for (size_t i = 0; i < UTIL_SIZE(default_fonts); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(default_fonts); ++i) {
 		struct font_catalog *fc = &default_fonts[i];
 
 		if (mlk_font_openmem(&fc->font, fc->data, fc->datasz, fc->size) < 0)
@@ -148,7 +148,7 @@
 void
 theme_finish(void)
 {
-	for (size_t i = 0; i < UTIL_SIZE(default_fonts); ++i) {
+	for (size_t i = 0; i < MLK_UTIL_SIZE(default_fonts); ++i) {
 		mlk_font_finish(&default_fonts[i].font);
 		*default_fonts[i].dest = NULL;
 	}
--- a/tests/test-save-quest.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/tests/test-save-quest.c	Mon Feb 27 12:41:53 2023 +0100
@@ -44,7 +44,7 @@
 		.name = "0001-getting-started",
 		.description = "Initial quest for adventurer.",
 		.steps = steps,
-		.stepsz = UTIL_SIZE(steps)
+		.stepsz = MLK_UTIL_SIZE(steps)
 	};
 
 	DT_EQ_INT(quest_save(&quest, save), 0);
--- a/tests/test-state.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/tests/test-state.c	Mon Feb 27 12:41:53 2023 +0100
@@ -204,7 +204,7 @@
 	};
 
 	/* 0 becomes active and should start. */
-	mlk_game_init(mainstates, UTIL_SIZE(mainstates));
+	mlk_game_init(mainstates, MLK_UTIL_SIZE(mainstates));
 	mlk_game_push(&states[0].state);
 
 	DT_EQ_UINT(states[0].inv.start, 1U);
--- a/tests/test-util.c	Mon Feb 27 11:26:23 2023 +0100
+++ b/tests/test-util.c	Mon Feb 27 12:41:53 2023 +0100
@@ -27,7 +27,7 @@
 
 	/* Only try from [2..5], util_nrand does not include upper range. */
 	for (int i = 0; i < 100000; ++i)
-		found[util_nrand(2, 6)] = 1;
+		found[mlk_util_nrand(2, 6)] = 1;
 
 	DT_ASSERT(!found[0]);
 	DT_ASSERT(!found[1]);