Guest User

Untitled

a guest
Jun 30th, 2009
415
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "timer.h"
  2. #include <time.h>
  3.  
  4. int32 TTimer::MulDiv64(int64 nNumber, int64 nNumerator, int64 nDenominator) {
  5.   return (int32) ((nNumber * nNumerator) / nDenominator);
  6. }
  7.  
  8. TTimer::TTimer() {  
  9.   msOffset = 0;
  10.     QueryPerformanceFrequency((LARGE_INTEGER*)&counterFrequency);
  11. }
  12.  
  13. void TTimer::start(void) {
  14.     QueryPerformanceCounter((LARGE_INTEGER*)&startValue);
  15. }
  16.  
  17. int32 TTimer::getMs(void) {
  18.     QueryPerformanceCounter((LARGE_INTEGER*)&actualValue);
  19.   actualValue -= startValue;
  20.     return MulDiv64(actualValue, 1000, counterFrequency) + msOffset;
  21. }
  22.  
  23. void TTimer::setOffset(int32 offset) {
  24.     msOffset = offset;
  25. }
  26.  
  27. int32 TTimer::getPrecisionTimeCount(int32 precision) {
  28.     QueryPerformanceCounter((LARGE_INTEGER*)&actualValue);
  29.     actualValue -= startValue;
  30.     return MulDiv64(actualValue, precision, counterFrequency);
  31. }
  32.  
  33. int32 TTimer::getCurrentFrame(int32 totalframes, int32 totalms) {
  34.     QueryPerformanceCounter((LARGE_INTEGER*)&actualValue);
  35.     actualValue -= startValue;
  36.     int32 t=MulDiv64(actualValue, 1000, counterFrequency)+msOffset;
  37.     return MulDiv64(totalframes, t, totalms);
  38. }
  39.  
  40. int32 TTimer::getTicks(void) {
  41.     QueryPerformanceCounter((LARGE_INTEGER*)&actualValue);
  42.     actualValue -= startValue;
  43.     return (int32) actualValue;
  44. }
  45.  
  46. int32 TTimer::getTicksPerSecond(void) {
  47.     return (int32) counterFrequency/1000;
  48.  
  49. }
RAW Paste Data