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 Oct 13, 2024
2 parents 2153c6f + 0a6b0c4 commit bd307ed
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 83 deletions.
19 changes: 10 additions & 9 deletions src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "clientenvironment.h"
#include "irr_v3d.h"
#include "irrlichttypes_extrabloated.h"
#include <atomic>
#include <ostream>
#include <map>
#include <memory>
Expand Down Expand Up @@ -131,13 +132,13 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

private:
//fm:
bool is_simple_singleplayer_game = 0;
float m_timelapse_timer = -1;
bool is_simple_singleplayer_game {};
float m_timelapse_timer {-1};

public:
double m_uptime = 0;
bool use_weather = false;
unsigned int overload = 0;
std::atomic<double> m_uptime {};
bool use_weather {};
unsigned int overload {};

void handleCommand_FreeminerInit(NetworkPacket *pkt);
void handleCommand_BlockDataFm(NetworkPacket *pkt);
Expand All @@ -153,10 +154,10 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
std::unique_ptr<MapgenParams> m_mapgen_params;
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;
size_t m_new_farmeshes = 0;
ChatBackend *chat_backend = nullptr;
f32 fog_range {};
std::atomic_size_t m_new_meshes {};
size_t m_new_farmeshes {};
ChatBackend *chat_backend {};
FarContainer far_container;

// ==
Expand Down
3 changes: 2 additions & 1 deletion src/client/clientmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/mesh.h"
#include "mapblock_mesh.h"
#include <IMaterialRenderer.h>
#include <atomic>
#include <matrix4.h>
#include "mapsector.h"
#include "mapblock.h"
Expand Down Expand Up @@ -825,7 +826,7 @@ void ClientMap::updateDrawListFm(float dtime, unsigned int max_cycle_ms)

//bool free_move = g_settings->getBool("free_move");

float range_max = m_control.range_all ? MAX_MAP_GENERATION_LIMIT*2 : m_control.wanted_range;
auto range_max = m_control.range_all ? MAX_MAP_GENERATION_LIMIT*2 : m_control.wanted_range.load(std::memory_order::relaxed);

const auto speedf = m_client->getEnv().getLocalPlayer()->getSpeed().getLength();

Expand Down
3 changes: 2 additions & 1 deletion src/client/clientmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include "irrlichttypes_extrabloated.h"
#include "map.h"
#include "camera.h"
#include <atomic>
#include <set>
#include <unordered_set>
#include <vector>
Expand Down Expand Up @@ -62,7 +63,7 @@ struct MapDrawControl
// ==

// Wanted drawing range
float wanted_range = 0.0f;
std::atomic_int32_t wanted_range = 0.0f;
// Overrides limits by drawing everything
bool range_all = false;
// Allow rendering out of bounds
Expand Down
4 changes: 2 additions & 2 deletions src/client/fm_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void Client::createFarMesh(MapBlockP &block)
MeshMakeData mdat(m_client, false, 0, step, &m_client->far_container);
mdat.m_blockpos = blockpos_actual;
auto mbmsh = std::make_shared<MapBlockMesh>(&mdat, m_camera_offset);
block->setFarMesh(mbmsh, step, m_client->m_uptime);
block->setFarMesh(mbmsh, step);
block->creating_far_mesh = false;
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ void Client::handleCommand_BlockDataFm(NetworkPacket *pkt)
if (it->second->far_step != block->far_step) {
return;
}
block->far_iteration = it->second->far_iteration;
block->far_iteration = it->second->far_iteration.load(std::memory_order::relaxed);
far_blocks.at(bpos) = block;
}
});
Expand Down
14 changes: 7 additions & 7 deletions src/client/fm_farmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ void FarMesh::makeFarBlock(
}
block->far_iteration = far_iteration_complete;
if (new_block) {
std::async(std::launch::async, [this, block]() mutable {
m_client->createFarMesh(block);
});
std::async(std::launch::async,
[this, block]() mutable { m_client->createFarMesh(block); });
}
return;
}
Expand Down Expand Up @@ -334,8 +333,7 @@ int FarMesh::go_direction(const size_t dir_n)
const auto pos_int = align_shift(
floatToInt(pos, BS), step_aligned_pow > 0 ? step_aligned_pow : 0);

