mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Extend bone override capabilities (#12388)
This commit is contained in:
parent
61d0f613df
commit
0d61598d8a
12 changed files with 375 additions and 80 deletions
|
@ -256,13 +256,13 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
|
|||
msg_os << serializeString32(getPropertyPacket()); // message 1
|
||||
msg_os << serializeString32(generateUpdateArmorGroupsCommand()); // 2
|
||||
msg_os << serializeString32(generateUpdateAnimationCommand()); // 3
|
||||
for (const auto &bone_pos : m_bone_position) {
|
||||
msg_os << serializeString32(generateUpdateBonePositionCommand(
|
||||
bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // 3 + N
|
||||
for (const auto &bone_override : m_bone_override) {
|
||||
msg_os << serializeString32(generateUpdateBoneOverrideCommand(
|
||||
bone_override.first, bone_override.second)); // 3 + N
|
||||
}
|
||||
msg_os << serializeString32(generateUpdateAttachmentCommand()); // 4 + m_bone_position.size
|
||||
msg_os << serializeString32(generateUpdateAttachmentCommand()); // 4 + m_bone_override.size
|
||||
|
||||
int message_count = 4 + m_bone_position.size();
|
||||
int message_count = 4 + m_bone_override.size();
|
||||
|
||||
for (const auto &id : getAttachmentChildIds()) {
|
||||
if (ServerActiveObject *obj = m_env->getActiveObject(id)) {
|
||||
|
|
|
@ -121,14 +121,14 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
|
|||
msg_os << serializeString32(getPropertyPacket()); // message 1
|
||||
msg_os << serializeString32(generateUpdateArmorGroupsCommand()); // 2
|
||||
msg_os << serializeString32(generateUpdateAnimationCommand()); // 3
|
||||
for (const auto &bone_pos : m_bone_position) {
|
||||
msg_os << serializeString32(generateUpdateBonePositionCommand(
|
||||
bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // 3 + N
|
||||
for (const auto &it : m_bone_override) {
|
||||
msg_os << serializeString32(generateUpdateBoneOverrideCommand(
|
||||
it.first, it.second)); // 3 + N
|
||||
}
|
||||
msg_os << serializeString32(generateUpdateAttachmentCommand()); // 4 + m_bone_position.size
|
||||
msg_os << serializeString32(generateUpdatePhysicsOverrideCommand()); // 5 + m_bone_position.size
|
||||
msg_os << serializeString32(generateUpdateAttachmentCommand()); // 4 + m_bone_override.size
|
||||
msg_os << serializeString32(generateUpdatePhysicsOverrideCommand()); // 5 + m_bone_override.size
|
||||
|
||||
int message_count = 5 + m_bone_position.size();
|
||||
int message_count = 5 + m_bone_override.size();
|
||||
|
||||
for (const auto &id : getAttachmentChildIds()) {
|
||||
if (ServerActiveObject *obj = m_env->getActiveObject(id)) {
|
||||
|
|
|
@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "itemgroup.h"
|
||||
#include "util/container.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Some planning
|
||||
|
@ -167,14 +168,16 @@ public:
|
|||
{}
|
||||
virtual void setAnimationSpeed(float frame_speed)
|
||||
{}
|
||||
virtual void setBonePosition(const std::string &bone, v3f position, v3f rotation)
|
||||
{}
|
||||
virtual void getBonePosition(const std::string &bone, v3f *position, v3f *lotation)
|
||||
virtual void setBoneOverride(const std::string &bone, const BoneOverride &props)
|
||||
{}
|
||||
virtual BoneOverride getBoneOverride(const std::string &bone)
|
||||
{ BoneOverride props; return props; }
|
||||
virtual const BoneOverrideMap &getBoneOverrides() const
|
||||
{ static BoneOverrideMap rv; return rv; }
|
||||
virtual const std::unordered_set<int> &getAttachmentChildIds() const
|
||||
{ static std::unordered_set<int> rv; return rv; }
|
||||
virtual ServerActiveObject *getParent() const { return nullptr; }
|
||||
virtual ObjectProperties* accessObjectProperties()
|
||||
virtual ObjectProperties *accessObjectProperties()
|
||||
{ return NULL; }
|
||||
virtual void notifyObjectPropertiesModified()
|
||||
{}
|
||||
|
|
|
@ -76,20 +76,20 @@ void UnitSAO::setAnimationSpeed(float frame_speed)
|
|||
m_animation_speed_sent = false;
|
||||
}
|
||||
|
||||
void UnitSAO::setBonePosition(const std::string &bone, v3f position, v3f rotation)
|
||||
void UnitSAO::setBoneOverride(const std::string &bone, const BoneOverride &props)
|
||||
{
|
||||
// store these so they can be updated to clients
|
||||
m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
|
||||
m_bone_position_sent = false;
|
||||
m_bone_override[bone] = props;
|
||||
m_bone_override_sent = false;
|
||||
}
|
||||
|
||||
void UnitSAO::getBonePosition(const std::string &bone, v3f *position, v3f *rotation)
|
||||
BoneOverride UnitSAO::getBoneOverride(const std::string &bone)
|
||||
{
|
||||
auto it = m_bone_position.find(bone);
|
||||
if (it != m_bone_position.end()) {
|
||||
*position = it->second.X;
|
||||
*rotation = it->second.Y;
|
||||
}
|
||||
auto it = m_bone_override.find(bone);
|
||||
BoneOverride props;
|
||||
if (it != m_bone_override.end())
|
||||
props = it->second;
|
||||
return props;
|
||||
}
|
||||
|
||||
void UnitSAO::sendOutdatedData()
|
||||
|
@ -109,11 +109,11 @@ void UnitSAO::sendOutdatedData()
|
|||
m_messages_out.emplace(getId(), true, generateUpdateAnimationSpeedCommand());
|
||||
}
|
||||
|
||||
if (!m_bone_position_sent) {
|
||||
m_bone_position_sent = true;
|
||||
for (const auto &bone_pos : m_bone_position) {
|
||||
m_messages_out.emplace(getId(), true, generateUpdateBonePositionCommand(
|
||||
bone_pos.first, bone_pos.second.X, bone_pos.second.Y));
|
||||
if (!m_bone_override_sent) {
|
||||
m_bone_override_sent = true;
|
||||
for (const auto &bone_pos : m_bone_override) {
|
||||
m_messages_out.emplace(getId(), true, generateUpdateBoneOverrideCommand(
|
||||
bone_pos.first, bone_pos.second));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,16 +275,25 @@ std::string UnitSAO::generateUpdateAttachmentCommand() const
|
|||
return os.str();
|
||||
}
|
||||
|
||||
std::string UnitSAO::generateUpdateBonePositionCommand(
|
||||
const std::string &bone, const v3f &position, const v3f &rotation)
|
||||
std::string UnitSAO::generateUpdateBoneOverrideCommand(
|
||||
const std::string &bone, const BoneOverride &props)
|
||||
{
|
||||
std::ostringstream os(std::ios::binary);
|
||||
// command
|
||||
writeU8(os, AO_CMD_SET_BONE_POSITION);
|
||||
// parameters
|
||||
os << serializeString16(bone);
|
||||
writeV3F32(os, position);
|
||||
writeV3F32(os, rotation);
|
||||
writeV3F32(os, props.position.vector);
|
||||
v3f euler_rot;
|
||||
props.rotation.next.toEuler(euler_rot);
|
||||
writeV3F32(os, euler_rot * core::RADTODEG);
|
||||
writeV3F32(os, props.scale.vector);
|
||||
writeF32(os, props.position.interp_timer);
|
||||
writeF32(os, props.rotation.interp_timer);
|
||||
writeF32(os, props.scale.interp_timer);
|
||||
writeU8(os, (props.position.absolute & 1) << 0
|
||||
| (props.rotation.absolute & 1) << 1
|
||||
| (props.scale.absolute & 1) << 2);
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
|
|
@ -70,8 +70,10 @@ public:
|
|||
void setAnimationSpeed(float frame_speed);
|
||||
|
||||
// Bone position
|
||||
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
|
||||
void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
|
||||
void setBoneOverride(const std::string &bone, const BoneOverride &props);
|
||||
BoneOverride getBoneOverride(const std::string &bone);
|
||||
const std::unordered_map<std::string, BoneOverride>
|
||||
&getBoneOverrides() const { return m_bone_override; };
|
||||
|
||||
// Attachments
|
||||
ServerActiveObject *getParent() const;
|
||||
|
@ -100,8 +102,8 @@ public:
|
|||
const v3f &velocity, const v3f &acceleration, const v3f &rotation,
|
||||
bool do_interpolate, bool is_movement_end, f32 update_interval);
|
||||
std::string generateSetPropertiesCommand(const ObjectProperties &prop) const;
|
||||
static std::string generateUpdateBonePositionCommand(const std::string &bone,
|
||||
const v3f &position, const v3f &rotation);
|
||||
static std::string generateUpdateBoneOverrideCommand(
|
||||
const std::string &bone, const BoneOverride &props);
|
||||
void sendPunchCommand();
|
||||
|
||||
protected:
|
||||
|
@ -117,7 +119,7 @@ protected:
|
|||
ObjectProperties m_prop;
|
||||
|
||||
// Stores position and rotation for each bone name
|
||||
std::unordered_map<std::string, core::vector2d<v3f>> m_bone_position;
|
||||
std::unordered_map<std::string, BoneOverride> m_bone_override;
|
||||
|
||||
int m_attachment_parent_id = 0;
|
||||
|
||||
|
@ -139,7 +141,7 @@ private:
|
|||
bool m_animation_speed_sent = false;
|
||||
|
||||
// Bone positions
|
||||
bool m_bone_position_sent = false;
|
||||
bool m_bone_override_sent = false;
|
||||
|
||||
// Attachments
|
||||
std::unordered_set<int> m_attachment_child_ids;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue