Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Nov 24, 2024
1 parent 2fbb428 commit 121809b
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 155 deletions.
2 changes: 1 addition & 1 deletion games/Repixture
Submodule Repixture updated from 30eccc to b59c1e
2 changes: 1 addition & 1 deletion src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ void Client::sendReady()
void Client::sendPlayerPos()
{
LocalPlayer *player = m_env.getLocalPlayer();
if (!player || !player->getCAO())
if (!player)
return;

// Save bandwidth by only updating position when
Expand Down
2 changes: 2 additions & 0 deletions src/fm_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ thread_local v3bpos_t block_cache_p;
}
#endif

std::atomic_uint ServerMap::time_life {};

// TODO: REMOVE THIS func and use Map::getBlock
MapBlockPtr Map::getBlock(v3bpos_t p, bool trylock, bool nocache)
{
Expand Down
2 changes: 1 addition & 1 deletion src/fm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ int Server::AsyncRunMapStep(float dtime, float dedicated_server_step, bool async

int ret = 0;

m_env->getMap().time_life = m_uptime_counter->get() + m_env->m_game_time_start;
m_env->getServerMap().time_life = m_uptime_counter->get() + m_env->m_game_time_start;

/*
float dtime;
Expand Down
1 change: 0 additions & 1 deletion src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Map::Map(IGameDef *gamedef):
m_gamedef(gamedef),
m_nodedef(gamedef->ndef())
{
time_life = 0;
getBlockCacheFlush();
}

Expand Down
2 changes: 0 additions & 2 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ class Map : public NodeContainer
u32 m_blocks_save_last{};

public:
std::atomic_uint time_life{};

inline MapNode getNodeNoEx(const v3pos_t &p) override { return getNodeTry(p); };
inline MapNode getNodeNoExNoEmerge(const v3pos_t &p) override
{
Expand Down
276 changes: 148 additions & 128 deletions src/mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

#include "mapblock.h"
#include "servermap.h"

#include <atomic>
#include <sstream>
Expand Down Expand Up @@ -51,6 +52,153 @@ static const char *modified_reason_strings[] = {
"unknown",
};

// fm:
MapNode MapBlock::getNodeNoEx(v3pos_t p)
{
#ifndef NDEBUG
ScopeProfiler sp(g_profiler, "Map: getNodeNoEx");
#endif
auto lock = lock_shared_rec();
return getNodeNoLock(p);
}

void MapBlock::setNode(const v3pos_t &p, const MapNode &n, bool important)
{
#ifndef NDEBUG
g_profiler->add("Map: setNode", 1);
#endif

auto nodedef = m_gamedef->ndef();
auto index = p.Z * zstride + p.Y * ystride + p.X;
const auto &f1 = nodedef->get(n.getContent());

auto lock = lock_unique_rec();

const auto &f0 = nodedef->get(data[index].getContent());

data[index] = n;

modified_light light = modified_light_no;
if (f0.light_propagates != f1.light_propagates || f0.solidness != f1.solidness ||
f0.light_source != f1.light_source) /*|| f0.drawtype != f1.drawtype*/
light = modified_light_yes;
if (important)
raiseModified(MOD_STATE_WRITE_NEEDED, light);
}

void MapBlock::raiseModified(u32 mod, modified_light light, bool important)
{
static const thread_local auto save_changed_block =
g_settings->getBool("save_changed_block");

if(mod >= MOD_STATE_WRITE_NEEDED /*&& m_timestamp != BLOCK_TIMESTAMP_UNDEFINED*/) {
m_changed_timestamp = (unsigned int) ServerMap::time_life;
}


if (mod > m_modified) {
if (save_changed_block ||
important) // || m_disk_timestamp != BLOCK_TIMESTAMP_UNDEFINED )
m_modified = mod;
if (m_modified >= MOD_STATE_WRITE_AT_UNLOAD)
m_disk_timestamp.store(m_timestamp);
}
if (light == modified_light_yes) {
setLightingComplete(0);
}
}

void MapBlock::pushElementsToCircuit(Circuit *circuit)
{
}

bool MapBlock::analyzeContent()
{
auto lock = try_lock_shared_rec();
if (!lock->owns_lock())
return false;
content_only = data[0].param0;
content_only_param1 = data[0].param1;
content_only_param2 = data[0].param2;
for (int i = 1; i < MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE; ++i) {
if (data[i].param0 != content_only || data[i].param1 != content_only_param1 ||
data[i].param2 != content_only_param2) {
content_only = CONTENT_IGNORE;
break;
}
}
return true;
}

const MapBlock::mesh_type empty_mesh;
#if CHECK_CLIENT_BUILD()
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];

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];
}
return empty_mesh;
}

const MapBlock::mesh_type MapBlock::getFarMesh(block_step_t step)
{
return m_far_mesh[step];
}

void MapBlock::setLodMesh(const MapBlock::mesh_type &rmesh)
{
const auto ms = rmesh->lod_step;
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, block_step_t step)
{
if (auto mesh = std::move(m_far_mesh[step])) {
delete_mesh = std::move(mesh);
}
m_far_mesh[step] = rmesh;
}

#endif

void MapBlock::incrementUsageTimer(float dtime)
{
std::lock_guard<std::mutex> lock(m_usage_timer_mutex);
m_usage_timer += dtime * usage_timer_multiplier;
}

void MapBlock::setNodeNoLock(v3pos_t p, MapNode n, bool important)
{
data[p.Z * zstride + p.Y * ystride + p.X] = n;
raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE, important);
}

MapNode &MapBlock::getNodeRef(const v3pos_t &p)
{
auto lock = try_lock_shared_rec();
if (!lock->owns_lock())
return ignoreNode;
return getNodeNoLock(p);
}

