diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-02 20:54:02 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-02 20:54:02 +0200 |
commit | 827b9f8d7054158b058679999d77c1345162a293 (patch) | |
tree | b03741002579b03d3657c1e496e73993e4070fa9 /src/serverenvironment.cpp | |
parent | 3ff3103e98b350712543f926c429ab339700e252 (diff) | |
parent | 9fc018ded10225589d2559d24a5db739e891fb31 (diff) | |
download | dragonfireclient-827b9f8d7054158b058679999d77c1345162a293.tar.xz |
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'src/serverenvironment.cpp')
-rw-r--r-- | src/serverenvironment.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index 6a9001052..2855f04b8 100644 --- a/src/serverenvironment.cpp +++ b/src/serverenvironment.cpp @@ -378,10 +378,7 @@ void ActiveBlockList::update(std::vector<PlayerSAO*> &active_players, /* Update m_list */ - m_list.clear(); - for (v3s16 p : newlist) { - m_list.insert(p); - } + m_list = std::move(newlist); } /* @@ -626,6 +623,9 @@ PlayerSAO *ServerEnvironment::loadPlayer(RemotePlayer *player, bool *new_player, /* Add object to environment */ addActiveObject(playersao); + // Update active blocks asap so objects in those blocks appear on the client + m_force_update_active_blocks = true; + return playersao; } @@ -1332,13 +1332,16 @@ void ServerEnvironment::step(float dtime) /* Manage active block list */ - if (m_active_blocks_management_interval.step(dtime, m_cache_active_block_mgmt_interval)) { + if (m_active_blocks_mgmt_interval.step(dtime, m_cache_active_block_mgmt_interval) || + m_force_update_active_blocks) { ScopeProfiler sp(g_profiler, "ServerEnv: update active blocks", SPT_AVG); + /* Get player block positions */ std::vector<PlayerSAO*> players; - for (RemotePlayer *player: m_players) { + players.reserve(m_players.size()); + for (RemotePlayer *player : m_players) { // Ignore disconnected players if (player->getPeerId() == PEER_ID_INEXISTENT) continue; @@ -1363,8 +1366,6 @@ void ServerEnvironment::step(float dtime) m_active_blocks.update(players, active_block_range, active_object_range, blocks_removed, blocks_added); - m_active_block_gauge->set(m_active_blocks.size()); - /* Handle removed blocks */ @@ -1388,14 +1389,21 @@ void ServerEnvironment::step(float dtime) for (const v3s16 &p: blocks_added) { MapBlock *block = m_map->getBlockOrEmerge(p); if (!block) { - m_active_blocks.m_list.erase(p); - m_active_blocks.m_abm_list.erase(p); + // TODO: The blocks removed here will only be picked up again + // on the next cycle. To minimize the latency of objects being + // activated we could remember the blocks pending activating + // and activate them instantly as soon as they're loaded. + m_active_blocks.remove(p); continue; } activateBlock(block); } + + // Some blocks may be removed again by the code above so do this here + m_active_block_gauge->set(m_active_blocks.size()); } + m_force_update_active_blocks = false; /* Mess around in active blocks |