Don't click here unless you want to be banned.

LSL Wiki : LibraryWarpPos

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org
The corresponding forum thread for this can be found here.

For an alternate method that does not use llSetPrimitiveParams, but parallel calls to llSetPos (link messages to multiple llSetPos scripts); if you can understand it, try LibrarySenWarp instead.

WarpPos: a method by which the 10m limit on non-physical movement, which limits speed to about 50m/s, may be avoided.

llSetPrimitiveParams, it would seem, executes each rule in the list as it comes across it. This allows you to set up a list in the form of [PRIM_POSITION,pos,PRIM_POSITION,pos, ... ,PRIM_POSITION,pos] which, when run by the server, basically causes many llSetPos calls in a very short amount of time. As far as I can tell, this is done in one frame on the server-- so there are no intermediate steps in the journey.

It's completely public domain. Look at it, modify it, sell it in an item, whatever. But I'll be annoyed if you scam noobs into buying it.

I have added a hack which currently allows this to work in just two steps, regardless of destination. This seriously speeds up the function and allows you to cross large distances easily - Felixe Thorne -- Moved hack to current function since it was added to the original

warpPos( vector d ) //R&D by Keknehv Psaltery, ~05/25/2006
{
    integer iterations;
    vector curpos;
    if ( d.z < (llGround(d-llGetPos())+0.01)) 
        d.z = llGround(d-llGetPos())+0.01; //Avoid object getting stuck at destination
    if ( d.z > 4096 )      //Object doesn't get stuck on ceiling as of 1.18.5 (3), and with
        d.z = 4096;        //havok 4 the height limit is increasing to 1024m.

    //Hack added by Felixe Thorne
    curpos=llGetPos();
    llSetPrimitiveParams([PRIM_POSITION, <1.84e+19, 1.84e+19, 1.84e+19>, PRIM_POSITION, d]);
    if (llGetPos()==curpos) {
        //Looks like it's been fixed, resort to the old method..
        do //This will ensure the code still works.. albeit slowly.. if LL remove this trick (which they have done and reverted in the past..)
        {
            iterations++;
            integer s = (integer)(llVecMag(d-llGetPos())/10)+1; //The number of jumps necessary
            if ( s > 100 )  //Try and avoid stack/heap collisions with far away destinations
                s = 100;    //  1km should be plenty
            integer e = (integer)( llLog( s ) / llLog( 2 ) );   //Solve '2^n=s'        
            list rules = [ PRIM_POSITION, d ];  //The start for the rules list
            integer i;
            for ( i = 0 ; i < e ; ++i )     //Start expanding the list
                rules += rules;
                integer r = s - (integer)llPow( 2, e );
                if ( r > 0 )                    //Finish it up
                    rules += llList2List( rules, 0, r * 2 + 1 );
                llSetPrimitiveParams( rules );
                curpos=llGetPos();
                if (iterations>100) {
                    d=curpos; //We're going nowhere fast, so bug out of the loop
                }
        } while (llVecDist(curpos,d) > 0.2);
    }
}

A few observations:
Sim crossings are perilous for AVs. Depending on connection speed and whether or not you are connected to the sim (can see it on the mini-map), it may screw up your client. However, it seems like objects, by themselves, can cross great distances. I managed to send an object 4 sims away diagonally. Further testing would help us to understand these things.

The script limits the maximum distance to 1km, in order to prevent stack/heap collisions. Still, this is 100 times what llSetPos was limited to-- and you can, of course, modify it to allow larger distances, but beware. "A couple of hacks have been added which negate this restriction, so long as they continue to work."

The average time this function takes to execute is .2 seconds, which is barely noticeable at all, and can easily be attributed to general lag. A simple optimization for an object with a known destination might be to calculate the list beforehand, and then call llSetPrimitiveParams with that list.

BlindWanderer (Strife Onizuka) and a few other people took my code and smashed the list expansion, making it much faster and less memory intensive. Here's the modified code:
warpPos( vector destpos) 
{   //R&D by Keknehv Psaltery, 05/25/2006
    //with a little pokeing by Strife, and a bit more
    //some more munging by Talarus Luan
    //Final cleanup by Keknehv Psaltery

    //Add hack by Felixe Thorne 
    vector curpos;
    if ( destpos.z < (llGround(destpos-llGetPos())+0.01)) 
        destpos.z = llGround(destpos-llGetPos())+0.01; //Avoid object getting stuck at destination
    if ( destpos.z > 4096 )      //Object doesn't get stuck on ceiling as of 1.18.5 (3), and with
        destpos.z = 4096;        //havok 4 the height limit is increasing to 4096m.

    //Hack added by Felixe Thorne
    curpos=llGetPos();
    llSetPrimitiveParams([PRIM_POSITION, <1.84e+19, 1.84e+19, 1.84e+19>, PRIM_POSITION, destpos]);
    if (llGetPos()==curpos) {
        //Looks like it's been fixed, resort to the old method..
       // Compute the number of jumps necessary
       integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
       // Try and avoid stack/heap collisions, can be changed from 100 to 400 easily when compiled in Mono
       if (jumps > 400 )
           jumps = 400;    //  4km should be plenty
       list rules = [ PRIM_POSITION, destpos ];  //The start for the rules list
       integer count = 1;
       while ( ( count = count << 1 ) < jumps)
           rules = (rules=[]) + rules + rules;   //should tighten memory use.
       //Changed by Eddy Ofarrel to tighten memory use some more
       llSetPrimitiveParams( (rules=[]) + rules + llList2List( rules, (count - jumps) << 1, count) );
       if ( llVecDist( llGetPos(), destpos ) > .001 ) //Failsafe
           while ( --jumps ) 
               llSetPos( destpos );
    }
}

TdubDowler (aka Riden Blaisdale) shrunk this even more (compile in mono or you could get stack heap errors):
warp(vector pos)
{
    list rules;
    integer num = llRound(llVecDist(llGetPos(),pos)/10)+1;
    integer x;
    for(x=0; x<num; ++x) rules=(rules=[])+rules+[PRIM_POSITION,pos];
    llSetPrimitiveParams(rules);
}

And shrinking the tiny version even more...
warp(vector pos)
{
    list rules;
    integer num = llCeil(llVecDist(llGetPos(),pos)/10);
    while(num--)rules=(rules=[])+rules+[PRIM_POSITION,pos];
    llSetPrimitiveParams(rules);
}
Well, that's all. Have fun!
There are 13 comments on this page. [Display comments/form]