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

Setup.cpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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/Setup.h"
  19. #include "physics/CylSphere.h"
  20. #include "physics/Sphere.h"
  21. #include "BinReader.h"
  22. #include "Core.h"
  23. #include "ResourceCache.h"
  24. #include "util.h"
  25. enum SetupFlag
  26. {
  27. kHasParentIndex = 0x1,
  28. kHasDefaultScale = 0x2,
  29. kAllowFreeHeading = 0x4,
  30. kHasPhysicsBSP = 0x8
  31. };
  32. Setup::Setup(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
  33. {
  34. BinReader reader(data, size);
  35. uint32_t resourceId = reader.readInt();
  36. assert(resourceId == id);
  37. UNUSED(resourceId);
  38. uint32_t flags = reader.readInt();
  39. assert(flags <= 0xF);
  40. uint32_t numModels = reader.readInt();
  41. models.reserve(numModels);
  42. for(uint32_t i = 0; i < numModels; i++)
  43. {
  44. uint32_t modelId = reader.readInt();
  45. models.emplace_back(Core::get().resourceCache().get(modelId));
  46. }
  47. parents.reserve(numModels);
  48. for(uint32_t i = 0; i < numModels; i++)
  49. {
  50. uint32_t parent = 0xFFFFFFFF;
  51. if(flags & kHasParentIndex)
  52. {
  53. parent = reader.readInt();
  54. }
  55. parents.push_back(parent);
  56. }
  57. scales.reserve(numModels);
  58. for(uint32_t i = 0; i < numModels; i++)
  59. {
  60. glm::vec3 scale{1.0, 1.0, 1.0};
  61. if(flags & kHasDefaultScale)
  62. {
  63. read(reader, scale);
  64. }
  65. scales.push_back(scale);
  66. }
  67. uint32_t numHoldingLocations = reader.readInt();
  68. for(uint32_t i = 0; i < numHoldingLocations; i++)
  69. {
  70. /*key*/ reader.readInt();
  71. /*partIndex*/ reader.readInt();
  72. Location holdingLocation;
  73. read(reader, holdingLocation);
  74. }
  75. uint32_t numConnectionPoints = reader.readInt();
  76. assert(numConnectionPoints == 0);
  77. for(uint32_t i = 0; i < numConnectionPoints; i++)
  78. {
  79. /*key*/ reader.readInt();
  80. /*partIndex*/ reader.readInt();
  81. Location connectionPoint;
  82. read(reader, connectionPoint);
  83. }
  84. uint32_t numPlacementFrames = reader.readInt();
  85. placementFrames.resize(numPlacementFrames);
  86. for(AnimationFrame& frame : placementFrames)
  87. {
  88. /*key*/ reader.readInt();
  89. read(reader, frame, numModels);
  90. }
  91. uint32_t numCylSpheres = reader.readInt();
  92. for(uint32_t i = 0; i < numCylSpheres; i++)
  93. {
  94. CylSphere cylSphere;
  95. read(reader, cylSphere);
  96. }
  97. uint32_t numSpheres = reader.readInt();
  98. for(uint32_t i = 0; i < numSpheres; i++)
  99. {
  100. Sphere sphere;
  101. read(reader, sphere);
  102. }
  103. /*height*/ reader.readFloat();
  104. /*radius*/ reader.readFloat();
  105. /*stepUpHeight*/ reader.readFloat();
  106. /*stepDownHeight*/ reader.readFloat();
  107. Sphere sortingSphere;
  108. read(reader, sortingSphere);
  109. Sphere selectionSphere;
  110. read(reader, selectionSphere);
  111. uint32_t numLights = reader.readInt();
  112. for(uint32_t i = 0; i < numLights; i++)
  113. {
  114. uint32_t lightIndex = reader.readInt();
  115. assert(lightIndex == i);
  116. UNUSED(lightIndex);
  117. Location lightLocation;
  118. read(reader, lightLocation);
  119. /*color*/ reader.readInt();
  120. /*intensity*/ reader.readFloat();
  121. /*falloff*/ reader.readFloat();
  122. /*coneAngle*/ reader.readFloat(); // junk 0xcdcdcdcd most of the time
  123. }
  124. ResourceCache& cache = Core::get().resourceCache();
  125. uint32_t defaultAnimId = reader.readInt();
  126. if(defaultAnimId)
  127. {
  128. defaultAnimation = cache.get(defaultAnimId);
  129. }
  130. uint32_t defaultPhysScriptId = reader.readInt();
  131. if(defaultPhysScriptId)
  132. {
  133. defaultPhysScript = cache.get(defaultPhysScriptId);
  134. }
  135. uint32_t defaultMotionTableId = reader.readInt();
  136. if(defaultMotionTableId)
  137. {
  138. defaultMotionTable = cache.get(defaultMotionTableId);
  139. }
  140. uint32_t defaultSoundTableId = reader.readInt();
  141. if(defaultSoundTableId)
  142. {
  143. defaultSoundTable = cache.get(defaultSoundTableId);
  144. }
  145. uint32_t defaultPhysScriptTableId = reader.readInt();
  146. if(defaultPhysScriptTableId)
  147. {
  148. defaultPhysScriptTable = cache.get(defaultPhysScriptTableId);
  149. }
  150. assert(reader.remaining() == 0);
  151. }