aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/media/Test%20sim/onefang%27s%20test%20bed/~memory.lsl
diff options
context:
space:
mode:
Diffstat (limited to 'media/Test%20sim/onefang%27s%20test%20bed/~memory.lsl')
-rw-r--r--media/Test%20sim/onefang%27s%20test%20bed/~memory.lsl378
1 files changed, 378 insertions, 0 deletions
diff --git a/media/Test%20sim/onefang%27s%20test%20bed/~memory.lsl b/media/Test%20sim/onefang%27s%20test%20bed/~memory.lsl
new file mode 100644
index 0000000..17f777d
--- /dev/null
+++ b/media/Test%20sim/onefang%27s%20test%20bed/~memory.lsl
@@ -0,0 +1,378 @@
1//MPLV2 Version 2.2 by Learjeff Innis, based on
2//MLP MULTI-LOVE-POSE V1.2 - Copyright (c) 2006, by Miffy Fluffy (BSD License)
3// OpenSim port by Jez Ember
4// Meta 7 fixes by onefang Rejected
5
6// v2.2 - rotate all poses, cleaner dump
7
8integer Checking = FALSE; // whether doing consistency check
9
10integer line;
11integer PosCount;
12list Poses; // list of pose names
13
14// indexed by same index as Poses, entry contains text string of pos/rot pairs, one for each ball in pose
15
16// list Positions;
17
18list Positions0;
19list Positions1;
20list Positions2;
21list Positions3;
22
23vector Pos1;
24vector Pos2;
25vector Pos3;
26vector Pos4;
27vector Pos5;
28vector Pos6;
29vector Rot1;
30vector Rot2;
31vector Rot3;
32vector Rot4;
33vector Rot5;
34vector Rot6;
35integer Ballcount;
36
37// Replacement for llListFindList which is currently broken in OSLSL
38integer myListFind(list a, string b) {
39 integer x;
40 integer l=llGetListLength(a);
41
42 for(x=0; x<l; x++) {
43 if(llList2String(a,x) == b) {
44 return x;
45 }
46 }
47
48 return -1;
49}
50
51announce()
52{
53 llOwnerSay((string)PosCount
54 + " positions stored ("
55 + llGetScriptName()
56 + ": "
57 + (string)llGetFreeMemory()
58 + " bytes free)");
59}
60
61getPosePos(string pdata) {
62 list plist = llParseString2List(pdata,[" "],[]);
63
64 Ballcount = llGetListLength(plist) / 2;
65
66 Pos1 = (vector)llList2String(plist, 0);
67 Rot1 = (vector)llList2String(plist, 1);
68 Pos2 = (vector)llList2String(plist, 2);
69 Rot2 = (vector)llList2String(plist, 3);
70 Pos3 = (vector)llList2String(plist, 4);
71 Rot3 = (vector)llList2String(plist, 5);
72 Pos4 = (vector)llList2String(plist, 6);
73 Rot4 = (vector)llList2String(plist, 7);
74 Pos5 = (vector)llList2String(plist, 8);
75 Rot5 = (vector)llList2String(plist, 8);
76 Pos6 = (vector)llList2String(plist, 10);
77 Rot6 = (vector)llList2String(plist, 11);
78}
79
80
81string adjust(integer doOffset, vector pos, vector erot, vector amt) {
82 if (doOffset) {
83 pos += amt/100.;
84 return (vround(pos) + " " + vround(erot));
85 }
86
87 rotation amount = llEuler2Rot(amt * DEG_TO_RAD);
88 erot *= DEG_TO_RAD;
89
90 rotation oldrot = llEuler2Rot(erot);
91 rotation newrot = oldrot / amount;
92
93 erot = llRot2Euler(newrot) * RAD_TO_DEG;
94 pos = pos / amount;
95 return(vround(pos) + " " + vround(erot));
96}
97
98adjust_all(integer doOffset, vector amt) {
99 integer ix;
100 integer bx;
101 string data;
102 for (ix = 0; ix < PosCount; ++ix) {
103 data = get_pose_by_index(ix);
104 getPosePos(data);
105
106 list parms = [ Pos1, Rot1, Pos2, Rot2, Pos3, Rot3, Pos4, Rot4, Pos5, Rot5, Pos6, Rot6 ];
107
108 data = adjust(doOffset, Pos1, Rot1, amt);
109 integer ballix = 1;
110 while (ballix < Ballcount) {
111 string stuff = adjust(doOffset, llList2Vector(parms, 2*ballix), llList2Vector(parms, 2*ballix+1), amt);
112 data += " " + stuff;
113 ++ballix;
114 }
115 store_pose(data, ix);
116 }
117}
118
119
120string get_pose_data(string name) {
121 integer ix = myListFind(Poses, name);
122
123 // if not found, use default positions
124 if (ix == -1) {
125 ix = 0;
126 }
127
128 return (get_pose_by_index(ix));
129}
130
131
132string get_pose_by_index(integer ix) {
133 if ((ix & 3) == 0) {
134 return llList2String(Positions0, ix>>2);
135 } else if ((ix & 3) == 1) {
136 return llList2String(Positions1, ix>>2);
137 } else if ((ix & 3) == 2) {
138 return llList2String(Positions2, ix>>2);
139 }
140 return llList2String(Positions3, ix>>2);
141}
142
143store_pose(string data, integer ix) {
144 if ((ix & 3) == 0) {
145 Positions0 = llListReplaceList(Positions0,[ data ],ix>>2,ix>>2);
146 } else if ((ix & 3) == 1) {
147 Positions1 = llListReplaceList(Positions1,[ data ],ix>>2,ix>>2);
148 } else if ((ix & 3) == 2) {
149 Positions2 = llListReplaceList(Positions2,[ data ],ix>>2,ix>>2);
150 } else if ((ix & 3) == 3) {
151 Positions3 = llListReplaceList(Positions3,[ data ],ix>>2,ix>>2);
152 }
153}
154
155
156save_pose(string name, string data) {
157 integer ix = myListFind(Poses, name);
158 if (ix == -1) {
159 add_pose(name, data);
160 } else {
161 store_pose(data, ix);
162 }
163}
164
165add_pose(string name, string data) {
166 integer ix = myListFind(Poses, name);
167 if (ix != -1) {
168 llOwnerSay("===> WARNING: Multiple .POSITIONS* entries for '" + name + "'");
169 } else {
170 Poses += name;
171 ix = ++PosCount;
172 }
173 store_pose(data, ix-1);
174}
175
176check_pose(string name) {
177 integer ix;
178
179 // if this is the last pose, report results
180 if (name == "CHECK2") {
181 string nameA;
182 for (ix = 0; ix < llGetListLength(Poses); ++ix) {
183 nameA = llList2String(Poses, ix);
184 if (get_pose_data(nameA) != "") {
185 if (nameA != "default" && nameA != "stand") {
186 llOwnerSay("No .MENUITEMS* entry for '" + nameA + "'.");
187 }
188 }
189 }
190 llOwnerSay("Checks complete, resetting.");
191 llResetScript();
192 }
193
194 ix = myListFind(Poses, name);
195 if (ix == -1) {
196 llOwnerSay("No .POSITIONS* entry for '" + name + "'.");
197 return;
198 }
199 save_pose(name, "");
200}
201
202
203string vround(vector vec) {
204 return ("<"+round(vec.x, 3)+","+round(vec.y, 3)+","+round(vec.z, 3)+">");
205}
206
207string round(float number, integer places) {
208 float shifted;
209 integer rounded;
210 string s;
211 shifted = number * llPow(10.0,(float)places);
212 rounded = llRound(shifted);
213 s = (string)((float)rounded / llPow(10.0,(float)places));
214 rounded = llSubStringIndex(s, ".");
215 if (-1 != rounded)
216 s = llGetSubString(s,0,llSubStringIndex(s, ".")+places);
217 else
218 {
219 s += ".00000000";
220 s = llGetSubString(s,0,llSubStringIndex(s, ".")+places);
221 }
222 return s;
223}
224
225dashes() {
226 llOwnerSay("_______________________________________________________________________________");
227 llOwnerSay("");
228}
229
230
231// Globals for reading card config
232integer ConfigLineIndex;
233list ConfigCards; // list of names of config cards
234string ConfigCardName; // name of card being read
235integer ConfigCardIndex; // index of next card to read
236key ConfigQueryId;
237
238integer next_card()
239{
240 if (ConfigCardIndex >= llGetListLength(ConfigCards)) {
241 ConfigCards = [];
242 return (FALSE);
243 }
244
245 ConfigLineIndex = 0;
246 ConfigCardName = llList2String(ConfigCards, ConfigCardIndex);
247 ConfigCardIndex++;
248 ConfigQueryId = llGetNotecardLine(ConfigCardName, ConfigLineIndex);
249 llOwnerSay("Reading " + ConfigCardName);
250 return (TRUE);
251}
252
253
254default {
255 state_entry() {
256 string item;
257 ConfigCards = [];
258 integer n = llGetInventoryNumber(INVENTORY_NOTECARD);
259 while (n-- > 0) {
260 item = llGetInventoryName(INVENTORY_NOTECARD, n);
261 if (llSubStringIndex(item, ".POSITIONS") != -1) {
262 ConfigCards += item;
263 }
264 }
265
266 ConfigCardIndex = 0;
267 ConfigCards = llListSort(ConfigCards, 1, TRUE);
268 next_card();
269 }
270
271 dataserver(key query_id, string data) {
272 if (query_id != ConfigQueryId) {
273 return;
274 }
275 if (data == EOF) {
276 if (next_card()) {
277 return;
278 }
279 state on;
280 }
281 if (llGetSubString(data,0,0) != "/") { // skip comments
282 integer ix = llSubStringIndex(data, "{"); //split name from positions, remove junk
283 integer jx = llSubStringIndex(data, "} <");
284 if (ix != -1 && jx != -1) {
285 add_pose(llGetSubString(data, ix+1, jx-1), llGetSubString(data, jx+2, -1));
286 }
287 }
288 ++ConfigLineIndex;
289 ConfigQueryId = llGetNotecardLine(ConfigCardName, ConfigLineIndex); //read next line of positions notecard
290 }
291
292 state_exit() {
293 if (PosCount < 1) {
294 add_pose("stand", "<-0.7,0.0,0.9> <0.0,0.0,0.0> <0.7,0.0,0.9> <0.0,0.0,-180.0>");
295 }
296 if (PosCount < 2) {
297 add_pose("default", "<-0.7,0.0,0.7> <0.0,0.0,0.0> <0.7,0.0,0.7> <0.0,0.0,-180.0>");
298 }
299
300 // do one save to indicate actual amount of available memory
301 string position = llList2String(Positions1, 0);
302 Positions1 = llListReplaceList(Positions1, [position],0,0);
303
304 if (llGetInventoryType("~props") == INVENTORY_SCRIPT) {
305 llSetScriptState("~props", TRUE);
306 llResetOtherScript("~props");
307 llSleep(1.0); // give props a chance to run -- doesn't really matter if not enough
308 }
309 }
310}
311
312
313state on {
314 state_entry() {
315 llMessageLinked(LINK_THIS, 2, "OK", (key)""); //msg to menu, in case it's waiting for loading
316 announce();
317 }
318
319 link_message(integer from, integer num, string str, key dkey) {
320 if (str == "PRIMTOUCH" || num < 0) {
321 return;
322 }
323
324 if (num == 0 && str == "POSEB") {
325 string name = (string)dkey;
326 if (name == "CHECK1") {
327 Checking = TRUE;
328 } else if (Checking) {
329 check_pose((string)dkey);
330 } else {
331 llMessageLinked(LINK_THIS, 0, "POSEPOS", (key)get_pose_data((string)dkey)); // to ~pos
332 }
333 return;
334 }
335
336 if (num != 1) {
337 return;
338 }
339
340 if (str == "OK?") { //question from menu, before loading menu
341 llMessageLinked(from, 2, "OK", (key)""); //answer to menu
342 } else if (str == "DUMP") {
343 dashes();
344 llOwnerSay("Copy to .POSITIONS; delete any other *.POSITIONS* cards");
345 dashes();
346 string name = llGetObjectName();
347 llSetObjectName("");
348
349 integer ix;
350 for (ix = 0; ix < PosCount; ++ix) {
351 string nameA = llList2String(Poses, ix);
352 llOwnerSay("{" + nameA + "} " + get_pose_data(nameA));
353 }
354
355 llSetObjectName(name);
356 dashes();
357 } else if (llSubStringIndex(str, "REORIENT=") == 0) {
358 // Reorient command (LINKMENU command from .MENUITEMS file)
359 // str format: REORIENT=OFF=<x,y,z> or REORIENT=ROT=<x,y,z> (in degrees)
360 list parms = llParseString2List(str, ["="], []);
361 vector amount = (vector)llList2String(parms, 2);
362 llWhisper(0, "Adjusting Poses, please wait");
363
364 if (llList2String(parms, 1) == "OFF") {
365 adjust_all(TRUE, amount);
366 } else {
367 adjust_all(FALSE, amount);
368 }
369 llMessageLinked(LINK_THIS, 0, "AGAIN", (key)"");
370 llWhisper(0, "Pose adjustment complete");
371 } else {
372 if (llGetSubString((string)dkey, 0, 0) == "<") { //SAVE
373 save_pose(str, (string)dkey);
374 announce();
375 }
376 }
377 }
378}