[Freeciv-Dev] (PR#12892) load rulesets on startup
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12892 >
As requested in a number of other tickets (civworld, pregame nations,
etc.) this patch causes rulesets to be loaded on server startup.
1. The ruleset is loaded when the server starts.
2. The ruleset is no longer loaded when the game begins.
3. The ruleset must still be loaded when a savegame is loaded.
4. The ruleset must now be loaded inside /rulesetdir.
5. rulesets_load now calls ruleset_data_free to free any old data.
Although #4 makes /rulesetdir substantially slower, this is balanced
because /start is now faster. So for multiplayer games this should be a
slight improvement, and for most single-player games it won't make any
difference (since /rulesetdir is rare).
I also fixed some related and unrelated memory leaks so that #5 works
properly.
This patch works with the client but the rulesets still aren't sent to
clients immediately (not until game start). This change will also be
needed but should be done in a separate patch I think. I also didn't
check the client for memory leaks (likely the leaks I fixed will affect
the client as well).
-jason
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.30
diff -u -r1.30 effects.c
--- common/effects.c 21 Apr 2005 21:37:34 -0000 1.30
+++ common/effects.c 25 Apr 2005 22:10:12 -0000
@@ -375,7 +375,7 @@
}
for (i = 0; i < ARRAY_SIZE(ruleset_cache.effects); i++) {
- struct effect_list *plist = get_effects(i);
+ struct effect_list *plist = ruleset_cache.effects[i];
if (plist) {
effect_list_unlink_all(plist);
@@ -385,11 +385,7 @@
}
for (i = 0; i < ARRAY_SIZE(ruleset_cache.reqs.buildings); i++) {
- struct req_source source = {
- .type = REQ_BUILDING,
- .value = {.building = i}
- };
- struct effect_list *plist = get_req_source_effects(&source);
+ struct effect_list *plist = ruleset_cache.reqs.buildings[i];
if (plist) {
effect_list_unlink_all(plist);
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.206
diff -u -r1.206 game.c
--- common/game.c 23 Apr 2005 17:40:26 -0000 1.206
+++ common/game.c 25 Apr 2005 22:10:12 -0000
@@ -351,6 +351,7 @@
improvements_free();
city_styles_free();
tile_types_free();
+ ruleset_cache_free();
}
/***************************************************************
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.245
diff -u -r1.245 ruleset.c
--- server/ruleset.c 21 Apr 2005 00:28:28 -0000 1.245
+++ server/ruleset.c 25 Apr 2005 22:10:16 -0000
@@ -2046,6 +2046,7 @@
group = add_new_nation_group(name);
group->match = secfile_lookup_int_default(file, 0, "%s.match", groups[i]);
}
+ free(groups);
sec = secfile_get_secnames_prefix(file, "nation", &nval);
@@ -2058,6 +2059,7 @@
for (j = 0; j < dim; j++) {
pl->groups[j] = add_new_nation_group(groups[j]);
}
+ free(groups);
/* nation leaders */
@@ -3068,7 +3070,9 @@
}
/**************************************************************************
-...
+ Loads the ruleset currently given in game.rulesetdir.
+
+ This may be called more than once and it will free any stale data.
**************************************************************************/
void load_rulesets(void)
{
@@ -3077,6 +3081,8 @@
freelog(LOG_NORMAL, _("Loading rulesets"));
+ ruleset_data_free();
+
openload_ruleset_file(&techfile, "techs");
load_tech_names(&techfile);
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.245
diff -u -r1.245 srv_main.c
--- server/srv_main.c 13 Apr 2005 18:41:11 -0000 1.245
+++ server/srv_main.c 25 Apr 2005 22:10:17 -0000
@@ -1643,6 +1643,7 @@
game_init();
stdinhand_init();
diplhand_init();
+ load_rulesets(); /* May be reloaded later if the rulesetdir is changed. */
/* init network */
init_connections();
@@ -1742,11 +1743,6 @@
(void) send_server_info_to_metaserver(META_INFO);
- if (game.is_new_game) {
- load_rulesets();
- /* otherwise rulesets were loaded when savegame was loaded */
- }
-
nations_available
= fc_realloc(nations_available,
game.playable_nation_count * sizeof(*nations_available));
@@ -1958,6 +1954,5 @@
player_map_free(pplayer);
} players_iterate_end;
game_free();
- ruleset_cache_free();
BV_CLR_ALL(srvarg.draw);
}
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.396
diff -u -r1.396 stdinhand.c
--- server/stdinhand.c 20 Apr 2005 16:54:33 -0000 1.396
+++ server/stdinhand.c 25 Apr 2005 22:10:21 -0000
@@ -3273,6 +3273,7 @@
cmd_reply(CMD_RULESETDIR, caller, C_OK,
_("Ruleset directory set to \"%s\""), str);
sz_strlcpy(game.rulesetdir, str);
+ load_rulesets();
}
return TRUE;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12892) load rulesets on startup,
Jason Short <=
|
|