Jump to content
Sign in to follow this  
Ben Russell

0 to 60 in 3 seconds.

Recommended Posts



global_val = 0

function 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 )

end

You can use this to turn throttles down over time, etc. etc.

Share this post


Link to post
Share on other sites



global_val = 0

function 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 )

end

You 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?

Cheers

x-a

Share this post


Link to post
Share on other sites

The way I would do it at the moment is


dr_time = xp.getDataref("sim/time/total_running_time_sec")

local time_current = 0
local time_last = 0
local delta_time = 0
local 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_current
end

It would be cool to have a specific function, which could check the delta time between two calls of a function.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×