<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40561 >

Attached patch removes some struct fields in struct player
and struct tile that were only used by the server for editor
related support code. Instead, static data structures are
added to edithand.c which keep track of the necessary
information. This then requires the addition of edithand.h
(added to server/Makefile.am) and module initialization/
destruction functions edithand_{init,free}.


-----------------------------------------------------------------------
汚染削減委員会の作戦だった。
 common/map.c       |    1 -
 common/player.h    |    3 --
 common/tile.h      |    3 --
 server/Makefile.am |    1 +
 server/edithand.c  |   86 +++++++++++++++++++++++++++++++++++++--------------
 server/plrhand.c   |    1 -
 server/srv_main.c  |    3 ++
 7 files changed, 66 insertions(+), 32 deletions(-)

diff --git a/common/map.c b/common/map.c
index 27d372f..e5a6685 100644
--- a/common/map.c
+++ b/common/map.c
@@ -288,7 +288,6 @@ static void tile_init(struct tile *ptile)
   ptile->owner    = NULL; /* Not claimed by any player. */
   ptile->worked   = NULL; /* No city working here. */
   ptile->spec_sprite = NULL;
-  ptile->editor.need_terrain_fix = FALSE;
 }
 
 /****************************************************************************
diff --git a/common/player.h b/common/player.h
index a35400e..824cbaa 100644
--- a/common/player.h
+++ b/common/player.h
@@ -203,9 +203,6 @@ struct player {
   struct attribute_block_s attribute_block;
   struct attribute_block_s attribute_block_buffer;
   bv_debug debug;
-  struct {
-    bool fog_of_war_disabled;
-  } editor;
 };
 
 /* A slot is a possibly uninitialized player. */
diff --git a/common/tile.h b/common/tile.h
index 93e7a5d..8c886d0 100644
--- a/common/tile.h
+++ b/common/tile.h
@@ -46,9 +46,6 @@ struct tile {
   struct player *owner;			/* NULL for not owned */
   struct city *worked;			/* NULL for not worked */
   char *spec_sprite;
-  struct {
-    bool need_terrain_fix; /* Server only. */
-  } editor;
 };
 
 /* get 'struct tile_list' and related functions: */
diff --git a/server/Makefile.am b/server/Makefile.am
index 09f5812..7e570db 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -42,6 +42,7 @@ libcivserver_a_SOURCES = \
 		diplomats.c	\
 		diplomats.h	\
 		edithand.c	\
+		edithand.h	\
 		gamehand.c	\
 		gamehand.h	\
 		gotohand.c	\
diff --git a/server/edithand.c b/server/edithand.c
index a17a88d..15fad95 100644
--- a/server/edithand.c
+++ b/server/edithand.c
@@ -36,6 +36,7 @@
 #include "citytools.h"
 #include "cityturn.h"
 #include "connecthand.h"
+#include "edithand.h"
 #include "gamehand.h"
 #include "hand_gen.h"
 #include "maphand.h"
@@ -46,28 +47,65 @@
 #include "unittools.h"
 #include "utilities.h"
 
-/* The number of tiles for which expensive checks have
- * been deferred after their terrains have been edited. */
-static int unfixed_terrain_count;
+/* This table holds pointers to tiles for which expensive
+ * checks (e.g. assign_continent_numbers) have been left
+ * until after a sequence of edits is complete. */
+static struct hash_table *unfixed_tile_table;
 
