Solved Time (lua) in scenarios

Discussion in 'Mod Support' started by Darthbob555, Sep 15, 2016.

  1. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    283
    I have found the function onPreRender(dt) in the lua reference page. The parameter in it, dt, increments up, like I expected, however, what does it refer to? I have read that it is the frames, but is that dynamic or hard coded?

    To give more detail, does the dt parameter increment based on the frame per second that the game is running at?
     
  2. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,619
    dt stands for "Delta Time" in this instance. It's the amount of time which has passed since the last call. If you start adding up like this then your variable measuredTime will hold the amount of time (in seconds) since you started:

    Code:
     M.onPreRender(dt)
       measuredTime = measuredTime + dt
    end
    OTOH if you wanted FPS you could use something like the code below which should be mostly correct, although I STRONGLY recommend doing some averaging if you want to use this to determine FPS. Instantaneous numbers can sometimes give very poor results - see the screenshot below for where my system dropped to 0.5 fps momentarily while switching from Fullscreen to Windowed. Before switching to windowed I was getting about 40+fps and after the change settles I'm getting about 59fps (vsync).

    Code:
    M.onPreRender(dt)
       fps = 1 / dt
    end
     

    Attached Files:

    • 20160920233503_1.jpg
    #2 torsion, Sep 21, 2016
    Last edited: Sep 21, 2016
  3. Darthbob555

    Darthbob555
    Expand Collapse

    Joined:
    Feb 14, 2016
    Messages:
    283
    Thank you for this information :). It seems to work very nicely for what I want it to do.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice