Game Development Reference
In-Depth Information
Rendering and Presenting the Display
The DirectX 11 Framework provides a pretty good routine to render and present the
display. It is called from the DXUTMainLoop() function when the game is not pro-
cessing messages, in exactly the way the MainGameLoop() function was mentioned
earlier. The function is DXUTRender3DEnvironment11() inside Source\GCC4
\3rdParty\DX11\Core\DXUT.cpp around line 3816. Let ' s pick it apart so you can
understand what
t have permission to reprint this method,
you should launch Visual Studio and load either a DirectX sample or the Game Cod-
ing Complete 4 source code and follow along.
The first thing you should notice about this function is how much can go wrong, and
that it can pretty much go wrong after nearly every single line of code. The reason for
this is a quirk of Windows games
'
s going on. Since I don
'
players have an annoying tendency to actually
have other applications up, like Firefox or something, while playing your game! Any
kind of task switching, or user switching under XP or later, can cause DirectX to lose
its devices.
After getting a bunch of a DirectX objects and making sure they still exist, the func-
tion checks to see if rendering is paused, if the window is occluded, or if it ' s inactive.
If any of these conditions is true, it calls Sleep() to relinquish time back to other
applications. This is just part of being a nice Windows application, and even silly
Windows tools that have similar message pumps should do this. You might decide
to tweak the amount of time you sleep. Your mileage with the sleep values in the
framework could vary from game to game.
After all that, the code handles issues related to timers and timing. This is the section
of code that starts with DXUTGetGlobalTimer()->GetTimeValues() . Almost
every game needs to track how many milliseconds have elapsed since the last frame
so that animations and object movement can be kept in sync with reality. The alter-
native is to ignore time altogether and just render things based on each frame that
renders, but that would mean that faster computers would literally play the game
faster
sense but in an actual sense. If you keep track of time,
then objects on faster computers will still fall to the ground at the same rate as slower
computers, but the faster computers will look smooth as silk.
The next section of code retrieves and calls the application
not in the
gamer
s frame move callback func-
tion.Thiscallbackissetto GameCodeApp::OnUpdateGame() , which controls the
game logic and how the game state changes over each pass of the main loop. Control
passes to the game logic
'
s VOnUpdate() method, which will update all the running
game processes and send updates to all the game views attached to the game logic.
'
 
 
Search WWH ::




Custom Search