diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2016-10-08 17:56:38 +0200 |
---|---|---|
committer | Ner'zhul <nerzhul@users.noreply.github.com> | 2016-10-08 22:27:44 +0200 |
commit | 7bbd716426bf989bf071e2322a9b797cc5f78acb (patch) | |
tree | 0c626a1cb5dd84a04c5963c020c0c9d29863e770 /src/environment.cpp | |
parent | edba6e50d9c9c0a7120c251bed36a87b51f4c826 (diff) | |
download | hax-minetest-server-7bbd716426bf989bf071e2322a9b797cc5f78acb.tar.gz hax-minetest-server-7bbd716426bf989bf071e2322a9b797cc5f78acb.zip |
RemotePlayer/LocalPlayer Player base class proper separation (code cleanup) (patch 3 of X)
* remove IGameDef from Player class, only LocalPlayer has it now
* move many attributes/functions only used by LocalPlayer from Player to LocalPlayer
* move many attributes/functions only used by RemotePlayer from Player to RemotePlayer
* make some functions const
* hudGetHotbarSelectedImage now returns const ref
* RemotePlayer getHotbarSelectedImage now returns const ref
* various code style fixes
Diffstat (limited to '')
-rw-r--r-- | src/environment.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/environment.cpp b/src/environment.cpp index bc246f66c..514aa918a 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -603,8 +603,9 @@ void ServerEnvironment::kickAllPlayers(AccessDeniedCode reason, { for (std::vector<Player*>::iterator it = m_players.begin(); it != m_players.end(); ++it) { - ((Server*)m_gamedef)->DenyAccessVerCompliant((*it)->peer_id, - (*it)->protocol_version, reason, str_reason, reconnect); + RemotePlayer *player = dynamic_cast<RemotePlayer *>(*it); + ((Server*)m_gamedef)->DenyAccessVerCompliant(player->peer_id, + player->protocol_version, reason, str_reason, reconnect); } } @@ -618,7 +619,7 @@ void ServerEnvironment::saveLoadedPlayers() ++it) { RemotePlayer *player = static_cast<RemotePlayer*>(*it); if (player->checkModified()) { - player->save(players_path); + player->save(players_path, m_gamedef); } } } @@ -628,7 +629,7 @@ void ServerEnvironment::savePlayer(RemotePlayer *player) std::string players_path = m_path_world + DIR_DELIM "players"; fs::CreateDir(players_path); - player->save(players_path); + player->save(players_path, m_gamedef); } RemotePlayer *ServerEnvironment::loadPlayer(const std::string &playername) @@ -640,7 +641,7 @@ RemotePlayer *ServerEnvironment::loadPlayer(const std::string &playername) RemotePlayer *player = getPlayer(playername.c_str()); if (!player) { - player = new RemotePlayer(m_gamedef, ""); + player = new RemotePlayer("", m_gamedef->idef()); newplayer = true; } @@ -2300,15 +2301,14 @@ LocalPlayer *ClientEnvironment::getPlayer(const char* name) return dynamic_cast<LocalPlayer *>(Environment::getPlayer(name)); } -void ClientEnvironment::addPlayer(Player *player) +void ClientEnvironment::addPlayer(LocalPlayer *player) { DSTACK(FUNCTION_NAME); /* - It is a failure if player is local and there already is a local - player + It is a failure if already is a local player */ - FATAL_ERROR_IF(player->isLocal() && getLocalPlayer() != NULL, - "Player is local but there is already a local player"); + FATAL_ERROR_IF(getLocalPlayer() != NULL, + "Player is local but there is already a local player"); Environment::addPlayer(player); } @@ -2563,7 +2563,7 @@ void ClientEnvironment::step(float dtime) */ for (std::vector<Player*>::iterator i = m_players.begin(); i != m_players.end(); ++i) { - LocalPlayer *player = dynamic_cast<LocalPlayer *>(*i); + Player *player = *i; assert(player); /* |