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 24, 2024
2 parents d4b54b4 + ae36dfe commit b41c136
Show file tree
Hide file tree
Showing 23 changed files with 664 additions and 122 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog
* Farmesh alpha
* Multi protocol network: Auto use enet for freeminer servers and mt for minetest
* Run abm's in whole world: to enable: abm_world=1
* Mapgen Earth (whole terrain 1:1 with seabeds)

### 5.7.0.0 (?)
* Tree growth
Expand Down
2 changes: 1 addition & 1 deletion build_tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ -z "$NO_DEPS" ]; then
sudo apt install -y $PACKAGE ||:
done
elif [ -e /etc/arch-release ]; then
sudo pacman --needed --noconfirm -S git subversion cmake ninja ccache bzip2 zstd libjpeg-turbo freetype2 libxxf86vm libxi sqlite3 hiredis libvorbis openal curl luajit gettext msgpack-cxx boost clang lld llvm libc++ libc++abi libpng12 libpng libunwind
sudo pacman --needed --noconfirm -S git subversion cmake ninja ccache bzip2 zstd libjpeg-turbo freetype2 glfw-x11 libxxf86vm libxi sqlite3 hiredis libvorbis openal curl luajit gettext msgpack-cxx boost clang lld llvm libc++ libc++abi libpng12 libpng libunwind
echo Todo
fi
fi
Expand Down
9 changes: 5 additions & 4 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Client::Client(
ELoginRegister allow_login_or_register
):
far_container{this},
mesh_thread_pool(rangelim(rangelim(g_settings->getS32("mesh_generation_threads"), 0, 8) ?: Thread::getNumberOfProcessors()/2, 2,8)),

m_simple_singleplayer_mode(is_simple_singleplayer_game),
m_tsrc(tsrc),
Expand Down Expand Up @@ -358,11 +359,12 @@ void Client::Stop()
m_localdb->endSave();
}

merger.reset(); // before m_localdb
mesh_thread_pool.wait_until_empty();

if (m_mods_loaded)
delete m_script;

merger.reset(); // before m_localdb

if (m_localdb)
delete m_localdb;
}
Expand Down Expand Up @@ -417,7 +419,6 @@ Client::~Client()
for (auto &csp : m_sounds_client_to_server)
m_sound->freeId(csp.first);
m_sounds_client_to_server.clear();
last_async.wait();
}

