mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +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
|
@ -1108,7 +1108,7 @@ PlayerSAO* Server::StageTwoClientInit(u16 peer_id)
|
|||
SendPlayerBreath(peer_id);
|
||||
|
||||
// Show death screen if necessary
|
||||
if(player->isDead())
|
||||
if (player->isDead())
|
||||
SendDeathscreen(peer_id, false, v3f(0,0,0));
|
||||
|
||||
// Note things in chat if not in simple singleplayer mode
|
||||
|
@ -3080,14 +3080,6 @@ void Server::hudSetHotbarSelectedImage(RemotePlayer *player, std::string name)
|
|||
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_SELECTED_IMAGE, name);
|
||||
}
|
||||
|
||||
std::string Server::hudGetHotbarSelectedImage(RemotePlayer *player)
|
||||
{
|
||||
if (!player)
|
||||
return "";
|
||||
|
||||
return player->getHotbarSelectedImage();
|
||||
}
|
||||
|
||||
bool Server::setLocalPlayerAnimations(RemotePlayer *player,
|
||||
v2s32 animation_frames[4], f32 frame_speed)
|
||||
{
|
||||
|
@ -3408,11 +3400,10 @@ PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id, u16 proto_version
|
|||
/*
|
||||
Try to get an existing player
|
||||
*/
|
||||
RemotePlayer *player = static_cast<RemotePlayer*>(m_env->getPlayer(name));
|
||||
RemotePlayer *player = m_env->getPlayer(name);
|
||||
|
||||
// If player is already connected, cancel
|
||||
if(player != NULL && player->peer_id != 0)
|
||||
{
|
||||
if (player != NULL && player->peer_id != 0) {
|
||||
infostream<<"emergePlayer(): Player already connected"<<std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3420,8 +3411,7 @@ PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id, u16 proto_version
|
|||
/*
|
||||
If player with the wanted peer_id already exists, cancel.
|
||||
*/
|
||||
if(m_env->getPlayer(peer_id) != NULL)
|
||||
{
|
||||
if (m_env->getPlayer(peer_id) != NULL) {
|
||||
infostream<<"emergePlayer(): Player with wrong name but same"
|
||||
" peer_id already exists"<<std::endl;
|
||||
return NULL;
|
||||
|
@ -3429,13 +3419,13 @@ PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id, u16 proto_version
|
|||
|
||||
// Load player if it isn't already loaded
|
||||
if (!player) {
|
||||
player = static_cast<RemotePlayer*>(m_env->loadPlayer(name));
|
||||
player = m_env->loadPlayer(name);
|
||||
}
|
||||
|
||||
// Create player if it doesn't exist
|
||||
if (!player) {
|
||||
newplayer = true;
|
||||
player = new RemotePlayer(this, name);
|
||||
player = new RemotePlayer(name, this->idef());
|
||||
// Set player position
|
||||
infostream<<"Server: Finding spawn place for player \""
|
||||
<<name<<"\""<<std::endl;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue