add support for entity linking
authorsapier <sapier at gmx dot net>
Sun, 15 Jan 2012 21:22:07 +0000 (22:22 +0100)
committersapier <sapier at gmx dot net>
Sun, 15 Jan 2012 21:22:07 +0000 (22:22 +0100)
src/content_cao_lua.cpp
src/content_sao_lua.cpp
src/content_sao_lua.h

index afb98c2eab7e02c48ca79fb0ac6427bab7695ff8..ed5ecf9c0db126a9d90ed5e3819450069f7fd0f1 100644 (file)
@@ -19,8 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <list>
 #include "content_cao.h"
 #include "luaentity_common.h"
+#include "clientlinkableobject.h"
 
-class LuaEntityCAO : public ClientActiveObject
+class LuaEntityCAO : public ClientActiveObject, public ClientLinkableObject
 {
 private:
        core::aabbox3d<f32> m_selection_box;
@@ -223,35 +224,40 @@ public:
 
        void step(float dtime, ClientEnvironment *env)
        {
-               if(m_prop->physical){
-                       core::aabbox3d<f32> box = m_prop->collisionbox;
-                       box.MinEdge *= BS;
-                       box.MaxEdge *= BS;
-                       collisionMoveResult moveresult;
-                       f32 pos_max_d = BS*0.25; // Distance per iteration
-                       v3f p_pos = m_position;
-                       v3f p_velocity = m_velocity;
-                       IGameDef *gamedef = env->getGameDef();
-                       moveresult = collisionMovePrecise(&env->getMap(), gamedef,
-                                       pos_max_d, box, dtime, p_pos, p_velocity);
-                       // Apply results
-                       m_position = p_pos;
-                       m_velocity = p_velocity;
-
-                       bool is_end_position = moveresult.collides;
-                       pos_translator.update(m_position, is_end_position, dtime);
-                       pos_translator.translate(dtime);
-                       updateNodePos();
-
-                       m_velocity += dtime * m_acceleration;
-               } else {
-                       m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
-                       m_velocity += dtime * m_acceleration;
-                       pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
-                       pos_translator.translate(dtime);
-                       updateNodePos();
+               //if liked movement is handled by parent entity
+               if(!this->isLinked()) {
+                       if(m_prop->physical){
+                               core::aabbox3d<f32> box = m_prop->collisionbox;
+                               box.MinEdge *= BS;
+                               box.MaxEdge *= BS;
+                               collisionMoveResult moveresult;
+                               f32 pos_max_d = BS*0.25; // Distance per iteration
+                               v3f p_pos = m_position;
+                               v3f p_velocity = m_velocity;
+                               IGameDef *gamedef = env->getGameDef();
+                               moveresult = collisionMovePrecise(&env->getMap(), gamedef,
+                                               pos_max_d, box, dtime, p_pos, p_velocity);
+                               // Apply results
+                               m_position = p_pos;
+                               m_velocity = p_velocity;
+
+                               bool is_end_position = moveresult.collides;
+                               pos_translator.update(m_position, is_end_position, dtime);
+                               pos_translator.translate(dtime);
+                               updateNodePos();
+
+                               m_velocity += dtime * m_acceleration;
+                       } else {
+                               m_position += dtime * m_velocity + 0.5 * dtime * dtime * m_acceleration;
+                               m_velocity += dtime * m_acceleration;
+                               pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
+                               pos_translator.translate(dtime);
+                               updateNodePos();
+                       }
                }
 
+               stepLinkedObjects(this->m_position,dtime);
+
                m_anim_timer += dtime;
                if(m_anim_timer >= m_anim_framelength){
                        m_anim_timer -= m_anim_framelength;
@@ -397,7 +403,23 @@ public:
 
                        updateTexturePos();
                }
+               else if (handleLinkUnlinkMessages(cmd,&is,this->m_env))
+               {
+                       //Link unlink already done in handleLinkUnlinkMessages!
+               }
+       }
+
+       void setPosition(v3f toset, float dtime){
+               if (this->isLinked()) {
+                       this->m_position = toset + this->m_linkOffset;
+
+                       pos_translator.update(m_position, pos_translator.aim_is_end, pos_translator.anim_time);
+                       pos_translator.translate(dtime);
+                       updateNodePos();
+               }
        }
+
+       void updateLinkState(bool value) {}
 };
 
 // Prototype
index 6092d613bc6ed409f91d69e1296be30914b284fd..0d89c555192d7ebe6e0479390772a8417198a497 100644 (file)
@@ -319,5 +319,26 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
        m_messages_out.push_back(aom);
 }
 
+bool LuaEntitySAO::sendLinkMsg(ServerActiveObject* parent,v3f offset) {
+       std::ostringstream os(std::ios::binary);
+       writeU8(os, AO_Message_type::Link);
+       // parameters
+       writeU16(os, parent->getId());
+       writeV3F1000(os, offset);
+       // create message and add to list
+       ActiveObjectMessage aom(getId(), false, os.str());
+       m_messages_out.push_back(aom);
+       return true;
+}
+
+bool LuaEntitySAO::sendUnlinkMsg() {
+       std::ostringstream os(std::ios::binary);
+       writeU8(os, AO_Message_type::UnLink);
+       // create message and add to list
+       ActiveObjectMessage aom(getId(), false, os.str());
+       m_messages_out.push_back(aom);
+       return true;
+}
+
 // Prototype
 LuaEntitySAO proto_LuaEntitySAO(NULL, v3f(0,0,0), "_prototype", "");
index b0f23ff49b78adf65737b4d108ed5c63c5fba80c..035e52123c00a152182cc0aae4531db0cd494e6f 100644 (file)
@@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "scriptapi.h"
 #include "luaentity_common.h"
 
-class LuaEntitySAO : public ServerActiveObject
+class LuaEntitySAO : public ServerActiveObject, public ServerLinkableObject
 {
 public:
        LuaEntitySAO(ServerEnvironment *env, v3f pos,
@@ -55,6 +55,8 @@ public:
        void setSprite(v2s16 p, int num_frames, float framelength,
                        bool select_horiz_by_yawpitch);
        std::string getName();
+       bool sendLinkMsg(ServerActiveObject* parent,v3f offset);
+       bool sendUnlinkMsg();
 
 private:
        void sendPosition(bool do_interpolate, bool is_movement_end);