diff options
author | sfan5 <sfan5@live.de> | 2022-06-08 19:33:46 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2022-07-14 20:55:45 +0200 |
commit | 137eef6590205b7bcdf5273221bc22c17b218f6e (patch) | |
tree | 8933aefd5ec6fb351bdf54727f65e379f82ae37c | |
parent | b204655081f495c9d45fdf7d49d203e910dafc7a (diff) | |
download | minetest-137eef6590205b7bcdf5273221bc22c17b218f6e.tar.gz minetest-137eef6590205b7bcdf5273221bc22c17b218f6e.tar.bz2 minetest-137eef6590205b7bcdf5273221bc22c17b218f6e.zip |
Move f1000 sanitizing to the places that still use this type
-rw-r--r-- | src/player.h | 1 | ||||
-rw-r--r-- | src/server/luaentity_sao.cpp | 2 | ||||
-rw-r--r-- | src/server/player_sao.cpp | 6 | ||||
-rw-r--r-- | src/staticobject.cpp | 4 | ||||
-rw-r--r-- | src/staticobject.h | 2 | ||||
-rw-r--r-- | src/util/serialize.h | 10 |
6 files changed, 8 insertions, 17 deletions
diff --git a/src/player.h b/src/player.h index cc1357010..beca82f66 100644 --- a/src/player.h +++ b/src/player.h @@ -141,7 +141,6 @@ public: void setSpeed(v3f speed) { - clampToF1000(speed); m_speed = speed; } diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index a0a8aede0..ab4a9e3f2 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -290,7 +290,7 @@ void LuaEntitySAO::getStaticData(std::string *result) const os<<serializeString32(m_init_state); } writeU16(os, m_hp); - writeV3F1000(os, m_velocity); + writeV3F1000(os, clampToF1000(m_velocity)); // yaw writeF1000(os, m_rotation.Y); diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index c5f6d0a24..a58a0397f 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -321,12 +321,6 @@ std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const 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); diff --git a/src/staticobject.cpp b/src/staticobject.cpp index 1160ec68f..f92995d0b 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -28,12 +28,12 @@ StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_): 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); } diff --git a/src/staticobject.h b/src/staticobject.h index 6fb486193..03cd23cc8 100644 --- a/src/staticobject.h +++ b/src/staticobject.h @@ -37,7 +37,7 @@ struct StaticObject 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); }; diff --git a/src/util/serialize.h b/src/util/serialize.h index 2203fff0c..4dc1a54c6 100644 --- a/src/util/serialize.h +++ b/src/util/serialize.h @@ -439,16 +439,14 @@ MAKE_STREAM_WRITE_FXN(video::SColor, ARGB8, 4); //// 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 |