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

index 28c2787e1ac84aa2e6f109d37a6900d4fac8cfed..0db9803cce71659f5c7556f910bca8ee6ec29dd3 100644 (file)
@@ -1366,9 +1366,11 @@ void LuaEntityCAO::processMessage(const std::string &data)
                m_position = readV3F1000(is);
                // yaw
                m_yaw = readF1000(is);
+               // is_end_position (for interpolation)
+               bool is_end_position = readU8(is);
                
                if(do_interpolate)
-                       pos_translator.update(m_position);
+                       pos_translator.update(m_position, is_end_position);
                else
                        pos_translator.init(m_position);
                updateNodePos();
index 3231a190f0a665cf5cfd1b60e1a0181111d7e1f0..72cb94eb71d35960691268691e95bcf696718cb7 100644 (file)
@@ -35,6 +35,7 @@ struct SmoothTranslator
        v3f vect_old;
        v3f vect_show;
        v3f vect_aim;
+       bool aim_is_end;
        f32 anim_counter;
        f32 anim_time;
        f32 anim_time_counter;
@@ -53,6 +54,7 @@ struct SmoothTranslator
                vect_old = vect;
                vect_show = vect;
                vect_aim = vect;
+               aim_is_end = true;
                anim_counter = 0;
                anim_time = 0;
                anim_time_counter = 0;
@@ -63,8 +65,9 @@ struct SmoothTranslator
                init(vect_show);
        }
 
-       void update(v3f vect_new)
+       void update(v3f vect_new, bool is_end_position=false)
        {
+               aim_is_end = is_end_position;
                vect_old = vect_show;
                vect_aim = vect_new;
                if(anim_time < 0.001 || anim_time > 1.0)
@@ -85,8 +88,11 @@ struct SmoothTranslator
                        moveratio = anim_time_counter / anim_time;
                // Move a bit less than should, to avoid oscillation
                moveratio = moveratio * 0.5;
-               if(moveratio > 1.5)
-                       moveratio = 1.5;
+               float move_end = 1.5;
+               if(aim_is_end)
+                       move_end = 1.0;
+               if(moveratio > move_end)
+                       moveratio = move_end;
                vect_show = vect_old + vect_move * moveratio;
        }
 
index ec6f39697de721fbead009068a005131f8cc5ff9..6d9d5a9482f6b7802fa13b3d3f87638b7840e88c 100644 (file)
@@ -1572,14 +1572,17 @@ 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)
+       if(m_last_sent_position_timer > 1.0){
                minchange = 0.01*BS;
-       else if(m_last_sent_position_timer > 0.2)
+               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);
+               sendPosition(true, move_end);
        }
 }
 
@@ -1643,15 +1646,16 @@ void LuaEntitySAO::rightClick(Player *player)
 void LuaEntitySAO::setPos(v3f pos)
 {
        m_base_position = pos;
-       sendPosition(false);
+       sendPosition(false, true);
 }
 
 void LuaEntitySAO::moveTo(v3f pos)
 {
        m_base_position = pos;
+       sendPosition(true, true);
 }
 
-void LuaEntitySAO::sendPosition(bool do_interpolate)
+void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
 {
        m_last_sent_yaw = m_yaw;
        m_last_sent_position = m_base_position;
@@ -1660,12 +1664,16 @@ void LuaEntitySAO::sendPosition(bool do_interpolate)
        std::ostringstream os(std::ios::binary);
        // command (0 = update position)
        writeU8(os, 0);
+
        // do_interpolate
        writeU8(os, do_interpolate);
        // pos
        writeV3F1000(os, m_base_position);
        // yaw
        writeF1000(os, m_yaw);
+       // is_end_position (for interpolation)
+       writeU8(os, is_movement_end);
+
        // create message and add to list
        ActiveObjectMessage aom(getId(), false, os.str());
        m_messages_out.push_back(aom);
index 718ea027101ff136eaced35963da3fd7c1ca9fed..2316aba8dc83a20500a93ccff2937feda1320631 100644 (file)
@@ -219,7 +219,7 @@ public:
        void setPos(v3f pos);
        void moveTo(v3f pos);
 private:
-       void sendPosition(bool do_interpolate);
+       void sendPosition(bool do_interpolate, bool is_movement_end);
 
        std::string m_init_name;
        std::string m_init_state;