src/heightmap.cpp
changeset 5869 33d51b7f639d
parent 5867 724600f8ae0d
child 6285 187e3ef04cc9
equal deleted inserted replaced
5868:baa704b6dc4f 5869:33d51b7f639d
   285 	uint img_row, img_col;
   285 	uint img_row, img_col;
   286 	TileIndex tile;
   286 	TileIndex tile;
   287 
   287 
   288 	/* Get map size and calculate scale and padding values */
   288 	/* Get map size and calculate scale and padding values */
   289 	switch (_patches.heightmap_rotation) {
   289 	switch (_patches.heightmap_rotation) {
   290 	case HM_COUNTER_CLOCKWISE:
   290 		default: NOT_REACHED();
   291 		width   = MapSizeX();
   291 		case HM_COUNTER_CLOCKWISE:
   292 		height  = MapSizeY();
   292 			width   = MapSizeX();
   293 		break;
   293 			height  = MapSizeY();
   294 	case HM_CLOCKWISE:
   294 			break;
   295 		width   = MapSizeY();
   295 		case HM_CLOCKWISE:
   296 		height  = MapSizeX();
   296 			width   = MapSizeY();
   297 		break;
   297 			height  = MapSizeX();
   298 	default:
   298 			break;
   299 		NOT_REACHED();
       
   300 		/* Avoids compiler warnings */
       
   301 		return;
       
   302 	}
   299 	}
   303 
   300 
   304 	if ((img_width * num_div) / img_height > ((width * num_div) / height)) {
   301 	if ((img_width * num_div) / img_height > ((width * num_div) / height)) {
   305 		/* Image is wider than map - center vertically */
   302 		/* Image is wider than map - center vertically */
   306 		img_scale = (width * num_div) / img_width;
   303 		img_scale = (width * num_div) / img_width;
   313 
   310 
   314 	/* Form the landscape */
   311 	/* Form the landscape */
   315 	for (row = 0; row < height - 1; row++) {
   312 	for (row = 0; row < height - 1; row++) {
   316 		for (col = 0; col < width - 1; col++) {
   313 		for (col = 0; col < width - 1; col++) {
   317 			switch (_patches.heightmap_rotation) {
   314 			switch (_patches.heightmap_rotation) {
   318 			case HM_COUNTER_CLOCKWISE: tile = TileXY(col, row); break;
   315 				default: NOT_REACHED();
   319 			case HM_CLOCKWISE:         tile = TileXY(row, col); break;
   316 				case HM_COUNTER_CLOCKWISE: tile = TileXY(col, row); break;
   320 			default:                   NOT_REACHED(); return;
   317 				case HM_CLOCKWISE:         tile = TileXY(row, col); break;
   321 			}
   318 			}
   322 
   319 
   323 			/* Check if current tile is within the 1-pixel map edge or padding regions */
   320 			/* Check if current tile is within the 1-pixel map edge or padding regions */
   324 			if ((DistanceFromEdge(tile) <= 1) ||
   321 			if ((DistanceFromEdge(tile) <= 1) ||
   325 					(row < row_pad) || (row >= (height - row_pad - 1)) ||
   322 					(row < row_pad) || (row >= (height - row_pad - 1)) ||
   328 			} else {
   325 			} else {
   329 				/* Use nearest neighbor resizing to scale map data.
   326 				/* Use nearest neighbor resizing to scale map data.
   330 				 *  We rotate the map 45 degrees (counter)clockwise */
   327 				 *  We rotate the map 45 degrees (counter)clockwise */
   331 				img_row = (((row - row_pad) * num_div) / img_scale);
   328 				img_row = (((row - row_pad) * num_div) / img_scale);
   332 				switch (_patches.heightmap_rotation) {
   329 				switch (_patches.heightmap_rotation) {
   333 				case HM_COUNTER_CLOCKWISE:
   330 					default: NOT_REACHED();
   334 					img_col = (((width - 1 - col - col_pad) * num_div) / img_scale);
   331 					case HM_COUNTER_CLOCKWISE:
   335 					break;
   332 						img_col = (((width - 1 - col - col_pad) * num_div) / img_scale);
   336 				case HM_CLOCKWISE:
   333 						break;
   337 					img_col = (((col - col_pad) * num_div) / img_scale);
   334 					case HM_CLOCKWISE:
   338 					break;
   335 						img_col = (((col - col_pad) * num_div) / img_scale);
   339 				default:
   336 						break;
   340 					NOT_REACHED();
       
   341 					/* Avoids compiler warnings */
       
   342 					return;
       
   343 				}
   337 				}
   344 
   338 
   345 				assert(img_row < img_height);
   339 				assert(img_row < img_height);
   346 				assert(img_col < img_width);
   340 				assert(img_col < img_width);
   347 
   341 
   406  * Reads the heightmap with the correct file reader
   400  * Reads the heightmap with the correct file reader
   407  */
   401  */
   408 static bool ReadHeightMap(char *filename, uint *x, uint *y, byte **map)
   402 static bool ReadHeightMap(char *filename, uint *x, uint *y, byte **map)
   409 {
   403 {
   410 	switch (_file_to_saveload.mode) {
   404 	switch (_file_to_saveload.mode) {
       
   405 		default: NOT_REACHED();
   411 #ifdef WITH_PNG
   406 #ifdef WITH_PNG
   412 		case SL_PNG:
   407 		case SL_PNG:
   413 			return ReadHeightmapPNG(filename, x, y, map);
   408 			return ReadHeightmapPNG(filename, x, y, map);
   414 #endif /* WITH_PNG */
   409 #endif /* WITH_PNG */
   415 		case SL_BMP:
   410 		case SL_BMP:
   416 			return ReadHeightmapBMP(filename, x, y, map);
   411 			return ReadHeightmapBMP(filename, x, y, map);
   417 
       
   418 		default:
       
   419 			NOT_REACHED();
       
   420 			/* Avoids compiler warnings */
       
   421 			return false;
       
   422 	}
   412 	}
   423 }
   413 }
   424 
   414 
   425 bool GetHeightmapDimensions(char *filename, uint *x, uint *y)
   415 bool GetHeightmapDimensions(char *filename, uint *x, uint *y)
   426 {
   416 {