Home > c# > Best C++ Portable time library for game development

Best C++ Portable time library for game development

October 10Hits:1

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! :)


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.

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.

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.

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.


Related Articles

  • Best C++ Portable time library for game development October 10

    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 alte

  • Why netscape portable runtime libraryJanuary 26

    As an Ubuntu user, we often have updates. Today I saw an update titled "Netscape portable runtime library" and the file was tagged libnspr4. The only thing I can relate it to is FireFox but I'm not sure. So why does Ubuntu need a Netscape projec

  • Nuget from portable class library: Value cannot be null or an empty string. Parameter name: profileValueJanuary 15

    What I have I have Portable Class Library MyProj.Backend.Contracts.csproj that targets: .NET Framework 4.6 Windows Universal 10 ASP.NET CORE 5.0. I've created nuget from package from .nuspec where I specified the assemblies manually using nuget pack

  • Portable class library designFebruary 5

    I have a portable class library that, for example, exposes this interface method: public interface IPortablePainter { void PaintTheSky(PortableColor color); } Then, I need to define some platform-specific implementation, (totally invented, just for e

  • Nuget fails to add lightinject 4.0.6 to portable class libraryFebruary 6

    I'm trying to use lightinject for xamarin application. Common code is inside separate portable class library. This project is configured for TargetFrameWorkProfile Profile78. When I'm adding lightinject 4.0.6 following error appears: Attempting to ga

  • How to get all files/folders in a folder in Portable Class Library (PCL)February 14

    I have searched everywhere for a code sample but for the life of me I cannot find a working solution to get all files/folders in a particular folder in an Indexer library I am coding as a Portable Class Library. I was linked to What need I do to get

  • How can I get the word out about a new (open-source) library I've developed? May 5

    I'm finishing up a personal project in which I've implemented a library that I expect others may want to use. Without going into too much detail, the library provides a cross-platform interface for parsing a particular type of file, where none had ex

  • Is GNU PDF Library in active development?May 16

    I've been hearing about The GNU PDF Library since 2007. Since then I've been looking forward to see this tool in the wild, but four years have passed and it seems to me that this is a painfully long time. I'm aware of the complexities of the project,

  • Best portable console platform for game development?September 30

    I'm looking to experiment on a portable console platform ala Nintendo DS and PSP. But it could also be GP32, GP2X, GP2X Wiz or GP2X Caanoo. So, before I go out and buy one, I'd like to hear from people who have experience with any portable console. I

  • How to structure project where a library and application using the library are concurrently developed?June 22

    I am planning to develop a new application that will heavily use a library that will be developed from scratch specifically for the application, but made general enough for it to be used for other programs once it's finished. So the development of th

  • Surrogate types for serialization in C# Portable Class LibraryFebruary 9

    I am currently porting code to a PCL (Key targets .NET 4.5 + mobile via Xamarin) and am running into a familiar issue, serialization of classes derived from non-serializable dependencies. I am using DataContract/Member attributes with DataContractJso

  • Source control: projects which share a 3rd library which is still under development in RTCMay 27

    this is not a new question for source control, but IBM's Rational Team Concert is a slightly different animal than Git, SVN, etc. We have a number of .NET web sites under development with Visual Studio. Each web site is represented by a VS solution.

  • Issues with Adobe Lightroom Library vs Develop modules

    Issues with Adobe Lightroom Library vs Develop modulesJanuary 18

    Please help: I've been having a bizarre, frustrating issue for quite some time . . . In general my workflow is: (a) launch Adobe LR CC (ver 2015.2.1), browse images in the Library Module; (b) open desired image in Develop Module . . . (c) apply adjus

  • What is exactly the meaning of "portability"?February 24

    I know very well that java is a portable language..and it is the byte-code that makes it portable.. However I've studied also that C is a portable language. "The programs written in C are portable i.e. programs written for one type of computer or ope

  • 2D game development with C++ July 13

    I'm pretty newbie in this things and I've never really had particular experience in game developing. I started learning something about 3D (using 3Ds Max and then Blender) and then 3D game developing using OpenGL. While with 3D i found it very easy t

  • Bringing Unicode to PHP with Portable UTF-8September 10

    PHP allows multibyte variable names like $a∩b, $Ʃxy and $Δx, mbstring and other extensions work with Unicode strings, and the utf8_encode() and utf8_decode() functions translate strings between the UTF-8 and ISO-8859-1 encodings. Yet it's widely ackn

  • GPLed Library (EXT JS) Licensing IssueOctober 15

    Good Day Everyone, I am realy out of option for interpreting the GPL for EXTJS for my work/idea/personal project. I can see that this is an active forum I realy hope, I have a closure on this. First let me explain my project, Iam creating this websit

  • Is my "engine" development process ideal? August 5

    I was thinking about a game engine development, I understand as engine the main program that can develope next duties: Receives parameters. calculates what is needed. Delivers results. As an example lets say I'm writing an sports game, so I was think

  • Setting up iPhoto library on external HDDJanuary 5

    Is there any way to set iPhoto library on external HDD instead of main HDD. I have a lot of photos and am running out of space on my MBP. I was thinking to achieve it by symlinks or something. It this possible at all? If not, I'd be glad if anyone co

  • SharePoint 2007 merge nested document library itemsMay 9

    is it possible to collect (i.e. merge, consolidate, de-normalize, etc.) items from multiple nested document libraries on a site? My manager wants to flatten our MOSS 07 site's current nested hierarchical directory list structure and combine all items

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.494 s.