TheCherno / Sparky

Cross-Platform High Performance 2D/3D game engine for people like me who like to write code.
Apache License 2.0
1.1k stars 222 forks source link

Universal Timer #16

Closed Zelif closed 9 years ago

Zelif commented 9 years ago

Decided to quickly remove the windows dependency for the timer class. Only downfall is it requires Cx11(if someone needs earlier porting it with boost shouldnt be too hard)

#pragma once

#include <chrono>

namespace sparky {

    class Timer
    {
    private:
        typedef std::chrono::high_resolution_clock hrClock;
        typedef std::chrono::duration<float, std::milli> milliseconds_type;
        std::chrono::time_point<hrClock> m_Start;
    public:
        Timer()
        {
            reset();
        }

        void reset()
        {
            m_Start = hrClock::now();
        }

        float elapsed()
        {
            return std::chrono::duration_cast<milliseconds_type>(hrClock::now() - m_Start).count() / 1000.0f;
        }

    };

}
TheCherno commented 9 years ago

Added in Ep. 20. Thanks! :)