LSL Wiki Mirror 10-5-2006: LibraryWarpPos

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
The corresponding forum thread for this can be found here.

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.
warpPos( vector d ) //R&D by Keknehv Psaltery, ~05/25/2006
{
    if ( d.z > 768 )      //Otherwise we'll get stuck hitting the ceiling
        d.z = 768;
    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 );
}

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-- be happy! (This isn't exactly correct, both llSetPos and llSetPrimitiveParams using PRIM_POSITION are limited to 10m, this function simply calculates all the 10m jumps puts them in a list to pass to llSetPrimitiveParams) And you can, of course, modify it to allow larger distances, but beware.

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 simply 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
    // Compute the number of jumps necessary
    integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
    // Try and avoid stack/heap collisions
    if (jumps > 100 )
        jumps = 100;    //  1km 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.
    llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
}

Well, that's all. Have fun!
There are 9 comments on this page. [Display comments/form]