Is there an algorithm for collecting the list of [to_spawn][to_despawn][to_send_movement] players from world on player movement from point A to B.
I have list of player in world. I have function that collects the visible players for a given point. Each player has a list of visible players.
How can I do this fast & efficient?
void p_spawn::filter(player_list &p_l)
{
player_list to_depsawn;
player_list to_spawn;
std::shared_ptr<Node> temp = std::atomic_load(&head);
if (p_l.size() > 0)
{
while (1)
{
if (!temp) break;
bool in = false;
for (size_t i = 0; i < p_l.size(); i++)
{
if (p_l[i]->eid == temp->p->eid)
{
in = true; break;
}
}
if (!in)
{
to_depsawn.push_back(temp->p);
temp->p->spawn.add_erase(parent, false);
add_erase(temp->p, false);
}
temp = temp->next;
}
for (size_t i = 0; i < p_l.size(); i++)
{
if (!inside(p_l[i]->eid))
{
add_erase(p_l[i]);
p_l[i]->spawn.add_erase(parent);
to_spawn.push_back(p_l[i]);
}
}
}
else
{
while (1)
{
if (!head) break;
head->p->spawn.add_erase(parent, false);
to_depsawn.push_back(head->p);
head = head->next;
}
}
}