diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 4 | ||||
-rw-r--r-- | src/environment.cpp | 4 | ||||
-rw-r--r-- | src/localplayer.cpp | 4 | ||||
-rw-r--r-- | src/localplayer.h | 4 | ||||
-rw-r--r-- | src/player.cpp | 23 | ||||
-rw-r--r-- | src/player.h | 36 | ||||
-rw-r--r-- | src/server.cpp | 3 |
7 files changed, 30 insertions, 48 deletions
diff --git a/src/client.cpp b/src/client.cpp index 5a276e306..4a00283ee 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -270,9 +270,7 @@ Client::Client( Add local player */ { - Player *player = new LocalPlayer(this); - - player->updateName(playername); + Player *player = new LocalPlayer(this, playername); m_env.addPlayer(player); } diff --git a/src/environment.cpp b/src/environment.cpp index 66898f012..4106ecdf5 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -449,11 +449,11 @@ Player *ServerEnvironment::loadPlayer(const std::string &playername) bool newplayer = false; bool found = false; if (!player) { - player = new RemotePlayer(m_gamedef); + player = new RemotePlayer(m_gamedef, playername.c_str()); newplayer = true; } - RemotePlayer testplayer(m_gamedef); + RemotePlayer testplayer(m_gamedef, ""); std::string path = players_path + playername; for (u32 i = 0; i < PLAYER_FILE_ALTERNATE_TRIES; i++) { // Open file and deserialize diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 1a238cb47..84b7c1146 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -33,8 +33,8 @@ with this program; if not, write to the Free Software Foundation, Inc., LocalPlayer */ -LocalPlayer::LocalPlayer(IGameDef *gamedef): - Player(gamedef), +LocalPlayer::LocalPlayer(IGameDef *gamedef, const char *name): + Player(gamedef, name), parent(0), isAttached(false), overridePosition(v3f(0,0,0)), diff --git a/src/localplayer.h b/src/localplayer.h index bfe476b70..16830f3ec 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -32,14 +32,14 @@ enum LocalPlayerAnimations {NO_ANIM, WALK_ANIM, DIG_ANIM, WD_ANIM}; // no local class LocalPlayer : public Player { public: - LocalPlayer(IGameDef *gamedef); + LocalPlayer(IGameDef *gamedef, const char *name); virtual ~LocalPlayer(); bool isLocal() const { return true; } - + ClientActiveObject *parent; bool isAttached; diff --git a/src/player.cpp b/src/player.cpp index 8e5f56199..a8f95bb99 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -28,8 +28,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_sao.h" #include "filesys.h" #include "log.h" +#include "porting.h" // strlcpy -Player::Player(IGameDef *gamedef): + +Player::Player(IGameDef *gamedef, const char *name): touching_ground(false), in_liquid(false), in_liquid_stable(false), @@ -52,20 +54,16 @@ Player::Player(IGameDef *gamedef): m_speed(0,0,0), m_position(0,0,0), m_collisionbox(-BS*0.30,0.0,-BS*0.30,BS*0.30,BS*1.75,BS*0.30), - m_last_pitch(0), - m_last_yaw(0), - m_last_pos(0,0,0), - m_last_hp(PLAYER_MAX_HP), - m_last_inventory(gamedef->idef()) + m_dirty(false) { - updateName("<not set>"); + strlcpy(m_name, name, PLAYERNAME_SIZE); + inventory.clear(); inventory.addList("main", PLAYER_INVENTORY_SIZE); InventoryList *craft = inventory.addList("craft", 9); craft->setWidth(3); inventory.addList("craftpreview", 1); inventory.addList("craftresult", 1); - m_last_inventory = inventory; // Can be redefined via Lua inventory_formspec = "size[8,7.5]" @@ -207,7 +205,7 @@ void Player::deSerialize(std::istream &is, std::string playername) //args.getS32("version"); // Version field value not used std::string name = args.get("name"); - updateName(name.c_str()); + strlcpy(m_name, name.c_str(), PLAYERNAME_SIZE); setPitch(args.getFloat("pitch")); setYaw(args.getFloat("yaw")); setPosition(args.getV3F("position")); @@ -238,8 +236,7 @@ void Player::deSerialize(std::istream &is, std::string playername) } } - // Set m_last_* - checkModified(); + m_dirty = false; } u32 Player::addHud(HudElement *toadd) @@ -290,7 +287,7 @@ void RemotePlayer::save(std::string savedir) */ // A player to deserialize files into to check their names - RemotePlayer testplayer(m_gamedef); + RemotePlayer testplayer(m_gamedef, ""); savedir += DIR_DELIM; std::string path = savedir + m_name; @@ -302,6 +299,7 @@ void RemotePlayer::save(std::string savedir) if (!fs::safeWriteToFile(path, ss.str())) { infostream << "Failed to write " << path << std::endl; } + m_dirty = false; return; } // Open file and deserialize @@ -319,6 +317,7 @@ void RemotePlayer::save(std::string savedir) if (!fs::safeWriteToFile(path, ss.str())) { infostream << "Failed to write " << path << std::endl; } + m_dirty = false; return; } path = savedir + m_name + itos(i); diff --git a/src/player.h b/src/player.h index 93197d374..174f14728 100644 --- a/src/player.h +++ b/src/player.h @@ -95,7 +95,7 @@ class Player { public: - Player(IGameDef *gamedef); + Player(IGameDef *gamedef, const char *name); virtual ~Player() = 0; virtual void move(f32 dtime, Environment *env, f32 pos_max_d) @@ -142,16 +142,19 @@ public: virtual void setPosition(const v3f &position) { + m_dirty = true; m_position = position; } void setPitch(f32 pitch) { + m_dirty = true; m_pitch = pitch; } virtual void setYaw(f32 yaw) { + m_dirty = true; m_yaw = yaw; } @@ -172,6 +175,7 @@ public: virtual void setBreath(u16 breath) { + m_dirty = true; m_breath = breath; } @@ -185,11 +189,6 @@ public: return (m_yaw + 90.) * core::DEGTORAD; } - void updateName(const char *name) - { - snprintf(m_name, PLAYERNAME_SIZE, "%s", name); - } - const char * getName() const { return m_name; @@ -225,19 +224,7 @@ public: bool checkModified() { - if(m_last_hp != hp || m_last_pitch != m_pitch || - m_last_pos != m_position || m_last_yaw != m_yaw || - !(inventory == m_last_inventory)) - { - m_last_hp = hp; - m_last_pitch = m_pitch; - m_last_pos = m_position; - m_last_yaw = m_yaw; - m_last_inventory = inventory; - return true; - } else { - return false; - } + return m_dirty; } bool touching_ground; @@ -316,11 +303,7 @@ protected: v3f m_position; core::aabbox3d<f32> m_collisionbox; - f32 m_last_pitch; - f32 m_last_yaw; - v3f m_last_pos; - u16 m_last_hp; - Inventory m_last_inventory; + bool m_dirty; std::vector<HudElement *> hud; }; @@ -332,7 +315,10 @@ protected: class RemotePlayer : public Player { public: - RemotePlayer(IGameDef *gamedef): Player(gamedef), m_sao(0) {} + RemotePlayer(IGameDef *gamedef, const char *name): + Player(gamedef, name), + m_sao(NULL) + {} virtual ~RemotePlayer() {} void save(std::string savedir); diff --git a/src/server.cpp b/src/server.cpp index 262970c09..4f4763ea4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -5038,8 +5038,7 @@ PlayerSAO* Server::emergePlayer(const char *name, u16 peer_id) // Create player if it doesn't exist if (!player) { newplayer = true; - player = new RemotePlayer(this); - player->updateName(name); + player = new RemotePlayer(this, name); /* Set player position */ infostream<<"Server: Finding spawn place for player \"" <<name<<"\""<<std::endl; |