📄 peer_8h-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>peer.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center><hr><h1>peer.h</h1><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> ZIG - An extendable, portable game engine focused on networking & scripting</span>00003 <span class="comment"> Project Home: http://zige.sourceforge.net</span>00004 <span class="comment"> Copyright (C) 2002 F醔io Reis Cecin <fcecin AT inf DOT ufrgs DOT br></span>00005 <span class="comment"></span>00006 <span class="comment"> This library is free software; you can redistribute it and/or</span>00007 <span class="comment"> modify it under the terms of the GNU Lesser General Public</span>00008 <span class="comment"> License as published by the Free Software Foundation; either</span>00009 <span class="comment"> version 2.1 of the License, or (at your option) any later version.</span>00010 <span class="comment"></span>00011 <span class="comment"> This library is distributed in the hope that it will be useful,</span>00012 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00013 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>00014 <span class="comment"> Lesser General Public License for more details.</span>00015 <span class="comment"></span>00016 <span class="comment"> You should have received a copy of the GNU Lesser General Public</span>00017 <span class="comment"> License along with this library; if not, write to the Free Software</span>00018 <span class="comment"> Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA </span>00019 <span class="comment">*/</span>00020 <span class="comment">/*</span>00021 <span class="comment"></span>00022 <span class="comment"> main "client" class for ZIG's peer-to-peer protocol</span>00023 <span class="comment"></span>00024 <span class="comment"> to be introduced in ZIG 1.4.0 beta, someday...</span>00025 <span class="comment"></span>00026 <span class="comment"> FIXME: this is EXPERIMENTAL and generally NON-WORKING -- DO NOT include this </span>00027 <span class="comment"> on the 1.3.x releases!</span>00028 <span class="comment"></span>00029 <span class="comment"> THREAD-SAFETY NOTE: peer_c and remote_peer_c are NOT THREAD SAFE. all peer-to-peer </span>00030 <span class="comment"> game classes are designed to work with "non-blocking" network/etc operation.</span>00031 <span class="comment"></span>00032 <span class="comment">*/</span>00033 00034 <span class="preprocessor">#ifndef _ZIG_HEADER_PEER_H_</span>00035 <span class="preprocessor"></span><span class="preprocessor">#define _ZIG_HEADER_PEER_H_</span>00036 <span class="preprocessor"></span>00037 <span class="preprocessor">#include <map></span>00038 <span class="preprocessor">#include "address.h"</span>00039 <span class="preprocessor">#include "station.h"</span>00040 <span class="preprocessor">#include "leet.h"</span>00041 00042 <span class="comment">// remote peer class: represents a remote "peer_c" instante</span>00043 <span class="keyword">class </span>peer_c;00044 <span class="keyword">class </span>remote_peer_c {00045 <span class="keyword">public</span>:00046 00047 <span class="comment">//reference to owner peer_c</span>00048 peer_c *peer;00049 00050 <span class="comment">//the remote peer's id</span>00051 <span class="keywordtype">int</span> id;00052 00053 <span class="comment">//the remote peer's address</span>00054 <a class="code" href="classaddress__c.html">address_c</a> remote_addr;00055 00056 <span class="comment">//RUDP socket</span>00057 station_c station;00058 00059 <span class="comment">// time of last packet received from this peer. to check peer timeouts.</span>00060 <span class="keywordtype">double</span> last_received_packet;00061 00062 <span class="comment">// keeps copies of the last record updates (and update sequence) received from this peer </span>00063 <span class="comment">// <record id --> (buffer data)></span>00064 std::map<int, buffer_c> records;00065 std::map<int, NLubyte> updseq;00066 00067 <span class="comment">// IMPORTANT: for EACH remote peer, must keep the set of update sequences of my LOCAL updates</span>00068 <span class="comment">// that are acked by that peer</span>00069 std::map<int, NLubyte> received_updseq;00070 00071 <span class="comment">//ctor</span>00072 remote_peer_c(peer_c *pr, <a class="code" href="classconsole__c.html">console_c</a> *conio = 0) {00073 peer = pr;00074 station.set_console(conio);00075 00076 last_received_packet = <a class="code" href="utils_8h.html#a13">get_time</a>();00077 }00078 00079 <span class="comment">//dtor</span>00080 <span class="keyword">virtual</span> ~remote_peer_c() {00081 }00082 };00083 00084 <span class="comment">// peer class</span>00085 <span class="keyword">class </span>peer_c : <span class="keyword">public</span> leet_c, <span class="keyword">public</span> station_callback_i {00086 <span class="keyword">public</span>:00087 00088 <span class="comment">// ctor</span>00089 peer_c(<a class="code" href="classconsole__c.html">console_c</a> *conio = 0);00090 00091 <span class="comment">// dtor</span>00092 <span class="keyword">virtual</span> ~peer_c();00093 00094 <span class="comment">// called beafter run_nonblocking()</span>00095 <span class="comment">// virtual void init() = 0;</span>00096 00097 <span class="comment">// called before stop()</span>00098 <span class="comment">// virtual void finish() = 0;</span>00099 00100 <span class="comment">// -----------------------------------------------------------------------</span>00101 <span class="comment">// main methods - session management</span>00102 <span class="comment">// -----------------------------------------------------------------------</span>00103 00104 <span class="comment">// process networking etc. tasks asynchronously. does nothing if no active session </span>00105 <span class="comment">// (started with host() or connect()). MUST CALL PERIODICALLY, e.g. somewhere on </span>00106 <span class="comment">// the game main loop.</span>00107 <span class="keywordtype">void</span> process_nonblocking();00108 00109 <span class="comment">// start hosting a game</span>00110 <span class="keywordtype">void</span> host(<span class="keywordtype">int</span> port_num, <span class="keywordtype">int</span> max_players);00111 00112 <span class="comment">// connect to a host</span>00113 <span class="keywordtype">void</span> connect(<a class="code" href="classaddress__c.html">address_c</a> &host_addr);00114
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -