void setSpeed(v3f speed)
{
- clampToF1000(speed);
m_speed = speed;
}
os<<serializeString32(m_init_state);
}
writeU16(os, m_hp);
- writeV3F1000(os, m_velocity);
+ writeV3F1000(os, clampToF1000(m_velocity));
// yaw
writeF1000(os, m_rotation.Y);
void PlayerSAO::setBasePosition(v3f position)
{
- // It's not entirely clear which parts of the network protocol still use
- // v3f1000, but the script API enforces its bound on all float vectors
- // (maybe it shouldn't?). For that reason we need to make sure the position
- // isn't ever set to values that fail this restriction.
- clampToF1000(position);
-
if (m_player && position != m_base_position)
m_player->setDirty(true);
s_obj->getStaticData(&data);
}
-void StaticObject::serialize(std::ostream &os)
+void StaticObject::serialize(std::ostream &os) const
{
// type
writeU8(os, type);
// pos
- writeV3F1000(os, pos);
+ writeV3F1000(os, clampToF1000(pos));
// data
os<<serializeString16(data);
}
StaticObject() = default;
StaticObject(const ServerActiveObject *s_obj, const v3f &pos_);
- void serialize(std::ostream &os);
+ void serialize(std::ostream &os) const;
void deSerialize(std::istream &is, u8 version);
};
//// More serialization stuff
////
-inline void clampToF1000(float &v)
+inline float clampToF1000(float v)
{
- v = core::clamp(v, F1000_MIN, F1000_MAX);
+ return core::clamp(v, F1000_MIN, F1000_MAX);
}
-inline void clampToF1000(v3f &v)
+inline v3f clampToF1000(v3f v)
{
- clampToF1000(v.X);
- clampToF1000(v.Y);
- clampToF1000(v.Z);
+ return {clampToF1000(v.X), clampToF1000(v.Y), clampToF1000(v.Z)};
}
// Creates a string with the length as the first two bytes