[Freeciv-Dev] (PR#14827) save ppms of map in the server
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=14827 >
to make animated gifs in viewgame.phtml, we currently make ppms of the maps
from savegames, then after some manipulation, do ppm2gif to make the gif.
This patch moves the ppm-making into the server. This allows for less
processor time and less screwups in keeping the ppm-maker uptodate. To turn
it on, pass -Ppm to the server on the command line. The ppms should be put
wherever the savegames are.
-mike
Index: server/civserver.c
===================================================================
--- server/civserver.c (revision 11340)
+++ server/civserver.c (working copy)
@@ -169,6 +169,8 @@
srvarg.auth_allow_guests = TRUE;
} else if (is_option("--Newusers", argv[inx])) {
srvarg.auth_allow_newusers = TRUE;
+ } else if (is_option("--Ppm", argv[inx])) {
+ srvarg.save_ppm = TRUE;
} else if ((option = get_option_malloc("--Serverid", argv, &inx, argc))) {
sz_strlcpy(srvarg.serverid, option);
free(option);
@@ -229,6 +231,8 @@
_(" -s, --saves DIR\tSave games to directory DIR\n"));
fc_fprintf(stderr,
_(" -S, --Serverid ID\tSets the server id to ID\n"));
+ fc_fprintf(stderr,
+ _(" -P, --Ppm\t\tSave ppms of the map when saving the game.\n"));
fc_fprintf(stderr, _(" -r, --read FILE\tRead startup script FILE\n"));
fc_fprintf(stderr, _(" -v, --version\t\tPrint the version number\n"));
fc_fprintf(stderr, _("Report bugs to <%s>.\n"), BUG_EMAIL_ADDRESS);
Index: server/score.c
===================================================================
--- server/score.c (revision 11340)
+++ server/score.c (working copy)
@@ -20,9 +20,12 @@
#include "game.h"
#include "improvement.h"
+#include "log.h"
#include "map.h"
#include "mem.h"
#include "player.h"
+#include "srv_main.h"
+#include "shared.h"
#include "score.h"
#include "unit.h"
@@ -338,3 +341,69 @@
return count;
}
+
+/**************************************************************************
+ save a ppm file which is a representation of the map of the current turn.
+ this can later be turned into a animated gif.
+
+ terrain type, units, and cities are saved.
+**************************************************************************/
+void save_ppm(void)
+{
+ char filename[600];
+ char tmpname[600];
+ FILE *fp;
+ int i, j;
+
+ /* put this file in the same place we put savegames */
+ my_snprintf(filename, sizeof(filename),
+ "%s%+05d.int.ppm", game.save_name, game.info.year);
+
+ /* Ensure the saves directory exists. */
+ make_dir(srvarg.saves_pathname);
+
+ sz_strlcpy(tmpname, srvarg.saves_pathname);
+ if (tmpname[0] != '\0') {
+ sz_strlcat(tmpname, "/");
+ }
+ sz_strlcat(tmpname, filename);
+ sz_strlcpy(filename, tmpname);
+
+ fp = fopen(filename, "w");
+
+ if (!fp) {
+ freelog(LOG_ERROR, "couldn't open file ppm save: %s\n", filename);
+ return;
+ }
+
+ fprintf(fp, "P3\n# An intermediate map from saved Freeciv game %s%+05d\n",
+ game.save_name, game.info.year);
+
+ for (i = 0; i < game.info.nplayers; i++) {
+ struct player *pplayer = get_player(i);
+ fprintf(fp, "# playerno:%d:race:%d:name:\"%s\"\n", pplayer->player_no,
+ pplayer->nation->index, pplayer->name);
+ }
+ terrain_type_iterate(pterrain) {
+ fprintf(fp, "# terrain:%d:name:\"%s\"\n", pterrain->index, pterrain->name);
+ } terrain_type_iterate_end;
+
+ fprintf(fp, "%d %d\n", map.xsize, map.ysize);
+ fprintf(fp, "255\n");
+
+ for (j = 0; j < map.ysize; j++) {
+ for (i = 0; i < map.xsize; i++) {
+ struct tile *ptile = native_pos_to_tile(i, j);
+ int R, G, B;
+
+ R = (ptile->city) ? city_owner(ptile->city)->nation->index + 1 : 0;
+ G = (unit_list_size(ptile->units) > 0) ?
+ unit_owner(unit_list_get(ptile->units, 0))->nation->index + 1 : 0;
+ B = tile_get_terrain(ptile)->index;
+
+ fprintf(fp, "%d %d %d\n", R, G, B);
+ }
+ }
+
+ fclose(fp);
+}
Index: server/srv_main.c
===================================================================
--- server/srv_main.c (revision 11340)
+++ server/srv_main.c (working copy)
@@ -186,6 +186,8 @@
srvarg.auth_allow_guests = FALSE;
srvarg.auth_allow_newusers = FALSE;
+ srvarg.save_ppm = FALSE;
+
/* mark as initialized */
has_been_srv_init = TRUE;
@@ -824,6 +826,7 @@
my_snprintf(filename, sizeof(filename),
"%s%+05d.sav", game.save_name, game.info.year);
save_game(filename, save_reason);
+ save_ppm();
gamelog(GAMELOG_STATUS);
}
Index: server/score.h
===================================================================
--- server/score.h (revision 11340)
+++ server/score.h (working copy)
@@ -19,4 +19,6 @@
int total_player_citizens(const struct player *pplayer);
+void save_ppm(void);
+
#endif /* FC__SCORE_H */
Index: server/srv_main.h
===================================================================
--- server/srv_main.h (revision 11340)
+++ server/srv_main.h (working copy)
@@ -39,6 +39,8 @@
char *script_filename;
char *saves_pathname;
char serverid[256];
+ /* save a ppm of the map? */
+ bool save_ppm;
/* quit if there no players after a given time interval */
int quitidle;
/* exit the server on game ending */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#14827) save ppms of map in the server,
Mike Kaufman <=
|
|