mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 18:13:46 +01:00
Scripting WIP
This commit is contained in:
parent
b35adfbd2d
commit
23adfff4fe
@ -1366,9 +1366,11 @@ void LuaEntityCAO::processMessage(const std::string &data)
|
|||||||
m_position = readV3F1000(is);
|
m_position = readV3F1000(is);
|
||||||
// yaw
|
// yaw
|
||||||
m_yaw = readF1000(is);
|
m_yaw = readF1000(is);
|
||||||
|
// is_end_position (for interpolation)
|
||||||
|
bool is_end_position = readU8(is);
|
||||||
|
|
||||||
if(do_interpolate)
|
if(do_interpolate)
|
||||||
pos_translator.update(m_position);
|
pos_translator.update(m_position, is_end_position);
|
||||||
else
|
else
|
||||||
pos_translator.init(m_position);
|
pos_translator.init(m_position);
|
||||||
updateNodePos();
|
updateNodePos();
|
||||||
|
@ -35,6 +35,7 @@ struct SmoothTranslator
|
|||||||
v3f vect_old;
|
v3f vect_old;
|
||||||
v3f vect_show;
|
v3f vect_show;
|
||||||
v3f vect_aim;
|
v3f vect_aim;
|
||||||
|
bool aim_is_end;
|
||||||
f32 anim_counter;
|
f32 anim_counter;
|
||||||
f32 anim_time;
|
f32 anim_time;
|
||||||
f32 anim_time_counter;
|
f32 anim_time_counter;
|
||||||
@ -53,6 +54,7 @@ struct SmoothTranslator
|
|||||||
vect_old = vect;
|
vect_old = vect;
|
||||||
vect_show = vect;
|
vect_show = vect;
|
||||||
vect_aim = vect;
|
vect_aim = vect;
|
||||||
|
aim_is_end = true;
|
||||||
anim_counter = 0;
|
anim_counter = 0;
|
||||||
anim_time = 0;
|
anim_time = 0;
|
||||||
anim_time_counter = 0;
|
anim_time_counter = 0;
|
||||||
@ -63,8 +65,9 @@ struct SmoothTranslator
|
|||||||
init(vect_show);
|
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_old = vect_show;
|
||||||
vect_aim = vect_new;
|
vect_aim = vect_new;
|
||||||
if(anim_time < 0.001 || anim_time > 1.0)
|
if(anim_time < 0.001 || anim_time > 1.0)
|
||||||
@ -85,8 +88,11 @@ struct SmoothTranslator
|
|||||||
moveratio = anim_time_counter / anim_time;
|
moveratio = anim_time_counter / anim_time;
|
||||||
// Move a bit less than should, to avoid oscillation
|
// Move a bit less than should, to avoid oscillation
|
||||||
moveratio = moveratio * 0.5;
|
moveratio = moveratio * 0.5;
|
||||||
if(moveratio > 1.5)
|
float move_end = 1.5;
|
||||||
moveratio = 1.5;
|
if(aim_is_end)
|
||||||
|
move_end = 1.0;
|
||||||
|
if(moveratio > move_end)
|
||||||
|
moveratio = move_end;
|
||||||
vect_show = vect_old + vect_move * moveratio;
|
vect_show = vect_old + vect_move * moveratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1572,14 +1572,17 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
|
|||||||
if(send_recommended == false)
|
if(send_recommended == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool move_end = false;
|
||||||
float minchange = 0.2*BS;
|
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;
|
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;
|
minchange = 0.05*BS;
|
||||||
|
}
|
||||||
if(m_base_position.getDistanceFrom(m_last_sent_position) > minchange
|
if(m_base_position.getDistanceFrom(m_last_sent_position) > minchange
|
||||||
|| fabs(m_yaw - m_last_sent_yaw) > 1.0){
|
|| 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)
|
void LuaEntitySAO::setPos(v3f pos)
|
||||||
{
|
{
|
||||||
m_base_position = pos;
|
m_base_position = pos;
|
||||||
sendPosition(false);
|
sendPosition(false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaEntitySAO::moveTo(v3f pos)
|
void LuaEntitySAO::moveTo(v3f pos)
|
||||||
{
|
{
|
||||||
m_base_position = 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_yaw = m_yaw;
|
||||||
m_last_sent_position = m_base_position;
|
m_last_sent_position = m_base_position;
|
||||||
@ -1660,12 +1664,16 @@ void LuaEntitySAO::sendPosition(bool do_interpolate)
|
|||||||
std::ostringstream os(std::ios::binary);
|
std::ostringstream os(std::ios::binary);
|
||||||
// command (0 = update position)
|
// command (0 = update position)
|
||||||
writeU8(os, 0);
|
writeU8(os, 0);
|
||||||
|
|
||||||
// do_interpolate
|
// do_interpolate
|
||||||
writeU8(os, do_interpolate);
|
writeU8(os, do_interpolate);
|
||||||
// pos
|
// pos
|
||||||
writeV3F1000(os, m_base_position);
|
writeV3F1000(os, m_base_position);
|
||||||
// yaw
|
// yaw
|
||||||
writeF1000(os, m_yaw);
|
writeF1000(os, m_yaw);
|
||||||
|
// is_end_position (for interpolation)
|
||||||
|
writeU8(os, is_movement_end);
|
||||||
|
|
||||||
// create message and add to list
|
// create message and add to list
|
||||||
ActiveObjectMessage aom(getId(), false, os.str());
|
ActiveObjectMessage aom(getId(), false, os.str());
|
||||||
m_messages_out.push_back(aom);
|
m_messages_out.push_back(aom);
|
||||||
|
@ -219,7 +219,7 @@ public:
|
|||||||
void setPos(v3f pos);
|
void setPos(v3f pos);
|
||||||
void moveTo(v3f pos);
|
void moveTo(v3f pos);
|
||||||
private:
|
private:
|
||||||
void sendPosition(bool do_interpolate);
|
void sendPosition(bool do_interpolate, bool is_movement_end);
|
||||||
|
|
||||||
std::string m_init_name;
|
std::string m_init_name;
|
||||||
std::string m_init_state;
|
std::string m_init_state;
|
||||||
|
Loading…
Reference in New Issue
Block a user