From 7adadf0c62d73a8001045665078897debc45b01e Mon Sep 17 00:00:00 2001 From: proller Date: Sun, 1 Dec 2024 04:59:02 +0100 Subject: [PATCH 1/2] fog --- src/client/game.cpp | 48 +++++++++++++------------------ src/client/renderingengine.h | 3 ++ src/defaultsettings.cpp | 2 +- src/script/lua_api/l_mainmenu.cpp | 24 +++++++++++++--- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 33e45ba97..204cd911f 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -724,7 +724,7 @@ struct GameRunData { bool show_block_boundaries = false; bool connected = false; bool reconnect = false; - bool enable_fog = false; + bool enable_fog = g_settings->getBool("enable_fog"); //== @@ -4461,36 +4461,28 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, if (draw_control->range_all && sky->getFogDistance() < 0) { - runData.fog_range = FARMESH_LIMIT * BS; - } else if (!runData.headless_optimize) { - runData.fog_range = draw_control->wanted_range * BS - + 0.0 * MAP_BLOCKSIZE * BS; - - thread_local static const auto farmesh_bs = g_settings->getS32("farmesh") * BS; - if (runData.fog_range < farmesh_bs) { - runData.fog_range = farmesh_bs ; - } - - if (client->use_weather) { - auto humidity = client->getEnv().getClientMap().getHumidity(pos_i, 1); - runData.fog_range *= (1.55 - 1.4*(float)humidity/100); - } - - if (!runData.enable_fog) - runData.fog_range = FARMESH_LIMIT * BS; - else - runData.fog_range = MYMIN( - runData.fog_range, - //(draw_control->farthest_drawn + 20) - draw_control->wanted_range * BS); - runData.fog_range *= 0.9; - - runData.fog_range = fog_was + (runData.fog_range-fog_was)/50; - -/* + runData.fog_range = FOG_RANGE_ALL; } else { +/* runData.fog_range = draw_control->wanted_range * BS; */ + if (!runData.enable_fog) { + runData.fog_range = FOG_RANGE_ALL; + } else { + runData.fog_range = draw_control->wanted_range * BS + 0.0 * MAP_BLOCKSIZE * BS; + thread_local static const auto farmesh_bs = g_settings->getS32("farmesh") * BS; + if (runData.fog_range < farmesh_bs) { + runData.fog_range = farmesh_bs; + } + + if (client->use_weather) { + const auto humidity = client->getEnv().getClientMap().getHumidity(pos_i, 1); + const auto mul = (100 - humidity) / 100.0; + runData.fog_range *= mul * mul * mul * mul; + runData.fog_range += 50 * BS; + } + } + runData.fog_range = fog_was + (runData.fog_range - fog_was) / 50; } client->fog_range = runData.fog_range; diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 22b8a3946..4739ee07f 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -43,6 +43,9 @@ class Minimap; class RenderingCore; +// Instead of a mechanism to disable fog we just set it to be really far away +#define FOG_RANGE_ALL (FARMESH_LIMIT*3 * BS) + class RenderingEngine { public: diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 837e0e521..39c6987d0 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -99,7 +99,7 @@ const bool emscripten = #endif ; -const bool slow = debug || android || emscripten; +const bool slow = debug || emscripten; // || android void fm_set_default_settings(Settings *settings) { diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 7588cb66b..4b592f93c 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -1078,12 +1078,28 @@ int ModApiMainMenu::l_get_lan_servers(lua_State *L) for (const auto &field_name : server.second.getMemberNames()) { lua_pushstring(L, field_name.c_str()); - if (server.second[field_name].isString()) + if (server.second[field_name].isString()) { lua_pushstring(L, server.second[field_name].asCString()); - else if (server.second[field_name].isConvertibleTo(Json::realValue)) + } else if (server.second[field_name].isConvertibleTo(Json::realValue)) { lua_pushnumber(L, server.second[field_name].asDouble()); - else - lua_pushnil(L); + } else if (server.second[field_name].isObject()) { + // TODO: use recursive json->lua convert + lua_newtable(L); + int table = lua_gettop(L); + for (const auto &k : server.second[field_name].getMemberNames()) { + const auto &v = server.second[field_name][k]; + lua_pushstring(L, k.c_str()); + if (v.isConvertibleTo(Json::realValue)) { + lua_pushnumber(L, v.asDouble()); + } else { + lua_pushnil(L); + } + lua_settable(L, table); + } + } + else { + lua_pushnil(L); + } lua_settable(L, top_lvl2); } From 64792e350f69bfab4e97301b35029c33f2d937a7 Mon Sep 17 00:00:00 2001 From: proller Date: Sat, 30 Nov 2024 04:32:44 +0100 Subject: [PATCH 2/2] hgt --- src/mapgen/earth/hgt.cpp | 59 +++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/mapgen/earth/hgt.cpp b/src/mapgen/earth/hgt.cpp index 2dddfc88e..ff2f1c2c1 100644 --- a/src/mapgen/earth/hgt.cpp +++ b/src/mapgen/earth/hgt.cpp @@ -326,7 +326,8 @@ bool height_hgt::load(ll_t lat, ll_t lon) //DUMP(lat_dec, lon_dec); return false; } - DUMP((long)this, lat_dec, lon_dec, lat_loading, lon_loading, lat_loaded, lon_loaded); + DUMP((long long)this, lat_dec, lon_dec, lat_loading, lon_loading, lat_loaded, + lon_loaded); TimeTaker timer("hgt load"); lat_loading = lat_dec; @@ -361,9 +362,11 @@ bool height_hgt::load(ll_t lat, ll_t lon) std::string zipfile = zipname + ".zip"; std::string zipfull = folder + "/" + zipfile; - std::string filename(255, 0); - sprintf(filename.data(), "%c%02d%c%03d.hgt", lat_dec > 0 ? 'N' : 'S', abs(lat_dec), - lon_dec > 0 ? 'E' : 'W', abs(lon_dec)); + char buff[100]; + std::snprintf(buff, sizeof(buff), "%c%02d%c%03d.hgt", lat_dec > 0 ? 'N' : 'S', + abs(lat_dec), lon_dec > 0 ? 'E' : 'W', abs(lon_dec)); + std::string filename = buff; + std::string filefull = folder + "/" + filename; // DUMP(lat_dec, lon_dec, filename, zipname, zipfull); @@ -383,7 +386,34 @@ bool height_hgt::load(ll_t lat, ll_t lon) DUMP("sides", side_length_x, side_length_y, seconds_per_px_x, seconds_per_px_y); }; + // zst fastest + if (srtmTile.empty()) { + const auto zstfile = zipname + "/" + filename + ".zst"; + std::string ffolder = folder + "/" + zipname; + std::string zstdfull = folder + "/" + zstfile; + fs::CreateAllDirs(ffolder); + multi_http_to_file(zstfile, + { + "http://cdn.freeminer.org/earth/" + zstfile, + }, + zstdfull); + if (std::filesystem::exists(zstdfull) && std::filesystem::file_size(zstdfull)) { + + // FIXME: zero copy possible in c++26 or with custom rdbuf + std::ifstream is(zstdfull, std::ios_base::binary); + std::ostringstream os(std::ios_base::binary); + + decompressZstd(is, os); + srtmTile = os.str(); + filesize = srtmTile.size(); + if (filesize) { + set_ratio(filesize); + } + } + } + // bz2 has best compression + /* use zstd if (srtmTile.empty()) { const auto bzipfile = zipname + ".tar.bz2"; std::string bzipfull = folder + "/" + bzipfile; @@ -402,6 +432,7 @@ bool height_hgt::load(ll_t lat, ll_t lon) } } } +*/ // TODO: because unzip //#if 1 //!defined(_WIN32) @@ -483,9 +514,9 @@ bool height_hgt::load(ll_t lat, ll_t lon) } lat_loaded = lat_dec; lon_loaded = lon_dec; - DUMP("loadok", (long)this, heights.size(), lat_loaded, lon_loaded, filesize, zipname, - filename, seconds_per_px_x, get(lat_dec, lon_dec), heights[0], heights.back(), - heights[side_length_x]); + DUMP("loadok", (long long)this, heights.size(), lat_loaded, lon_loaded, filesize, + zipname, filename, seconds_per_px_x, get(lat_dec, lon_dec), heights[0], + heights.back(), heights[side_length_x]); return true; } @@ -530,7 +561,8 @@ bool height_tif::load(ll_t lat, ll_t lon) //DUMP(lat_dec, lon_dec); return false; } - DUMP((long)this, lat_dec, lon_dec, lat_loading, lon_loading, lat_loaded, lon_loaded); + DUMP((long long)this, lat_dec, lon_dec, lat_loading, lon_loading, lat_loaded, + lon_loaded); TimeTaker timer("hgt load"); lat_loading = lat_dec; @@ -618,8 +650,9 @@ bool height_tif::load(ll_t lat, ll_t lon) pixel_per_deg_x = (ll_t)side_length_x / tile_deg_x; pixel_per_deg_y = (ll_t)side_length_y / tile_deg_y; - DUMP("loadok", (long)this, heights.size(), lat_loaded, lon_loaded, - zipname, tifname, seconds_per_px_x, get(lat_dec, lon_dec)); + DUMP("loadok", (long long)this, heights.size(), lat_loaded, + lon_loaded, zipname, tifname, seconds_per_px_x, + get(lat_dec, lon_dec)); DUMP("ppd", pixel_per_deg_x, pixel_per_deg_y); return true; @@ -748,8 +781,8 @@ bool height_gebco_tif::load(ll_t lat, ll_t lon) //DUMP(lat_dec, lon_dec); return false; } - DUMP("loadstart", (long)this, lat_dec, lon_dec, lat_loading, lon_loading, lat_loaded, - lon_loaded); + DUMP("loadstart", (long long)this, lat_dec, lon_dec, lat_loading, lon_loading, + lat_loaded, lon_loaded); TimeTaker timer("tiff load"); lat_loading = lat_dec; @@ -890,7 +923,7 @@ bool height_gebco_tif::load(ll_t lat, ll_t lon) #endif - DUMP("load not ok", (long)this, heights.size(), lat_loaded, lon_loaded, + DUMP("load not ok", (long long)this, heights.size(), lat_loaded, lon_loaded, seconds_per_px_x, get(lat_dec, lon_dec)); return false; }