mirror of
https://github.com/bdnugget/freeminer.git
synced 2026-11-07 06:57:27 +00:00
Farmesh cleaner
This commit is contained in:
1 parent
745bf53de9
commit
a759623e00
10 files changed
+95
-37
No files matched your search
@@ -1130,6 +1130,9 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)
|
||||
fmesh_step, m_control));
|
||||
}
|
||||
|
||||
if (mesh) {
|
||||
mesh->last_used = m_client->m_uptime;
|
||||
}
|
||||
// Add to set
|
||||
//block->refGrab();
|
||||
//block->resetUsageTimer();
|
||||
@@ -1481,6 +1484,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
|
||||
if (is_frustum_culled(mesh_sphere_center, mesh_sphere_radius))
|
||||
continue;
|
||||
|
||||
block_mesh->last_used = m_client->m_uptime;
|
||||
|
||||
// Mesh animation
|
||||
if (pass == scene::ESNRP_SOLID) {
|
||||
// 50 nodes is pretty arbitrary but it should work somewhat nicely
|
||||
@@ -2013,6 +2018,8 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
|
||||
// Number of blocks with mesh in rendering range
|
||||
u32 blocks_in_range_with_mesh = 0;
|
||||
|
||||
std::unordered_set<v3bpos_t> blocks_skip_farmesh;
|
||||
|
||||
/*
|
||||
for (auto §or_it : m_sectors) {
|
||||
const MapSector *sector = sector_it.second;
|
||||
@@ -2052,18 +2059,23 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
|
||||
if (m_drawlist_shadow.emplace(block->getPos(), block).second) {
|
||||
block->refGrab();
|
||||
}
|
||||
|
||||
blocks_skip_farmesh.emplace(block->getPos());
|
||||
}
|
||||
|
||||
#if FARMESH_SHADOWS
|
||||
{
|
||||
const auto lock = m_far_blocks.lock_shared_rec();
|
||||
for (const auto &[pos, block] : m_far_blocks) {
|
||||
if (far_iteration_clean && block->far_iteration < far_iteration_clean) {
|
||||
} else if (block->far_iteration >= far_iteration_use) {
|
||||
m_drawlist_shadow.emplace(pos, block);
|
||||
{
|
||||
const auto lock = m_far_blocks.lock_shared_rec();
|
||||
for (const auto &[pos, block] : m_far_blocks) {
|
||||
if (far_iteration_clean && block->far_iteration < far_iteration_clean) {
|
||||
} else if (block->far_iteration >= far_iteration_use) {
|
||||
if (blocks_skip_farmesh.contains(pos))
|
||||
continue;
|
||||
|
||||
m_drawlist_shadow.emplace(pos, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
m_drawlist_shadow_current = !m_drawlist_shadow_current;
|
||||
|
||||
@@ -205,9 +205,9 @@ public:
|
||||
async_step_runner update_drawlist_async;
|
||||
async_step_runner update_shadows_async;
|
||||
std::map<v3pos_t, MapBlock*> m_block_boundary;
|
||||
void cleanPerodic(uint32_t uptime);
|
||||
private:
|
||||
|
||||
|
||||
//std::map<v3s16, MapBlock*, MapBlockComparer> m_drawlist;
|
||||
std::vector<MapBlock*> m_keeplist;
|
||||
/*
|
||||
|
||||
@@ -173,11 +173,10 @@ void Client::createFarMesh(MapBlockPtr &block)
|
||||
//const auto &m_camera_offset = m_camera->getOffset();
|
||||
const auto &step = block->far_step;
|
||||
MeshMakeData mdat(m_client->getNodeDefManager(),
|
||||
MAP_BLOCKSIZE * m_client->getMeshGrid().cell_size, m_mesh_grid,
|
||||
0, step, &m_client->far_container);
|
||||
MAP_BLOCKSIZE * m_client->getMeshGrid().cell_size, m_mesh_grid, 0, step,
|
||||
&m_client->far_container);
|
||||
mdat.m_blockpos = blockpos_actual;
|
||||
const auto mbmsh =
|
||||
std::make_shared<MapBlockMesh>(m_client, &mdat);
|
||||
const auto mbmsh = std::make_shared<MapBlockMesh>(m_client, &mdat);
|
||||
block->setFarMesh(mbmsh, step);
|
||||
block->creating_far_mesh = false;
|
||||
}
|
||||
@@ -254,7 +253,7 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)
|
||||
block->content_only != CONTENT_AIR) {
|
||||
if (getNodeBlockPos(floatToInt(m_env.getLocalPlayer()->getPosition(), BS))
|
||||
.getDistanceFrom(bpos) <= 1)
|
||||
addUpdateMeshTaskWithEdge(bpos);
|
||||
addUpdateMeshTaskWithEdge(bpos);
|
||||
}
|
||||
} else {
|
||||
static thread_local const auto settings_farmesh_server =
|
||||
@@ -267,11 +266,13 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)
|
||||
auto &far_blocks_storage = getEnv().getClientMap().far_blocks_storage[step];
|
||||
{
|
||||
const auto lock = far_blocks_storage.lock_unique_rec();
|
||||
if (far_blocks_storage.find(bpos) != far_blocks_storage.end()) {
|
||||
if (const auto it = far_blocks_storage.find(bpos);
|
||||
it != far_blocks_storage.end() && it->second.block) {
|
||||
return;
|
||||
}
|
||||
|
||||
far_blocks_storage.insert_or_assign(block->getPos(), std::make_pair(block, (int)m_uptime));
|
||||
far_blocks_storage.insert_or_assign(
|
||||
block->getPos(), Map::BlockUsed{block, (int32_t)m_uptime});
|
||||
}
|
||||
++m_new_farmeshes;
|
||||
|
||||
@@ -366,3 +367,37 @@ void Client::sendDrawControl()
|
||||
pkt.putLongString({buffer.data(), buffer.size()});
|
||||
Send(&pkt);
|
||||
}
|
||||
|
||||
void ClientMap::cleanPerodic(uint32_t uptime)
|
||||
{
|
||||
#if FARMESH_CLEAN
|
||||
for (const auto &[pos, block] : m_blocks) {
|
||||
thread_local static const auto client_unload_unused_data_timeout =
|
||||
g_settings->getFloat("client_unload_unused_data_timeout");
|
||||
|
||||
{
|
||||
int step = 0;
|
||||
for (auto &m : block->m_lod_mesh) {
|
||||
if (m) {
|
||||
if (m->last_used + client_unload_unused_data_timeout < uptime) {
|
||||
m.reset();
|
||||
}
|
||||
}
|
||||
++step;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int step = 0;
|
||||
for (auto &m : block->m_far_mesh) {
|
||||
if (m) {
|
||||
if (m->last_used + client_unload_unused_data_timeout < uptime) {
|
||||
m.reset();
|
||||
}
|
||||
}
|
||||
++step;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -39,7 +39,7 @@ const MapNode &FarContainer::getNodeRefUnsafe(const v3pos_t &pos)
|
||||
|
||||
if (!block && step < FARMESH_STEP_MAX) {
|
||||
const auto &storage = m_client->getEnv().getClientMap().far_blocks_storage[step];
|
||||
block = storage.get(bpos_aligned).first;
|
||||
block = storage.get(bpos_aligned).block;
|
||||
}
|
||||
|
||||
const auto loadBlock = [this](const auto &bpos, const auto step) -> MapBlockPtr {
|
||||
|
||||
+20
-15
@@ -68,9 +68,9 @@ void FarMesh::makeFarBlock(const v3bpos_t &blockpos, block_step_t step, bool bne
|
||||
auto &far_blocks = //near ? m_client->getEnv().getClientMap().m_far_near_blocks :
|
||||
client_map.m_far_blocks;
|
||||
if (const auto it = client_map.far_blocks_storage[step].find(blockpos_actual);
|
||||
it != client_map.far_blocks_storage[step].end()) {
|
||||
auto &block = it->second.first;
|
||||
it->second.second = m_client->m_uptime;
|
||||
it != client_map.far_blocks_storage[step].end() && it->second.block) {
|
||||
auto &block = it->second.block;
|
||||
it->second.last_used = m_client->m_uptime;
|
||||
{
|
||||
const auto lock = far_blocks.lock_unique_rec();
|
||||
if (const auto &fbit = far_blocks.find(blockpos_actual);
|
||||
@@ -291,10 +291,10 @@ int FarMesh::go_container()
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto contains = m_client->getEnv()
|
||||
.getClientMap()
|
||||
.far_blocks_storage[step]
|
||||
.contains(bpos);
|
||||
auto &step_blocks =
|
||||
m_client->getEnv().getClientMap().far_blocks_storage[step];
|
||||
const auto it = step_blocks.find(bpos);
|
||||
const auto contains = it != step_blocks.end() && it->second.block;
|
||||
|
||||
if (contains) {
|
||||
makeFarBlock(bpos, step);
|
||||
@@ -664,6 +664,7 @@ uint8_t FarMesh::update(v3opos_t camera_pos,
|
||||
}
|
||||
*/
|
||||
|
||||
#if FARMESH_CLEAN
|
||||
if (complete_set) {
|
||||
const auto now = m_client->m_uptime.load(); //porting::getTimeMs();
|
||||
if (now > async_cleaner_next) {
|
||||
@@ -672,22 +673,25 @@ uint8_t FarMesh::update(v3opos_t camera_pos,
|
||||
async_cleaner_next = now + client_unload_unused_data_timeout / 2;
|
||||
async_cleaner.step([this]() {
|
||||
auto &client_map = m_client->getEnv().getClientMap();
|
||||
const auto &far_blocks = client_map.m_far_blocks;
|
||||
//const auto &far_blocks = client_map.m_far_blocks;
|
||||
block_step_t step = 0;
|
||||
for (auto &bs : client_map.far_blocks_storage) {
|
||||
std::vector<v3pos_t> del;
|
||||
//std::vector<v3pos_t> del;
|
||||
{
|
||||
if (const auto lock = bs.try_lock_shared_rec();
|
||||
lock->owns_lock()) {
|
||||
for (const auto &b : bs) {
|
||||
if (m_client->m_uptime >
|
||||
b.second.second +
|
||||
client_unload_unused_data_timeout) {
|
||||
del.emplace_back(b.first);
|
||||
for (auto &b : bs) {
|
||||
if (b.second.last_used &&
|
||||
m_client->m_uptime >
|
||||
b.second.last_used +
|
||||
client_unload_unused_data_timeout) {
|
||||
b.second.last_used = 0;
|
||||
b.second.block.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (const auto sz = del.size(); sz) {
|
||||
infostream << "Deleting old far blocks step=" << step << " "
|
||||
<< sz << " / " << bs.size() << "\n";
|
||||
@@ -695,12 +699,13 @@ uint8_t FarMesh::update(v3opos_t camera_pos,
|
||||
for (const auto &pos : del) {
|
||||
bs.erase(pos);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
++step;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return planes_processed;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ class Server;
|
||||
// #define FARMESH_FAST 1
|
||||
// #define FARMESH_DEBUG 1 // One direction, one thread, no neighborhoods
|
||||
#define FARMESH_SHADOWS 1
|
||||
//#define FARMESH_CLEAN 1
|
||||
|
||||
class FarMesh
|
||||
{
|
||||
|
||||
+1
-1
@@ -967,7 +967,7 @@ void Hud::drawBlockBounds()
|
||||
.m_far_blocks_last_cam_pos),
|
||||
blockPos);
|
||||
*/
|
||||
const auto &mesh_step = block->far_step;
|
||||
const auto &mesh_step = block->far_step;
|
||||
int g = 0;
|
||||
|
||||
if (!inFarGrid(blockPos, getNodeBlockPos(
|
||||
|
||||
@@ -623,6 +623,7 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data):
|
||||
lod_step{data->lod_step},
|
||||
fscale{data->fscale},
|
||||
timestamp{data->timestamp},
|
||||
last_used{static_cast<u32>(client->m_uptime)},
|
||||
|
||||
m_tsrc(client->getTextureSource()),
|
||||
m_shdrsrc(client->getShaderSource()),
|
||||
|
||||
@@ -253,9 +253,9 @@ public:
|
||||
const int lod_step;
|
||||
const int fscale;
|
||||
//bool no_draw = 0;
|
||||
unsigned int timestamp = 0;
|
||||
//u32 m_usage_timer = 0;
|
||||
// ===
|
||||
unsigned int timestamp{};
|
||||
uint32_t last_used{};
|
||||
// ===
|
||||
|
||||
|
||||
/// Radius of the bounding-sphere, in BS-space.
|
||||
|
||||
@@ -276,8 +276,12 @@ public:
|
||||
using far_blocks_ask_t = concurrent_shared_unordered_map<v3bpos_t,
|
||||
std::pair<block_step_t, uint32_t>>; // client
|
||||
far_blocks_ask_t m_far_blocks_ask;
|
||||
std::array<concurrent_unordered_map<v3bpos_t, std::pair<MapBlockPtr, int>>, FARMESH_STEP_MAX>
|
||||
far_blocks_storage;
|
||||
struct BlockUsed
|
||||
{
|
||||
MapBlockPtr block{};
|
||||
int32_t last_used{};
|
||||
};
|
||||
std::array<concurrent_unordered_map<v3bpos_t, BlockUsed>, FARMESH_STEP_MAX> far_blocks_storage;
|
||||
//double m_far_blocks_created = 0;
|
||||
float far_blocks_sent_timer{1};
|
||||
v3pos_t far_blocks_last_cam_pos;
|
||||
|
||||
Reference in new issue
Block a user