From e75291c816243c162afc0db894e37bd26890c7de Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 21 Jan 2012 17:18:44 +1000 Subject: Change the test script to the longest MLP script. --- LuaSL/test2.lsl | 412 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 341 insertions(+), 71 deletions(-) diff --git a/LuaSL/test2.lsl b/LuaSL/test2.lsl index 3b93b64..c72b6e2 100644 --- a/LuaSL/test2.lsl +++ b/LuaSL/test2.lsl @@ -1,108 +1,378 @@ -// MLPV2 Version 2.3j, by Learjeff Innis, based on +//MPLV2 Version 2.2 by Learjeff Innis, based on //MLP MULTI-LOVE-POSE V1.2 - Copyright (c) 2006, by Miffy Fluffy (BSD License) // OpenSim port by Jez Ember -// Meta 7 fixes by onefang Rejected and one by Tatjana Kidd. +// Meta 7 fixes by onefang Rejected -integer MAX_BALLS = 6; +// v2.2 - rotate all poses, cleaner dump -integer ch; -integer swap; -integer BallCount; +integer Checking = FALSE; // whether doing consistency check -string pr1; -string pr2; +integer line; +integer PosCount; +list Poses; // list of pose names -integer Zoffset; +// indexed by same index as Poses, entry contains text string of pos/rot pairs, one for each ball in pose -vector RefPos; -rotation RefRot; +// list Positions; -getRefPos() { //reference position - RefPos = llGetPos(); - RefRot = llGetRot(); - Zoffset = (integer)llGetObjectDesc(); - RefPos.z += (float) Zoffset / 100.; +list Positions0; +list Positions1; +list Positions2; +list Positions3; + +vector Pos1; +vector Pos2; +vector Pos3; +vector Pos4; +vector Pos5; +vector Pos6; +vector Rot1; +vector Rot2; +vector Rot3; +vector Rot4; +vector Rot5; +vector Rot6; +integer Ballcount; + +// Replacement for llListFindList which is currently broken in OSLSL +integer myListFind(list a, string b) { + integer x; + integer l=llGetListLength(a); + + for(x=0; x 1) { - llSay(ch+swap,pr1); //msg to ball1/2 - llSay(ch+!swap,pr2); +adjust_all(integer doOffset, vector amt) { + integer ix; + integer bx; + string data; + for (ix = 0; ix < PosCount; ++ix) { + data = get_pose_by_index(ix); + getPosePos(data); + + list parms = [ Pos1, Rot1, Pos2, Rot2, Pos3, Rot3, Pos4, Rot4, Pos5, Rot5, Pos6, Rot6 ]; + + data = adjust(doOffset, Pos1, Rot1, amt); + integer ballix = 1; + while (ballix < Ballcount) { + string stuff = adjust(doOffset, llList2Vector(parms, 2*ballix), llList2Vector(parms, 2*ballix+1), amt); + data += " " + stuff; + ++ballix; + } + store_pose(data, ix); + } +} + + +string get_pose_data(string name) { + integer ix = myListFind(Poses, name); + + // if not found, use default positions + if (ix == -1) { + ix = 0; + } + + return (get_pose_by_index(ix)); +} + + +string get_pose_by_index(integer ix) { + if ((ix & 3) == 0) { + return llList2String(Positions0, ix>>2); + } else if ((ix & 3) == 1) { + return llList2String(Positions1, ix>>2); + } else if ((ix & 3) == 2) { + return llList2String(Positions2, ix>>2); + } + return llList2String(Positions3, ix>>2); +} + +store_pose(string data, integer ix) { + if ((ix & 3) == 0) { + Positions0 = llListReplaceList(Positions0,[ data ],ix>>2,ix>>2); + } else if ((ix & 3) == 1) { + Positions1 = llListReplaceList(Positions1,[ data ],ix>>2,ix>>2); + } else if ((ix & 3) == 2) { + Positions2 = llListReplaceList(Positions2,[ data ],ix>>2,ix>>2); + } else if ((ix & 3) == 3) { + Positions3 = llListReplaceList(Positions3,[ data ],ix>>2,ix>>2); + } +} + + +save_pose(string name, string data) { + integer ix = myListFind(Poses, name); + if (ix == -1) { + add_pose(name, data); } else { - llSay(ch,pr1); //msg to ball1/2 + store_pose(data, ix); } +} + +add_pose(string name, string data) { + integer ix = myListFind(Poses, name); + if (ix != -1) { + llOwnerSay("===> WARNING: Multiple .POSITIONS* entries for '" + name + "'"); + } else { + Poses += (list) name; + ix = ++PosCount; + } + store_pose(data, ix-1); +} +check_pose(string name) { integer ix; - for (ix = 2; ix < BallCount; ++ix) { - llSay(ch + ix, (string)((vector)llList2String(Pdata, 2*ix) * RefRot + RefPos) - + (string)(llEuler2Rot((vector)llList2String(Pdata, 2*ix + 1) * DEG_TO_RAD) * RefRot)); + + // if this is the last pose, report results + if (name == "CHECK2") { + string nameA; + for (ix = 0; ix < llGetListLength(Poses); ++ix) { + nameA = llList2String(Poses, ix); + if (get_pose_data(nameA) != "") { + if (nameA != "default" && nameA != "stand") { + llOwnerSay("No .MENUITEMS* entry for '" + nameA + "'."); + } + } + } + llOwnerSay("Checks complete, resetting."); + llResetScript(); + } + + ix = myListFind(Poses, name); + if (ix == -1) { + llOwnerSay("No .POSITIONS* entry for '" + name + "'."); + return; } + save_pose(name, ""); } -getChan() { - ch = (integer)("0x"+llGetSubString((string)llGetKey(),-4,-1)); //fixed channel for prim + +string vround(vector vec) { + return ("<"+round(vec.x, 3)+","+round(vec.y, 3)+","+round(vec.z, 3)+">"); } +string round(float number, integer places) { + float shifted; + integer rounded; + string s; + shifted = number * llPow(10.0,(float)places); + rounded = llRound(shifted); + s = (string)((float)rounded / llPow(10.0,(float)places)); + rounded = llSubStringIndex(s, "."); + if (-1 != rounded) + s = llGetSubString(s,0,llSubStringIndex(s, ".")+places); + else + { + s += ".00000000"; + s = llGetSubString(s,0,llSubStringIndex(s, ".")+places); + } + return s; +} + +dashes() { + llOwnerSay("_______________________________________________________________________________"); + llOwnerSay(""); +} + + +// Globals for reading card config +integer ConfigLineIndex; +list ConfigCards; // list of names of config cards +string ConfigCardName; // name of card being read +integer ConfigCardIndex; // index of next card to read +key ConfigQueryId; + +integer next_card() +{ + if (ConfigCardIndex >= llGetListLength(ConfigCards)) { + ConfigCards = []; + return (FALSE); + } + + ConfigLineIndex = 0; + ConfigCardName = llList2String(ConfigCards, ConfigCardIndex); + ConfigCardIndex++; + ConfigQueryId = llGetNotecardLine(ConfigCardName, ConfigLineIndex); + llOwnerSay("Reading " + ConfigCardName); + return (TRUE); +} + + default { state_entry() { - getRefPos(); - getChan(); - } + string item; + ConfigCards = []; + integer n = llGetInventoryNumber(INVENTORY_NOTECARD); + while (n-- > 0) { + item = llGetInventoryName(INVENTORY_NOTECARD, n); + if (llSubStringIndex(item, ".POSITIONS") != -1) { + ConfigCards += (list) item; + } + } - on_rez(integer arg) { - getRefPos(); - getChan(); + ConfigCardIndex = 0; + ConfigCards = llListSort(ConfigCards, 1, TRUE); + next_card(); } - - link_message(integer from, integer num, string cmd, key pkey) { - if (cmd == "PRIMTOUCH"){ + + dataserver(key query_id, string data) { + if (query_id != ConfigQueryId) { return; } + if (data == EOF) { + if (next_card()) { + return; + } + state on; + } + if (llGetSubString(data,0,0) != "/") { // skip comments + integer ix = llSubStringIndex(data, "{"); //split name from positions, remove junk + integer jx = llSubStringIndex(data, "} <"); + if (ix != -1 && jx != -1) { + add_pose(llGetSubString(data, ix+1, jx-1), llGetSubString(data, jx+2, -1)); + } + } + ++ConfigLineIndex; + ConfigQueryId = llGetNotecardLine(ConfigCardName, ConfigLineIndex); //read next line of positions notecard + } + + state_exit() { + if (PosCount < 1) { + 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>"); + } + if (PosCount < 2) { + 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>"); + } + + // do one save to indicate actual amount of available memory + string position = llList2String(Positions1, 0); + Positions1 = llListReplaceList(Positions1, [position],0,0); + + if (llGetInventoryType("~props") == INVENTORY_SCRIPT) { + llSetScriptState("~props", TRUE); + llResetOtherScript("~props"); + llSleep(1.0); // give props a chance to run -- doesn't really matter if not enough + } + } +} - if (num == 1 && cmd == "STOP") { - swap = 0; + +state on { + state_entry() { + llMessageLinked(LINK_THIS, 2, "OK", (key)""); //msg to menu, in case it's waiting for loading + announce(); + } + + link_message(integer from, integer num, string str, key dkey) { + if (str == "PRIMTOUCH" || num < 0) { return; } - if (num) return; + if (num == 0 && str == "POSEB") { + string name = (string)dkey; + if (name == "CHECK1") { + Checking = TRUE; + } else if (Checking) { + check_pose((string)dkey); + } else { + llMessageLinked(LINK_THIS, 0, "POSEPOS", (key)get_pose_data((string)dkey)); // to ~pos + } + return; + } - if (cmd == "POSE") { - list parms = llCSV2List((string)pkey); - BallCount = llList2Integer(parms,1); + if (num != 1) { return; - } else if (cmd == "POSEPOS") { - // p = (integer)((string)pkey - getPosNew((string)pkey); - setPos(); - } else if (cmd == "SWAP") { - swap = (integer)((string)pkey) & 1; - llSay(ch+swap,pr1); //msg to ball1/2 - llSay(ch+!swap,pr2); - } else if (cmd == "REPOS") { - getRefPos(); - } else if (llGetSubString(cmd, 0, 0) == "Z") { - // Changed by Tatjana to make it work :) - integer change; - if (llGetSubString(cmd,1,1) == "+") change = (integer)llGetSubString(cmd,2,10); - else change = (integer)llGetSubString(cmd,1,10); - // End Tatjana changing (Penny helped, of course!) - Zoffset += change; - RefPos.z += (float)change/100.; - setPos(); - llOwnerSay("Height Adjustment: change by " + (string) change + "cm, new offset: " + (string)Zoffset + "cm"); - llSetObjectDesc((string)Zoffset); - } else if (cmd == "GETREFPOS") { - llMessageLinked(LINK_THIS,8,(string)RefPos,(string)RefRot); //send reference position to pose } + + if (str == "OK?") { //question from menu, before loading menu + llMessageLinked(from, 2, "OK", (key)""); //answer to menu + } else if (str == "DUMP") { + dashes(); + llOwnerSay("Copy to .POSITIONS; delete any other *.POSITIONS* cards"); + dashes(); + string name = llGetObjectName(); + llSetObjectName(""); + + integer ix; + for (ix = 0; ix < PosCount; ++ix) { + string nameA = llList2String(Poses, ix); + llOwnerSay("{" + nameA + "} " + get_pose_data(nameA)); + } + + llSetObjectName(name); + dashes(); + } else if (llSubStringIndex(str, "REORIENT=") == 0) { + // Reorient command (LINKMENU command from .MENUITEMS file) + // str format: REORIENT=OFF= or REORIENT=ROT= (in degrees) + list parms = llParseString2List(str, ["="], []); + vector amount = (vector)llList2String(parms, 2); + llWhisper(0, "Adjusting Poses, please wait"); + + if (llList2String(parms, 1) == "OFF") { + adjust_all(TRUE, amount); + } else { + adjust_all(FALSE, amount); + } + llMessageLinked(LINK_THIS, 0, "AGAIN", (key)""); + llWhisper(0, "Pose adjustment complete"); + } else { + if (llGetSubString((string)dkey, 0, 0) == "<") { //SAVE + save_pose(str, (string)dkey); + announce(); + } + } } } -- cgit v1.1