MapNode MapBlock::getNodeTry(const v3pos_t &p)
{
auto lock = try_lock_shared_rec();
if (!lock->owns_lock())
return ignoreNode;
return getNodeNoLock(p);
}

// ==

/*
MapBlock
*/
Expand Down Expand Up @@ -642,134 +790,6 @@ void MapBlock::deSerializeNetworkSpecific(std::istream &is)
}
}

// fm:
MapNode MapBlock::getNodeNoEx(v3pos_t p)
{
#ifndef NDEBUG
ScopeProfiler sp(g_profiler, "Map: getNodeNoEx");
#endif
auto lock = lock_shared_rec();
return getNodeNoLock(p);
}

void MapBlock::setNode(const v3pos_t &p, const MapNode &n, bool important)
{
#ifndef NDEBUG
g_profiler->add("Map: setNode", 1);
#endif
//if (!isValidPosition(p.X, p.Y, p.Z))
// return;

auto nodedef = m_gamedef->ndef();
auto index = p.Z * zstride + p.Y * ystride + p.X;
const auto &f1 = nodedef->get(n.getContent());

auto lock = lock_unique_rec();

const auto &f0 = nodedef->get(data[index].getContent());

data[index] = n;

modified_light light = modified_light_no;
if (f0.light_propagates != f1.light_propagates || f0.solidness != f1.solidness ||
f0.light_source != f1.light_source) /*|| f0.drawtype != f1.drawtype*/
light = modified_light_yes;
if (important)
raiseModified(MOD_STATE_WRITE_NEEDED, light);
}

void MapBlock::raiseModified(u32 mod, modified_light light, bool important)
{
static const thread_local auto save_changed_block =
g_settings->getBool("save_changed_block");

/*
if(mod >= MOD_STATE_WRITE_NEEDED / *&& m_timestamp != BLOCK_TIMESTAMP_UNDEFINED* /) {
m_changed_timestamp = (unsigned int)m_parent->time_life;
}
*/
if (mod > m_modified) {
if (save_changed_block ||
important) // || m_disk_timestamp != BLOCK_TIMESTAMP_UNDEFINED )
m_modified = mod;
if (m_modified >= MOD_STATE_WRITE_AT_UNLOAD)
m_disk_timestamp.store(m_timestamp);
}
if (light == modified_light_yes) {
setLightingComplete(0);
}
}

void MapBlock::pushElementsToCircuit(Circuit *circuit)
{
}

bool MapBlock::analyzeContent()
{
auto lock = try_lock_shared_rec();
if (!lock->owns_lock())
return false;
content_only = data[0].param0;
content_only_param1 = data[0].param1;
content_only_param2 = data[0].param2;
for (int i = 1; i < MAP_BLOCKSIZE * MAP_BLOCKSIZE * MAP_BLOCKSIZE; ++i) {
if (data[i].param0 != content_only || data[i].param1 != content_only_param1 ||
data[i].param2 != content_only_param2) {
content_only = CONTENT_IGNORE;
break;
}
}
return true;
}

const MapBlock::mesh_type empty_mesh;
#if CHECK_CLIENT_BUILD()
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];

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];
}
return empty_mesh;
}

const MapBlock::mesh_type MapBlock::getFarMesh(block_step_t step)
{
return m_far_mesh[step];
}

void MapBlock::setLodMesh(const MapBlock::mesh_type &rmesh)
{
const auto ms = rmesh->lod_step;
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, block_step_t step)
{
if (auto mesh = std::move(m_far_mesh[step])) {
delete_mesh = std::move(mesh);
}
m_far_mesh[step] = rmesh;
}


#endif

void MapBlock::incrementUsageTimer(float dtime)
{
std::lock_guard<std::mutex> lock(m_usage_timer_mutex);
m_usage_timer += dtime * usage_timer_multiplier;
}

// ===

bool MapBlock::storeActiveObject(u16 id)
{
if (m_static_objects.storeActiveObject(id)) {
Expand Down
24 changes: 4 additions & 20 deletions src/mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,34 +564,18 @@ class MapBlock

std::atomic_bool m_lighting_expired {false};

inline MapNode getNodeTry(const v3pos_t &p)
{
auto lock = try_lock_shared_rec();
if (!lock->owns_lock())
return ignoreNode;
return getNodeNoLock(p);
}
MapNode getNodeTry(const v3pos_t &p);

inline MapNode& getNodeRef(const v3pos_t &p)
{
auto lock = try_lock_shared_rec();
if (!lock->owns_lock())
return ignoreNode;
return getNodeNoLock(p);
}
MapNode &getNodeRef(const v3pos_t &p);

MapNode &getNodeNoLock(v3pos_t p)
{
return data[p.Z*zstride + p.Y*ystride + p.X];
}

inline void setNodeNoLock(v3pos_t p, MapNode n, bool important = false)
{
data[p.Z * zstride + p.Y * ystride + p.X] = n;
raiseModified(MOD_STATE_WRITE_NEEDED, MOD_REASON_SET_NODE, important);
}
void setNodeNoLock(v3pos_t p, MapNode n, bool important = false);

//===
//===

bool storeActiveObject(u16 id);
// clearObject and return removed objects count
Expand Down
2 changes: 2 additions & 0 deletions src/servermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class ServerMap : public Map
s16 findGroundLevel(v2pos_t p2d, bool cacheBlocks);
MapBlockPtr emergeBlockP(v3bpos_t p, bool create_blank=false) override;

static std::atomic_uint time_life;

// == end of freeminer


Expand Down
Loading

0 comments on commit 121809b

Please sign in to comment.