diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2016-10-08 12:21:41 +0200 |
---|---|---|
committer | Ner'zhul <nerzhul@users.noreply.github.com> | 2016-10-08 15:57:50 +0200 |
commit | 656faf7373587bc59b47986a28dbd2fce4c45474 (patch) | |
tree | 0d2414db105bfeaa1112576725da61bfdfc1edec /src/environment.cpp | |
parent | 9393e4a0a8e32905d32a9dc58131218aee318686 (diff) | |
download | minetest-656faf7373587bc59b47986a28dbd2fce4c45474.tar.gz minetest-656faf7373587bc59b47986a28dbd2fce4c45474.tar.bz2 minetest-656faf7373587bc59b47986a28dbd2fce4c45474.zip |
Player/LocalPlayer/RemotePlayer inheritance cleanup (part 2 on X)
* Server/Client Environments now have an helper to cast Player object in the right type to use it
* Server: use RemotePlayer everywhere and remove previous added casts
* Client: use LocalPlayer where needed
* Environment: remove unused functions (getPlayers(), getRandomConnectedPlayer(), getNearestConnectedPlayer())
Diffstat (limited to 'src/environment.cpp')
-rw-r--r-- | src/environment.cpp | 84 |
1 files changed, 20 insertions, 64 deletions
diff --git a/src/environment.cpp b/src/environment.cpp index 34b3c34f4..d30b70527 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -127,65 +127,6 @@ Player * Environment::getPlayer(const char *name) return NULL; } -Player * Environment::getRandomConnectedPlayer() -{ - std::vector<Player*> connected_players = getPlayers(true); - u32 chosen_one = myrand() % connected_players.size(); - u32 j = 0; - for(std::vector<Player*>::iterator - i = connected_players.begin(); - i != connected_players.end(); ++i) { - if(j == chosen_one) { - Player *player = *i; - return player; - } - j++; - } - return NULL; -} - -Player * Environment::getNearestConnectedPlayer(v3f pos) -{ - std::vector<Player*> connected_players = getPlayers(true); - f32 nearest_d = 0; - Player *nearest_player = NULL; - for(std::vector<Player*>::iterator - i = connected_players.begin(); - i != connected_players.end(); ++i) { - Player *player = *i; - f32 d = player->getPosition().getDistanceFrom(pos); - if(d < nearest_d || nearest_player == NULL) { - nearest_d = d; - nearest_player = player; - } - } - return nearest_player; -} - -std::vector<Player*> Environment::getPlayers() -{ - return m_players; -} - -std::vector<Player*> Environment::getPlayers(bool ignore_disconnected) -{ - std::vector<Player*> newlist; - for(std::vector<Player*>::iterator - i = m_players.begin(); - i != m_players.end(); ++i) { - Player *player = *i; - - if(ignore_disconnected) { - // Ignore disconnected players - if(player->peer_id == 0) - continue; - } - - newlist.push_back(player); - } - return newlist; -} - u32 Environment::getDayNightRatio() { MutexAutoLock lock(this->m_time_lock); @@ -199,11 +140,6 @@ void Environment::setTimeOfDaySpeed(float speed) m_time_of_day_speed = speed; } -float Environment::getTimeOfDaySpeed() -{ - return m_time_of_day_speed; -} - void Environment::setDayNightRatioOverride(bool enable, u32 value) { MutexAutoLock lock(this->m_time_lock); @@ -625,6 +561,16 @@ ServerMap & ServerEnvironment::getServerMap() return *m_map; } +RemotePlayer *ServerEnvironment::getPlayer(const u16 peer_id) +{ + return dynamic_cast<RemotePlayer *>(Environment::getPlayer(peer_id)); +} + +RemotePlayer *ServerEnvironment::getPlayer(const char* name) +{ + return dynamic_cast<RemotePlayer *>(Environment::getPlayer(name)); +} + bool ServerEnvironment::line_of_sight(v3f pos1, v3f pos2, float stepsize, v3s16 *p) { float distance = pos1.getDistanceFrom(pos2); @@ -2349,6 +2295,16 @@ ClientMap & ClientEnvironment::getClientMap() return *m_map; } +LocalPlayer *ClientEnvironment::getPlayer(const u16 peer_id) +{ + return dynamic_cast<LocalPlayer *>(Environment::getPlayer(peer_id)); +} + +LocalPlayer *ClientEnvironment::getPlayer(const char* name) +{ + return dynamic_cast<LocalPlayer *>(Environment::getPlayer(name)); +} + void ClientEnvironment::addPlayer(Player *player) { DSTACK(FUNCTION_NAME); |