ATTENTION READERS! Lucky's VB Gaming Site is no longer active. For updated game programming information and tutorials, please visit The Game Programming Wiki!
Introduction to DirectPlay
So, you want to make a multiplayer game, eh? Well you've come to the right place. DirectPlay makes the process as painless
as possible. Serial, modem, IPX (LAN), or TCP/IP (Internet) - DirectPlay can handle them all, and you'll hardly notice a
difference between any of these connection types. So, keep your arms and legs inside the vehicle at all times, and buckle up;
you're in for a ride!
The path to DirectPlay enlightenment is 8-fold: Initialization, Enumeration of Service Providers, Initializing a Connection,
Starting/Joining a Game, Creating a Player, Commencing Gameplay, In-Game Messaging, and Termination. What follows is a brief
description of each.
Initialization - As with all other aspects of DirectX, there are various and sundry objects to be initialized. These steps
are quite simple, as you will see.
Enumeration of Service Providers - A "Service Provider" is merely a driver that allows DirectPlay to interact with other
instances of itself on remote systems. The four standard service providers enable Serial Cable, Modem, IPX, and TCP/IP connections.
It is possible to write custom service providers, but such discussion is far beyond the scope of this tutorial. The fab-four should
be enough for any budding multiplayer-game programmer! Once the service providers have been enumerated, they can be displayed to
the user in a variety of fashions, allowing for identification of the desired connection type.
Initializing a Connection - Just because a service provider is present (that is to say, the DRIVER is present), does NOT necessarily
mean that the connection can be initialized successfully. Even if you are not on a LAN, the IPX service provider will still show up in your
enumeration! When the user selects a service provider, it is your job to attempt to initialize the connection and report back on the
success of the operation.
Starting/Joining a Game - Assuming that the connection was initialized, we can then continue by choosing either to "Host" a game,
or to "Join" a pre-existing game. Both options require a unique set of actions to be carried out. To host a game, we must create a
"Session Object" and specify various parameters such as maximum number of players, and session title. To join a game, we must first list
all available "Sessions" exposed by our current service provider (our current "connection") and allow the user to select the desired
game to join.
Creating a Player - After we've joined or started a game, we must create a "Player" which we will use as our identity
during the upcoming game. We must specify various parameters when we initialize the player, and trap the handle that is returned.
Commencing Gameplay - Once a sufficient number of players have connected to the session, the game may commence. This is truly
more of a logical formality than it is a requirement of DirectPlay. Once a player has joined a session, he/she may already send and
receive messages with any of the other connected players. In games with fixed numbers of players, however, it is important to disable
the session's "Join" ability after commencement, in order to keep players from jumping into the middle of a running game.
In-Game Messaging - Once the game is started, messages can be sent between any and all of the players involved. The format of
these messages is user-defined, and can be bent to suit the needs of any particular program. Also, a variety of messaging options
can affect the speed or reliability of messaging.
Termination - When a player drops out of a DirectPlay game, it is important that the associated objects are dismantled correctly,
or else the "Termination" system message may not be sent out. Indeed, DirectX will likely handle this on your behalf, but you never
can be too sure!
Keep in mind that this is a simplification of the structure of DirectPlay, but it should serve as a good framework around which you can
build your DirectPlay knowledge. Pay attention to how the concepts of Service Providers, Sessions, and Players all interact, and you'll
do just fine.
Now, forge ahead! Read the Initialization tutorial. (click here to download this
tutorial's source code)