482 changes: 425 additions & 57 deletions src/client/clientmap.cpp

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/client/clientmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ClientMap : public Map, public scene::ISceneNode
s32 id
);

virtual ~ClientMap() = default;
virtual ~ClientMap();

bool maySaveBlocks() override
{
Expand Down Expand Up @@ -116,6 +116,8 @@ class ClientMap : public Map, public scene::ISceneNode
void getBlocksInViewRange(v3s16 cam_pos_nodes,
v3s16 *p_blocks_min, v3s16 *p_blocks_max, float range=-1.0f);
void updateDrawList();
// @brief Calculate statistics about the map and keep the blocks alive
void touchMapBlocks();
void updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir, float radius, float length);
// Returns true if draw list needs updating before drawing the next frame.
bool needsUpdateDrawList() { return m_needs_update_drawlist; }
Expand All @@ -136,11 +138,14 @@ class ClientMap : public Map, public scene::ISceneNode
f32 getWantedRange() const { return m_control.wanted_range; }
f32 getCameraFov() const { return m_camera_fov; }

void onSettingChanged(const std::string &name);

private:

// update the vertex order in transparent mesh buffers
void updateTransparentMeshBuffers();


// Orders blocks by distance to the camera
class MapBlockComparer
{
Expand Down Expand Up @@ -205,4 +210,7 @@ class ClientMap : public Map, public scene::ISceneNode
bool m_cache_bilinear_filter;
bool m_cache_anistropic_filter;
u16 m_cache_transparency_sorting_distance;

bool m_new_occlusion_culler;
bool m_enable_raytraced_culling;
};
10 changes: 10 additions & 0 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ struct GameRunData {

float damage_flash;
float update_draw_list_timer;
float touch_blocks_timer;

f32 fog_range;

Expand Down Expand Up @@ -4030,6 +4031,9 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
changed much
*/
runData.update_draw_list_timer += dtime;
runData.touch_blocks_timer += dtime;

bool draw_list_updated = false;

float update_draw_list_delta = 0.2f;

Expand All @@ -4041,6 +4045,12 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
runData.update_draw_list_timer = 0;
client->getEnv().getClientMap().updateDrawList();
runData.update_draw_list_last_cam_dir = camera_direction;
draw_list_updated = true;
}

if (runData.touch_blocks_timer > update_draw_list_delta && !draw_list_updated) {
client->getEnv().getClientMap().touchMapBlocks();
runData.touch_blocks_timer = 0;
}

if (RenderingEngine::get_shadow_renderer()) {
Expand Down
28 changes: 28 additions & 0 deletions src/client/mapblock_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,3 +1582,31 @@ video::SColor encode_light(u16 light, u8 emissive_light)
float b = (day + night) / 2;
return video::SColor(r, b, b, b);
}

u8 get_solid_sides(MeshMakeData *data)
{
v3s16 blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE;
const NodeDefManager *ndef = data->m_client->ndef();

u8 result = 0x3F; // all sides solid;

for (s16 i = 0; i < MAP_BLOCKSIZE && result != 0; i++)
for (s16 j = 0; j < MAP_BLOCKSIZE && result != 0; j++) {
v3s16 positions[6] = {
v3s16(0, i, j),
v3s16(MAP_BLOCKSIZE - 1, i, j),
v3s16(i, 0, j),
v3s16(i, MAP_BLOCKSIZE - 1, j),
v3s16(i, j, 0),
v3s16(i, j, MAP_BLOCKSIZE - 1)
};

for (u8 k = 0; k < 6; k++) {
const MapNode &top = data->m_vmanip.getNodeRefUnsafe(blockpos_nodes + positions[k]);
if (ndef->get(top).solidness != 2)
result &= ~(1 << k);
}
}

return result;
}
5 changes: 5 additions & 0 deletions src/client/mapblock_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,8 @@ void final_color_blend(video::SColor *result,
// TileFrame vector copy cost very much to client
void getNodeTileN(MapNode mn, const v3s16 &p, u8 tileindex, MeshMakeData *data, TileSpec &tile);
void getNodeTile(MapNode mn, const v3s16 &p, const v3s16 &dir, MeshMakeData *data, TileSpec &tile);

/// Return bitset of the sides of the mapblock that consist of solid nodes only
/// Bits:
/// 0 0 -Z +Z -X +X -Y +Y
u8 get_solid_sides(MeshMakeData *data);
1 change: 1 addition & 0 deletions src/client/mesh_generator_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ void MeshUpdateWorkerThread::doUpdate()
MeshUpdateResult r;
r.p = q->p;
r.mesh = mesh_new;
r.solid_sides = get_solid_sides(q->data);
r.ack_block_to_server = q->ack_block_to_server;
r.urgent = q->urgent;

Expand Down
1 change: 1 addition & 0 deletions src/client/mesh_generator_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct MeshUpdateResult
{
v3s16 p = v3s16(-1338, -1338, -1338);
MapBlockMesh *mesh = nullptr;
u8 solid_sides = 0;
bool ack_block_to_server = false;
bool urgent = false;

Expand Down
2 changes: 2 additions & 0 deletions src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ void set_default_settings()
settings->setDefault("max_out_chat_queue_size", "20");
settings->setDefault("pause_on_lost_focus", "false");
settings->setDefault("enable_split_login_register", "true");
settings->setDefault("occlusion_culler", "bfs");
settings->setDefault("enable_raytraced_culling", "true");
settings->setDefault("chat_weblink_color", "#8888FF");

// Keymap
Expand Down
2 changes: 2 additions & 0 deletions src/mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ class MapBlock
bool contents_cached = false;
// True if we never want to cache content types for this block
bool do_not_cache_contents = false;
// marks the sides which are opaque: 00+Z-Z+Y-Y+X-X
u8 solid_sides {0};

private:
/*
Expand Down