+/* Array of size player_slot_count() indexed by player
+ * number to tell whether a given player has fog of war
+ * disabled in edit mode. */
+static bool *unfogged_players;
+
+/****************************************************************************
+  Initialize data structures required for edit mode.
+****************************************************************************/
+void edithand_init(void)
+{
+  if (unfixed_tile_table != NULL) {
+    hash_free(unfixed_tile_table);
+  }
+  unfixed_tile_table = hash_new(hash_fval_keyval, hash_fcmp_keyval);
+
+  if (!unfogged_players) {
+    free(unfogged_players);
+  }
+  unfogged_players = fc_calloc(player_slot_count(), sizeof(bool));
+}
+
+/****************************************************************************
+  Free all memory used by data structures required for edit mode.
+****************************************************************************/
+void edithand_free(void)
+{
+  if (unfixed_tile_table != NULL) {
+    hash_free(unfixed_tile_table);
+    unfixed_tile_table = NULL;
+  }
+
+  if (unfogged_players != NULL) {
+    free(unfogged_players);
+    unfogged_players = NULL;
+  }
+}
 
 /****************************************************************************
   Do the potentially slow checks required after some tile's terrain changes.
 ****************************************************************************/
 static void check_edited_tile_terrains(void)
 {
-  if (unfixed_terrain_count > 0) {
-    whole_map_iterate(ptile) {
-      if (!ptile->editor.need_terrain_fix) {
-        continue;
-      }
-      fix_tile_on_terrain_change(ptile, FALSE);
-      ptile->editor.need_terrain_fix = FALSE;
-    } whole_map_iterate_end;
-    assign_continent_numbers();
-    send_all_known_tiles(NULL);
+  if (hash_num_entries(unfixed_tile_table) < 1) {
+    return;
   }
-  unfixed_terrain_count = 0;
+
+  hash_iterate(unfixed_tile_table, ptile, dummy) {
+    fix_tile_on_terrain_change(ptile, FALSE);
+  } hash_iterate_end;
+
+  assign_continent_numbers();
+  send_all_known_tiles(NULL);
+
+  hash_delete_all_entries(unfixed_tile_table);
 }
 
 /****************************************************************************
@@ -76,16 +114,17 @@ static void check_edited_tile_terrains(void)
 ****************************************************************************/
 static void check_leaving_edit_mode(void)
 {
+  bool unfogged;
+
   conn_list_do_buffer(game.est_connections);
   players_iterate(pplayer) {
-    if (pplayer->editor.fog_of_war_disabled
-        && game.info.fogofwar) {
+    unfogged = unfogged_players[player_number(pplayer)];
+    if (unfogged && game.info.fogofwar) {
       enable_fog_of_war_player(pplayer);
-    } else if (!pplayer->editor.fog_of_war_disabled
-               && !game.info.fogofwar) {
+    } else if (!unfogged && !game.info.fogofwar) {
       disable_fog_of_war_player(pplayer);
     }
-    pplayer->editor.fog_of_war_disabled = FALSE;
+    unfogged_players[player_number(pplayer)] = FALSE;
   } players_iterate_end;
 
   check_edited_tile_terrains();
@@ -163,8 +202,7 @@ void handle_edit_tile_terrain(struct connection *pc, int x, int y,
     tile_change_terrain(ptile, pterrain);
 
     if (need_to_fix_terrain_change(old_terrain, pterrain)) {
-      ptile->editor.need_terrain_fix = TRUE;
-      unfixed_terrain_count++;
+      hash_insert(unfixed_tile_table, ptile, ptile);
     }
     update_tile_knowledge(ptile);
   } square_iterate_end;
@@ -1212,12 +1250,12 @@ void handle_edit_toggle_fogofwar(struct connection *pc, int plr_no)
   }
 
   conn_list_do_buffer(game.est_connections);
-  if (pplayer->editor.fog_of_war_disabled) {
+  if (unfogged_players[player_number(pplayer)]) {
     enable_fog_of_war_player(pplayer);
-    pplayer->editor.fog_of_war_disabled = FALSE;
+    unfogged_players[player_number(pplayer)] = FALSE;
   } else {
     disable_fog_of_war_player(pplayer);
-    pplayer->editor.fog_of_war_disabled = TRUE;
+    unfogged_players[player_number(pplayer)] = TRUE;
   }
   conn_list_do_unbuffer(game.est_connections);
 }
diff --git a/server/plrhand.c b/server/plrhand.c
index 110bd9e..507444a 100644
--- a/server/plrhand.c
+++ b/server/plrhand.c
@@ -1144,7 +1144,6 @@ void server_player_init(struct player *pplayer,
     team_add_player(pplayer, find_empty_team());
   }
   ai_data_init(pplayer);
-  pplayer->editor.fog_of_war_disabled = FALSE;
 }
 
 /********************************************************************** 
diff --git a/server/srv_main.c b/server/srv_main.c
index 856d35c..54a9dbc 100644
--- a/server/srv_main.c
+++ b/server/srv_main.c
@@ -79,6 +79,7 @@
 #include "connecthand.h"
 #include "console.h"
 #include "diplhand.h"
+#include "edithand.h"
 #include "gamehand.h"
 #include "ggzserver.h"
 #include "handchat.h"
@@ -1056,6 +1057,7 @@ void server_quit(void)
 #endif /* HAVE_AUTH */
 
   stdinhand_free();
+  edithand_free();
   voting_free();
   close_connections_and_socket();
   exit(EXIT_SUCCESS);
@@ -1943,6 +1945,7 @@ static void srv_prepare(void)
   con_flush();
 
   stdinhand_init();
+  edithand_init();
   voting_init();
   diplhand_init();
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to