Add local player
*/
{
- Player *player = new LocalPlayer(this);
-
- player->updateName(playername);
+ Player *player = new LocalPlayer(this, playername);
m_env.addPlayer(player);
}
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
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)),
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;
#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),
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]"
//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"));
}
}
- // Set m_last_*
- checkModified();
+ m_dirty = false;
}
u32 Player::addHud(HudElement *toadd)
*/
// 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;
if (!fs::safeWriteToFile(path, ss.str())) {
infostream << "Failed to write " << path << std::endl;
}
+ m_dirty = false;
return;
}
// Open file and deserialize
if (!fs::safeWriteToFile(path, ss.str())) {
infostream << "Failed to write " << path << std::endl;
}
+ m_dirty = false;
return;
}
path = savedir + m_name + itos(i);
{
public:
- Player(IGameDef *gamedef);
+ Player(IGameDef *gamedef, const char *name);
virtual ~Player() = 0;
virtual void move(f32 dtime, Environment *env, f32 pos_max_d)
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;
}
virtual void setBreath(u16 breath)
{
+ m_dirty = true;
m_breath = breath;
}
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;
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;
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;
};
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);
// 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;