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 Aug 28, 2024
2 parents a07a74f + a9e890e commit 8019a19
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 32 deletions.
24 changes: 19 additions & 5 deletions src/fm_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,35 @@ void Map::eraseBlock(const MapBlockP block)
m_block_cache = nullptr;
}

MapNode dummy{CONTENT_IGNORE};

MapNode &Map::getNodeTry(const v3pos_t &p)
MapNode Map::getNodeTry(const v3pos_t &p)
{
#ifndef NDEBUG
ScopeProfiler sp(g_profiler, "Map: getNodeTry");
#endif
auto blockpos = getNodeBlockPos(p);
auto block = getBlockNoCreateNoEx(blockpos, true);
if (!block)
return dummy; // MapNode(CONTENT_IGNORE);
if (!block) {
return {CONTENT_IGNORE};
}
auto relpos = p - blockpos * MAP_BLOCKSIZE;
return block->getNodeTry(relpos);
}

MapNode &Map::getNodeRef(const v3pos_t &p)
{
#ifndef NDEBUG
ScopeProfiler sp(g_profiler, "Map: getNodeTry");
#endif
auto blockpos = getNodeBlockPos(p);
auto block = getBlockNoCreateNoEx(blockpos, true);
if (!block) {
static thread_local MapNode dummy{CONTENT_IGNORE};
return dummy;
}
auto relpos = p - blockpos * MAP_BLOCKSIZE;
return block->getNodeRef(relpos);
}

/*
MapNode Map::getNodeLog(v3POS p){
auto blockpos = getNodeBlockPos(p);
Expand Down
5 changes: 3 additions & 2 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class Map : public NodeContainer


//freeminer:
MapNode &getNodeTry(const v3pos_t &p);
MapNode getNodeTry(const v3pos_t &p);
//MapNode getNodeNoLock(v3s16 p); // dont use

std::atomic_uint m_liquid_step_flow{0};
Expand Down Expand Up @@ -311,6 +311,7 @@ class Map : public NodeContainer
uint64_t m_blocks_delete_time = 0;
// void getBlocks(std::list<MapBlock*> &dest);
concurrent_shared_unordered_map<v3bpos_t, int, v3posHash, v3posEqual> m_db_miss;
MapNode &getNodeRef(const v3pos_t &p);

#if !ENABLE_THREADS
locker<> m_nothread_locker;
Expand All @@ -336,7 +337,7 @@ class Map : public NodeContainer
{
return getNodeTry(p);
};
inline MapNode &getNodeRefUnsafe(const v3pos_t &p) override { return getNodeTry(p); }
inline MapNode &getNodeRefUnsafe(const v3pos_t &p) override { return getNodeRef(p); }

bool isBlockOccluded(const v3pos_t &pos, const v3pos_t & cam_pos_nodes);

Expand Down
3 changes: 2 additions & 1 deletion src/mapblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ static void correctBlockNodeIds(const NameIdMapping *nimap, MapNode *nodes,

void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int compression_level, bool use_content_only)
{
auto lock = lock_shared_rec();
if(!ser_ver_supported(version))
throw VersionMismatchException("ERROR: MapBlock format not supported");

Expand All @@ -419,6 +418,8 @@ void MapBlock::serialize(std::ostream &os_compressed, u8 version, bool disk, int
infostream<<" serialize not generated block"<<std::endl;
}

auto lock = lock_shared_rec();

writeU8(os, flags);
if (version >= 27) {
writeU16(os, m_lighting_complete);
Expand Down
65 changes: 41 additions & 24 deletions src/mapblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct abm_trigger_one {
////

class MapBlock
: public shared_locker
: public locker<> // TODO: find all deadlocks and change to shared_locker
{
public:
MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef);
Expand Down Expand Up @@ -180,6 +180,13 @@ class MapBlock
return m_modified;
}

/*
inline u32 getModifiedReason()
{
return m_modified_reason;
}
*/

std::string getModifiedReasonString();

inline void resetModified()
Expand Down Expand Up @@ -319,18 +326,6 @@ class MapBlock
return getNodeNoEx(p);
}

MapNode &getNodeTry(v3pos_t p)
{
auto lock = try_lock_shared_rec();
if (!lock->owns_lock())
return ignoreNode;
return getNodeNoLock(p);
/*
bool is_valid;
return getNode(p.X, p.Y, p.Z, &is_valid);
*/
}

/*
inline void setNode(s16 x, s16 y, s16 z, MapNode n)
{
Expand All @@ -344,17 +339,6 @@ class MapBlock

void setNode(v3pos_t p, MapNode& n);

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_NO_CHECK, important);
}

////
//// Non-checking variants of the above
////
Expand Down Expand Up @@ -596,6 +580,33 @@ 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);
}

inline MapNode& getNodeRef(const v3pos_t &p)
{
auto lock = try_lock_shared_rec();
if (!lock->owns_lock())
return ignoreNode;
return getNodeNoLock(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_NO_CHECK, important);
}

//===


Expand All @@ -613,6 +624,12 @@ class MapBlock
public:
/*
Public member variables
*/

/*
#ifndef SERVER // Only on client
MapBlockMesh *mesh = nullptr;
#endif
*/

NodeMetadataList m_node_metadata;
Expand Down
6 changes: 6 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,12 @@ void Server::AsyncRunStep(float dtime, bool initial_step)
if (!playersao)
continue;

// TODO: only for minetest clients
#if MINETEST_PROTO
if (client->getState() < CS_Active || client->uptime() < 2)
continue;
#endif

SendActiveObjectRemoveAdd(client.get(), playersao);
}
}
Expand Down

0 comments on commit 8019a19

Please sign in to comment.