Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This file contains a series of defines and functions that will
- allow you to use linkSetData memory for lists. These lists will
- not have all the versitlity of normal LSL lists.
- The format in LinksetData memory are as follows.
- The first entry in a list is the master header file. It is
- defined as the following.
- linkset listName is the list listName and the data is the number of
- entries the list.
- <listName> -> <list entries number>
- the format of each list entry is as follows
- <listName>|<entrynumber>:<data>
- */
- #include "color.lsl"
- #define DEBUG
- #define BLINK(a,b,c) if((a%2)) llSetColor(b, ALL_SIDES); else llSetColor(c, ALL_SIDES);
- DS(string sayd)
- {
- #ifdef DEBUG
- llOwnerSay(sayd);
- #endif
- }
- // http://wiki.secondlife.com/wiki/hex
- string XDIGITS = "0123456789abcdef"; // could be "0123456789ABCDEF"
- string hexes(integer bits)
- {
- string nybbles = "";
- while (bits)
- {
- integer lsn = bits & 0xF; // least significant nybble
- string nybble = llGetSubString(XDIGITS, lsn, lsn);
- nybbles = nybble + nybbles;
- bits = bits >> 4; // discard the least significant bits at right
- bits = bits & 0xfffFFFF; // discard the sign bits at left
- }
- return nybbles;
- }
- string hex(integer value)
- {
- if (value < 0)
- {
- return "-0x" + hexes(-value);
- }
- else if (value == 0)
- {
- return "0x0"; // hexes(value) == "" when (value == 0)
- }
- else // if (0 < value)
- {
- return "0x" + hexes(value);
- }
- }
- DLS(string linkList)
- {
- list tl;
- tl = llLinksetDataFindKeys("^" +linkList +"\\|", 0, 10);
- tl = llListSort(tl, 0, 1);
- DS(llDumpList2String(tl, "\n"));
- }
- // The first step is the define the linkSetList entry
- integer linkSetDefine(string listName)
- {
- // test to see if entry already exists, if so return error
- // of -1
- if(llLinksetDataRead(listName) != "")
- return -1;
- else
- llLinksetDataWrite(listName, "0");
- return 1; // linkSetList Created.
- }
- // add a entry to the linkset entry and increment the
- // the count by one when adding. create the linkSet
- // if it does not exist. any data other than a string
- // must be typecast to a string.
- integer addLinkData(string listName, string data)
- {
- integer tcList;
- // if listName exists, add link
- // and increment count.
- if(linkSetDefine(listName) == 1)
- tcList = incrmLinkCount(listName, 0);
- else
- tcList = incrmLinkCount(listName, 1);
- llLinksetDataWrite(listName +"|"+ (string) tcList +":"+data, "0");
- return tcList;
- }
- // get count total from base and increase it by 'count'
- integer incrmLinkCount(string listName, integer count)
- {
- integer currentNum = (integer) llLinksetDataRead(listName);
- currentNum += count;
- llLinksetDataWrite(listName, (string) currentNum);
- return currentNum;
- }
- // Return the number of entries in a linkSetList
- integer GetlinkListLength(string listName)
- {
- // return error if linkSetList does not exits of -1
- integer listLength = (integer) llLinksetDataRead(listName);
- if(listLength == 0)
- return -1;
- else
- return (listLength + 1);
- }
- /*
- The following fuctions return entries in a linkList.
- None of them currently support negative indexes.
- */
- // returns a string that is at index in src
- string linkList2String(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a integer that is at index in src
- integer linkList2Integer(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (integer) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a float that is at index in src
- float linkList2Float(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (float) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a key that is at index in src
- key linkList2Key(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (key) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a rotation that is at index in src
- rotation linkList2Rot(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (rotation) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // returns a vector that is at index in src
- vector linkList2Vector(string src, integer index)
- {
- string found;
- string searchFor = src+"\\|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return (vector) llGetSubString(found, (llSubStringIndex(found, ":") + 1), -1);
- }
- // Returns a list that is a subset of a linkList.
- // be aware of memory limtations since linkLists can
- // be significnally larger than script memory.
- //
- // if the end parameter is a -1 the function will return
- // everything from start to the end of the linkList.
- // linkList2List(listName, 0, -1) will return the entire linkList
- // as a list.
- list linkList2List(string listName, integer start, integer end)
- {
- // check see if linkList exists, return emply list if does not.
- if(llLinksetDataRead(listName) == "")
- return [""];
- // linkList exist, but start is out of bounds,
- // return a empty list.
- integer listLength = GetlinkListLength(listName);
- if(start > listLength)
- return [""];
- // if end of linkList is longer than linkList, set end to
- // listLength
- if(end > listLength || end == -1)
- end = listLength;
- integer i;
- list tl;
- for(i = start; i < (end + 1); i++)
- {
- // DS("i : " + (string)i);
- tl += linkList2String(listName, i);
- }
- return tl;
- }
- // Returns a string with the linklist converted to string
- // with seperator between entries.
- string linkListDump2String(string listName, string seperator)
- {
- integer i;
- integer endofList = GetlinkListLength(listName);
- string rc;
- for (i = 0; i < endofList; i++)
- rc += linkList2String(listName, i) + seperator;
- return rc;
- }
- // returns a string with the linkList converted to string
- // with commas(,) between entries
- string linkList2CSV(string linkName)
- {
- return linkListDump2String(linkName, ",");
- }
- // removes entries from start to end of linkName. returning the new size of
- // linkName;
- // if a -1 is used for the end parameter then the linkList will be deleted
- // from start to end of the linkLIst
- integer linkListDeleteSubList(string linkName, integer start, integer end)
- {
- integer i;
- list tl;
- integer tmpEnd = (integer) llLinksetDataRead(linkName);
- string tmpData;
- if(end == -1)
- end = tmpEnd;
- // remove entries from linkName, start to end
- for(i = start; i < (end + 1); ++i)
- tl = llLinksetDataDeleteFound("^" + linkName+"\\|"+(string) i +":", "");
- llLinksetDataWrite(linkName, (string) (start-1));
- for(i = (end+1); i < (tmpEnd+1); i++)
- {
- tmpData = linkList2String(linkName, i);
- addLinkData(linkName, tmpData);
- tl = llLinksetDataDeleteFound("^" + linkName+"\\|"+(string) i +":", "");
- }
- return (integer) llLinksetDataRead(linkName);
- }
- // The following takes list (src) and puts it in linkList (dest) starting at
- // position start. If start is a -1, then the list is appended to the end
- // of the linkLinks. The function returns the new length of the linkList.
- integer listInsertLinkList (string linkName, list src, integer start)
- {
- integer i;
- string tmplink = (string) llGenerateKey();
- // if start is longer than linkName, then just append
- // the output to linkName.
- if(start == -1 || start > GetlinkListLength(linkName))
- {
- for(i = 0; i < llGetListLength(src); i++)
- addLinkData(linkName, llList2String(src, i));
- DLS(linkName);
- }
- else // insert src into linkList at position indicated by start
- {
- // move linkName from 0 to start to tmplink
- for(i = 0; i < start; ++i)
- addLinkData(tmplink, linkList2String(linkName, i));
- // add list src to the end of tmplink
- for(i = 0; i < llGetListLength(src); i++)
- addLinkData(tmplink, llList2String(src, i));
- for(i = start; i < GetlinkListLength(linkName); i++)
- addLinkData(tmplink, linkList2String(linkName, i));
- // delete old linkList, then move data from tmplink to
- // listLink.
- linkListRemove(linkName);
- for (i = 0; i< GetlinkListLength(tmplink); i++)
- addLinkData(linkName, linkList2String(tmplink, i));
- linkListRemove(tmplink);
- }
- return GetlinkListLength(linkName);
- }
- // function to remove a linkList
- // returns -1 if not successful
- // returns 1 if successful
- integer linkListRemove(string linkName)
- {
- llLinksetDataDeleteFound("^" + linkName+"\\|", "");
- llLinksetDataDeleteFound("^" + linkName, "");
- return 1;
- }
- // returns the index of the first instance of needle
- // in linkList of linkName
- integer linkListFind(string linkName, string needle)
- {
- string findTmp = (string) llLinksetDataFindKeys("^" + linkName + "\\|" + ".*:.*" + needle +".*", 0, 1);
- list tmpList = llParseString2List(findTmp, [":", "|"], []);
- if(llGetListLength(tmpList) < 1)
- return -1;
- else
- return llList2Integer(tmpList, 1);
- }
- integer i;
- default
- {
- state_entry()
- {
- llSetTimerEvent(0.2);
- // addLinkData("test", "fuckme");
- // llLinksetDataReset();
- // DLS("test");
- DS((string) linkListFind("test", "ff"));
- }
- timer()
- {
- llSetText((string) llLinksetDataAvailable()
- + "\n"+(string) llLinksetDataCountKeys()
- + "\n"+(string) llGetFreeMemory(), FUCHSIA, TRUE);
- llSetColor(WHITE, ALL_SIDES );
- }
- touch_start(integer num_detected)
- {
- llSetTimerEvent(0);
- llResetTime();
- }
- touch( integer num_detected )
- {
- if(llGetTime() > 2)
- llSetColor(GREEN, ALL_SIDES);
- }
- touch_end(integer num_detected)
- {
- llSetTimerEvent(0.5);
- if(llGetTime() > 2)
- {
- llLinksetDataReset();
- llSetColor(WHITE, ALL_SIDES );
- }
- else
- {
- llSetColor(BLUE, ALL_SIDES );
- llResetTime();
- for(i = 0; i < 500; ++i)
- {
- addLinkData("test", hex(i));
- // addLinkData("goat", (string) ZERO_VECTOR);
- DS((string) i +" : " +hex(i));
- }
- DS((string)llGetTime());
- // DS(llDumpList2String(llLinksetDataListKeys(0,0), "\n"));
- llSetColor(WHITE, ALL_SIDES );
- }
- }
- linkset_data(integer action, string name, string value)
- {
- if(llLinksetDataAvailable()%2)
- llSetColor(BLUE, ALL_SIDES );
- else
- llSetColor(RED, ALL_SIDES );
- llSetText((string) llLinksetDataAvailable()
- + "\n"+(string) llLinksetDataCountKeys()
- + "\n"+(string) llGetFreeMemory(), FUCHSIA, TRUE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement