<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US"> <head> <title>libkdegames: kgameio.cpp Source File (libkdegames)</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="pics-label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline DE v2.0" l gen true for "http://www.kde.org" r (nz 1 vz 1 lz 1 oz 1 cb 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://www.kde.org" r (n 0 s 0 v 0 l 0))' /> <meta name="trademark" content="KDE e.V." /> <meta name="description" content="K Desktop Environment Homepage, KDE.org" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="robots" content="all" /> <link rel="shortcut icon" href="../../favicon.ico" /> <link rel="stylesheet" media="screen" type="text/css" title="APIDOX" href="doxygen.css" /> </head> <body> <div id="nav_header_top" align="right"> <a href="#content" class="doNotDisplay" accesskey="2">Skip to main content ::</a> <a href="../.."><img id="nav_header_logo" alt="Home" align="left" src="../../kde_gear_64.png" border="0" /></a> <span class="doNotDisplay">::</span> <div id="nav_header_title" align="left">KDE API Reference</div> </div> <div id="nav_header_bottom" align="right"> <span class="doNotDisplay">:: <a href="#navigation" accesskey="5">Skip to Link Menu</a><br/></span> <div id="nav_header_bottom_right" style="text-align: left;"> / <a href="../..">API Reference</a> / <a href=".">libkdegames</a> </div> </div> <table id="main" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top" class="menuheader" height="0"></td> <td id="contentcolumn" valign="top" rowspan="2" > <div id="content" style="padding-top: 0px;"><div style="width:100%; margin: 0px; padding: 0px;"> <a name="content"></a> <!-- Generated by Doxygen 1.5.5 --> <h1>kgameio.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> This file is part of the KDE games library</span> <a name="l00003"></a>00003 <span class="comment"> Copyright (C) 2001 Martin Heni (martin@heni-online.de)</span> <a name="l00004"></a>00004 <span class="comment"> Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)</span> <a name="l00005"></a>00005 <span class="comment"></span> <a name="l00006"></a>00006 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00007"></a>00007 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00008"></a>00008 <span class="comment"> License version 2 as published by the Free Software Foundation.</span> <a name="l00009"></a>00009 <span class="comment"></span> <a name="l00010"></a>00010 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00013"></a>00013 <span class="comment"> Library General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment"></span> <a name="l00015"></a>00015 <span class="comment"> You should have received a copy of the GNU Library General Public License</span> <a name="l00016"></a>00016 <span class="comment"> along with this library; see the file COPYING.LIB. If not, write to</span> <a name="l00017"></a>00017 <span class="comment"> the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,</span> <a name="l00018"></a>00018 <span class="comment"> Boston, MA 02110-1301, USA.</span> <a name="l00019"></a>00019 <span class="comment">*/</span> <a name="l00020"></a>00020 <span class="comment">/*</span> <a name="l00021"></a>00021 <span class="comment"> $Id: kgameio.cpp 465369 2005-09-29 14:33:08Z mueller $</span> <a name="l00022"></a>00022 <span class="comment">*/</span> <a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="preprocessor">#include "kgameio.h"</span> <a name="l00025"></a>00025 <span class="preprocessor">#include "kgameio.moc"</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "kgame.h"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "kplayer.h"</span> <a name="l00028"></a>00028 <span class="preprocessor">#include "kgamemessage.h"</span> <a name="l00029"></a>00029 <span class="preprocessor">#include "kmessageio.h"</span> <a name="l00030"></a>00030 <a name="l00031"></a>00031 <span class="preprocessor">#include <kdebug.h></span> <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="preprocessor">#include <qwidget.h></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <qbuffer.h></span> <a name="l00035"></a>00035 <span class="preprocessor">#include <qtimer.h></span> <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="preprocessor">#include <stdlib.h></span> <a name="l00038"></a>00038 <a name="l00039"></a>00039 <span class="comment">// ----------------------- Generic IO -------------------------</span> <a name="l00040"></a><a class="code" href="classKGameIO.html#06f7a8c6c09a779ba0621fd543b13683">00040</a> <a class="code" href="classKGameIO.html#06f7a8c6c09a779ba0621fd543b13683" title="Constructs a KGameIO object.">KGameIO::KGameIO</a>() : QObject(0,0) <a name="l00041"></a>00041 { <a name="l00042"></a>00042 kdDebug(11001) << k_funcinfo << <span class="stringliteral">": this="</span> << <span class="keyword">this</span> << <span class="stringliteral">", sizeof(this)"</span> << <span class="keyword">sizeof</span>(<a class="code" href="classKGameIO.html" title="Base class for IO devices for games.">KGameIO</a>) << endl; <a name="l00043"></a>00043 mPlayer = 0; <a name="l00044"></a>00044 } <a name="l00045"></a>00045 <a name="l00046"></a>00046 <a class="code" href="classKGameIO.html#06f7a8c6c09a779ba0621fd543b13683" title="Constructs a KGameIO object.">KGameIO::KGameIO</a>(<a class="code" href="classKPlayer.html" title="Base class for a game player.">KPlayer</a>* <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>) : QObject(0,0) <a name="l00047"></a>00047 { <a name="l00048"></a>00048 kdDebug(11001) << k_funcinfo << <span class="stringliteral">": this="</span> << <span class="keyword">this</span> << <span class="stringliteral">", sizeof(this)"</span> << <span class="keyword">sizeof</span>(<a class="code" href="classKGameIO.html" title="Base class for IO devices for games.">KGameIO</a>) << endl; <a name="l00049"></a>00049 mPlayer = 0; <a name="l00050"></a>00050 <span class="keywordflow">if</span> (player) <a name="l00051"></a>00051 { <a name="l00052"></a>00052 player-><a class="code" href="classKPlayer.html#7cf34f66a583cd003b71e9e5648269f3" title="Adds an IO device for the player.">addGameIO</a>(<span class="keyword">this</span>); <a name="l00053"></a>00053 } <a name="l00054"></a>00054 } <a name="l00055"></a>00055 <a name="l00056"></a>00056 KGameIO::~KGameIO() <a name="l00057"></a>00057 { <a name="l00058"></a>00058 kdDebug(11001) << k_funcinfo << <span class="stringliteral">": this="</span> << <span class="keyword">this</span> << endl; <a name="l00059"></a>00059 <span class="comment">// unregister ourselves</span> <a name="l00060"></a>00060 <span class="keywordflow">if</span> (<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00061"></a>00061 { <a name="l00062"></a>00062 <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()-><a class="code" href="classKPlayer.html#86618e1eaaac3788c331107c191cc283" title="remove (and delete) a game IO device">removeGameIO</a>(<span class="keyword">this</span>, <span class="keyword">false</span>); <a name="l00063"></a>00063 } <a name="l00064"></a>00064 } <a name="l00065"></a>00065 <a name="l00066"></a><a class="code" href="classKGameIO.html#b34ff5dafad0412c1ee871ed1dd8dba8">00066</a> <span class="keywordtype">void</span> <a class="code" href="classKGameIO.html#b34ff5dafad0412c1ee871ed1dd8dba8" title="Init this device by setting the player and e.g.">KGameIO::initIO</a>(<a class="code" href="classKPlayer.html" title="Base class for a game player.">KPlayer</a> *p) <a name="l00067"></a>00067 { <a name="l00068"></a>00068 <a class="code" href="classKGameIO.html#78a50548e29d842e03e7b69af1754fbf" title="Sets the player to which this IO belongs to.">setPlayer</a>(p); <a name="l00069"></a>00069 } <a name="l00070"></a>00070 <a name="l00071"></a><a class="code" href="classKGameIO.html#20bf262118d7420385351c1339b4c40f">00071</a> <span class="keywordtype">void</span> <a class="code" href="classKGameIO.html#20bf262118d7420385351c1339b4c40f" title="Notifies the IO device that the player&#39;s setTurn had been called Called by KPlayer...">KGameIO::notifyTurn</a>(<span class="keywordtype">bool</span> b) <a name="l00072"></a>00072 { <a name="l00073"></a>00073 <span class="keywordflow">if</span> (!<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00074"></a>00074 { <a name="l00075"></a>00075 kdWarning(11001) << k_funcinfo << <span class="stringliteral">": player() is NULL"</span> << endl; <a name="l00076"></a>00076 <span class="keywordflow">return</span>; <a name="l00077"></a>00077 } <a name="l00078"></a>00078 <span class="keywordtype">bool</span> sendit=<span class="keyword">false</span>; <a name="l00079"></a>00079 QByteArray buffer; <a name="l00080"></a>00080 QDataStream stream(buffer, IO_WriteOnly); <a name="l00081"></a>00081 emit <a class="code" href="classKGameIO.html#0091d3ba6ae94d70fc83a362087f32a9" title="Signal generated when KPlayer::myTurn changes.">signalPrepareTurn</a>(stream, b, <span class="keyword">this</span>, &sendit); <a name="l00082"></a>00082 <span class="keywordflow">if</span> (sendit) <a name="l00083"></a>00083 { <a name="l00084"></a>00084 QDataStream ostream(buffer,IO_ReadOnly); <a name="l00085"></a>00085 Q_UINT32 sender = <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()-><a class="code" href="classKPlayer.html#a1151863225396c0f96678bf3ca938ae" title="Returns the id of the player.">id</a>(); <span class="comment">// force correct sender</span> <a name="l00086"></a>00086 kdDebug(11001) << <span class="stringliteral">"Prepare turn sendInput"</span> << endl; <a name="l00087"></a>00087 <a class="code" href="classKGameIO.html#2ebd7ca9f71a45a0bdfe05d6e84e7117" title="Send an input message using KPlayer::forwardInput.">sendInput</a>(ostream, <span class="keyword">true</span>, sender); <a name="l00088"></a>00088 } <a name="l00089"></a>00089 } <a name="l00090"></a>00090 <a name="l00091"></a><a class="code" href="classKGameIO.html#dbbb350ec3c9ef0d057cdb222158f8b9">00091</a> <a class="code" href="classKGame.html" title="The main KDE game object.">KGame</a>* <a class="code" href="classKGameIO.html#dbbb350ec3c9ef0d057cdb222158f8b9" title="Equivalent to player()-&gt;game().">KGameIO::game</a>()<span class="keyword"> const</span> <a name="l00092"></a>00092 <span class="keyword"></span>{ <a name="l00093"></a>00093 <span class="keywordflow">if</span> (!<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00094"></a>00094 { <a name="l00095"></a>00095 <span class="keywordflow">return</span> 0; <a name="l00096"></a>00096 } <a name="l00097"></a>00097 <span class="keywordflow">return</span> <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()-><a class="code" href="classKPlayer.html#377817feb7e53e5fe6deedc23f399b17" title="Query to which game the player belongs to.">game</a>(); <a name="l00098"></a>00098 } <a name="l00099"></a>00099 <a name="l00100"></a><a class="code" href="classKGameIO.html#2ebd7ca9f71a45a0bdfe05d6e84e7117">00100</a> <span class="keywordtype">bool</span> <a class="code" href="classKGameIO.html#2ebd7ca9f71a45a0bdfe05d6e84e7117" title="Send an input message using KPlayer::forwardInput.">KGameIO::sendInput</a>(QDataStream& s, <span class="keywordtype">bool</span> transmit, Q_UINT32 sender) <a name="l00101"></a>00101 { <a name="l00102"></a>00102 <span class="keywordflow">if</span> (!<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00103"></a>00103 { <a name="l00104"></a>00104 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00105"></a>00105 } <a name="l00106"></a>00106 <span class="keywordflow">return</span> <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()-><a class="code" href="classKPlayer.html#41572b54137d6c26cd426a2d450c7afc" title="Forwards input to the game object.">forwardInput</a>(s, transmit, sender); <a name="l00107"></a>00107 } <a name="l00108"></a>00108 <a name="l00109"></a><a class="code" href="classKGameIO.html#865012eb7613972d1c0ed8e1ba67ff6a">00109</a> <span class="keywordtype">void</span> <a class="code" href="classKGameIO.html#865012eb7613972d1c0ed8e1ba67ff6a" title="Gives debug output of the game status.">KGameIO::Debug</a>() <a name="l00110"></a>00110 { <a name="l00111"></a>00111 kdDebug(11001) << <span class="stringliteral">"------------------- KGAMEINPUT --------------------"</span> << endl; <a name="l00112"></a>00112 kdDebug(11001) << <span class="stringliteral">"this: "</span> << <span class="keyword">this</span> << endl; <a name="l00113"></a>00113 kdDebug(11001) << <span class="stringliteral">"rtti : "</span> << <a class="code" href="classKGameIO.html#88a4154d5e130823ee152c0e0258cc62" title="Run time idendification.">rtti</a>() << endl; <a name="l00114"></a>00114 kdDebug(11001) << <span class="stringliteral">"Player: "</span> << <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>() << endl; <a name="l00115"></a>00115 kdDebug(11001) << <span class="stringliteral">"---------------------------------------------------"</span> << endl; <a name="l00116"></a>00116 } <a name="l00117"></a>00117 <a name="l00118"></a>00118 <a name="l00119"></a>00119 <span class="comment">// ----------------------- Key IO ---------------------------</span> <a name="l00120"></a><a class="code" href="classKGameKeyIO.html#07e2339645eddfe668955045b5835f71">00120</a> <a class="code" href="classKGameKeyIO.html#07e2339645eddfe668955045b5835f71" title="Create a keyboard input devices.">KGameKeyIO::KGameKeyIO</a>(QWidget *parent) <a name="l00121"></a>00121 : <a class="code" href="classKGameIO.html" title="Base class for IO devices for games.">KGameIO</a>() <a name="l00122"></a>00122 { <a name="l00123"></a>00123 <span class="keywordflow">if</span> (parent) <a name="l00124"></a>00124 { <a name="l00125"></a>00125 kdDebug(11001) << <span class="stringliteral">"Key Event filter installed"</span> << endl; <a name="l00126"></a>00126 parent->installEventFilter(<span class="keyword">this</span>); <a name="l00127"></a>00127 } <a name="l00128"></a>00128 } <a name="l00129"></a>00129 <a name="l00130"></a>00130 KGameKeyIO::~KGameKeyIO() <a name="l00131"></a>00131 { <a name="l00132"></a>00132 <span class="keywordflow">if</span> (parent()) <a name="l00133"></a>00133 { <a name="l00134"></a>00134 parent()->removeEventFilter(<span class="keyword">this</span>); <a name="l00135"></a>00135 } <a name="l00136"></a>00136 } <a name="l00137"></a>00137 <a name="l00138"></a><a class="code" href="classKGameKeyIO.html#83192d0e296ab3bade49cb8564f574fd">00138</a> <span class="keywordtype">int</span> <a class="code" href="classKGameKeyIO.html#83192d0e296ab3bade49cb8564f574fd" title="The idendification of the IO.">KGameKeyIO::rtti</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> KeyIO; } <a name="l00139"></a>00139 <a name="l00140"></a><a class="code" href="classKGameKeyIO.html#7592f65f23bb0359381b56a19a874849">00140</a> <span class="keywordtype">bool</span> <a class="code" href="classKGameKeyIO.html#7592f65f23bb0359381b56a19a874849" title="Internal method to process the events.">KGameKeyIO::eventFilter</a>( QObject *o, QEvent *e ) <a name="l00141"></a>00141 { <a name="l00142"></a>00142 <span class="keywordflow">if</span> (!<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00143"></a>00143 { <a name="l00144"></a>00144 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00145"></a>00145 } <a name="l00146"></a>00146 <a name="l00147"></a>00147 <span class="comment">// key press/release</span> <a name="l00148"></a>00148 <span class="keywordflow">if</span> ( e->type() == QEvent::KeyPress || <a name="l00149"></a>00149 e->type() == QEvent::KeyRelease ) <a name="l00150"></a>00150 { <a name="l00151"></a>00151 QKeyEvent *k = (QKeyEvent*)e; <a name="l00152"></a>00152 <span class="comment">// kdDebug(11001) << "KGameKeyIO " << this << " key press/release " << k->key() << endl ;</span> <a name="l00153"></a>00153 QByteArray buffer; <a name="l00154"></a>00154 QDataStream stream(buffer,IO_WriteOnly); <a name="l00155"></a>00155 <span class="keywordtype">bool</span> eatevent=<span class="keyword">false</span>; <a name="l00156"></a>00156 emit <a class="code" href="classKGameKeyIO.html#25ecdf0aa7139e4707ec2066c9cfe03f" title="Signal handler for keyboard events.">signalKeyEvent</a>(<span class="keyword">this</span>,stream,k,&eatevent); <a name="l00157"></a>00157 QDataStream msg(buffer,IO_ReadOnly); <a name="l00158"></a>00158 <a name="l00159"></a>00159 <span class="keywordflow">if</span> (eatevent && <a class="code" href="classKGameIO.html#2ebd7ca9f71a45a0bdfe05d6e84e7117" title="Send an input message using KPlayer::forwardInput.">sendInput</a>(msg)) <a name="l00160"></a>00160 { <a name="l00161"></a>00161 <span class="keywordflow">return</span> eatevent; <a name="l00162"></a>00162 } <a name="l00163"></a>00163 <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// do not eat otherwise</span> <a name="l00164"></a>00164 } <a name="l00165"></a>00165 <span class="keywordflow">return</span> QObject::eventFilter( o, e ); <span class="comment">// standard event processing</span> <a name="l00166"></a>00166 } <a name="l00167"></a>00167 <a name="l00168"></a>00168 <a name="l00169"></a>00169 <span class="comment">// ----------------------- Mouse IO ---------------------------</span> <a name="l00170"></a><a class="code" href="classKGameMouseIO.html#1c943c4591ccbb945024265c2225e8d0">00170</a> <a class="code" href="classKGameMouseIO.html#1c943c4591ccbb945024265c2225e8d0" title="Creates a mouse IO device.">KGameMouseIO::KGameMouseIO</a>(QWidget *parent,<span class="keywordtype">bool</span> trackmouse) <a name="l00171"></a>00171 : <a class="code" href="classKGameIO.html" title="Base class for IO devices for games.">KGameIO</a>() <a name="l00172"></a>00172 { <a name="l00173"></a>00173 <span class="keywordflow">if</span> (parent) <a name="l00174"></a>00174 { <a name="l00175"></a>00175 kdDebug(11001) << <span class="stringliteral">"Mouse Event filter installed tracking="</span> << trackmouse << endl; <a name="l00176"></a>00176 parent->installEventFilter(<span class="keyword">this</span>); <a name="l00177"></a>00177 parent->setMouseTracking(trackmouse); <a name="l00178"></a>00178 } <a name="l00179"></a>00179 } <a name="l00180"></a>00180 <a name="l00181"></a>00181 KGameMouseIO::~KGameMouseIO() <a name="l00182"></a>00182 { <a name="l00183"></a>00183 <span class="keywordflow">if</span> (parent()) <a name="l00184"></a>00184 { <a name="l00185"></a>00185 parent()->removeEventFilter(<span class="keyword">this</span>); <a name="l00186"></a>00186 } <a name="l00187"></a>00187 } <a name="l00188"></a>00188 <a name="l00189"></a><a class="code" href="classKGameMouseIO.html#21475af059f43030f1063f6fa9f05ae2">00189</a> <span class="keywordtype">int</span> <a class="code" href="classKGameMouseIO.html#21475af059f43030f1063f6fa9f05ae2" title="The idendification of the IO.">KGameMouseIO::rtti</a>()<span class="keyword"> const</span> <a name="l00190"></a>00190 <span class="keyword"></span>{ <a name="l00191"></a>00191 <span class="keywordflow">return</span> MouseIO; <a name="l00192"></a>00192 } <a name="l00193"></a>00193 <a name="l00194"></a><a class="code" href="classKGameMouseIO.html#44941583e92ab36efab2dc58e545200b">00194</a> <span class="keywordtype">void</span> <a class="code" href="classKGameMouseIO.html#44941583e92ab36efab2dc58e545200b" title="Manually activate or deactivate mouse tracking.">KGameMouseIO::setMouseTracking</a>(<span class="keywordtype">bool</span> b) <a name="l00195"></a>00195 { <a name="l00196"></a>00196 <span class="keywordflow">if</span> (parent()) <a name="l00197"></a>00197 { <a name="l00198"></a>00198 ((QWidget*)parent())-><a class="code" href="classKGameMouseIO.html#44941583e92ab36efab2dc58e545200b" title="Manually activate or deactivate mouse tracking.">setMouseTracking</a>(b); <a name="l00199"></a>00199 } <a name="l00200"></a>00200 } <a name="l00201"></a>00201 <a name="l00202"></a><a class="code" href="classKGameMouseIO.html#33353803e0aea828d1c7074aa707f812">00202</a> <span class="keywordtype">bool</span> <a class="code" href="classKGameMouseIO.html#33353803e0aea828d1c7074aa707f812" title="Internal event filter.">KGameMouseIO::eventFilter</a>( QObject *o, QEvent *e ) <a name="l00203"></a>00203 { <a name="l00204"></a>00204 <span class="keywordflow">if</span> (!<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00205"></a>00205 { <a name="l00206"></a>00206 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00207"></a>00207 } <a name="l00208"></a>00208 <span class="comment">// kdDebug(11001) << "KGameMouseIO " << this << endl ;</span> <a name="l00209"></a>00209 <a name="l00210"></a>00210 <span class="comment">// mouse action</span> <a name="l00211"></a>00211 <span class="keywordflow">if</span> ( e->type() == QEvent::MouseButtonPress || <a name="l00212"></a>00212 e->type() == QEvent::MouseButtonRelease || <a name="l00213"></a>00213 e->type() == QEvent::MouseButtonDblClick || <a name="l00214"></a>00214 e->type() == QEvent::Wheel || <a name="l00215"></a>00215 e->type() == QEvent::MouseMove <a name="l00216"></a>00216 ) <a name="l00217"></a>00217 { <a name="l00218"></a>00218 QMouseEvent *k = (QMouseEvent*)e; <a name="l00219"></a>00219 <span class="comment">// kdDebug(11001) << "KGameMouseIO " << this << endl ;</span> <a name="l00220"></a>00220 QByteArray buffer; <a name="l00221"></a>00221 QDataStream stream(buffer,IO_WriteOnly); <a name="l00222"></a>00222 <span class="keywordtype">bool</span> eatevent=<span class="keyword">false</span>; <a name="l00223"></a>00223 emit <a class="code" href="classKGameMouseIO.html#1c5a79207c993c6f24dcc0cf38c5f079" title="Signal handler for mouse events.">signalMouseEvent</a>(<span class="keyword">this</span>,stream,k,&eatevent); <a name="l00224"></a>00224 <span class="comment">// kdDebug(11001) << "################# eatevent=" << eatevent << endl;</span> <a name="l00225"></a>00225 QDataStream msg(buffer,IO_ReadOnly); <a name="l00226"></a>00226 <span class="keywordflow">if</span> (eatevent && <a class="code" href="classKGameIO.html#2ebd7ca9f71a45a0bdfe05d6e84e7117" title="Send an input message using KPlayer::forwardInput.">sendInput</a>(msg)) <a name="l00227"></a>00227 { <a name="l00228"></a>00228 <span class="keywordflow">return</span> eatevent; <a name="l00229"></a>00229 } <a name="l00230"></a>00230 <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">// do not eat otherwise</span> <a name="l00231"></a>00231 } <a name="l00232"></a>00232 <span class="keywordflow">return</span> QObject::eventFilter( o, e ); <span class="comment">// standard event processing</span> <a name="l00233"></a>00233 } <a name="l00234"></a>00234 <a name="l00235"></a>00235 <a name="l00236"></a>00236 <span class="comment">// ----------------------- KGameProcesPrivate ---------------------------</span> <a name="l00237"></a>00237 <span class="keyword">class </span>KGameProcessIO::KGameProcessIOPrivate <a name="l00238"></a>00238 { <a name="l00239"></a>00239 <span class="keyword">public</span>: <a name="l00240"></a>00240 KGameProcessIOPrivate() <a name="l00241"></a>00241 { <a name="l00242"></a>00242 <span class="comment">//mMessageServer = 0;</span> <a name="l00243"></a>00243 <span class="comment">//mMessageClient = 0;</span> <a name="l00244"></a>00244 mProcessIO=0; <a name="l00245"></a>00245 } <a name="l00246"></a>00246 <span class="comment">//KMessageServer *mMessageServer;</span> <a name="l00247"></a>00247 <span class="comment">//KMessageClient *mMessageClient;</span> <a name="l00248"></a>00248 KMessageProcess *mProcessIO; <a name="l00249"></a>00249 }; <a name="l00250"></a>00250 <a name="l00251"></a>00251 <span class="comment">// ----------------------- Process IO ---------------------------</span> <a name="l00252"></a><a class="code" href="classKGameProcessIO.html#f8a129777a0080a01c1a6dbe1629e25e">00252</a> <a class="code" href="classKGameProcessIO.html#f8a129777a0080a01c1a6dbe1629e25e" title="Creates a computer player via a separate process.">KGameProcessIO::KGameProcessIO</a>(<span class="keyword">const</span> QString& name) <a name="l00253"></a>00253 : <a class="code" href="classKGameIO.html" title="Base class for IO devices for games.">KGameIO</a>() <a name="l00254"></a>00254 { <a name="l00255"></a>00255 kdDebug(11001) << k_funcinfo << <span class="stringliteral">": this="</span> << <span class="keyword">this</span> << <span class="stringliteral">", sizeof(this)="</span> << <span class="keyword">sizeof</span>(<a class="code" href="classKGameProcessIO.html" title="The KGameProcessIO class.">KGameProcessIO</a>) << endl; <a name="l00256"></a>00256 d = <span class="keyword">new</span> KGameProcessIOPrivate; <a name="l00257"></a>00257 <a name="l00258"></a>00258 <span class="comment">//kdDebug(11001) << "================= KMEssageServer ==================== " << endl;</span> <a name="l00259"></a>00259 <span class="comment">//d->mMessageServer=new KMessageServer(0,this);</span> <a name="l00260"></a>00260 <span class="comment">//kdDebug(11001) << "================= KMEssageClient ==================== " << endl;</span> <a name="l00261"></a>00261 <span class="comment">//d->mMessageClient=new KMessageClient(this);</span> <a name="l00262"></a>00262 kdDebug(11001) << <span class="stringliteral">"================= KMEssageProcessIO ==================== "</span> << endl; <a name="l00263"></a>00263 d->mProcessIO=<span class="keyword">new</span> KMessageProcess(<span class="keyword">this</span>,name); <a name="l00264"></a>00264 kdDebug(11001) << <span class="stringliteral">"================= KMEssage Add client ==================== "</span> << endl; <a name="l00265"></a>00265 <span class="comment">//d->mMessageServer->addClient(d->mProcessIO);</span> <a name="l00266"></a>00266 <span class="comment">//kdDebug(11001) << "================= KMEssage SetSErver ==================== " << endl;</span> <a name="l00267"></a>00267 <span class="comment">//d->mMessageClient->setServer(d->mMessageServer);</span> <a name="l00268"></a>00268 kdDebug(11001) << <span class="stringliteral">"================= KMEssage: Connect ==================== "</span> << endl; <a name="l00269"></a>00269 <span class="comment">//connect(d->mMessageClient, SIGNAL(broadcastReceived(const QByteArray&, Q_UINT32)),</span> <a name="l00270"></a>00270 <span class="comment">// this, SLOT(clientMessage(const QByteArray&, Q_UINT32)));</span> <a name="l00271"></a>00271 <span class="comment">//connect(d->mMessageClient, SIGNAL(forwardReceived(const QByteArray&, Q_UINT32, const QValueList <Q_UINT32> &)),</span> <a name="l00272"></a>00272 <span class="comment">// this, SLOT(clientMessage(const QByteArray&, Q_UINT32, const QValueList <Q_UINT32> &)));</span> <a name="l00273"></a>00273 connect(d->mProcessIO, SIGNAL(received(<span class="keyword">const</span> QByteArray&)), <a name="l00274"></a>00274 <span class="keyword">this</span>, SLOT(<a class="code" href="classKGameProcessIO.html#254ca9286bda893f00fbc2122938611a" title="Internal message handler to receive data from the process.">receivedMessage</a>(<span class="keyword">const</span> QByteArray&))); <a name="l00275"></a>00275 <span class="comment">//kdDebug(11001) << "Our client is id="<<d->mMessageClient->id() << endl;</span> <a name="l00276"></a>00276 } <a name="l00277"></a>00277 <a name="l00278"></a><a class="code" href="classKGameProcessIO.html#187fe65129580678be2950058b3c2b1c">00278</a> <a class="code" href="classKGameProcessIO.html#187fe65129580678be2950058b3c2b1c" title="Deletes the process input devices.">KGameProcessIO::~KGameProcessIO</a>() <a name="l00279"></a>00279 { <a name="l00280"></a>00280 kdDebug(11001) << k_funcinfo << <span class="stringliteral">": this="</span> << <span class="keyword">this</span> << endl; <a name="l00281"></a>00281 kdDebug(11001) << <span class="stringliteral">"player="</span><<<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>() << endl; <a name="l00282"></a>00282 <span class="keywordflow">if</span> (<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00283"></a>00283 { <a name="l00284"></a>00284 <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()-><a class="code" href="classKPlayer.html#86618e1eaaac3788c331107c191cc283" title="remove (and delete) a game IO device">removeGameIO</a>(<span class="keyword">this</span>,<span class="keyword">false</span>); <a name="l00285"></a>00285 } <a name="l00286"></a>00286 <span class="keywordflow">if</span> (d->mProcessIO) <a name="l00287"></a>00287 { <a name="l00288"></a>00288 <span class="keyword">delete</span> d->mProcessIO; <a name="l00289"></a>00289 d->mProcessIO=0; <a name="l00290"></a>00290 } <a name="l00291"></a>00291 <span class="keyword">delete</span> d; <a name="l00292"></a>00292 } <a name="l00293"></a>00293 <a name="l00294"></a><a class="code" href="classKGameProcessIO.html#ab06daea67f651f1637798e704529d97">00294</a> <span class="keywordtype">int</span> <a class="code" href="classKGameProcessIO.html#ab06daea67f651f1637798e704529d97" title="The idendification of the IO.">KGameProcessIO::rtti</a>()<span class="keyword"> const</span> <a name="l00295"></a>00295 <span class="keyword"></span>{ <a name="l00296"></a>00296 <span class="keywordflow">return</span> ProcessIO; <a name="l00297"></a>00297 } <a name="l00298"></a>00298 <a name="l00299"></a><a class="code" href="classKGameProcessIO.html#823281f4a928a6a1a69f12b82f33d0c6">00299</a> <span class="keywordtype">void</span> <a class="code" href="classKGameProcessIO.html#823281f4a928a6a1a69f12b82f33d0c6" title="Init this device by setting the player and e.g.">KGameProcessIO::initIO</a>(<a class="code" href="classKPlayer.html" title="Base class for a game player.">KPlayer</a> *p) <a name="l00300"></a>00300 { <a name="l00301"></a>00301 <a class="code" href="classKGameIO.html#b34ff5dafad0412c1ee871ed1dd8dba8" title="Init this device by setting the player and e.g.">KGameIO::initIO</a>(p); <a name="l00302"></a>00302 <span class="comment">// Send 'hello' to process</span> <a name="l00303"></a>00303 QByteArray buffer; <a name="l00304"></a>00304 QDataStream stream(buffer, IO_WriteOnly); <a name="l00305"></a>00305 Q_INT16 <span class="keywordtype">id</span> = p-><a class="code" href="classKPlayer.html#0728d51e848c183a6dba2935ccb4c4dd" title="Returns the user defined id of the player This value can be used arbitrary by you...">userId</a>(); <a name="l00306"></a>00306 stream << id; <a name="l00307"></a>00307 <a name="l00308"></a>00308 <span class="keywordtype">bool</span> sendit=<span class="keyword">true</span>; <a name="l00309"></a>00309 <span class="keywordflow">if</span> (p) <a name="l00310"></a>00310 { <a name="l00311"></a>00311 emit <a class="code" href="classKGameProcessIO.html#471cd73cf6737e12192cefef00b221c6" title="Signal generated when the computer player is added.">signalIOAdded</a>(<span class="keyword">this</span>,stream,p,&sendit); <a name="l00312"></a>00312 <span class="keywordflow">if</span> (sendit ) <a name="l00313"></a>00313 { <a name="l00314"></a>00314 Q_UINT32 sender = p-><a class="code" href="classKPlayer.html#a1151863225396c0f96678bf3ca938ae" title="Returns the id of the player.">id</a>(); <a name="l00315"></a>00315 kdDebug(11001) << <span class="stringliteral">"Sending IOAdded to process player !!!!!!!!!!!!!! "</span> << endl; <a name="l00316"></a>00316 <a class="code" href="classKGameProcessIO.html#f6b01bfdb454d86b339e5bb8e6a0b842" title="Send a system message to the process.">sendSystemMessage</a>(stream, KGameMessage::IdIOAdded, 0, sender); <a name="l00317"></a>00317 } <a name="l00318"></a>00318 } <a name="l00319"></a>00319 } <a name="l00320"></a>00320 <a name="l00321"></a><a class="code" href="classKGameProcessIO.html#dfc88299e5f7efeda143068114e986d8">00321</a> <span class="keywordtype">void</span> <a class="code" href="classKGameProcessIO.html#dfc88299e5f7efeda143068114e986d8" title="Notifies the IO device that the player&#39;s setTurn had been called Called by KPlayer...">KGameProcessIO::notifyTurn</a>(<span class="keywordtype">bool</span> b) <a name="l00322"></a>00322 { <a name="l00323"></a>00323 <span class="keywordflow">if</span> (!<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00324"></a>00324 { <a name="l00325"></a>00325 kdWarning(11001) << k_funcinfo << <span class="stringliteral">": player() is NULL"</span> << endl; <a name="l00326"></a>00326 <span class="keywordflow">return</span>; <a name="l00327"></a>00327 } <a name="l00328"></a>00328 <span class="keywordtype">bool</span> sendit=<span class="keyword">true</span>; <a name="l00329"></a>00329 QByteArray buffer; <a name="l00330"></a>00330 QDataStream stream(buffer,IO_WriteOnly); <a name="l00331"></a>00331 stream << (Q_INT8)b; <a name="l00332"></a>00332 emit <a class="code" href="classKGameIO.html#0091d3ba6ae94d70fc83a362087f32a9" title="Signal generated when KPlayer::myTurn changes.">signalPrepareTurn</a>(stream,b,<span class="keyword">this</span>,&sendit); <a name="l00333"></a>00333 <span class="keywordflow">if</span> (sendit) <a name="l00334"></a>00334 { <a name="l00335"></a>00335 Q_UINT32 sender=<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()-><a class="code" href="classKPlayer.html#a1151863225396c0f96678bf3ca938ae" title="Returns the id of the player.">id</a>(); <a name="l00336"></a>00336 kdDebug(11001) << <span class="stringliteral">"Sending Turn to process player !!!!!!!!!!!!!! "</span> << endl; <a name="l00337"></a>00337 <a class="code" href="classKGameProcessIO.html#f6b01bfdb454d86b339e5bb8e6a0b842" title="Send a system message to the process.">sendSystemMessage</a>(stream, KGameMessage::IdTurn, 0, sender); <a name="l00338"></a>00338 } <a name="l00339"></a>00339 } <a name="l00340"></a>00340 <a name="l00341"></a><a class="code" href="classKGameProcessIO.html#f6b01bfdb454d86b339e5bb8e6a0b842">00341</a> <span class="keywordtype">void</span> <a class="code" href="classKGameProcessIO.html#f6b01bfdb454d86b339e5bb8e6a0b842" title="Send a system message to the process.">KGameProcessIO::sendSystemMessage</a>(QDataStream &stream,<span class="keywordtype">int</span> msgid, Q_UINT32 receiver, Q_UINT32 sender) <a name="l00342"></a>00342 { <a name="l00343"></a>00343 <a class="code" href="classKGameProcessIO.html#4e0f8c82d5edc19b9059f6807060e30a" title="Internal ~ombined function for all message handling.">sendAllMessages</a>(stream, msgid, receiver, sender, <span class="keyword">false</span>); <a name="l00344"></a>00344 } <a name="l00345"></a>00345 <a name="l00346"></a><a class="code" href="classKGameProcessIO.html#e9f9c2c52d681f863da35ca3e621f362">00346</a> <span class="keywordtype">void</span> <a class="code" href="classKGameProcessIO.html#e9f9c2c52d681f863da35ca3e621f362" title="Send a message to the process.">KGameProcessIO::sendMessage</a>(QDataStream &stream,<span class="keywordtype">int</span> msgid, Q_UINT32 receiver, Q_UINT32 sender) <a name="l00347"></a>00347 { <a name="l00348"></a>00348 <a class="code" href="classKGameProcessIO.html#4e0f8c82d5edc19b9059f6807060e30a" title="Internal ~ombined function for all message handling.">sendAllMessages</a>(stream, msgid, receiver, sender, <span class="keyword">true</span>); <a name="l00349"></a>00349 } <a name="l00350"></a>00350 <a name="l00351"></a><a class="code" href="classKGameProcessIO.html#4e0f8c82d5edc19b9059f6807060e30a">00351</a> <span class="keywordtype">void</span> <a class="code" href="classKGameProcessIO.html#4e0f8c82d5edc19b9059f6807060e30a" title="Internal ~ombined function for all message handling.">KGameProcessIO::sendAllMessages</a>(QDataStream &stream,<span class="keywordtype">int</span> msgid, Q_UINT32 receiver, Q_UINT32 sender, <span class="keywordtype">bool</span> usermsg) <a name="l00352"></a>00352 { <a name="l00353"></a>00353 kdDebug(11001) << <span class="stringliteral">"==============> KGameProcessIO::sendMessage (usermsg="</span><<usermsg<<<span class="stringliteral">")"</span> << endl; <a name="l00354"></a>00354 <span class="comment">// if (!player()) return ;</span> <a name="l00355"></a>00355 <span class="comment">//if (!player()->isActive()) return ;</span> <a name="l00356"></a>00356 <a name="l00357"></a>00357 <span class="keywordflow">if</span> (usermsg) <a name="l00358"></a>00358 { <a name="l00359"></a>00359 msgid+=KGameMessage::IdUser; <a name="l00360"></a>00360 } <a name="l00361"></a>00361 <a name="l00362"></a>00362 kdDebug(11001) << <span class="stringliteral">"=============* ProcessIO ("</span> << msgid << <span class="stringliteral">","</span> << receiver << <span class="stringliteral">","</span> << sender << <span class="stringliteral">") ==========="</span> << endl; <a name="l00363"></a>00363 <a name="l00364"></a>00364 QByteArray buffer; <a name="l00365"></a>00365 QDataStream ostream(buffer,IO_WriteOnly); <a name="l00366"></a>00366 QBuffer *device=(QBuffer *)stream.device(); <a name="l00367"></a>00367 QByteArray data=device->buffer();; <a name="l00368"></a>00368 <a name="l00369"></a>00369 KGameMessage::createHeader(ostream,sender,receiver,msgid); <a name="l00370"></a>00370 <span class="comment">// ostream.writeRawBytes(data.data()+device->at(),data.size()-device->at());</span> <a name="l00371"></a>00371 ostream.writeRawBytes(data.data(),data.size()); <a name="l00372"></a>00372 kdDebug(11001) << <span class="stringliteral">" Adding user data from pos="</span><< device->at() <<<span class="stringliteral">" amount= "</span> << data.size() << <span class="stringliteral">" byte "</span> << endl; <a name="l00373"></a>00373 <span class="comment">//if (d->mMessageClient) d->mMessageClient->sendBroadcast(buffer);</span> <a name="l00374"></a>00374 <span class="keywordflow">if</span> (d->mProcessIO) <a name="l00375"></a>00375 { <a name="l00376"></a>00376 d->mProcessIO->send(buffer); <a name="l00377"></a>00377 } <a name="l00378"></a>00378 } <a name="l00379"></a>00379 <a name="l00380"></a>00380 <span class="comment">//void KGameProcessIO::clientMessage(const QByteArray& receiveBuffer, Q_UINT32 clientID, const QValueList <Q_UINT32> &recv)</span> <a name="l00381"></a><a class="code" href="classKGameProcessIO.html#254ca9286bda893f00fbc2122938611a">00381</a> <span class="keywordtype">void</span> <a class="code" href="classKGameProcessIO.html#254ca9286bda893f00fbc2122938611a" title="Internal message handler to receive data from the process.">KGameProcessIO::receivedMessage</a>(<span class="keyword">const</span> QByteArray& receiveBuffer) <a name="l00382"></a>00382 { <a name="l00383"></a>00383 QDataStream stream(receiveBuffer,IO_ReadOnly); <a name="l00384"></a>00384 <span class="keywordtype">int</span> msgid; <a name="l00385"></a>00385 Q_UINT32 sender; <a name="l00386"></a>00386 Q_UINT32 receiver; <a name="l00387"></a>00387 KGameMessage::extractHeader(stream,sender,receiver,msgid); <a name="l00388"></a>00388 <a name="l00389"></a>00389 kdDebug(11001) << <span class="stringliteral">"************* Got process message sender ="</span> << sender <a name="l00390"></a>00390 << <span class="stringliteral">" receiver="</span> << receiver << <span class="stringliteral">" msgid="</span> << msgid << endl; <a name="l00391"></a>00391 <a name="l00392"></a>00392 <a name="l00393"></a>00393 <span class="comment">// Cut out the header part...to not confuse network code</span> <a name="l00394"></a>00394 QBuffer *buf=(QBuffer *)stream.device(); <a name="l00395"></a>00395 QByteArray newbuffer; <a name="l00396"></a>00396 newbuffer.setRawData(buf->buffer().data()+buf->at(),buf->size()-buf->at()); <a name="l00397"></a>00397 QDataStream ostream(newbuffer,IO_ReadOnly); <a name="l00398"></a>00398 kdDebug(11001) << <span class="stringliteral">"Newbuffer size="</span> << newbuffer.size() << endl; <a name="l00399"></a>00399 <a name="l00400"></a>00400 <a name="l00401"></a>00401 <a name="l00402"></a>00402 <span class="comment">// This is a dummy message which allows us the process to talk with its owner</span> <a name="l00403"></a>00403 <span class="keywordflow">if</span> (msgid==KGameMessage::IdProcessQuery) <a name="l00404"></a>00404 { <a name="l00405"></a>00405 emit <a class="code" href="classKGameProcessIO.html#5a1ec90348d26b912961aa36317fb98c" title="A computer query message is received.">signalProcessQuery</a>(ostream,<span class="keyword">this</span>); <a name="l00406"></a>00406 } <a name="l00407"></a>00407 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()) <a name="l00408"></a>00408 { <a name="l00409"></a>00409 sender = <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()-><a class="code" href="classKPlayer.html#a1151863225396c0f96678bf3ca938ae" title="Returns the id of the player.">id</a>(); <span class="comment">// force correct sender</span> <a name="l00410"></a>00410 <span class="keywordflow">if</span> (msgid==KGameMessage::IdPlayerInput) <a name="l00411"></a>00411 { <a name="l00412"></a>00412 <a class="code" href="classKGameIO.html#2ebd7ca9f71a45a0bdfe05d6e84e7117" title="Send an input message using KPlayer::forwardInput.">sendInput</a>(ostream,<span class="keyword">true</span>,sender); <a name="l00413"></a>00413 } <a name="l00414"></a>00414 <span class="keywordflow">else</span> <a name="l00415"></a>00415 { <a name="l00416"></a>00416 <a class="code" href="classKGameIO.html#f0c625cabd48ddaa5306f909f80d983d" title="This function returns the player who owns this IO.">player</a>()-><a class="code" href="classKPlayer.html#c1c3f9a4267e6c9c9b15c3cf73a154dc" title="Forwards Message to the game object.">forwardMessage</a>(ostream,msgid,receiver,sender); <a name="l00417"></a>00417 } <a name="l00418"></a>00418 } <a name="l00419"></a>00419 <span class="keywordflow">else</span> <a name="l00420"></a>00420 { <a name="l00421"></a>00421 kdDebug(11001) << k_funcinfo << <span class="stringliteral">": Got message from process but no player defined!"</span> << endl; <a name="l00422"></a>00422 } <a name="l00423"></a>00423 newbuffer.resetRawData(buf->buffer().data()+buf->at(),buf->size()-buf->at()); <a name="l00424"></a>00424 } <a name="l00425"></a>00425 <a name="l00426"></a>00426 <a name="l00427"></a>00427 <span class="comment">// ----------------------- Computer IO --------------------------</span> <a name="l00428"></a>00428 <span class="keyword">class </span>KGameComputerIO::KGameComputerIOPrivate <a name="l00429"></a>00429 { <a name="l00430"></a>00430 <span class="comment">//TODO: maybe these should be KGameProperties!!</span> <a name="l00431"></a>00431 <span class="keyword">public</span>: <a name="l00432"></a>00432 KGameComputerIOPrivate() <a name="l00433"></a>00433 { <a name="l00434"></a>00434 mAdvanceCounter = 0; <a name="l00435"></a>00435 mReactionPeriod = 0; <a name="l00436"></a>00436 <a name="l00437"></a>00437 mPauseCounter = 0; <a name="l00438"></a>00438 <a name="l00439"></a>00439 mAdvanceTimer = 0; <a name="l00440"></a>00440 } <a name="l00441"></a>00441 <span class="keywordtype">int</span> mAdvanceCounter; <a name="l00442"></a>00442 <span class="keywordtype">int</span> mReactionPeriod; <a name="l00443"></a>00443 <a name="l00444"></a>00444 <span class="keywordtype">int</span> mPauseCounter; <a name="l00445"></a>00445 <a name="l00446"></a>00446 QTimer* mAdvanceTimer; <a name="l00447"></a>00447 }; <a name="l00448"></a>00448 <a name="l00449"></a><a class="code" href="classKGameComputerIO.html#a4f513b2e984d6510956c1ed34a446e3">00449</a> <a class="code" href="classKGameComputerIO.html#a4f513b2e984d6510956c1ed34a446e3" title="Creates a LOCAL computer player.">KGameComputerIO::KGameComputerIO</a>() : <a class="code" href="classKGameIO.html" title="Base class for IO devices for games.">KGameIO</a>() <a name="l00450"></a>00450 { <a name="l00451"></a>00451 init(); <a name="l00452"></a>00452 } <a name="l00453"></a>00453 <a name="l00454"></a>00454 <a class="code" href="classKGameComputerIO.html#a4f513b2e984d6510956c1ed34a446e3" title="Creates a LOCAL computer player.">KGameComputerIO::KGameComputerIO</a>(<a class="code" href="classKPlayer.html" title="Base class for a game player.">KPlayer</a>* p) : <a class="code" href="classKGameIO.html" title="Base class for IO devices for games.">KGameIO</a>(p) <a name="l00455"></a>00455 { <a name="l00456"></a>00456 init(); <a name="l00457"></a>00457 } <a name="l00458"></a>00458 <a name="l00459"></a>00459 <span class="keywordtype">void</span> KGameComputerIO::init() <a name="l00460"></a>00460 { <a name="l00461"></a>00461 d = <span class="keyword">new</span> KGameComputerIOPrivate; <a name="l00462"></a>00462 } <a name="l00463"></a>00463 <a name="l00464"></a>00464 KGameComputerIO::~KGameComputerIO() <a name="l00465"></a>00465 { <a name="l00466"></a>00466 <span class="keywordflow">if</span> (d->mAdvanceTimer) <a name="l00467"></a>00467 { <a name="l00468"></a>00468 <span class="keyword">delete</span> d->mAdvanceTimer; <a name="l00469"></a>00469 } <a name="l00470"></a>00470 <span class="keyword">delete</span> d; <a name="l00471"></a>00471 } <a name="l00472"></a>00472 <a name="l00473"></a><a class="code" href="classKGameComputerIO.html#e1de92f6e3f9115a44ca862fdde2a5cb">00473</a> <span class="keywordtype">int</span> <a class="code" href="classKGameComputerIO.html#e1de92f6e3f9115a44ca862fdde2a5cb" title="Run time idendification.">KGameComputerIO::rtti</a>()<span class="keyword"> const</span> <a name="l00474"></a>00474 <span class="keyword"></span>{ <a name="l00475"></a>00475 <span class="keywordflow">return</span> ComputerIO; <a name="l00476"></a>00476 } <a name="l00477"></a>00477 <a name="l00478"></a><a class="code" href="classKGameComputerIO.html#c2e156eb72e37a45a09de5049b4eae4d">00478</a> <span class="keywordtype">void</span> <a class="code" href="classKGameComputerIO.html#c2e156eb72e37a45a09de5049b4eae4d" title="The number of advance calls until the player (or rather: the IO) does something (default:...">KGameComputerIO::setReactionPeriod</a>(<span class="keywordtype">int</span> calls) <a name="l00479"></a>00479 { <a name="l00480"></a>00480 d->mReactionPeriod = calls; <a name="l00481"></a>00481 } <a name="l00482"></a>00482 <a name="l00483"></a>00483 <span class="keywordtype">int</span> KGameComputerIO::reactionPeriod()<span class="keyword"> const</span> <a name="l00484"></a>00484 <span class="keyword"></span>{ <a name="l00485"></a>00485 <span class="keywordflow">return</span> d->mReactionPeriod; <a name="l00486"></a>00486 } <a name="l00487"></a>00487 <a name="l00488"></a><a class="code" href="classKGameComputerIO.html#6ee28c75c1cfacf0f78fa6c964ea8cd8">00488</a> <span class="keywordtype">void</span> <a class="code" href="classKGameComputerIO.html#6ee28c75c1cfacf0f78fa6c964ea8cd8" title="Start a QTimer which calls advance every ms milli seconds.">KGameComputerIO::setAdvancePeriod</a>(<span class="keywordtype">int</span> ms) <a name="l00489"></a>00489 { <a name="l00490"></a>00490 stopAdvancePeriod(); <a name="l00491"></a>00491 d->mAdvanceTimer = <span class="keyword">new</span> QTimer(<span class="keyword">this</span>); <a name="l00492"></a>00492 connect(d->mAdvanceTimer, SIGNAL(timeout()), <span class="keyword">this</span>, SLOT(<a class="code" href="classKGameComputerIO.html#6f9f6c9f152398096eff63b7470a995e" title="Works kind of similar to QCanvas::advance.">advance</a>())); <a name="l00493"></a>00493 d->mAdvanceTimer->start(ms); <a name="l00494"></a>00494 } <a name="l00495"></a>00495 <a name="l00496"></a>00496 <span class="keywordtype">void</span> KGameComputerIO::stopAdvancePeriod() <a name="l00497"></a>00497 { <a name="l00498"></a>00498 <span class="keywordflow">if</span> (d->mAdvanceTimer) <a name="l00499"></a>00499 { <a name="l00500"></a>00500 d->mAdvanceTimer->stop(); <a name="l00501"></a>00501 <span class="keyword">delete</span> d->mAdvanceTimer; <a name="l00502"></a>00502 } <a name="l00503"></a>00503 } <a name="l00504"></a>00504 <a name="l00505"></a><a class="code" href="classKGameComputerIO.html#a0ad885b286f4dc1ae42cce32b86b751">00505</a> <span class="keywordtype">void</span> <a class="code" href="classKGameComputerIO.html#a0ad885b286f4dc1ae42cce32b86b751" title="Ignore calls number of advance calls.">KGameComputerIO::pause</a>(<span class="keywordtype">int</span> calls) <a name="l00506"></a>00506 { <a name="l00507"></a>00507 d->mPauseCounter = calls; <a name="l00508"></a>00508 } <a name="l00509"></a>00509 <a name="l00510"></a><a class="code" href="classKGameComputerIO.html#a02af05693334b1a97a2749ab4b4d15c">00510</a> <span class="keywordtype">void</span> <a class="code" href="classKGameComputerIO.html#a02af05693334b1a97a2749ab4b4d15c" title="Equivalent to pause(0).">KGameComputerIO::unpause</a>() <a name="l00511"></a>00511 { <a name="l00512"></a>00512 <a class="code" href="classKGameComputerIO.html#a0ad885b286f4dc1ae42cce32b86b751" title="Ignore calls number of advance calls.">pause</a>(0); <a name="l00513"></a>00513 } <a name="l00514"></a>00514 <a name="l00515"></a><a class="code" href="classKGameComputerIO.html#6f9f6c9f152398096eff63b7470a995e">00515</a> <span class="keywordtype">void</span> <a class="code" href="classKGameComputerIO.html#6f9f6c9f152398096eff63b7470a995e" title="Works kind of similar to QCanvas::advance.">KGameComputerIO::advance</a>() <a name="l00516"></a>00516 { <a name="l00517"></a>00517 <span class="keywordflow">if</span> (d->mPauseCounter > 0) <a name="l00518"></a>00518 { <a name="l00519"></a>00519 d->mPauseCounter--; <a name="l00520"></a>00520 <span class="keywordflow">return</span>; <a name="l00521"></a>00521 } <a name="l00522"></a>00522 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (d->mPauseCounter < 0) <a name="l00523"></a>00523 { <a name="l00524"></a>00524 <span class="keywordflow">return</span>; <a name="l00525"></a>00525 } <a name="l00526"></a>00526 d->mAdvanceCounter++; <a name="l00527"></a>00527 <span class="keywordflow">if</span> (d->mAdvanceCounter >= d->mReactionPeriod) <a name="l00528"></a>00528 { <a name="l00529"></a>00529 d->mAdvanceCounter = 0; <a name="l00530"></a>00530 <a class="code" href="classKGameComputerIO.html#fbb43270dbfb2ca020a44a3abe3415eb" title="Default implementation simply emits signalReaction.">reaction</a>(); <a name="l00531"></a>00531 } <a name="l00532"></a>00532 } <a name="l00533"></a>00533 <a name="l00534"></a><a class="code" href="classKGameComputerIO.html#fbb43270dbfb2ca020a44a3abe3415eb">00534</a> <span class="keywordtype">void</span> <a class="code" href="classKGameComputerIO.html#fbb43270dbfb2ca020a44a3abe3415eb" title="Default implementation simply emits signalReaction.">KGameComputerIO::reaction</a>() <a name="l00535"></a>00535 { <a name="l00536"></a>00536 emit <a class="code" href="classKGameComputerIO.html#2a662322dad2682080b628a759774524" title="This signal is emitted when your computer player is meant to do something, or better...">signalReaction</a>(); <a name="l00537"></a>00537 } <a name="l00538"></a>00538 <a name="l00539"></a>00539 </pre></div></div> </div></div> </td> </tr> <tr> <td valign="top" id="leftmenu" width="25%"> <a name="navigation"></a> <div class="menu_box"><h2>libkdegames</h2> <div class="nav_list"> <ul><li><a href="index.html">Main Page</a></li><li><a href="hierarchy.html">Class Hierarchy</a></li><li><a href="classes.html">Alphabetical List</a></li><li><a href="annotated.html">Class List</a></li><li><a href="files.html">File List</a></li><li><a href="functions.html">Class Members</a></li><li><a href="pages.html">Related Pages</a></li></ul> <!-- <h2>Class Picker</h2> <div style="text-align: center;"> <form name="guideform"> <select name="guidelinks" style="width:100%;" onChange="window.location=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value"> <option value="annotated.html">-- Choose --</option> <option value="classKCanvasRootPixmap.html">kcanvasrootpixmap</option>, <option value="classKCardDialog.html">kcarddialog</option>, <option value="classKChat.html">kchat</option>, <option value="classKChatBase.html">kchatbase</option>, <option value="classKChatBaseText.html">kchatbasetext</option>, <option value="classKExtHighscore_1_1Item.html">kexthighscore::item</option>, <option value="classKExtHighscore_1_1ItemArray.html">kexthighscore::itemarray</option>, <option value="classKExtHighscore_1_1Manager.html">kexthighscore::manager</option>, <option value="classKExtHighscore_1_1MultiplayerScores.html">kexthighscore::multiplayerscores</option>, <option value="classKExtHighscore_1_1Score.html">kexthighscore::score</option>, <option value="classKGame.html">kgame</option>, <option value="classKGameChat.html">kgamechat</option>, <option value="classKGameComputerIO.html">kgamecomputerio</option>, <option value="classKGameConnectDialog.html">kgameconnectdialog</option>, <option value="classKGameDialog.html">kgamedialog</option>, <option value="classKGameDialogChatConfig.html">kgamedialogchatconfig</option>, <option value="classKGameDialogConfig.html">kgamedialogconfig</option>, <option value="classKGameErrorDialog.html">kgameerrordialog</option>, <option value="classKGameErrorMessageDialog.html">kgameerrormessagedialog</option>, <option value="classKGameIO.html">kgameio</option>, <option value="classKGameKeyIO.html">kgamekeyio</option>, <option value="classKGameLCD.html">kgamelcd</option>, <option value="classKGameLCDClock.html">kgamelcdclock</option>, <option value="classKGameLCDList.html">kgamelcdlist</option>, <option value="classKGameMisc.html">kgamemisc</option>, <option value="classKGameMouseIO.html">kgamemouseio</option>, <option value="classKGameNetwork.html">kgamenetwork</option>, <option value="classKGameProcess.html">kgameprocess</option>, <option value="classKGameProcessIO.html">kgameprocessio</option>, <option value="classKGameProgress.html">kgameprogress</option>, <option value="classKGameProperty.html">kgameproperty</option>, <option value="classKGamePropertyBase.html">kgamepropertybase</option>, <option value="classKGamePropertyHandler.html">kgamepropertyhandler</option>, <option value="classKGameSequence.html">kgamesequence</option>, <option value="classKGrid2D_1_1Generic.html">kgrid2d::generic</option>, <option value="classKGrid2D_1_1Hexagonal.html">kgrid2d::hexagonal</option>, <option value="classKGrid2D_1_1HexagonalBase.html">kgrid2d::hexagonalbase</option>, <option value="classKGrid2D_1_1Square.html">kgrid2d::square</option>, <option value="classKGrid2D_1_1SquareBase.html">kgrid2d::squarebase</option>, <option value="classKHighscore.html">khighscore</option>, <option value="classKMessageClient.html">kmessageclient</option>, <option value="classKMessageDirect.html">kmessagedirect</option>, <option value="classKMessageIO.html">kmessageio</option>, <option value="classKMessageServer.html">kmessageserver</option>, <option value="classKMessageServerSocket.html">kmessageserversocket</option>, <option value="classKMessageSocket.html">kmessagesocket</option>, <option value="classKPlayer.html">kplayer</option>, <option value="classKScoreDialog.html">kscoredialog</option>, <option value="classKStdGameAction.html">kstdgameaction</option>, </select> </form> </div> --> </div></div> <div class="menu_box"><h2>API Dox</h2> <div class="nav_list"> <ul> <li><a href="../../libkdegames/html/index.html">libkdegames</a></li> </ul></div></div> </td> </tr> </table> <span class="doNotDisplay"> <a href="http://www.kde.org/" accesskey="8">KDE Home</a> | <a href="http://accessibility.kde.org/" accesskey="9">KDE Accessibility Home</a> | <a href="http://www.kde.org/media/accesskeys.php" accesskey="0">Description of Access Keys</a> </span> <div style="height: 8px"></div> <div id="footer"> <div id="footer_left"> Maintained by <a href="mailto:groot@kde.org">Adriaan de Groot</a> and <a href="mailto:winter@kde.org">Allen Winter</a>. <br/> KDE and K Desktop Environment are trademarks of <a href="http://www.kde.org/areas/kde-ev/" title="Homepage of the KDE non-profit Organization">KDE e.V.</a> | <a href="http://www.kde.org/contact/impressum.php">Legal</a> </div> <div id="footer_right"><img src="/media/images/footer_right.png" style="margin: 0px" alt="" /></div> </div> <!-- WARNING: DO NOT SEND MAIL TO THE FOLLOWING EMAIL ADDRESS! YOU WILL BE BLOCKED INSTANTLY AND PERMANENTLY! <a href="mailto:aaaatrap-425acc3b5374943f@kde.org">Block me</a> WARNING END --> </body> </html>