Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm venturing into the dark world of portable development and I'm looking for a nice library to keep track of system time for all game events. So far I've turned to trust boost and found:

This boost library

But I'm wondering if it there are some alternatives. I use boost a lot and (while I like it) I find that it sometimes takes me longer to figure out how to use the generic code than to write my own...not-so-generic code. (Ya, ya...I know. I should be less lazy). But anyway, advice appreciated! :)

share|improve this question
how much portable do you want your code to be? is it enough if it only supports VS and GCC (linux and unix based systems)? –  Ali.S Oct 10 '12 at 21:01
@Gajoo - great question. And yes, GCC and VS based systems. I want to support Windows, Linux, Mac. No handheld support is necessary. –  Darkenor Oct 10 '12 at 21:08
Maybe they didn't have these same rules in the 80s, but this site is for questions that have a specific correct answer. What you're asking here is just generating a list (sort of like a discussion). Refresh yourself on the FAQ to see what kinds of questions to ask here. –  Byte56 Oct 10 '12 at 22:22
add comment

closed as not constructive by Byte56, Nicol Bolas, Maik Semder, Jari Komppa, Jonathan Hobbs Oct 11 '12 at 13:33

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

5 Answers

As general rule you should avoid to add more dependecies than the ones you really need and try to semplify the building process or keep it as simple as you can.

I honestly don't like the boost libraries because of their own build system and the fact that they use too much abstraction, meaning that most of the time there is a significative loss in terms of performance. They are also not so easy to port to new platforms, for example the boost libraries on Android are not really easy to port but Android provides complete support for a C++ toolchain, the problem is just the building system adopted by the boost project; also the boost libraries have a significative amount of Mb, meaning that they take time to build, debug and they make your application larger.

I know that i'm pedantic on this but this are the downpoints in my opinion, the boost libraries still are a great package in the C++ world, but for some specific task like the one that you describe i would just consider writing my own wrapper and probably this will contribute to keep everything else much easier to handle. I think that you will appreciate the boost libraries if you are going to use them for at least 3-4 generic tasks, and with tasks i mean the "names" of the internal libraries in the boost library; with this usage you can consider adopting boost libraries, otherwise i don't think that they will be worth the trouble.

If you are already using the boost libraries just keep using them and try to avoid adding new dependecies to your project, there are also the platinum libraries which are kinda like an alternative to the boost libraries.

share|improve this answer
add comment

If you are looking for C++ to work with time try POCO. That's the second most general C++ library. The third is obviously is Qt.

share|improve this answer
add comment

Any game developer worth their salt should understand and be able to quickly write their own timekeeping implementations. This is too crucial to the very concept of developing any kind of real-time simulation, to pass the job of writing that code off to someone else. An excellent introduction to the topic is Glenn Fiedler's "Fix your Timestep", which has been quoted over and over and this site and will be quoted many times more.

The gist is that timekeeping is crucial to determinism in:

  • Physics
  • AI
  • Networking
  • General game logic
  • Rendering (less important, but still important)

A deterministic simulation is one you can debug more easily, and thus develop more fruitfully, because using the same set of inputs, you will always get the same set of outputs. So you can reproduce bugs and undesirable emergent conditions instantly using program logs from a previous run where that problem was observed. An excellent source on how crucial this can be is "1500 Archers on a 28.8" which is about the development of Age of Empires.

share|improve this answer
I agree that timing is of critical importance, but I think it's disingenuous to conflate timing with the game loop. He's not asking for a game loop, which is what the article you linked is really about. It's perfectly reasonable to want to defer to a tested timing implementation, given how extremely thorny the issues can be in practice (see my answer for details). –  Neverender Oct 11 '12 at 0:26
add comment

If you are interested in the nitty gritty reality of high resolution timing on the PC, you should read the article Timing Pitfalls and Solutions by Jan Wassenberg. It is 5 years old now, but unfortunately the landscape has not improved significantly as far as I'm aware.

You may also be interested in the related GameDev.net discussion thread and article. Unfortunately, the formatting is badly broken on the latter, presumably from years of site redesigns, but the content by and large appears to simply be an earlier iteration of what's in the PDF I linked above.

The forum thread in particular has links that are supposed to go to source code, but they all 404 at this point. The article, meanwhile, has a small snippet of code at the bottom that you can get to a semi-readable view of by looking at the article revision history.

share|improve this answer
add comment

Sorry for this dirty answer but here is my solution! I've used this code both in VS 2010 and xCode. Since the xCode version is based on linux tutorials I assume it works there you, any way you might want to clean somethings in there but it should work without any problems by itself. just use it like how you use unix gettimeofthe day variable.

#pragma once
#ifdef _WIN32
#include <windows.h>
#include <sys/time.h>

class Timer
#ifdef _WIN32
    struct timezone
        int tz_minuteswest;
        int tz_dsttime;
    struct timeval {
        long tv_sec;
        long tv_usec;
    int gettimeofday(timeval* tp,timezone* tzp)
        LARGE_INTEGER ticksPerSecond;
        LARGE_INTEGER tick;

        tp->tv_sec = tick.QuadPart / ticksPerSecond.QuadPart;
        tp->tv_usec = ((tick.QuadPart % ticksPerSecond.QuadPart) * 1000000) /ticksPerSecond.QuadPart;
        return 1;
    typedef struct ::timeval timeval;
    typedef struct ::timezone timezone;

I've once heard that QueryPerformanceCounter is not very accurate due to the fact that these days processors may change their frequencies. But it worked fine on my coreI7 cpu so I guess that was not causing any problems.

share|improve this answer
sidenote: it also worked on iPhone! –  Ali.S Oct 10 '12 at 21:23
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.