interiorResObjects.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "interior/interiorResObjects.h"
  23. #include "core/stream/stream.h"
  24. #include "math/mathIO.h"
  25. //--------------------------------------------------------------------------
  26. //--------------------------------------
  27. //
  28. void InteriorDict::read(Stream &stream)
  29. {
  30. U32 sz;
  31. stream.read(&sz);
  32. setSize(sz);
  33. for(U32 i = 0; i < sz; i++)
  34. {
  35. InteriorDictEntry e;
  36. stream.readString(e.name);
  37. stream.readString(e.value);
  38. (*this)[i] = e;
  39. }
  40. }
  41. void InteriorDict::write(Stream &stream) const
  42. {
  43. U32 sz = size();
  44. stream.write(sz);
  45. for(U32 i = 0; i < sz; i++)
  46. {
  47. stream.writeString((*this)[i].name);
  48. stream.writeString((*this)[i].value);
  49. }
  50. }
  51. bool InteriorResTrigger::read(Stream& stream)
  52. {
  53. U32 i, size;
  54. stream.readString(mName);
  55. mDataBlock = stream.readSTString();
  56. mDictionary.read(stream);
  57. // Read the polyhedron
  58. stream.read(&size);
  59. mPolyhedron.pointList.setSize(size);
  60. for (i = 0; i < mPolyhedron.pointList.size(); i++)
  61. mathRead(stream, &mPolyhedron.pointList[i]);
  62. stream.read(&size);
  63. mPolyhedron.planeList.setSize(size);
  64. for (i = 0; i < mPolyhedron.planeList.size(); i++)
  65. mathRead(stream, &mPolyhedron.planeList[i]);
  66. stream.read(&size);
  67. mPolyhedron.edgeList.setSize(size);
  68. for (i = 0; i < mPolyhedron.edgeList.size(); i++) {
  69. Polyhedron::Edge& rEdge = mPolyhedron.edgeList[i];
  70. stream.read(&rEdge.face[0]);
  71. stream.read(&rEdge.face[1]);
  72. stream.read(&rEdge.vertex[0]);
  73. stream.read(&rEdge.vertex[1]);
  74. }
  75. // And the offset
  76. mathRead(stream, &mOffset);
  77. return (stream.getStatus() == Stream::Ok);
  78. }
  79. bool InteriorResTrigger::write(Stream& stream) const
  80. {
  81. U32 i;
  82. stream.writeString(mName);
  83. stream.writeString(mDataBlock);
  84. mDictionary.write(stream);
  85. // Write the polyhedron
  86. stream.write(mPolyhedron.pointList.size());
  87. for (i = 0; i < mPolyhedron.pointList.size(); i++)
  88. mathWrite(stream, mPolyhedron.pointList[i]);
  89. stream.write(mPolyhedron.planeList.size());
  90. for (i = 0; i < mPolyhedron.planeList.size(); i++)
  91. mathWrite(stream, mPolyhedron.planeList[i]);
  92. stream.write(mPolyhedron.edgeList.size());
  93. for (i = 0; i < mPolyhedron.edgeList.size(); i++) {
  94. const Polyhedron::Edge& rEdge = mPolyhedron.edgeList[i];
  95. stream.write(rEdge.face[0]);
  96. stream.write(rEdge.face[1]);
  97. stream.write(rEdge.vertex[0]);
  98. stream.write(rEdge.vertex[1]);
  99. }
  100. // And the offset
  101. mathWrite(stream, mOffset);
  102. return (stream.getStatus() == Stream::Ok);
  103. }
  104. InteriorPathFollower::InteriorPathFollower()
  105. {
  106. VECTOR_SET_ASSOCIATION( mTriggerIds );
  107. VECTOR_SET_ASSOCIATION( mWayPoints );
  108. mName = "";
  109. mPathIndex = 0;
  110. mOffset.set(0, 0, 0);
  111. }
  112. InteriorPathFollower::~InteriorPathFollower()
  113. {
  114. }
  115. bool InteriorPathFollower::read(Stream& stream)
  116. {
  117. mName = stream.readSTString();
  118. mDataBlock = stream.readSTString();
  119. stream.read(&mInteriorResIndex);
  120. mathRead(stream, &mOffset);
  121. mDictionary.read(stream);
  122. U32 numTriggers;
  123. stream.read(&numTriggers);
  124. mTriggerIds.setSize(numTriggers);
  125. for (U32 i = 0; i < mTriggerIds.size(); i++)
  126. stream.read(&mTriggerIds[i]);
  127. U32 numWayPoints;
  128. stream.read(&numWayPoints);
  129. mWayPoints.setSize(numWayPoints);
  130. for(U32 i = 0; i < numWayPoints; i++)
  131. {
  132. mathRead(stream, &mWayPoints[i].pos);
  133. mathRead(stream, &mWayPoints[i].rot);
  134. stream.read(&mWayPoints[i].msToNext);
  135. stream.read(&mWayPoints[i].smoothingType);
  136. }
  137. stream.read(&mTotalMS);
  138. return (stream.getStatus() == Stream::Ok);
  139. }
  140. bool InteriorPathFollower::write(Stream& stream) const
  141. {
  142. stream.writeString(mName);
  143. stream.writeString(mDataBlock);
  144. stream.write(mInteriorResIndex);
  145. mathWrite(stream, mOffset);
  146. mDictionary.write(stream);
  147. stream.write(mTriggerIds.size());
  148. for (U32 i = 0; i < mTriggerIds.size(); i++)
  149. stream.write(mTriggerIds[i]);
  150. stream.write(U32(mWayPoints.size()));
  151. for (U32 i = 0; i < mWayPoints.size(); i++) {
  152. mathWrite(stream, mWayPoints[i].pos);
  153. mathWrite(stream, mWayPoints[i].rot);
  154. stream.write(mWayPoints[i].msToNext);
  155. stream.write(mWayPoints[i].smoothingType);
  156. }
  157. stream.write(mTotalMS);
  158. return (stream.getStatus() == Stream::Ok);
  159. }
  160. AISpecialNode::AISpecialNode()
  161. {
  162. mName = "";
  163. mPos.set(0, 0, 0);
  164. }
  165. AISpecialNode::~AISpecialNode()
  166. {
  167. }
  168. bool AISpecialNode::read(Stream& stream)
  169. {
  170. mName = stream.readSTString();
  171. mathRead(stream, &mPos);
  172. return (stream.getStatus() == Stream::Ok);
  173. }
  174. bool AISpecialNode::write(Stream& stream) const
  175. {
  176. stream.writeString(mName);
  177. mathWrite(stream, mPos);
  178. return (stream.getStatus() == Stream::Ok);
  179. }
  180. ItrGameEntity::ItrGameEntity()
  181. {
  182. mDataBlock = "";
  183. mGameClass = "";
  184. mPos.set(0, 0, 0);
  185. }
  186. ItrGameEntity::~ItrGameEntity()
  187. {
  188. }
  189. bool ItrGameEntity::read(Stream& stream)
  190. {
  191. mDataBlock = stream.readSTString();
  192. mGameClass = stream.readSTString();
  193. mathRead(stream, &mPos);
  194. mDictionary.read(stream);
  195. return (stream.getStatus() == Stream::Ok);
  196. }
  197. bool ItrGameEntity::write(Stream& stream) const
  198. {
  199. stream.writeString(mDataBlock);
  200. stream.writeString(mGameClass);
  201. mathWrite(stream, mPos);
  202. mDictionary.write(stream);
  203. return (stream.getStatus() == Stream::Ok);
  204. }