Ben Russell 1,008 Posted May 21, 2011 Report Share Posted May 21, 2011 global_val = 0function main() --gfx.getFrameSpeed( delta_per_second ) returns: delta_per_second / frames_per_second --we want to reach 60 in 3 seconds, so we divide the target_value by the duration. global_val = global_val + gfx.getFrameSpeed( 20 )endYou can use this to turn throttles down over time, etc. etc. Quote Link to post Share on other sites
x-alberto 1 Posted May 21, 2011 Report Share Posted May 21, 2011 global_val = 0function main() --gfx.getFrameSpeed( delta_per_second ) returns: delta_per_second / frames_per_second --we want to reach 60 in 3 seconds, so we divide the target_value by the duration. global_val = global_val + gfx.getFrameSpeed( 20 )endYou can use this to turn throttles down over time, etc. etc.I see a lot of cases for this, but why not just making "inElapsedSinceLastCall" available to the script?Cheersx-a Quote Link to post Share on other sites
Pete_SMS 348 Posted May 21, 2011 Report Share Posted May 21, 2011 The way I would do it at the moment isdr_time = xp.getDataref("sim/time/total_running_time_sec")local time_current = 0local time_last = 0local delta_time = 0local rate = 20 -- we want to reach 60 in 3 seconds, so we divide the target_value by the duration.function do_something() local time_current = xp.getFloat( dr_time ) local delta_time = time_current - time_last global_val = global_val + rate * delta_time local time_last = time_currentendIt would be cool to have a specific function, which could check the delta time between two calls of a function. Quote Link to post Share on other sites
Ben Russell 1,008 Posted May 21, 2011 Author Report Share Posted May 21, 2011 Alberto + Pete: the elapsed time data available from x-plane is invalidated by gizmos subsystems.Their can be lag or latency introduced by -your code- that runs before main.Which brings me to a second point: the data from x-plane is only provided for main.Many other hooks and functions are available in gizmo and where possible functions/data as useful as this needs to be available everywhere in scripting land. ( any event book -you- write )By providing gfx.getFrameSpeed( target_per_second ) I can return a value based on x-planes basic fps value Even then I have still seen some quite annoying drift.If you want to dig I into the guts of main and gizmo scripting event que which does all the nice "holy crap it just works" stuff - to prove me wrong feel free, but I don't see the "inElapsedTime" data from SDK land being a good thing inside Gizmo for untainted(C SDK) users. Quote Link to post Share on other sites
Pete_SMS 348 Posted May 21, 2011 Report Share Posted May 21, 2011 Ben, not having a Gizmo function like this is absolutley no problem. Especially, after you explained the trouble involved. Quote Link to post Share on other sites
Ben Russell 1,008 Posted May 21, 2011 Author Report Share Posted May 21, 2011 All good, open source has it's advantages.I'm also just talking off the top of my head, I'd have to review the graphics callbacks stuff to be totally sure of the above, but I'm on my iPad and cant be bothered switching sims around. Quote Link to post Share on other sites
x-alberto 1 Posted May 21, 2011 Report Share Posted May 21, 2011 I see your point, Ben.Also, Pete's approach looks nice to me so I will be just fine.Cheers Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.