Multiple High Resolution Timer Class for Windows – C++
Earlier i had posted a tutorial on doing high resolution timing on windows and i’d given a very basic class to act as a timer, now i found when doing my graphics work i often needed multiple timers and so i just extended my baby timer class a little to support multiple timers.
So you can create as many timers as you need on the fly (the controller class acts as a big timer vector) and also get a pointer back for each timer if you wish to create a easily readable shortcut ie.
HRTimer* animationTimer = timers[5];
hope you find it useful: MHRTimer.h
FPT Toolkit and my first steps into win32
The screenshot above is my latest little project, a windows based tool for the decomposition of image using my fast pulse transform (FPT) technique. It needed to have a few features like file IO, pulse selections and highlighting of pulses. I’ve never done any sort of c++ winapi programming before apart from some windows forms stuff in c#. I figured since i’m busy messing around with win32 in my openGL and directX adventures, i might as well just use that. :/
Probably not the smartest decision, since the bare win api is c based and not c++ based and so the way the api is structured is based on c techniques. I’ll be honest and it took me a day or two to get used to it and to figure out how most things occurs and now i’ve pretty much got the gist of it. Now it comes down to using the msdn docs to find out what the flag values i need are, and trying to figure out when specific messages are sent. I’ve got a very basic grasp of it at the moment. I wish i could spend more time messing around with it but i need to focus on this semester and finish learning directx 10. And even so once that is done, i think i’m gonna focus on learning MFC or windows forms even as it seems the bulk of development is done using these APIs. From what i can see most window game dev toolsets are developed in MFC.
So some last words about my app… i couldn’t for the life of me figure out how the fuck DIBs and HBITMAPS work (creating DIBs programmatically at least – the conversion from DIB to HBITMAP was simple enough) so i had to use openGL to display my 2D images (haha, oh well its not like people don’t have openGL videos cards these days). I just got the pulse selection and reconstruction saving working, just need to finish the highlighting section and its done (for now). I need to sit and think logically about what i want for the highlighting interface and then code it.
I have struggled these last few days trying to learn winapi programming from scratch using nothing more than google and the MSDN docs but at the same time I’ve learnt a lot and so its been worth it! OH and for a development environment: visual studio 2008 + vista 64 is a dream come true
High Resolution C++ Timing on Windows
Accurate Timing is something that seems simple until you actually try it, at first people would be like just get two timestamps and minus them, sure that works for per second timing but what about millisecond or even microsecond timing?
Just get 2 millisecond timestamps and minus them, right? No, the problem comes into that when the CPU is heavily loaded, often the timestamps will be significantly off, i noticed this in my surveillance project, where a specified time of 10seconds ended up being between 5 to 15 real seconds depending on the load on the processor.
So how do you do accurate high resolution timing in windows? Before people made use of the now antiquated Multimedia timers, these days you simple use the Windows API QueryPerformanceCounter and QueryPerformanceFrequency functions.
The QueryPerformanceCounter function call returns the value of the performance counter (in counts) at that point and the QueryPerformanceFrequency returns the amount of counts per second for that processor… You can see where i’m going with this, Simple huh?
The only other thing you need to take into account is that you need to make use of the LARGE_INTEGER union type for the count storage, since the count is a 64bit int you need to make use of the QuadPart (LongLong) of the union for storage.
here’s a very basic c++ timing class: HRTimer.h
