sound.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. struct SimpleSoundSpec
  22. {
  23. SimpleSoundSpec(const std::string &name = "", float gain = 1.0f,
  24. float fade = 0.0f, float pitch = 1.0f) :
  25. name(name),
  26. gain(gain), fade(fade), pitch(pitch)
  27. {
  28. }
  29. bool exists() const { return !name.empty(); }
  30. // Take cf_version from ContentFeatures::serialize to
  31. // keep in sync with item definitions
  32. void serialize(std::ostream &os, u8 cf_version) const
  33. {
  34. os << serializeString16(name);
  35. writeF32(os, gain);
  36. writeF32(os, pitch);
  37. writeF32(os, fade);
  38. // if (cf_version < ?)
  39. // return;
  40. }
  41. void deSerialize(std::istream &is, u8 cf_version)
  42. {
  43. name = deSerializeString16(is);
  44. gain = readF32(is);
  45. pitch = readF32(is);
  46. fade = readF32(is);
  47. }
  48. std::string name;
  49. float gain = 1.0f;
  50. float fade = 0.0f;
  51. float pitch = 1.0f;
  52. };