(svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
authorfrosch
Wed, 25 Jun 2008 18:46:05 +0000
changeset 9592 835ccfd13653
parent 9591 6b54f7b28d0f
child 9593 24938c3df0ac
(svn r13632) -Codechange: Use 'void *' for user-data of CircularTileSearch().
src/industry_cmd.cpp
src/map.cpp
src/map_func.h
src/newgrf_house.cpp
src/town_cmd.cpp
--- a/src/industry_cmd.cpp	Wed Jun 25 17:45:05 2008 +0000
+++ b/src/industry_cmd.cpp	Wed Jun 25 18:46:05 2008 +0000
@@ -962,10 +962,10 @@
 /**
  * Search callback function for ChopLumberMillTrees
  * @param tile to test
- * @param data that is passed by the caller.  In this case, nothing
+ * @param user_data that is passed by the caller.  In this case, nothing
  * @return the result of the test
  */
-static bool SearchLumberMillTrees(TileIndex tile, uint32 data)
+static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
 {
 	if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees
 		PlayerID old_player = _current_player;
@@ -994,7 +994,7 @@
 
 	if (!IsIndustryCompleted(tile)) return;  ///< Can't proceed if not completed
 
-	if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles  to search
+	if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, NULL)) ///< 40x40 tiles  to search
 		i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
 }
 
--- a/src/map.cpp	Wed Jun 25 17:45:05 2008 +0000
+++ b/src/map.cpp	Wed Jun 25 18:46:05 2008 +0000
@@ -261,12 +261,12 @@
  * @param tile to start the search from. Upon completion, it will return the tile matching the search
  * @param size: number of tiles per side of the desired search area
  * @param proc: callback testing function pointer.
- * @param data to be passed to the callback function. Depends on the implementation
+ * @param user_data to be passed to the callback function. Depends on the implementation
  * @return result of the search
  * @pre proc != NULL
  * @pre size > 0
  */
-bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, uint32 data)
+bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
 {
 	uint n, x, y;
 	DiagDirection dir;
@@ -281,7 +281,7 @@
 		/* If the length of the side is uneven, the center has to be checked
 		 * separately, as the pattern of uneven sides requires to go around the center */
 		n = 2;
-		if (proc(TileXY(x, y), data)) {
+		if (proc(TileXY(x, y), user_data)) {
 			*tile = TileXY(x, y);
 			return true;
 		}
@@ -304,7 +304,7 @@
 			uint j;
 			for (j = n; j != 0; j--) {
 				if (x <= MapMaxX() && y <= MapMaxY() && ///< Is the tile within the map?
-						proc(TileXY(x, y), data)) {     ///< Is the callback successful?
+						proc(TileXY(x, y), user_data)) {     ///< Is the callback successful?
 					*tile = TileXY(x, y);
 					return true;                        ///< then stop the search
 				}
--- a/src/map_func.h	Wed Jun 25 17:45:05 2008 +0000
+++ b/src/map_func.h	Wed Jun 25 18:46:05 2008 +0000
@@ -383,15 +383,15 @@
  * A callback function type for searching tiles.
  *
  * @param tile The tile to test
- * @param data additional data for the callback function to use
+ * @param user_data additional data for the callback function to use
  * @return A boolean value, depend on the definition of the function.
  */
-typedef bool TestTileOnSearchProc(TileIndex tile, uint32 data);
+typedef bool TestTileOnSearchProc(TileIndex tile, void *user_data);
 
 /**
  * Searches for some cirumstances of a tile around a given tile with a helper function.
  */
-bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, uint32 data);
+bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data);
 
 /**
  * Get a random tile out of a given seed.
--- a/src/newgrf_house.cpp	Wed Jun 25 17:45:05 2008 +0000
+++ b/src/newgrf_house.cpp	Wed Jun 25 18:46:05 2008 +0000
@@ -203,15 +203,16 @@
 
 /** Callback function to search a house by its HouseID
  * @param tile TileIndex to be examined
- * @param data house id, in order to get the specs
+ * @param user_data house id, in order to get the specs
  * @return true or false, if found or not
  */
-static bool SearchNearbyHouseID(TileIndex tile, uint32 data)
+static bool SearchNearbyHouseID(TileIndex tile, void *user_data)
 {
 	if (IsTileType(tile, MP_HOUSE)) {
 		const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); // tile been examined
 		if (hs->grffile != NULL) { // must be one from a grf file
-			const HouseSpec *test_hs = GetHouseSpecs((HouseID)GB(data, 0, 16));
+			HouseID *test_house = (HouseID *)user_data;
+			const HouseSpec *test_hs = GetHouseSpecs(*test_house);
 			return hs->local_id == test_hs->local_id &&  // same local id as the one requested
 				hs->grffile->grfid == test_hs->grffile->grfid;  // from the same grf
 		}
@@ -221,15 +222,16 @@
 
 /** Callback function to search a house by its classID
  * @param tile TileIndex to be examined
- * @param data house id, in order to get the specs
+ * @param user_data house id, in order to get the specs
  * @return true or false, if found or not
  */
-static bool SearchNearbyHouseClass(TileIndex tile, uint32 data)
+static bool SearchNearbyHouseClass(TileIndex tile, void *user_data)
 {
 	if (IsTileType(tile, MP_HOUSE)) {
 		const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); // tile been examined
 		if (hs->grffile != NULL) { // must be one from a grf file
-			const HouseSpec *test_hs = GetHouseSpecs((HouseID)GB(data, 0, 16));
+			HouseID *test_house = (HouseID *)user_data;
+			const HouseSpec *test_hs = GetHouseSpecs(*test_house);
 			return hs->class_id == test_hs->class_id &&  // same classid as the one requested
 				hs->grffile->grfid == test_hs->grffile->grfid;  // from the same grf
 		}
@@ -239,15 +241,16 @@
 
 /** Callback function to search a house by its grfID
  * @param tile TileIndex to be examined
- * @param data house id, in order to get the specs
+ * @param user_data house id, in order to get the specs
  * @return true or false, if found or not
  */
-static bool SearchNearbyHouseGRFID(TileIndex tile, uint32 data)
+static bool SearchNearbyHouseGRFID(TileIndex tile, void *user_data)
 {
 	if (IsTileType(tile, MP_HOUSE)) {
 		const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile)); // tile been examined
 		if (hs->grffile != NULL) { // must be one from a grf file
-			const HouseSpec *test_hs = GetHouseSpecs((HouseID)GB(data, 0, 16));
+			HouseID *test_house = (HouseID *)user_data;
+			const HouseSpec *test_hs = GetHouseSpecs(*test_house);
 			return hs->grffile->grfid == test_hs->grffile->grfid;  // from the same grf
 		}
 	}
@@ -260,10 +263,10 @@
  *                  bits 0..6 radius of the search
  *                  bits 7..8 search type i.e.: 0 = houseID/ 1 = classID/ 2 = grfID
  * @param tile TileIndex from which to start the search
- * @param data the HouseID that is associated to the house work who started the callback
- * @result the Manhattan distance from the center tile, if any, and 0 if failure
-  */
-static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, uint32 data)
+ * @param house the HouseID that is associated to the house, the callback is called for
+ * @return the Manhattan distance from the center tile, if any, and 0 if failure
+ */
+static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseID house)
 {
 	static TestTileOnSearchProc * const search_procs[3] = {
 		SearchNearbyHouseID,
@@ -277,7 +280,7 @@
 	if (searchradius < 1) return 0; // do not use a too low radius
 
 	/* Use a pointer for the tile to start the search. Will be required for calculating the distance*/
-	if (CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], data)) {
+	if (CircularTileSearch(&found_tile, 2 * searchradius + 1, search_procs[searchtype], &house)) {
 		return DistanceManhattan(found_tile, tile);
 	}
 	return 0;
--- a/src/town_cmd.cpp	Wed Jun 25 17:45:05 2008 +0000
+++ b/src/town_cmd.cpp	Wed Jun 25 18:46:05 2008 +0000
@@ -2182,12 +2182,13 @@
 /**
  * Search callback function for TownActionBuildStatue
  * @param tile on which to perform the search
- * @param town_id The town_id for which we want a statue
+ * @param user_data The town_id for which we want a statue
  * @return the result of the test
  */
-static bool SearchTileForStatue(TileIndex tile, uint32 town_id)
+static bool SearchTileForStatue(TileIndex tile, void *user_data)
 {
-	return DoBuildStatueOfCompany(tile, town_id);
+	TownID *town_id = (TownID *)user_data;
+	return DoBuildStatueOfCompany(tile, *town_id);
 }
 
 /**
@@ -2199,7 +2200,7 @@
 {
 	TileIndex tile = t->xy;
 
-	if (CircularTileSearch(&tile, 9, SearchTileForStatue, t->index)) {
+	if (CircularTileSearch(&tile, 9, SearchTileForStatue, &t->index)) {
 		SetBit(t->statues, _current_player); // Once found and built, "inform" the Town
 	}
 }