I have used this to turn the binary nature of the controls into a somewhat analog value by counting how many times control() is called in a 1 second period (as measured by timer()). When turning a boat, for example, tapping on the left_arrow key only results in a couple of control() events in a second, while mashing down on the key and holding it gives you 11 counts in a second (I thought). The higher the number, the faster I turn the boat.
I recently saw some effects in one of my scripted objects that suggested that control() timing is very different on different worlds here in Kitely. I wrote a script to measure this (listed below). The results were astonishing! On some Kitely worlds I was seeing as many as 100 control() events per second! This is amazingly good performance, but of course it fails to work right with my assumption of 11 events per second. Unfortunately, when I tried doing the timing test on other Kitely worlds I got very different results, as low as 7 events per second. Strangely, I got very good results on my own worlds where I have too many scripts that use too much time (according to Ilan). So having lots and lots of large scripts is not what causes the control() time to be so slow. Perhaps there is one bad script out there on some of these worlds that hogs so much time that it slows down control() response time on other better behaved scripts? (I lump my scripts into the better behaved category, of course!)
Here are some results from running the test script on several different grids and worlds. The times column is control() events per second, higher times are good I suppose, variability is bad.
Times Grid Region
100 Kitely Test Bed (1x1, empty, private)
90 Kitely Merchant Sandbox (2x2, empty)
62 Kitely Panthalassa (3x3 very full of busy scripts, lots of prims)
17 Kitely Never Ending Story (4x4, lots of prims, unknown scripts)
15* Kitely Frostbite Thane (4x4, lots of prims, unknown scripts)
67 OSGrid International Sailing (6x6, OS 0.9, medium load of scripts, lots of prims)
20 OSGrid Panthalassa (3x3, OS 0.9, lots of prims and scripts)
86 OSGrid Panthalassa1 (3x3, OS 0.9, empty region)
82 OSGrid Sandbox 12 (1x1, OS 0.9, empty)
44 SL Port Lux (1x1, moderate number of prims and scripts)
8 Inworldz Pomo (1x1, lots of scripts and prims)
*The statistic for this region slowly cycled between 7/second, rising to 20/second then slowly back down to start over again on about a 20 second cycle.
What I am going to have to do is measure this maximum number every time a vehicle starts. Then use this maximum number instead of the assumption of 11 per second. That will fail on Frostbite, where the number changes over time, but will work most places.
Code: Select all
//put this script in a prim, sit on it,
//try tapping and holding the forward-arrow key (or the w key)
//hold it for different periods of time
//the timer() time should be around 1 second, but gets longer on very busy regions
//Holding the key down continuously I thought would give a count of 11 and a time of 0.0909.
//But I am seeing counts as high as 100! Events per second!
integer times=0; //how many times control is called in a second
float avetime=0.0; //average time between control events
float lastime; //last time control was called
float lastsec; //time of the last timer() event
default
{
state_entry()
{
llSitTarget(<0,0,2>,ZERO_ROTATION); //seat the avatar above the prim
} //state_entry
changed(integer flag)
{
if (flag&CHANGED_LINK)
{
if (llAvatarOnSitTarget()!=NULL_KEY) //detect the avatar sitting
{
llRequestPermissions(llAvatarOnSitTarget(),PERMISSION_TAKE_CONTROLS);
llSetTimerEvent(1.0); //count controls in one second
lastsec=llGetTime(); //used to watch the timer time
}
else //(this isn't the best way, but for a single prim test this works)
{
llReleaseControls(); //give the avatar back the controls
llSetTimerEvent(0.0); //stop working when they stand up
llSetText("",<0,0,0>,0.0); //erase the old data display
}
}
} //changed
run_time_permissions(integer flag)
{
if (flag&PERMISSION_TAKE_CONTROLS) //when permission granted,
llTakeControls(CONTROL_FWD,TRUE,FALSE); //capture the fwd-arrow key
} //run_time_permissions
control(key id, integer level, integer edge)
{
if (level&CONTROL_FWD) //if the fwd-arrow key is pressed
{
times += 1; //count how often you notice it is down
float curtime=llGetTime();
if (times>1)
avetime += curtime-lastime; //how long since the last time
lastime=curtime;
}
} //control
timer()
{
float cursec=llGetTime();
float delta=cursec-lastsec; //this should be around 1 second
lastsec=llGetTime();
string mess = "timer="+(string)delta+" (should be around 1.0)";
mess += "\ncontrol events = "+(string)times+" (never larger than 11)";
if (times>1)
{
mess += "\ntime between events = "+(string)(avetime/(float)(times-1))+ " (should be around 0.09)";
}
times=0;
avetime=0.0;
llSetText(mess,<1,1,1>,1.0);
} //timer
}