This commit is contained in:
proller committed 2025-09-29 00:30:24 +02:00
1 parent 971ac01a34
commit e0aaa08c49
11 files changed
+117 -53

No files matched your search

+21 -15
View File
@@ -47,7 +47,7 @@ thread_local v3bpos_t block_cache_p;
}
#endif
std::atomic_uint ServerMap::time_life {};
std::atomic_uint ServerMap::time_life{};
// TODO: REMOVE THIS func and use Map::getBlock
MapBlockPtr Map::getBlock(v3bpos_t p, bool trylock, bool nocache)
@@ -77,7 +77,8 @@ MapBlockPtr Map::getBlock(v3bpos_t p, bool trylock, bool nocache)
MapBlockPtr block;
{
const auto lock = trylock ? m_blocks.try_lock_shared_rec() : m_blocks.lock_shared_rec();
const auto lock =
trylock ? m_blocks.try_lock_shared_rec() : m_blocks.lock_shared_rec();
if (!lock->owns_lock())
return nullptr;
const auto &n = m_blocks.find(p);
@@ -238,7 +239,7 @@ MapNode Map::getNodeNoLock(v3POS p) //dont use
}
*/
s16 Map::getHeat(const v3pos_t &p, bool no_random)
s16 Map::getHeat(const v3bpos_t &p, bool no_random)
{
MapBlock *block = getBlockNoCreateNoEx(getNodeBlockPos(p));
if (block != NULL) {
@@ -249,7 +250,7 @@ s16 Map::getHeat(const v3pos_t &p, bool no_random)
return 0;
}
s16 Map::getHumidity(const v3pos_t &p, bool no_random)
s16 Map::getHumidity(const v3bpos_t &p, bool no_random)
{
MapBlock *block = getBlockNoCreateNoEx(getNodeBlockPos(p));
if (block != NULL) {
@@ -260,8 +261,8 @@ s16 Map::getHumidity(const v3pos_t &p, bool no_random)
return 0;
}
ServerMap::heat_t ServerMap::updateBlockHeat(ServerEnvironment *env, const v3pos_t &p,
MapBlock *block, unordered_map_v3pos<ServerMap::heat_t> *cache, bool block_add)
weather::heat_t ServerMap::updateBlockHeat(ServerEnvironment *env, const v3pos_t &p,
MapBlock *block, unordered_map_v3bpos<weather::heat_t> *cache, bool block_add)
{
const auto bp = getNodeBlockPos(p);
const auto gametime = env->getGameTime();
@@ -274,8 +275,10 @@ ServerMap::heat_t ServerMap::updateBlockHeat(ServerEnvironment *env, const v3pos
if (cache && cache->contains(bp)) {
return cache->at(bp); // + myrand_range(0, 1);
}
auto value = m_emerge->biomemgr->calcBlockHeat(p, getSeed(), env->getTimeOfDayF(),
gametime * env->m_time_of_day_speed, env->m_use_weather);
auto value =
m_emerge->getFirstMapgen()->calcBlockHeat(p, getSeed(), env->getTimeOfDayF(),
gametime * env->m_time_of_day_speed, env->m_use_weather);
//auto value = m_emerge->biomemgr->calcBlockHeat(p, getSeed(), env->getTimeOfDayF(), gametime * env->m_time_of_day_speed, env->m_use_weather);
if (!block) {
block = getBlockNoCreateNoEx(bp); //, true);
@@ -283,7 +286,7 @@ ServerMap::heat_t ServerMap::updateBlockHeat(ServerEnvironment *env, const v3pos
{
int8_t blocks_around = 0;
heat_t sum = 0;
weather::heat_t sum = 0;
for (const auto &dir : g_6dirs) {
if (auto nblock = getBlockNoCreateNoEx(bp + dir, true)) {
sum += nblock->humidity;
@@ -313,9 +316,9 @@ ServerMap::heat_t ServerMap::updateBlockHeat(ServerEnvironment *env, const v3pos
return value; // + myrand_range(0, 1);
}
ServerMap::humidity_t ServerMap::updateBlockHumidity(ServerEnvironment *env,
weather::humidity_t ServerMap::updateBlockHumidity(ServerEnvironment *env,
const v3pos_t &p, MapBlock *block,
unordered_map_v3pos<ServerMap::humidity_t> *cache, bool block_add)
unordered_map_v3bpos<weather::humidity_t> *cache, bool block_add)
{
const auto bp = getNodeBlockPos(p);
const auto gametime = env->getGameTime();
@@ -328,8 +331,11 @@ ServerMap::humidity_t ServerMap::updateBlockHumidity(ServerEnvironment *env,
if (cache && cache->count(bp)) {
return cache->at(bp) + myrand_range(0, 1);
}
auto value = m_emerge->biomemgr->calcBlockHumidity(p, getSeed(), env->getTimeOfDayF(),
gametime * env->m_time_of_day_speed, env->m_use_weather);
auto value =
m_emerge->getFirstMapgen()->calcBlockHeat(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);
if (!block) {
block = getBlockNoCreateNoEx(bp); //, true);
@@ -337,7 +343,7 @@ ServerMap::humidity_t ServerMap::updateBlockHumidity(ServerEnvironment *env,
{
int8_t blocks_around = 0;
humidity_t sum = 0;
weather::humidity_t sum = 0;
for (const auto &dir : g_6dirs) {
if (auto nblock = getBlockNoCreateNoEx(bp + dir, true)) {
sum += nblock->humidity;
@@ -1640,7 +1646,7 @@ s32 ServerMap::save(ModifiedState save_level, float dedicated_server_step, bool
//modprofiler.add(block->getModifiedReasonString(), 1);
const auto lock = breakable ? block->try_lock_unique_rec()
: block->lock_unique_rec();
: block->lock_unique_rec();
if (!lock->owns_lock())
continue;
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include <cstdint>
namespace weather
{
using humidity_t = int16_t;
using heat_t = int16_t;
}
+13 -15
View File
@@ -260,6 +260,7 @@ struct Ground
// Return ground level for a single XZ point
int level(const XZPoint &pos) const
{
++mg->stat.level;
const auto h = mg->get_height(pos.X, pos.Y);
return h;
}
@@ -287,16 +288,8 @@ struct WorldEditor
{
// Implementation for adding a block to the world
const auto yg = ground->level({x, z});
const v3pos_t pos{
static_cast<pos_t>(x), static_cast<pos_t>(yg + y), static_cast<pos_t>(z)};
if (!mg || !mg->vm) {
DUMP("broken mg");
return;
}
if (mg->vm->exists(pos)) {
mg->vm->setNode(pos, block);
}
return set_block_absolute(block, x, yg + y, z, replace_with, avoid);
}
void set_block(const Block &block, int x, int y, int z,
@@ -343,6 +336,9 @@ struct WorldEditor
}
if (mg->vm->exists(pos)) {
mg->vm->setNode(pos, block);
++mg->stat.set;
} else {
++mg->stat.miss;
}
}
@@ -362,6 +358,8 @@ struct WorldEditor
const v3pos_t pos{
static_cast<pos_t>(x), static_cast<pos_t>(y), static_cast<pos_t>(z)};
++mg->stat.check;
if (!mg->vm->exists(pos))
return false;
@@ -372,9 +370,11 @@ struct WorldEditor
//inline auto node_to_xz(const osmium::NodeRef &node)
inline auto node_to_xz(const auto &node)
{
const auto pos2 = mg->ll_to_pos({static_cast<ll_t>(node.y()) /
osmium::detail::coordinate_precision,
static_cast<ll_t>(node.x()) / osmium::detail::coordinate_precision});
const auto pos2 = mg->ll_to_pos(
{static_cast<ll_t>(node.y()) /
static_cast<ll_t>(osmium::detail::coordinate_precision),
static_cast<ll_t>(node.x()) /
static_cast<ll_t>(osmium::detail::coordinate_precision)});
// TODO: scale y
return std::make_pair(pos2.X, pos2.Y);
}
@@ -398,7 +398,6 @@ struct WorldEditor
auto [min_x, max_x] = std::minmax(x1, x2);
auto [min_y, max_y] = std::minmax(y1, y2);
auto [min_z, max_z] = std::minmax(z1, z2);
for (std::int32_t x = min_x; x <= max_x; ++x) {
for (std::int32_t y = min_y; y <= max_y; ++y) {
for (std::int32_t z = min_z; z <= max_z; ++z) {
@@ -407,6 +406,7 @@ struct WorldEditor
}
}
}
++mg->stat.fill;
}
void fill_blocks(const Block &block, std::int32_t x1, std::int32_t y1,
@@ -444,13 +444,11 @@ struct WorldEditor
}
using namespace world_editor;
}
#include "arnis-cpp/src/block_definitions.h"
namespace arnis
{
void init(MapgenEarth *mg);
+11
View File
@@ -7,6 +7,7 @@
#include <cmath>
#include "irr_v3d.h"
#include "mapgen.h"
#include "servermap.h"
#include "voxel.h"
#include "noise.h"
#include "gamedef.h"
@@ -1262,3 +1263,13 @@ const MapNode &Mapgen::visible_content(const v3pos_t &p, bool use_weather)
: heat < 40 ? (humidity < 20 ? visible_surface_dry : visible_surface_green)
: visible_surface_hot;
}
weather::heat_t Mapgen::calcBlockHeat(const v3pos_t &p, uint64_t seed, float timeofday, float totaltime, bool use_weather)
{
return m_emerge->biomemgr->calcBlockHeat(p, seed, timeofday, totaltime, use_weather);
}
weather::humidity_t Mapgen::calcBlockHumidity(const v3pos_t &p, uint64_t seed, float timeofday, float totaltime, bool use_weather)
{
return m_emerge->biomemgr->calcBlockHumidity(p, seed, timeofday, totaltime, use_weather);
}
+7 -3
View File
@@ -6,6 +6,7 @@
#pragma once
#include "fm_weather.h"
#include "noise.h"
#include "nodedef.h"
#include "util/string.h"
@@ -239,10 +240,10 @@ public:
virtual int getGroundLevelAtPoint(v2s16 p) { return 0; }
// freeminer:
ServerEnvironment *env = nullptr;
ServerEnvironment *env {};
s16 liquid_pressure = 0;
unordered_map_v3pos<s16> heat_cache;
unordered_map_v3pos<s16> humidity_cache;
unordered_map_v3bpos<weather::heat_t> heat_cache;
unordered_map_v3bpos<weather::humidity_t> humidity_cache;
MapNode visible_surface;
MapNode visible_surface_green;
@@ -257,6 +258,9 @@ public:
virtual bool visible_water_level(const v3pos_t &p);
virtual const MapNode &visible_content(const v3pos_t &p, bool use_weather);
virtual bool surface_2d() { return true; };
virtual weather::heat_t calcBlockHeat(const v3pos_t &p, uint64_t seed, float timeofday, float totaltime, bool use_weather);
virtual weather::humidity_t calcBlockHumidity(const v3pos_t &p, uint64_t seed, float timeofday, float totaltime, bool use_weather);
// ===
// getSpawnLevelAtPoint() is a function within each mapgen that returns a
// suitable y co-ordinate for player spawn ('suitable' usually meaning
+28 -3
View File
@@ -23,6 +23,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include <cstdlib>
#include <memory>
#include <mutex>
#include <osmium/geom/tile.hpp>
#include <sstream>
#include <string>
#include <system_error>
@@ -256,6 +257,10 @@ ll MapgenEarth::pos_to_ll(const pos_t x, const pos_t z)
return {89.9999, 0};
}
}
ll MapgenEarth::pos_to_ll(const v3pos_t &p)
{
return pos_to_ll(p.X, p.Z);
}
v2pos_t MapgenEarth::ll_to_pos(const ll &l)
{
@@ -288,7 +293,7 @@ int MapgenEarth::generateTerrain()
for (pos_t z = node_min.Z; z <= node_max.Z; z++) {
for (pos_t x = node_min.X; x <= node_max.X; x++, index++) {
s16 heat =
auto heat =
m_emerge->env->m_use_weather
? m_emerge->env->getServerMap().updateBlockHeat(m_emerge->env,
v3pos_t(x, node_max.Y, z), nullptr, &heat_cache)
@@ -375,8 +380,7 @@ void MapgenEarth::generateBuildings()
const auto lon_dec = lon_start(tc.lon);
static const auto timestamp = []() {
// const std::string ts = "202509040800";
std::string ts = "latest";
std::string ts = "latest";
g_settings->getNoEx("earth_movisda_timestamp", ts);
return ts;
}();
@@ -449,5 +453,26 @@ void MapgenEarth::generateBuildings()
if (const auto &hdlr = maps_holder->osm_bbox.get(bbox)) {
hdlr->apply();
}
warningstream << "Buildings stat: " << node_min << " set=" << stat.set
<< " miss=" << stat.miss << " level=" << stat.level
<< " check=" << stat.check << " fill=" << stat.fill << "\n";
stat = {};
#endif
}
weather::heat_t MapgenEarth::calcBlockHeat(const v3pos_t &p, uint64_t seed,
float timeofday, float totaltime, bool use_weather)
{
const auto ll = pos_to_ll(p);
const auto tile = osmium::geom::Tile(3, osmium::Location(ll.lon, ll.lat));
return m_emerge->biomemgr->calcBlockHeat(p, seed, timeofday, totaltime, use_weather);
}
weather::humidity_t MapgenEarth::calcBlockHumidity(const v3pos_t &p, uint64_t seed,
float timeofday, float totaltime, bool use_weather)
{
return m_emerge->biomemgr->calcBlockHumidity(
p, seed, timeofday, totaltime, use_weather);
}
+15 -3
View File
@@ -105,8 +105,20 @@ public:
pos_t get_height(pos_t x, pos_t z);
ll pos_to_ll(pos_t x, pos_t z);
ll pos_to_ll(const v3pos_t &p);
v2pos_t ll_to_pos(const ll &l);
//v2d ll_to_pos_absolute(const ll &l);
void bresenham(
pos_t xa, pos_t za, pos_t xb, pos_t zb, pos_t y, pos_t h, const MapNode &n);
weather::heat_t calcBlockHeat(const v3pos_t &p, uint64_t seed, float timeofday,
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;
struct Stat
{
int set{};
int miss{};
int level{};
int check{};
int fill{};
} stat;
};
+2 -2
View File
@@ -307,7 +307,7 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po
}
// Freeminer Weather
s16 BiomeManager::calcBlockHeat(v3pos_t p, uint64_t seed, float timeofday, float totaltime, bool use_weather) {
weather::heat_t BiomeManager::calcBlockHeat(const v3pos_t &p, uint64_t seed, float timeofday, float totaltime, bool use_weather) {
//variant 1: full random
//f32 heat = NoisePerlin3D(np_heat, p.X, env->getGameTime()/100, p.Z, seed);
@@ -334,7 +334,7 @@ s16 BiomeManager::calcBlockHeat(v3pos_t p, uint64_t seed, float timeofday, float
return heat;
}
s16 BiomeManager::calcBlockHumidity(v3pos_t p, uint64_t seed, float timeofday, float totaltime, bool use_weather) {
weather::humidity_t BiomeManager::calcBlockHumidity(const v3pos_t &p, uint64_t seed, float timeofday, float totaltime, bool use_weather) {
auto humidity = NoiseFractal2D(&(mapgen_params->bparams->np_humidity), p.X, p.Z, seed);
// auto humidity = calcHumidityAtPoint(p);
+4 -3
View File
@@ -5,6 +5,7 @@
#pragma once
#include "fm_weather.h"
#include "irr_v3d.h"
#include "objdef.h"
#include "nodedef.h"
@@ -245,9 +246,9 @@ public:
s32 weather_humidity_height;
s32 weather_hot_core;
MapgenParams * mapgen_params = nullptr;
s16 calcBlockHeat(v3pos_t p, uint64_t seed, float timeofday, float totaltime, bool use_weather = 1);
s16 calcBlockHumidity(v3pos_t p, uint64_t seed, float timeofday, float totaltime, bool use_weather = 1);
MapgenParams * mapgen_params{};
weather::heat_t calcBlockHeat(const v3pos_t &p, uint64_t seed, float timeofday, float totaltime, bool use_weather = 1);
weather::humidity_t calcBlockHumidity(const v3pos_t &p, uint64_t seed, float timeofday, float totaltime, bool use_weather = 1);
//====
BiomeGen *createBiomeGen(BiomeGenType type, BiomeParams *params, v3s16 chunksize)
+6 -8
View File
@@ -4,6 +4,7 @@
#pragma once
#include "fm_weather.h"
#include "irr_v3d.h"
#include "mapblock.h"
#include "threading/concurrent_set.h"
@@ -51,15 +52,12 @@ class ServerMap : public Map
{
public:
// freeminer:
using humidity_t = s16;
using heat_t = s16;
virtual heat_t updateBlockHeat(ServerEnvironment *env, const v3pos_t &p,
MapBlock *block = nullptr, unordered_map_v3pos<heat_t> *cache = nullptr,
// freeminer:
virtual weather::heat_t updateBlockHeat(ServerEnvironment *env, const v3pos_t &p,
MapBlock *block = nullptr, unordered_map_v3bpos<weather::heat_t> *cache = nullptr,
bool block_add = true);
virtual humidity_t updateBlockHumidity(ServerEnvironment *env, const v3pos_t &p,
MapBlock *block = nullptr, unordered_map_v3pos<humidity_t> *cache = nullptr,
virtual weather::humidity_t updateBlockHumidity(ServerEnvironment *env, const v3pos_t &p,
MapBlock *block = nullptr, unordered_map_v3bpos<weather::humidity_t> *cache = nullptr,
bool block_add = true);
size_t transforming_liquid_size();