Game Timer In C++

Posted by user1870398 on Game Development See other posts from Game Development or by user1870398
Published on 2012-12-13T06:44:50Z Indexed on 2012/12/13 11:22 UTC
Read the original article Hit count: 377

Filed under:
|
|

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);
    }
}

© Game Development or respective owner

Related posts about c++

Related posts about game-mechanics