mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
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
This commit is contained in:
parent
edba6e50d9
commit
7bbd716426
9 changed files with 255 additions and 292 deletions
|
@ -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);
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue