Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesia
Home

[Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesia

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10047) RFC: restructuring map code to not use cartesian coordinates
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 12 Sep 2004 11:43:17 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10047 >

Here is a patch showing about what the changes to the map.h interface
would be.

I started out setting the "const" modifier when appropriate, but gave up
after a while.

As you can see the changes are pretty extensive...

jason

? diff
? settler_recursion_crash
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.213
diff -u -r1.213 map.h
--- common/map.h        3 Sep 2004 15:12:25 -0000       1.213
+++ common/map.h        12 Sep 2004 18:41:28 -0000
@@ -207,26 +207,28 @@
 void map_allocate(void);
 void map_free(void);
 
-const char *map_get_tile_info_text(int x, int y);
-const char *map_get_tile_fpt_text(int x, int y);
-struct tile *map_get_tile(int x, int y);
+const char *map_get_tile_info_text(const struct tile *ptile);
+const char *map_get_tile_fpt_text(const struct tile *ptile);
+struct tile *map_get_tile(const struct tile *ptile);
 
 int map_vector_to_real_distance(int dx, int dy);
 int map_vector_to_sq_distance(int dx, int dy);
-int map_distance(int x0, int y0, int x1, int y1);
-int real_map_distance(int x0, int y0, int x1, int y1);
-int sq_map_distance(int x0, int y0, int x1, int y1);
-
-bool same_pos(int x1, int y1, int x2, int y2);
-bool base_get_direction_for_step(int start_x, int start_y, int end_x,
-                               int end_y, int *dir);
-int get_direction_for_step(int start_x, int start_y, int end_x, int end_y);
+int map_distance(const struct tile *ptile1, const struct tile *ptile2);
+int real_map_distance(const struct tile *ptile1, const struct tile *ptile2);
+int sq_map_distance(const struct tile *ptile1, const struct tile *ptile2);
+
+bool same_pos(const struct tile *ptile1, const struct tile *ptile2);
+bool base_get_direction_for_step(const struct tile *ptile1,
+                                const struct tile *ptile2,
+                                enum direction8 *dir);
+int get_direction_for_step(const struct tile *ptile1,
+                          const struct tile *ptile2);
 
-void map_set_continent(int x, int y, Continent_id val);
-Continent_id map_get_continent(int x, int y);
+void map_set_continent(const struct tile *ptile, Continent_id val);
+Continent_id map_get_continent(const struct tile *ptile);
 
 void initialize_move_costs(void);
-void reset_move_costs(int x, int y);
+void reset_move_costs(const struct tile *ptile);
 
 /* Maximum value of index (for sanity checks and allocations) */
 #define MAX_MAP_INDEX (map.xsize * map.ysize)
@@ -345,52 +347,50 @@
        (dest_y) = (src_y) + DIR_DY[(dir)],             \
        normalize_map_pos(&(dest_x), &(dest_y))))
 
-struct player *map_get_owner(int x, int y);
-void map_set_owner(int x, int y, struct player *pplayer);
-struct city *map_get_city(int x, int y);
-void map_set_city(int x, int y, struct city *pcity);
-Terrain_type_id map_get_terrain(int x, int y);
-Terrain_type_id nat_get_terrain(int nat_x, int nat_y);
-enum tile_special_type map_get_special(int x, int y);
-void map_set_terrain(int x, int y, Terrain_type_id ter);
-void nat_set_terrain(int nat_x, int nat_y, Terrain_type_id ter);
-void map_set_special(int x, int y, enum tile_special_type spe);
-void map_clear_special(int x, int y, enum tile_special_type spe);
-void map_clear_all_specials(int x, int y);
+struct player *map_get_owner(const struct tile *ptile);
+void map_set_owner(struct tile *ptile, struct player *pplayer);
+struct city *map_get_city(const struct tile *ptile);
+void map_set_city(struct tile *ptile, struct city *pcity);
+Terrain_type_id map_get_terrain(const struct tile *ptile);
+enum tile_special_type map_get_special(const struct tile *ptile);
+void map_set_terrain(struct tile *ptile, Terrain_type_id ter);
+void map_set_special(struct tile *ptile, enum tile_special_type spe);
+void map_clear_special(struct tile *ptile, enum tile_special_type spe);
+void map_clear_all_specials(struct tile *ptile);
+
 bool is_real_map_pos(int x, int y);
 bool is_normal_map_pos(int x, int y);
 
 /* implemented in server/maphand.c and client/climisc.c */
-enum known_type map_get_known(int x, int y, struct player *pplayer);
+enum known_type map_get_known(struct tile *ptile, struct player *pplayer);
 
 /* special testing */
