]> git.lizzy.rs Git - minetest.git/blobdiff - src/sound.h
Object selection: Improve distance checks (#12974)
[minetest.git] / src / sound.h
index 6cbd55e8fdb8d9337cd1976d783e1bdb575ac95f..801c552a96143d6dcb5c7d950a5040f9e7da0b82 100644 (file)
@@ -24,32 +24,30 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/serialize.h"
 #include "irrlichttypes_bloated.h"
 
+// This class describes the basic sound information for playback.
+// Positional handling is done separately.
+
 struct SimpleSoundSpec
 {
        SimpleSoundSpec(const std::string &name = "", float gain = 1.0f,
-                       float fade = 0.0f, float pitch = 1.0f) :
-                       name(name),
-                       gain(gain), fade(fade), pitch(pitch)
+                       bool loop = false, float fade = 0.0f, float pitch = 1.0f) :
+                       name(name), gain(gain), fade(fade), pitch(pitch), loop(loop)
        {
        }
 
        bool exists() const { return !name.empty(); }
 
-       // Take cf_version from ContentFeatures::serialize to
-       // keep in sync with item definitions
-       void serialize(std::ostream &os, u8 cf_version) const
+       void serialize(std::ostream &os, u16 protocol_version) const
        {
-               os << serializeString(name);
+               os << serializeString16(name);
                writeF32(os, gain);
                writeF32(os, pitch);
                writeF32(os, fade);
-               // if (cf_version < ?)
-               //     return;
        }
 
-       void deSerialize(std::istream &is, u8 cf_version)
+       void deSerialize(std::istream &is, u16 protocol_version)
        {
-               name = deSerializeString(is);
+               name = deSerializeString16(is);
                gain = readF32(is);
                pitch = readF32(is);
                fade = readF32(is);
@@ -59,4 +57,13 @@ struct SimpleSoundSpec
        float gain = 1.0f;
        float fade = 0.0f;
        float pitch = 1.0f;
+       bool loop = false;
+};
+
+
+// The order must not be changed. This is sent over the network.
+enum class SoundLocation : u8 {
+       Local,
+       Position,
+       Object
 };