Programming for the Windows 95 Game SDK

Jason Robar

July 13, 1995

The Windows 95 Game Software Developers Kit (SDK) offers game developers new tools and technology to help create high-performance games.

The Game SDK provides a standard set of system services. Under MS-DOS, developers had to implement and maintain such services themselves. The SDK also meets or exceeds the functionality available on the next generations of game consoles, while enabling functionality unique to the PC game platform.

The role of Windows 95

Windows 95 makes installing and configuring games and game peripherals easier with features such as Plug and Play and AutoPlay.

Currently, the Windows 95 game subsystem is available only as part of the Windows 95 Game SDK but will be built into future versions of Windows. The game subsystem is royalty-free, and the run-time library will be redistributed by game developers with their Windows 95-based games.

The Game APIs provide device independence and broad hardware support for a wide range of game peripherals without sacrificing speed or functionality. The architecture is based on the Component Object Model (COM). For an introductory look at COM, see "COM: A Model Problem Solver," MSDN_COMODEL Developer Network News, March/April 1995.

The Game SDK provides the following functionality:

• DirectDraw for high-speed graphics

• DirectSound for sound mixing

• DirectPlay for multiplayer communication

• DirectInput for handling game input devices

DirectDraw

DirectDraw provides a device-independent way for games and Windows library software, such as 3-D graphics packages or digital video codecs, to access display device-dependent features. It allows direct linear manipulation of video display memory, hardware blters, hardware overlays, page flipping, and control of the palette and mode setting on the fly. This enables better graphics for animation.

By using DirectDraw, programmers will have access to features that previously required device dependence, such as:

• Support for multiple-buffered and page-flipped animation.

• Access to and control of the video card blter.

• Hardware-assisted overlays with z ordering.

• Support for 3-D z buffers.

• Direct access to 3-D texture maps with or without palettes.

• Tight integration with 3-D hardware acceleration.

• Improved video playback quality through access to YUV color formats.

• Improved graphics and video quality through access to image-stretching hardware.

• Translucency.

• Transparency.

DirectDraw is composed of three major components:

• The DirectDraw object manages the DirectDraw drivers' global functionality and represents the display device. Display modes, resolution, and color depth are controlled through the DirectDraw object.

• The DirectDraw surface is simply a linear area of memory. It contains the device-dependent bits that represent a directly displayable object.

• The DirectDraw palette is a 16- or 256-color indexed palette provided for textures, offscreen surfaces, and overlay surfaces, which might not have the same palette as the primary surface.

To achieve greater speeds, DirectDraw will use whatever hardware acceleration features are present and will employ software emulation for unsupported features. It also allows an application to determine easily the hardware functionality and software emulation capabilities so it can optimize its graphic demands based on how a system will perform.

The graphic methods that game programmers rely on are provided for in a simplified low-level API that does not sacrifice speed for functionality. By providing developers with a simple method to use the features that most video cards already provide (such as hardware blting), games under Windows 95 can achieve screen updates faster than anything that is practical to implement under MS-DOS.

DirectSound

DirectSound is the audio equivalent of DirectDraw. Developed in conjunction with PC audio expert John Miles, the DirectSound APIs were created to provide high-fidelity, low-latency sound and sound mixing. This enables realistic sound effects for Windows-based games.

DirectSound allows direct access to the hardware sound channel of an audio card. It does this by virtualizing the direct memory access (DMA) buffer, enabling direct access to on-card audio buffers, or emulating this for sound cards, such as the current generation of PCMCIA cards.

By using DirectSound, a game can store different sounds into different memory buffers. These buffers can be easily mixed and played quickly without the latency problems associated with Windows 3.x. DirectSound provides this functionality while maintaining compatibility with existing Windows 95-based applications and device drivers.

DirectSound is composed of two structures—the DirectSound object, which represents the sound card, and DirectSoundBuffer objects, which represent the sounds.

DirectSound is essentially an audio buffer manager. An application can employ DirectSound to create DirectSoundBuffer objects. These objects represent audio streams that can be written into directly. The application can mix audio data into these buffers, position these buffers in 3-D space, and play them. A DirectSoundBuffer object may be any of the popular formats currently supported by the WaveOut APIs. This includes mono or stereo; 8 or 16 bits; and 8, 11, 22, or 44 kHz.

The DirectSound object controls the sound card, which includes all of the operating parameters for the sound card and listener for 3-D audio. It is designed to give demanding applications control of the sound card when required. This enables very responsive, high-fidelity sound.

DirectPlay

To simplify adding multiplayer functionality to games, the DirectPlay component provides a method for two or more players' games to communicate.

DirectPlay provides a common interface for a game to use in order to establish a link to other games and handles providing the communication with the other machines. The application itself no longer has to provide the code for communicating data to other machines.

DirectPlay is made up of two pieces—the DirectPlay object that a game communicates with and the DirectPlay servers that the DirectPlay object uses. Microsoft will supply DirectPlay servers for modem, serial, and network connections. Any third party can also provide DirectPlay servers for specialized hardware or online communication services.

When a player wants to begin playing with other players, a list of the available servers can be presented to the player. After the player makes the selection, the game uses DirectPlay to establish the connection and handle the communication.

To adjust for communication performance, the game can query the DirectPlay object for the current latency and bandwidth of the communication method. The game can also query the DirectPlay object for information about previous and existing game play sessions.

A game using DirectPlay does not have to worry about whether it is using a modem or a network or an online service provider, thus saving developers time.

DirectInput

For a game to find out what a player wants to do, it needs a method to communicate with an input device. For the PC, the analog joystick has remained the standard by default for over a decade. This hasn't improved because the analog joystick method does not permit innovations in input device design. DirectInput is an API that solves these problems and provides even greater functionality.

By abstracting a game away from programming directly to the hardware, DirectInput allows Windows 95 to support a more diverse range of devices as they become available, such as headtrackers or digital joysticks. This also allows manufacturers to develop new designs without having to worry about compatibility with existing games. If a game was developed using DirectInput, a new minidriver is all that's needed for the game to make use of a new device.

DirectInput supports up to 16 input devices simultaneously, each with up to six axes of motion and n number of buttons. It also allows for increased performance through serial and digital input, while still supporting the current analog method.

This architecture also supports devices that react to data from the application (known as "force feedback"). A simple example of this is a steering wheel device that shakes when the player drives over rough ground.

With these features, DirectInput frees developers from worrying about which input devices to support, and allows hardware manufacturers to develop new designs without achieving industry acceptance beforehand.

How to get the Game SDK

The Game SDK is currently in beta but is scheduled to be available this fall. To receive a beta copy, e-mail betareq@microsoft.com with your contact information (name, address, e-mail, phone, fax, and so on) and specifically request the Windows 95 Game SDK Beta. Support sections are currently available on CompuServe in the WINMM forum.

The Windows 95 Game SDK represents an evolutionary leap forward for the Microsoft Windows API. By using the game subsystem, Windows 95-based games will be the best available on any platform.

When he's not evangelizing the gaming world about the Ultimate Gaming Platform (UGP), Jason Robar enjoys exploring the clubs and cafes of Seattle, looking for the perfect band or the perfect spot to relax and read in Russian.