void Client::connect(Address address, bool is_local_server)
Expand Down Expand Up @@ -1071,7 +1072,7 @@ void Client::initLocalMapSaving(const Address &address,
if (!m_simple_singleplayer_mode) {
far_dbases[0].reset(m_localdb, [](auto) {});
if (!merger) {
merger = std::make_unique<WorldMerger>(WorldMerger{
merger.reset(new WorldMerger{
.get_time_func{[this]() {
return m_uptime.load(std::memory_order::relaxed);
}}, // find client game time == server time?
Expand Down
4 changes: 2 additions & 2 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#pragma once

// fm:
#include <future>
#include "client/fm_far_container.h"
#include "map.h"
#include "map_settings_manager.h"
#include "mapgen/mapgen.h"
#include "msgpack_fix.h"
#include "network/fm_connection_use.h"
#include "threading/ThreadPool.h"
constexpr const auto FARMESH_DEFAULT_MAPGEN = MAPGEN_FLAT;
// ==

Expand Down Expand Up @@ -167,7 +167,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
FarContainer far_container;
ServerMap::far_dbases_t far_dbases;
std::unique_ptr<WorldMerger> merger;
std::future<void> last_async;
progschj::ThreadPool mesh_thread_pool;
// ==

public:
Expand Down
48 changes: 23 additions & 25 deletions src/client/clientmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,30 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
struct MapDrawControl
{

// freeminer:
int32_t farmesh = 30000;
uint16_t farmesh_quality = 0;
bool farmesh_stable = false;
int32_t lodmesh = 4;
int cell_size = 1;
uint8_t cell_size_pow = 0;
uint8_t farmesh_quality_pow = 0;

float fps = 30;
float fps_avg = 30;
float fps_wanted = 30;
float drawtime_avg = 30;

float fov = 180;
float fov_add = 0;
float fov_want = 180; // smooth change

float farthest_drawn = 0;

//bool block_overflow;
// freeminer:
int32_t farmesh{30000};
uint16_t farmesh_quality{};
bool farmesh_stable{};
int32_t lodmesh{4};
int cell_size{1};
uint8_t cell_size_pow{};
uint8_t farmesh_quality_pow{};

float fps{30};
float fps_avg{30};
float fps_wanted{30};
float drawtime_avg{30};

float fov{180};
float fov_add{};
float fov_want{180}; // smooth change

float farthest_drawn{};

void fm_init();
MapDrawControl() {
fm_init();
}
// ==
MapDrawControl() { fm_init(); }
// ==


// Wanted drawing range
std::atomic_int32_t wanted_range = 0.0f;
Expand Down
4 changes: 2 additions & 2 deletions src/client/fm_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)
}
auto &packet = *(pkt->packet);
v3bpos_t bpos = packet[TOCLIENT_BLOCKDATA_POS].as<v3bpos_t>();
MapBlock::block_step_t step = 0;
block_step_t step = 0;
packet[TOCLIENT_BLOCKDATA_STEP].convert(step);
std::istringstream istr(
packet[TOCLIENT_BLOCKDATA_DATA].as<std::string>(), std::ios_base::binary);
Expand Down Expand Up @@ -266,7 +266,7 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)
++m_new_farmeshes;

//todo: step ordered thread pool
last_async = std::async(std::launch::async, [this, block]() mutable {
mesh_thread_pool.enqueue([this, block]() mutable {
createFarMesh(block);
auto &client_map = getEnv().getClientMap();
const auto &control = client_map.getControl();
Expand Down
120 changes: 110 additions & 10 deletions src/client/fm_far_calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "irr_v3d.h"
#include "irrlichttypes.h"

int getLodStep(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
block_step_t getLodStep(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
const v3bpos_t &blockpos, const pos_t speedf)
{
if (draw_control.lodmesh) {
Expand Down Expand Up @@ -66,7 +66,7 @@ int getLodStep(const MapDrawControl &draw_control, const v3bpos_t &playerblockpo
return 0;
};

int getFarStepBad(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
block_step_t getFarStepBad(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
const v3bpos_t &blockpos)
{
if (!draw_control.farmesh)
Expand Down Expand Up @@ -120,7 +120,7 @@ using v3tpos_t = v3bpos_t;
using tpos_t = int32_t;
using v3tpos_t = v3s32;
#endif
bool inFarGrid(const v3bpos_t &blockpos, const v3bpos_t &playerblockpos, int step,
bool inFarGrid(const v3bpos_t &blockpos, const v3bpos_t &playerblockpos, block_step_t step,
const MapDrawControl &draw_control)
{
const auto act = getFarActual(blockpos, playerblockpos, step, draw_control);
Expand Down Expand Up @@ -186,9 +186,10 @@ std::optional<child_t> find(const v3tpos_t &block_pos, const v3tpos_t &player_po
child.pos.Z + childSize),
.size = childSize},
}) {
const auto res = find(
block_pos, player_pos, child, cell_size_pow, farmesh_quality, depth + 1);
if (res) {

if (const auto res = find(block_pos, player_pos, child, cell_size_pow,
farmesh_quality, depth + 1);
res) {
return res;
}
}
Expand All @@ -205,7 +206,7 @@ const auto tree_align = tree_pow - 1;
const auto tree_align_size = 1 << (tree_align);
const auto external_pow = tree_pow - 2;

int getFarStepCellSize(const MapDrawControl &draw_control, const v3bpos_t &ppos,
block_step_t getFarStepCellSize(const MapDrawControl &draw_control, const v3bpos_t &ppos,
const v3bpos_t &blockpos, uint8_t cell_size_pow)
{
const auto blockpos_aligned_cell = align_shift(blockpos, cell_size_pow);
Expand Down Expand Up @@ -241,17 +242,16 @@ int getFarStepCellSize(const MapDrawControl &draw_control, const v3bpos_t &ppos,
//return external_pow; //+ draw_control.cell_size_pow;
}

int getFarStep(const MapDrawControl &draw_control, const v3bpos_t &ppos,
block_step_t getFarStep(const MapDrawControl &draw_control, const v3bpos_t &ppos,
const v3bpos_t &blockpos)
{
return getFarStepCellSize(draw_control, ppos, blockpos, draw_control.cell_size_pow);
}

v3bpos_t getFarActual(const v3bpos_t &blockpos, const v3bpos_t &ppos, int step,
v3bpos_t getFarActual(const v3bpos_t &blockpos, const v3bpos_t &ppos, block_step_t step,
const MapDrawControl &draw_control)
{
const auto blockpos_aligned_cell = align_shift(blockpos, draw_control.cell_size_pow);

const auto start =
child_t{.pos = v3tpos_t((((tpos_t)ppos.X >> tree_align) << tree_align) -
(tree_align_size >> 1),
Expand Down Expand Up @@ -288,4 +288,104 @@ v3bpos_t getFarActual(const v3bpos_t &blockpos, const v3bpos_t &ppos, int step,
(blockpos.Z >> ext_align) << ext_align);
}

struct each_param_t
{
const v3tpos_t &player_pos;
const int cell_size_pow;
const uint16_t farmesh_quality;
const std::function<bool(const child_t &)> &func;
const bool two_d{false};
};

void each(const each_param_t &param, const child_t &child)
{
auto distance = std::max({std::abs((tpos_t)param.player_pos.X - child.pos.X -
(child.size >> 1)),
std::abs((tpos_t)param.player_pos.Y - child.pos.Y - (child.size >> 1)),
std::abs((tpos_t)param.player_pos.Z - child.pos.Z - (child.size >> 1))});

if (param.farmesh_quality) {
distance /= param.farmesh_quality;
}

if (distance > child.size) {
param.func(child);
return;
}

const tpos_t childSize = child.size >> 1;
uint8_t i{0};
for (const auto &child : {
// first with unchanged Y for 2d
child_t{.pos{child.pos}, .size = childSize},
child_t{.pos = v3tpos_t(
child.pos.X + childSize, child.pos.Y, child.pos.Z),
.size = childSize},
child_t{.pos = v3tpos_t(
child.pos.X, child.pos.Y, child.pos.Z + childSize),
.size = childSize},
child_t{.pos = v3tpos_t(child.pos.X + childSize, child.pos.Y,
child.pos.Z + childSize),
.size = childSize},

// two_d ends here

child_t{.pos = v3tpos_t(
child.pos.X, child.pos.Y + childSize, child.pos.Z),
.size = childSize},
child_t{.pos = v3tpos_t(child.pos.X + childSize, child.pos.Y + childSize,
child.pos.Z),
.size = childSize},
child_t{.pos = v3tpos_t(child.pos.X, child.pos.Y + childSize,
child.pos.Z + childSize),
.size = childSize},
child_t{.pos = v3tpos_t(child.pos.X + childSize, child.pos.Y + childSize,
child.pos.Z + childSize),
.size = childSize},
}) {

if (param.two_d && i++ >= 4) {
break;
}

if (child.size < (1 << (param.cell_size_pow))) {
if (param.func(child)) {
return;
}
continue;
}

each(param, 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)
{

const auto start =
child_t{.pos = v3tpos_t((((tpos_t)ppos.X >> tree_align) << tree_align) -
(tree_align_size >> 1),
two_d
?: (((tpos_t)(ppos.Y) >> tree_align) << tree_align) -
(tree_align_size >> 1),
(((tpos_t)(ppos.Z) >> tree_align) << tree_align) -
(tree_align_size >> 1)),
.size{tree_size}};

const auto func_convert = [&func](const child_t &child) {
return func(v3bpos_t(child.pos.X, child.pos.Y, child.pos.Z), child.size);
};

// DUMP(start.pos, start.size, tree_align);

each({.player_pos{ppos.X, ppos.Y, ppos.Z},
.cell_size_pow{cell_size_pow},
.farmesh_quality{draw_control.farmesh_quality},
.func{func_convert},
.two_d{static_cast<bool>(two_d)}},
start);
}

#endif
16 changes: 10 additions & 6 deletions src/client/fm_far_calc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#pragma once

#include "irr_v3d.h"
#include "irrlichttypes.h"

struct MapDrawControl;

int getLodStep(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
block_step_t getLodStep(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
const v3bpos_t &block_pos, const pos_t speedf);
int getFarStepCellSize(const MapDrawControl &draw_control, const v3bpos_t &ppos,
block_step_t getFarStepCellSize(const MapDrawControl &draw_control, const v3bpos_t &ppos,
const v3bpos_t &blockpos, uint8_t cell_size_pow);
int getFarStep(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
block_step_t getFarStep(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
const v3bpos_t &block_pos);
int getFarStepBad(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
block_step_t getFarStepBad(const MapDrawControl &draw_control, const v3bpos_t &playerblockpos,
const v3bpos_t &block_pos);
bool inFarGrid(const v3bpos_t &blockpos, const v3bpos_t &playerblockpos, int step,
bool inFarGrid(const v3bpos_t &blockpos, const v3bpos_t &playerblockpos, block_step_t step,
const MapDrawControl &draw_control);
v3bpos_t getFarActual(const v3bpos_t &blockpos, const v3bpos_t &playerblockpos, int step,
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,
const std::function<bool(const v3bpos_t &, const bpos_t &)> &func);
Loading

0 comments on commit b41c136

Please sign in to comment.