Move tool stuff to tool.{h,cpp}
[oweals/minetest.git] / src / content_cao.h
index 963e1a4889aef425dd302546f5b81caa9a38453f..5310127a6147556ad8231fe8c514e490ec227db0 100644 (file)
@@ -38,6 +38,7 @@ struct SmoothTranslator
        f32 anim_counter;
        f32 anim_time;
        f32 anim_time_counter;
+       bool aim_is_end;
 
        SmoothTranslator():
                vect_old(0,0,0),
@@ -45,7 +46,8 @@ struct SmoothTranslator
                vect_aim(0,0,0),
                anim_counter(0),
                anim_time(0),
-               anim_time_counter(0)
+               anim_time_counter(0),
+               aim_is_end(true)
        {}
 
        void init(v3f vect)
@@ -56,6 +58,7 @@ struct SmoothTranslator
                anim_counter = 0;
                anim_time = 0;
                anim_time_counter = 0;
+               aim_is_end = true;
        }
 
        void sharpen()
@@ -63,14 +66,19 @@ struct SmoothTranslator
                init(vect_show);
        }
 
-       void update(v3f vect_new)
+       void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
        {
+               aim_is_end = is_end_position;
                vect_old = vect_show;
                vect_aim = vect_new;
-               if(anim_time < 0.001 || anim_time > 1.0)
-                       anim_time = anim_time_counter;
-               else
-                       anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
+               if(update_interval > 0){
+                       anim_time = update_interval;
+               } else {
+                       if(anim_time < 0.001 || anim_time > 1.0)
+                               anim_time = anim_time_counter;
+                       else
+                               anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
+               }
                anim_time_counter = 0;
                anim_counter = 0;
        }
@@ -85,8 +93,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;
        }
 
@@ -376,6 +387,52 @@ private:
        Settings *m_properties;
 };
 
+/*
+       LuaEntityCAO
+*/
+
+struct LuaEntityProperties;
+
+class LuaEntityCAO : public ClientActiveObject
+{
+public:
+       LuaEntityCAO();
+       virtual ~LuaEntityCAO();
+       
+       u8 getType() const
+       {
+               return ACTIVEOBJECT_TYPE_LUAENTITY;
+       }
+       
+       static ClientActiveObject* create();
+
+       void addToScene(scene::ISceneManager *smgr);
+       void removeFromScene();
+       void updateLight(u8 light_at_pos);
+       v3s16 getLightPosition();
+       void updateNodePos();
+
+       void step(float dtime, ClientEnvironment *env);
+
+       void processMessage(const std::string &data);
+
+       void initialize(const std::string &data);
+       
+       core::aabbox3d<f32>* getSelectionBox()
+               {return &m_selection_box;}
+       v3f getPosition()
+               {return pos_translator.vect_show;}
+
+private:
+       core::aabbox3d<f32> m_selection_box;
+       scene::IMeshSceneNode *m_meshnode;
+       scene::MyBillboardSceneNode *m_spritenode;
+       v3f m_position;
+       float m_yaw;
+       struct LuaEntityProperties *m_prop;
+       SmoothTranslator pos_translator;
+};
+
 
 #endif