Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4691) replace regular_map_pos_is_normal users with nat
Home

[Freeciv-Dev] (PR#4691) replace regular_map_pos_is_normal users with nat

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4691) replace regular_map_pos_is_normal users with native coordinates
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Jul 2003 13:13:09 -0700
Reply-to: rt@xxxxxxxxxxxxxx

This patch removes the regular_map_pos_is_normal macro, and replaces its 
users (in savegame.c) with native coordinates instead.

This means the savegames will be stored in native coordinates.  For an 
iso-map this is a big savings versus using map coordinates since the 
native coordinates are rectangular.

jason

Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.151
diff -u -r1.151 map.h
--- common/map.h        2003/07/23 20:24:36     1.151
+++ common/map.h        2003/07/25 20:10:35
@@ -280,13 +280,6 @@
 bool contains_special(enum tile_special_type all,
                      enum tile_special_type to_test_for);
 
-/* 
- * Determines whether the position is normal given that it's in the
- * range 0<=x<map.xsize and 0<=y<map.ysize.  It's primarily a faster
- * version of is_normal_map_pos since such checks are pretty common.
- */
-#define regular_map_pos_is_normal(x, y) (TRUE)
-
 /*
  * A "border position" is any one that _may have_ positions within
  * map distance dist that are non-normal.  To see its correctness,
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.127
diff -u -r1.127 savegame.c
--- server/savegame.c   2003/07/23 13:46:04     1.127
+++ server/savegame.c   2003/07/25 20:10:35
@@ -56,30 +56,34 @@
 /* 
  * This loops over the entire map to save data. It collects all the
  * data of a line using get_xy_char and then executes the
- * secfile_insert_line code. The macro provides the variables x and y
- * and line. Parameter:
+ * secfile_insert_line code. The macro provides the variables x and y,
+ * nat_x and nat_y, and line.  The data is stored in a native format,
+ * e.g. aligned with (nat_x, nat_y).  (x,y) provides the map position for
+ * a saved tile.
+ *
+ * Parameters:
  * - get_xy_char: code that returns the character for each (x, y)
- * coordinate.
- *  - secfile_insert_line: code which is executed every time a line is
- *  processed
+ *   coordinate.
+ * - secfile_insert_line: code which is executed every time a line is
+ *   processed
+ *
+ * Note: don't use this macro, use SAVE_NORMAL_MAP_DATA/SAVE_PLAYER_MAP_DATA
+ * instead.
  */
-
 #define SAVE_MAP_DATA(get_xy_char, secfile_insert_line) \
 {                                                       \
   char *line = fc_malloc(map.xsize + 1);                \
-  int x, y;                                             \
+  int nat_x, nat_y;                                     \
+                                                        \
+  for (nat_y = 0; nat_y < map.ysize; nat_y++) {         \
+    for (nat_x = 0; nat_x < map.xsize; nat_x++) {       \
+      int x, y; /* map position */                      \
                                                         \
-  for (y = 0; y < map.ysize; y++) {                     \
-    for (x = 0; x < map.xsize; x++) {                   \
-      if (regular_map_pos_is_normal(x, y)) {            \
-       line[x] = get_xy_char;                          \
-        if(!my_isprint(line[x] & 0x7f)) {               \
+      native_to_map_pos(&x, &y, nat_x, nat_y);          \
+      line[nat_x] = get_xy_char;                        \
+      if(!my_isprint(line[nat_x] & 0x7f)) {             \
           die("Trying to write invalid map "            \
-              "data: '%c' %d", line[x], line[x]);       \
-        }                                               \
-      } else {                                          \
-        /* skipped over in loading */                   \
-       line[x] = '#';                                  \
+            "data: '%c' %d", line[nat_x], line[nat_x]); \
       }                                                 \
     }                                                   \
     line[map.xsize] = '\0';                             \
@@ -88,40 +92,50 @@
   free(line);                                           \
 }
 
+/*
+ * Wrappers for SAVE_MAP_DATA.
+ *
+ * SAVE_NORMAL_MAP_DATA saves a standard line of map data.
+ *
+ * SAVE_PLAYER_MAP_DATA saves a line of map data from a playermap.
+ */
 #define SAVE_NORMAL_MAP_DATA(secfile, get_xy_char, secfile_name)          \
        SAVE_MAP_DATA(get_xy_char,                                        \
-                     secfile_insert_str(secfile, line, secfile_name, y))
+                     secfile_insert_str(secfile, line, secfile_name, nat_y))
 
 #define SAVE_PLAYER_MAP_DATA(secfile, get_xy_char, secfile_name, plrno)   \
        SAVE_MAP_DATA(get_xy_char,                                        \
                      secfile_insert_str(secfile, line, secfile_name,     \
-                                        plrno, y))
+                                        plrno, nat_y))
 
-/* This loops over the entire map to load data. It loads all the data
+/*
+ * Loop over the entire map to load data. It loads all the data
  * of a line using secfile_lookup_line and then executes the
  * set_xy_char code for every position in that line. The macro
- * provides the variables x and y and ch (ch is the current character
- * of the line). Parameters:
+ * provides the variables x and y and ch (ch is the current character of the
+ * line).
+ *
+ * Parameters:
  * - set_xy_char: code that sets the character for each (x, y)
- * coordinate.
- *  - secfile_lookup_line: code which is executed every time a line is
- *  processed; it returns a char* for the line */
-
-/* Note: some (but not all) of the code this is replacing used to
+ *   coordinate.
+ * - secfile_lookup_line: code which is executed every time a line is
+ *   processed; it returns a char* for the line.
+ *
+ * Note: some (but not all) of the code this is replacing used to
  * skip over lines that did not exist.  This allowed for
  * backward-compatibility.  We could add another parameter that
  * specified whether it was OK to skip the data, but there's not
  * really much advantage to exiting early in this case.  Instead,
  * we let any map data type to be empty, and just print an
- * informative warning message about it. */
-
+ * informative warning message about it.
+ */
 #define LOAD_MAP_DATA(secfile_lookup_line, set_xy_char)                       \
 {                                                                             \
-  int y;                                                                      \
+  int nat_x, nat_y;                                                           \
   bool warning_printed = FALSE;                                               \
-  for (y = 0; y < map.ysize; y++) {                                           \
+  for (nat_y = 0; nat_y < map.ysize; nat_y++) {                               \
+    int x, y = nat_y; /* secfile_lookup_line may access y */                  \
     char *line = secfile_lookup_line;                                         \
-    int x;                                                                    \
     if (!line || strlen(line) != map.xsize) {                                 \
       if(!warning_printed) {                                                  \
         freelog(LOG_ERROR, _("The save file contains incomplete "             \
@@ -141,13 +155,12 @@
       }                                                                       \
       continue;                                                               \
     }                                                                         \
-    for(x = 0; x < map.xsize; x++) {                                          \
-      char ch = line[x];                                                      \
-      if (regular_map_pos_is_normal(x, y)) {                                  \
-        set_xy_char;                                                          \
-      } else {                                                                \
-        assert(ch == '#');                                                    \
-      }                                                                       \
+    for (nat_x = 0; nat_x < map.xsize; nat_x++) {                             \
+      char ch = line[nat_x];                                                  \
+                                                                              \
+      native_to_map_pos(&x, &y, nat_x, nat_y);                                \
+      /* set_xy_char may access (x,y) in map coordinates */                   \
+      set_xy_char;                                                            \
     }                                                                         \
   }                                                                           \
 }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#4691) replace regular_map_pos_is_normal users with native coordinates, Jason Short <=