function TNT:on_rightclick(clicker)
pos = self.object:getpos()
pos = {x=pos.x, y=pos.y+0.1, z=pos.z}
- self.object:moveto(pos)
+ self.object:moveto(pos, false)
end
--[[
function TNT:on_rightclick(clicker)
m_yaw = readF1000(is);
// is_end_position (for interpolation)
bool is_end_position = readU8(is);
+ // update_interval
+ float update_interval = readF1000(is);
if(do_interpolate)
- pos_translator.update(m_position, is_end_position);
+ pos_translator.update(m_position, is_end_position, update_interval);
else
pos_translator.init(m_position);
updateNodePos();
v3f vect_old;
v3f vect_show;
v3f vect_aim;
- bool aim_is_end;
f32 anim_counter;
f32 anim_time;
f32 anim_time_counter;
+ bool aim_is_end;
SmoothTranslator():
vect_old(0,0,0),
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)
vect_old = vect;
vect_show = vect;
vect_aim = vect;
- aim_is_end = true;
anim_counter = 0;
anim_time = 0;
anim_time_counter = 0;
+ aim_is_end = true;
}
void sharpen()
init(vect_show);
}
- void update(v3f vect_new, bool is_end_position=false)
+ 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;
}
m_yaw(0),
m_last_sent_yaw(0),
m_last_sent_position(0,0,0),
- m_last_sent_position_timer(0)
+ m_last_sent_position_timer(0),
+ m_last_sent_move_precision(0)
{
// Only register type if no environment supplied
if(env == NULL){
if(send_recommended == false)
return;
- bool move_end = false;
float minchange = 0.2*BS;
if(m_last_sent_position_timer > 1.0){
minchange = 0.01*BS;
- 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, move_end);
+ float move_d = m_base_position.getDistanceFrom(m_last_sent_position);
+ move_d += m_last_sent_move_precision;
+ if(move_d > minchange || fabs(m_yaw - m_last_sent_yaw) > 1.0){
+ sendPosition(true, false);
}
}
sendPosition(false, true);
}
-void LuaEntitySAO::moveTo(v3f pos)
+void LuaEntitySAO::moveTo(v3f pos, bool continuous)
{
m_base_position = pos;
- sendPosition(true, true);
+ if(!continuous)
+ sendPosition(true, true);
}
void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
{
+ m_last_sent_move_precision = m_base_position.getDistanceFrom(
+ m_last_sent_position);
+ m_last_sent_position_timer = 0;
m_last_sent_yaw = m_yaw;
m_last_sent_position = m_base_position;
- m_last_sent_position_timer = 0;
+
+ float update_interval = m_env->getSendRecommendedInterval();
std::ostringstream os(std::ios::binary);
// command (0 = update position)
writeF1000(os, m_yaw);
// is_end_position (for interpolation)
writeU8(os, is_movement_end);
+ // update_interval (for interpolation)
+ writeF1000(os, update_interval);
// create message and add to list
ActiveObjectMessage aom(getId(), false, os.str());
void rightClick(Player *player);
void setPos(v3f pos);
- void moveTo(v3f pos);
+ void moveTo(v3f pos, bool continuous);
private:
void sendPosition(bool do_interpolate, bool is_movement_end);
float m_last_sent_yaw;
v3f m_last_sent_position;
float m_last_sent_position_timer;
+ float m_last_sent_move_precision;
};
#endif
// This helps the objects to send data at the same time
bool send_recommended = false;
m_send_recommended_timer += dtime;
- if(m_send_recommended_timer > 0.10)
+ if(m_send_recommended_timer > getSendRecommendedInterval())
{
- m_send_recommended_timer = 0;
+ m_send_recommended_timer -= getSendRecommendedInterval();
send_recommended = true;
}
return m_lua;
}
+ float getSendRecommendedInterval()
+ {
+ return 0.10;
+ }
+
/*
Save players
*/
}
// Exported functions
-
+
+ // remove(self)
static int l_remove(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
co->m_removed = true;
return 0;
}
-
+
+ // getpos(self)
+ // returns: {x=num, y=num, z=num}
static int l_getpos(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
lua_setfield(L, -2, "z");
return 1;
}
-
+
+ // setpos(self, pos)
static int l_setpos(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
co->setPos(pos);
return 0;
}
-
+
+ // moveto(self, pos, continuous=false)
static int l_moveto(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
if(co == NULL) return 0;
// pos
v3f pos = readFloatPos(L, 2);
+ // continuous
+ bool continuous = lua_toboolean(L, 3);
// Do it
- co->moveTo(pos);
+ co->moveTo(pos, continuous);
return 0;
}
/*
Some more dynamic interface
*/
- virtual void setPos(v3f pos){ setBasePosition(pos); }
- virtual void moveTo(v3f pos){ setBasePosition(pos); }
+ virtual void setPos(v3f pos)
+ { setBasePosition(pos); }
+ // continuous: if true, object does not stop immediately at pos
+ virtual void moveTo(v3f pos, bool continuous)
+ { setBasePosition(pos); }
/*
Step object in time.