/indra/llprimitive/lltextureanim.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 239 lines · 184 code · 30 blank · 25 comment · 35 complexity · 1f484393ba9bf404e98f89aa107089ef MD5 · raw file

  1. /**
  2. * @file lltextureanim.cpp
  3. * @brief LLTextureAnim base class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "lltextureanim.h"
  28. #include "message.h"
  29. #include "lldatapacker.h"
  30. const S32 TA_BLOCK_SIZE = 16;
  31. LLTextureAnim::LLTextureAnim()
  32. {
  33. reset();
  34. }
  35. LLTextureAnim::~LLTextureAnim()
  36. {
  37. }
  38. void LLTextureAnim::reset()
  39. {
  40. mMode = 0;
  41. mFace = -1;
  42. mSizeX = 4;
  43. mSizeY = 4;
  44. mStart = 0.f;
  45. mLength = 0.f;
  46. mRate = 1.f;
  47. }
  48. BOOL LLTextureAnim::equals(const LLTextureAnim &other) const
  49. {
  50. if (mMode != other.mMode)
  51. {
  52. return FALSE;
  53. }
  54. if (mFace != other.mFace)
  55. {
  56. return FALSE;
  57. }
  58. if (mSizeX != other.mSizeX)
  59. {
  60. return FALSE;
  61. }
  62. if (mSizeY != other.mSizeY)
  63. {
  64. return FALSE;
  65. }
  66. if (mStart != other.mStart)
  67. {
  68. return FALSE;
  69. }
  70. if (mLength != other.mLength)
  71. {
  72. return FALSE;
  73. }
  74. if (mRate != other.mRate)
  75. {
  76. return FALSE;
  77. }
  78. return TRUE;
  79. }
  80. void LLTextureAnim::packTAMessage(LLMessageSystem *mesgsys) const
  81. {
  82. U8 data[TA_BLOCK_SIZE];
  83. data[0] = mMode;
  84. data[1] = mFace;
  85. data[2] = mSizeX;
  86. data[3] = mSizeY;
  87. htonmemcpy(data + 4, &mStart, MVT_F32, sizeof(F32));
  88. htonmemcpy(data + 8, &mLength, MVT_F32, sizeof(F32));
  89. htonmemcpy(data + 12, &mRate, MVT_F32, sizeof(F32));
  90. mesgsys->addBinaryDataFast(_PREHASH_TextureAnim, data, TA_BLOCK_SIZE);
  91. }
  92. void LLTextureAnim::packTAMessage(LLDataPacker &dp) const
  93. {
  94. U8 data[TA_BLOCK_SIZE];
  95. data[0] = mMode;
  96. data[1] = mFace;
  97. data[2] = mSizeX;
  98. data[3] = mSizeY;
  99. htonmemcpy(data + 4, &mStart, MVT_F32, sizeof(F32));
  100. htonmemcpy(data + 8, &mLength, MVT_F32, sizeof(F32));
  101. htonmemcpy(data + 12, &mRate, MVT_F32, sizeof(F32));
  102. dp.packBinaryData(data, TA_BLOCK_SIZE, "TextureAnimation");
  103. }
  104. void LLTextureAnim::unpackTAMessage(LLMessageSystem *mesgsys, const S32 block_num)
  105. {
  106. S32 size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_TextureAnim);
  107. if (size != TA_BLOCK_SIZE)
  108. {
  109. if (size)
  110. {
  111. llwarns << "Bad size " << size << " for TA block, ignoring." << llendl;
  112. }
  113. mMode = 0;
  114. return;
  115. }
  116. U8 data[TA_BLOCK_SIZE];
  117. mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureAnim, data, TA_BLOCK_SIZE, block_num);
  118. mMode = data[0];
  119. mFace = data[1];
  120. if (mMode & LLTextureAnim::SMOOTH)
  121. {
  122. mSizeX = llmax((U8)0, data[2]);
  123. mSizeY = llmax((U8)0, data[3]);
  124. }
  125. else
  126. {
  127. mSizeX = llmax((U8)1, data[2]);
  128. mSizeY = llmax((U8)1, data[3]);
  129. }
  130. htonmemcpy(&mStart, data + 4, MVT_F32, sizeof(F32));
  131. htonmemcpy(&mLength, data + 8, MVT_F32, sizeof(F32));
  132. htonmemcpy(&mRate, data + 12, MVT_F32, sizeof(F32));
  133. }
  134. void LLTextureAnim::unpackTAMessage(LLDataPacker &dp)
  135. {
  136. S32 size;
  137. U8 data[TA_BLOCK_SIZE];
  138. dp.unpackBinaryData(data, size, "TextureAnimation");
  139. if (size != TA_BLOCK_SIZE)
  140. {
  141. if (size)
  142. {
  143. llwarns << "Bad size " << size << " for TA block, ignoring." << llendl;
  144. }
  145. mMode = 0;
  146. return;
  147. }
  148. mMode = data[0];
  149. mFace = data[1];
  150. mSizeX = data[2];
  151. mSizeY = data[3];
  152. htonmemcpy(&mStart, data + 4, MVT_F32, sizeof(F32));
  153. htonmemcpy(&mLength, data + 8, MVT_F32, sizeof(F32));
  154. htonmemcpy(&mRate, data + 12, MVT_F32, sizeof(F32));
  155. }
  156. LLSD LLTextureAnim::asLLSD() const
  157. {
  158. LLSD sd;
  159. sd["mode"] = mMode;
  160. sd["face"] = mFace;
  161. sd["sizeX"] = mSizeX;
  162. sd["sizeY"] = mSizeY;
  163. sd["start"] = mStart;
  164. sd["length"] = mLength;
  165. sd["rate"] = mRate;
  166. return sd;
  167. }
  168. bool LLTextureAnim::fromLLSD(LLSD& sd)
  169. {
  170. const char *w;
  171. w = "mode";
  172. if (sd.has(w))
  173. {
  174. mMode = (U8)sd[w].asInteger();
  175. } else goto fail;
  176. w = "face";
  177. if (sd.has(w))
  178. {
  179. mFace = (S8)sd[w].asInteger();
  180. } else goto fail;
  181. w = "sizeX";
  182. if (sd.has(w))
  183. {
  184. mSizeX = (U8)sd[w].asInteger();
  185. } else goto fail;
  186. w = "sizeY";
  187. if (sd.has(w))
  188. {
  189. mSizeY = (U8)sd[w].asInteger();
  190. } else goto fail;
  191. w = "start";
  192. if (sd.has(w))
  193. {
  194. mStart = (F32)sd[w].asReal();
  195. } else goto fail;
  196. w = "length";
  197. if (sd.has(w))
  198. {
  199. mLength = (F32)sd[w].asReal();
  200. } else goto fail;
  201. w = "rate";
  202. if (sd.has(w))
  203. {
  204. mRate = (F32)sd[w].asReal();
  205. } else goto fail;
  206. return true;
  207. fail:
  208. return false;
  209. }