mirror of https://github.com/OpenTTD/OpenTTD
(svn r22509) -Add: Save heightmap.
parent
64745b4d0d
commit
be048e05f2
|
@ -28,6 +28,7 @@
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
static const char * const SCREENSHOT_NAME = "screenshot"; ///< Default filename of a saved screenshot.
|
static const char * const SCREENSHOT_NAME = "screenshot"; ///< Default filename of a saved screenshot.
|
||||||
|
static const char * const HEIGHTMAP_NAME = "heightmap"; ///< Default filename of a saved heightmap.
|
||||||
|
|
||||||
char _screenshot_format_name[8]; ///< Extension of the current screenshot format (corresponds with #_cur_screenshot_format).
|
char _screenshot_format_name[8]; ///< Extension of the current screenshot format (corresponds with #_cur_screenshot_format).
|
||||||
uint _num_screenshot_formats; ///< Number of available screenshot formats.
|
uint _num_screenshot_formats; ///< Number of available screenshot formats.
|
||||||
|
@ -770,6 +771,48 @@ static bool MakeWorldScreenshot()
|
||||||
BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette);
|
BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for generating a heightmap. Supports 8bpp grayscale only.
|
||||||
|
* @param userdata Pointer to user data.
|
||||||
|
* @param buf Destination buffer.
|
||||||
|
* @param y Line number of the first line to write.
|
||||||
|
* @param pitch Number of pixels to write (1 byte for 8bpp, 4 bytes for 32bpp). @see Colour
|
||||||
|
* @param n Number of lines to write.
|
||||||
|
* @see ScreenshotCallback
|
||||||
|
*/
|
||||||
|
static void HeightmapCallback(void *userdata, void *buffer, uint y, uint pitch, uint n)
|
||||||
|
{
|
||||||
|
byte *buf = (byte *)buffer;
|
||||||
|
while (n > 0) {
|
||||||
|
TileIndex ti = TileXY(MapMaxX(), y);
|
||||||
|
for (uint x = MapMaxX(); true; x--) {
|
||||||
|
*buf = 16 * TileHeight(ti);
|
||||||
|
buf++;
|
||||||
|
if (x == 0) break;
|
||||||
|
ti = TILE_ADDXY(ti, -1, 0);
|
||||||
|
}
|
||||||
|
y++;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a heightmap of the current map.
|
||||||
|
* @param filename Filename to use for saving.
|
||||||
|
*/
|
||||||
|
bool MakeHeightmapScreenshot(const char *filename)
|
||||||
|
{
|
||||||
|
Colour palette[256];
|
||||||
|
for (uint i = 0; i < lengthof(palette); i++) {
|
||||||
|
palette[i].a = 0xff;
|
||||||
|
palette[i].r = i;
|
||||||
|
palette[i].g = i;
|
||||||
|
palette[i].b = i;
|
||||||
|
}
|
||||||
|
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
|
||||||
|
return sf->proc(filename, HeightmapCallback, NULL, MapSizeX(), MapSizeY(), 8, palette);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make an actual screenshot.
|
* Make an actual screenshot.
|
||||||
* @param t the type of screenshot to make.
|
* @param t the type of screenshot to make.
|
||||||
|
@ -805,6 +848,12 @@ bool MakeScreenshot(ScreenshotType t, const char *name)
|
||||||
ret = MakeWorldScreenshot();
|
ret = MakeWorldScreenshot();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SC_HEIGHTMAP: {
|
||||||
|
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
|
||||||
|
ret = MakeHeightmapScreenshot(MakeScreenshotName(HEIGHTMAP_NAME, sf->extension));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
NOT_REACHED();
|
NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,14 @@ void SetScreenshotFormat(uint i);
|
||||||
|
|
||||||
/** Type of requested screenshot */
|
/** Type of requested screenshot */
|
||||||
enum ScreenshotType {
|
enum ScreenshotType {
|
||||||
SC_VIEWPORT, ///< Screenshot of viewport
|
SC_VIEWPORT, ///< Screenshot of viewport.
|
||||||
SC_RAW, ///< Raw screenshot from blitter buffer
|
SC_RAW, ///< Raw screenshot from blitter buffer.
|
||||||
SC_ZOOMEDIN, ///< Zoomed in screenshot of the visible area
|
SC_ZOOMEDIN, ///< Zoomed in screenshot of the visible area.
|
||||||
SC_WORLD, ///< World screenshot
|
SC_WORLD, ///< World screenshot.
|
||||||
|
SC_HEIGHTMAP, ///< Heightmap of the world.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool MakeHeightmapScreenshot(const char *filename);
|
||||||
bool MakeScreenshot(ScreenshotType t, const char *name);
|
bool MakeScreenshot(ScreenshotType t, const char *name);
|
||||||
|
|
||||||
extern char _screenshot_format_name[8];
|
extern char _screenshot_format_name[8];
|
||||||
|
|
Loading…
Reference in New Issue