-bool map_has_special(int x, int y, enum tile_special_type to_test_for);
-bool tile_has_special(const struct tile *ptile,
-                     enum tile_special_type to_test_for);
+bool map_has_special(struct tile *ptile, enum tile_special_type to_test_for);
 bool contains_special(enum tile_special_type all,
                      enum tile_special_type to_test_for);
 
 
-bool is_singular_map_pos(int map_x, int map_y, int dist);
+bool is_singular_map_pos(struct tile *ptile, int dist);
 bool normalize_map_pos(int *x, int *y);
 void nearest_real_pos(int *x, int *y);
-void map_distance_vector(int *dx, int *dy, int x0, int y0, int x1, int y1);
+void map_distance_vector(int *dx, int *dy,
+                        struct tile *ptile1, struct tile *ptile2);
 int map_num_tiles(void);
 
-void rand_neighbour(int x0, int y0, int *x, int *y);
-void rand_map_pos(int *x, int *y);
-bool rand_map_pos_filtered(int *x, int *y, void *data,
-                          bool (*filter)(int x, int y, void *data));
-
-bool is_water_adjacent_to_tile(int x, int y);
-bool is_tiles_adjacent(int x0, int y0, int x1, int y1);
-bool is_move_cardinal(int start_x, int start_y, int end_x, int end_y);
-int map_move_cost(struct unit *punit, int x, int y);
+struct tile *rand_neighbour(struct tile *ptile);
+struct tile *rand_map_pos(void);
+struct tile * rand_map_pos_filtered(void *data,
+                       bool (*filter)(int x, int y, void *data));
+
+bool is_water_adjacent_to_tile(struct tile *ptile);
+bool is_tiles_adjacent(struct tile *ptile1, struct tile *ptile2);
+bool is_move_cardinal(struct tile *ptile1, struct tile *ptile2);
+int map_move_cost(struct unit *punit, struct tile *ptile);
 enum tile_special_type get_special_by_name(const char * name);
 const char *get_special_name(enum tile_special_type type);
-bool is_safe_ocean(int x, int y);
-bool is_cardinally_adj_to_ocean(int x, int y);
-bool is_sea_usable(int x, int y);
+bool is_safe_ocean(struct tile *ptile);
+bool is_cardinally_adj_to_ocean(struct tile *ptile);
+bool is_sea_usable(struct tile *ptile);
 int get_tile_food_base(struct tile * ptile);
 int get_tile_shield_base(struct tile * ptile);
 int get_tile_trade_base(struct tile * ptile);
@@ -399,24 +399,24 @@
 enum tile_special_type map_get_infrastructure_prerequisite(enum 
tile_special_type spe);
 enum tile_special_type get_preferred_pillage(enum tile_special_type pset);
 
-void map_irrigate_tile(int x, int y);
-void map_mine_tile(int x, int y);
-void change_terrain(int x, int y, Terrain_type_id type);
-void map_transform_tile(int x, int y);
-
-int map_build_road_time(int x, int y);
-int map_build_irrigation_time(int x, int y);
-int map_build_mine_time(int x, int y);
-int map_transform_time(int x, int y);
-int map_build_rail_time(int x, int y);
-int map_build_airbase_time(int x, int y);
-int map_build_fortress_time(int x, int y);
-int map_clean_pollution_time(int x, int y);
-int map_clean_fallout_time(int x, int y);
-int map_activity_time(enum unit_activity activity, int x, int y);
+void map_irrigate_tile(struct tile *ptile);
+void map_mine_tile(struct tile *ptile);
+void change_terrain(struct tile *ptile, Terrain_type_id type);
+void map_transform_tile(struct tile *ptile);
+
+int map_build_road_time(struct tile *ptile);
+int map_build_irrigation_time(struct tile *ptile);
+int map_build_mine_time(struct tile *ptile);
+int map_transform_time(struct tile *ptile);
+int map_build_rail_time(struct tile *ptile);
+int map_build_airbase_time(struct tile *ptile);
+int map_build_fortress_time(struct tile *ptile);
+int map_clean_pollution_time(struct tile *ptile);
+int map_clean_fallout_time(struct tile *ptile);
+int map_activity_time(enum unit_activity activity, struct tile *ptile);
 
-bool can_channel_land(int x, int y);
-bool can_reclaim_ocean(int x, int y);
+bool can_channel_land(struct tile *ptile);
+bool can_reclaim_ocean(struct tile *ptile);
 
 extern struct civ_map map;
 
@@ -428,8 +428,7 @@
  * starting position must be normal.
  *
  * See also iterate_outward() */
-#define iterate_outward_dxy(start_x, start_y, max_dist, x_itr, y_itr,      \
-                           dx_itr, dy_itr)                                 \
+#define iterate_outward_dxy(start_tile, max_dist, iter_tile, dx_itr, dy_itr)
 {                                                                          \
   int _start_x = (start_x), _start_y = (start_y), _max_dist = (max_dist);   \
   bool _is_border = IS_BORDER_MAP_POS(_start_x, _start_y, _max_dist);      \
@@ -453,7 +452,7 @@
 }
 
 /* See iterate_outward_dxy() */
