📄 peer_8h-source.html
字号:
00115 <span class="comment">// disconnect from current session (host() / connect())</span>00116 <span class="keywordtype">void</span> disconnect();00117 00118 <span class="comment">// ------- callbacks -----------------------------------------------------</span>00119 00120 <span class="comment">// called when a peer becomes the host (also when it is starting as host with host())</span>00121 <span class="keyword">virtual</span> <span class="keywordtype">void</span> begin_host() = 0;00122 00123 <span class="comment">// called when the connection attempt fails.</span>00124 <span class="keyword">virtual</span> <span class="keywordtype">void</span> connect_failed() = 0;00125 00126 <span class="comment">// called when you connect to the game host (or if you are the host with host()). the </span>00127 <span class="comment">// game host tells you what is your peer_id, since you must know that to make intelligent </span>00128 <span class="comment">// decisions as to become (or not) the new host, in case the current host fails.</span>00129 <span class="keyword">virtual</span> <span class="keywordtype">void</span> connected(<span class="keywordtype">int</span> self_peer_id) = 0;00130 00131 <span class="comment">// called when a new peer "joins" the game (as seen from your own standpoint, since </span>00132 <span class="comment">// peers may "join" and "leave" the local games of different peers at different times,</span>00133 <span class="comment">// but this connection is authorized by the current host)</span>00134 <span class="keyword">virtual</span> <span class="keywordtype">void</span> peer_connected(<span class="keywordtype">int</span> remote_peer_id) = 0;00135 00136 <span class="comment">// called when a peer "leaves" the game (see above remarks)</span>00137 <span class="keyword">virtual</span> <span class="keywordtype">void</span> peer_disconnected(<span class="keywordtype">int</span> remote_peer_id) = 0;00138 00139 <span class="comment">// called when you leave a session. with the current protocol semantics, this will </span>00140 <span class="comment">// probably only be called if you call disconnect() on purpose, since even if you </span>00141 <span class="comment">// lose your connection to all the other peers, you will elect yourself as the </span>00142 <span class="comment">// "new host" of the session and stay hosting the game to yourself.</span>00143 <span class="comment">// NOTE: actually, if the current host sends a message telling you to leave the </span>00144 <span class="comment">// game, the implementation may choose to obey and terminate all connections, and</span>00145 <span class="comment">// also shut down the local connection entirely, calling the disconnect() event</span>00146 <span class="keyword">virtual</span> <span class="keywordtype">void</span> disconnected() = 0;00147 00148 <span class="comment">// -----------------------------------------------------------------------</span>00149 <span class="comment">// data in/out</span>00150 <span class="comment">// -----------------------------------------------------------------------</span>00151 00152 <span class="comment">// update a local data record value</span>00153 <span class="keywordtype">void</span> local_update(<span class="keywordtype">int</span> record_id, <a class="code" href="classbuffer__c.html">buffer_c</a>& data);00154 00155 <span class="comment">// tell network to dispatch an update packet for every peer in order to </span>00156 <span class="comment">// synchronize all the previous local updates</span>00157 <span class="keywordtype">void</span> broadcast_local_updates();00158 00159 <span class="comment">// send reliable message to a peer</span>00160 <span class="keywordtype">void</span> send_message(<span class="keywordtype">int</span> peer_id, <a class="code" href="classbuffer__c.html">buffer_c</a>& msg, <span class="keywordtype">int</span> policy = RSP_USE_DEFAULT);00161 00162 <span class="comment">// send reliable message to all peers</span>00163 <span class="keywordtype">void</span> broadcast_message(<a class="code" href="classbuffer__c.html">buffer_c</a>& msg, <span class="keywordtype">int</span> policy = RSP_USE_DEFAULT);00164 00165 <span class="comment">// read next relible message into "msgbuf" from a peer. returns: </span>00166 <span class="comment">// -1: if peer not found or other weird error</span>00167 <span class="comment">// 0: if no more messages to read</span>00168 <span class="comment">// 1: if message read ok into "msgbuf"</span>00169 <span class="keywordtype">int</span> receive_message(<span class="keywordtype">int</span> peer_id, <a class="code" href="classbuffer__c.html">buffer_c</a> &msgbuf);00170 00171 <span class="comment">// ------- callbacks -----------------------------------------------------</span>00172 00173 <span class="comment">// incoming data from a peer. use this to read pending reliable messages. </span>00174 <span class="comment">// after this callback, it is possible that "incoming_update" callbacks will </span>00175 <span class="comment">// be triggered</span>00176 <span class="keyword">virtual</span> <span class="keywordtype">void</span> incoming_data(<span class="keywordtype">int</span> peer_id) = 0;00177 00178 <span class="comment">// incoming update from a peer: a remote peer has updated one of the records </span>00179 <span class="comment">// it is serving</span>00180 <span class="keywordtype">void</span> incoming_update(<span class="keywordtype">int</span> peer_id, <span class="keywordtype">int</span> record_id, <a class="code" href="classbuffer__c.html">buffer_c</a>& data);00181 00182 <span class="comment">// -----------------------------------------------------------------------</span>00183 <span class="comment">// network rate "timer" service</span>00184 <span class="comment">// -----------------------------------------------------------------------</span>00185 00186 <span class="comment">// set network tick rate. set to zero/negative to turn off the broadcast_frame() callback</span>00187 <span class="keywordtype">void</span> set_net_tick(<span class="keywordtype">double</span> tick = 0.0);00188 00189 <span class="comment">// ------- callbacks -----------------------------------------------------</span>00190 00191 <span class="comment">// called from process_nonblocking, on preconfigured "net tick" rate</span>00192 <span class="keyword">virtual</span> <span class="keywordtype">void</span> broadcast_frame() = 0;00193 00194 <span class="keyword">protected</span>:00195 00196 <span class="comment">// -----------------------------------------------------------------------</span>00197 <span class="comment">// implementation details - methods</span>00198 <span class="comment">// -----------------------------------------------------------------------</span>00199 00200 <span class="comment">// leet_c: listen socket is telling the leet client/server of new connection.</span>00201 <span class="keyword">virtual</span> <span class="keywordtype">void</span> listen_socket_incoming_connection(listen_socket_c *ls, NLsocket sock);00202 00203 <span class="comment">// station_callback_i: channel opened</span>00204 <span class="keyword">virtual</span> <span class="keywordtype">void</span> station_channel_opened(<span class="keywordtype">int</span> channel_id, <a class="code" href="classchannel__c.html">channel_c</a> *ch, <span class="keywordtype">int</span> tag);00205 00206 <span class="comment">// station_callback_i: can't open a channel</span>00207 <span class="keyword">virtual</span> <span class="keywordtype">void</span> station_channel_failed(<span class="keywordtype">int</span> channel_id, <span class="keywordtype">int</span> code_reason, <span class="keywordtype">int</span> tag);00208 00209 <span class="comment">// -----------------------------------------------------------------------</span>00210 <span class="comment">// implementation details - vars</span>00211 <span class="comment">// -----------------------------------------------------------------------</span>00212 00213 <span class="comment">// my peer id. assigned by the original host that I've connected to (or self)</span>00214 <span class="keywordtype">int</span> id;00215 00216 <span class="comment">// broadcast_frame() support</span>00217 <span class="keywordtype">double</span> net_tick;00218 <span class="keywordtype">double</span> last_net_tick_time;00219 00220 <span class="comment">//peers map <peer id --> (peer data record)></span>00221 std::map<int, remote_peer_c*> peers;00222 00223 <span class="comment">//keeps copies of the local update records (and update sequences) <record id --> (buffer data)></span>00224 std::map<int, buffer_c> records;00225 std::map<int, NLubyte> updseq;00226 };00227 00228 00229 <span class="preprocessor">#endif</span></pre></div><hr><address style="align: right;"><small>Generated on Mon Jan 24 21:14:23 2005 for ZIG by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -