Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Aug 25, 2024
1 parent 42ed61c commit 087b618
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 35 deletions.
37 changes: 20 additions & 17 deletions src/client/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,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 @@ -833,14 +833,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 @@ -855,7 +855,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 @@ -865,7 +865,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 @@ -931,27 +931,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 @@ -972,6 +974,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 @@ -990,16 +993,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 @@ -1025,8 +1028,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
26 changes: 12 additions & 14 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4609,7 +4609,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, 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 @@ -4634,25 +4634,23 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,

#if 1
const auto camera_position = camera->getPosition();
if (!runData.headless_optimize) {
if (client->m_new_meshes ||
//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 * 1 ||
m_camera_offset_changed) {
if (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)) {
client->m_new_meshes = 0;
runData.update_draw_list_timer = 0;
runData.update_draw_list_last_cam_pos = camera_position;
}
runData.update_draw_list_timer);

}
}
#endif

if (!runData.headless_optimize)
if (RenderingEngine::get_shadow_renderer()) {
updateShadows();
Expand Down
2 changes: 1 addition & 1 deletion src/fm_clientiface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ 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;
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 087b618

Please sign in to comment.