Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Dec 15, 2024
1 parent 9fcff50 commit 903d37e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
3 changes: 3 additions & 0 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ farmesh_quality () int 2
# Farmesh map data from server
farmesh_server () bool true

# Use all changed blocks in radius
farmesh_all_changed () int 10000

# Set to true to disable wield light (enabled by default, requires shaders)
disable_wieldlight () bool false

Expand Down
8 changes: 3 additions & 5 deletions src/client/fm_far_calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include <cstdint>

#include "client/clientmap.h"
#include "constants.h"
#include "irr_v3d.h"
#include "irrlichttypes.h"

Expand Down Expand Up @@ -359,9 +358,8 @@ void each(const each_param_t &param, const child_t &child)
}
}

void runFarAll(const MapDrawControl &draw_control, const v3bpos_t &ppos,
uint8_t cell_size_pow, pos_t two_d,
const std::function<bool(const v3bpos_t &, const bpos_t &)> &func)
void runFarAll(const v3bpos_t &ppos, uint8_t cell_size_pow, uint8_t farmesh_quality,
pos_t two_d, const std::function<bool(const v3bpos_t &, const bpos_t &)> &func)
{

const auto start =
Expand All @@ -382,7 +380,7 @@ void runFarAll(const MapDrawControl &draw_control, const v3bpos_t &ppos,

each({.player_pos{ppos.X, ppos.Y, ppos.Z},
.cell_size_pow{cell_size_pow},
.farmesh_quality{draw_control.farmesh_quality},
.farmesh_quality{farmesh_quality},
.func{func_convert},
.two_d{static_cast<bool>(two_d)}},
start);
Expand Down
4 changes: 2 additions & 2 deletions src/client/fm_far_calc.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ v3bpos_t getFarActual(const v3bpos_t &blockpos, const v3bpos_t &playerblockpos,
block_step_t step, const MapDrawControl &draw_control);
v3bpos_t playerBlockAlign(
const MapDrawControl &draw_control, const v3bpos_t &playerblockpos);
void runFarAll(const MapDrawControl &draw_control, const v3bpos_t &ppos,
uint8_t cell_size_pow, pos_t two_d,
void runFarAll(const v3bpos_t &ppos,
uint8_t cell_size_pow, uint8_t farmesh_quality, pos_t two_d,
const std::function<bool(const v3bpos_t &, const bpos_t &)> &func);
17 changes: 14 additions & 3 deletions src/client/fm_farmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,19 @@ int FarMesh::go_container()
const auto &draw_control = m_client->getEnv().getClientMap().getControl();
const auto cbpos = getNodeBlockPos(m_camera_pos_aligned);

runFarAll(draw_control, cbpos, draw_control.cell_size_pow, false,
[this](const v3bpos_t &bpos, const bpos_t &size) -> bool {
thread_local static const s16 farmesh_all_changed =
g_settings->getU32("farmesh_all_changed");

runFarAll(cbpos, draw_control.cell_size_pow, draw_control.farmesh_quality, 0,
[this, &cbpos](const v3bpos_t &bpos, const bpos_t &size) -> bool {
const block_step_t step = log(size) / log(2);

// TODO: use block center
const auto bdist = radius_box(cbpos, bpos);
if ((bdist << MAP_BLOCKP) > farmesh_all_changed) {
return false;
}

const auto contains = m_client->getEnv()
.getClientMap()
.far_blocks_storage[step]
Expand Down Expand Up @@ -303,7 +313,8 @@ int FarMesh::go_flat()

// todo: maybe save blocks while cam pos not changed
std::array<std::unordered_set<v3bpos_t>, FARMESH_STEP_MAX> blocks;
runFarAll(draw_control, cbpos, draw_control.cell_size_pow, cbpos.Y ?: 1,
runFarAll(cbpos, draw_control.cell_size_pow, draw_control.farmesh_quality,
cbpos.Y ?: 1,
[this, &draw_control, &blocks](
const v3bpos_t &bpos, const bpos_t &size) -> bool {
for (const auto &add : {
Expand Down
2 changes: 2 additions & 0 deletions src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ void fm_set_default_settings(Settings *settings) {
settings->setDefault("farmesh_quality", slow ? "1" : "2"); //depends on client_mesh_chunk
settings->setDefault("farmesh_stable", "0");
settings->setDefault("farmesh_server", "1");
settings->setDefault("farmesh_all_changed", "10000");

settings->setDefault("headless_optimize", "false");
//settings->setDefault("node_highlighting", "halo");
//settings->setDefault("enable_vbo", win ? "false" : "true");
Expand Down
24 changes: 17 additions & 7 deletions src/fm_clientiface.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "client/clientmap.h"
#include "client/fm_far_calc.h"
#include "constants.h"
#include "server/clientiface.h"
Expand All @@ -18,7 +17,6 @@
#include "util/numeric.h"
#include "util/unordered_map_hash.h"


int RemoteClient::GetNextBlocksFm(ServerEnvironment *env, EmergeManager *emerge,
float dtime, std::vector<PrioritySortedBlockTransfer> &dest, double m_uptime,
u64 max_ms)
Expand Down Expand Up @@ -120,7 +118,7 @@ int RemoteClient::GetNextBlocksFm(ServerEnvironment *env, EmergeManager *emerge,
}

// s16 last_nearest_unsent_d = m_nearest_unsent_d;
short d_start = m_nearest_unsent_d;//.load();
short d_start = m_nearest_unsent_d; //.load();

// infostream<<"d_start="<<d_start<<std::endl;

Expand Down Expand Up @@ -618,13 +616,25 @@ uint32_t RemoteClient::SendFarBlocks()
if (!sao)
return 0;

MapDrawControl draw_control;
draw_control.farmesh_quality = farmesh_quality;
auto playerpos = sao->getBasePosition();

auto cbpos = floatToInt(playerpos, BS * MAP_BLOCKSIZE);
runFarAll(draw_control, cbpos, draw_control.cell_size_pow, false,
[this, &ordered](const v3bpos_t &bpos, const bpos_t &size) -> bool {

const auto cell_size = 1; // FMTODO from remoteclient
const auto cell_size_pow = log(cell_size) / log(2);

thread_local static const s16 farmesh_all_changed =
g_settings->getU32("farmesh_all_changed");

runFarAll(cbpos, cell_size_pow, farmesh_quality, false,
[this, &ordered, &cbpos](
const v3bpos_t &bpos, const bpos_t &size) -> bool {
// TODO: use block center
const auto bdist = radius_box(cbpos, bpos);
if (bdist << MAP_BLOCKP > farmesh_all_changed) {
return false;
}

block_step_t step = log(size) / log(2);
auto &[stepp, sent_ts] = far_blocks_requested[step][bpos];
if (sent_ts < 0) { // <=
Expand Down

0 comments on commit 903d37e

Please sign in to comment.