diff options
author | sfan5 <sfan5@live.de> | 2022-05-26 22:22:48 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2022-05-29 14:00:19 +0200 |
commit | c1d03695d4859ff4a531c31b6bddcd8f50384c41 (patch) | |
tree | e8a8b88a3089adbda8897969cd596f413f275f8c | |
parent | ea74680df4340172674adfc3335e6ba887c3f79e (diff) | |
download | minetest-c1d03695d4859ff4a531c31b6bddcd8f50384c41.tar.gz minetest-c1d03695d4859ff4a531c31b6bddcd8f50384c41.tar.bz2 minetest-c1d03695d4859ff4a531c31b6bddcd8f50384c41.zip |
Minor code improvements around active block keeping
-rw-r--r-- | src/serverenvironment.cpp | 20 | ||||
-rw-r--r-- | src/serverenvironment.h | 6 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp index bff563a61..06bfc7b98 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); } /* @@ -1343,7 +1340,8 @@ void ServerEnvironment::step(float dtime) 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; @@ -1368,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 */ @@ -1393,13 +1389,19 @@ 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; diff --git a/src/serverenvironment.h b/src/serverenvironment.h index 223cd3420..00184421e 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -180,8 +180,14 @@ public: m_list.clear(); } + void remove(v3s16 p) { + m_list.erase(p); + m_abm_list.erase(p); + } + std::set<v3s16> m_list; std::set<v3s16> m_abm_list; + // list of blocks that are always active, not modified by this class std::set<v3s16> m_forceloaded_list; }; |