|
OpenTTD Source 20260218-master-g2123fca5ea
|
Creating of maps from heightmaps. More...
#include "stdafx.h"#include "heightmap.h"#include "landscape.h"#include "clear_map.h"#include "strings_func.h"#include "void_map.h"#include "error.h"#include "saveload/saveload.h"#include "bmp.h"#include "gfx_func.h"#include "fios.h"#include "fileio_func.h"#include "table/strings.h"#include <png.h>#include "safeguards.h"Go to the source code of this file.
Functions | |
| static bool | IsValidHeightmapDimension (size_t width, size_t height) |
| Check whether the loaded dimension of the heightmap image are considered valid enough to attempt to load the image. | |
| static uint8_t | RGBToGreyscale (uint8_t red, uint8_t green, uint8_t blue) |
| Convert RGB colours to Greyscale using 29.9% Red, 58.7% Green, 11.4% Blue (average luminosity formula, NTSC Colour Space). | |
| static void | ReadHeightmapPNGImageData (std::span< uint8_t > map, png_structp png_ptr, png_infop info_ptr) |
| The PNG Heightmap loader. | |
| static bool | ReadHeightmapPNG (std::string_view filename, uint *x, uint *y, std::vector< uint8_t > *map) |
| Reads the heightmap and/or size of the heightmap from a PNG file. | |
| static void | ReadHeightmapBMPImageData (std::span< uint8_t > map, const BmpInfo &info, const BmpData &data) |
| The BMP Heightmap loader. | |
| static bool | ReadHeightmapBMP (std::string_view filename, uint *x, uint *y, std::vector< uint8_t > *map) |
| Reads the heightmap and/or size of the heightmap from a BMP file. | |
| static void | GreyscaleToMapHeights (uint img_width, uint img_height, std::span< const uint8_t > map) |
| Converts a given greyscale map to something that fits in OTTD map system and create a map of that data. | |
| void | FixSlopes () |
| This function takes care of the fact that land in OpenTTD can never differ more than 1 in height. | |
| static bool | ReadHeightMap (DetailedFileType dft, std::string_view filename, uint *x, uint *y, std::vector< uint8_t > *map) |
| Reads the heightmap with the correct file reader. | |
| bool | GetHeightmapDimensions (DetailedFileType dft, std::string_view filename, uint *x, uint *y) |
| Get the dimensions of a heightmap. | |
| bool | LoadHeightmap (DetailedFileType dft, std::string_view filename) |
| Load a heightmap from file and change the map in its current dimensions to a landscape representing the heightmap. | |
| void | FlatEmptyWorld (uint8_t tile_height) |
| Make an empty world where all tiles are of height 'tile_height'. | |
Variables | |
| static const uint | MAX_HEIGHTMAP_SIDE_LENGTH_IN_PIXELS = 2 * MAX_MAP_SIZE |
| Maximum number of pixels for one dimension of a heightmap image. | |
| static const uint | MAX_HEIGHTMAP_SIZE_PIXELS = 256 << 20 |
Creating of maps from heightmaps.
Definition in file heightmap.cpp.
| void FixSlopes | ( | ) |
This function takes care of the fact that land in OpenTTD can never differ more than 1 in height.
Definition at line 423 of file heightmap.cpp.
References _settings_game, IsInnerTile(), MakeClear(), MAX_TILE_HEIGHT, RandomRange(), Rocks, SetTileHeight(), Map::SizeX(), Map::SizeY(), TileHeight(), and TileXY().
Referenced by FlatEmptyWorld(), GenerateLandscape(), and LoadHeightmap().
| void FlatEmptyWorld | ( | uint8_t | tile_height | ) |
Make an empty world where all tiles are of height 'tile_height'.
| tile_height | of the desired new empty world |
Definition at line 563 of file heightmap.cpp.
References _settings_game, FixSlopes(), MarkWholeScreenDirty(), SetTileHeight(), Map::SizeX(), Map::SizeY(), and TileXY().
Referenced by _GenerateWorld().
| bool GetHeightmapDimensions | ( | DetailedFileType | dft, |
| std::string_view | filename, | ||
| uint * | x, | ||
| uint * | y ) |
Get the dimensions of a heightmap.
| dft | Type of image file. |
| filename | to query |
| x | dimension x |
| y | dimension y |
Definition at line 525 of file heightmap.cpp.
References ReadHeightMap().
|
static |
Converts a given greyscale map to something that fits in OTTD map system and create a map of that data.
| img_width | the with of the image in pixels/tiles |
| img_height | the height of the image in pixels/tiles |
| map | the input map |
Definition at line 327 of file heightmap.cpp.
References _settings_game, DistanceFromEdge(), Grass, HM_CLOCKWISE, HM_COUNTER_CLOCKWISE, IsInnerTile(), MakeClear(), MakeVoid(), MAX_HEIGHTMAP_SIDE_LENGTH_IN_PIXELS, SetTileHeight(), Map::SizeX(), Map::SizeY(), and TileXY().
Referenced by LoadHeightmap().
|
inlinestatic |
Check whether the loaded dimension of the heightmap image are considered valid enough to attempt to load the image.
In other words, the width and height are not beyond the MAX_HEIGHTMAP_SIDE_LENGTH_IN_PIXELS limit and the total number of pixels does not exceed #MAX_HEIGHTMAP_SIZE_PIXELS. A width or height less than 1 are disallowed too.
| width | The width of the to be loaded height map. |
| height | The height of the to be loaded height map. |
Definition at line 58 of file heightmap.cpp.
References MAX_HEIGHTMAP_SIDE_LENGTH_IN_PIXELS.
Referenced by ReadHeightmapBMP(), and ReadHeightmapPNG().
| bool LoadHeightmap | ( | DetailedFileType | dft, |
| std::string_view | filename ) |
Load a heightmap from file and change the map in its current dimensions to a landscape representing the heightmap.
It converts pixels to height. The brighter, the higher.
| dft | Type of image file. |
| filename | of the heightmap file to be imported. |
true iff the heightmap could be loaded. Definition at line 538 of file heightmap.cpp.
References _settings_game, FixSlopes(), GreyscaleToMapHeights(), IsMapSurroundedByWater(), MarkWholeScreenDirty(), and ReadHeightMap().
Referenced by GenerateLandscape().
|
static |
Reads the heightmap with the correct file reader.
| dft | Type of image file. | |
| filename | Name of the file to load. | |
| [out] | x | Length of the image. |
| [out] | y | Height of the image. |
| [in,out] | map | If not nullptr, destination to store the loaded block of image data. |
Definition at line 501 of file heightmap.cpp.
References DFT_HEIGHTMAP_BMP, DFT_HEIGHTMAP_PNG, ReadHeightmapBMP(), and ReadHeightmapPNG().
Referenced by GetHeightmapDimensions(), and LoadHeightmap().
|
static |
Reads the heightmap and/or size of the heightmap from a BMP file.
If map == nullptr only the size of the BMP is read, otherwise a map with greyscale pixels is allocated and assigned to *map.
| filename | Name of the file to load. | |
| [out] | x | Length of the image. |
| [out] | y | Height of the image. |
| [in,out] | map | If not nullptr, destination to store the loaded block of image data. |
Definition at line 282 of file heightmap.cpp.
References BmpReadBitmap(), BmpReadHeader(), FioFOpenFile(), GetEncodedString(), BmpInfo::height, HEIGHTMAP_DIR, IsValidHeightmapDimension(), ReadHeightmapBMPImageData(), ShowErrorMessage(), BmpInfo::width, and WL_ERROR.
Referenced by ReadHeightMap().
|
static |
The BMP Heightmap loader.
| map | The image to load into. |
| info | Metadata about the image. |
| data | The actual BMP data. |
For a non-gray palette of size 16 we assume that the order of the palette determines the height; the first entry is the sea (level 0), the second one level 1, etc.
For a palette of size 2 we assume that the order of the palette determines the height; the first entry is the sea (level 0), the second one is the land (level 1)
Definition at line 222 of file heightmap.cpp.
References BmpInfo::bpp, BmpInfo::height, BmpInfo::palette_size, RGBToGreyscale(), and BmpInfo::width.
Referenced by ReadHeightmapBMP().
|
static |
Reads the heightmap and/or size of the heightmap from a PNG file.
If map == nullptr only the size of the PNG is read, otherwise a map with greyscale pixels is allocated and assigned to *map.
| filename | Name of the file to load. | |
| [out] | x | Length of the image. |
| [out] | y | Height of the image. |
| [in,out] | map | If not nullptr, destination to store the loaded block of image data. |
Definition at line 153 of file heightmap.cpp.
References FioFOpenFile(), GetEncodedString(), HEIGHTMAP_DIR, IsValidHeightmapDimension(), ReadHeightmapPNGImageData(), ShowErrorMessage(), and WL_ERROR.
Referenced by ReadHeightMap().
|
static |
The PNG Heightmap loader.
| map | The map to write data to. |
| png_ptr | The PNG file to load. |
| info_ptr | Metadata about the loaded PNG. |
For a non-gray palette of size 16 we assume that the order of the palette determines the height; the first entry is the sea (level 0), the second one level 1, etc.
Definition at line 89 of file heightmap.cpp.
References RGBToGreyscale().
Referenced by ReadHeightmapPNG().
|
inlinestatic |
Convert RGB colours to Greyscale using 29.9% Red, 58.7% Green, 11.4% Blue (average luminosity formula, NTSC Colour Space).
| red | The red component of a colour. |
| green | The green component of a colour. |
| blue | The blue component of a colour. |
Definition at line 73 of file heightmap.cpp.
Referenced by ReadHeightmapBMPImageData(), and ReadHeightmapPNGImageData().
|
static |
Maximum number of pixels for one dimension of a heightmap image.
Do not allow images for which the longest side is twice the maximum number of tiles along the longest side of the (tile) map.
Definition at line 36 of file heightmap.cpp.
Referenced by GreyscaleToMapHeights(), and IsValidHeightmapDimension().
|
static |
Definition at line 41 of file heightmap.cpp.