Skip to main content
edited tags
Link
bobobobo
  • 17.2k
  • 10
  • 67
  • 99
Source Link
LiquidFeline
  • 1.4k
  • 2
  • 13
  • 32

Game Timer In C++

I need to be able to find out how many milliseconds since that last update. Is there any way I can find it out with time rather then a thread that counts like I did below?

#include <iostream>
#include<windows.h>
#include<time.h>
#include<process.h>

using namespace std;

int Timer = 0;
int LastTimer = 0;
bool End = false;

void Update(int Ticks)
{

}

void UpdateTimer()
{
    while (true)
    {
        LastTimer = Timer;
        Timer++;
         Sleep(1);
        if (End)
            break;
    }
}

int WINAPI WinMain(HINSTANCE par1, HINSTANCE par2, LPSTR par3, int par4)
{
    _beginthread(UpdateTimer, 0, NULL);
    while(true)
    {
        if (Timer == 1000)
        Timer = 0;
        Update(Timer - LastTimer);
    }
}