Author: cazfi
Date: Thu Jan  5 20:58:05 2017
New Revision: 34793

URL: http://svn.gna.org/viewcvs/freeciv?rev=34793&view=rev
Log:
Give map as parameter to map_init(), map_free(), and map_allocate()

See patch #8055

Modified:
    trunk/client/packhand.c
    trunk/common/game.c
    trunk/common/map.c
    trunk/common/map.h
    trunk/server/generator/mapgen.c
    trunk/server/savegame2.c
    trunk/server/savegame3.c
    trunk/server/srv_main.c

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=34793&r1=34792&r2=34793&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Thu Jan  5 20:58:05 2017
@@ -2000,7 +2000,8 @@
 void handle_map_info(int xsize, int ysize, int topology_id)
 {
   if (!map_is_empty()) {
-    map_free();
+    map_free(&(wld.map));
+    free_city_map_index();
   }
 
   wld.map.xsize = xsize;
@@ -2013,7 +2014,7 @@
   wld.map.topology_id = topology_id;
 
   map_init_topology();
-  map_allocate();
+  main_map_allocate();
   client_player_maps_reset();
   init_client_goto();
   mapdeco_init();

Modified: trunk/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/game.c?rev=34793&r1=34792&r2=34793&view=diff
==============================================================================
--- trunk/common/game.c (original)
+++ trunk/common/game.c Thu Jan  5 20:58:05 2017
@@ -436,7 +436,7 @@
 {
   game_defaults();
   player_slots_init();
-  map_init();
+  map_init(&wld.map, is_server());
   team_slots_init();
   game_ruleset_init();
   idex_init();
@@ -465,7 +465,8 @@
 void game_free(void)
 {
   player_slots_free();
-  map_free();
+  map_free(&(wld.map));
+  free_city_map_index();
   idex_free();
   team_slots_free();
   game_ruleset_free();
@@ -488,10 +489,11 @@
       player_clear(pplayer, FALSE);
     } players_iterate_end;
 
-    map_free();
+    map_free(&(wld.map));
+    free_city_map_index();
     idex_free();
 
-    map_init();
+    map_init(&wld.map, FALSE);
     idex_init();
     researches_init();
   }

Modified: trunk/common/map.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/map.c?rev=34793&r1=34792&r2=34793&view=diff
==============================================================================
--- trunk/common/map.c  (original)
+++ trunk/common/map.c  Thu Jan  5 20:58:05 2017
@@ -150,46 +150,46 @@
 }
 
 /***************************************************************
- put some sensible values into the map structure
+  Put some sensible values into the map structure
 ***************************************************************/
