Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

SoundTable.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "resource/SoundTable.h"
  19. #include "BinReader.h"
  20. static void read(BinReader& reader, SoundData& soundData)
  21. {
  22. soundData.soundId = reader.readInt();
  23. assert(soundData.soundId == 0 ||
  24. (soundData.soundId & 0xFF000000) == static_cast<uint32_t>(ResourceType::kSound));
  25. soundData.priority = reader.readFloat();
  26. assert(soundData.priority >= 0.0 && soundData.priority <= 1.0);
  27. soundData.probability = reader.readFloat();
  28. assert(soundData.probability >= 0.0 && soundData.probability <= 1.0);
  29. soundData.volume = reader.readFloat();
  30. assert(soundData.volume >= 0.0 && soundData.volume <= 10.0);
  31. }
  32. static void read(BinReader& reader, SoundTableData& soundTableData)
  33. {
  34. uint32_t numData = reader.readInt();
  35. soundTableData.data.resize(numData);
  36. for(auto& soundData : soundTableData.data)
  37. {
  38. read(reader, soundData);
  39. }
  40. }
  41. SoundTable::SoundTable(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
  42. {
  43. BinReader reader(data, size);
  44. uint32_t resourceId = reader.readInt();
  45. assert(resourceId == id);
  46. UNUSED(resourceId);
  47. uint32_t unk1 = reader.readInt();
  48. assert(unk1 == 0);
  49. UNUSED(unk1);
  50. SoundTableData defaultData;
  51. read(reader, defaultData);
  52. uint32_t soundTableSize = reader.readInt();
  53. for(uint32_t i = 0; i < soundTableSize; i++)
  54. {
  55. uint32_t soundType = reader.readInt();
  56. read(reader, soundTable[soundType]);
  57. uint32_t unk2 = reader.readInt();
  58. assert(unk2 == 0);
  59. UNUSED(unk2);
  60. }
  61. assert(reader.remaining() == 0);
  62. }