Environment::~Environment()
{
// Deallocate players
- for(std::list<Player*>::iterator i = m_players.begin();
- i != m_players.end(); ++i)
- {
+ for(std::vector<Player*>::iterator i = m_players.begin();
+ i != m_players.end(); ++i) {
delete (*i);
}
}
{
DSTACK(__FUNCTION_NAME);
- for(std::list<Player*>::iterator i = m_players.begin();
+ for(std::vector<Player*>::iterator i = m_players.begin();
i != m_players.end();)
{
Player *player = *i;
void Environment::removePlayer(const char *name)
{
- for (std::list<Player*>::iterator it = m_players.begin();
+ for (std::vector<Player*>::iterator it = m_players.begin();
it != m_players.end(); ++it) {
if (strcmp((*it)->getName(), name) == 0) {
delete *it;
Player * Environment::getPlayer(u16 peer_id)
{
- for(std::list<Player*>::iterator i = m_players.begin();
- i != m_players.end(); ++i)
- {
+ for(std::vector<Player*>::iterator i = m_players.begin();
+ i != m_players.end(); ++i) {
Player *player = *i;
if(player->peer_id == peer_id)
return player;
Player * Environment::getPlayer(const char *name)
{
- for(std::list<Player*>::iterator i = m_players.begin();
- i != m_players.end(); ++i)
- {
+ for(std::vector<Player*>::iterator i = m_players.begin();
+ i != m_players.end(); ++i) {
Player *player = *i;
if(strcmp(player->getName(), name) == 0)
return player;
Player * Environment::getRandomConnectedPlayer()
{
- std::list<Player*> connected_players = getPlayers(true);
+ std::vector<Player*> connected_players = getPlayers(true);
u32 chosen_one = myrand() % connected_players.size();
u32 j = 0;
- for(std::list<Player*>::iterator
+ for(std::vector<Player*>::iterator
i = connected_players.begin();
- i != connected_players.end(); ++i)
- {
- if(j == chosen_one)
- {
+ i != connected_players.end(); ++i) {
+ if(j == chosen_one) {
Player *player = *i;
return player;
}
Player * Environment::getNearestConnectedPlayer(v3f pos)
{
- std::list<Player*> connected_players = getPlayers(true);
+ std::vector<Player*> connected_players = getPlayers(true);
f32 nearest_d = 0;
Player *nearest_player = NULL;
- for(std::list<Player*>::iterator
+ for(std::vector<Player*>::iterator
i = connected_players.begin();
- i != connected_players.end(); ++i)
- {
+ i != connected_players.end(); ++i) {
Player *player = *i;
f32 d = player->getPosition().getDistanceFrom(pos);
- if(d < nearest_d || nearest_player == NULL)
- {
+ if(d < nearest_d || nearest_player == NULL) {
nearest_d = d;
nearest_player = player;
}
return nearest_player;
}
-std::list<Player*> Environment::getPlayers()
+std::vector<Player*> Environment::getPlayers()
{
return m_players;
}
-std::list<Player*> Environment::getPlayers(bool ignore_disconnected)
+std::vector<Player*> Environment::getPlayers(bool ignore_disconnected)
{
- std::list<Player*> newlist;
- for(std::list<Player*>::iterator
+ std::vector<Player*> newlist;
+ for(std::vector<Player*>::iterator
i = m_players.begin();
- i != m_players.end(); ++i)
- {
+ i != m_players.end(); ++i) {
Player *player = *i;
- if(ignore_disconnected)
- {
+ if(ignore_disconnected) {
// Ignore disconnected players
if(player->peer_id == 0)
continue;
}
}
-void ActiveBlockList::update(std::list<v3s16> &active_positions,
+void ActiveBlockList::update(std::vector<v3s16> &active_positions,
s16 radius,
std::set<v3s16> &blocks_removed,
std::set<v3s16> &blocks_added)
Create the new list
*/
std::set<v3s16> newlist = m_forceloaded_list;
- for(std::list<v3s16>::iterator i = active_positions.begin();
+ for(std::vector<v3s16>::iterator i = active_positions.begin();
i != active_positions.end(); ++i)
{
fillRadiusBlock(*i, radius, newlist);
//calculate normalized direction vector
v3f normalized_vector = v3f((pos2.X - pos1.X)/distance,
- (pos2.Y - pos1.Y)/distance,
- (pos2.Z - pos1.Z)/distance);
+ (pos2.Y - pos1.Y)/distance,
+ (pos2.Z - pos1.Z)/distance);
//find out if there's a node on path between pos1 and pos2
for (float i = 1; i < distance; i += stepsize) {
std::string players_path = m_path_world + DIR_DELIM "players";
fs::CreateDir(players_path);
- for (std::list<Player*>::iterator it = m_players.begin();
+ for (std::vector<Player*>::iterator it = m_players.begin();
it != m_players.end();
++it) {
RemotePlayer *player = static_cast<RemotePlayer*>(*it);
{
private:
ServerEnvironment *m_env;
- std::map<content_t, std::list<ActiveABM> > m_aabms;
+ std::map<content_t, std::vector<ActiveABM> > m_aabms;
public:
ABMHandler(std::list<ABMWithState> &abms,
float dtime_s, ServerEnvironment *env,
k != ids.end(); k++)
{
content_t c = *k;
- std::map<content_t, std::list<ActiveABM> >::iterator j;
+ std::map<content_t, std::vector<ActiveABM> >::iterator j;
j = m_aabms.find(c);
if(j == m_aabms.end()){
- std::list<ActiveABM> aabmlist;
+ std::vector<ActiveABM> aabmlist;
m_aabms[c] = aabmlist;
j = m_aabms.find(c);
}
content_t c = n.getContent();
v3s16 p = p0 + block->getPosRelative();
- std::map<content_t, std::list<ActiveABM> >::iterator j;
+ std::map<content_t, std::vector<ActiveABM> >::iterator j;
j = m_aabms.find(c);
if(j == m_aabms.end())
continue;
- for(std::list<ActiveABM>::iterator
- i = j->second.begin(); i != j->second.end(); i++)
- {
+ for(std::vector<ActiveABM>::iterator
+ i = j->second.begin(); i != j->second.end(); i++) {
if(myrand() % i->chance != 0)
continue;
*/
{
ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_AVG);
- for(std::list<Player*>::iterator i = m_players.begin();
+ for(std::vector<Player*>::iterator i = m_players.begin();
i != m_players.end(); ++i)
{
Player *player = *i;
/*
Get player block positions
*/
- std::list<v3s16> players_blockpos;
- for(std::list<Player*>::iterator
+ std::vector<v3s16> players_blockpos;
+ for(std::vector<Player*>::iterator
i = m_players.begin();
- i != m_players.end(); ++i)
- {
+ i != m_players.end(); ++i) {
Player *player = *i;
// Ignore disconnected players
if(player->peer_id == 0)
continue;
+
v3s16 blockpos = getNodeBlockPos(
floatToInt(player->getPosition(), BS));
players_blockpos.push_back(blockpos);
}
// Activate stored objects
- std::list<StaticObject> new_stored;
+ std::vector<StaticObject> new_stored;
for(std::list<StaticObject>::iterator
i = block->m_static_objects.m_stored.begin();
i != block->m_static_objects.m_stored.end(); ++i) {
// Clear stored list
block->m_static_objects.m_stored.clear();
// Add leftover failed stuff to stored list
- for(std::list<StaticObject>::iterator
+ for(std::vector<StaticObject>::iterator
i = new_stored.begin();
- i != new_stored.end(); ++i)
- {
+ i != new_stored.end(); ++i) {
StaticObject &s_obj = *i;
block->m_static_objects.m_stored.push_back(s_obj);
}
*/
void ServerEnvironment::deactivateFarObjects(bool force_delete)
{
- std::list<u16> objects_to_remove;
+ std::vector<u16> objects_to_remove;
for(std::map<u16, ServerActiveObject*>::iterator
i = m_active_objects.begin();
- i != m_active_objects.end(); ++i)
- {
+ i != m_active_objects.end(); ++i) {
ServerActiveObject* obj = i->second;
assert(obj);
}
// Remove references from m_active_objects
- for(std::list<u16>::iterator i = objects_to_remove.begin();
- i != objects_to_remove.end(); ++i)
- {
+ for(std::vector<u16>::iterator i = objects_to_remove.begin();
+ i != objects_to_remove.end(); ++i) {
m_active_objects.erase(*i);
}
}
LocalPlayer * ClientEnvironment::getLocalPlayer()
{
- for(std::list<Player*>::iterator i = m_players.begin();
- i != m_players.end(); ++i)
- {
+ for(std::vector<Player*>::iterator i = m_players.begin();
+ i != m_players.end(); ++i) {
Player *player = *i;
if(player->isLocal())
return (LocalPlayer*)player;
/*
Stuff that can be done in an arbitarily large dtime
*/
- for(std::list<Player*>::iterator i = m_players.begin();
- i != m_players.end(); ++i)
- {
+ for(std::vector<Player*>::iterator i = m_players.begin();
+ i != m_players.end(); ++i) {
Player *player = *i;
/*
Handle non-local players
*/
- if(player->isLocal() == false)
- {
+ if(player->isLocal() == false) {
// Move
player->move(dtime, this, 100*BS);