sound.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include <set>
  18. #include <string>
  19. #include "util/serialize.h"
  20. #include "irrlichttypes_bloated.h"
  21. // This class describes the basic sound information for playback.
  22. // Positional handling is done separately.
  23. struct SimpleSoundSpec
  24. {
  25. SimpleSoundSpec(const std::string &name = "", float gain = 1.0f,
  26. bool loop = false, float fade = 0.0f, float pitch = 1.0f) :
  27. name(name), gain(gain), fade(fade), pitch(pitch), loop(loop)
  28. {
  29. }
  30. bool exists() const { return !name.empty(); }
  31. void serialize(std::ostream &os, u16 protocol_version) const
  32. {
  33. os << serializeString16(name);
  34. writeF32(os, gain);
  35. writeF32(os, pitch);
  36. writeF32(os, fade);
  37. }
  38. void deSerialize(std::istream &is, u16 protocol_version)
  39. {
  40. name = deSerializeString16(is);
  41. gain = readF32(is);
  42. pitch = readF32(is);
  43. fade = readF32(is);
  44. }
  45. std::string name;
  46. float gain = 1.0f;
  47. float fade = 0.0f;
  48. float pitch = 1.0f;
  49. bool loop = false;
  50. };
  51. // The order must not be changed. This is sent over the network.
  52. enum class SoundLocation : u8 {
  53. Local,
  54. Position,
  55. Object
  56. };