Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

FPS Plotter and FPS Radar: experiments with DeltaTime

edited August 2012 in Code Sharing Posts: 489

I thought I detected a stutter in DeltaTime when beta testing Codea, and wrote the code below to examine it (DeltaTime) graphically. Try changing the size of the Output pane while it is running.

-- 
-- FPS Plotter
--
supportedOrientations(LANDSCAPE_ANY)
backingMode(RETAINED)
function setup()
    maxDeltaTime = 1/60
    odt = 1
    dim = math.min(WIDTH, HEIGHT) * 0.5
    ox = (WIDTH - dim)/2
    oy = (HEIGHT - dim)/2
    background(0)
    strokeWidth(5)
    stroke(0, 127, 0)
    noFill()
    line(0, oy + dim/2, WIDTH, oy + dim/2)
    line(ox + dim/2, 0, ox + dim/2, HEIGHT)
    rect(ox, oy, dim, dim)
    fill(0, 255, 0)
    text("0, 0", ox - 10, oy - 10)
    text("30, 0", ox + dim/2, oy - 10)
    text("60, 0", ox + dim + 10, oy - 10)
    text("0, 30", ox - 30, oy + dim/2)
    text("60, 30", ox + dim + 30, oy + dim/2)
    text("0, 60", ox - 10, oy + dim + 10)
    text("30, 60", ox + dim/2, oy + dim + 10)
    text("60, 60", ox + dim + 10, oy + dim + 10)
    fill(255, 64)
    noStroke()
end

function draw()
    dt = maxDeltaTime/DeltaTime
 -- print(dt) -- Uncomment to see effect of print in draw()
    ellipse(ox + dim * dt, oy + dim * odt, 10)
    odt = dt
end
Tagged:

Comments

  • edited August 2012 Posts: 489

    'FPS Radar' below is another such experiment. Try touching in the empty Output pane and then dragging anywhere to cause draw() to be skipped while EllapsedTime marches on. Also, on my iPad2, I can create a dip (red) and spike (green) that then repeats once a second.

    --
    -- FPS Radar
    --
    supportedOrientations(LANDSCAPE_ANY)
    backingMode(RETAINED)
    function setup()
        background(0)
        dim = math.min(WIDTH, HEIGHT) * 0.5 / 2
        cx = WIDTH/2
        cy = HEIGHT/2
        maxDeltaTime = 1/60
        twoPi = 2 * math.pi
        parameter("dummy") -- Just for experimentation
    end
    
    function draw()
        local a = ElapsedTime * twoPi
        local ratio = maxDeltaTime/DeltaTime
        local radius = ratio * dim
        fill(0, 10)
        noStroke()
        rect(0, 0, WIDTH, HEIGHT)
        local r = 255
        local g = 255
        local b = 255
        if ratio > 1.1 then r = 0; b = 0 end
        if ratio < 0.9 then g = 0; b = 0 end
        stroke(r, g, b)
        strokeWidth(10)
        line(cx, cy, cx + math.cos(a) * radius, cy + math.sin(a) * radius)
    end
    
  • Posts: 384

    Hi @mpilgrem, dragging or scrolling from the text output has paused my programs from the beginning I think. I actually got used to it and used it as an easier-to-hit pause... But I suppose it shouldn't be that way! :)

    I like the visualisations!

  • edited August 2012 Posts: 123

    This inspired me to add some frame rate history to my frame rate library. When I develop animations, I often see some jerky movements. I was not able to break down from where it comes, but with the frame rate history, I could now see it -> It only happens, when started in standard mode. When I start in full screen, then the framerate is always ok. When started in standard mode, the framerate drops every 5th or so frame. When playing around with the parameters and scrolling in the print output (although its empty), suddenly the problems are gone.

    Have a look at the two screenshots, the first with the jerky movement, the second with normal movement. The framerate is shown for the last 100 frames as vertical bars from red to green:

    https://dl.dropbox.com/u/80475380/CodeaForumPictures/framerate_jerky.JPG

    https://dl.dropbox.com/u/80475380/CodeaForumPictures/framerate_stable.JPG

Sign In or Register to comment.