Class Clock

Synopsis

#include <Source/Falcor/Utils/Timing/Clock.h>

class dlldecl Clock

Description

A clock. This class supports both real-time clock (based on the system's clock) and a fixed time-step clock (based on tick count)

Mentioned in

Methods

Clock
getDeltaGet the time delta between the 2 previous ticks
getExitFrameGet the frame at which to terminate the application.
getExitTimeGet the time at which to terminate the application.
getFrameGet the current frame ID
getFramerateGet the requested FPS value
getRealTimeDeltaGet the real-time delta between the 2 previous ticks
getScriptGet the script string
getTimeGet the time of the last tick() call
getTimeScaleGet the scale
isPausedCheck if the clock is paused
isSimulatingFpsCheck if the clock is in real-time mode
pausePause the clock
playResume the clock
renderUIRender the UI
setExitFrameSet the frame at which to terminate the application.
setExitTimeSet the time at which to terminate the application.
setFrameSet the current frame ID
setFramerateSet the requested FPS to simulate, or disable FPS simulation
setTimeSet the current time
setTimeScaleSet the time scale
shouldExitCheck if the application should be terminated.
shutdownEnd the system
startStart the system
stepStep forward or backward
stopStop the clock (pause + reset)
tickTick the clock

Source

Lines 36-186 in Source/Falcor/Utils/Timing/Clock.h.

class dlldecl Clock
{
public:
    Clock();
    /** Start the system
    */
    static void start();
    /** End the system
    */
    static void shutdown();
    /** Set the current time
        \param[in] seconds The time in seconds
        \param[in] deferToNextTick Apply the change on the next tick. No changes will be made to the clock until the next tick
    */
    Clock& setTime(double seconds, bool deferToNextTick = false);
    /** Get the time of the last `tick()` call
    */
    double getTime() const { return mTime.now; }
    /** Get the time delta between the 2 previous ticks. This function respects the FPS simulation setting
        Note that due to floating-point precision, this function won't necessarily return exactly (1/FPS) when simulating framerate.
        This function will potentially return a negative number, for example when resetting the time to zero
    */
    double getDelta() const { return mTime.delta; }
    /** Set the current frame ID. Calling this will cause the next `tick()` call to be skipped
        When running in real-time mode, it will only change the frame number without affecting the time
        When simulating FPS, it will change the time to match the current frame ID
        \param[in] seconds The frame ID
        \param[in] deferToNextTick Apply the change on the next tick. No changes will be made to the clock until the next tick
    */
    Clock& setFrame(uint64_t f, bool deferToNextTick = false);
    /** Get the current frame ID.
        When running in real-time mode, this is the number of frames since the last time the time was set.
        When simulating FPS, the number of frames according to the time
    */
    uint64_t getFrame() const { return mFrames; }
    /** Get the real-time delta between the 2 previous ticks.
        This function returns the actual time that passed between the 2 `tick()` calls. It doesn't any time-manipulation setting like time-scaling and FPS simulation
    */
    double getRealTimeDelta() const { return mRealtime.delta; }
    /** Set the time at which to terminate the application.
    */
    Clock& setExitTime(double seconds);
    /** Get the time at which to terminate the application.
    */
    double getExitTime() const { return mExitTime; }
    /** Set the frame at which to terminate the application.
    */
    Clock& setExitFrame(uint64_t frame);
    /** Get the frame at which to terminate the application.
    */
    uint64_t getExitFrame() const { return mExitFrame; }
    /** Check if the application should be terminated.
    */
    bool shouldExit() const;
    /** Tick the clock. Calling this function has no effect if the clock is paused
    */
    Clock& tick();
    /** Set the requested FPS to simulate, or disable FPS simulation.
        When enabling FPS simulation, calls to tick() will change the time by `1/FPS` seconds.
        If FPS simulation is disabled, calling `tick()` will add the actual time that passed since the previous `tick()` call
    */
    Clock& setFramerate(uint32_t fps);
    /** Get the requested FPS value
    */
    uint32_t getFramerate() const { return mFramerate; }
    /** Pause the clock
    */
    Clock& pause() { mPaused = true; return *this; }
    /** Resume the clock
    */
    Clock& play();
    /** Stop the clock (pause + reset)
    */
    Clock& stop() { setTime(0); return pause(); }
    /** Step forward or backward. Ignored if the Clock is running or not in FPS simulation mode
        \param[in] frames The number of frames to step. Can be negative
        The function will not step backward beyond frame zero
    */
    Clock& step(int64_t frames = 1);
    /** Set the time scale. This value is ignored when simulating FPS
    */
    Clock& setTimeScale(double scale) { mScale = scale; return *this; }
    /** Get the scale
    */
    double getTimeScale() const { return mScale; }
    /** Check if the clock is paused
    */
    bool isPaused() const { return mPaused; }
    /** Check if the clock is in real-time mode
    */
    bool isSimulatingFps() const { return mFramerate != 0; }
    /** Render the UI
    */
    void renderUI(Gui::Window& w);
    /** Get the script string
    */
    std::string getScript(const std::string& var) const;
private:
    struct Time
    {
        double now = 0;
        double delta = 0;
        void update(double time)
        {
            delta = time - now;
            now = time;
        }
    } mRealtime, mTime;
    uint32_t mFramerate = 0;
    uint64_t mFrames = 0;
    uint64_t mTicksPerFrame = 0;
    CpuTimer mTimer;
    bool mPaused = false;
    double mScale = 1;
    std::optional<double> mDeferredTime;
    std::optional<uint64_t> mDeferredFrameID;
    double mExitTime = 0.0;
    uint64_t mExitFrame = 0;
    void updateTimer();
    void resetDeferredObjects();
};





Add Discussion as Guest

Log in