acthandler_8c-source.html
来自「仿真人工智能是指用人工的方法和技术」· HTML 代码 · 共 206 行 · 第 1/2 页
HTML
206 行
<!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>ActHandler.C Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"><!-- Generated by Doxygen 1.2.12 --><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>ActHandler.C</h1><a href="ActHandler_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font>00002 <font class="comment">Copyright (c) 2000,2001, Jelle Kok, University of Amsterdam</font>00003 <font class="comment">All rights reserved.</font>00004 <font class="comment"></font>00005 <font class="comment">Redistribution and use in source and binary forms, with or without </font>00006 <font class="comment">modification, are permitted provided that the following conditions are met:</font>00007 <font class="comment"></font>00008 <font class="comment">1. Redistributions of source code must retain the above copyright notice, this </font>00009 <font class="comment">list of conditions and the following disclaimer. </font>00010 <font class="comment"></font>00011 <font class="comment">2. Redistributions in binary form must reproduce the above copyright notice, </font>00012 <font class="comment">this list of conditions and the following disclaimer in the documentation </font>00013 <font class="comment">and/or other materials provided with the distribution. </font>00014 <font class="comment"></font>00015 <font class="comment">3. Neither the name of the University of Amsterdam nor the names of its </font>00016 <font class="comment">contributors may be used to endorse or promote products derived from this </font>00017 <font class="comment">software without specific prior written permission. </font>00018 <font class="comment"></font>00019 <font class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" </font>00020 <font class="comment">AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </font>00021 <font class="comment">IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE </font>00022 <font class="comment">DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE </font>00023 <font class="comment">FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </font>00024 <font class="comment">DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR </font>00025 <font class="comment">SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER </font>00026 <font class="comment">CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, </font>00027 <font class="comment">OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </font>00028 <font class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</font>00029 <font class="comment">*/</font>00043 <font class="preprocessor">#include "<a class="code" href="ActHandler_8h.html">ActHandler.h</a>"</font>00044 00045 <font class="preprocessor">#include <poll.h></font> <font class="comment">// poll</font>00046 <font class="preprocessor">#include <sys/poll.h></font> <font class="comment">// poll</font>00047 <font class="preprocessor">#include <signal.h></font> <font class="comment">// SIGALARM</font>00048 <a name="l00049"></a><a class="code" href="ActHandler_8C.html#a0">00049</a> <a class="code" href="classActHandler.html">ActHandler</a>* <a class="code" href="ActHandler_8C.html#a0">ACT</a>; <a name="l00057"></a><a class="code" href="ActHandler_8C.html#a1">00057</a> <font class="keyword">extern</font> <font class="keywordtype">void</font> <a class="code" href="ActHandler_8h.html#a1">sigalarmHandler</a>( <font class="keywordtype">int</font> i )00058 {00059 ACT-><a class="code" href="classActHandler.html#a4">sendCommands</a>( );00060 }00061 <a name="l00067"></a><a class="code" href="classActHandler.html#a0">00067</a> <a class="code" href="classActHandler.html#a0">ActHandler::ActHandler</a>( <a class="code" href="classConnection.html">Connection</a> *c, <a class="code" href="classWorldModel.html">WorldModel</a> *wm, <a class="code" href="classServerSettings.html">ServerSettings</a> *ss )00068 {00069 <a class="code" href="classActHandler.html#o0">connection</a> = c;00070 <a class="code" href="classActHandler.html#o1">SS</a> = ss;00071 <a class="code" href="classActHandler.html#o2">WM</a> = wm;00072 00073 <a class="code" href="classActHandler.html#o5">m_iMultipleCommands</a> = 0;00074 ACT = <font class="keyword">this</font>; <font class="comment">// needed to let signal call method from class</font>00075 }00076 <a name="l00078"></a><a class="code" href="classActHandler.html#a2">00078</a> <font class="keywordtype">void</font> <a class="code" href="classActHandler.html#a2">ActHandler::emptyQueue</a>( )00079 {00080 <a class="code" href="classActHandler.html#o3">m_queueOneCycleCommand</a>.<a class="code" href="classSoccerCommand.html#m1">commandType</a> = <a class="code" href="SoccerTypes_8h.html#a247a180">CMD_ILLEGAL</a>;00081 <font class="keywordflow">for</font>( <font class="keywordtype">int</font> i = 0; i < <a class="code" href="SoccerTypes_8h.html#a5">MAX_COMMANDS</a> - 1 ; i ++ )00082 <a class="code" href="classActHandler.html#o4">m_queueMultipleCommands</a>[i].<a class="code" href="classSoccerCommand.html#m1">commandType</a> = <a class="code" href="SoccerTypes_8h.html#a247a180">CMD_ILLEGAL</a>;00083 <a class="code" href="classActHandler.html#o5">m_iMultipleCommands</a>=0;00084 }00085 <a name="l00088"></a><a class="code" href="classActHandler.html#a3">00088</a> <font class="keywordtype">bool</font> <a class="code" href="classActHandler.html#a3">ActHandler::isQueueEmpty</a>()00089 {00090 <font class="keywordflow">return</font> <a class="code" href="classActHandler.html#o3">m_queueOneCycleCommand</a>.<a class="code" href="classSoccerCommand.html#m1">commandType</a> == <a class="code" href="SoccerTypes_8h.html#a247a180">CMD_ILLEGAL</a> &&00091 <a class="code" href="classActHandler.html#o5">m_iMultipleCommands</a> == 0;00092 }00093 <a name="l00102"></a><a class="code" href="classActHandler.html#a4">00102</a> <font class="keywordtype">bool</font> <a class="code" href="classActHandler.html#a4">ActHandler::sendCommands</a>( )00103 {00104 <font class="keyword">static</font> <a class="code" href="classTime.html">Time</a> timeLastSent = -1;00105 <font class="keywordtype">bool</font> bNoOneCycle = <font class="keyword">false</font>;00106 <font class="keywordtype">char</font> strCommand[<a class="code" href="SoccerTypes_8h.html#a6">MAX_MSG</a>];00107 strCommand[0] = <font class="charliteral">'\0'</font>;00108 00109 <font class="keywordflow">if</font>( <a class="code" href="classActHandler.html#o2">WM</a>-><a class="code" href="classWorldModel.html#a4">getCurrentTime</a>() == timeLastSent )00110 {00111 Log.logWithTime( 2, <font class="stringliteral">" already sent message; don't send"</font> );00112 <font class="keywordflow">return</font> <font class="keyword">false</font>;00113 }00114 00115 <font class="keywordflow">if</font>(<a class="code" href="classActHandler.html#o2">WM</a>-><a class="code" href="classWorldModel.html#a72">isQueuedActionPerformed</a>() == <font class="keyword">false</font> && <font class="comment">// don't send action when</font>00116 <a class="code" href="classActHandler.html#o3">m_queueOneCycleCommand</a>.<a class="code" href="classSoccerCommand.html#m1">commandType</a> != <a class="code" href="SoccerTypes_8h.html#a247a185">CMD_CATCH</a>) <font class="comment">// previous one is not</font>00117 { <font class="comment">// not processed yet</font>00118 Log.logWithTime( 2, <font class="stringliteral">" previous message not processed yet; don't send"</font> );00119 <font class="keywordflow">return</font> <font class="keyword">false</font>; <font class="comment">// except with catch since</font>00120 } <font class="comment">// too important</font>00121 00122 <font class="comment">// make string of primary action and send it to server (if there was any)</font>00123 <a class="code" href="classActHandler.html#o3">m_queueOneCycleCommand</a>.<a class="code" href="classSoccerCommand.html#a7">getCommandString</a>( strCommand, <a class="code" href="classActHandler.html#o1">SS</a> );00124 <font class="keywordflow">if</font>( strCommand[0] != <font class="charliteral">'\0'</font> )00125 {00126 <a class="code" href="classActHandler.html#o0">connection</a>-><a class="code" href="classConnection.html#a8">sendMessage</a>( strCommand );00127 Log.logWithTime( 2, <font class="stringliteral">" send queued action to server: %s"</font>, strCommand);00128 }00129 <font class="keywordflow">else</font>00130 {00131 bNoOneCycle = <font class="keyword">true</font>;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?