# HG changeset patch # User David Demelier # Date 1677498113 -3600 # Node ID ca30ff96bbe078ad2da2b39d5857701a8015eba7 # Parent 02b16dd49b54c8e07d269ae55c5dbdd296729420 core: util -> mlk_util diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-animation/example-animation.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-audio/example-audio.c --- 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(); diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-battle/example-battle.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-cursor/example-cursor.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-debug/example-debug.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-drawable/example-drawable.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-font/example-font.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-gridmenu/example-gridmenu.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-label/example-label.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-message/example-message.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-notify/example-notify.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-sprite/example-sprite.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-trace/example-trace.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 examples/example-ui/example-ui.c --- 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(); } diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-core/mlk/core/game.c --- 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); } diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-core/mlk/core/util.c --- 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); diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-core/mlk/core/util.h --- 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 diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-core/mlk/core/window.c --- 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]); } diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-example/mlk/example/registry.c --- 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 = ®istry_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 = ®istry_textures[textures[i].index]; struct mlk_sprite *sprite = ®istry_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 = ®istry_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(®istry_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(®istry_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(®istry_sounds[i]); } diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-rpg/mlk/rpg/battle-bar-default.c --- 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); diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-rpg/mlk/rpg/battle.c --- 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; diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-rpg/mlk/rpg/map-file.c --- 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); diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-rpg/mlk/rpg/save.c --- 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"); diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-rpg/mlk/rpg/selection.c --- 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])); } diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-rpg/mlk/rpg/tileset-file.c --- 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); } diff -r 02b16dd49b54 -r ca30ff96bbe0 libmlk-ui/mlk/ui/theme.c --- 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; } diff -r 02b16dd49b54 -r ca30ff96bbe0 tests/test-save-quest.c --- 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); diff -r 02b16dd49b54 -r ca30ff96bbe0 tests/test-state.c --- 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); diff -r 02b16dd49b54 -r ca30ff96bbe0 tests/test-util.c --- 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]);