Sign in to follow this  

"Frames" per second in Win32 console application

This topic is 1890 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

Hi, I am wondering if there is a function such as SDL_GetTicks() native to windows? I want to limit how often my update and draw methods execute inside my console application.

I am making an ascii game. Any help is appreciated, thanks.

Share this post


Link to post
Share on other sites
Off the top of my head:
[tt]timeGetTime[/tt] (winmm.lib, millisecond resolution, and deprecated?)
[tt]GetPerformanceFrequency[/tt] and [tt]GetPerformanceCounter[/tt] (highest resolution timer, may be inconsistent across multiple cores)

There may be others...
Edited by fastcall22

Share this post


Link to post
Share on other sites
[quote name='dAND3h' timestamp='1352760491' post='5000362']
Hi, I am wondering if there is a function such as SDL_GetTicks() native to windows? I want to limit how often my update and draw methods execute inside my console application.
[/quote]

If you are able to use the new c++11 standard try to use the new chrono date and time utilities found here: http://en.cppreference.com/w/cpp/chrono
Note that using chrono is a little less than straightforward but here is a complete chrono timer class: http://codepad.org/FHkSQKiO

Share this post


Link to post
Share on other sites
I've been using the C function clock(), which is a part of the C include time.h.. There is also a define in time.h 'CLOCKS_PER_SEC' which allows you to effectively do something like:
[source lang="cpp"]
#include <time.h>

float gettime()
{
return (float)clock() / CLOCKS_PER_SEC;
}
[/source]
This has worked sufficiently well for the majority of my purposes, and being that it is a part of C itself it is as portable as portable can get.

Share this post


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