aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/content_sao.cpp28
-rw-r--r--src/content_sao.h13
-rw-r--r--src/network/serverpackethandler.cpp4
-rw-r--r--src/remoteplayer.cpp8
-rw-r--r--src/script/lua_api/l_object.cpp8
-rw-r--r--src/unittest/test_player.cpp12
6 files changed, 39 insertions, 34 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 23a064085..5fb8f936e 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -507,7 +507,7 @@ void LuaEntitySAO::rightClick(ServerActiveObject *clicker)
m_env->getScriptIface()->luaentity_Rightclick(m_id, clicker);
}
-void LuaEntitySAO::setPos(v3f pos)
+void LuaEntitySAO::setPos(const v3f &pos)
{
if(isAttached())
return;
@@ -1078,27 +1078,32 @@ void PlayerSAO::moveTo(v3f pos, bool continuous)
((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
}
-void PlayerSAO::setYaw(const float yaw, bool send_data)
+void PlayerSAO::setYaw(const float yaw)
{
if (m_player && yaw != m_yaw)
m_player->setDirty(true);
UnitSAO::setYaw(yaw);
+}
- // Datas should not be sent at player initialization
- if (send_data)
- ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
+void PlayerSAO::setYawAndSend(const float yaw)
+{
+ setYaw(yaw);
+ ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
}
-void PlayerSAO::setPitch(const float pitch, bool send_data)
+void PlayerSAO::setPitch(const float pitch)
{
if (m_player && pitch != m_pitch)
m_player->setDirty(true);
m_pitch = pitch;
+}
- if (send_data)
- ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
+void PlayerSAO::setPitchAndSend(const float pitch)
+{
+ setPitch(pitch);
+ ((Server*)m_env->getGameDef())->SendMovePlayer(m_peer_id);
}
int PlayerSAO::punch(v3f dir,
@@ -1173,13 +1178,8 @@ s16 PlayerSAO::readDamage()
return damage;
}
-void PlayerSAO::setHP(s16 hp, bool direct)
+void PlayerSAO::setHP(s16 hp)
{
- if (direct) {
- m_hp = hp;
- return;
- }
-
s16 oldhp = m_hp;
s16 hp_change = m_env->getScriptIface()->on_player_hpchange(this, hp - oldhp);
diff --git a/src/content_sao.h b/src/content_sao.h
index 4ea6277ff..5d837a466 100644
--- a/src/content_sao.h
+++ b/src/content_sao.h
@@ -73,7 +73,7 @@ public:
ServerActiveObject *puncher=NULL,
float time_from_last_punch=1000000);
void rightClick(ServerActiveObject *clicker);
- void setPos(v3f pos);
+ void setPos(const v3f &pos);
void moveTo(v3f pos, bool continuous);
float getMinimumSavedMovement();
std::string getDescription();
@@ -204,8 +204,12 @@ public:
void setBasePosition(const v3f &position);
void setPos(const v3f &pos);
void moveTo(v3f pos, bool continuous);
- void setYaw(const float yaw, bool send_data = true);
- void setPitch(const float pitch, bool send_data = true);
+ void setYaw(const float yaw);
+ // Data should not be sent at player initialization
+ void setYawAndSend(const float yaw);
+ void setPitch(const float pitch);
+ // Data should not be sent at player initialization
+ void setPitchAndSend(const float pitch);
f32 getPitch() const { return m_pitch; }
f32 getRadPitch() const { return m_pitch * core::DEGTORAD; }
// Deprecated
@@ -220,7 +224,8 @@ public:
ServerActiveObject *puncher,
float time_from_last_punch);
void rightClick(ServerActiveObject *clicker);
- void setHP(s16 hp, bool direct = false);
+ void setHP(s16 hp);
+ void setHPRaw(s16 hp) { m_hp = hp; }
s16 readDamage();
u16 getBreath() const { return m_breath; }
void setBreath(const u16 breath);
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 5e70b4c6c..80eec140d 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -827,8 +827,8 @@ void Server::handleCommand_PlayerPos(NetworkPacket* pkt)
playersao->setBasePosition(position);
player->setSpeed(speed);
- playersao->setPitch(pitch, false);
- playersao->setYaw(yaw, false);
+ playersao->setPitch(pitch);
+ playersao->setYaw(yaw);
player->keyPressed = keyPressed;
player->control.up = (keyPressed & 1);
player->control.down = (keyPressed & 2);
diff --git a/src/remoteplayer.cpp b/src/remoteplayer.cpp
index 605346928..f4a79dd08 100644
--- a/src/remoteplayer.cpp
+++ b/src/remoteplayer.cpp
@@ -131,9 +131,9 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
if (sao) {
try {
- sao->setHP(args.getS32("hp"), true);
+ sao->setHPRaw(args.getS32("hp"));
} catch(SettingNotFoundException &e) {
- sao->setHP(PLAYER_MAX_HP, true);
+ sao->setHPRaw(PLAYER_MAX_HP);
}
try {
@@ -141,10 +141,10 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername,
} catch (SettingNotFoundException &e) {}
try {
- sao->setPitch(args.getFloat("pitch"), false);
+ sao->setPitch(args.getFloat("pitch"));
} catch (SettingNotFoundException &e) {}
try {
- sao->setYaw(args.getFloat("yaw"), false);
+ sao->setYaw(args.getFloat("yaw"));
} catch (SettingNotFoundException &e) {}
try {
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index cf124f17c..42395717f 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -1090,7 +1090,7 @@ int ObjectRef::l_set_look_vertical(lua_State *L)
if (co == NULL) return 0;
float pitch = luaL_checknumber(L, 2) * core::RADTODEG;
// Do it
- co->setPitch(pitch);
+ co->setPitchAndSend(pitch);
return 1;
}
@@ -1103,7 +1103,7 @@ int ObjectRef::l_set_look_horizontal(lua_State *L)
if (co == NULL) return 0;
float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
// Do it
- co->setYaw(yaw);
+ co->setYawAndSend(yaw);
return 1;
}
@@ -1121,7 +1121,7 @@ int ObjectRef::l_set_look_pitch(lua_State *L)
if (co == NULL) return 0;
float pitch = luaL_checknumber(L, 2) * core::RADTODEG;
// Do it
- co->setPitch(pitch);
+ co->setPitchAndSend(pitch);
return 1;
}
@@ -1139,7 +1139,7 @@ int ObjectRef::l_set_look_yaw(lua_State *L)
if (co == NULL) return 0;
float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
// Do it
- co->setYaw(yaw);
+ co->setYawAndSend(yaw);
return 1;
}
diff --git a/src/unittest/test_player.cpp b/src/unittest/test_player.cpp
index fba422475..85fbc8b2d 100644
--- a/src/unittest/test_player.cpp
+++ b/src/unittest/test_player.cpp
@@ -50,9 +50,9 @@ void TestPlayer::testSave(IGameDef *gamedef)
sao.initialize(&rplayer, std::set<std::string>());
rplayer.setPlayerSAO(&sao);
sao.setBreath(10);
- sao.setHP(8, true);
- sao.setYaw(0.1f, false);
- sao.setPitch(0.6f, false);
+ sao.setHPRaw(8);
+ sao.setYaw(0.1f);
+ sao.setPitch(0.6f);
sao.setBasePosition(v3f(450.2f, -15.7f, 68.1f));
rplayer.save(".", gamedef);
UASSERT(fs::PathExists("testplayer_save"));
@@ -65,9 +65,9 @@ void TestPlayer::testLoad(IGameDef *gamedef)
sao.initialize(&rplayer, std::set<std::string>());
rplayer.setPlayerSAO(&sao);
sao.setBreath(10);
- sao.setHP(8, true);
- sao.setYaw(0.1f, false);
- sao.setPitch(0.6f, false);
+ sao.setHPRaw(8);
+ sao.setYaw(0.1f);
+ sao.setPitch(0.6f);
sao.setBasePosition(v3f(450.2f, -15.7f, 68.1f));
rplayer.save(".", gamedef);
UASSERT(fs::PathExists("testplayer_load"));