This wiki is out of date, use the continuation of this wiki instead

Frame time

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 00:19, 21 January 2008 (edit)
Sandman (Talk | contribs)
m (Example)
← Previous diff
Current revision (09:54, 24 March 2008) (edit) (undo)
Sandman (Talk | contribs)
m (Example)
 
Line 60: Line 60:
</pre> </pre>
-This can be done with a timer too, as is displayed [[timer#Example|here]], along with an example on how to measure time using frame_time.+This can be done with a timer too, as is displayed [[timer#Example|here]].
{{Globals}} {{Globals}}

Current revision

Up to Global Variables



[edit] Definition

FLOAT frame_time

Frame_time is a global variable, holding the time passed the last frame. In other words: the difference in time between the start of the last frame and the current frame.

Doing a bit of physics, we see that:

FPS = 1 / frame_time

Be advised that frame_time is in milliseconds accurate, so it can be 0 at times, so one might prevent such a case from happening:

FPS = 1 / ( frame_time + (frame_time==0)*0.0001 );

This gives a sort of FPS which is accurate every frame.

[edit] Example

Display how long the program has been running, by use of frame_time:

Program timers;
Private
    int ft; // Help variable
    int i;  // how long the program has been running in 1/100s
    float f; // how long the program has been running in 1/100s
Begin

    set_mode(320,400,8);
    write_int   (0,0,300,0,&timer);
    write_int   (0,0,310,0,&i);
    write_float (0,0,320,0,&f);

    Repeat

        // Calculate how long the program has been running in 1/100s without a float
        ft %= 10; // keep the milliseconds from last time
        ft += frame_time*1000; // add the last passed time to it in milliseconds
        i += ft/10; // add it to the integer without the milliseconds

        // Calculate how long the program has been running in 1/100s with a float
        f+=frame_time*100;

        frame;
    Until(key(_ESC))

End

Used in example: set_mode(), write_int(), write_float(), key(), timer

Let a process wait for a certain time by calling this function:

Function int wait(float seconds)
Begin
    While( (seconds-=frame_time) > 0 ) frame; End
    return -seconds;
End

This can be done with a timer too, as is displayed here.


Global variables
ArgcArgvCdinfoDump_typeFadingFileinfoFpsFrame_timeFull_screenGraph_modeMouseOs_idRestore_typeScale_modeScrollSound_channelsSound_freqSound_modeText_flagsText_zTimer
Personal tools