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 Aug 25, 2024
2 parents 18875d8 + 087b618 commit 158595e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 58 deletions.
3 changes: 3 additions & 0 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ void Client::step(float dtime)
delete block->mesh;
block->mesh = nullptr;
*/
if (!block->getLodMesh(r.mesh->lod_step)) {
++m_new_meshes;
}
block->setLodMesh(r.mesh);
block->solid_sides = r.solid_sides;

Expand Down
1 change: 1 addition & 0 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
std::unique_ptr<MapSettingsManager> m_settings_mgr;
//concurrent_unordered_map<v3bpos_t, bool> farmesh_remake;
f32 fog_range = 0;
size_t m_new_meshes = 0;

private:

Expand Down
37 changes: 20 additions & 17 deletions src/client/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)

drawlist.clear();

auto is_frustum_culled = m_client->getCamera()->getFrustumCuller();
//auto is_frustum_culled = m_client->getCamera()->getFrustumCuller();

//v3f camera_position = m_camera_position;
//f32 camera_fov = m_camera_fov;
Expand Down Expand Up @@ -854,14 +854,14 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)
continue;

f32 d = radius_box(bp*MAP_BLOCKSIZE, m_camera_position_node); //blockpos_relative.getLength();
if (d > range_max) {
if (d > range_max ) {
if (d > range_max + m_client->getMeshGrid().cell_size * MAP_BLOCKSIZE) {
if (d > range_max * 4) {
int mul = d / range_max;
block->usage_timer_multiplier = mul;
}
continue;
}
int range = d / MAP_BLOCKSIZE;
int range_blocks = d / MAP_BLOCKSIZE;

block->resetUsageTimer();

Expand All @@ -876,7 +876,7 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)

const auto mesh = block->getLodMesh(mesh_step, true);
{
blocks_in_range++;
++blocks_in_range;

const int smesh_size = !mesh ? -1 : mesh->getMesh()->getMeshBufferCount();

Expand All @@ -886,7 +886,7 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)
{
if ((!mesh && smesh_size < 0) || mesh_step != mesh->lod_step) {
blocks_in_range_without_mesh++;
if (m_mesh_queued < maxq || range <= 2) {
if (m_mesh_queued < maxq || range_blocks <= 2) {
const auto bts = block->getTimestamp();
if (block->mesh_requested_timestamp < bts) {
block->mesh_requested_timestamp = bts;
Expand Down Expand Up @@ -952,27 +952,29 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)
}
*/

if (m_client->getMeshGrid().cell_size > 1) {
// Calculate the coordinates for range and frustum culling
v3opos_t mesh_sphere_center;

f32 mesh_sphere_radius;

v3pos_t block_pos_nodes = block->getPosRelative();

if (mesh) {
mesh_sphere_center = intToFloat(block_pos_nodes, BS)
+ mesh->getBoundingSphereCenter();
mesh_sphere_center = intToFloat(block_pos_nodes, BS) +
mesh->getBoundingSphereCenter();
mesh_sphere_radius = mesh->getBoundingRadius();
} else {
mesh_sphere_center = intToFloat(block_pos_nodes, BS)
+ v3opos_t((MAP_BLOCKSIZE * 0.5f - 0.5f) * BS);
mesh_sphere_center = intToFloat(block_pos_nodes, BS) +
v3opos_t((MAP_BLOCKSIZE * 0.5f - 0.5f) * BS);
mesh_sphere_radius = 0.0f;
}

// First, perform a simple distance check.
if (!m_control.range_all &&
mesh_sphere_center.getDistanceFrom(m_camera_position) >
radius_box(mesh_sphere_center, m_camera_position) >
m_control.wanted_range * BS + mesh_sphere_radius)
continue; // Out of range, skip.
}

// Keep the block alive as long as it is in range.
//block->resetUsageTimer();
Expand All @@ -993,6 +995,7 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)
*/

// Raytraced occlusion culling - send rays from the camera to the block's corners
if (range_blocks>3)
if (!m_control.range_all && occlusion_culling_enabled && m_enable_raytraced_culling &&
mesh &&
isMeshOccluded(block, mesh_grid.cell_size, m_camera_position_node)) {
Expand All @@ -1011,16 +1014,16 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)
*/

if (mesh_step != mesh->lod_step && smesh_size < 0 &&
(m_mesh_queued < maxq * 1.2 || range <= 2)) {
(m_mesh_queued < maxq * 1.2 || range_blocks <= 2)) {
m_client->addUpdateMeshTask(bp);
++m_mesh_queued;
} else if (const auto bts = block->getTimestamp();
bts != BLOCK_TIMESTAMP_UNDEFINED &&
block->getTimestamp() > mesh->timestamp + (smesh_size ? 0
: range >= 2
: range_blocks >= 2
? 60
: 0) &&
(m_mesh_queued < maxq * 1.5 || range <= 2)) {
(m_mesh_queued < maxq * 1.5 || range_blocks <= 2)) {
if (mesh_step > 1)
m_client->addUpdateMeshTask(bp);
else
Expand All @@ -1046,8 +1049,8 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)

//blocks_drawn++;

if(range * MAP_BLOCKSIZE > farthest_drawn)
farthest_drawn = range * MAP_BLOCKSIZE;
if(range_blocks * MAP_BLOCKSIZE > farthest_drawn)
farthest_drawn = range_blocks * MAP_BLOCKSIZE;
}

}
Expand Down
1 change: 0 additions & 1 deletion src/client/clientmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class ClientMap : public Map, public scene::ISceneNode
drawlist_map m_drawlist_0, m_drawlist_1;
std::atomic<drawlist_map *> m_drawlist {&m_drawlist_0};
std::atomic_bool m_drawlist_current = 0;
std::vector<std::pair<v3bpos_t, int>> draw_nearest;
public:
std::map<v3pos_t, MapBlock*> m_block_boundary;
private:
Expand Down
54 changes: 24 additions & 30 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2560,12 +2560,15 @@ void Game::processKeyInput()
} else if (wasKeyDown(KeyType::INCREASE_VIEWING_RANGE)) {
increaseViewRange();
client->sendDrawControl();
++client->m_new_meshes;
} else if (wasKeyDown(KeyType::DECREASE_VIEWING_RANGE)) {
decreaseViewRange();
client->sendDrawControl();
++client->m_new_meshes;
} else if (wasKeyPressed(KeyType::RANGESELECT)) {
toggleFullViewRange();
client->sendDrawControl();
++client->m_new_meshes;
} else if (wasKeyDown(KeyType::ZOOM)) {
checkZoomEnabled();
client->sendDrawControl();
Expand Down Expand Up @@ -3091,16 +3094,16 @@ void Game::increaseViewRange()
s16 server_limit = sky->getFogDistance();

{ //fm:
if (g_settings->getS32("farmesh")) {
if (g_settings->getS32("lodmesh")) {
range_new = range * 1.5;
} else {
range_new = range + MAP_BLOCKSIZE;
range_new = range + MAP_BLOCKSIZE * client->getMeshGrid().cell_size;
}

// it's < 0 if it's outside the range of s16
// and increase it directly from 1 to 16 for less key pressing
if (range_new < MAP_BLOCKSIZE)
range_new = MAP_BLOCKSIZE;
if (range_new < MAP_BLOCKSIZE * client->getMeshGrid().cell_size)
range_new = MAP_BLOCKSIZE * client->getMeshGrid().cell_size;
}

if (range_new >= MAX_MAP_GENERATION_LIMIT) {
Expand All @@ -3126,15 +3129,15 @@ void Game::decreaseViewRange()
pos_t server_limit = sky->getFogDistance();

{ //fm:
if (g_settings->getS32("farmesh")) {
if (g_settings->getS32("lodmesh")) {
range_new = range / 1.5;
} else {
range_new = range - MAP_BLOCKSIZE;
range_new = range - MAP_BLOCKSIZE * client->getMeshGrid().cell_size;
}
}

if (range_new <= MAP_BLOCKSIZE) {
range_new = MAP_BLOCKSIZE;
if (range_new <= MAP_BLOCKSIZE * client->getMeshGrid().cell_size) {
range_new = MAP_BLOCKSIZE * client->getMeshGrid().cell_size;
std::wstring msg = server_limit >= 0 && range_new > server_limit ?
fwgettext("Viewing changed to %d (the minimum), but limited to %d by game or mod", range_new, server_limit) :
fwgettext("Viewing changed to %d (the minimum)", range_new);
Expand Down Expand Up @@ -4809,7 +4812,7 @@ void Game::updateFrame(f32 dtime,
runData.update_draw_list_timer += dtime;
runData.touch_blocks_timer += dtime;

float update_draw_list_delta = 0.2f;
float update_draw_list_delta = 0.5f;

/* mt dir */
#if 0
Expand All @@ -4834,32 +4837,23 @@ void Game::updateFrame(f32 dtime,

#if 1
const auto camera_position = camera->getPosition();
if (!runData.headless_optimize) {
if (//client->getEnv().getClientMap().m_drawlist_last ||
runData.update_draw_list_timer >= update_draw_list_delta ||
if (!runData.headless_optimize)
if ((client->m_new_meshes &&
runData.update_draw_list_timer >= update_draw_list_delta) ||
runData.update_draw_list_last_cam_pos.getDistanceFrom(camera_position) >
MAP_BLOCKSIZE * BS * 2 ||
MAP_BLOCKSIZE * BS * 1 ||
m_camera_offset_changed) {
bool allow = true;
static const auto thread_local more_threads =
g_settings->getBool("more_threads");
if (more_threads) {
updateDrawList_async.step(
updateDrawList_async.step(
[&](const float dtime) {
client->getEnv().getClientMap().updateDrawListFm(
dtime, 10000);
client->m_new_meshes = 0;
runData.update_draw_list_timer = 0;
runData.update_draw_list_last_cam_pos = camera_position;
client->getEnv().getClientMap().updateDrawListFm(dtime, 10000);
},
runData.update_draw_list_timer);
} else
client->getEnv().getClientMap().updateDrawListFm(
runData.update_draw_list_timer);
runData.update_draw_list_timer = 0;
if (allow) {
runData.update_draw_list_last_cam_pos = camera->getPosition();
}
runData.update_draw_list_timer);

}
}
#endif

if (!runData.headless_optimize)
if (RenderingEngine::get_shadow_renderer()) {
updateShadows();
Expand Down
8 changes: 4 additions & 4 deletions src/fm_clientiface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int RemoteClient::GetNextBlocks(ServerEnvironment *env, EmergeManager *emerge,
MYMIN(g_settings->getS16("block_send_optimize_distance"), wanted_range);
*/

const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE;
//const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE;
// infostream << "Fov from client " << camera_fov << " full_d_max " << full_d_max <<
// std::endl;

Expand Down Expand Up @@ -331,13 +331,13 @@ int RemoteClient::GetNextBlocks(ServerEnvironment *env, EmergeManager *emerge,
}

if (block_sent > 0 &&
(/* (block_overflow && d>1) || */ block_sent + (d <= 2 ? 1 : d * d) >
(/* (block_overflow && d>1) || */ block_sent + (d <= 2 ? 1 : d * d * d) >
m_uptime)) {
// DUMP(p, block_sent, d, "ddd");
continue;
}

if (d > 2 && can_skip && occlusion_culling_enabled) {
if (d >= 2 && can_skip && occlusion_culling_enabled) {
const auto visible = [&](const v3pos_t &p) {
ScopeProfiler sp(g_profiler, "SMap: Occusion calls");
auto cpn = p * MAP_BLOCKSIZE;
Expand Down Expand Up @@ -378,7 +378,7 @@ int RemoteClient::GetNextBlocks(ServerEnvironment *env, EmergeManager *emerge,
// bool surely_not_found_on_disk = false;
// bool block_is_invalid = false;
if (block) {
if (d > 2 && block->content_only == CONTENT_AIR) {
if (d >= 2 && block->content_only == CONTENT_AIR) {
uint8_t not_air = 0;
for (const auto &dir : g_6dirs) {
if (const auto *block_near =
Expand Down
7 changes: 4 additions & 3 deletions src/mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,15 +790,16 @@ void MapBlock::deSerializeNetworkSpecific(std::istream &is)
void MapBlock::setLodMesh(const MapBlock::mesh_type &rmesh)
{
const auto ms = rmesh->lod_step;
delete_mesh = std::move(m_lod_mesh[ms]);
if (auto mesh = std::move(m_lod_mesh[ms]))
delete_mesh = std::move(mesh);
m_lod_mesh[ms] = rmesh;
}

void MapBlock::setFarMesh(const MapBlock::mesh_type &rmesh, uint32_t time)
{
const auto ms = rmesh->far_step;
if (const auto mesh = m_far_mesh[ms]) {
delete_mesh = mesh;
if (const auto mesh = std::move(m_far_mesh[ms])) {
delete_mesh = std::move(mesh);
}
m_far_mesh[ms] = rmesh;
}
Expand Down
10 changes: 7 additions & 3 deletions src/threading/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include <cstdint>
#include <future>
#include <chrono>

#if defined(DUMP_STREAM)
#include "log.h"
#endif


class async_step_runner
{
std::future<void> future;
Expand Down Expand Up @@ -57,16 +57,20 @@ class async_step_runner

inline bool valid() { return future.valid(); }

constexpr static uint8_t UNKNOWN = 2;
// 0 : started
// 1 : skipped
// 2 : unknown ?
template <class Func, typename... Args>
bool step(Func func, Args &&...args)
uint8_t step(Func func, Args &&...args)
{
if (future.valid()) {
auto res = future.wait_for(std::chrono::milliseconds(0));
if (res == std::future_status::timeout) {
#if defined(DUMP_STREAM)
++skips;
#endif
return true;
return UNKNOWN;
}
}

Expand Down

0 comments on commit 158595e

Please sign in to comment.