Jump to content
  • Advertisement
Sign in to follow this  
acdc123

Game runs faster in some computer..

This topic is 2562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color="#1C2837"]I'm creating a rhythm style game in C++ where the notes come down the screen and you have to hit a key that corresponds to that note within the correct time, I'm sure we all know those type of games by now.

[color="#1C2837"]I currently have the following code in controlling the frame rate of the game:

[color="#1c2837"]
DWORD time_count; = 20; // ms per frame
LONGLONG next_time; = 0; // time to render next frame
LONGLONG cur_time; = 0; // current time
BOOL move_flag; = TRUE; // flag noting if we have moved yet


if (move_flag)
{
// yes, move and clear flag
actualGame->update();
move_flag = FALSE;
}

QueryPerformanceCounter((LARGE_INTEGER *) &cur_time);

// is it time to render the frame?
if (cur_time > next_time)
{
// yes, render the frame
actualGame->draw();
// set time for next frame
next_time += time_count;

// If we get more than a frame ahead, allow us to drop one
// Otherwise, we will never catch up if we let the error
// accumulate, and message handling will suffer
if (next_time < cur_time)
{
next_time = cur_time + time_count;
}

// flag that we need to move objects again
move_flag = TRUE;
}



[color="#1c2837"]
The problem, however is that the game runs normally on SOME computers but runs extremely faster on SOME computers as well ( fast in terms of how quickly the notes fall down on the screen).
[color="#1C2837"]In moving down the notes, I just increment a note's Y position by some constant (based on song tempo) every game "update phase".

[color="#1C2837"]Am I missing something?? Am I doing it wrong??

[color="#1C2837"]Thanks!

Share this post


Link to post
Share on other sites
Advertisement
QueryPerformanceCounter doesn't return miliseconds. QueryPerformanceCounter returns computer specific counter. To convert it to absolute seconds you must divide value with frequency. Frequency is how how much this counter value is per second. To get frequency use QueryPerformanceFrequency.
Basically what you must do:
LARGE_INTEGER freq, t1, t2;
QueryPerformanceFrequency(&freq);

QueryPerformanceCounter(&t1);
// ... do some work here
QueryPerformanceCounter(&t2);

printf("Elapsed milliseconds = %f\n", 1000.0 * (t2.QuadPart - t1.QuadPart) / freq.QuadPart);

Share this post


Link to post
Share on other sites

QueryPerformanceCounter doesn't return miliseconds. QueryPerformanceCounter returns computer specific counter. To convert it to absolute seconds you must divide value with frequency. Frequency is how how much this counter value is per second. To get frequency use QueryPerformanceFrequency.
Basically what you must do:
LARGE_INTEGER freq, t1, t2;
QueryPerformanceFrequency(&freq);

QueryPerformanceCounter(&t1);
// ... do some work here
QueryPerformanceCounter(&t2);

printf("Elapsed milliseconds = %f\n", 1000.0 * (t2.QuadPart - t1.QuadPart) / freq.QuadPart);



Is it safe to assume QueryPerformanceCounter is supported by all computers today?

Share this post


Link to post
Share on other sites

Is it safe to assume QueryPerformanceCounter is supported by all computers today?


No. But if someone's computer is so old it doesn't have that function, it'll be too old to run your game too.

Share this post


Link to post
Share on other sites

Is it safe to assume QueryPerformanceCounter is supported by all computers today?

You might want to read this. In particular, recommendation #4 is very relevant now because most computers will have multiple cores.

Share this post


Link to post
Share on other sites
I don't remember where i found this timer class, (last post at the bottom) but it always worked great for me, i also integrated an fps counter, which is optional. The returned value from Tick() is a float, for example, if it return 0.5 that mean half a second has passed since the last time you called this function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!