[ Pobierz całość w formacie PDF ]
.UsingSendEx(), you can obtain the ID of a specific message, which you can later use to cancelthat message if it hasn t already been sent.This might come in handy if a player makes amove which might cancel out a previous move, meaning that you can simply cancel themessage indicating the first move and ignore sending the second.You could also eventake this management a little further (especially, perhaps on slow links like modem-to-modem) and cancel a message indicating a player s state if it hasn t been sent within acertain time and new state data should be transmitted anyway. 28 1634xCH20 11/13/99 11:12 AM Page 423Putting Your Game on the Net Writing Multiplayer Titles 423CancelPriority() cancels all messages currently pending transmittal by DirectPlay thatare within a certain priority range.This introduces the idea that DirectPlay can also pri-oritize messages by indicating a message s priority in the call to SendEx().By setting thedwPriority value to an appropriate DWORD value on a call to SendEx(), you can ensurethat DirectPlay will try to send messages in order of priority.A value of 0 is the lowestpriority, while 65535 is the highest.The function GetMessageQueue() is used to determine how many messages are in a par-ticular player s send or receive queue.By setting the idFrom and idTo parameters, youcan determine how many messages are waiting to be sent to or received from a specificplayer.By setting dwFlags to either DPMESSAGEQUEUE_SEND or DPMESSAGEQUEUE_RECEIVE,you can specify which queue to look at.GetMessageCount() simply returns the numberof messages waiting to be processed in a specific player s receive message queue.You can use these last two functions to gauge just how well a receiving computer is han-dling messages.If, for example, the receiving computer were much slower than the send-ing one, it would be possible for the faster computer to overwhelm the slow computer bysending too much data too fast.You can implement  throttling, which means that youstart to delay sending messages, or, maybe even more likely, start discarding low prioritymessages.This would be easy to do with a single call to CancelPriority(), where youcan stop DirectPlay from sending a lot of messages with a given priority (or lower).SummaryThis hour covered a lot of information.You learned how to devise a strategy for dealingwith deterministic and non-deterministic data, as well as how to maintain game stateinformation between game clients.You learned about players, sessions, and groups, aswell as the management of those objects.You learned about how to develop strategies for writing games that have high responsive-ness over a network, as well as how to handle situations that might arise if your game isplayed over a slow network.20You also learned about DirectPlay s notion of Service Providers, and how to pick a spe-cific service provider, or let the user choose which one to use.You also learned how touse DirectPlay s callback functions to enumerate game sessions, groups, and players on anetwork.We ll continue on with this notion of adding multiplayer capabilities in the next hour,when we discuss DirectPlay lobbies.You ll continue to add functionality to your game toadd an additional,  social experience to your game. 28 1634xCH20 11/13/99 11:12 AM Page 424424 Hour 20Q&AQ When setting up a network session, the user must make decisions, such aswhich service provider to use and perhaps some device-specific parameterslike a phone number for a modem or a baud rate on a serial port.How is thatinterface implemented?A You can use the Windows dialog boxes that come with the service providers to domost these things, but that is often ugly, undesirable, and disruptive to a full-screen(immersive) application.Yuck, all of a sudden I m back in Windows looking at adialog box! These dialog boxes can be silenced and replaced by your application suser interface, but now your application must assemble the DirectPlay address tocreate the connection.You should either plan to allow dialog boxes to intrude orimplement some of your own user interface to replace them.Q You said that, in a client/server configuration, most of the data traffic flowsclient to server.Because the host has most the data, wouldn t most of the flowbe from server to client?A It really depends on application, architecture, and the engineering philosophiesbehind what messages you use to get the job done.If there are many players in dis-tinct areas of a vast virtual world, the server gets incoming data from all the play-ers and must send updates of one to another only when they draw near each other.Hence, over time, the main data flow is client to server.However, if we fill thatworld with AI agents, the client must display their images using server-sent mes-sages, and the main data flow will be server to client.Q Do you have to use event handles to receive player messages?A This opens up a very old argument between deterministic and asynchronous solu-tions to real-time problems.A deterministic application is, in essence, a cyclicactivity that manages its own time slicing.That typically means it polls the mes-sage queue rather than waits for an event signal.One could argue that polling isinefficient, but another could point out the problem is network latency, not the timeit takes to see if any messages are waiting.To answer the question: No, you do nothave to use event handles unless your application uses asynchronous threads.WorkshopThe Workshop is designed to help you anticipate possible questions, review what you velearned, and begin thinking ahead to put your knowledge into practice.The answers tothe quiz are in Appendix A,  Answers. 28 1634xCH20 11/13/99 11:12 AM Page 425Putting Your Game on the Net Writing Multiplayer Titles 425Quiz1.What is a DirectPlay Service Provider? What is an example of one?2.What two main models of communication are used by DirectPlay?3.What is a callback function and how is it used?4.What is meant by deterministic data?5.How do you create a secure session?6.How are DirectPlay players and groups identified?7.What is meant by guaranteed messaging? How do you use it?8.What is the DPSESSION_MIGRATEHOST flag used for in the DPSESSIONDESC2 struc-ture?9.How might you send a message to all players in a session?10.Can an IDirectPlay4 object be used for more than one session?Exercises1.Be sure to check out the Duel sample in the DirectX SDK.It is a good example ofhow to tie different components of DirectX together, as well as how to managegame state information.2.For a real challenge, experiment with the Duel sample to see if you can make itmore responsive to player input without impacting network consistency [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • szamanka888.keep.pl