Changeset - r5618:88ed03fd4fdd
[Not reviewed]
master
0 1 0
Darkvater - 17 years ago 2007-01-12 14:28:00
darkvater@openttd.org
(svn r8077) -Cleanup: Restructure some switch() statements' default case when they're unreachable
1 file changed with 20 insertions and 30 deletions:
0 comments (0 inline, 0 general)
src/heightmap.cpp
Show inline comments
 
@@ -284,24 +284,21 @@ static void GrayscaleToMapHeights(uint i
 
	uint img_scale;
 
	uint img_row, img_col;
 
	TileIndex tile;
 

	
 
	/* Get map size and calculate scale and padding values */
 
	switch (_patches.heightmap_rotation) {
 
	case HM_COUNTER_CLOCKWISE:
 
		width   = MapSizeX();
 
		height  = MapSizeY();
 
		break;
 
	case HM_CLOCKWISE:
 
		width   = MapSizeY();
 
		height  = MapSizeX();
 
		break;
 
	default:
 
		NOT_REACHED();
 
		/* Avoids compiler warnings */
 
		return;
 
		default: NOT_REACHED();
 
		case HM_COUNTER_CLOCKWISE:
 
			width   = MapSizeX();
 
			height  = MapSizeY();
 
			break;
 
		case HM_CLOCKWISE:
 
			width   = MapSizeY();
 
			height  = MapSizeX();
 
			break;
 
	}
 

	
 
	if ((img_width * num_div) / img_height > ((width * num_div) / height)) {
 
		/* Image is wider than map - center vertically */
 
		img_scale = (width * num_div) / img_width;
 
		row_pad = (1 + height - ((img_height * img_scale) / num_div)) / 2;
 
@@ -312,37 +309,34 @@ static void GrayscaleToMapHeights(uint i
 
	}
 

	
 
	/* Form the landscape */
 
	for (row = 0; row < height - 1; row++) {
 
		for (col = 0; col < width - 1; col++) {
 
			switch (_patches.heightmap_rotation) {
 
			case HM_COUNTER_CLOCKWISE: tile = TileXY(col, row); break;
 
			case HM_CLOCKWISE:         tile = TileXY(row, col); break;
 
			default:                   NOT_REACHED(); return;
 
				default: NOT_REACHED();
 
				case HM_COUNTER_CLOCKWISE: tile = TileXY(col, row); break;
 
				case HM_CLOCKWISE:         tile = TileXY(row, col); break;
 
			}
 

	
 
			/* Check if current tile is within the 1-pixel map edge or padding regions */
 
			if ((DistanceFromEdge(tile) <= 1) ||
 
					(row < row_pad) || (row >= (height - row_pad - 1)) ||
 
					(col < col_pad) || (col >= (width  - col_pad - 1))) {
 
				SetTileHeight(tile, 0);
 
			} else {
 
				/* Use nearest neighbor resizing to scale map data.
 
				 *  We rotate the map 45 degrees (counter)clockwise */
 
				img_row = (((row - row_pad) * num_div) / img_scale);
 
				switch (_patches.heightmap_rotation) {
 
				case HM_COUNTER_CLOCKWISE:
 
					img_col = (((width - 1 - col - col_pad) * num_div) / img_scale);
 
					break;
 
				case HM_CLOCKWISE:
 
					img_col = (((col - col_pad) * num_div) / img_scale);
 
					break;
 
				default:
 
					NOT_REACHED();
 
					/* Avoids compiler warnings */
 
					return;
 
					default: NOT_REACHED();
 
					case HM_COUNTER_CLOCKWISE:
 
						img_col = (((width - 1 - col - col_pad) * num_div) / img_scale);
 
						break;
 
					case HM_CLOCKWISE:
 
						img_col = (((col - col_pad) * num_div) / img_scale);
 
						break;
 
				}
 

	
 
				assert(img_row < img_height);
 
				assert(img_col < img_width);
 

	
 
				/* Color scales from 0 to 255, OpenTTD height scales from 0 to 15 */
 
@@ -405,23 +399,19 @@ static void FixSlopes(void)
 
/**
 
 * Reads the heightmap with the correct file reader
 
 */
 
static bool ReadHeightMap(char *filename, uint *x, uint *y, byte **map)
 
{
 
	switch (_file_to_saveload.mode) {
 
		default: NOT_REACHED();
 
#ifdef WITH_PNG
 
		case SL_PNG:
 
			return ReadHeightmapPNG(filename, x, y, map);
 
#endif /* WITH_PNG */
 
		case SL_BMP:
 
			return ReadHeightmapBMP(filename, x, y, map);
 

	
 
		default:
 
			NOT_REACHED();
 
			/* Avoids compiler warnings */
 
			return false;
 
	}
 
}
 

	
 
bool GetHeightmapDimensions(char *filename, uint *x, uint *y)
 
{
 
	return ReadHeightMap(filename, x, y, NULL);
0 comments (0 inline, 0 general)