Predicting Script execution speed?
|
|
Krashnburn Hillquit
Registered User
Join date: 14 Feb 2006
Posts: 15
|
03-24-2006 08:17
While this looks hopeless to me, I figured that it was worth asking if any one has and cool tricks or something I havent thought of.
I have a function, the output of the function depends on the time it takes the function to execute.
In order to be accurate, I need to know how long it will take the function to execute, at the start of the function, so checking time at the end will not help.
I would simply hardcode the time in to the function if it was even remotely stable, but I have benchmarked it from 0.02 seconds to 0.2 seconds execution time.
In certain cases, that difference can cause wildly inacurate results.
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
03-24-2006 08:28
/me tries to compose a coherent reply around the hilarity ensuing.
Sorry - it's just not possible in lsl. Some parts of functions are variable in execution speed (list sorting being one obvious example). Even assuming you're not doing that the sim code will kill time-predicting like this.
In each "tick" (sim frame) the time available for script processing is variable - it "tops up" the time per frame to 22.2ms (1/45s) after images, physics, etc. have been processed (if possible). If there is only you in a sim, no one else enters and everything's stable and you don't have anything rezzing, nor variable load scripts (you in an empty sim pretty much) you might get stable times I guess.
But someone tping in hits the image time (the sim sends them the textures to draw etc.) someone rezzing a physical object (vehicle say) hits images a bit, then as they drive/fly/pilot/steer the vehicle around the physics time will change and both of these will reduce (assuming it's a moderately normally loaded sim) will hit the script time and slow the execution of your script down.
EDIT:
There are almost certainly other ways to do what you're after if you could share a bit? It can't be predicting time though.
|
|
Krashnburn Hillquit
Registered User
Join date: 14 Feb 2006
Posts: 15
|
03-24-2006 08:39
I was afraid this was the case, this fact alone prohibits acurate manipulation of physical objects moving at high velocities, even if I finished perfecting compensation for all other factors, how depressing.
|
|
Krashnburn Hillquit
Registered User
Join date: 14 Feb 2006
Posts: 15
|
03-24-2006 08:58
ahh missed your edit. This function attempts to convert a requested push vector, in to a meters/second push on the target ID that compensates for all known factors (outside energy). That is, for an object with neutral buoyancy, its velocity will be adjusted by the requested vector in m/s. Obviously for this to be acurate the TargetPos must be acurate as of the time the llPushObject call goes off. For objects moving at high velocities, accurately knowing the delay untill the llPushObject call becomes critical. Push(key Tgt,vector ToPush, float Mass,vector TargetPos) { ToPush *= Mass; float Dist = llVecDist(llGetPos(),TargetPos); ToPush *= llPow(Dist,3);
float MyMass = llGetMass(); float InnerRange = llPow(MyMass/10,1.0/3.0); ToPush *= 10; if(Dist >= InnerRange) { ToPush /= (MyMass); ToPush *=(1 + 0.000000631314 * llVecMag(ToPush));//this needs upgrading, the multiplier seems to vary a bit over time. } else ToPush /= (MyMass*llPow((Dist/InnerRange),3)); llPushObject(Target,ToPush,ZERO_VECTOR,FALSE); }
|
|
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
|
03-24-2006 10:35
float speed = 0.0;
default { event() { // This is how long since the event last fired. speed = llGetAndResetTime();
// To correct a push for amount of energy available multiple it by (1.0 / (llGetEnergy() + 0.001))
// This all might work :). } }
|
|
Krashnburn Hillquit
Registered User
Join date: 14 Feb 2006
Posts: 15
|
03-24-2006 12:25
Yea, I did some testing with energy yesterday, I know how to correct for it, I prefer to figure up how long it takes to regen and space the pushes at higher intervals, thats done outside this function, thank you though.
I don't need to know how long its been since the last push,
A: I get an objects information
B: some script runs
C:the script calls llPushObject
That would be figuring up A to next A, I need to know elapsed time between A and C.... the problem is I have to know it before B...
|
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
03-24-2006 14:34
From: Krashnburn Hillquit That would be figuring up A to next A, I need to know elapsed time between A and C.... the problem is I have to know it before B... You could do this: float calibrated_delay; float last_calibration; action() { if(llGetTime() - last_calibration > CALIBRATION_INTERVAL) calibrate(); do_action(calibrated_delay); } do_action(float delay) { // do calculation here if(delay < 0) return; // do push or whatever other work you need here } calibrate() { integer i; last_calibration = llGetTime(); for(i = 0; i < 1000; i++) do_action(-1.0); calibrated_delay = (llGetTime() - tlast_calibration) / 1000.0; }
|