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 Oct 15, 2024
2 parents 24a8007 + c53c4df commit e896e5d
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 42 deletions.
5 changes: 3 additions & 2 deletions src/client/fm_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)
if (far_blocks_storage.find(bpos) != far_blocks_storage.end()) {
return;
}
far_blocks_storage.insert_or_assign(block->getPos(), block);
}
far_blocks_storage.insert_or_assign(block->getPos(), block);
++m_new_farmeshes;

//todo: step ordered thread pool
Expand All @@ -262,7 +262,8 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)
if (it->second->far_step != block->far_step) {
return;
}
block->far_iteration = it->second->far_iteration.load(std::memory_order::relaxed);
block->far_iteration =
it->second->far_iteration.load(std::memory_order::relaxed);
far_blocks.at(bpos) = block;
}
});
Expand Down
42 changes: 30 additions & 12 deletions src/client/fm_far_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,53 @@ FarContainer::FarContainer(Client *client) : m_client{client}
{
}

const MapNode &FarContainer::getNodeRefUnsafe(const v3pos_t &pos)
namespace
{
auto bpos = getNodeBlockPos(pos);
thread_local MapBlockP block_cache{};
thread_local v3bpos_t block_cache_p;
}

int fmesh_step = getFarStep(m_client->getEnv().getClientMap().getControl(),
const MapNode &FarContainer::getNodeRefUnsafe(const v3pos_t &pos)
{
const auto bpos = getNodeBlockPos(pos);
const auto fmesh_step = getFarStep(m_client->getEnv().getClientMap().getControl(),
getNodeBlockPos(m_client->getEnv().getClientMap().far_blocks_last_cam_pos),
bpos);

const auto &shift = fmesh_step; // + cell_size_pow;
v3bpos_t bpos_aligned((bpos.X >> shift) << shift, (bpos.Y >> shift) << shift,
const v3bpos_t bpos_aligned((bpos.X >> shift) << shift, (bpos.Y >> shift) << shift,
(bpos.Z >> shift) << shift);

const auto &storage =
m_client->getEnv().getClientMap().far_blocks_storage[fmesh_step];
if (const auto &block = storage.at_or(bpos_aligned)) {
MapBlockP block;

if (block_cache && bpos_aligned == block_cache_p) {
block = block_cache;
}

if (!block && fmesh_step < FARMESH_STEP_MAX) {
const auto &storage =
m_client->getEnv().getClientMap().far_blocks_storage[fmesh_step];

block = storage.get(bpos_aligned);
}

if (block) {
v3pos_t relpos = pos - bpos_aligned * MAP_BLOCKSIZE;

const auto &relpos_shift = fmesh_step; // + 1;
auto relpos_shifted = v3pos_t(relpos.X >> relpos_shift, relpos.Y >> relpos_shift,
relpos.Z >> relpos_shift);
const auto relpos_shifted = v3pos_t(relpos.X >> relpos_shift,
relpos.Y >> relpos_shift, relpos.Z >> relpos_shift);
const auto &n = block->getNodeNoLock(relpos_shifted);
if (n.getContent() != CONTENT_IGNORE) {
return n;
}

block_cache_p = bpos_aligned;
block_cache = block;
}

const auto &v = m_mg->visible_content(pos);
if (v.getContent()) {
if (const auto &v = m_mg->visible_content(pos); v.getContent()) {
return v;
}

return m_mg->visible_transparent;
};
8 changes: 4 additions & 4 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4664,14 +4664,14 @@ void Game::updateFrame(f32 dtime,


if (draw_control->range_all && sky->getFogDistance() < 0) {
runData.fog_range = 100000 * BS;
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 = g_settings->getS32("farmesh");
if (runData.fog_range < farmesh) {
runData.fog_range = farmesh;
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) {
Expand Down
21 changes: 11 additions & 10 deletions src/fm_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "irrlichttypes.h"
#include "map.h"
#include "mapblock.h"
#include "log_types.h"
#include "profiler.h"

#include "nodedef.h"
#include "environment.h"
#include "emerge.h"
Expand All @@ -37,8 +35,11 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "voxelalgorithms.h"

#if HAVE_THREAD_LOCAL
thread_local MapBlockP m_block_cache = nullptr;
thread_local v3pos_t m_block_cache_p;
namespace
{
thread_local MapBlockP block_cache{};
thread_local v3bpos_t block_cache_p;
}
#endif

// TODO: REMOVE THIS func and use Map::getBlock
Expand All @@ -59,11 +60,11 @@ MapBlockP Map::getBlock(v3bpos_t p, bool trylock, bool nocache)
auto lock = maybe_shared_lock(m_block_cache_mutex, try_to_lock);
if (lock.owns_lock())
#endif
if (m_block_cache && p == m_block_cache_p) {
if (block_cache && p == block_cache_p) {
#ifndef NDEBUG
g_profiler->add("Map: getBlock cache hit", 1);
#endif
return m_block_cache;
return block_cache;
}
}

Expand All @@ -84,8 +85,8 @@ MapBlockP Map::getBlock(v3bpos_t p, bool trylock, bool nocache)
if (lock.owns_lock())
#endif
{
m_block_cache_p = p;
m_block_cache = block;
block_cache_p = p;
block_cache = block;
}
}

Expand All @@ -102,7 +103,7 @@ void Map::getBlockCacheFlush()
#if ENABLE_THREADS && !HAVE_THREAD_LOCAL
auto lock = unique_lock(m_block_cache_mutex);
#endif
m_block_cache = nullptr;
block_cache = nullptr;
}

MapBlock *Map::createBlankBlockNoInsert(const v3pos_t &p)
Expand Down Expand Up @@ -175,7 +176,7 @@ void Map::eraseBlock(const MapBlockP block)
#if ENABLE_THREADS && !HAVE_THREAD_LOCAL
auto lock = unique_lock(m_block_cache_mutex);
#endif
m_block_cache = nullptr;
block_cache = nullptr;
}

MapNode Map::getNodeTry(const v3pos_t &p)
Expand Down
21 changes: 12 additions & 9 deletions src/mapgen/earth/hgt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ height::height_t hgts::get(height_hgt::ll_t lat, height_hgt::ll_t lon)
}
}
{
auto hgt = std::make_unique<height_dummy>();
const auto lat_dec = hgt->lat_start(lat);
const auto lon_dec = hgt->lon_start(lon);
// DUMP("place dummy", lat, lon, lat_dec, lon_dec, map1[lat_dec].contains(lon_dec));
const static auto hgt_dummy = std::make_shared<height_dummy>();
const auto lat_dec = hgt_dummy->lat_start(lat);
const auto lon_dec = hgt_dummy->lon_start(lon);
DUMP("place dummy", lat, lon, lat_dec, lon_dec, map1[lat_dec].contains(lon_dec));
if (!map1[lat_dec].contains(lon_dec))
map1[lat_dec][lon_dec] = std::move(hgt);
map1[lat_dec][lon_dec] = hgt_dummy;
if (!map90[lat90].contains(lon90))
map90[lat90][lon90] = std::make_unique<height_dummy>();
map90[lat90][lon90] = hgt_dummy;
return map1[lat_dec][lon_dec]->get(lat, lon);
}
}
Expand Down Expand Up @@ -895,7 +895,8 @@ bool height_gebco_tif::load(ll_t lat, ll_t lon)
return false;
}

