Hey guys, I was looking into the performance impact of passing by reference vs passing by value. I know it's not necessary right now, but I was curious. The easiest way for me to do this was informally making a simple FPS counter. I have it display to the title bar rather than going through the process of putting a child window on the screen to display the text.
Windows implementation, as I haven't started cross platforming yet:
Before the GlobalRunning loop, declare some variables to hold frames and times. Initialize to 0.
| DWORD Frames = 0;
DWORD CurrentTime = 0;
DWORD PreviousTime = 0;
DWORD ElapsedTime = 0;
TCHAR FPS[32] = {};
|
Then inside the GlobalRunning loop, after doing everything else in it (or before doing everything, just not in the middle of the loop), update the frames and do calculations to see if it's been a second. If it has, create a string that labels the FPS and pass it to the window.
1
2
3
4
5
6
7
8
9
10
11
12 | Frames++;
CurrentTime = timeGetTime(); // More reliable than GetTickCount(); [1]
ElapsedTime = CurrentTime - PreviousTime;
if (ElapsedTime >= 1000) // In milliseconds, so 1000 == 1 second
{
sprintf(FPS, "FPS: %u\n", (UINT)(Frames * 1000.0 / ElapsedTime));
Frames = 0;
PreviousTime = CurrentTime;
}
SetWindowText(Window, TEXT(FPS));
|
Lastly, you need to add winmm.lib as a linked library to your compile line.
[1]:
http://blogs.msdn.com/b/larryoste...gettickcount-and-timegettime.aspx
NOTE: I am not fully caught up on the episodes, so if this has been implemented in the main stream then I apologize.
PS: First post, hello everyone.