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

PhysicsDesc.cpp 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 "PhysicsDesc.h"
  19. #include "BinReader.h"
  20. #include "Core.h"
  21. #include "ResourceCache.h"
  22. #include "util.h"
  23. enum PhysicsDescFlags
  24. {
  25. kCSetup = 0x00000001,
  26. kMTable = 0x00000002,
  27. kVelocity = 0x00000004,
  28. kAcceleration = 0x00000008,
  29. kOmega = 0x00000010,
  30. kParent = 0x00000020,
  31. kChildren = 0x00000040,
  32. kObjScale = 0x00000080,
  33. kFriction = 0x00000100,
  34. kElasticity = 0x00000200,
  35. kSTable = 0x00000800,
  36. kPETable = 0x00001000,
  37. kDefaultScript = 0x00002000,
  38. kDefaultScriptIntensity = 0x00004000,
  39. kPosition = 0x00008000,
  40. kMovement = 0x00010000,
  41. kAnimFrameId = 0x00020000,
  42. kTranslucency = 0x00040000
  43. };
  44. PhysicsDesc::Relation::Relation() : objectId(0), slot(0)
  45. {}
  46. PhysicsDesc::PhysicsDesc() : animFrameId(0)
  47. {}
  48. static void read(BinReader& reader, PhysicsDesc::Relation& relation)
  49. {
  50. relation.objectId = reader.readInt();
  51. relation.slot = reader.readInt();
  52. }
  53. void read(BinReader& reader, PhysicsDesc& physicsDesc)
  54. {
  55. uint32_t flags = reader.readInt();
  56. /*unknown*/ reader.readInt();
  57. if(flags & kMovement)
  58. {
  59. uint32_t movementSize = reader.readInt();
  60. reader.readRaw(movementSize);
  61. /*autonomousMovement*/ reader.readInt();
  62. }
  63. if(flags & kAnimFrameId)
  64. {
  65. physicsDesc.animFrameId = reader.readInt();
  66. }
  67. if(flags & kPosition)
  68. {
  69. physicsDesc.landcell = LandcellId(reader.readInt());
  70. read(reader, physicsDesc.location.position);
  71. read(reader, physicsDesc.location.rotation);
  72. }
  73. if(flags & kMTable)
  74. {
  75. physicsDesc.motionTable = Core::get().resourceCache().get(reader.readInt());
  76. }
  77. if(flags & kSTable)
  78. {
  79. physicsDesc.soundTable = Core::get().resourceCache().get(reader.readInt());
  80. }
  81. if(flags & kPETable)
  82. {
  83. physicsDesc.particleEmitterTable = Core::get().resourceCache().get(reader.readInt());
  84. }
  85. if(flags & kCSetup)
  86. {
  87. physicsDesc.setup = Core::get().resourceCache().get(reader.readInt());
  88. }
  89. if(flags & kParent)
  90. {
  91. read(reader, physicsDesc.parent);
  92. }
  93. if(flags & kChildren)
  94. {
  95. physicsDesc.children.resize(reader.readInt());
  96. for(PhysicsDesc::Relation& child : physicsDesc.children)
  97. {
  98. read(reader, child);
  99. }
  100. }
  101. if(flags & kObjScale)
  102. {
  103. physicsDesc.scale = reader.readFloat();
  104. }
  105. if(flags & kFriction)
  106. {
  107. physicsDesc.friction = reader.readFloat();
  108. }
  109. if(flags & kElasticity)
  110. {
  111. physicsDesc.elasticity = reader.readFloat();
  112. }
  113. if(flags & kTranslucency)
  114. {
  115. physicsDesc.translucency = reader.readFloat();
  116. }
  117. if(flags & kVelocity)
  118. {
  119. read(reader, physicsDesc.velocity);
  120. }
  121. if(flags & kAcceleration)
  122. {
  123. read(reader, physicsDesc.acceleration);
  124. }
  125. if(flags & kOmega)
  126. {
  127. read(reader, physicsDesc.angularVelocity);
  128. }
  129. if(flags & kDefaultScript)
  130. {
  131. physicsDesc.defaultScript = Core::get().resourceCache().get(reader.readInt());
  132. }
  133. if(flags & kDefaultScriptIntensity)
  134. {
  135. physicsDesc.defaultScriptIntensity = reader.readFloat();
  136. }
  137. /*timestamps*/ reader.readRaw(sizeof(uint16_t) * 9);
  138. reader.align();
  139. }