Scripting WIP
authorPerttu Ahola <celeron55@gmail.com>
Sat, 12 Nov 2011 10:12:15 +0000 (12:12 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 29 Nov 2011 17:13:39 +0000 (19:13 +0200)
src/content_sao.cpp
src/content_sao.h
src/scriptapi.cpp

index 6cc0106b6d13580184d775c59f8c55943502e5e2..ec6f39697de721fbead009068a005131f8cc5ff9 100644 (file)
@@ -1509,7 +1509,8 @@ LuaEntitySAO::LuaEntitySAO(ServerEnvironment *env, v3f pos,
        m_prop(new LuaEntityProperties),
        m_yaw(0),
        m_last_sent_yaw(0),
-       m_last_sent_position(0,0,0)
+       m_last_sent_position(0,0,0),
+       m_last_sent_position_timer(0)
 {
        // Only register type if no environment supplied
        if(env == NULL){
@@ -1561,6 +1562,8 @@ ServerActiveObject* LuaEntitySAO::create(ServerEnvironment *env, v3f pos,
 
 void LuaEntitySAO::step(float dtime, bool send_recommended)
 {
+       m_last_sent_position_timer += dtime;
+       
        if(m_registered){
                lua_State *L = m_env->getLua();
                scriptapi_luaentity_step(L, m_id, dtime);
@@ -1568,7 +1571,13 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
 
        if(send_recommended == false)
                return;
-       if(m_base_position.getDistanceFrom(m_last_sent_position) > 0.05*BS
+       
+       float minchange = 0.2*BS;
+       if(m_last_sent_position_timer > 1.0)
+               minchange = 0.01*BS;
+       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);
        }
@@ -1646,6 +1655,7 @@ void LuaEntitySAO::sendPosition(bool do_interpolate)
 {
        m_last_sent_yaw = m_yaw;
        m_last_sent_position = m_base_position;
+       m_last_sent_position_timer = 0;
 
        std::ostringstream os(std::ios::binary);
        // command (0 = update position)
index 4bb35b70deeb2966ac4d1a9d10f4d43a991889c7..718ea027101ff136eaced35963da3fd7c1ca9fed 100644 (file)
@@ -229,6 +229,7 @@ private:
        float m_yaw;
        float m_last_sent_yaw;
        v3f m_last_sent_position;
+       float m_last_sent_position_timer;
 };
 
 #endif
index b0a99041e6ed43556e08c01aaf159f575be97c91..dc9c832d2f07ffd8488ed527cfe8ed189bd31fe3 100644 (file)
@@ -383,7 +383,6 @@ private:
                ObjectRef *ref = checkobject(L, 1);
                ServerActiveObject *co = getobject(ref);
                if(co == NULL) return 0;
-               infostream<<"ObjectRef::l_getpos(): id="<<co->getId()<<std::endl;
                v3f pos = co->getBasePosition() / BS;
                lua_newtable(L);
                lua_pushnumber(L, pos.X);