timer.h

来自「一个纹理地形渲染器」· C头文件 代码 · 共 53 行

H
53
字号
// DirectX Timer

#pragma once

#include "System/Timer.h"

namespace DirectX
{
    /// %DirectX implementation of %Timer.
    /// In the future we should find a solution that allows
    /// sharing of the Windows implementation of Timer across DirectX and OpenGL.
    /// Uses QueryPerformanceCounter internally.

    class Timer : public System::Timer
    {
        public:

            /// default constructor.
            /// clears time and delta to 0.0f.

		    Timer()
		    {
                QueryPerformanceFrequency((LARGE_INTEGER*)&_frequency);
			    QueryPerformanceCounter((LARGE_INTEGER*)&_counter);
			    _time = 0.0;
                _delta = 0.0;
		    }

		    double time()
		    {
			    __int64 new_counter;
			    QueryPerformanceCounter((LARGE_INTEGER*)&new_counter);
			    __int64 delta = new_counter - _counter;
                _delta = delta / (float) _frequency;
			    _time += _delta;
			    _counter = new_counter;
			    return _time;
		    }

            double delta()
            {
                return _delta;
            }

        private:

            double _time;               ///< current time in seconds
            double _delta;              ///< current delta in seconds
            __int64 _counter;           ///< raw 64bit timer counter
            __int64 _frequency;         ///< raw 64bit timer frequency
    };
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?