lltextureanim.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * @file lltextureanim.cpp
  3. * @brief LLTextureAnim base class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "linden_common.h"
  33. #include "lltextureanim.h"
  34. #include "llmessage.h"
  35. #include "lldatapacker.h"
  36. constexpr S32 TA_BLOCK_SIZE = 16;
  37. LLTextureAnim::LLTextureAnim()
  38. {
  39. reset();
  40. }
  41. void LLTextureAnim::reset()
  42. {
  43. mMode = 0;
  44. mFace = -1;
  45. mSizeX = 4;
  46. mSizeY = 4;
  47. mStart = 0.f;
  48. mLength = 0.f;
  49. mRate = 1.f;
  50. }
  51. void LLTextureAnim::packTAMessage(LLMessageSystem* mesgsys) const
  52. {
  53. U8 data[TA_BLOCK_SIZE];
  54. data[0] = mMode;
  55. data[1] = mFace;
  56. data[2] = mSizeX;
  57. data[3] = mSizeY;
  58. htonmemcpy(data + 4, &mStart, MVT_F32, sizeof(F32));
  59. htonmemcpy(data + 8, &mLength, MVT_F32, sizeof(F32));
  60. htonmemcpy(data + 12, &mRate, MVT_F32, sizeof(F32));
  61. mesgsys->addBinaryDataFast(_PREHASH_TextureAnim, data, TA_BLOCK_SIZE);
  62. }
  63. void LLTextureAnim::packTAMessage(LLDataPacker& dp) const
  64. {
  65. U8 data[TA_BLOCK_SIZE];
  66. data[0] = mMode;
  67. data[1] = mFace;
  68. data[2] = mSizeX;
  69. data[3] = mSizeY;
  70. htonmemcpy(data + 4, &mStart, MVT_F32, sizeof(F32));
  71. htonmemcpy(data + 8, &mLength, MVT_F32, sizeof(F32));
  72. htonmemcpy(data + 12, &mRate, MVT_F32, sizeof(F32));
  73. dp.packBinaryData(data, TA_BLOCK_SIZE, "TextureAnimation");
  74. }
  75. void LLTextureAnim::unpackTAMessage(LLMessageSystem* mesgsys, S32 block_num)
  76. {
  77. S32 size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num,
  78. _PREHASH_TextureAnim);
  79. if (size != TA_BLOCK_SIZE)
  80. {
  81. if (size)
  82. {
  83. llwarns << "Bad size " << size << " for TA block, ignoring."
  84. << llendl;
  85. }
  86. mMode = 0;
  87. return;
  88. }
  89. U8 data[TA_BLOCK_SIZE];
  90. mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureAnim, data,
  91. TA_BLOCK_SIZE, block_num);
  92. mMode = data[0];
  93. mFace = data[1];
  94. if (mMode & LLTextureAnim::SMOOTH)
  95. {
  96. mSizeX = llmax((U8)0, data[2]);
  97. mSizeY = llmax((U8)0, data[3]);
  98. }
  99. else
  100. {
  101. mSizeX = llmax((U8)1, data[2]);
  102. mSizeY = llmax((U8)1, data[3]);
  103. }
  104. htonmemcpy(&mStart, data + 4, MVT_F32, sizeof(F32));
  105. htonmemcpy(&mLength, data + 8, MVT_F32, sizeof(F32));
  106. htonmemcpy(&mRate, data + 12, MVT_F32, sizeof(F32));
  107. }
  108. void LLTextureAnim::unpackTAMessage(LLDataPacker& dp)
  109. {
  110. S32 size;
  111. U8 data[TA_BLOCK_SIZE];
  112. dp.unpackBinaryData(data, size, "TextureAnimation");
  113. if (size != TA_BLOCK_SIZE)
  114. {
  115. if (size)
  116. {
  117. llwarns << "Bad size " << size << " for TA block, ignoring."
  118. << llendl;
  119. }
  120. mMode = 0;
  121. return;
  122. }
  123. mMode = data[0];
  124. mFace = data[1];
  125. mSizeX = data[2];
  126. mSizeY = data[3];
  127. htonmemcpy(&mStart, data + 4, MVT_F32, sizeof(F32));
  128. htonmemcpy(&mLength, data + 8, MVT_F32, sizeof(F32));
  129. htonmemcpy(&mRate, data + 12, MVT_F32, sizeof(F32));
  130. }
  131. LLSD LLTextureAnim::asLLSD() const
  132. {
  133. LLSD sd;
  134. sd["mode"] = mMode;
  135. sd["face"] = mFace;
  136. sd["sizeX"] = mSizeX;
  137. sd["sizeY"] = mSizeY;
  138. sd["start"] = mStart;
  139. sd["length"] = mLength;
  140. sd["rate"] = mRate;
  141. return sd;
  142. }
  143. bool LLTextureAnim::fromLLSD(LLSD& sd)
  144. {
  145. const char* w;
  146. w = "mode";
  147. if (sd.has(w))
  148. {
  149. mMode = (U8)sd[w].asInteger();
  150. }
  151. else
  152. {
  153. return false;
  154. }
  155. w = "face";
  156. if (sd.has(w))
  157. {
  158. mFace = (S8)sd[w].asInteger();
  159. }
  160. else
  161. {
  162. return false;
  163. }
  164. w = "sizeX";
  165. if (sd.has(w))
  166. {
  167. mSizeX = (U8)sd[w].asInteger();
  168. }
  169. else
  170. {
  171. return false;
  172. }
  173. w = "sizeY";
  174. if (sd.has(w))
  175. {
  176. mSizeY = (U8)sd[w].asInteger();
  177. }
  178. else
  179. {
  180. return false;
  181. }
  182. w = "start";
  183. if (sd.has(w))
  184. {
  185. mStart = (F32)sd[w].asReal();
  186. }
  187. else
  188. {
  189. return false;
  190. }
  191. w = "length";
  192. if (sd.has(w))
  193. {
  194. mLength = (F32)sd[w].asReal();
  195. }
  196. else
  197. {
  198. return false;
  199. }
  200. w = "rate";
  201. if (sd.has(w))
  202. {
  203. mRate = (F32)sd[w].asReal();
  204. }
  205. else
  206. {
  207. return false;
  208. }
  209. return true;
  210. }