Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/client/content_cao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,7 @@ void GenericCAO::processMessage(const std::string &data)
bool do_interpolate = readU8(is);
bool is_end_position = readU8(is);
float update_interval = readF32(is);
bool do_interpolate_rotation = is.peek() != EOF ? readU8(is) : true;

if(getParent() != NULL) // Just in case
return;
Expand All @@ -1551,7 +1552,10 @@ void GenericCAO::processMessage(const std::string &data)
} else {
pos_translator.init(m_position);
}
rot_translator.update(m_rotation, false, update_interval);
if (do_interpolate_rotation)
rot_translator.update(m_rotation, false, update_interval);
else
rot_translator.init(m_rotation);
updateNodePos();
} else if (cmd == AO_CMD_SET_TEXTURE_MOD) {
std::string mod = deSerializeString16(is);
Expand Down
7 changes: 5 additions & 2 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ int ObjectRef::l_get_acceleration(lua_State *L)
return 1;
}

// set_rotation(self, rotation)
// set_rotation(self, rotation, interpolate)
int ObjectRef::l_set_rotation(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
Expand All @@ -1166,9 +1166,12 @@ int ObjectRef::l_set_rotation(lua_State *L)

v3f rotation = check_v3f(L, 2) * core::RADTODEG;

// Optional second parameter: interpolate (default true)
bool interpolate = lua_isboolean(L, 3) ? lua_toboolean(L, 3) : true;

// Note: These angles are inverted before being applied using setPitchYawRoll,
// hence we end up with a right-handed rotation
entitysao->setRotation(rotation);
entitysao->setRotation(rotation, interpolate);
return 0;
}

Expand Down
5 changes: 4 additions & 1 deletion src/server/luaentity_sao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,11 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end)
m_rotation,
do_interpolate,
is_movement_end,
update_interval
update_interval,
m_rotation_interpolate
);
// Reset per-update rotation interpolation flag to default
m_rotation_interpolate = true;
// create message and add to list
m_messages_out.emplace(getId(), false, str);
}
Expand Down
5 changes: 4 additions & 1 deletion src/server/unit_sao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ std::string UnitSAO::generateUpdateArmorGroupsCommand() const

std::string UnitSAO::generateUpdatePositionCommand(const v3f &position,
const v3f &velocity, const v3f &acceleration, const v3f &rotation,
bool do_interpolate, bool is_movement_end, f32 update_interval)
bool do_interpolate, bool is_movement_end, f32 update_interval,
bool do_interpolate_rotation)
{
std::ostringstream os(std::ios::binary);
// command
Expand All @@ -378,6 +379,8 @@ std::string UnitSAO::generateUpdatePositionCommand(const v3f &position,
writeU8(os, is_movement_end);
// update_interval (for interpolation)
writeF32(os, update_interval);
// do_interpolate_rotation
writeU8(os, do_interpolate_rotation);
return os.str();
}

Expand Down
8 changes: 7 additions & 1 deletion src/server/unit_sao.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class UnitSAO : public ServerActiveObject

// Rotation
void setRotation(v3f rotation) { m_rotation = rotation; }
void setRotation(v3f rotation, bool interpolate) {
m_rotation = rotation;
m_rotation_interpolate = interpolate;
}
const v3f &getRotation() const { return m_rotation; }
const v3f getTotalRotation() const {
// This replicates what happens clientside serverside
Expand Down Expand Up @@ -87,7 +91,8 @@ class UnitSAO : public ServerActiveObject
std::string generateUpdateArmorGroupsCommand() const;
static std::string generateUpdatePositionCommand(const v3f &position,
const v3f &velocity, const v3f &acceleration, const v3f &rotation,
bool do_interpolate, bool is_movement_end, f32 update_interval);
bool do_interpolate, bool is_movement_end, f32 update_interval,
bool do_interpolate_rotation = true);
std::string generateSetPropertiesCommand(const ObjectProperties &prop) const;
static std::string generateUpdateBoneOverrideCommand(
const std::string &bone, const BoneOverride &props);
Expand All @@ -98,6 +103,7 @@ class UnitSAO : public ServerActiveObject

v3f m_rotation;
f32 m_rotation_add_yaw = 0;
bool m_rotation_interpolate = true; // per-update flag for rotation interpolation

ItemGroupList m_armor_groups;

Expand Down
Loading