Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Oct 13, 2024
1 parent 7cd4893 commit 0a6b0c4
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 34 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 @@ -802,7 +803,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
3 changes: 2 additions & 1 deletion src/client/game.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 "game.h"

#include <atomic>
#include <iomanip>
#include <cmath>
#include "client/renderingengine.h"
Expand Down Expand Up @@ -4448,7 +4449,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, 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
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

0 comments on commit 0a6b0c4

Please sign in to comment.