00001 00032 #include "linden_common.h" 00033 00034 #include "lltextureanim.h" 00035 #include "message.h" 00036 #include "lldatapacker.h" 00037 00038 const S32 TA_BLOCK_SIZE = 16; 00039 00040 LLTextureAnim::LLTextureAnim() 00041 { 00042 reset(); 00043 } 00044 00045 00046 LLTextureAnim::~LLTextureAnim() 00047 { 00048 } 00049 00050 00051 void LLTextureAnim::reset() 00052 { 00053 mMode = 0; 00054 mFace = -1; 00055 mSizeX = 4; 00056 mSizeY = 4; 00057 mStart = 0.f; 00058 mLength = 0.f; 00059 mRate = 1.f; 00060 } 00061 00062 BOOL LLTextureAnim::equals(const LLTextureAnim &other) const 00063 { 00064 if (mMode != other.mMode) 00065 { 00066 return FALSE; 00067 } 00068 if (mFace != other.mFace) 00069 { 00070 return FALSE; 00071 } 00072 if (mSizeX != other.mSizeX) 00073 { 00074 return FALSE; 00075 } 00076 if (mSizeY != other.mSizeY) 00077 { 00078 return FALSE; 00079 } 00080 if (mStart != other.mStart) 00081 { 00082 return FALSE; 00083 } 00084 if (mLength != other.mLength) 00085 { 00086 return FALSE; 00087 } 00088 if (mRate != other.mRate) 00089 { 00090 return FALSE; 00091 } 00092 00093 return TRUE; 00094 } 00095 void LLTextureAnim::packTAMessage(LLMessageSystem *mesgsys) const 00096 { 00097 U8 data[TA_BLOCK_SIZE]; 00098 data[0] = mMode; 00099 data[1] = mFace; 00100 data[2] = mSizeX; 00101 data[3] = mSizeY; 00102 htonmemcpy(data + 4, &mStart, MVT_F32, sizeof(F32)); 00103 htonmemcpy(data + 8, &mLength, MVT_F32, sizeof(F32)); 00104 htonmemcpy(data + 12, &mRate, MVT_F32, sizeof(F32)); 00105 00106 mesgsys->addBinaryDataFast(_PREHASH_TextureAnim, data, TA_BLOCK_SIZE); 00107 } 00108 00109 00110 void LLTextureAnim::packTAMessage(LLDataPacker &dp) const 00111 { 00112 U8 data[TA_BLOCK_SIZE]; 00113 data[0] = mMode; 00114 data[1] = mFace; 00115 data[2] = mSizeX; 00116 data[3] = mSizeY; 00117 htonmemcpy(data + 4, &mStart, MVT_F32, sizeof(F32)); 00118 htonmemcpy(data + 8, &mLength, MVT_F32, sizeof(F32)); 00119 htonmemcpy(data + 12, &mRate, MVT_F32, sizeof(F32)); 00120 00121 dp.packBinaryData(data, TA_BLOCK_SIZE, "TextureAnimation"); 00122 } 00123 00124 00125 void LLTextureAnim::unpackTAMessage(LLMessageSystem *mesgsys, const S32 block_num) 00126 { 00127 S32 size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_TextureAnim); 00128 00129 if (size != TA_BLOCK_SIZE) 00130 { 00131 if (size) 00132 { 00133 llwarns << "Bad size " << size << " for TA block, ignoring." << llendl; 00134 } 00135 mMode = 0; 00136 return; 00137 } 00138 00139 U8 data[TA_BLOCK_SIZE]; 00140 mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureAnim, data, TA_BLOCK_SIZE, block_num); 00141 00142 mMode = data[0]; 00143 mFace = data[1]; 00144 if (mMode & LLTextureAnim::SMOOTH) 00145 { 00146 mSizeX = llmax((U8)0, data[2]); 00147 mSizeY = llmax((U8)0, data[3]); 00148 } 00149 else 00150 { 00151 mSizeX = llmax((U8)1, data[2]); 00152 mSizeY = llmax((U8)1, data[3]); 00153 } 00154 htonmemcpy(&mStart, data + 4, MVT_F32, sizeof(F32)); 00155 htonmemcpy(&mLength, data + 8, MVT_F32, sizeof(F32)); 00156 htonmemcpy(&mRate, data + 12, MVT_F32, sizeof(F32)); 00157 } 00158 00159 void LLTextureAnim::unpackTAMessage(LLDataPacker &dp) 00160 { 00161 S32 size; 00162 U8 data[TA_BLOCK_SIZE]; 00163 dp.unpackBinaryData(data, size, "TextureAnimation"); 00164 if (size != TA_BLOCK_SIZE) 00165 { 00166 if (size) 00167 { 00168 llwarns << "Bad size " << size << " for TA block, ignoring." << llendl; 00169 } 00170 mMode = 0; 00171 return; 00172 } 00173 00174 mMode = data[0]; 00175 mFace = data[1]; 00176 mSizeX = llmax((U8)1, data[2]); 00177 mSizeY = llmax((U8)1, data[3]); 00178 htonmemcpy(&mStart, data + 4, MVT_F32, sizeof(F32)); 00179 htonmemcpy(&mLength, data + 8, MVT_F32, sizeof(F32)); 00180 htonmemcpy(&mRate, data + 12, MVT_F32, sizeof(F32)); 00181 } 00182 00183 LLSD LLTextureAnim::asLLSD() const 00184 { 00185 LLSD sd; 00186 sd["mode"] = mMode; 00187 sd["face"] = mFace; 00188 sd["sizeX"] = mSizeX; 00189 sd["sizeY"] = mSizeY; 00190 sd["start"] = mStart; 00191 sd["length"] = mLength; 00192 sd["rate"] = mRate; 00193 return sd; 00194 } 00195 00196 bool LLTextureAnim::fromLLSD(LLSD& sd) 00197 { 00198 const char *w; 00199 w = "mode"; 00200 if (sd.has(w)) 00201 { 00202 mMode = (U8)sd[w].asInteger(); 00203 } else goto fail; 00204 00205 w = "face"; 00206 if (sd.has(w)) 00207 { 00208 mFace = (S8)sd[w].asInteger(); 00209 } else goto fail; 00210 00211 w = "sizeX"; 00212 if (sd.has(w)) 00213 { 00214 mSizeX = (U8)sd[w].asInteger(); 00215 } else goto fail; 00216 00217 w = "sizeY"; 00218 if (sd.has(w)) 00219 { 00220 mSizeY = (U8)sd[w].asInteger(); 00221 } else goto fail; 00222 00223 w = "start"; 00224 if (sd.has(w)) 00225 { 00226 mStart = (F32)sd[w].asReal(); 00227 } else goto fail; 00228 00229 w = "length"; 00230 if (sd.has(w)) 00231 { 00232 mLength = (F32)sd[w].asReal(); 00233 } else goto fail; 00234 00235 w = "rate"; 00236 if (sd.has(w)) 00237 { 00238 mRate = (F32)sd[w].asReal(); 00239 } else goto fail; 00240 00241 return true; 00242 fail: 00243 return false; 00244 }