* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <glib.h>
-#include <glib/gi18n.h>
-
#include "main_bd.h"
{
int i;
- for (i = 1; i<G_N_ELEMENTS(direction_filename); i++)
+ for (i = 1; i < ARRAY_SIZE(direction_filename); i++)
if (strcasecmp(str, direction_filename[i]) == 0)
return (GdDirection) i;
{
int i;
- for (i = 0; i < G_N_ELEMENTS(scheduling_filename); i++)
+ for (i = 0; i < ARRAY_SIZE(scheduling_filename); i++)
if (strcasecmp(str, scheduling_filename[i]) == 0)
return (GdScheduling) i;
"properties" describes the structure and its pointers,
"defaults" are the pieces of data which will be copied to str.
*/
-void gd_struct_set_defaults_from_array(gpointer str,
+void gd_struct_set_defaults_from_array(void *str,
const GdStructDescriptor *properties,
GdPropertyDefault *defaults)
{
for (i = 0; defaults[i].offset != -1; i++)
{
- gpointer pvalue = G_STRUCT_MEMBER_P(str, defaults[i].offset);
+ void *pvalue = STRUCT_MEMBER_P(str, defaults[i].offset);
/* these point to the same, but to avoid the awkward cast syntax */
int *ivalue = pvalue;
GdElement *evalue = pvalue;
int i;
/* fill all with unknown */
- for (i = 0; i < G_N_ELEMENTS(gd_char_to_element); i++)
+ for (i = 0; i < ARRAY_SIZE(gd_char_to_element); i++)
gd_char_to_element[i] = O_UNKNOWN;
/* then set fixed characters */
}
/* search the element database for the specified character, and return the element. */
-GdElement gd_get_element_from_character (guint8 character)
+GdElement gd_get_element_from_character (byte character)
{
if (gd_char_to_element[character] != O_UNKNOWN)
return gd_char_to_element[character];
{
char *key;
- key = g_ascii_strup(gd_elements[i].filename, -1);
+ key = getStringToUpper(gd_elements[i].filename);
if (hashtable_exists(name_to_element, key)) /* hash value may be 0 */
Warn("Name %s already used for element %x", key, i);
/* search the element database for the specified name, and return the element */
GdElement gd_get_element_from_string (const char *string)
{
- char *upper = g_ascii_strup(string, -1);
+ char *upper = getStringToUpper(string);
void *value;
boolean found;
}
/* for quicksort. compares two highscores. */
-int gd_highscore_compare(gconstpointer a, gconstpointer b)
+int gd_highscore_compare(const void *a, const void *b)
{
const GdHighScore *ha = a;
const GdHighScore *hb = b;
qsort(highscores, GD_HIGHSCORE_NUM, sizeof(GdHighScore), gd_highscore_compare);
for (i = 0; i < GD_HIGHSCORE_NUM; i++)
- if (g_str_equal(highscores[i].name, name) && highscores[i].score == score)
+ if (strEqual(highscores[i].name, name) && highscores[i].score == score)
return i;
return -1;
allocate a cave map-like array, and initialize to zero.
one cell is cell_size bytes long.
*/
-gpointer gd_cave_map_new_for_cave(const GdCave *cave, const int cell_size)
+void *gd_cave_map_new_for_cave(const GdCave *cave, const int cell_size)
{
- gpointer *rows; /* this is void**, pointer to array of ... */
+ void **rows; /* this is void**, pointer to array of ... */
int y;
- rows = checked_malloc((cave->h) * sizeof(gpointer));
+ rows = checked_malloc((cave->h) * sizeof(void *));
rows[0] = checked_calloc(cell_size * cave->w * cave->h);
for (y = 1; y < cave->h; y++)
if map is null, this also returns null.
*/
-gpointer gd_cave_map_dup_size(const GdCave *cave, const gpointer map, const int cell_size)
+void *gd_cave_map_dup_size(const GdCave *cave, const void *map, const int cell_size)
{
- gpointer *rows;
- gpointer *maplines = (gpointer *)map;
+ void **rows;
+ void **maplines = (void **)map;
int y;
if (!map)
return NULL;
- rows = checked_malloc((cave->h) * sizeof(gpointer));
- rows[0] = getMemCopy (maplines[0], cell_size * cave->w * cave->h);
+ rows = checked_malloc((cave->h) * sizeof(void *));
+ rows[0] = get_memcpy (maplines[0], cell_size * cave->w * cave->h);
for (y = 1; y < cave->h; y++)
rows[y] = (char *)rows[0] + cell_size * cave->w * y;
return rows;
}
-void gd_cave_map_free(gpointer map)
+void gd_cave_map_free(void *map)
{
- gpointer *maplines = (gpointer *) map;
+ void **maplines = (void **) map;
if (!map)
return;
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++)
if (gd_cave_properties[i].type == GD_TYPE_LONGSTRING)
- checked_free(G_STRUCT_MEMBER(char *, cave, gd_cave_properties[i].offset));
+ checked_free(STRUCT_MEMBER(char *, cave, gd_cave_properties[i].offset));
/* map */
gd_cave_map_free(cave->map);
int i;
/* copy entire data */
- g_memmove(dest, src, sizeof(GdCave));
+ memmove(dest, src, sizeof(GdCave));
/* but duplicate dynamic data */
dest->tags = create_hashtable(gd_str_case_hash, gd_str_case_equal, free, free);
/* for longstrings */
for (i = 0; gd_cave_properties[i].identifier != NULL; i++)
if (gd_cave_properties[i].type == GD_TYPE_LONGSTRING)
- G_STRUCT_MEMBER(char *, dest, gd_cave_properties[i].offset) =
- getStringCopy(G_STRUCT_MEMBER(char *, src, gd_cave_properties[i].offset));
+ STRUCT_MEMBER(char *, dest, gd_cave_properties[i].offset) =
+ getStringCopy(STRUCT_MEMBER(char *, src, gd_cave_properties[i].offset));
/* no reason to copy this */
dest->objects_order = NULL;
dest->objects = NULL; /* new empty list */
for (iter = src->objects; iter != NULL; iter = iter->next) /* do a deep copy */
- dest->objects = list_append(dest->objects, getMemCopy (iter->data, sizeof (GdObject)));
+ dest->objects = list_append(dest->objects, get_memcpy (iter->data, sizeof (GdObject)));
}
/* copy replays */
/* 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. */
gd_c64_random_set_seed(&cave->c64_rand, seed1, seed2);
}
-/*
- select random colors for a given cave.
- this function will select colors so that they should look somewhat nice; for example
- brick walls won't be the darkest color, for example.
-*/
-static inline void swap(int *i1, int *i2)
-{
- int t = *i1;
- *i1 = *i2;
- *i2 = t;
-}
-
/*
shrink cave
if last line or last row is just steel wall (or (invisible) outbox).
{
/* 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;
}
}
GdReplay *rep;
rep = checked_calloc(sizeof(GdReplay));
-
- rep->movements = g_byte_array_new();
+ rep->movements = checked_calloc(sizeof(GdReplayMovements));
return rep;
}
{
GdReplay *rep;
- rep = getMemCopy(orig, sizeof(GdReplay));
+ rep = get_memcpy(orig, sizeof(GdReplay));
/* replicate dynamic data */
rep->comment = getStringCopy(orig->comment);
- rep->movements = g_byte_array_new();
- g_byte_array_append(rep->movements, orig->movements->data, orig->movements->len);
+ rep->movements = get_memcpy(orig->movements, sizeof(GdReplayMovements));
return rep;
}
void gd_replay_free(GdReplay *replay)
{
- g_byte_array_free(replay->movements, TRUE);
+ checked_free(replay->movements);
checked_free(replay->comment);
free(replay);
}
void gd_replay_store_movement(GdReplay *replay, GdDirection player_move,
boolean player_fire, boolean suicide)
{
- guint8 data[1];
+ byte data[1];
data[0] = ((player_move) |
(player_fire ? GD_REPLAY_FIRE_MASK : 0) |
(suicide ? GD_REPLAY_SUICIDE_MASK : 0));
- g_byte_array_append(replay->movements, data, 1);
+ if (replay->movements->len < MAX_REPLAY_LEN)
+ {
+ replay->movements->data[replay->movements->len++] = data[0];
+
+ if (replay->movements->len == MAX_REPLAY_LEN)
+ Warn("BD replay truncated: size exceeds maximum replay size %d", MAX_REPLAY_LEN);
+ }
}
/* calculate adler checksum for a rendered cave; this can be used for more caves. */
-void gd_cave_adler_checksum_more(GdCave *cave, guint32 *a, guint32 *b)
+void gd_cave_adler_checksum_more(GdCave *cave, unsigned int *a, unsigned int *b)
{
int x, y;
}
/* calculate adler checksum for a single rendered cave. */
-guint32
-gd_cave_adler_checksum(GdCave *cave)
+unsigned int gd_cave_adler_checksum(GdCave *cave)
{
- guint32 a = 1;
- guint32 b = 0;
+ unsigned int a = 1;
+ unsigned int b = 0;
gd_cave_adler_checksum_more(cave, &a, &b);
return (b << 16) + a;