#include "timer.h"
#include <time.h>
 
int32 TTimer::MulDiv64(int64 nNumber, int64 nNumerator, int64 nDenominator) {
  return (int32) ((nNumber * nNumerator) / nDenominator);
}
 
TTimer::TTimer() {  
  msOffset = 0;
	QueryPerformanceFrequency((LARGE_INTEGER*)&counterFrequency);
}
 
void TTimer::start(void) {
	QueryPerformanceCounter((LARGE_INTEGER*)&startValue);
}
 
int32 TTimer::getMs(void) {
	QueryPerformanceCounter((LARGE_INTEGER*)&actualValue);
  actualValue -= startValue;
	return MulDiv64(actualValue, 1000, counterFrequency) + msOffset;
}
 
void TTimer::setOffset(int32 offset) {
	msOffset = offset;
}
 
int32 TTimer::getPrecisionTimeCount(int32 precision) {
	QueryPerformanceCounter((LARGE_INTEGER*)&actualValue);
	actualValue -= startValue;
	return MulDiv64(actualValue, precision, counterFrequency);
}
 
int32 TTimer::getCurrentFrame(int32 totalframes, int32 totalms) {
	QueryPerformanceCounter((LARGE_INTEGER*)&actualValue);
	actualValue -= startValue;
	int32 t=MulDiv64(actualValue, 1000, counterFrequency)+msOffset;
	return MulDiv64(totalframes, t, totalms);
}
 
int32 TTimer::getTicks(void) {
	QueryPerformanceCounter((LARGE_INTEGER*)&actualValue);
	actualValue -= startValue;
	return (int32) actualValue;
}
 
int32 TTimer::getTicksPerSecond(void) {
	return (int32) counterFrequency/1000;
 
}
 
 

Download timer.cpp timer.cpp - 1.3 KB