📄 classzigserver__c.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>zigserver_c class Reference</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>zigserver_c Class Reference</h1>The server class; extend this class (overriding the marked methods) to implement your own "game server" class. <a href="#_details">More...</a><p><code>#include <<a class="el" href="zigserver_8h-source.html">zigserver.h</a>></code><p><a href="classzigserver__c-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0><tr><td></td></tr><tr><td colspan=2><br><h2>Public Methods</h2></td></tr><tr><td nowrap align=right valign=top><a name="a0" doxytag="zigserver_c::zigserver_c"></a> </td><td valign=bottom><a class="el" href="classzigserver__c.html#a0">zigserver_c</a> (<a class="el" href="classconsole__c.html">console_c</a> *conio)</td></tr><tr><td> </td><td><font size=-1><em>ctor. you must pass a <a class="el" href="classconsole__c.html">console_c</a> instance that will be used as output for internal debug messages.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a1" doxytag="zigserver_c::~zigserver_c"></a>virtual </td><td valign=bottom><a class="el" href="classzigserver__c.html#a1">~zigserver_c</a> ()</td></tr><tr><td> </td><td><font size=-1><em>dtor</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a2" doxytag="zigserver_c::zigserver_c"></a> </td><td valign=bottom><a class="el" href="classzigserver__c.html#a2">zigserver_c</a> ()</td></tr><tr><td> </td><td><font size=-1><em>ctor: no console; if you want to set a console later, call <a class="el" href="classzigserver__c.html#a3">set_console()</a>. messages generated by this zigserver between the object construction and the call to <a class="el" href="classzigserver__c.html#a3">set_console()</a> will be sent to the default global console (console_c::con)</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a3" doxytag="zigserver_c::set_console"></a>void </td><td valign=bottom><a class="el" href="classzigserver__c.html#a3">set_console</a> (<a class="el" href="classconsole__c.html">console_c</a> *conio)</td></tr><tr><td> </td><td><font size=-1><em>set the console (works with the no-args ctor)</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a4" doxytag="zigserver_c::set_server_tick"></a>void </td><td valign=bottom><a class="el" href="classzigserver__c.html#a4">set_server_tick</a> (double tick=0.1)</td></tr><tr><td> </td><td><font size=-1><em>sets the server's logic update (and, indirectly, the network's) tick rate. the parameter is a real number for the interval, in seconds, between calls to the <a class="el" href="classzigserver__c.html#a17">update_frame()</a> method. WARNING: It's better to call this BEFORE any clients connect to the server (in your game server's "<a class="el" href="classzigserver__c.html#a16">init()</a>" callback), and NOT change it afterwards.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a5" doxytag="zigserver_c::set_net_ratio"></a>void </td><td valign=bottom><a class="el" href="classzigserver__c.html#a5">set_net_ratio</a> (int ratio=1)</td></tr><tr><td> </td><td><font size=-1><em>sets the server's update ticks to net ticks ratio. example: with set_server_tick(0.05), the server calls <a class="el" href="classzigserver__c.html#a17">update_frame()</a> at 20Hz. if set_net_ratio(1), then it calls <a class="el" href="classzigserver__c.html#a18">broadcast_frame()</a> at 20Hz (every 50ms) too, but with set_net_ratio(2), it calls broadcast at 10Hz (every 100ms), and with set_net_ratio(3), it calls at 6.66666666667Hz (every 150ms). WARNING: It's better to call this BEFORE any clients connect to the server (in your game server's "<a class="el" href="classzigserver__c.html#a16">init()</a>" callback), and NOT change it afterwards.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a6" doxytag="zigserver_c::set_shutdown_timeout"></a>void </td><td valign=bottom><a class="el" href="classzigserver__c.html#a6">set_shutdown_timeout</a> (int timeout=5)</td></tr><tr><td> </td><td><font size=-1><em>set the shutdown timeout in seconds. the default value of the paramter is the default value of the timeout (this is called in the constructor)</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a7" doxytag="zigserver_c::set_client_timeout"></a>void </td><td valign=bottom><a class="el" href="classzigserver__c.html#a7">set_client_timeout</a> (int timeout=30)</td></tr><tr><td> </td><td><font size=-1><em>set client timeout. client will be disconnected automatically if it does not send any packets in the specified timeout in seconds.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a8" doxytag="zigserver_c::set_default_send_message_policy"></a>void </td><td valign=bottom><a class="el" href="classzigserver__c.html#a8">set_default_send_message_policy</a> (int send_policy)</td></tr><tr><td> </td><td><font size=-1><em>set the default "send policy" value (RSP_CRITICAL, RSP_HIGHEST, etc.) for reliable messages that should be used when the caller of the <a class="el" href="classzigserver__c.html#a37">send_message()</a> method does not specify the "send policy" that should be used.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a9" doxytag="zigserver_c::set_timing_policy"></a>void </td><td valign=bottom><a class="el" href="classzigserver__c.html#a9">set_timing_policy</a> (int policy=ZIGTIMING_SLEEP)</td></tr><tr><td> </td><td><font size=-1><em>set the timing policy. called from constructor to set default.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a10" doxytag="zigserver_c::set_compression"></a>void </td><td valign=bottom><a class="el" href="classzigserver__c.html#a10">set_compression</a> (int minimum_packet_size=-1)</td></tr><tr><td> </td><td><font size=-1><em>configure usage of packet compression. to turn on the sending of compressed packets at any time, pass a value >=0 as argument, which specifies the minimum size that the packet must have, in bytes, to be compressed (pass 0 to compress all outgoing packets). to turn off the sending of compressed packets at any time, call this method with no parameters (or a negative value as parameter). NOTE: this call resets the compression stats.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a11" doxytag="zigserver_c::run"></a>bool </td><td valign=bottom><a class="el" href="classzigserver__c.html#a11">run</a> (int port, int maxplayers, int channel_port, int threads_prio=ZIGTHREADSPRIO_ALL_HIGH, int threading_strategy=ZIG_SERVER_THREADING_1_N)</td></tr><tr><td> </td><td><font size=-1><em>starts and runs the server. this call blocks the thread that called it to work as the main thread of the server. in other words, this call only returns when the server wants to shutdown (via some input triggered at the <a class="el" href="classzigserver__c.html#a20">poll_input()</a> maybe?) returns false if there was an error. port: the port that the clients will have to connect() to. maxplayers: the hard maximum number of simultaneous players that the server will support. channel_port: a TCP port for listen socket. threads_prio: when using ZIG_SERVER_THREADING_1_1, the thread priority assignment strategy to be used (see <a class="el" href="zig_8h.html">zig.h</a>) threading_strategy: the threading strategy to be used for dealing with multiple clients (see <a class="el" href="zig_8h.html">zig.h</a>)</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a12" doxytag="zigserver_c::run_async"></a>bool </td><td valign=bottom><a class="el" href="classzigserver__c.html#a12">run_async</a> (int port, int maxplayers, int channel_port, int threads_prio=ZIGTHREADSPRIO_ALL_HIGH, int threading_strategy=ZIG_SERVER_THREADING_1_N)</td></tr><tr><td> </td><td><font size=-1><em>starts the server and starts a new thread to run the server. the caller thread returns immediatelly. the caller thread may call <a class="el" href="classzigserver__c.html#a14">stop()</a> at a later time to terminate the server and join with it's thread. returns false if there was an error. port: the port that the clients will have to connect() to. maxplayers: the hard maximum number of simultaneous players that the server will support. channel_port: a TCP port for listen socket. threads_prio: when using ZIG_SERVER_THREADING_1_1, the thread priority assignment strategy to be used (see <a class="el" href="zig_8h.html">zig.h</a>) threading_strategy: the threading strategy to be used for dealing with multiple clients (see <a class="el" href="zig_8h.html">zig.h</a>)</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a13" doxytag="zigserver_c::run_nonblocking"></a>bool </td><td valign=bottom><a class="el" href="classzigserver__c.html#a13">run_nonblocking</a> (int port, int maxplayers, int channel_port, int threads_prio=ZIGTHREADSPRIO_ALL_HIGH)</td></tr><tr><td> </td><td><font size=-1><em>starts the server in non-blocking mode. the caller thread returns immediatelly. the caller thread may call <a class="el" href="classzigserver__c.html#a14">stop()</a> at a later time to terminate the server. returns false if there was an error. port: the port that the clients will have to connect() to. maxplayers: the hard maximum number of simultaneous players that the server will support. channel_port: a TCP port for listen socket. threads_prio: when using ZIG_SERVER_THREADING_1_1, the thread priority assignment strategy to be used (see <a class="el" href="zig_8h.html">zig.h</a>) WHAT YOU MUST DO AFTER CALLING THIS METHOD: you must periodically call the <a class="el" href="classzigserver__c.html#a15">process_nonblocking()</a> method, or the server won't communicate. typically, you will do this inside your own "main loop". IMPORTANT: both the <a class="el" href="classzigserver__c.html#a19">render_frame()</a> and <a class="el" href="classzigserver__c.html#a20">poll_input()</a> methods WILL NOT BE CALLED! when running non-blocking, it is YOUR responsibility to deal with the timing of polling input and rendering to the screen (controlling frames-per-second).</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a14" doxytag="zigserver_c::stop"></a>bool </td><td valign=bottom><a class="el" href="classzigserver__c.html#a14">stop</a> ()</td></tr><tr><td> </td><td><font size=-1><em>stops the server. call this function if you called <a class="el" href="classzigserver__c.html#a12">run_async()</a> or run_non_blocking(). if running async, stops and joins the thread running the server. if running non blocking, just makes sure that the server shuts down. takes some time, as it involves sending messages and waiting responses. 'timeout' specifies how much time to wait before nuking the server, disregarding the shutdown network protocol for clients.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a15" doxytag="zigserver_c::process_nonblocking"></a>int </td><td valign=bottom><a class="el" href="classzigserver__c.html#a15">process_nonblocking</a> ()</td></tr><tr><td> </td><td><font size=-1><em>ONLY IF USING run_non_blocking: runs timing logic to decide whether it's time to call back the application's <a class="el" href="classzigserver__c.html#a17">update_frame()</a> or <a class="el" href="classzigserver__c.html#a18">broadcast_frame()</a> callbacks. IMPORTANT: if you called run_non_blocking() to start running the server, you MUST call this method periodically (on your own code's "main loop" probably) or the server won't communicate, that is, your app's "<a class="el" href="classzigserver__c.html#a17">update_frame()</a>" and "<a class="el" href="classzigserver__c.html#a18">broadcast_frame()</a>" methods will not get called at all. RETURN VALUE: the status code returned by the socket polling code (which is the number of client sockets that were read, or -1 if server was or is now stopped or if some error occurred while reading.</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a16" doxytag="zigserver_c::init"></a>virtual bool </td><td valign=bottom><a class="el" href="classzigserver__c.html#a16">init</a> ()</td></tr><tr><td> </td><td><font size=-1><em>SHOULD OVERRIDE: called at the start of the "run" method. this should initialize stuff needed for the subsequent calls to render_frame, poll_input, update_frame, etc. for example: loading resources, scripts... return FALSE to cause shutdown (if initialization fails, for example).</em></font><br><br></td></tr><tr><td nowrap align=right valign=top><a name="a17" doxytag="zigserver_c::update_frame"></a>virtual bool </td><td valign=bottom><a class="el" href="classzigserver__c.html#a17">update_frame</a> ()</td></tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -