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 80d0f3f commit 73dbefa
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/client/clientmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct MapDrawControl

// freeminer:
int32_t farmesh{30000};
uint16_t farmesh_quality{};
uint8_t farmesh_quality{};
bool farmesh_stable{};
int32_t lodmesh{4};
int cell_size{1};
Expand Down
15 changes: 8 additions & 7 deletions src/client/fm_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)
} else {
static thread_local const auto farmesh_server =
g_settings->getU16("farmesh_server");
if (!farmesh_server)
if (!farmesh_server){
return;
}

auto &far_blocks_storage = getEnv().getClientMap().far_blocks_storage[step];
{
Expand Down Expand Up @@ -340,19 +341,19 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)

void Client::sendDrawControl()
{
MSGPACK_PACKET_INIT((int)TOSERVER_DRAWCONTROL, 7);
MSGPACK_PACKET_INIT((int)TOSERVER_DRAWCONTROL, 3);
const auto &draw_control = m_env.getClientMap().getControl();
PACK(TOSERVER_DRAWCONTROL_WANTED_RANGE, (int32_t)draw_control.wanted_range);
PACK(TOSERVER_DRAWCONTROL_RANGE_ALL, draw_control.range_all);
//PACK(TOSERVER_DRAWCONTROL_RANGE_ALL, draw_control.range_all);
PACK(TOSERVER_DRAWCONTROL_FARMESH, draw_control.farmesh);
PACK(TOSERVER_DRAWCONTROL_LODMESH, draw_control.lodmesh);
PACK(TOSERVER_DRAWCONTROL_FOV, draw_control.fov);
//PACK(TOSERVER_DRAWCONTROL_LODMESH, draw_control.lodmesh);
//PACK(TOSERVER_DRAWCONTROL_FOV, draw_control.fov);
//PACK(TOSERVER_DRAWCONTROL_BLOCK_OVERFLOW, false /*draw_control.block_overflow*/);
PACK(TOSERVER_DRAWCONTROL_LODMESH, draw_control.lodmesh);
//PACK(TOSERVER_DRAWCONTROL_LODMESH, draw_control.lodmesh);
PACK(TOSERVER_DRAWCONTROL_FARMESH_QUALITY, draw_control.farmesh_quality);


NetworkPacket pkt(TOSERVER_DRAWCONTROL, 0);
NetworkPacket pkt(TOSERVER_DRAWCONTROL, buffer.size());
pkt.putLongString({buffer.data(), buffer.size()});
Send(&pkt);
}
28 changes: 28 additions & 0 deletions src/client/fm_farmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
*/

#include <array>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -264,6 +265,29 @@ auto align_shift(auto pos, const auto amount)
(pos.Z >>= amount) <<= amount;
return pos;
}

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 {
const block_step_t step = log(size) / log(2);
const auto contains = m_client->getEnv()
.getClientMap()
.far_blocks_storage[step]
.contains(bpos);

if (contains) {
makeFarBlock(bpos, step);
}

return false;
});
return 0;
}

int FarMesh::go_flat()
{
const auto &draw_control = m_client->getEnv().getClientMap().getControl();
Expand Down Expand Up @@ -566,12 +590,16 @@ uint8_t FarMesh::update(v3opos_t camera_pos,
if (!plane_processed[i].processed) {
continue;
}

++planes_processed;
async[i].step([this, i = i]() {
plane_processed[i].processed = go_direction(i);
});
}
}

go_container();

planes_processed_last = planes_processed;

if (planes_processed) {
Expand Down
1 change: 1 addition & 0 deletions src/client/fm_farmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class FarMesh
std::atomic_uint last_distance_max{};
int go_direction(const size_t dir_n);
int go_flat();
int go_container();
uint32_t far_iteration_complete{};
bool complete_set{};
uint32_t collect_reset_timestamp{static_cast<uint32_t>(-1)};
Expand Down
1 change: 1 addition & 0 deletions src/clientiface.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class RemoteClient
std::atomic_bool range_all{};
std::atomic_int farmesh{};
uint8_t farmesh_quality{};
bool have_farmesh_quality{};
float fov{72};
//bool block_overflow;
ServerEnvironment *m_env{};
Expand Down
4 changes: 4 additions & 0 deletions src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ void fm_set_default_settings(Settings *settings) {
//settings->setDefault("client_mesh_chunk", std::to_string(std::max<int>(1, Thread::getNumberOfProcessors() / 4)));
settings->setDefault("client_mesh_chunk","1");

if (slow || android) {
settings->setDefault("translucent_liquids", "false");
}

// Liquid
settings->setDefault("liquid_real", "true");
settings->setDefault("liquid_step", "100");
Expand Down
51 changes: 49 additions & 2 deletions src/fm_clientiface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cstdint>
#include "clientiface.h"
#include "client/clientmap.h"
#include "client/fm_far_calc.h"
#include "constants.h"
#include "server/clientiface.h"
#include "irr_v3d.h"
#include "irrlichttypes.h"
#include "map.h"
Expand Down Expand Up @@ -605,6 +606,51 @@ uint32_t RemoteClient::SendFarBlocks()
}
}

