diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-11-12 13:14:44 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-11-29 19:13:39 +0200 |
commit | 23adfff4fea9c1ad49e7bc4cd08341c2e1fded78 (patch) | |
tree | 7401d4ad3e91e4949b4a55b454eb573b63e6d33c /src | |
parent | b35adfbd2dd434d0b75b91b0b4784ef5cdef2ae0 (diff) | |
download | minetest-23adfff4fea9c1ad49e7bc4cd08341c2e1fded78.tar.gz minetest-23adfff4fea9c1ad49e7bc4cd08341c2e1fded78.tar.bz2 minetest-23adfff4fea9c1ad49e7bc4cd08341c2e1fded78.zip |
Scripting WIP
Diffstat (limited to 'src')
-rw-r--r-- | src/content_cao.cpp | 4 | ||||
-rw-r--r-- | src/content_cao.h | 12 | ||||
-rw-r--r-- | src/content_sao.cpp | 18 | ||||
-rw-r--r-- | src/content_sao.h | 2 |
4 files changed, 26 insertions, 10 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 28c2787e1..0db9803cc 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -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(); diff --git a/src/content_cao.h b/src/content_cao.h index 3231a190f..72cb94eb7 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -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; } diff --git a/src/content_sao.cpp b/src/content_sao.cpp index ec6f39697..6d9d5a948 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -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); diff --git a/src/content_sao.h b/src/content_sao.h index 718ea0271..2316aba8d 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -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; |