(svn r21878) -Codechange: move parts of UpdateInclination() to separate functions
This commit is contained in:
		| @@ -106,16 +106,13 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Checks if the vehicle is in a slope and sets the required flags in that case. | 	 * Updates vehicle's Z position and inclination. | ||||||
| 	 * @param new_tile True if the vehicle reached a new tile. | 	 * Used when the vehicle entered given tile. | ||||||
| 	 * @param turned Indicates if the vehicle has turned. | 	 * @pre The vehicle has to be at (or near to) a border of the tile, | ||||||
| 	 * @return Old height of the vehicle. | 	 *      directed towards tile centre | ||||||
| 	 */ | 	 */ | ||||||
| 	FORCEINLINE byte UpdateInclination(bool new_tile, bool turned) | 	FORCEINLINE void UpdateZPositionAndInclination() | ||||||
| 	{ | 	{ | ||||||
| 		byte old_z = this->z_pos; |  | ||||||
|  |  | ||||||
| 		if (new_tile) { |  | ||||||
| 		this->z_pos = GetSlopeZ(this->x_pos, this->y_pos); | 		this->z_pos = GetSlopeZ(this->x_pos, this->y_pos); | ||||||
| 		ClrBit(this->gv_flags, GVF_GOINGUP_BIT); | 		ClrBit(this->gv_flags, GVF_GOINGUP_BIT); | ||||||
| 		ClrBit(this->gv_flags, GVF_GOINGDOWN_BIT); | 		ClrBit(this->gv_flags, GVF_GOINGDOWN_BIT); | ||||||
| @@ -125,15 +122,20 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> { | |||||||
| 			 * direction it is sloped, we get the 'z' at the center of | 			 * direction it is sloped, we get the 'z' at the center of | ||||||
| 			 * the tile (middle_z) and the edge of the tile (old_z), | 			 * the tile (middle_z) and the edge of the tile (old_z), | ||||||
| 			 * which we then can compare. */ | 			 * which we then can compare. */ | ||||||
| 				static const int INV_TILE_SIZE_MASK = ~(TILE_SIZE - 1); | 			byte middle_z = GetSlopeZ((this->x_pos & ~TILE_UNIT_MASK) | HALF_TILE_SIZE, (this->y_pos & ~TILE_UNIT_MASK) | HALF_TILE_SIZE); | ||||||
|  |  | ||||||
| 				byte middle_z = GetSlopeZ((this->x_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE, (this->y_pos & INV_TILE_SIZE_MASK) | HALF_TILE_SIZE); |  | ||||||
|  |  | ||||||
| 			if (middle_z != this->z_pos) { | 			if (middle_z != this->z_pos) { | ||||||
| 					SetBit(this->gv_flags, (middle_z > old_z) ? GVF_GOINGUP_BIT : GVF_GOINGDOWN_BIT); | 				SetBit(this->gv_flags, (middle_z > this->z_pos) ? GVF_GOINGUP_BIT : GVF_GOINGDOWN_BIT); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		} else { | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Updates vehicle's Z position. | ||||||
|  | 	 * Inclination can't change in the middle of a tile. | ||||||
|  | 	 */ | ||||||
|  | 	FORCEINLINE void UpdateZPosition() | ||||||
|  | 	{ | ||||||
| 		/* Flat tile, tile with two opposing corners raised and tile with 3 corners | 		/* Flat tile, tile with two opposing corners raised and tile with 3 corners | ||||||
| 		 * raised can never have sloped track ... */ | 		 * raised can never have sloped track ... */ | ||||||
| 		static const uint32 never_sloped = 1 << SLOPE_FLAT | 1 << SLOPE_EW | 1 << SLOPE_NS | 1 << SLOPE_NWS | 1 << SLOPE_WSE | 1 << SLOPE_SEN | 1 << SLOPE_ENW; | 		static const uint32 never_sloped = 1 << SLOPE_FLAT | 1 << SLOPE_EW | 1 << SLOPE_NS | 1 << SLOPE_NWS | 1 << SLOPE_WSE | 1 << SLOPE_SEN | 1 << SLOPE_ENW; | ||||||
| @@ -147,6 +149,22 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Checks if the vehicle is in a slope and sets the required flags in that case. | ||||||
|  | 	 * @param new_tile True if the vehicle reached a new tile. | ||||||
|  | 	 * @param turned Indicates if the vehicle has turned. | ||||||
|  | 	 * @return Old height of the vehicle. | ||||||
|  | 	 */ | ||||||
|  | 	FORCEINLINE byte UpdateInclination(bool new_tile, bool turned) | ||||||
|  | 	{ | ||||||
|  | 		byte old_z = this->z_pos; | ||||||
|  |  | ||||||
|  | 		if (new_tile) { | ||||||
|  | 			this->UpdateZPositionAndInclination(); | ||||||
|  | 		} else { | ||||||
|  | 			this->UpdateZPosition(); | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		this->UpdateViewport(true, turned); | 		this->UpdateViewport(true, turned); | ||||||
| 		return old_z; | 		return old_z; | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 smatz
					smatz