Difference between revisions of "User:ANSI Soderstrom/Threading with LSL"
Line 11: | Line 11: | ||
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. | 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. | ||
Timer Example | |||
<lsl> | <lsl> | ||
integer LOOP_COUNT; | integer LOOP_COUNT; | ||
Line 37: | Line 38: | ||
llSetTimerEvent(THREATING_SPEED); | llSetTimerEvent(THREATING_SPEED); | ||
} | } | ||
} | |||
} | |||
</lsl> | |||
Sensor Example | |||
<lsl> | |||
default | |||
{ | |||
state_entry() | |||
{ | |||
llSensor("",NULL_KEY,AGENT,96,PI); | |||
} | |||
sensor(integer i) { | |||
// do something... | |||
// and AFTER that repeat the Sensor ! (DONT use SensorRepeat) | |||
llSensor("",NULL_KEY,AGENT,96,PI); | |||
} | } | ||
} | } | ||
</lsl> | </lsl> |
Revision as of 00:08, 6 March 2011
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.
Timer Example <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>
Sensor Example <lsl> default {
state_entry() { llSensor("",NULL_KEY,AGENT,96,PI); }
sensor(integer i) { // do something...
// and AFTER that repeat the Sensor ! (DONT use SensorRepeat) llSensor("",NULL_KEY,AGENT,96,PI); }
} </lsl>