📄 article722.asp.htm
字号:
//interrupt-handler <i>x</i> is called when a character is received from the
//serial buffer. The interrupt handler sets serial_buffer[cur_buf] to the
//character received, increments cur_buf, and performs any necessary bounding
//work (making sure that cur_buf <max_buffer, namely). <i>x also tracks
//packet-boundaries; if the last character received was 0xFF and the current
//is also 0xFF, then x will increment the global "last". Last is tested at
//the end of the ISR; when last reaches 3, queue[cur_queue] will be filled
//with the last sizeof(packet)-1 bytes in the serial buffer along with the
//current character, unprocessed_packets will be incremented, last will be
//set to 0, cur_buf will be set to 0, and cur_queue will be incremented. If
//cur_queue > MAX_QUEUE, cur_queue is set to 0 and this entry is used to fill
//the packet; packets_lost is also incremented by 1, and unprocessed_packets
//is set to 1.
//what that does:
//it reads characters from the serial buffer, and when there's a complete
//packet, it fills one element of a recycling queue with the packet
...
void Send_Packet(game_packet *p) {
...
Send_Out_Serial(open_port, p->obj);
Send_Out_Serial(open_port, p->x);
Send_Out_Serial(open_port, p->y);
Send_Out_Serial(open_port, p->z);
...
}
void Process_Packets(packet *p) {
...
if(!unprocessed_packets) //no new packets to process, so return
return;
asm cli
for (int index=cur_queue-(unprocessed_packets-1);index <unprocessed_packets;index++) {
Update_Game(queue[index]);
}
cur_queue = 0;
unprocessed_packets = 0;
asm sti
...
}
//Process_Packets would be called in the main game loop at a certain
//point. If everything is running okay, the error-handling "features"
//built into it and interrupt-handler <i>x</i> shouldn't have to take over.
void Init_Game(int port) { //where port is a serial port
//connected to another machine
game_packet init;
init.flags = NEW_GAME | RESET;
Send_Packet(port, (game_packet*)&init);
Init_Local_Game();
}
...
//You get the idea?
</FONT></PRE></BLOCKQUOTE>
<P><FONT COLOR="#00983E" SIZE="4"><B>Networked multiplayer games: Internet intro ala crash-course</B></FONT></P>
<P><TABLE WIDTH="90%" CELLPADDING="5" BORDER=1 ALIGN="center"><TR><TD >
RANT: These are the real hot topics these days in the multiplayer game world. Networked multiplayer games can be really, really cool. No longer are you playing a game with your friend sitting in the chair next to you, trying to figure out whose character just moved, no longer are you playing a game against some half-witted FSM, you're playing against a <B>REAL PERSON</B> and you can <i>tell</i>.<P>Gamers today don't want to simply interact with their games by moving a little model around, and could care less whether or not you used quaternion-based interpolation between keyframes coupled with skeletal-hierarchy animation for your two-hundred polygon optimized character with hardware bilinear-filtered perspective-correct texture mapping applied and high-end LOD processing. Rather, they want to take interaction to a higher level, whether this higher level is achieved via outstanding scene-realism or any other means. The influx of networked-multiplayer games is an exciting manifestation of this.
</TD></TR></TABLE>
<P>Networked multiplayer games are conceptually the same as local-multiplayer games, with a few exceptions. First of all, each machine in the game still handles processing for the player using it. However, instead of sending packets out to all of the other players in the game (or just the other player), in a networked game, machines send packets to one central <i>server</i> and receive packets from the server in return. The server is at the center of the game, storing all the game's information and keeping things running. If turn-based systems are used somehow, then the server is responsible for managing them. All the machines connected to the game's server are called clients. This model in general is called the client-server model of communication. Client-server is <u>the</u> communications model used in the real world, so get used to it.</P>
<P><TABLE WIDTH="90%" CELLPADDING="5" BORDER=1 ALIGN="center"><TR><TD >
There are many books on client-server and other networking concepts...see <a href="javascript:if(confirm('http://www.developer.com/reference/r_servers.html \n\n这个文件不能通过 Teleport Pro 取回, 因为 它被访问于一个域或在它的起始地址边界外部的路径上. \n\n你想从服务器打开它吗?'))window.location='http://www.developer.com/reference/r_servers.html'" tppabs="http://www.developer.com/reference/r_servers.html"><font color="#00ff00">http://www.developer.com/reference/r_servers.html</font></a> for a great online collection.
</TD></TR></TABLE>
<P>Networks implement communication protocols in order to give meaning and structure to communications taking place on them. All communications on a network are carried out according to a standard set of these protocols; if you are to use a network effectively, then you must use its communications protocols. The Internet has TCP/IP (Transmission Control Protocol/Internet Protocol) to serve this purpose. TCP/IP is a family of protocols, both application-level (i.e., high-level, like FTP, HTTP, Gopher) and network-level protocols (such as IP, ARP, ICMP). In TCP/IP, packets are constructed and routed through the network to the appropriate machine, based upon the headers of these packets. The data-area of these packets is the acceptable place for you to put your game's data (you don't have to handle packets quite as was done above). The Internet gaurantees that your packets will be sent to the correct machine, that is, the machine running the server.</P>
<P>Client applications, or the version of the game that you would distribute to your end-users (this program is often called the "client"), send TCP/IP packets to the server, a program that dissects them and processes them; the server is a program that runs on a machine identified by an IP address. The server listens to a TCP/IP "port", where data comes in, and sends data back to its clients via TCP/IP.</P>
<P>For the amateur, client/server based games can present a lot of problems, when one tries to take them on from the ground up: First of all, you need a dedicated machine with a dedicated IP to run the server. Next on the list, the machine has to be able to actually run the server: Many commercial end-user operating systems like Windows 95 don't ship with TCP/IP server implementations. Fortunately, there are solutions such as Linux...</P>
<P>There's a lot involved in sending and processing a single packet of data in networked games. Fortunately, in most operating systems, we've got access to TCP/IP client implementations that allow us to avert the technicalities of low-level Internet communication. With Winsock, for instance, it's possible to come up with programs that do things like retrieve web pages from port 80 on any machine, in about a page of code. High-level operating system APIs for Internet functions are a blessing, not a hurdle, despite what the complaints may register. After all, is it really practical to implement around thirty years of Internet yourself?</P>
<P><FONT COLOR="#00983E" SIZE="4"><B>That's all for now</B></FONT></P>
<P>Hopefully, this article has helped you understand the essentials of multiplayer game programming. If you didn't understand it, go back and read through it again; this was designed to be a practical introduction that would allow you to go write some multiplayer games as soon as possible.</P>
<P>Anyway, happy coding, and finish that game! :)</P>
</FONT>
<P ALIGN="center"><B><A HREF="javascript:if(confirm('http://www.gamedev.net/community/forums/topic.asp?key=featart&uid=722&forum_id=35&Topic_Title=The+Essentials+of+Multiplayer+Games \n\n这个文件不能通过 Teleport Pro 取回, 因为 它被链接到离它的起始地址太远的地方. 如果你增大起始地址在其范围内的深度设置, 这个文件将进行列队等待取回. \n\n你想从服务器打开它吗?'))window.location='http://www.gamedev.net/community/forums/topic.asp?key=featart&uid=722&forum_id=35&Topic_Title=The+Essentials+of+Multiplayer+Games'" tppabs="http://www.gamedev.net/community/forums/topic.asp?key=featart&uid=722&forum_id=35&Topic_Title=The+Essentials+of+Multiplayer+Games">Discuss this article in the forums</A></B></P>
<P>
<CENTER>
<!-- -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -