From: Holger Schemel Date: Sun, 25 Feb 2024 00:40:35 +0000 (+0100) Subject: replaced glib function calls to g_rand_*() and g_random_*() X-Git-Tag: 4.4.0.0-test-1~284 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=8b154afb27d3c3307f465a61a9542a57e97823c2;p=rocksndiamonds.git replaced glib function calls to g_rand_*() and g_random_*() --- diff --git a/src/game_bd/bd_cave.c b/src/game_bd/bd_cave.c index 07cb74a6..7d5aca5d 100644 --- a/src/game_bd/bd_cave.c +++ b/src/game_bd/bd_cave.c @@ -538,8 +538,8 @@ void gd_cave_free(GdCave *cave) if (cave->tags) hashtable_destroy(cave->tags); - if (cave->random) /* random generator is a GRand * */ - g_rand_free(cave->random); + if (cave->random) /* random generator is a GdRand * */ + gd_rand_free(cave->random); /* free strings */ for (i = 0; gd_cave_properties[i].identifier != NULL; i++) @@ -620,7 +620,7 @@ void gd_cave_copy(GdCave *dest, const GdCave *src) /* copy random number generator */ if (src->random) - dest->random = g_rand_copy(src->random); + dest->random = gd_rand_copy(src->random); } /* create new cave, which is a copy of the cave given. */ @@ -1146,10 +1146,10 @@ void gd_drawcave_game(const GdCave *cave, int **element_buffer, int **gfx_buffer { /* blinking and tapping is started at the beginning of animation sequences. */ /* 1/4 chance of blinking, every sequence. */ - player_blinking = g_random_int_range(0, 4) == 0; + player_blinking = gd_random_int_range(0, 4) == 0; /* 1/16 chance of starting or stopping tapping. */ - if (g_random_int_range(0, 16) == 0) + if (gd_random_int_range(0, 16) == 0) player_tapping = !player_tapping; } } diff --git a/src/game_bd/bd_cave.h b/src/game_bd/bd_cave.h index d267c363..cc0f3ebe 100644 --- a/src/game_bd/bd_cave.h +++ b/src/game_bd/bd_cave.h @@ -20,6 +20,7 @@ #include #include "bd_elements.h" +#include "bd_random.h" // colors @@ -567,7 +568,7 @@ typedef struct _gd_cave boolean hatched; /* hatching has happened. (timers may run, ...) */ boolean gate_open; /* self-explaining */ guint32 render_seed; /* the seed value, which was used to render the cave, is saved here. will be used by record&playback */ - GRand *random; /* random number generator of rendered cave */ + GdRand *random; /* random number generator of rendered cave */ int rendered; /* if not zero, rendered at level x */ int timing_factor; /* number of "milliseconds" in each second :) 1000 for ntsc, 1200 for pal. */ gpointer **objects_order; /* two-dimensional map of cave; each cell is a pointer to the drawing object, which created this element. NULL if map or random. */ diff --git a/src/game_bd/bd_caveengine.c b/src/game_bd/bd_caveengine.c index 4d528a41..109bcb2d 100644 --- a/src/game_bd/bd_caveengine.c +++ b/src/game_bd/bd_caveengine.c @@ -1100,7 +1100,7 @@ static boolean do_push(GdCave *cave, int x, int y, GdDirection player_move, bool } if (is_space_dir(cave, x, y, GD_MV_TWICE + player_move) && - g_rand_int_range(cave->random, 0, 1000000) < prob) + gd_rand_int_range(cave->random, 0, 1000000) < prob) { /* if decided that he will be able to push, */ store_dir(cave, x, y, GD_MV_TWICE + player_move, what); @@ -2337,7 +2337,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, { int px = cave->px[0]; int py = cave->py[0]; - boolean horizontal = g_rand_boolean(cave->random); + boolean horizontal = gd_rand_boolean(cave->random); boolean dont_move = FALSE; int i = 3; @@ -2711,7 +2711,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, }; GdDirection random_dir; - random_dir = dirs[g_rand_int_range(cave->random, 0, G_N_ELEMENTS(dirs))]; + random_dir = dirs[gd_rand_int_range(cave->random, 0, G_N_ELEMENTS(dirs))]; if (is_space_dir(cave, x, y, random_dir)) { move(cave, x, y, random_dir, O_GHOST); @@ -2756,9 +2756,9 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, /* if alive, check in which dir to grow (or not) */ if (cave->amoeba_state == GD_AM_AWAKE) { - if (g_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_growth_prob) + if (gd_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_growth_prob) { - switch (g_rand_int_range(cave->random, 0, 4)) + switch (gd_rand_int_range(cave->random, 0, 4)) { /* decided to grow, choose a random direction. */ case 0: /* let this be up. numbers indifferent. */ @@ -2824,9 +2824,9 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, /* if it is alive, decide if it attempts to grow */ if (cave->amoeba_2_state == GD_AM_AWAKE) - if (g_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_2_growth_prob) + if (gd_rand_int_range(cave->random, 0, 1000000) < cave->amoeba_2_growth_prob) { - switch (g_rand_int_range(cave->random, 0, 4)) + switch (gd_rand_int_range(cave->random, 0, 4)) { /* decided to grow, choose a random direction. */ case 0: /* let this be up. numbers indifferent. */ @@ -2857,7 +2857,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, case O_ACID: /* choose randomly, if it spreads */ - if (g_rand_int_range(cave->random, 0, 1000000) <= cave->acid_spread_ratio) + if (gd_rand_int_range(cave->random, 0, 1000000) <= cave->acid_spread_ratio) { /* the current one explodes */ store(cave, x, y, cave->acid_turns_to); @@ -2985,12 +2985,12 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, (rrr & cave->slime_permeability_c64) == 0); #endif /* - * unpredictable: g_rand_int + * unpredictable: gd_rand_int * predictable: c64 predictable random generator. * for predictable, a random number is generated, * whether or not it is even possible that the stone will be able to pass. */ - if (cave->slime_predictable ? ((rrr /* XXX */ & cave->slime_permeability_c64) == 0) : g_rand_int_range(cave->random, 0, 1000000) < cave->slime_permeability) + if (cave->slime_predictable ? ((rrr /* XXX */ & cave->slime_permeability_c64) == 0) : gd_rand_int_range(cave->random, 0, 1000000) < cave->slime_permeability) { GdDirection grav = cave->gravity; GdDirection oppos = opposite[cave->gravity]; @@ -3201,7 +3201,7 @@ void gd_cave_iterate(GdCave *cave, GdDirection player_move, boolean player_fire, O_WAITING_STONE, O_BITER_1 }; - store(cave, x, y, ghost_explode[g_rand_int_range(cave->random, 0, G_N_ELEMENTS(ghost_explode))]); + store(cave, x, y, ghost_explode[gd_rand_int_range(cave->random, 0, G_N_ELEMENTS(ghost_explode))]); } break; diff --git a/src/game_bd/bd_caveobject.c b/src/game_bd/bd_caveobject.c index 568d2b3a..01c3caf9 100644 --- a/src/game_bd/bd_caveobject.c +++ b/src/game_bd/bd_caveobject.c @@ -823,7 +823,7 @@ static void draw_join(GdCave *cave, const GdObject *object) /* create a maze in a boolean **maze. */ /* recursive algorithm. */ -static void mazegen(GRand *rand, boolean **maze, int width, int height, int x, int y, int horiz) +static void mazegen(GdRand *rand, boolean **maze, int width, int height, int x, int y, int horiz) { int dirmask = 15; @@ -833,7 +833,7 @@ static void mazegen(GRand *rand, boolean **maze, int width, int height, int x, i int dir; /* horiz or vert */ - dir = g_rand_int_range(rand, 0, 100) y2; int w, h, path, wall; int xk, yk; - GRand *rand; + GdRand *rand; int i,j; /* change coordinates if not in correct order */ @@ -1023,8 +1023,8 @@ static void draw_maze(GdCave *cave, const GdObject *object, int level) /* start generation, if map is big enough. otherwise the application would crash, as the editor places maze objects during mouse click & drag that have no sense */ - rand = g_rand_new_with_seed(object->seed[level] == -1 ? - g_rand_int(cave->random) : object->seed[level]); + rand = gd_rand_new_with_seed(object->seed[level] == -1 ? + gd_rand_int(cave->random) : object->seed[level]); if (w >= 1 && h >= 1) mazegen(rand, map, w, h, 0, 0, object->horiz); @@ -1032,7 +1032,7 @@ static void draw_maze(GdCave *cave, const GdObject *object, int level) if (object->type == GD_MAZE_BRAID) braidmaze(rand, map, w, h); - g_rand_free(rand); + gd_rand_free(rand); if (w >= 1 && h >= 1 && object->type == GD_MAZE_UNICURSAL) { @@ -1137,17 +1137,17 @@ static void draw_random_fill(GdCave *cave, const GdObject *object, int level) int y1 = object->y1; int x2 = object->x2; int y2 = object->y2; - GRand *rand; + GdRand *rand; GdC64RandomGenerator c64_rand; guint32 seed; /* -1 means that it should be different every time played. */ if (object->seed[level] == -1) - seed = g_rand_int(cave->random); + seed = gd_rand_int(cave->random); else seed = object->seed[level]; - rand = g_rand_new_with_seed(seed); + rand = gd_rand_new_with_seed(seed); /* for c64 random, use the 2*8 lsb. */ gd_c64_random_set_seed(&c64_rand, seed / 256 % 256, seed % 256); @@ -1178,7 +1178,7 @@ static void draw_random_fill(GdCave *cave, const GdObject *object, int level) randm = gd_c64_random(&c64_rand); else /* use the much better glib random generator */ - randm = g_rand_int_range(rand, 0, 256); + randm = gd_rand_int_range(rand, 0, 256); element = object->fill_element; if (randm < object->random_fill_probability[0]) @@ -1196,7 +1196,7 @@ static void draw_random_fill(GdCave *cave, const GdObject *object, int level) } } - g_rand_free(rand); + gd_rand_free(rand); } @@ -1328,7 +1328,7 @@ GdCave *gd_cave_new_rendered(const GdCave *data, const int level, const guint32 cave->rendered = level + 1; cave->render_seed = seed; - cave->random = g_rand_new_with_seed(cave->render_seed); + cave->random = gd_rand_new_with_seed(cave->render_seed); /* maps needed during drawing and gameplay */ cave->objects_order = gd_cave_map_new(cave, gpointer); @@ -1356,8 +1356,8 @@ GdCave *gd_cave_new_rendered(const GdCave *data, const int level, const guint32 /* IF CAVE HAS NO MAP, USE THE RANDOM NUMBER GENERATOR */ /* init c64 randomgenerator */ if (data->level_rand[level] < 0) - gd_cave_c64_random_set_seed(cave, g_rand_int_range(cave->random, 0, 256), - g_rand_int_range(cave->random, 0, 256)); + gd_cave_c64_random_set_seed(cave, gd_rand_int_range(cave->random, 0, 256), + gd_rand_int_range(cave->random, 0, 256)); else gd_cave_c64_random_set_seed(cave, 0, data->level_rand[level]); @@ -1374,7 +1374,7 @@ GdCave *gd_cave_new_rendered(const GdCave *data, const int level, const guint32 if (data->level_rand[level] < 0) /* use the much better glib random generator */ - randm = g_rand_int_range(cave->random, 0, 256); + randm = gd_rand_int_range(cave->random, 0, 256); else /* use c64 */ randm = gd_cave_c64_random(cave); diff --git a/src/game_bd/bd_gameplay.c b/src/game_bd/bd_gameplay.c index ea7017b8..a4b7e05b 100644 --- a/src/game_bd/bd_gameplay.c +++ b/src/game_bd/bd_gameplay.c @@ -328,8 +328,8 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean * this way the uncovering is the same speed also for intermissions. */ for (j = 0; j < game->cave->w * game->cave->h / 40; j++) { - y = g_random_int_range(0, game->cave->h); - x = g_random_int_range(0, game->cave->w); + y = gd_random_int_range(0, game->cave->h); + x = gd_random_int_range(0, game->cave->w); game->cave->map[y][x] &= ~COVERED; } @@ -530,7 +530,7 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean /* covering eight times faster than uncovering. */ for (j = 0; j < game->cave->w * game->cave->h * 8 / 40; j++) - game->cave->map[g_random_int_range(0, game->cave->h)][g_random_int_range (0, game->cave->w)] |= COVERED; + game->cave->map[gd_random_int_range(0, game->cave->h)][gd_random_int_range (0, game->cave->w)] |= COVERED; } return_state = GD_GAME_NOTHING; diff --git a/src/game_bd/bd_sound.c b/src/game_bd/bd_sound.c index 2087da4c..af024d95 100644 --- a/src/game_bd/bd_sound.c +++ b/src/game_bd/bd_sound.c @@ -333,13 +333,13 @@ static void play_sound(int channel, GdSound sound) /* change diamond falling random to a selected diamond falling sound. */ if (sound == GD_S_DIAMOND_FALLING_RANDOM) - sound = diamond_falling_sounds[g_random_int_range(0, 8)]; + sound = diamond_falling_sounds[gd_random_int_range(0, 8)]; else if (sound == GD_S_DIAMOND_IMPACT_RANDOM) - sound = diamond_impact_sounds[g_random_int_range(0, 8)]; + sound = diamond_impact_sounds[gd_random_int_range(0, 8)]; else if (sound == GD_S_FLYING_DIAMOND_FALLING_RANDOM) - sound = flying_diamond_falling_sounds[g_random_int_range(0, 8)]; + sound = flying_diamond_falling_sounds[gd_random_int_range(0, 8)]; else if (sound == GD_S_FLYING_DIAMOND_IMPACT_RANDOM) - sound = flying_diamond_impact_sounds[g_random_int_range(0, 8)]; + sound = flying_diamond_impact_sounds[gd_random_int_range(0, 8)]; /* channel 1 may have been changed to channel 4 above. */ diff --git a/src/game_bd/main_bd.c b/src/game_bd/main_bd.c index 68f0ec40..0ffea6be 100644 --- a/src/game_bd/main_bd.c +++ b/src/game_bd/main_bd.c @@ -243,7 +243,7 @@ unsigned int InitEngineRandom_BD(int seed) if (seed == NEW_RANDOMIZE) { // get randomly selected seed to render the cave - seed = g_random_int_range(0, GD_CAVE_SEED_MAX); + seed = gd_random_int_range(0, GD_CAVE_SEED_MAX); } game_bd.random_seed = seed;