-void map_init(void)
-{
-  wld.map.topology_id = MAP_DEFAULT_TOPO;
-  wld.map.num_continents = 0;
-  wld.map.num_oceans = 0;
-  wld.map.tiles = NULL;
-  wld.map.startpos_table = NULL;
-  wld.map.iterate_outwards_indices = NULL;
+void map_init(struct civ_map *imap, bool server_side)
+{
+  imap->topology_id = MAP_DEFAULT_TOPO;
+  imap->num_continents = 0;
+  imap->num_oceans = 0;
+  imap->tiles = NULL;
+  imap->startpos_table = NULL;
+  imap->iterate_outwards_indices = NULL;
 
   /* The [xy]size values are set in map_init_topology.  It is initialized
    * to a non-zero value because some places erronously use these values
    * before they're initialized. */
-  wld.map.xsize = MAP_DEFAULT_LINEAR_SIZE;
-  wld.map.ysize = MAP_DEFAULT_LINEAR_SIZE;
-
-  if (is_server()) {
-    wld.map.server.mapsize = MAP_DEFAULT_MAPSIZE;
-    wld.map.server.size = MAP_DEFAULT_SIZE;
-    wld.map.server.tilesperplayer = MAP_DEFAULT_TILESPERPLAYER;
-    wld.map.server.seed_setting = MAP_DEFAULT_SEED;
-    wld.map.server.seed = MAP_DEFAULT_SEED;
-    wld.map.server.riches = MAP_DEFAULT_RICHES;
-    wld.map.server.huts = MAP_DEFAULT_HUTS;
-    wld.map.server.huts_absolute = -1;
-    wld.map.server.animals = MAP_DEFAULT_ANIMALS;
-    wld.map.server.landpercent = MAP_DEFAULT_LANDMASS;
-    wld.map.server.wetness = MAP_DEFAULT_WETNESS;
-    wld.map.server.steepness = MAP_DEFAULT_STEEPNESS;
-    wld.map.server.generator = MAP_DEFAULT_GENERATOR;
-    wld.map.server.startpos = MAP_DEFAULT_STARTPOS;
-    wld.map.server.tinyisles = MAP_DEFAULT_TINYISLES;
-    wld.map.server.separatepoles = MAP_DEFAULT_SEPARATE_POLES;
-    wld.map.server.single_pole = MAP_DEFAULT_SINGLE_POLE;
-    wld.map.server.alltemperate = MAP_DEFAULT_ALLTEMPERATE;
-    wld.map.server.temperature = MAP_DEFAULT_TEMPERATURE;
-    wld.map.server.have_huts = FALSE;
-    wld.map.server.have_resources = FALSE;
-    wld.map.server.team_placement = MAP_DEFAULT_TEAM_PLACEMENT;
+  imap->xsize = MAP_DEFAULT_LINEAR_SIZE;
+  imap->ysize = MAP_DEFAULT_LINEAR_SIZE;
+
+  if (server_side) {
+    imap->server.mapsize = MAP_DEFAULT_MAPSIZE;
+    imap->server.size = MAP_DEFAULT_SIZE;
+    imap->server.tilesperplayer = MAP_DEFAULT_TILESPERPLAYER;
+    imap->server.seed_setting = MAP_DEFAULT_SEED;
+    imap->server.seed = MAP_DEFAULT_SEED;
+    imap->server.riches = MAP_DEFAULT_RICHES;
+    imap->server.huts = MAP_DEFAULT_HUTS;
+    imap->server.huts_absolute = -1;
+    imap->server.animals = MAP_DEFAULT_ANIMALS;
+    imap->server.landpercent = MAP_DEFAULT_LANDMASS;
+    imap->server.wetness = MAP_DEFAULT_WETNESS;
+    imap->server.steepness = MAP_DEFAULT_STEEPNESS;
+    imap->server.generator = MAP_DEFAULT_GENERATOR;
+    imap->server.startpos = MAP_DEFAULT_STARTPOS;
+    imap->server.tinyisles = MAP_DEFAULT_TINYISLES;
+    imap->server.separatepoles = MAP_DEFAULT_SEPARATE_POLES;
+    imap->server.single_pole = MAP_DEFAULT_SINGLE_POLE;
+    imap->server.alltemperate = MAP_DEFAULT_ALLTEMPERATE;
+    imap->server.temperature = MAP_DEFAULT_TEMPERATURE;
+    imap->server.have_huts = FALSE;
+    imap->server.have_resources = FALSE;
+    imap->server.team_placement = MAP_DEFAULT_TEAM_PLACEMENT;
   }
 }
 
@@ -482,7 +482,7 @@
   Allocate space for map, and initialise the tiles.
   Uses current map.xsize and map.ysize.
 **************************************************************************/
-void map_allocate(void)
+void map_allocate(struct civ_map *amap)
 {
   log_debug("map_allocate (was %p) (%d,%d)",
             (void *) wld.map.tiles, wld.map.xsize, wld.map.ysize);
@@ -499,37 +499,43 @@
     tile_init(ptile);
   } whole_map_iterate_end;
 
+  if (wld.map.startpos_table != NULL) {
+    startpos_hash_destroy(wld.map.startpos_table);
+  }
+  wld.map.startpos_table = startpos_hash_new();
+}
+
+/***************************************************************
+  Allocate main map and related global structures.
+***************************************************************/
+void main_map_allocate(void)
+{
+  map_allocate(&(wld.map));
   generate_city_map_indices();
   generate_map_indices();
-
-  if (wld.map.startpos_table != NULL) {
-    startpos_hash_destroy(wld.map.startpos_table);
-  }
-  wld.map.startpos_table = startpos_hash_new();
 }
 
 /***************************************************************
   Frees the allocated memory of the map.
 ***************************************************************/
-void map_free(void)
-{
-  if (wld.map.tiles) {
+void map_free(struct civ_map *fmap)
+{
+  if (fmap->tiles) {
     /* it is possible that map_init was called but not map_allocate */
 
-    whole_map_iterate(&(wld.map), ptile) {
+    whole_map_iterate(fmap, ptile) {
       tile_free(ptile);
     } whole_map_iterate_end;
 
-    free(wld.map.tiles);
-    wld.map.tiles = NULL;
-
-    if (wld.map.startpos_table) {
-      startpos_hash_destroy(wld.map.startpos_table);
-      wld.map.startpos_table = NULL;
-    }
-
-    FC_FREE(wld.map.iterate_outwards_indices);
-    free_city_map_index();
+    free(fmap->tiles);
+    fmap->tiles = NULL;
+
+    if (fmap->startpos_table) {
+      startpos_hash_destroy(fmap->startpos_table);
+      fmap->startpos_table = NULL;
+    }
+
+    FC_FREE(fmap->iterate_outwards_indices);
   }
 }
 

Modified: trunk/common/map.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/map.h?rev=34793&r1=34792&r2=34793&view=diff
==============================================================================
--- trunk/common/map.h  (original)
+++ trunk/common/map.h  Thu Jan  5 20:58:05 2017
@@ -47,10 +47,11 @@
 #define ALL_DIRECTIONS_CARDINAL() topo_has_flag((CURRENT_TOPOLOGY), TF_HEX)
 
 bool map_is_empty(void);
-void map_init(void);
+void map_init(struct civ_map *imap, bool server_side);
 void map_init_topology(void);
-void map_allocate(void);
-void map_free(void);
+void map_allocate(struct civ_map *amap);
+void main_map_allocate(void);
+void map_free(struct civ_map *fmap);
 
 int map_vector_to_real_distance(int dx, int dy);
 int map_vector_to_sq_distance(int dx, int dy);

Modified: trunk/server/generator/mapgen.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/generator/mapgen.c?rev=34793&r1=34792&r2=34793&view=diff
==============================================================================
--- trunk/server/generator/mapgen.c     (original)
+++ trunk/server/generator/mapgen.c     Thu Jan  5 20:58:05 2017
@@ -1290,7 +1290,7 @@
     generator_init_topology(autosize);
     /* Map can be already allocated, if we failed first map generation */
     if (map_is_empty()) {
-      map_allocate();
+      main_map_allocate();
     }
     adjust_terrain_param();
     /* if one mapgenerator fails, it will choose another mapgenerator */

Modified: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=34793&r1=34792&r2=34793&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Thu Jan  5 20:58:05 2017
@@ -1886,7 +1886,7 @@
   map_init_topology();
 
   /* Allocate map. */
-  map_allocate();
+  main_map_allocate();
 
   /* get the terrain type */
   LOAD_MAP_CHAR(ch, ptile, ptile->terrain = char2terrain(ch), loading->file,

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=34793&r1=34792&r2=34793&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Thu Jan  5 20:58:05 2017
@@ -2486,7 +2486,7 @@
   map_init_topology();
 
   /* Allocate map. */
-  map_allocate();
+  main_map_allocate();
 
   /* get the terrain type */
   LOAD_MAP_CHAR(ch, ptile, ptile->terrain = char2terrain(ch), loading->file,

Modified: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=34793&r1=34792&r2=34793&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Thu Jan  5 20:58:05 2017
@@ -2951,7 +2951,8 @@
         wld.map.server.have_resources = FALSE;
 
         /* Remove old information already present in tiles */
-        map_free();
+        map_free(&(wld.map));
+        free_city_map_index();
         /* Restore the settings. */
         for (set = 0; set < ARRAY_SIZE(mapgen_settings); set++) {
           struct setting *pset = setting_by_name(mapgen_settings[set].name);
@@ -2970,7 +2971,7 @@
                         error);
 #endif /* FREECIV_NDEBUG */
         }
-        map_allocate(); /* NOT map_init() as that would overwrite settings */
+        main_map_allocate(); /* NOT map_init() as that would overwrite 
settings */
       }
     }
     if (!created) {


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to