Game Development Reference
In-Depth Information
Lastly, we calculate our FPS based on the duration of the previous frame. We simply
take StopWatch.Frequency and divide it by the duration of the previous frame.
The parameter of the UpdateScene() method is the amount of time that has
elapsed since the last time UpdateScene() was called. So we calculate that by
subtracting the previous frame's time from the current frame's time. We then di-
vide by StopWatch.Frequency to convert the result into seconds. This is neces-
sary because the StopWatch.GetTimeStamp() function returns the current time
in ticks. Essentially, it is a count of how many ticks have elapsed on the system timer
since Windows was last booted up. The StopWatch.Frequency property tells us
how many ticks our system timer does in one second. This is important because
the timer in one computer may be faster or slower than the timer in another. The
RenderScene() method is mostly empty for now too, but it does have a simple if
statement in it though. Here is its code:
public virtual void RenderScene()
{
if ((!this.IsInitialized) || this.IsDisposed)
{
return;
}
}
The if statement in the RenderScene() method checks to see if the game window
is ready for rendering. If the game window has not been initialized yet, or if the game
window has been disposed of, then we simply return out of this function. This is im-
portant because it prevents possible crashing when the game window first starts up
and when it shuts down.
Note that IsInitialized and IsDisposed are two of the properties we talked
about earlier for our member variables.
We almost have a functional GameWindow class now. But we need to add a
StartGameLoop() method. This method is called to start up the game loop. It only
contains the following few lines of code:
Search WWH ::




Custom Search