📄 utils_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>utils.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>utils.h</h1><a href="utils_8h.html">Go to the documentation of this file.</a><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"> LEETNET 2</span>00023 <span class="comment"></span>00024 <span class="comment"> utils</span>00025 <span class="comment"></span>00026 <span class="comment">*/</span>00027 00028 00029 <span class="preprocessor">#ifndef _ZIG_HEADER_UTILS_H_</span>00030 <span class="preprocessor"></span><span class="preprocessor">#define _ZIG_HEADER_UTILS_H_</span>00031 <span class="preprocessor"></span>00032 <span class="preprocessor">#include <nl.h></span>00033 <span class="preprocessor">#include <assert.h></span>00034 <span class="preprocessor">#include "<a class="code" href="log_8h.html">log.h</a>"</span>00035 00040 <span class="preprocessor">#define SAFEDELETE(X) { assert(X != 0); if (X) { delete X; X = 0; } }</span>00041 <span class="preprocessor"></span><a name="l00043"></a><a class="code" href="utils_8h.html#a1">00043</a> <span class="preprocessor">#define FAILSTOP() { assert(false); throw 666; }</span>00044 <span class="preprocessor"></span>00045 <span class="preprocessor">#define LOG_NL_ERRORS(LEV) { con->xprintf(LEV, "HawkNL errors: %i %s %i %s\n", nlGetError(), nlGetErrorStr(nlGetError()), nlGetSystemError(), nlGetSystemErrorStr(nlGetSystemError())); }</span>00046 <span class="preprocessor"></span>00047 <span class="preprocessor">#include <string></span>00048 <span class="comment">//using namespace std;</span>00050 <span class="comment">std::string RandomName(int npal=-1);</span>00051 00052 <span class="comment">// socket statistics -- a bunch of NO-OP name wrappers for the HawkNL functions</span>00053 <span class="comment">// -------------------------------------------------------------------------------</span>00054 00057 <span class="keywordtype">int</span> zig_avg_total();00058 00061 <span class="keywordtype">int</span> zig_avg_out();00062 00065 <span class="keywordtype">int</span> zig_avg_in();00066 00067 <span class="comment">// compression statistics</span>00068 <span class="comment">// -------------------------------------------------------------------------------</span>00069 00072 <span class="keywordtype">double</span> zig_avg_compression_gain();00073 00075 <span class="keywordtype">void</span> zig_reset_compression_stats();00076 00077 <span class="comment">// -------------------------------------------------------------------------------</span>00078 00079 <span class="comment">// sleep ( secs )</span>00080 <span class="comment">//</span>00081 <span class="preprocessor">#if defined WINDOWS || WIN32 || WIN64</span>00082 <span class="preprocessor"></span><span class="preprocessor">#define WIN32_LEAN_AND_MEAN</span>00083 <span class="preprocessor"></span><span class="preprocessor">#define WIN32_EXTRA_LEAN</span>00084 <span class="preprocessor"></span><span class="preprocessor">#include <windows.h></span>00085 <span class="preprocessor">#define SLEEP(x) Sleep(x)</span>00086 <span class="preprocessor"></span><span class="preprocessor">#else</span>00087 <span class="preprocessor"></span>00088 <span class="comment">//you should have the nanosleep() function available</span>00089 <span class="preprocessor">#include <time.h></span>00090 <span class="preprocessor">#define SLEEP(x) { timespec ts1,ts2; ts1.tv_sec = (x)/1000; ts1.tv_nsec = ((x)%1000)*1000000; nanosleep(&ts1,&ts2); }</span>00091 <span class="preprocessor"></span><span class="comment">//#define SLEEP(x)</span>00092 00093 <span class="preprocessor">#endif</span>00094 <span class="preprocessor"></span><a name="l00096"></a><a class="code" href="utils_8h.html#a13">00096</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="utils_8h.html#a13">get_time</a>() {00097 <span class="preprocessor">#ifndef WIN32</span>00098 <span class="preprocessor"></span> NLtime ts;00099 nlTime(&ts);00100 <span class="keywordflow">return</span> (((double)ts.seconds)+(((double)ts.useconds)/1000000.0));00101 <span class="preprocessor">#else</span>00102 <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keywordtype">bool</span> bInit=<span class="keyword">false</span>;00103 <span class="keyword">static</span> LARGE_INTEGER stFrequency;00104 LARGE_INTEGER stTime;00105 <span class="keywordflow">if</span> (!bInit) {00106 QueryPerformanceFrequency(&stFrequency);00107 bInit=<span class="keyword">true</span>;00108 }00109 QueryPerformanceCounter(&stTime);00110 <span class="keywordflow">return</span> (stTime.QuadPart/(double)stFrequency.QuadPart);00111 <span class="preprocessor">#endif</span>00112 <span class="preprocessor"></span>}00113 00115 <span class="keywordtype">int</span> slap_local_socket(<span class="keywordtype">int</span> port);00116 00118 <span class="keywordtype">bool</span> check_private_IP(<span class="keywordtype">char</span> *address);00119 00121 <span class="keywordtype">bool</span> check_private_IP(NLaddress &address);00122 00123 <span class="comment">//USHORT ID API </span>00124 <span class="comment">//these functions enable LEETNET to use just an unsigned short (unsigned 16bit) value</span>00125 <span class="comment">//as a packet id, by handling when the id value wraps around 65K back to zero.</span>00126 00127 <span class="preprocessor">#define FIRST_USHORT_ID 1</span>00128 <span class="preprocessor"></span><span class="comment">//#define LAST_USHORT_ID 65280</span>00129 <span class="comment">//#define HALF_USHORT_ID 32640</span>00130 <span class="comment">//</span>00131 <span class="comment">// NEW: we will be using one bit of the 16 bits to check if the packet is compressed or not</span>00132 <span class="comment">// so changing stuff to half the value</span>00133 <span class="comment">// MAX ID : 32767, e tem que sobrar espaco p/ uns 10 IDs especiais</span>00134 <span class="comment">//</span>00135 <span class="preprocessor">#define LAST_USHORT_ID 32512 // ainda
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -