Skip to content

Commit

Permalink
simplify active object logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lhofhansl committed Dec 23, 2023
1 parent d58d1c7 commit 0568134
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions src/serverenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,12 @@ void ActiveBlockList::update(std::vector<PlayerSAO*> &active_players,
s16 active_object_range,
std::set<v3s16> &blocks_removed,
std::set<v3s16> &blocks_added,
std::set<v3s16> &extra_blocks_added)
std::set<v3s16> &extralist)
{
/*
Create the new list
*/
std::set<v3s16> newlist = m_forceloaded_list;
std::set<v3s16> extralist;
m_abm_list = m_forceloaded_list;
for (const PlayerSAO *playersao : active_players) {
v3s16 pos = getNodeBlockPos(floatToInt(playersao->getBasePosition(), BS));
Expand All @@ -366,37 +365,21 @@ void ActiveBlockList::update(std::vector<PlayerSAO*> &active_players,
}
}

/*
Find out which blocks on the old list are not on the new list
*/
// Go through old list
for (v3s16 p : m_list) {
// If not on new list, it's been removed
if (newlist.find(p) == newlist.end() && extralist.find(p) == newlist.end())
blocks_removed.insert(p);
}

/*
Find out which blocks on the new list are not on the old list
*/
// Go through new list
// make sure extra list only contains extra blocks
for (v3s16 p : newlist) {
// remove duplicate blocks from the extra list
extralist.erase(p);
// If not on old list, it's been added
if (m_list.find(p) == m_list.end())
blocks_added.insert(p);
}
for (v3s16 p : extralist) {
newlist.insert(p);
// If not on old list, it's been added
if (m_list.find(p) == m_list.end())
extra_blocks_added.insert(p);
}

/*
Update m_list
*/
// newlist now contains all blocks
newlist.insert(extralist.begin(), extralist.end());

// Find out which blocks on the old list are not on the new list
std::set_difference(m_list.begin(), m_list.end(), newlist.begin(), newlist.end(), std::inserter(blocks_removed, blocks_removed.end()));

// Find out which blocks on the new list are not on the old list
std::set_difference(newlist.begin(), newlist.end(), m_list.begin(), m_list.end(), std::inserter(blocks_added, blocks_added.end()));

// Update m_list
m_list = std::move(newlist);
}

Expand Down

0 comments on commit 0568134

Please sign in to comment.