// TODO: why not have?
if (have_farmesh_quality) {
auto *player = m_env->getPlayer(peer_id);
if (!player)
return 0;

auto *sao = player->getPlayerSAO();
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 {
block_step_t step = log(size) / log(2);
auto &[stepp, sent_ts] = far_blocks_requested[step][bpos];
if (sent_ts < 0) { // <=
return false;
}
const auto dbase = GetFarDatabase(m_env->m_map->m_db.dbase,
m_env->m_server->far_dbases, m_env->m_map->m_savedir,
step);
if (!dbase) {
sent_ts = -1;
return false;
}
const auto block =
loadBlockNoStore(m_env->m_map.get(), dbase, bpos);
if (!block) {
sent_ts = -1;
return false;
}

block->far_step = step;
//sent_ts = 0;
sent_ts = -1; //TODO
ordered.emplace(sent_ts - step, block);

return false;
});
}

// First with larger iteration and smaller step

for (auto it = ordered.rbegin(); it != ordered.rend(); ++it) {
Expand All @@ -613,6 +659,7 @@ uint32_t RemoteClient::SendFarBlocks()
peer_id, it->second, serialization_version, net_proto_version);
}
}

return sent_cnt;
}

Expand Down
17 changes: 12 additions & 5 deletions src/fm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,19 @@ void Server::handleCommand_Drawcontrol(NetworkPacket *pkt)
}
{
const auto lock = client->lock_unique_rec();
client->wanted_range = packet[TOSERVER_DRAWCONTROL_WANTED_RANGE].as<uint32_t>();
client->range_all = packet[TOSERVER_DRAWCONTROL_RANGE_ALL].as<bool>();
client->farmesh = packet[TOSERVER_DRAWCONTROL_FARMESH].as<uint32_t>();
if (packet.contains(TOSERVER_DRAWCONTROL_WANTED_RANGE))
client->wanted_range =
packet[TOSERVER_DRAWCONTROL_WANTED_RANGE].as<uint32_t>();
if (packet.contains(TOSERVER_DRAWCONTROL_RANGE_ALL))
client->range_all = packet[TOSERVER_DRAWCONTROL_RANGE_ALL].as<bool>();
if (packet.contains(TOSERVER_DRAWCONTROL_FARMESH))
client->farmesh = packet[TOSERVER_DRAWCONTROL_FARMESH].as<uint32_t>();
//client->lodmesh = packet[TOSERVER_DRAWCONTROL_LODMESH].as<u32>();
client->fov = packet[TOSERVER_DRAWCONTROL_FOV].as<float>();
client->farmesh_quality = packet[TOSERVER_DRAWCONTROL_FARMESH_QUALITY].as<uint8_t>();
if (packet.contains(TOSERVER_DRAWCONTROL_FARMESH_QUALITY)) {
client->farmesh_quality =
packet[TOSERVER_DRAWCONTROL_FARMESH_QUALITY].as<uint8_t>();
client->have_farmesh_quality = true;
}
}
//client->block_overflow = packet[TOSERVER_DRAWCONTROL_BLOCK_OVERFLOW].as<bool>();

Expand Down
2 changes: 1 addition & 1 deletion src/network/serveropcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
// fm:
{ "TOSERVER_INIT_FM", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_InitFm }, // 0x03
{ "TOSERVER_GET_BLOCKS", TOSERVER_STATE_INGAME, &Server::handleCommand_GetBlocks}, // 0x04
{ "TOSERVER_DRAWCONTROL", TOSERVER_STATE_STARTUP, &Server::handleCommand_Drawcontrol }, // 0x05
{ "TOSERVER_DRAWCONTROL", TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_Drawcontrol }, // 0x05
// ==

null_command_handler, // 0x06
Expand Down

0 comments on commit 73dbefa

Please sign in to comment.