diff options
author | sfan5 <sfan5@live.de> | 2022-09-04 16:22:12 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2022-09-14 13:48:06 +0200 |
commit | a20b758e199eb48da7d99ba23808e15d987f2d3f (patch) | |
tree | d1690caff18c3885b67afe33f28bf12b0fbaaa94 /src/tileanimation.cpp | |
parent | 128842becf4d93ef333c317b6f999af8c90afe96 (diff) | |
download | minetest-a20b758e199eb48da7d99ba23808e15d987f2d3f.tar.gz minetest-a20b758e199eb48da7d99ba23808e15d987f2d3f.tar.bz2 minetest-a20b758e199eb48da7d99ba23808e15d987f2d3f.zip |
Allow looped animation to be used safely with old clients
fixes #12657
Diffstat (limited to 'src/tileanimation.cpp')
-rw-r--r-- | src/tileanimation.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/tileanimation.cpp b/src/tileanimation.cpp index a79a36e57..025d27d91 100644 --- a/src/tileanimation.cpp +++ b/src/tileanimation.cpp @@ -19,21 +19,27 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "tileanimation.h" #include "util/serialize.h" -void TileAnimationParams::serialize(std::ostream &os, u16 protocol_version) const +void TileAnimationParams::serialize(std::ostream &os, u16 protocol_ver) const { + // The particle code overloads the length parameter so that negative numbers + // indicate an extra feature which old clients don't understand (crash). + // In hindsight it would have been better to use an extra parameter for this + // but we're stuck with this now. + const bool need_abs = protocol_ver < 40; + writeU8(os, type); if (type == TAT_VERTICAL_FRAMES) { writeU16(os, vertical_frames.aspect_w); writeU16(os, vertical_frames.aspect_h); - writeF32(os, vertical_frames.length); + writeF32(os, need_abs ? fabs(vertical_frames.length) : vertical_frames.length); } else if (type == TAT_SHEET_2D) { writeU8(os, sheet_2d.frames_w); writeU8(os, sheet_2d.frames_h); - writeF32(os, sheet_2d.frame_length); + writeF32(os, need_abs ? fabs(sheet_2d.frame_length) : sheet_2d.frame_length); } } -void TileAnimationParams::deSerialize(std::istream &is, u16 protocol_version) +void TileAnimationParams::deSerialize(std::istream &is, u16 protocol_ver) { type = (TileAnimationType) readU8(is); |