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

MotionData.cpp 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/MotionData.h"
  19. #include "resource/Animation.h"
  20. #include "BinReader.h"
  21. #include "Core.h"
  22. #include "ResourceCache.h"
  23. enum MotionDataFlags
  24. {
  25. kNoMods = 1,
  26. kFromDefault = 2
  27. };
  28. MotionData::MotionData()
  29. {}
  30. MotionData::MotionData(MotionData&& other)
  31. {
  32. animInfos = move(other.animInfos);
  33. }
  34. MotionData& MotionData::operator=(MotionData&& other)
  35. {
  36. animInfos = move(other.animInfos);
  37. return *this;
  38. }
  39. static void read(BinReader& reader, AnimInfo& animInfo)
  40. {
  41. uint32_t animId = reader.readInt();
  42. animInfo.resource = Core::get().resourceCache().get(animId);
  43. animInfo.firstFrame = reader.readInt();
  44. animInfo.lastFrame = reader.readInt();
  45. animInfo.framesPerSecond = reader.readFloat();
  46. if(animInfo.lastFrame == 0xffffffff)
  47. {
  48. animInfo.lastFrame = static_cast<uint32_t>(animInfo.resource->cast<Animation>().frames.size() - 1);
  49. }
  50. if(animInfo.framesPerSecond < 0.0f && animInfo.firstFrame < animInfo.lastFrame)
  51. {
  52. swap(animInfo.firstFrame, animInfo.lastFrame);
  53. }
  54. }
  55. void read(BinReader& reader, MotionData& animStrip)
  56. {
  57. uint8_t numAnims = reader.readByte();
  58. animStrip.animInfos.resize(numAnims);
  59. uint8_t unk1 = reader.readByte();
  60. assert(unk1 == 0 || unk1 == 1 || unk1 == 2);
  61. UNUSED(unk1);
  62. uint8_t unk2 = reader.readByte();
  63. assert(unk2 == 0 || unk2 == 1 || unk2 == 2);
  64. uint8_t unk3 = reader.readByte();
  65. assert(unk3 == 0);
  66. UNUSED(unk3);
  67. for(AnimInfo& animInfo : animStrip.animInfos)
  68. {
  69. read(reader, animInfo);
  70. }
  71. if(unk2 == 1 || unk2 == 2)
  72. {
  73. reader.readFloat();
  74. reader.readFloat();
  75. reader.readFloat();
  76. }
  77. }