Normal Peer-to-Peer Game Play

DirectPlay

 
Microsoft DirectX 9.0 SDK Update (Summer 2003)

Normal Peer-to-Peer Game Play


In Microsoft® DirectPlay®, a message is essentially a block of game-related data that you send to one or more members of the session. DirectPlay does not specify the contents or format of the data block, it just provides a mechanism to transmit the data from one user to another. When the game is underway, each session member will normally send a constant stream of messages to all other members of the session for the duration of the game. The primary purpose of these messages is to keep the game state synchronized, so that each user's application displays the same user interface (UI). However, messages can also be used for a variety of other game-specific purposes.

For many games, especially rapidly changing ones, you may have to manage your messaging carefully. DirectPlay throttles outgoing messages to a level that can be handled by the target. You will have be careful that you do not send messages too rapidly, and ensure that the most important messages get through. See Basic Networking for a discussion of how to effectively handle DirectPlay messaging.

To send a message to another session member, call IDirectPlay8Peer::SendTo. That member will receive a DPN_MSGID_RECEIVE message with the data. To send a message to a specific player, set the dpnid parameter to the player identifier (ID) that you received with the associated DPN_MSGID_CREATE_PLAYER message. You can also send a message to every player in the session by setting dpnid to DPNID_ALL_PLAYERS_GROUP. You can also define groups of players, and use a single IDirectPlay8Peer::SendTo call to send a message to all members of a group.

Note  You can also use the IDirectPlay8Peer::SetPeerInfo method to send information to other users. They will receive the information with a DPN_MSGID_PEER_INFO message. However, this way of transmitting information is not very efficient, and should not be used for normal messaging.

Using Groups

Many games allow players to be organized into groups. For instance, strategy games typically allow individual players to be organized into groups that can then be directed as a single entity. DirectPlay also allows the formation of groups of players. DirectPlay groups are essentially a way to simplify your messaging. When you have defined a group, you can send a message to every group member with a single call to IDirectPlay8Peer::SendTo. While DirectPlay groups normally correspond to the groups that are defined by the game, you are free to create a group for any reason.

To create a DirectPlay group, call IDirectPlay8Peer::CreateGroup All session members will then receive a DPN_MSGID_CREATE_GROUP message with the details. The message will include a group ID that is used to send messages to the group.

Once the group is created, you then add players by calling IDirectPlay8Peer::AddPlayerToGroup. Session members will then receive a DPN_MSGID_ADD_PLAYER_TO_GROUP message with the IDs of the group and the player that was just added.

Once the group is established, you can send data to the group by calling IDirectPlay8Peer::SendTo, with the dpnid parameter set to the group ID. All group members will then receive a DPN_MSGID_RECEIVE message with the data.

To remove a player from a group, call IDirectPlay8Peer::RemovePlayerFromGroup. The session members will receive a DPN_MSGID_DESTROY_PLAYER message with the player's ID.

Finally, when you no longer need the group, you can destroy it by calling IDirectPlay8Peer::DestroyGroup All session members will then receive a DPN_MSGID_DESTROY_GROUP message with the group ID.


© 2003 Microsoft Corporation. All rights reserved.