X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_bd%2Fbd_bdcff.c;h=bc8c8015f55517c43992183eb5aa8d61e6e6ad10;hb=01bf4018243f57cefbc0308e49f4dd2d40a0c054;hp=8b7164b902cd83e82f505bcd86be440159a6726f;hpb=74980a61aa0aff2c56f46f7dbef8346c59509f4f;p=rocksndiamonds.git diff --git a/src/game_bd/bd_bdcff.c b/src/game_bd/bd_bdcff.c index 8b7164b9..bc8c8015 100644 --- a/src/game_bd/bd_bdcff.c +++ b/src/game_bd/bd_bdcff.c @@ -107,17 +107,17 @@ static boolean attrib_is_valid_for_cave(const char *attrib) int i; /* bdcff engine flag............ */ - if (strcasecmp(attrib, "Engine")==0) + if (strcasecmp(attrib, "Engine") == 0) return TRUE; /* old flags - for compatibility */ - if (strcasecmp(attrib, "BD1Scheduling")==0) + if (strcasecmp(attrib, "BD1Scheduling") == 0) return TRUE; - if (strcasecmp(attrib, "SnapExplosions")==0) + if (strcasecmp(attrib, "SnapExplosions") == 0) return TRUE; - if (strcasecmp(attrib, "AmoebaProperties")==0) + if (strcasecmp(attrib, "AmoebaProperties") == 0) return TRUE; /* search in property database */ @@ -151,7 +151,7 @@ static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_ boolean was_string; params = getSplitStringArray(param, " ", -1); - paramcount = g_strv_length(params); + paramcount = getStringArrayLength(params); identifier_found = FALSE; /* check all known tags. do not exit this loop if identifier_found == true... @@ -188,12 +188,10 @@ static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_ if (prop_desc[i].type == GD_TYPE_LONGSTRING) { - GString *str = *(GString **)value; - char *compressed; + char **str = (char **)value; - compressed = g_strcompress(param); - g_string_assign(str, compressed); - free(compressed); + checked_free(*str); + *str = getUnescapedString(param); /* remember this to skip checking the number of parameters at the end of the function */ was_string = TRUE; @@ -330,7 +328,7 @@ static boolean struct_set_property(gpointer str, const GdStructDescriptor *prop_ if (identifier_found && !was_string && paramindex < paramcount) Warn("excess parameters for attribute '%s': '%s'", attrib, params[paramindex]); - g_strfreev(params); + freeStringArray(params); return identifier_found; } @@ -352,7 +350,7 @@ static boolean replay_store_more_from_bdcff(GdReplay *replay, const char *param) for (i = 0; split[i] != 0; i++) result = result && replay_store_from_bdcff(replay, split[i]); - g_strfreev(split); + freeStringArray(split); return result; } @@ -389,10 +387,10 @@ static boolean replay_process_tags_func(const char *attrib, const char *param, G } /* ... */ -static void replay_process_tags(GdReplay *replay, GHashTable *tags) +static void replay_process_tags(GdReplay *replay, HashTable *tags) { /* process all tags */ - g_hash_table_foreach_remove(tags, (GHRFunc) replay_process_tags_func, replay); + hashtable_foreach_remove(tags, (hashtable_remove_fn)replay_process_tags_func, replay); } /* a GHashTable foreach func. @@ -482,7 +480,7 @@ static boolean cave_process_tags_func(const char *attrib, const char *param, GdC identifier_found = struct_set_property(cave, gd_cave_properties, attrib, param, cave->w * cave->h); } - g_strfreev(params); + freeStringArray(params); /* a ghrfunc should return true if the identifier is to be removed */ return identifier_found; @@ -495,33 +493,33 @@ static void cave_report_and_copy_unknown_tags_func(char *attrib, char *param, gp Warn("unknown tag '%s'", attrib); - g_hash_table_insert(cave->tags, g_strdup(attrib), g_strdup(param)); + hashtable_insert(cave->tags, getStringCopy(attrib), getStringCopy(param)); } /* having read all strings belonging to the cave, process it. */ -static void cave_process_tags(GdCave *cave, GHashTable *tags, GList *maplines) +static void cave_process_tags(GdCave *cave, HashTable *tags, List *maplines) { char *value; /* first check cave name, so we can report errors correctly (saying that GdCave xy: error foobar) */ - value = g_hash_table_lookup(tags, "Name"); + value = hashtable_search(tags, "Name"); if (value) cave_process_tags_func("Name", value, cave); /* process lame engine tag first so its settings may be overwritten later */ - value = g_hash_table_lookup(tags, "Engine"); + value = hashtable_search(tags, "Engine"); if (value) { cave_process_tags_func("Engine", value, cave); - g_hash_table_remove(tags, "Engine"); + hashtable_remove(tags, "Engine"); } /* check if this is an intermission, so we can set to cavesize or intermissionsize */ - value = g_hash_table_lookup(tags, "Intermission"); + value = hashtable_search(tags, "Intermission"); if (value) { cave_process_tags_func("Intermission", value, cave); - g_hash_table_remove(tags, "Intermission"); + hashtable_remove(tags, "Intermission"); } if (cave->intermission) @@ -546,39 +544,39 @@ static void cave_process_tags(GdCave *cave, GHashTable *tags, GList *maplines) } /* process size at the beginning... as ratio types depend on this. */ - value = g_hash_table_lookup(tags, "Size"); + value = hashtable_search(tags, "Size"); if (value) { cave_process_tags_func("Size", value, cave); - g_hash_table_remove(tags, "Size"); + hashtable_remove(tags, "Size"); } /* these are read from the hash table, but also have some implications */ /* we do not delete them from the hash table here; as _their values will be processed later_. */ /* here we only set their implicite meanings. */ /* these also set predictability */ - if (g_hash_table_lookup(tags, "SlimePermeability")) + if (hashtable_search(tags, "SlimePermeability")) cave->slime_predictable = FALSE; - if (g_hash_table_lookup(tags, "SlimePermeabilityC64")) + if (hashtable_search(tags, "SlimePermeabilityC64")) cave->slime_predictable = TRUE; /* these set scheduling type. framedelay takes precedence, if there are both; so we check it later. */ - if (g_hash_table_lookup(tags, "CaveDelay")) + if (hashtable_search(tags, "CaveDelay")) { /* only set scheduling type, when it is not the gdash-default. */ /* this allows settings cavescheduling = bd1 in the [game] section, for example. */ /* in that case, this one will not overwrite it. */ if (cave->scheduling == GD_SCHEDULING_MILLISECONDS) cave->scheduling = GD_SCHEDULING_PLCK; - } + } - if (g_hash_table_lookup(tags, "FrameTime")) + if (hashtable_search(tags, "FrameTime")) /* but if the cave has a frametime setting, always switch to milliseconds. */ cave->scheduling = GD_SCHEDULING_MILLISECONDS; /* process all tags */ - g_hash_table_foreach_remove(tags, (GHRFunc) cave_process_tags_func, cave); + hashtable_foreach_remove(tags, (hashtable_remove_fn)cave_process_tags_func, cave); /* and at the end, when read all tags (especially the size= tag) */ /* process map, if any. */ @@ -586,8 +584,8 @@ static void cave_process_tags(GdCave *cave, GHashTable *tags, GList *maplines) /* some old bdcff files use smaller intermissions than the one specified. */ if (maplines) { - int x, y, length = g_list_length(maplines); - GList *iter; + int x, y, length = list_length(maplines); + List *iter; /* create map and fill with initial border, in case that map strings are shorter or somewhat */ cave->map = gd_cave_map_new(cave, GdElement); @@ -644,7 +642,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) char **lines; int lineno; GdCave *cave; - GList *iter; + List *iter; boolean reading_replay = FALSE; boolean reading_map = FALSE; boolean reading_mapcodes = FALSE; @@ -653,9 +651,9 @@ boolean gd_caveset_load_from_bdcff(const char *contents) boolean reading_bdcff_demo = FALSE; /* assume version to be 0.32, also when the file does not specify it explicitly */ GdString version_read = "0.32"; - GList *mapstrings = NULL; + List *mapstrings = NULL; int linenum; - GHashTable *tags, *replay_tags; + HashTable *tags, *replay_tags; GdObjectLevels levels = GD_OBJECT_LEVEL_ALL; GdCave *default_cave; @@ -665,8 +663,8 @@ boolean gd_caveset_load_from_bdcff(const char *contents) set_intermissionsize_defaults(); gd_create_char_to_element_table(); - tags = g_hash_table_new_full(gd_str_case_hash, gd_str_case_equal, free, free); - replay_tags = g_hash_table_new_full(gd_str_case_hash, gd_str_case_equal, free, free); + tags = create_hashtable(gd_str_case_hash, gd_str_case_equal, free, free); + replay_tags = create_hashtable(gd_str_case_hash, gd_str_case_equal, free, free); /* split into lines */ lines = getSplitStringArray (contents, "\n", 0); @@ -676,7 +674,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) default_cave = gd_cave_new(); cave = default_cave; - linenum = g_strv_length(lines); + linenum = getStringArrayLength(lines); for (lineno = 0; lineno < linenum; lineno++) { @@ -703,7 +701,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) if (mapstrings) { Warn("incorrect file format: new [cave] section, but already read some map lines"); - g_list_free(mapstrings); + list_free(mapstrings); mapstrings = NULL; } @@ -712,17 +710,17 @@ boolean gd_caveset_load_from_bdcff(const char *contents) /* ... to be able to create a copy for a new cave. */ cave = gd_cave_new_from_cave(default_cave); - gd_caveset = g_list_append (gd_caveset, cave); + gd_caveset = list_append (gd_caveset, cave); } else if (strcasecmp(line, "[/cave]") == 0) { cave_process_tags(cave, tags, mapstrings); - g_list_free(mapstrings); + list_free(mapstrings); mapstrings = NULL; - if (g_hash_table_size(tags) != 0) - g_hash_table_foreach(tags, (GHFunc) cave_report_and_copy_unknown_tags_func, cave); - g_hash_table_remove_all(tags); + hashtable_foreach(tags, (hashtable_fn)cave_report_and_copy_unknown_tags_func, cave); + hashtable_remove_all(tags); + /* set this to point the pseudo-cave which holds default values */ cave = default_cave; } @@ -732,7 +730,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) if (mapstrings != NULL) { Warn("incorrect file format: new [map] section, but already read some map lines"); - g_list_free(mapstrings); + list_free(mapstrings); mapstrings = NULL; } } @@ -775,7 +773,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) replay = gd_replay_new(); replay->saved = TRUE; replay->success = TRUE; /* we think that it is a successful demo */ - cave->replays = g_list_append(cave->replays, replay); + cave->replays = list_append(cave->replays, replay); gd_strcpy(replay->player_name, "???"); /* name not saved */ } else @@ -809,12 +807,12 @@ boolean gd_caveset_load_from_bdcff(const char *contents) #endif /* report any remaining unknown tags */ - g_hash_table_foreach(replay_tags, (GHFunc) replay_report_unknown_tags_func, NULL); - g_hash_table_remove_all(replay_tags); + hashtable_foreach(replay_tags, (hashtable_fn)replay_report_unknown_tags_func, NULL); + hashtable_remove_all(replay_tags); if (replay->movements->len != 0) { - cave->replays = g_list_append(cave->replays, replay); + cave->replays = list_append(cave->replays, replay); } else { @@ -879,7 +877,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) if (reading_map) { /* just append to the mapstrings list. we will process it later */ - mapstrings = g_list_append(mapstrings, line); + mapstrings = list_append(mapstrings, line); continue; } @@ -914,13 +912,13 @@ boolean gd_caveset_load_from_bdcff(const char *contents) if (reading_bdcff_demo) { GdReplay *replay; - GList *iter; + List *iter; /* demo must be in [cave] section. we already showed an error message for this. */ if (cave == default_cave) continue; - iter = g_list_last(cave->replays); + iter = list_last(cave->replays); replay = (GdReplay *)iter->data; replay_store_more_from_bdcff(replay, line); @@ -936,7 +934,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) if (new_object) { new_object->levels = levels; /* apply levels to new object */ - cave->objects = g_list_append(cave->objects, new_object); + cave->objects = list_append(cave->objects, new_object); } else { @@ -958,7 +956,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) /* own tag: not too much thinking :P */ if (reading_replay) { - g_hash_table_insert(replay_tags, g_strdup(attrib), g_strdup(param)); + hashtable_insert(replay_tags, getStringCopy(attrib), getStringCopy(param)); } else if (reading_mapcodes) { @@ -1051,7 +1049,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) params = getSplitStringArray(param, " ", -1); /* an effect command has two parameters */ - if (g_strv_length(params) == 2) + if (getStringArrayLength(params) == 2) { int i; @@ -1095,7 +1093,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) else Warn("invalid effect specification '%s'", param); - g_strfreev(params); + freeStringArray(params); } else { @@ -1113,7 +1111,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) { /* it must be a default setting for all caves. is it a valid identifier? */ /* yes, it is. add to the hash table, which will be copied for all caves. */ - g_hash_table_insert(tags, g_strdup(attrib), g_strdup(param)); + hashtable_insert(tags, getStringCopy(attrib), getStringCopy(param)); } else /* unknown setting - report. */ @@ -1124,7 +1122,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) /* we are reading a [cave] */ /* cave settings are immediately added to cave hash table. */ /* if it is unknown, we have to remember it, and save it again. */ - g_hash_table_insert(tags, g_strdup(attrib), g_strdup(param)); + hashtable_insert(tags, getStringCopy(attrib), getStringCopy(param)); } } @@ -1137,7 +1135,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) if (mapstrings) { Warn("incorrect file format: end of file, but still have some map lines read"); - g_list_free(mapstrings); + list_free(mapstrings); mapstrings = NULL; } @@ -1149,9 +1147,9 @@ boolean gd_caveset_load_from_bdcff(const char *contents) Warn(_("Invalid BDCFF: [game] section has drawing objects defined")); /* cleanup */ - g_strfreev (lines); - g_hash_table_destroy(tags); - g_hash_table_destroy(replay_tags); + freeStringArray(lines); + hashtable_destroy(tags); + hashtable_destroy(replay_tags); gd_cave_free(default_cave); /* old bdcff files hack. explanation follows. */ @@ -1165,7 +1163,7 @@ boolean gd_caveset_load_from_bdcff(const char *contents) if (strEqual(version_read, "0.32")) { - GList *iter; + List *iter; Warn("No BDCFF version, or 0.32. Using unspecified-intermission-size hack."); @@ -1196,12 +1194,12 @@ boolean gd_caveset_load_from_bdcff(const char *contents) object.element = cave->initial_border; object.fill_element = cave->initial_border; - cave->objects = g_list_prepend(cave->objects, g_memdup(&object, sizeof(object))); + cave->objects = list_prepend(cave->objects, getMemCopy(&object, sizeof(object))); object.x1 = 19; object.y1 = 0; /* 19, as it is also the border */ - cave->objects = g_list_prepend(cave->objects, g_memdup(&object, sizeof(object))); /* another */ + cave->objects = list_prepend(cave->objects, getMemCopy(&object, sizeof(object))); /* another */ } } }