update heightmap:dump(...) filename argument

This commit is contained in:
MihailRis 2024-10-15 02:04:17 +03:00
parent 48143c5a2b
commit c34bc184a4

View File

@ -8,10 +8,11 @@
#include "util/functional_util.hpp" #include "util/functional_util.hpp"
#define FNL_IMPL #define FNL_IMPL
#include "maths/FastNoiseLite.h" #include "maths/FastNoiseLite.h"
#include "coders/png.hpp" #include "coders/imageio.hpp"
#include "files/util.hpp" #include "files/util.hpp"
#include "graphics/core/ImageData.hpp" #include "graphics/core/ImageData.hpp"
#include "maths/Heightmap.hpp" #include "maths/Heightmap.hpp"
#include "engine.hpp"
#include "../lua_util.hpp" #include "../lua_util.hpp"
using namespace lua; using namespace lua;
@ -49,11 +50,9 @@ const float* LuaHeightmap::getValues() const {
} }
static int l_dump(lua::State* L) { static int l_dump(lua::State* L) {
auto paths = scripting::engine->getPaths();
if (auto heightmap = touserdata<LuaHeightmap>(L, 1)) { if (auto heightmap = touserdata<LuaHeightmap>(L, 1)) {
auto filename = require_string(L, 2); auto file = paths->resolve(require_string(L, 2));
if (!files::is_valid_name(filename)) {
throw std::runtime_error("invalid file name");
}
uint w = heightmap->getWidth(); uint w = heightmap->getWidth();
uint h = heightmap->getHeight(); uint h = heightmap->getHeight();
ImageData image(ImageFormat::rgb888, w, h); ImageData image(ImageFormat::rgb888, w, h);
@ -69,7 +68,7 @@ static int l_dump(lua::State* L) {
raster[i*3 + 2] = val; raster[i*3 + 2] = val;
} }
} }
png::write_image(filename, &image); imageio::write(file.u8string(), &image);
} }
return 0; return 0;
} }