From ea827e4c5d5f67b2dc38b4d2ef754c7c70701781 Mon Sep 17 00:00:00 2001 From: grorp Date: Mon, 1 Jul 2024 20:41:54 +0200 Subject: [PATCH] Fix new texture properties not being sent for minetest.add_particle (#14760) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lars Müller --- doc/lua_api.md | 5 ++++- src/particles.cpp | 16 ++++++++++++---- src/particles.h | 6 ++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index a749b337e..126431bf9 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -10657,7 +10657,10 @@ Used by `minetest.add_particle`. texture = "image.png", -- The texture of the particle -- v5.6.0 and later: also supports the table format described in the - -- following section + -- following section, but due to a bug this did not take effect + -- (beyond the texture name). + -- v5.9.0 and later: fixes the bug. + -- Note: "texture.animation" is ignored here. Use "animation" below instead. playername = "singleplayer", -- Optional, if specified spawns particle only on the player's client diff --git a/src/particles.cpp b/src/particles.cpp index c67d72711..fdc041c3e 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -197,7 +197,8 @@ enum class ParticleTextureFlags : u8 { * decltype everywhere */ using FlagT = std::underlying_type_t; -void ServerParticleTexture::serialize(std::ostream &os, u16 protocol_ver, bool newPropertiesOnly) const +void ServerParticleTexture::serialize(std::ostream &os, u16 protocol_ver, + bool newPropertiesOnly, bool skipAnimation) const { /* newPropertiesOnly is used to de/serialize parameters of the legacy texture * field, which are encoded separately from the texspec string */ @@ -213,14 +214,19 @@ void ServerParticleTexture::serialize(std::ostream &os, u16 protocol_ver, bool n if (!newPropertiesOnly) os << serializeString32(string); - if (animated) + if (!skipAnimation && animated) animation.serialize(os, protocol_ver); } -void ServerParticleTexture::deSerialize(std::istream &is, u16 protocol_ver, bool newPropertiesOnly) +void ServerParticleTexture::deSerialize(std::istream &is, u16 protocol_ver, + bool newPropertiesOnly, bool skipAnimation) { FlagT flags = 0; deSerializeParameterValue(is, flags); + // new texture properties were missing in ParticleParameters::serialize + // before Minetest 5.9.0 + if (is.eof()) + return; animated = !!(flags & FlagT(ParticleTextureFlags::animated)); blendmode = BlendMode((flags & FlagT(ParticleTextureFlags::blend)) >> 1); @@ -230,7 +236,7 @@ void ServerParticleTexture::deSerialize(std::istream &is, u16 protocol_ver, bool if (!newPropertiesOnly) string = deSerializeString32(is); - if (animated) + if (!skipAnimation && animated) animation.deSerialize(is, protocol_ver); } @@ -254,6 +260,7 @@ void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const writeV3F32(os, drag); jitter.serialize(os); bounce.serialize(os); + texture.serialize(os, protocol_ver, true, true); } template @@ -291,4 +298,5 @@ void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver) return; jitter.deSerialize(is); bounce.deSerialize(is); + texture.deSerialize(is, protocol_ver, true, true); } diff --git a/src/particles.h b/src/particles.h index 4c178f4c4..a8d30390b 100644 --- a/src/particles.h +++ b/src/particles.h @@ -276,8 +276,10 @@ struct ParticleTexture struct ServerParticleTexture : public ParticleTexture { std::string string; - void serialize(std::ostream &os, u16 protocol_ver, bool newPropertiesOnly = false) const; - void deSerialize(std::istream &is, u16 protocol_ver, bool newPropertiesOnly = false); + void serialize(std::ostream &os, u16 protocol_ver, bool newPropertiesOnly = false, + bool skipAnimation = false) const; + void deSerialize(std::istream &is, u16 protocol_ver, bool newPropertiesOnly = false, + bool skipAnimation = false); }; struct CommonParticleParams