mirror of
https://github.com/bdnugget/freeminer.git
synced 2026-11-07 06:57:27 +00:00
wip
This commit is contained in:
1 parent
4a233014de
commit
80e724ce2f
7 files changed
+156
-27
No files matched your search
@@ -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
|
||||
|
||||
+105
-4
@@ -24,6 +24,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "client/clientmap.h"
|
||||
#include "constants.h"
|
||||
#include "debug/iostream_debug_helpers.h"
|
||||
#include "irr_v3d.h"
|
||||
#include "irrlichttypes.h"
|
||||
|
||||
@@ -186,9 +187,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;
|
||||
}
|
||||
}
|
||||
@@ -251,7 +253,6 @@ v3bpos_t getFarActual(const v3bpos_t &blockpos, const v3bpos_t &ppos, int 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),
|
||||
@@ -288,4 +289,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 ¶m, 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
|
||||
@@ -22,6 +22,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
|
||||
#pragma once
|
||||
|
||||
#include "irr_v3d.h"
|
||||
#include "irrlichttypes.h"
|
||||
|
||||
struct MapDrawControl;
|
||||
|
||||
@@ -39,3 +40,6 @@ v3bpos_t getFarActual(const v3bpos_t &blockpos, const v3bpos_t &playerblockpos,
|
||||
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);
|
||||
+44
-22
@@ -212,7 +212,6 @@ FarMesh::FarMesh(Client *client, Server *server, MapDrawControl *control) :
|
||||
|
||||
EmergeManager *emerge_use = server ? server->getEmergeManager()
|
||||
: client->m_emerge ? client->m_emerge.get()
|
||||
|
||||
: nullptr;
|
||||
|
||||
if (!emerge_use) {
|
||||
@@ -261,6 +260,30 @@ auto align_shift(auto pos, const auto amount)
|
||||
(pos.Z >>= amount) <<= amount;
|
||||
return pos;
|
||||
}
|
||||
int FarMesh::go_flat()
|
||||
{
|
||||
const auto &draw_control = m_client->getEnv().getClientMap().getControl();
|
||||
|
||||
auto &dcache = direction_caches[0][0];
|
||||
auto &last_range = dcache.step_num;
|
||||
// todo: slowly increase range here
|
||||
if (last_range > 0) {
|
||||
return 0;
|
||||
}
|
||||
last_range = 1;
|
||||
|
||||
const auto cbpos = getNodeBlockPos(m_camera_pos_aligned);
|
||||
|
||||
runFarAll(draw_control, cbpos, draw_control.cell_size_pow, 1,
|
||||
[this, &draw_control](const v3bpos_t &bpos, const bpos_t &size) -> bool {
|
||||
const auto stp = int(log(size) / log(2)) - draw_control.cell_size_pow;
|
||||
// DUMP(bpos, size, stp);
|
||||
makeFarBlocks(bpos, stp);
|
||||
return false;
|
||||
});
|
||||
|
||||
return last_range;
|
||||
}
|
||||
|
||||
int FarMesh::go_direction(const size_t dir_n)
|
||||
{
|
||||
@@ -273,7 +296,7 @@ int FarMesh::go_direction(const size_t dir_n)
|
||||
auto &cache = direction_caches[dir_n];
|
||||
auto &mg_cache = mg_caches[dir_n];
|
||||
|
||||
auto &draw_control = m_client->getEnv().getClientMap().getControl();
|
||||
const auto &draw_control = m_client->getEnv().getClientMap().getControl();
|
||||
|
||||
const auto dir = g_6dirso[dir_n];
|
||||
const auto grid_size_xy = grid_size_x * grid_size_y;
|
||||
@@ -491,30 +514,29 @@ uint8_t FarMesh::update(v3opos_t camera_pos,
|
||||
plane_processed.fill({});
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (mg->surface_2d()) {
|
||||
// TODO: use fast simple quadtree based direct mesh create
|
||||
} else
|
||||
*/
|
||||
|
||||
{
|
||||
uint8_t planes_processed = 0;
|
||||
for (uint8_t i = 0; i < sizeof(g_6dirso) / sizeof(g_6dirso[0]); ++i) {
|
||||
uint8_t planes_processed{};
|
||||
if (mg->surface_2d()) {
|
||||
if (plane_processed[0].processed) {
|
||||
++planes_processed;
|
||||
async[0].step([this]() { plane_processed[0].processed = go_flat(); });
|
||||
}
|
||||
} else {
|
||||
for (uint8_t i = 0; i < sizeof(g_6dirso) / sizeof(g_6dirso[0]); ++i) {
|
||||
#if FARMESH_DEBUG
|
||||
if (i) {
|
||||
break;
|
||||
}
|
||||
if (i) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (!plane_processed[i].processed) {
|
||||
continue;
|
||||
if (!plane_processed[i].processed) {
|
||||
continue;
|
||||
}
|
||||
++planes_processed;
|
||||
async[i].step([this, i = i]() {
|
||||
plane_processed[i].processed = go_direction(i);
|
||||
});
|
||||
}
|
||||
++planes_processed;
|
||||
async[i].step([this, i = i]() {
|
||||
//for (int depth = 0; depth < 100; ++depth) {
|
||||
plane_processed[i].processed = go_direction(i);
|
||||
// if (!plane_processed[i].processed)
|
||||
// break;
|
||||
//}
|
||||
});
|
||||
}
|
||||
planes_processed_last = planes_processed;
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ private:
|
||||
std::array<plane_cache, 6> plane_processed;
|
||||
std::atomic_uint last_distance_max{};
|
||||
int go_direction(const size_t dir_n);
|
||||
int go_flat();
|
||||
uint32_t far_iteration_complete{};
|
||||
bool complete_set = false;
|
||||
uint8_t planes_processed_last{};
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
MapNode layers_get(float value, float max);
|
||||
bool visible(const v3pos_t &p) override;
|
||||
const MapNode &visible_content(const v3pos_t &p, bool use_weather) override;
|
||||
bool surface_2d() override { return false; }; /// TODO make true
|
||||
|
||||
hgts hgt_reader;
|
||||
|
||||
|
||||
@@ -905,7 +905,6 @@ sub sytee (@) {
|
||||
say 'running ', join ' ', @_;
|
||||
file_append("$config->{logdir}/run.sh", join(' ', @_), "\n");
|
||||
my $pid = open my $fh, "-|", "@_ 2>&1" or return "can't open @_: $!";
|
||||
warn $config->{pid_file}, $pid;
|
||||
if ($config->{pid_file}) {
|
||||
unlink $config->{pid_file};
|
||||
file_append($config->{pid_file}, $pid);
|
||||
|
||||
Reference in new issue
Block a user