www.pudn.com > tomohide_fur.03.13.02.zip > timer.cpp
//----------------------------------------------------------------------------- // File: timer.cpp // // Copyright (C) 2001-2002 Tomohide Kano. All rights reserved. //----------------------------------------------------------------------------- #include#include "timer.h" static DWORD start = 0; static DWORD previous = 0; static DWORD current = 0; static DWORD count = 0; static DWORD interval = 1000; static float dt = 0.0; static float fps = 0.0; bool timerInit(float fps_interval) { timeBeginPeriod(1); start = previous = timeGetTime(); interval = int(fps_interval * 1000); return true; } void timerDestroy() { timeEndPeriod(1); } void timerUpdate() { current = timeGetTime(); dt = (current - previous) * 0.001f; previous = current; count++; if (current - start > interval) { fps = 1000 * count / float(current - start); start = current; count = 0; } } float timerGetDT() { return dt; } float timerGetFPS() { return fps; }