-#define iterate_outward(start_x, start_y, max_dist, x_itr, y_itr)          \
+#define iterate_outward(start_tile, max_dist, iter_tile)           \
   iterate_outward_dxy(start_x, start_y, max_dist, x_itr, y_itr,                
    \
                      _dx_itr, _dy_itr)
 
@@ -467,8 +466,7 @@
  * position. Note that when the square is larger than the map the
  * distance vector may not be the minimum distance vector.
  */
-#define square_dxy_iterate(center_x, center_y, radius, x_itr, y_itr,        \
-                           dx_itr, dy_itr)                                  \
+#define square_dxy_iterate(center_tile, radius, tile_iter, x_itr, dy_itr) \
   iterate_outward_dxy(center_x, center_y, radius, x_itr, y_itr,                
    \
                      dx_itr, dy_itr)
 
@@ -479,7 +477,7 @@
  * Positions returned will have adjusted x, and positions with illegal
  * y will be automatically discarded.
  */
-#define square_iterate(center_x, center_y, radius, x_itr, y_itr)              \
+#define square_iterate(center_tile, radius, iter_tile) \
 {                                                                             \
   square_dxy_iterate(center_x, center_y, radius, x_itr, y_itr,                \
                      _dummy_x, _dummy_y);
@@ -492,7 +490,7 @@
  * radius.  Positions returned will have adjusted (x, y); unreal
  * positions will be automatically discarded. 
  */
-#define circle_iterate(center_x, center_y, sq_radius, x_itr, y_itr)         \
+#define circle_iterate(center_tile, sq_radius, iter_tile)      \
 {                                                                           \
   int _sq_radius = (sq_radius);                                                
    \
   int _cr_radius = (int)sqrt((double)_sq_radius);                          \
@@ -507,7 +505,7 @@
 
 /* Iterate through all map positions adjacent to the given center map
  * position, with normalization.  The order of positions is unspecified. */
-#define adjc_iterate(center_x, center_y, x_itr, y_itr)                        \
+#define adjc_iterate(center_tile, iter_tile)            \
 {                                                                             \
   /* Written as a wrapper to adjc_dir_iterate since it's the cleanest and     \
    * most efficient. */                                                       \
@@ -517,19 +515,19 @@
   } adjc_dir_iterate_end;                                                     \
 }
 
-#define adjc_dir_iterate(center_x, center_y, x_itr, y_itr, dir_itr)        \
+#define adjc_dir_iterate(center_tile, iter_tile, dir_itr) \
   adjc_dirlist_iterate(center_x, center_y, x_itr, y_itr, dir_itr,          \
                       map.valid_dirs, map.num_valid_dirs)
 
 #define adjc_dir_iterate_end adjc_dirlist_iterate_end
 
-#define cardinal_adjc_iterate(center_x, center_y, x_itr, y_itr)                
    \
+#define cardinal_adjc_iterate(center_tile, iter_tile)  \
   adjc_dirlist_iterate(center_x, center_y, x_itr, y_itr, _dir_itr,         \
                       map.cardinal_dirs, map.num_cardinal_dirs)
 
 #define cardinal_adjc_iterate_end adjc_dirlist_iterate_end
 
-#define cardinal_adjc_dir_iterate(center_x, center_y, x_itr, y_itr, dir_itr)\
+#define cardinal_adjc_dir_iterate(center_tile, iter_tile, dir_itr)     \
   adjc_dirlist_iterate(center_x, center_y, x_itr, y_itr, dir_itr,          \
                       map.cardinal_dirs, map.num_cardinal_dirs)
 
@@ -542,7 +540,7 @@
  *
  * This macro should not be used directly.  Instead, use adjc_dir_iterate
  * or cartesian_adjacent_iterate. */
-#define adjc_dirlist_iterate(center_x, center_y, x_itr, y_itr, dir_itr,     \
+#define adjc_dirlist_iterate(center_tile, iter_tile, dir_itr,  \
                              dirlist, dircount)                                
    \
 {                                                                          \
   int x_itr, y_itr, _dir_index;                                                
    \
@@ -565,7 +563,7 @@
 }
 
 /* Iterate over all positions on the globe. */
-#define whole_map_iterate(map_x, map_y)                                     \
+#define whole_map_iterate(iter_tile)                                     \
 {                                                                           \
   int WMI_index; /* We use index positions for cache efficiency. */         \
   for (WMI_index = 0; WMI_index < MAX_MAP_INDEX; WMI_index++) {             \

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