Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2003:
[Freeciv-Dev] (PR#4710) introduce map topology check macros
Home

[Freeciv-Dev] (PR#4710) introduce map topology check macros

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#4710) introduce map topology check macros
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 28 Jul 2003 06:51:02 -0700
Reply-to: rt@xxxxxxxxxxxxxx

The attached patch introduces three new macros: map_is_isometric(), 
map_has_wrapx(), and map_has_wrapy().

These are used by the calling code to check these three boolean conditions.

map_is_isometric() - return TRUE iff the underlying map is isometric

map_has_wrapx() - return TRUE iff the map wraps in the X (E-W) direction

map_has_wrapy() - return TRUE iff the map wraps in the Y (N-S) direction

One user is also introduced: nearest_real_pos.  In the process this 
function is cleaned up a little (using CLIP and normalize_map_pos as 
helper functions).

Currently the macro return values are hard-coded as TRUE or FALSE.  This 
means the compiled calling code should not be changed at all by using 
these macros (unless it's changed in other ways, of course - e.g., the 
cleanup in this case).  Once all code checks the values this can be 
changed so that they check a map variable to get their return value.

jason

Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.141
diff -u -r1.141 map.c
--- common/map.c        2003/07/23 13:46:03     1.141
+++ common/map.c        2003/07/28 13:45:58
@@ -1352,15 +1352,20 @@
 **************************************************************************/
 void nearest_real_pos(int *x, int *y)
 {
-  if (*y < 0)
-    *y = 0;
-  else if (*y >= map.ysize)
-    *y = map.ysize - 1;
-  
-  while (*x < 0)
-    *x += map.xsize;
-  while (*x >= map.xsize)
-    *x -= map.xsize;
+  int nat_x, nat_y;
+
+  map_to_native_pos(&nat_x, &nat_y, *x, *y);
+  if (!map_has_wrapx()) {
+    nat_x = CLIP(0, nat_x, map.xsize - 1);
+  }
+  if (!map_has_wrapy()) {
+    nat_y = CLIP(0, nat_y, map.ysize - 1);
+  }
+  native_to_map_pos(x, y, nat_x, nat_y);
+
+  if (!normalize_map_pos(x, y)) {
+    assert(FALSE);
+  }
 }
 
 /**************************************************************************
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/28 13:45:58
@@ -180,6 +180,10 @@
   struct map_position *start_positions;        /* allocated at runtime */
 };
 
+#define map_is_isometric() (FALSE)
+#define map_has_wrapx() (TRUE)
+#define map_has_wrapy() (FALSE)
+
 bool map_is_empty(void);
 void map_init(void);
 void map_allocate(void);

[Prev in Thread] Current Thread [Next in Thread]