Difference between revisions of "User:ANSI Soderstrom/Threading with LSL"

From Second Life Wiki
Jump to navigation Jump to search
Line 31: Line 31:
         if(LOOP_COUNT) {
         if(LOOP_COUNT) {
             // Rotate the Prim around his axis
             // Rotate the Prim around his axis
             llSetRot(llGetRot()/llEuler2Rot(<0,0,LOOP_COUNT>*DEG_TO_RAD));
             llSetRot(llGetRot()*llEuler2Rot(<0,0,LOOP_COUNT>*DEG_TO_RAD));
             // increment the loop
             // increment the loop
             --LOOP_COUNT;
             --LOOP_COUNT;

Revision as of 06:16, 4 October 2010

Leave a comment

All About : Threating with LSL (Creating Low-Lag-Items)

Some functions in SL creating a lot of lag on the server-side. But the greatest lag is not coming from llSetRot() or something like that, but from loops !!! Do->while and for->to->next loops are the greatest lagproducers at the beginners level in SL. Furthermore its impossible to trigger a Event while a loop is running.

Some people say, timers are the godlike-laggers, but now we learn how to use timers for the opposite :)

We try to rotate the Prim around a angle of 360 degrees and producing no lag, because we wait at every loop for free server-power and can handle events while the loop is running.

<lsl> integer LOOP_COUNT; float THREATING_SPEED = 0.001; // 0.25 is nearby a NULL-Lag item !

default {

   state_entry()
   {
       // use the timer event instead of a loop and make sure we can handle events while the loop is running...
       LOOP_COUNT = 360;
       llSetTimerEvent(THREATING_SPEED);
   }
   timer() {
       // save serverPower
       llSetTimerEvent(0);
       // Do a loop (if possible)
       if(LOOP_COUNT) {
           // Rotate the Prim around his axis
           llSetRot(llGetRot()*llEuler2Rot(<0,0,LOOP_COUNT>*DEG_TO_RAD));
           // increment the loop
           --LOOP_COUNT;
           // look for events and do again the loop
           llSetTimerEvent(THREATING_SPEED);
       }
   }

} </lsl>