std::tuple<size_t, size_t, height::ll_t, height::ll_t> height_gebco_tif::ll_to_xy(ll_t lat, ll_t lon)
std::tuple<size_t, size_t, height::ll_t, height::ll_t> height_gebco_tif::ll_to_xy(
ll_t lat, ll_t lon)
{
const height::ll_t lat_seconds = (lat_loaded - lat) * 60 * 60;
const height::ll_t lon_seconds = (lon - lon_loaded) * 60 * 60;
Expand All @@ -921,7 +922,8 @@ int16_t height_gebco_tif::read(uint16_t y, uint16_t x)
return heights[pos];
}

std::tuple<size_t, size_t, height::ll_t, height::ll_t> height_hgt::ll_to_xy(height::ll_t lat, height::ll_t lon)
std::tuple<size_t, size_t, height::ll_t, height::ll_t> height_hgt::ll_to_xy(
height::ll_t lat, height::ll_t lon)
{

const height::ll_t lat_seconds = (lat - (ll_t)lat_loaded) * 60 * 60;
Expand All @@ -931,7 +933,8 @@ std::tuple<size_t, size_t, height::ll_t, height::ll_t> height_hgt::ll_to_xy(heig
return {x, y, lat_seconds, lon_seconds};
}

std::tuple<size_t, size_t, height::ll_t, height::ll_t> height_tif::ll_to_xy(height::ll_t lat, height::ll_t lon)
std::tuple<size_t, size_t, height::ll_t, height::ll_t> height_tif::ll_to_xy(
height::ll_t lat, height::ll_t lon)
{
const ll_t lat_seconds = (lat - (ll_t)lat_loaded) * 60 * 60;
const ll_t lon_seconds = (lon - (ll_t)lon_loaded) * 60 * 60;
Expand Down
6 changes: 4 additions & 2 deletions src/network/clientpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,14 @@ void Client::handleCommand_BlockData(NetworkPacket* pkt)
/*
Create a new block
*/
block = sector->createBlankBlock(p).get();
block = sector->createBlankBlockNoInsert(p);
if (!block->deSerialize(istr, m_server_ser_ver, false)){
delete block;
return;
};
}
block->deSerializeNetworkSpecific(istr);

sector->insertBlock(block);
++m_new_meshes;
}

Expand Down
5 changes: 2 additions & 3 deletions src/threading/concurrent_unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class concurrent_unordered_map_ : public std::unordered_map<Key, T, Hash, Pred,
const mapped_type &get(Args &&...args) const
{
const auto lock = LOCKER::lock_shared_rec();

if (const auto &it = full_type::find(std::forward<Args>(args)...);
it != full_type::end()) {
return it->second;
Expand All @@ -73,14 +72,14 @@ class concurrent_unordered_map_ : public std::unordered_map<Key, T, Hash, Pred,
}

template <typename... Args>
const mapped_type &at_or(Args &&...args) const
const mapped_type &at_or(Args &&...args, const mapped_type &def) const
{
const auto lock = LOCKER::lock_shared_rec();
if (const auto &it = full_type::find(std::forward<Args>(args)...);
it != full_type::end()) {
return it->second;
}
return nothing;
return def;
}

template <typename... Args>
Expand Down

0 comments on commit e896e5d

Please sign in to comment.