diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/lscript/lscript_library.h | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/lscript/lscript_library.h')
-rw-r--r-- | linden/indra/lscript/lscript_library.h | 401 |
1 files changed, 401 insertions, 0 deletions
diff --git a/linden/indra/lscript/lscript_library.h b/linden/indra/lscript/lscript_library.h new file mode 100644 index 0000000..300cbb6 --- /dev/null +++ b/linden/indra/lscript/lscript_library.h | |||
@@ -0,0 +1,401 @@ | |||
1 | /** | ||
2 | * @file lscript_library.h | ||
3 | * @brief External library interface | ||
4 | * | ||
5 | * Copyright (c) 2002-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #ifndef LL_LSCRIPT_LIBRARY_H | ||
29 | #define LL_LSCRIPT_LIBRARY_H | ||
30 | |||
31 | #include "lscript_byteformat.h" | ||
32 | #include "v3math.h" | ||
33 | #include "llquaternion.h" | ||
34 | #include "lluuid.h" | ||
35 | #include "lscript_byteconvert.h" | ||
36 | #include <stdio.h> | ||
37 | |||
38 | class LLScriptLibData; | ||
39 | |||
40 | class LLScriptLibraryFunction | ||
41 | { | ||
42 | public: | ||
43 | LLScriptLibraryFunction(F32 eu, F32 st, void (*exec_func)(LLScriptLibData *, LLScriptLibData *, const LLUUID &), char *name, char *ret_type, char *args, char *desc, BOOL god_only = FALSE); | ||
44 | ~LLScriptLibraryFunction(); | ||
45 | |||
46 | F32 mEnergyUse; | ||
47 | F32 mSleepTime; | ||
48 | void (*mExecFunc)(LLScriptLibData *, LLScriptLibData *, const LLUUID &); | ||
49 | char *mName; | ||
50 | char *mReturnType; | ||
51 | char *mArgs; | ||
52 | char *mDesc; | ||
53 | BOOL mGodOnly; | ||
54 | }; | ||
55 | |||
56 | class LLScriptLibrary | ||
57 | { | ||
58 | public: | ||
59 | LLScriptLibrary(); | ||
60 | ~LLScriptLibrary(); | ||
61 | |||
62 | void init(); | ||
63 | |||
64 | void addFunction(LLScriptLibraryFunction *func); | ||
65 | void assignExec(char *name, void (*exec_func)(LLScriptLibData *, LLScriptLibData *, const LLUUID &)); | ||
66 | |||
67 | S32 mNextNumber; | ||
68 | LLScriptLibraryFunction **mFunctions; | ||
69 | }; | ||
70 | |||
71 | extern LLScriptLibrary gScriptLibrary; | ||
72 | |||
73 | class LLScriptLibData | ||
74 | { | ||
75 | public: | ||
76 | // TODO: Change this to a union | ||
77 | LSCRIPTType mType; | ||
78 | S32 mInteger; | ||
79 | F32 mFP; | ||
80 | char *mKey; | ||
81 | char *mString; | ||
82 | LLVector3 mVec; | ||
83 | LLQuaternion mQuat; | ||
84 | LLScriptLibData *mListp; | ||
85 | |||
86 | friend const bool operator<=(const LLScriptLibData &a, const LLScriptLibData &b) | ||
87 | { | ||
88 | if (a.mType == b.mType) | ||
89 | { | ||
90 | if (a.mType == LST_INTEGER) | ||
91 | { | ||
92 | return a.mInteger <= b.mInteger; | ||
93 | } | ||
94 | if (a.mType == LST_FLOATINGPOINT) | ||
95 | { | ||
96 | return a.mFP <= b.mFP; | ||
97 | } | ||
98 | if (a.mType == LST_STRING) | ||
99 | { | ||
100 | return strcmp(a.mString, b.mString) <= 0; | ||
101 | } | ||
102 | if (a.mType == LST_KEY) | ||
103 | { | ||
104 | return strcmp(a.mKey, b.mKey) <= 0; | ||
105 | } | ||
106 | if (a.mType == LST_VECTOR) | ||
107 | { | ||
108 | return a.mVec.magVecSquared() <= b.mVec.magVecSquared(); | ||
109 | } | ||
110 | } | ||
111 | return TRUE; | ||
112 | } | ||
113 | |||
114 | friend const bool operator==(const LLScriptLibData &a, const LLScriptLibData &b) | ||
115 | { | ||
116 | if (a.mType == b.mType) | ||
117 | { | ||
118 | if (a.mType == LST_INTEGER) | ||
119 | { | ||
120 | return a.mInteger == b.mInteger; | ||
121 | } | ||
122 | if (a.mType == LST_FLOATINGPOINT) | ||
123 | { | ||
124 | return a.mFP == b.mFP; | ||
125 | } | ||
126 | if (a.mType == LST_STRING) | ||
127 | { | ||
128 | return !strcmp(a.mString, b.mString); | ||
129 | } | ||
130 | if (a.mType == LST_KEY) | ||
131 | { | ||
132 | return !strcmp(a.mKey, b.mKey); | ||
133 | } | ||
134 | if (a.mType == LST_VECTOR) | ||
135 | { | ||
136 | return a.mVec == b.mVec; | ||
137 | } | ||
138 | if (a.mType == LST_QUATERNION) | ||
139 | { | ||
140 | return a.mQuat == b.mQuat; | ||
141 | } | ||
142 | } | ||
143 | return FALSE; | ||
144 | } | ||
145 | |||
146 | S32 getListLength() | ||
147 | { | ||
148 | LLScriptLibData *data = this; | ||
149 | S32 retval = 0; | ||
150 | while (data->mListp) | ||
151 | { | ||
152 | retval++; | ||
153 | data = data->mListp; | ||
154 | } | ||
155 | return retval; | ||
156 | } | ||
157 | |||
158 | BOOL checkForMultipleLists() | ||
159 | { | ||
160 | LLScriptLibData *data = this; | ||
161 | while (data->mListp) | ||
162 | { | ||
163 | data = data->mListp; | ||
164 | if (data->mType == LST_LIST) | ||
165 | return TRUE; | ||
166 | } | ||
167 | return FALSE; | ||
168 | } | ||
169 | |||
170 | S32 getSavedSize() | ||
171 | { | ||
172 | S32 size = 0; | ||
173 | // mType | ||
174 | size += 4; | ||
175 | |||
176 | switch(mType) | ||
177 | { | ||
178 | case LST_INTEGER: | ||
179 | size += 4; | ||
180 | break; | ||
181 | case LST_FLOATINGPOINT: | ||
182 | size += 4; | ||
183 | break; | ||
184 | case LST_KEY: | ||
185 | size += (S32)strlen(mKey) + 1; | ||
186 | break; | ||
187 | case LST_STRING: | ||
188 | size += (S32)strlen(mString) + 1; | ||
189 | break; | ||
190 | case LST_LIST: | ||
191 | break; | ||
192 | case LST_VECTOR: | ||
193 | size += 12; | ||
194 | break; | ||
195 | case LST_QUATERNION: | ||
196 | size += 16; | ||
197 | break; | ||
198 | default: | ||
199 | break; | ||
200 | } | ||
201 | return size; | ||
202 | } | ||
203 | |||
204 | S32 write2bytestream(U8 *dest) | ||
205 | { | ||
206 | S32 offset = 0; | ||
207 | integer2bytestream(dest, offset, mType); | ||
208 | switch(mType) | ||
209 | { | ||
210 | case LST_INTEGER: | ||
211 | integer2bytestream(dest, offset, mInteger); | ||
212 | break; | ||
213 | case LST_FLOATINGPOINT: | ||
214 | float2bytestream(dest, offset, mFP); | ||
215 | break; | ||
216 | case LST_KEY: | ||
217 | char2bytestream(dest, offset, mKey); | ||
218 | break; | ||
219 | case LST_STRING: | ||
220 | char2bytestream(dest, offset, mString); | ||
221 | break; | ||
222 | case LST_LIST: | ||
223 | break; | ||
224 | case LST_VECTOR: | ||
225 | vector2bytestream(dest, offset, mVec); | ||
226 | break; | ||
227 | case LST_QUATERNION: | ||
228 | quaternion2bytestream(dest, offset, mQuat); | ||
229 | break; | ||
230 | default: | ||
231 | break; | ||
232 | } | ||
233 | return offset; | ||
234 | } | ||
235 | |||
236 | LLScriptLibData() : mType(LST_NULL), mInteger(0), mFP(0.f), mKey(NULL), mString(NULL), mVec(), mQuat(), mListp(NULL) | ||
237 | { | ||
238 | } | ||
239 | |||
240 | LLScriptLibData(const LLScriptLibData &data) : mType(data.mType), mInteger(data.mInteger), mFP(data.mFP), mKey(NULL), mString(NULL), mVec(data.mVec), mQuat(data.mQuat), mListp(NULL) | ||
241 | { | ||
242 | if (data.mKey) | ||
243 | { | ||
244 | mKey = new char[strlen(data.mKey) + 1]; | ||
245 | strcpy(mKey, data.mKey); | ||
246 | } | ||
247 | if (data.mString) | ||
248 | { | ||
249 | mString = new char[strlen(data.mString) + 1]; | ||
250 | strcpy(mString, data.mString); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | LLScriptLibData(U8 *src, S32 &offset) : mListp(NULL) | ||
255 | { | ||
256 | static char temp[TOP_OF_MEMORY]; | ||
257 | mType = (LSCRIPTType)bytestream2integer(src, offset); | ||
258 | switch(mType) | ||
259 | { | ||
260 | case LST_INTEGER: | ||
261 | mInteger = bytestream2integer(src, offset); | ||
262 | break; | ||
263 | case LST_FLOATINGPOINT: | ||
264 | mFP = bytestream2float(src, offset); | ||
265 | break; | ||
266 | case LST_KEY: | ||
267 | { | ||
268 | bytestream2char(temp, src, offset); | ||
269 | mKey = new char[strlen(temp) + 1]; | ||
270 | strcpy(mKey, temp); | ||
271 | } | ||
272 | break; | ||
273 | case LST_STRING: | ||
274 | { | ||
275 | bytestream2char(temp, src, offset); | ||
276 | mString = new char[strlen(temp) + 1]; | ||
277 | strcpy(mString, temp); | ||
278 | } | ||
279 | break; | ||
280 | case LST_LIST: | ||
281 | break; | ||
282 | case LST_VECTOR: | ||
283 | bytestream2vector(mVec, src, offset); | ||
284 | break; | ||
285 | case LST_QUATERNION: | ||
286 | bytestream2quaternion(mQuat, src, offset); | ||
287 | break; | ||
288 | default: | ||
289 | break; | ||
290 | } | ||
291 | } | ||
292 | |||
293 | void set(U8 *src, S32 &offset) | ||
294 | { | ||
295 | static char temp[TOP_OF_MEMORY]; | ||
296 | mType = (LSCRIPTType)bytestream2integer(src, offset); | ||
297 | switch(mType) | ||
298 | { | ||
299 | case LST_INTEGER: | ||
300 | mInteger = bytestream2integer(src, offset); | ||
301 | break; | ||
302 | case LST_FLOATINGPOINT: | ||
303 | mFP = bytestream2float(src, offset); | ||
304 | break; | ||
305 | case LST_KEY: | ||
306 | { | ||
307 | bytestream2char(temp, src, offset); | ||
308 | mKey = new char[strlen(temp) + 1]; | ||
309 | strcpy(mKey, temp); | ||
310 | } | ||
311 | break; | ||
312 | case LST_STRING: | ||
313 | { | ||
314 | bytestream2char(temp, src, offset); | ||
315 | mString = new char[strlen(temp) + 1]; | ||
316 | strcpy(mString, temp); | ||
317 | } | ||
318 | break; | ||
319 | case LST_LIST: | ||
320 | break; | ||
321 | case LST_VECTOR: | ||
322 | bytestream2vector(mVec, src, offset); | ||
323 | break; | ||
324 | case LST_QUATERNION: | ||
325 | bytestream2quaternion(mQuat, src, offset); | ||
326 | break; | ||
327 | default: | ||
328 | break; | ||
329 | } | ||
330 | } | ||
331 | |||
332 | void print(std::ostream &s, BOOL b_prepend_comma); | ||
333 | void print_separator(std::ostream& ostr, BOOL b_prepend_sep, char* sep); | ||
334 | |||
335 | void setFromCSV(char *src) | ||
336 | { | ||
337 | mType = LST_STRING; | ||
338 | mString = new char[strlen(src) + 1]; | ||
339 | strcpy(mString, src); | ||
340 | } | ||
341 | |||
342 | LLScriptLibData(S32 integer) : mType(LST_INTEGER), mInteger(integer), mFP(0.f), mKey(NULL), mString(NULL), mVec(), mQuat(), mListp(NULL) | ||
343 | { | ||
344 | } | ||
345 | |||
346 | LLScriptLibData(F32 fp) : mType(LST_FLOATINGPOINT), mInteger(0), mFP(fp), mKey(NULL), mString(NULL), mVec(), mQuat(), mListp(NULL) | ||
347 | { | ||
348 | } | ||
349 | |||
350 | LLScriptLibData(const LLUUID &id) : mType(LST_KEY), mInteger(0), mFP(0.f), mKey(NULL), mString(NULL), mVec(), mQuat(), mListp(NULL) | ||
351 | { | ||
352 | mKey = new char[UUID_STR_LENGTH]; | ||
353 | id.toString(mKey); | ||
354 | } | ||
355 | |||
356 | LLScriptLibData(char *string) : mType(LST_STRING), mInteger(0), mFP(0.f), mKey(NULL), mString(NULL), mVec(), mQuat(), mListp(NULL) | ||
357 | { | ||
358 | if (!string) | ||
359 | { | ||
360 | mString = new char[1]; | ||
361 | mString[0] = 0; | ||
362 | } | ||
363 | else | ||
364 | { | ||
365 | mString = new char[strlen(string) + 1]; | ||
366 | strcpy(mString, string); | ||
367 | } | ||
368 | } | ||
369 | |||
370 | LLScriptLibData(const char *string) : mType(LST_STRING), mInteger(0), mFP(0.f), mKey(NULL), mString(NULL), mVec(), mQuat(), mListp(NULL) | ||
371 | { | ||
372 | if (!string) | ||
373 | { | ||
374 | mString = new char[1]; | ||
375 | mString[0] = 0; | ||
376 | } | ||
377 | else | ||
378 | { | ||
379 | mString = new char[strlen(string) + 1]; | ||
380 | strcpy(mString, string); | ||
381 | } | ||
382 | } | ||
383 | |||
384 | LLScriptLibData(LLVector3 &vec) : mType(LST_VECTOR), mInteger(0), mFP(0.f), mKey(NULL), mString(NULL), mVec(vec), mQuat(), mListp(NULL) | ||
385 | { | ||
386 | } | ||
387 | |||
388 | LLScriptLibData(LLQuaternion &quat) : mType(LST_QUATERNION), mInteger(0), mFP(0.f), mKey(NULL), mString(NULL), mVec(), mQuat(quat), mListp(NULL) | ||
389 | { | ||
390 | } | ||
391 | |||
392 | ~LLScriptLibData() | ||
393 | { | ||
394 | delete mListp; | ||
395 | delete [] mKey; | ||
396 | delete [] mString; | ||
397 | } | ||
398 | |||
399 | }; | ||
400 | |||
401 | #endif | ||