summaryrefslogtreecommitdiff
path: root/src/content_sao.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-11-12 13:59:56 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-11-29 19:13:39 +0200
commit38944467d31bbfa8a98008962f147cbc3c73f507 (patch)
treedc634dbc194a0742480d64c42231485f6b9e04e0 /src/content_sao.cpp
parent23adfff4fea9c1ad49e7bc4cd08341c2e1fded78 (diff)
downloadminetest-38944467d31bbfa8a98008962f147cbc3c73f507.tar.gz
minetest-38944467d31bbfa8a98008962f147cbc3c73f507.tar.bz2
minetest-38944467d31bbfa8a98008962f147cbc3c73f507.zip
Scripting WIP
Diffstat (limited to 'src/content_sao.cpp')
-rw-r--r--src/content_sao.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 6d9d5a948..b053274f1 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -1510,7 +1510,8 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
m_yaw(0),
m_last_sent_yaw(0),
m_last_sent_position(0,0,0),
- m_last_sent_position_timer(0)
+ m_last_sent_position_timer(0),
+ m_last_sent_move_precision(0)
{
// Only register type if no environment supplied
if(env == NULL){
@@ -1572,17 +1573,16 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
if(send_recommended == false)
return;
- bool move_end = false;
float minchange = 0.2*BS;
if(m_last_sent_position_timer > 1.0){
minchange = 0.01*BS;
- move_end = true;
} else if(m_last_sent_position_timer > 0.2){
minchange = 0.05*BS;
}
- if(m_base_position.getDistanceFrom(m_last_sent_position) > minchange
- || fabs(m_yaw - m_last_sent_yaw) > 1.0){
- sendPosition(true, move_end);
+ float move_d = m_base_position.getDistanceFrom(m_last_sent_position);
+ move_d += m_last_sent_move_precision;
+ if(move_d > minchange || fabs(m_yaw - m_last_sent_yaw) > 1.0){
+ sendPosition(true, false);
}
}
@@ -1649,17 +1649,22 @@ void LuaEntitySAO::setPos(v3f pos)
sendPosition(false, true);
}
-void LuaEntitySAO::moveTo(v3f pos)
+void LuaEntitySAO::moveTo(v3f pos, bool continuous)
{
m_base_position = pos;
- sendPosition(true, true);
+ if(!continuous)
+ sendPosition(true, true);
}
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
{
+ m_last_sent_move_precision = m_base_position.getDistanceFrom(
+ m_last_sent_position);
+ m_last_sent_position_timer = 0;
m_last_sent_yaw = m_yaw;
m_last_sent_position = m_base_position;
- m_last_sent_position_timer = 0;
+
+ float update_interval = m_env->getSendRecommendedInterval();
std::ostringstream os(std::ios::binary);
// command (0 = update position)
@@ -1673,6 +1678,8 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
writeF1000(os, m_yaw);
// is_end_position (for interpolation)
writeU8(os, is_movement_end);
+ // update_interval (for interpolation)
+ writeF1000(os, update_interval);
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());