Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] (PR#18545) [Patch] WARMAP_INVALIDATE()
Home

[Freeciv-Dev] (PR#18545) [Patch] WARMAP_INVALIDATE()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#18545) [Patch] WARMAP_INVALIDATE()
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Wed, 12 Jul 2006 13:02:19 -0700
Reply-to: bugs@xxxxxxxxxxx

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


  warmap is global array. This makes it sometimes very hard to figure 
out where it actually is used after generate_warmap(). generate_warmap() 
is typically called in high level function and then some subfunction of 
a subfunction actually uses it. One may think that all uses of certain 
warmap has been eliminated and it's safe to remove generate_warmap() 
call when in reality some user remains.
  This patch tries to help that. It introduces WARMAP_INVALIDATE macro. 
Attempts to use warmap between WARMAP_INVALIDATE and next 
generate_warmap() result in failed assert.
  One puts WARMAP_INVALIDATE where generate_warmap() used to be. If 
assert fails, one knows that code tried to use warmap previously 
generated at that place.


  - ML

diff -Nurd -X.diff_ignore freeciv/server/gotohand.c freeciv/server/gotohand.c
--- freeciv/server/gotohand.c   2006-07-12 20:30:08.259366200 +0300
+++ freeciv/server/gotohand.c   2006-07-12 22:34:00.287606200 +0300
@@ -218,12 +218,12 @@
   case AIR_MOVING:
     assert(sizeof(*warmap.cost) == sizeof(char));
     memset(warmap.cost, MAXCOST, MAP_INDEX_SIZE * sizeof(char));
-    WARMAP_COST(orig_tile) = 0;
+    warmap.cost[orig_tile->index] = 0;
     break;
   case SEA_MOVING:
     assert(sizeof(*warmap.seacost) == sizeof(char));
     memset(warmap.seacost, MAXCOST, MAP_INDEX_SIZE * sizeof(char));
-    WARMAP_SEACOST(orig_tile) = 0;
+    warmap.seacost[orig_tile->index] = 0;
     break;
   default:
     freelog(LOG_ERROR, "Bad move_type in init_warmap().");
@@ -345,7 +345,7 @@
 
         move_cost += cost;
         if (WARMAP_COST(tile1) > move_cost && move_cost < maxcost) {
-          WARMAP_COST(tile1) = move_cost;
+          warmap.cost[tile1->index] = move_cost;
           add_to_mapqueue(move_cost, tile1);
         }
        break;
@@ -358,7 +358,7 @@
          /* by adding the move_cost to the warmap regardless if we
             can move between we allow for shore bombardment/transport
             to inland positions/etc. */
-          WARMAP_SEACOST(tile1) = move_cost;
+          warmap.seacost[tile1->index] = move_cost;
          if (map_move_cost_ai(ptile, tile1)
              == MOVE_COST_FOR_VALID_SEA_STEP) {
            add_to_mapqueue(move_cost, tile1);
@@ -414,6 +414,8 @@
   warmap.warcity = pcity;
   warmap.warunit = punit;
 
+  warmap.invalid = FALSE;
+
   if (punit) {
     if (is_sailing_unit(punit)) {
       really_generate_warmap(pcity, punit, SEA_MOVING);
@@ -861,7 +863,7 @@
 
         add_to_mapqueue(MAXCOST-1 - move_cost, tile1);
        /* Mark it on the warmap */
-       WARMAP_VECTOR(tile1) |= 1 << DIR_REVERSE(dir);  
+       warmap.vector[tile1->index] |= 1 << DIR_REVERSE(dir);   
        BV_CLR(LOCAL_VECTOR(ptile), dir); /* avoid repetition */
        freelog(LOG_DEBUG, "PATH-SEGMENT: %s from (%d, %d) to (%d, %d)",
                dir_get_name(DIR_REVERSE(dir)),
@@ -1581,7 +1583,7 @@
       if (airspace_looks_safe(tile1, pplayer)) {
        int cost = WARMAP_COST(ptile) + 1;
 
-       WARMAP_COST(tile1) = cost;
+       warmap.cost[tile1->index] = cost;
 
        /* Now for A* we find the minimum total cost. */
        cost += real_map_distance(tile1, dest_tile);
diff -Nurd -X.diff_ignore freeciv/server/gotohand.h freeciv/server/gotohand.h
--- freeciv/server/gotohand.h   2006-07-12 20:30:08.321710200 +0300
+++ freeciv/server/gotohand.h   2006-07-12 22:43:51.823064200 +0300
@@ -56,12 +56,16 @@
   struct city *warcity; /* so we know what we're dealing with here */
   struct unit *warunit; /* so we know what we're dealing with here */
   struct tile *orig_tile;
+
+  bool invalid;         /* We have invalidated warmap */
 };
 
 extern struct move_cost_map warmap;
 
-#define WARMAP_COST(ptile) (warmap.cost[(ptile)->index])
-#define WARMAP_SEACOST(ptile) (warmap.seacost[(ptile)->index])
-#define WARMAP_VECTOR(ptile) (warmap.vector[(ptile)->index])
+#define WARMAP_COST(ptile) (assert(!warmap.invalid), 
warmap.cost[(ptile)->index])
+#define WARMAP_SEACOST(ptile) (assert(!warmap.invalid), 
warmap.seacost[(ptile)->index])
+#define WARMAP_VECTOR(ptile) (assert(!warmap.invalid), 
warmap.vector[(ptile)->index])
+
+#define WARMAP_INVALIDATE {warmap.invalid = TRUE;}
 
 #endif  /* FC__GOTOHAND_H */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#18545) [Patch] WARMAP_INVALIDATE(), Marko Lindqvist <=