"Frames" per second in Win32 console application

Started by
3 comments, last by deftware 11 years, 5 months ago
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.
Advertisement
Off the top of my head:
timeGetTime (winmm.lib, millisecond resolution, and deprecated?)
GetPerformanceFrequency and GetPerformanceCounter (highest resolution timer, may be inconsistent across multiple cores)

There may be others...
GetTickCount()
is another, but it's not very reliable.
what

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.


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
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.

This topic is closed to new replies.

Advertisement