Game Development Reference
In-Depth Information
'
Luckily, I
ve included an entire chapter on the subject of file systems and the resource
cache. This just might be one of the most under-discussed topics in game development.
Managing Memory
Managing memory is a critical system for games, but it is largely ignored by most
game developers until they run out of it. Simply put, the default memory manager
that comes with the default C-runtime libraries is completely unsuitable for most
game applications. Many game data structures are relatively tiny things, and they
belong in different areas of memory, such as RAM or video memory. A general
memory manager tries to be all things to all applications, where you will know
every detail about how your game needs and uses memory. Generally, you ' ll write
your own memory manager to handle allocations of various sizes and persistence
and more importantly to track budgets.
Virtual Memory
Can Be Good, Can Be Bad
Windows can use virtual memory, and when a game runs out of physical
memory, the OS will automatically begin to use virtual memory. Sometimes,
Windows games can get away with this, but it is a little like playing Russian
roulette
at some point, the game will slow to a crawl. A console game is
completely different. For example, if your game allocates a single byte larger
than the available memory, it will crash. Every game programmer should be as
careful about memory as console programmers. Your game will run faster and
will simply be more fun. Create some way to track every byte of memory,
which subsystem is using it, and when any one of these areas exceeds its
memory budget. Your game will be better for it.
Initialization, the Main Loop, and Shutdown
Most software waits for the user to do something before any code is executed. If the
mouse isn
t being hammered, an application like
Microsoft Excel is completely idle. This is good because you can have a bunch of
applications up and running without a large CPU overhead. Games are completely
different. Games are simulations that have a life of their own. Without player input,
they
'
t moving and the keyboard isn
'
'
ll happily send some horrific creature over to start pounding on your character
'
s
skull. That will probably motivate a few button presses.
The system that controls this ongoing activity is the main loop, and it has three
major components: grabbing and queuing player input, ticking the game logic, and
presenting the game state to all the game views, which means rendering the screen,
playing sounds, or sending game state changes over the Internet.
 
 
 
Search WWH ::




Custom Search