PageRenderTime 407ms CodeModel.GetById 160ms app.highlight 64ms RepoModel.GetById 180ms app.codeStats 0ms

/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
 27#include "linden_common.h"
 28
 29#include "lltextureanim.h"
 30#include "message.h"
 31#include "lldatapacker.h"
 32
 33const S32 TA_BLOCK_SIZE = 16;
 34
 35LLTextureAnim::LLTextureAnim()
 36{
 37	reset();
 38}
 39
 40
 41LLTextureAnim::~LLTextureAnim()
 42{
 43}
 44
 45
 46void LLTextureAnim::reset()
 47{
 48	mMode = 0;
 49	mFace = -1;
 50	mSizeX = 4;
 51	mSizeY = 4;
 52	mStart = 0.f;
 53	mLength = 0.f;
 54	mRate = 1.f;
 55}
 56
 57BOOL LLTextureAnim::equals(const LLTextureAnim &other) const
 58{
 59	if (mMode != other.mMode)
 60	{
 61		return FALSE;
 62	}
 63	if (mFace != other.mFace)
 64	{
 65		return FALSE;
 66	}
 67	if (mSizeX != other.mSizeX)
 68	{
 69		return FALSE;
 70	}
 71	if (mSizeY != other.mSizeY)
 72	{
 73		return FALSE;
 74	}
 75	if (mStart != other.mStart)
 76	{
 77		return FALSE;
 78	}
 79	if (mLength != other.mLength)
 80	{
 81		return FALSE;
 82	}
 83	if (mRate != other.mRate)
 84	{
 85		return FALSE;
 86	}
 87
 88	return TRUE;
 89}
 90void LLTextureAnim::packTAMessage(LLMessageSystem *mesgsys) const
 91{
 92	U8 data[TA_BLOCK_SIZE];
 93	data[0] = mMode;
 94	data[1] = mFace;
 95	data[2] = mSizeX;
 96	data[3] = mSizeY;
 97	htonmemcpy(data + 4, &mStart, MVT_F32, sizeof(F32));
 98	htonmemcpy(data + 8, &mLength, MVT_F32, sizeof(F32));
 99	htonmemcpy(data + 12, &mRate, MVT_F32, sizeof(F32));
100
101	mesgsys->addBinaryDataFast(_PREHASH_TextureAnim, data, TA_BLOCK_SIZE);
102}
103
104
105void LLTextureAnim::packTAMessage(LLDataPacker &dp) const
106{
107	U8 data[TA_BLOCK_SIZE];
108	data[0] = mMode;
109	data[1] = mFace;
110	data[2] = mSizeX;
111	data[3] = mSizeY;
112	htonmemcpy(data + 4, &mStart, MVT_F32, sizeof(F32));
113	htonmemcpy(data + 8, &mLength, MVT_F32, sizeof(F32));
114	htonmemcpy(data + 12, &mRate, MVT_F32, sizeof(F32));
115
116	dp.packBinaryData(data, TA_BLOCK_SIZE, "TextureAnimation");
117}
118
119
120void LLTextureAnim::unpackTAMessage(LLMessageSystem *mesgsys, const S32 block_num)
121{
122	S32 size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_TextureAnim);
123
124	if (size != TA_BLOCK_SIZE)
125	{
126		if (size)
127		{
128			llwarns << "Bad size " << size << " for TA block, ignoring." << llendl;
129		}
130		mMode = 0;
131		return;
132	}
133
134	U8 data[TA_BLOCK_SIZE];
135	mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureAnim, data, TA_BLOCK_SIZE, block_num);
136
137	mMode = data[0];
138	mFace = data[1];
139	if (mMode & LLTextureAnim::SMOOTH)
140	{
141		mSizeX = llmax((U8)0, data[2]);
142		mSizeY = llmax((U8)0, data[3]);
143	}
144	else
145	{
146		mSizeX = llmax((U8)1, data[2]);
147		mSizeY = llmax((U8)1, data[3]);
148	}
149	htonmemcpy(&mStart, data + 4, MVT_F32, sizeof(F32));
150	htonmemcpy(&mLength, data + 8, MVT_F32, sizeof(F32));
151	htonmemcpy(&mRate, data + 12, MVT_F32, sizeof(F32));
152}
153
154void LLTextureAnim::unpackTAMessage(LLDataPacker &dp)
155{
156	S32 size;
157	U8 data[TA_BLOCK_SIZE];
158	dp.unpackBinaryData(data, size, "TextureAnimation");
159	if (size != TA_BLOCK_SIZE)
160	{
161		if (size)
162		{
163			llwarns << "Bad size " << size << " for TA block, ignoring." << llendl;
164		}
165		mMode = 0;
166		return;
167	}
168
169	mMode = data[0];
170	mFace = data[1];
171	mSizeX = data[2];
172	mSizeY = data[3];
173	htonmemcpy(&mStart, data + 4, MVT_F32, sizeof(F32));
174	htonmemcpy(&mLength, data + 8, MVT_F32, sizeof(F32));
175	htonmemcpy(&mRate, data + 12, MVT_F32, sizeof(F32));
176}
177
178LLSD LLTextureAnim::asLLSD() const
179{
180	LLSD sd;
181	sd["mode"] = mMode;
182	sd["face"] = mFace;
183	sd["sizeX"] = mSizeX;
184	sd["sizeY"] = mSizeY;
185	sd["start"] = mStart;
186	sd["length"] = mLength;
187	sd["rate"] = mRate;
188	return sd;
189}
190
191bool LLTextureAnim::fromLLSD(LLSD& sd)
192{
193	const char *w;
194	w = "mode";
195	if (sd.has(w))
196	{
197		mMode =	(U8)sd[w].asInteger();
198	} else goto fail;
199
200	w = "face";
201	if (sd.has(w))
202	{
203		mFace =	(S8)sd[w].asInteger();
204	} else goto fail;
205
206	w = "sizeX";
207	if (sd.has(w))
208	{
209		mSizeX = (U8)sd[w].asInteger();
210	} else goto fail;
211
212	w = "sizeY";
213	if (sd.has(w))
214	{
215		mSizeY = (U8)sd[w].asInteger();
216	} else goto fail;
217
218	w = "start";
219	if (sd.has(w))
220	{
221		mStart = (F32)sd[w].asReal();
222	} else goto fail;
223
224	w = "length";
225	if (sd.has(w))
226	{
227		mLength = (F32)sd[w].asReal();
228	} else goto fail;
229
230	w = "rate";
231	if (sd.has(w))
232	{
233		mRate =	(F32)sd[w].asReal();
234	} else goto fail;
235
236	return true;
237fail:
238	return false;
239}