-2

I am currently writing an SDL2 game engine, and it works pretty good so far, but there is one problem that SDL2 can't solve: a decent timer. Right now, it uses the default SDL2 timer stuff, but it has only millisecond support; and this is not very good for measuring FPS. The main problem is there is nothing in between 500FPS and 1000FPS, so it's one or the other. Obviously, potential gamers would want something a little more accurate than that, and getting accurate averages from those numbers is near impossible.

So my question is is there any clock libraries that can provide nanosecond/microsecond (Preferably the former) time measuring on Windows, Mac, and Linux? (Maybe even Android and iOS, but that is a bit of a stretch.)

If not, is there different libraries for each OS I could just #if WINDOWS or whatever to still get nanosecond/microsecond timing?

EDIT: A comment pointed out that some more information should be here, so I am using C++ 14, and will be on Mac and Linux as well. On Windows, I use MSVC (Visual Studio) and I plan to use XCode on Mac, and not too sure for Linux. Will as a friend.

Vulkan
  • 77
  • 8

3 Answers3

1

What is about std::chrono? Steady clock could be fine.

Naszta
  • 7,560
  • 2
  • 33
  • 49
  • Upvoted. SFML is limited to microsecond precision even when the underlying OS supports nanosecond precision. `std::chrono` has superior functionality, portability and syntax (especially in C++14). – Howard Hinnant Feb 20 '16 at 02:18
0

I've been learning this new library lately and I think it might be able to help you out with your problem.

SFML http://www.sfml-dev.org/tutorials/2.3/

SFML/time http://www.sfml-dev.org/tutorials/2.3/system-time.php

Hope this helps.

Axios
  • 49
  • 2
0

GLFW has a timer that is pretty accurate. It is a millisecond timer as far as I know. GLFW is also a pretty decent library for window management and inputs such as mouse/keys/gamepads etc..

http://www.glfw.org/docs/3.0/group__time.html

Careful Now
  • 260
  • 1
  • 9