mirror of
https://github.com/bdnugget/freeminer.git
synced 2026-11-07 06:57:27 +00:00
earth fix
This commit is contained in:
1 parent
ba12216d60
commit
a0aa0b2e98
6 files changed
+62
-20
No files matched your search
@@ -139,6 +139,11 @@ void Client::MakeEmerge(const Settings &settings, const MapgenType &mgtype)
|
||||
try {
|
||||
m_localserver = std::make_unique<Server>(
|
||||
"farmesh", findSubgame(game), false, Address{}, true);
|
||||
// auto m_env = new ServerEnvironment({}, //std::move(startup_server_map),
|
||||
// m_localserver.get(), &m_metrics_backend // m_metrics_backend.get()
|
||||
// );
|
||||
// m_localserver->m_env = m_env;
|
||||
|
||||
break;
|
||||
} catch (const std::exception &ex) {
|
||||
errorstream << "Failed to make local mapgen server with game " << game
|
||||
@@ -155,6 +160,7 @@ void Client::MakeEmerge(const Settings &settings, const MapgenType &mgtype)
|
||||
g_settings->set("num_emerge_threads", "1");
|
||||
m_emerge = std::make_unique<EmergeManager>(
|
||||
m_localserver.get(), m_localserver->m_metrics_backend.get());
|
||||
// m_emerge->env = &m_localserver->getEnv();
|
||||
m_emerge->initMapgens(m_mapgen_params.get());
|
||||
g_settings->set("num_emerge_threads", num_emerge_threads);
|
||||
}
|
||||
|
||||
+1
-1
@@ -333,7 +333,7 @@ weather::humidity_t ServerMap::updateBlockHumidity(ServerEnvironment *env,
|
||||
}
|
||||
|
||||
auto value =
|
||||
m_emerge->getFirstMapgen()->calcBlockHeat(p, getSeed(), env->getTimeOfDayF(),
|
||||
m_emerge->getFirstMapgen()->calcBlockHumidity(p, getSeed(), env->getTimeOfDayF(),
|
||||
gametime * env->m_time_of_day_speed, env->m_use_weather);
|
||||
//auto value = m_emerge->biomemgr->calcBlockHumidity(p, getSeed(), env->getTimeOfDayF(),gametime * env->m_time_of_day_speed, env->m_use_weather);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <thread>
|
||||
#include <fstream>
|
||||
#include "debug/dump.h"
|
||||
#include "filesys.h"
|
||||
#include "httpfetch.h"
|
||||
#include "log.h"
|
||||
#include "settings.h"
|
||||
@@ -50,12 +51,16 @@ size_t http_to_file(const std::string &url, const std::string &path)
|
||||
return std::filesystem::file_size(path);
|
||||
};
|
||||
|
||||
size_t multi_http_to_file(const std::string &name, const std::vector<std::string> &links,
|
||||
const std::string &path)
|
||||
size_t multi_http_to_file(
|
||||
const std::string &name, const std::vector<std::string> &links, std::string path)
|
||||
{
|
||||
if (path.empty()) {
|
||||
path = porting::path_cache + DIR_DELIM + "earth" + "/" + name;
|
||||
}
|
||||
|
||||
static concurrent_set<std::string> http_failed;
|
||||
if (http_failed.contains(name)) {
|
||||
return std::filesystem::file_size(path);
|
||||
return std::filesystem::exists(path) ? std::filesystem::file_size(path) : 0;
|
||||
}
|
||||
|
||||
if (std::filesystem::exists(path)) {
|
||||
@@ -83,6 +88,20 @@ size_t multi_http_to_file(const std::string &name, const std::vector<std::string
|
||||
return std::filesystem::file_size(path);
|
||||
};
|
||||
|
||||
size_t multi_http_to_file_cdn(
|
||||
const std::string &name, std::vector<std::string> links, const std::string &path)
|
||||
{
|
||||
links.insert(links.begin(),
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
"/"
|
||||
#else
|
||||
"http://cdn.freeminer.org/"
|
||||
#endif
|
||||
"earth/" +
|
||||
name);
|
||||
return multi_http_to_file(name, links, path);
|
||||
}
|
||||
|
||||
size_t multi_http_to_file(const std::vector<std::string> &links, const std::string &path)
|
||||
{
|
||||
static concurrent_set<std::string> http_failed;
|
||||
@@ -115,6 +134,7 @@ size_t multi_http_to_file(const std::vector<std::string> &links, const std::stri
|
||||
return std::filesystem::file_size(path);
|
||||
};
|
||||
|
||||
|
||||
std::string exec_to_string(const std::string &cmd)
|
||||
{
|
||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
|
||||
size_t http_to_file(const std::string &url, const std::string &zipfull);
|
||||
size_t multi_http_to_file(const std::string &zipfile,
|
||||
const std::vector<std::string> &links, const std::string &zipfull);
|
||||
const std::vector<std::string> &links, std::string zipfull = {});
|
||||
size_t multi_http_to_file(
|
||||
const std::vector<std::string> &links, const std::string &zipfull);
|
||||
size_t multi_http_to_file_cdn(const std::string &name, std::vector<std::string> links,
|
||||
const std::string &path = {});
|
||||
|
||||
std::string exec_to_string(const std::string &cmd);
|
||||
+25
-13
@@ -209,17 +209,26 @@ MapgenEarth::MapgenEarth(MapgenEarthParams *params_, EmergeParams *emerge) :
|
||||
hgt_reader.debug = 0;
|
||||
*/
|
||||
|
||||
{
|
||||
const auto heat_img = m_emerge->env->m_server->getGameSpec()->path + "/" +
|
||||
"mods/earth/data/earth_heat.png";
|
||||
if (std::filesystem::exists(heat_img)) {
|
||||
heat_image = std::make_unique<PngImage>(heat_img);
|
||||
}
|
||||
}
|
||||
|
||||
if (!maps_holder) {
|
||||
maps_holder = std::make_unique<maps_holder_t>();
|
||||
}
|
||||
|
||||
{
|
||||
const auto heat_img = maps_holder->data_root + "/earth_heat.png";
|
||||
if (!std::filesystem::exists(heat_img)) {
|
||||
const auto lock = std::lock_guard(maps_holder->download_lock);
|
||||
if (!std::filesystem::exists(heat_img)) {
|
||||
multi_http_to_file_cdn("earth_heat.png", {});
|
||||
}
|
||||
}
|
||||
|
||||
if (std::filesystem::exists(heat_img)) {
|
||||
const auto lock = std::lock_guard(maps_holder->download_lock);
|
||||
if (!maps_holder->heat_image) {
|
||||
maps_holder->heat_image = std::make_unique<PngImage>(heat_img);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MapgenEarth::~MapgenEarth()
|
||||
@@ -398,7 +407,7 @@ void MapgenEarth::generateBuildings()
|
||||
//#include "earth/osmium-inl.h"
|
||||
const auto tc = pos_to_ll(node_min.X, node_min.Z);
|
||||
const auto tc_max = pos_to_ll(node_max.X, node_max.Z);
|
||||
static const auto folder = porting::path_cache + DIR_DELIM + "earth";
|
||||
static const auto folder = maps_holder->data_root;
|
||||
const auto lat_dec = lat_start(tc.lat);
|
||||
const auto lon_dec = lon_start(tc.lon);
|
||||
|
||||
@@ -533,10 +542,13 @@ weather::heat_t MapgenEarth::calcBlockHeat(const v3pos_t &p, uint64_t seed,
|
||||
{
|
||||
#if USE_OSMIUM
|
||||
const auto ll = pos_to_ll(p);
|
||||
if (heat_image) {
|
||||
const auto x = heat_image->width() * ((ll.lon + 180) / 360);
|
||||
const auto y = (std::min<int>( heat_image->height(), heat_image->width()/1.6 )) * ((ll.lat + 90) / 180);
|
||||
const auto pixel = heat_image->get_pixel(x, y);
|
||||
if (maps_holder->heat_image) {
|
||||
const auto x = maps_holder->heat_image->width() *
|
||||
((int(45 + ll.lon + 180) % 360) / 360.0);
|
||||
const auto y = (std::min<int>(maps_holder->heat_image->height(),
|
||||
maps_holder->heat_image->width() / 1.6)) *
|
||||
((90 - ll.lat) / 180);
|
||||
const auto pixel = maps_holder->heat_image->get_pixel(x, y);
|
||||
auto heat = rgbToCelsiusJet(pixel->getRed(), pixel->getGreen(), pixel->getBlue());
|
||||
heat += m_emerge->biomemgr->weather_heat_daily *
|
||||
(sin(cycle_shift(timeofday, -0.25) * M_PI) - 0.5); //-64..0..34
|
||||
|
||||
@@ -74,12 +74,15 @@ public:
|
||||
|
||||
struct maps_holder_t
|
||||
{
|
||||
hgts hgt_reader{porting::path_cache + DIR_DELIM + "earth"};
|
||||
const std::string data_root {porting::path_cache + DIR_DELIM + "earth"};
|
||||
hgts hgt_reader{ data_root };
|
||||
using osm_ptr = std::shared_ptr<handler_i>;
|
||||
lru_cache<std::string, osm_ptr, 50> osm_bbox;
|
||||
std::mutex download_lock;
|
||||
std::mutex osm_bbox_lock;
|
||||
std::mutex osm_http_lock;
|
||||
std::mutex osm_extract_lock;
|
||||
std::unique_ptr<PngImage> heat_image;
|
||||
concurrent_shared_vector<std::string> files_to_delete;
|
||||
~maps_holder_t();
|
||||
};
|
||||
@@ -119,7 +122,6 @@ public:
|
||||
float totaltime, bool use_weather) override;
|
||||
weather::humidity_t calcBlockHumidity(const v3pos_t &p, uint64_t seed,
|
||||
float timeofday, float totaltime, bool use_weather) override;
|
||||
std::unique_ptr<PngImage> heat_image;
|
||||
|
||||
struct Stat
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user