tailieunhanh - Building XNA 2.0 Games- P14

Building XNA Games- P14: I would like to acknowledge John Sedlak, who saved this book from certain doom, as well as all of the great guys in the XNA community and Microsoft XNA team, who helped me with all of my stupid programming questions. (That is actually the term used—“stupid programming question”—and it is a question that one should not have to ask if one has been approached to write a book about the subject.) | 378 CHAPTER 12 NETWORKING Network Game Interaction The following is our NetGame class which concerns itself with message composing sending receiving and parsing public class NetGame NetPlay netPlay public const byte MSG_SERVER_DATA 0 public const byte MSG_CLIENT_DATA 1 public const byte MSG_CHARACTER 2 public const byte MSG_PARTICLE 3 public const byte MSG_END 4 Packetwriter writer PacketReader reader float frame public float frameTime Our constructor besides taking a reference to our overarching NetPlay class initializes our PacketReader and Packetwriter. We ll be using the writer and reader to send and receive messages respectively. public NetGame NetPlay _netPlay netPlay _netPlay writer new PacketWriter reader new PacketReader public void Update Character c ParticleManager pMan LocalNetworkGamer gamer will handle all of our reading and writing gamer can send and receive messages. The GetGamer function is defined later. Its purpose is to find the LocalNetworkGamer at player index 1. LocalNetworkGamer gamer GetGamer if gamer null return We re updating every frame but we don t want to send data every frame. If you think of the Internet as a large series of tubes we need to send the data just fast enough so that it doesn t clog up on one end. If we send too much data it will not fit in the pipe. If we send too little data at too great a speed it will just pile up somewhere. The goal is to get the perfect amount across with the perfect timing so that the players don t notice anything whatsoever. That s a little CHAPTER 12 NETWORKING 379 easier said than done. Since we re just testing a basic game we don t need to concern ourselves with the problem. If you plan on making this game available over the Live platform this is a problem you will need to tackle. For the time being we ll set it up to send data every second or at 20 frames per second. This is too fast for most if not all Live matches but will work fine for System Link. frame - frameTime if frame 0f frame

TÀI LIỆU MỚI ĐĂNG
5    174    1    27-12-2024