if (radius_box(pos_int, m_camera_pos_aligned) > last_distance_max)
{
if (radius_box(pos_int, m_camera_pos_aligned) > last_distance_max) {
break;
}

Expand All @@ -352,7 +350,6 @@ int FarMesh::go_direction(const size_t dir_n)
mg_cache[pos_int] = visible;
}
}

}
if (ray_cache.visible) {
if (depth > MAP_BLOCKSIZE * 8) {
Expand Down Expand Up @@ -505,8 +502,11 @@ uint8_t FarMesh::update(v3opos_t camera_pos,
if (planes_processed) {
complete_set = false;
}
if (!set_new_cam_pos()) {

bool cam_pos_updated{};
if (far_fast || !planes_processed)
cam_pos_updated = set_new_cam_pos();
if (!cam_pos_updated) {
if (!planes_processed && !complete_set) {
clientMap.far_blocks_last_cam_pos = m_camera_pos_aligned;
clientMap.far_iteration_use = far_iteration_complete;
Expand Down
3 changes: 2 additions & 1 deletion src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.

#include "game.h"

#include <atomic>
#include <iomanip>
#include <cmath>
#include "client/renderingengine.h"
Expand Down Expand Up @@ -4651,7 +4652,7 @@ void Game::updateFrame(f32 dtime,
*/

if (sky->getFogDistance() >= 0) {
draw_control->wanted_range = MYMIN(draw_control->wanted_range, sky->getFogDistance());
draw_control->wanted_range = MYMIN(draw_control->wanted_range.load(std::memory_order::relaxed), sky->getFogDistance());
}


Expand Down
6 changes: 3 additions & 3 deletions src/fm_clientiface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <cstdint>
#include <ranges>
#include "clientiface.h"
#include "constants.h"
#include "irr_v3d.h"
Expand Down Expand Up @@ -607,9 +606,10 @@ uint32_t RemoteClient::SendFarBlocks()

// First with larger iteration and smaller step

for (const auto &[key, block] : std::views::reverse(ordered)) {
for (auto it = ordered.rbegin(); it != ordered.rend(); ++it) {
// for (const auto &[key, block] : std::views::reverse(ordered)) {
m_env->m_server->SendBlockFm(
peer_id, block, serialization_version, net_proto_version);
peer_id, it->second, serialization_version, net_proto_version);
}
}
return sent_cnt;
Expand Down
45 changes: 10 additions & 35 deletions src/fm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#include <unordered_map>
#include <utility>
#include "database/database.h"
#include "debug/iostream_debug_helpers.h"
#include "emerge.h"
#include "filesys.h"
#include "irrTypes.h"
Expand Down Expand Up @@ -57,7 +56,6 @@ void *ServerThreadBase::run()
auto time_last = porting::getTimeMs();

while (!stopRequested()) {
DUMP("");
try {
const auto time_now = porting::getTimeMs();
const auto result = step(time_now - time_last);
Expand Down Expand Up @@ -219,42 +217,19 @@ size_t SendFarBlocksThread::step(float dtime)
}

SendBlocksThread::SendBlocksThread(Server *server) :
thread_vector{"SendBlocks", 30}, m_server{server}
ServerThreadBase{server, "SendBlocks", 30}
{
sleep_start = 100;
sleep_result = 5;
sleep_nothing = 200;
}

void *SendBlocksThread::run()
size_t SendBlocksThread::step(float dtime)
{
BEGIN_DEBUG_EXCEPTION_HANDLER

auto time = porting::getTimeMs();
while (!stopRequested()) {
// infostream<<"S run d="<<m_server->m_step_dtime<< "
// myt="<<(porting::getTimeMs() - time)/1000.0f<<std::endl;
try {
m_server->getEnv().getMap().getBlockCacheFlush();
auto time_now = porting::getTimeMs();
auto sent = m_server->SendBlocks((time_now - time) / 1000.0f);
time = time_now;
std::this_thread::sleep_for(std::chrono::milliseconds(sent ? 5 : 100));
#if !EXCEPTION_DEBUG
} catch (const std::exception &e) {
errorstream << m_name << ": exception: " << e.what() << std::endl
<< stacktrace() << std::endl;
} catch (...) {
errorstream << m_name << ": Unknown unhandled exception at "
<< __PRETTY_FUNCTION__ << ":" << __LINE__ << std::endl
<< stacktrace() << std::endl;
#else
} catch (int) { // nothing
#endif
}
}
END_DEBUG_EXCEPTION_HANDLER
return nullptr;
return m_server->SendBlocks(dtime);
}

LiquidThread::LiquidThread(Server *server) : thread_vector("Liquid", 4), m_server(server)
LiquidThread::LiquidThread(Server *server) : thread_vector{"Liquid", 4}, m_server{server}
{
}

Expand Down Expand Up @@ -295,7 +270,7 @@ void *LiquidThread::run()
return nullptr;
}

EnvThread::EnvThread(Server *server) : thread_vector("Env", 20), m_server(server)
EnvThread::EnvThread(Server *server) : thread_vector{"Env", 20}, m_server{server}
{
}

Expand Down Expand Up @@ -329,7 +304,7 @@ void *EnvThread::run()
return nullptr;
}

AbmThread::AbmThread(Server *server) : thread_vector("Abm", 20), m_server(server)
AbmThread::AbmThread(Server *server) : thread_vector{"Abm", 20}, m_server{server}
{
}

Expand Down Expand Up @@ -675,7 +650,7 @@ void Server::SendBlockFm(session_t peer_id, MapBlockP block, u8 ver,

uint32_t Server::SendFarBlocks(float dtime)
{
ScopeProfiler sp(g_profiler, "Server send far blocks");
ScopeProfiler sp(g_profiler, "Server: Far blocks send");
uint32_t sent{};
for (const auto &client : m_clients.getClientList()) {
if (!client)
Expand Down
7 changes: 3 additions & 4 deletions src/fm_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ class MapThread : public thread_vector
void *run();
};

class SendBlocksThread : public thread_vector
class SendBlocksThread : public ServerThreadBase
{
Server *const m_server;

public:
SendBlocksThread(Server *server);

void *run();
private:
size_t step(float dtime) override;
};

class SendFarBlocksThread : public ServerThreadBase
Expand Down
25 changes: 13 additions & 12 deletions src/mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.

#include "mapblock.h"

#include <atomic>
#include <sstream>
#include "map.h"
#include "light.h"
Expand Down Expand Up @@ -770,36 +771,36 @@ void MapBlock::deSerializeNetworkSpecific(std::istream &is)

const MapBlock::mesh_type empty_mesh;
#if BUILD_CLIENT
const MapBlock::mesh_type &MapBlock::getLodMesh(block_step_t step, bool allow_other)
const MapBlock::mesh_type MapBlock::getLodMesh(block_step_t step, bool allow_other)
{
if (m_lod_mesh[step] || !allow_other)
return m_lod_mesh[step];
if (m_lod_mesh[step].load(std::memory_order::relaxed) || !allow_other)
return m_lod_mesh[step].load(std::memory_order::relaxed);

for (int inc = 1; inc < 4; ++inc) {
if (step + inc < m_lod_mesh.size() && m_lod_mesh[step + inc])
return m_lod_mesh[step + inc];
if (step - inc >= 0 && m_lod_mesh[step - inc])
return m_lod_mesh[step - inc];
if (step + inc < m_lod_mesh.size() && m_lod_mesh[step + inc].load(std::memory_order::relaxed))
return m_lod_mesh[step + inc].load(std::memory_order::relaxed);
if (step - inc >= 0 && m_lod_mesh[step - inc].load(std::memory_order::relaxed))
return m_lod_mesh[step - inc].load(std::memory_order::relaxed);
}
return empty_mesh;
}

const MapBlock::mesh_type& MapBlock::getFarMesh(block_step_t step)
const MapBlock::mesh_type MapBlock::getFarMesh(block_step_t step)
{
return m_far_mesh[step];
return m_far_mesh[step].load(std::memory_order::relaxed);
}

void MapBlock::setLodMesh(const MapBlock::mesh_type &rmesh)
{
const auto ms = rmesh->lod_step;
if (auto mesh = std::move(m_lod_mesh[ms]))
if (auto mesh = std::move(m_lod_mesh[ms].load(std::memory_order::relaxed)))
delete_mesh = std::move(mesh);
m_lod_mesh[ms] = rmesh;
}

void MapBlock::setFarMesh(const MapBlock::mesh_type &rmesh, block_step_t step, uint32_t time)
void MapBlock::setFarMesh(const MapBlock::mesh_type &rmesh, block_step_t step)
{
if (auto mesh = std::move(m_far_mesh[step])) {
if (auto mesh = std::move(m_far_mesh[step].load(std::memory_order::relaxed))) {
delete_mesh = std::move(mesh);
}
m_far_mesh[step] = rmesh;
Expand Down
16 changes: 8 additions & 8 deletions src/mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,24 +527,24 @@ class MapBlock
using block_step_t = uint8_t;

#if BUILD_CLIENT // Only on client
const MapBlock::mesh_type &getLodMesh(block_step_t step, bool allow_other = false);
const MapBlock::mesh_type getLodMesh(block_step_t step, bool allow_other = false);
void setLodMesh(const MapBlock::mesh_type &rmesh);
const MapBlock::mesh_type &getFarMesh(block_step_t step);
void setFarMesh(const MapBlock::mesh_type &rmesh, block_step_t step, uint32_t time);
const MapBlock::mesh_type getFarMesh(block_step_t step);
void setFarMesh(const MapBlock::mesh_type &rmesh, block_step_t step);
std::mutex far_mutex;
u32 mesh_requested_timestamp = 0;
uint8_t mesh_requested_step = 0;
u32 mesh_requested_timestamp {};
uint8_t mesh_requested_step {};

private:
std::array<MapBlock::mesh_type, LODMESH_STEP_MAX + 1> m_lod_mesh;
std::array<MapBlock::mesh_type, FARMESH_STEP_MAX + 1> m_far_mesh;
std::array<std::atomic<MapBlock::mesh_type>, LODMESH_STEP_MAX + 1> m_lod_mesh;
std::array<std::atomic<MapBlock::mesh_type>, FARMESH_STEP_MAX + 1> m_far_mesh;
MapBlock::mesh_type delete_mesh;

public:
#endif

block_step_t far_step{};
uint32_t far_iteration{};
std::atomic_uint32_t far_iteration{};
std::atomic_bool creating_far_mesh{};
std::atomic_short heat{};
std::atomic_short humidity{};
Expand Down
3 changes: 3 additions & 0 deletions util/autotest/auto.pl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
$0 ----mg_math_tglag ----server_optimize ----far -static_spawnpoint='(24600,30000,0)'
$0 ----mg_math_tglag ----server_optimize ----far -static_spawnpoint='(24100,30000,24100)'
$0 ----fall1 -continuous_forward=1 bot
ASAN_OPTIONS=detect_container_overflow=0 $0 ---cmake_leveldb=0 -DENABLE_SYSTEM_JSONCPP=0 -DENABLE_WEBSOCKET=0 -keymap_toggle_block_bounds=KEY_F9 ----fall2 set_client asan build_client run_single
};

no if $] >= 5.017011, warnings => 'experimental::smartmatch';
Expand Down Expand Up @@ -356,6 +358,7 @@ ()
},
unload => {server_unload_unused_data_timeout => 20, client_unload_unused_data_timeout => 15,},
};
$options->{fall2} = { %{$options->{fall1}}, static_spawnpoint => '(10,21000,10)',};

map { /^-(\w+)(?:=(.*))?/ and $options->{opt}{$1} = $2; } @ARGV;
map { /^--(\w+)(?:=(.*))?/ and $options->{pass}{$1} = $2; } @ARGV;
Expand Down

0 comments on commit bd307ed

Please sign in to comment.