Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/wip5.8.0' into wip5.8.0webport
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Dec 2, 2024
2 parents 931233e + 64792e3 commit 99aa22b
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 46 deletions.
48 changes: 20 additions & 28 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,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");
//==


Expand Down Expand Up @@ -4664,36 +4664,28 @@ void Game::updateFrame(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;
Expand Down
3 changes: 3 additions & 0 deletions src/client/renderingengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ constexpr bool emscripten =
#endif
;

const bool slow = debug || android || emscripten;
const bool slow = debug || emscripten; // || android

void fm_set_default_settings(Settings *settings) {

Expand Down
59 changes: 46 additions & 13 deletions src/mapgen/earth/hgt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand All @@ -402,6 +432,7 @@ bool height_hgt::load(ll_t lat, ll_t lon)
}
}
}
*/

// TODO: because unzip
//#if 1 //!defined(_WIN32)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 20 additions & 4 deletions src/script/lua_api/l_mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 99aa22b

Please sign in to comment.