28#include "kgamemessage.h"
29#include "kmessageio.h"
42 kdDebug(11001) << k_funcinfo <<
": this=" <<
this <<
", sizeof(this)" <<
sizeof(
KGameIO) << endl;
48 kdDebug(11001) << k_funcinfo <<
": this=" <<
this <<
", sizeof(this)" <<
sizeof(
KGameIO) << endl;
58 kdDebug(11001) << k_funcinfo <<
": this=" <<
this << endl;
75 kdWarning(11001) << k_funcinfo <<
": player() is NULL" << endl;
80 TQDataStream stream(buffer, IO_WriteOnly);
84 TQDataStream ostream(buffer,IO_ReadOnly);
86 kdDebug(11001) <<
"Prepare turn sendInput" << endl;
111 kdDebug(11001) <<
"------------------- KGAMEINPUT --------------------" << endl;
112 kdDebug(11001) <<
"this: " <<
this << endl;
113 kdDebug(11001) <<
"rtti : " <<
rtti() << endl;
114 kdDebug(11001) <<
"Player: " <<
player() << endl;
115 kdDebug(11001) <<
"---------------------------------------------------" << endl;
125 kdDebug(11001) <<
"Key Event filter installed" << endl;
126 parent->installEventFilter(
this);
130KGameKeyIO::~KGameKeyIO()
134 parent()->removeEventFilter(
this);
148 if ( e->type() == TQEvent::KeyPress ||
149 e->type() == TQEvent::KeyRelease )
151 TQKeyEvent *k = (TQKeyEvent*)e;
154 TQDataStream stream(buffer,IO_WriteOnly);
157 TQDataStream msg(buffer,IO_ReadOnly);
165 return TQObject::eventFilter( o, e );
175 kdDebug(11001) <<
"Mouse Event filter installed tracking=" << trackmouse << endl;
176 parent->installEventFilter(
this);
177 parent->setMouseTracking(trackmouse);
181KGameMouseIO::~KGameMouseIO()
185 parent()->removeEventFilter(
this);
211 if ( e->type() == TQEvent::MouseButtonPress ||
212 e->type() == TQEvent::MouseButtonRelease ||
213 e->type() == TQEvent::MouseButtonDblClick ||
214 e->type() == TQEvent::Wheel ||
215 e->type() == TQEvent::MouseMove
218 TQMouseEvent *k = (TQMouseEvent*)e;
221 TQDataStream stream(buffer,IO_WriteOnly);
225 TQDataStream msg(buffer,IO_ReadOnly);
232 return TQObject::eventFilter( o, e );
237class KGameProcessIO::KGameProcessIOPrivate
240 KGameProcessIOPrivate()
248 KMessageProcess *mProcessIO;
255 kdDebug(11001) << k_funcinfo <<
": this=" <<
this <<
", sizeof(this)=" <<
sizeof(
KGameProcessIO) << endl;
256 d =
new KGameProcessIOPrivate;
262 kdDebug(11001) <<
"================= KMEssageProcessIO ==================== " << endl;
263 d->mProcessIO=
new KMessageProcess(
this,name);
264 kdDebug(11001) <<
"================= KMEssage Add client ==================== " << endl;
268 kdDebug(11001) <<
"================= KMEssage: Connect ==================== " << endl;
273 connect(d->mProcessIO, TQ_SIGNAL(received(
const TQByteArray&)),
280 kdDebug(11001) << k_funcinfo <<
": this=" <<
this << endl;
281 kdDebug(11001) <<
"player="<<
player() << endl;
288 delete d->mProcessIO;
304 TQDataStream stream(buffer, IO_WriteOnly);
305 TQ_INT16
id = p->
userId();
314 TQ_UINT32 sender = p->
id();
315 kdDebug(11001) <<
"Sending IOAdded to process player !!!!!!!!!!!!!! " << endl;
325 kdWarning(11001) << k_funcinfo <<
": player() is NULL" << endl;
330 TQDataStream stream(buffer,IO_WriteOnly);
331 stream << (TQ_INT8)b;
336 kdDebug(11001) <<
"Sending Turn to process player !!!!!!!!!!!!!! " << endl;
353 kdDebug(11001) <<
"==============> KGameProcessIO::sendMessage (usermsg="<<usermsg<<
")" << endl;
359 msgid+=KGameMessage::IdUser;
362 kdDebug(11001) <<
"=============* ProcessIO (" << msgid <<
"," << receiver <<
"," << sender <<
") ===========" << endl;
365 TQDataStream ostream(buffer,IO_WriteOnly);
366 TQBuffer *device=(TQBuffer *)stream.device();
367 TQByteArray data=device->buffer();;
369 KGameMessage::createHeader(ostream,sender,receiver,msgid);
371 ostream.writeRawBytes(data.data(),data.size());
372 kdDebug(11001) <<
" Adding user data from pos="<< device->at() <<
" amount= " << data.size() <<
" byte " << endl;
376 d->mProcessIO->send(buffer);
383 TQDataStream stream(receiveBuffer,IO_ReadOnly);
387 KGameMessage::extractHeader(stream,sender,receiver,msgid);
389 kdDebug(11001) <<
"************* Got process message sender =" << sender
390 <<
" receiver=" << receiver <<
" msgid=" << msgid << endl;
394 TQBuffer *buf=(TQBuffer *)stream.device();
395 TQByteArray newbuffer;
396 newbuffer.setRawData(buf->buffer().data()+buf->at(),buf->size()-buf->at());
397 TQDataStream ostream(newbuffer,IO_ReadOnly);
398 kdDebug(11001) <<
"Newbuffer size=" << newbuffer.size() << endl;
403 if (msgid==KGameMessage::IdProcessQuery)
410 if (msgid==KGameMessage::IdPlayerInput)
421 kdDebug(11001) << k_funcinfo <<
": Got message from process but no player defined!" << endl;
423 newbuffer.resetRawData(buf->buffer().data()+buf->at(),buf->size()-buf->at());
428class KGameComputerIO::KGameComputerIOPrivate
432 KGameComputerIOPrivate()
446 TQTimer* mAdvanceTimer;
459void KGameComputerIO::init()
461 d =
new KGameComputerIOPrivate;
464KGameComputerIO::~KGameComputerIO()
466 if (d->mAdvanceTimer)
468 delete d->mAdvanceTimer;
480 d->mReactionPeriod = calls;
483int KGameComputerIO::reactionPeriod()
const
485 return d->mReactionPeriod;
491 d->mAdvanceTimer =
new TQTimer(
this);
492 connect(d->mAdvanceTimer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(
advance()));
493 d->mAdvanceTimer->start(ms);
496void KGameComputerIO::stopAdvancePeriod()
498 if (d->mAdvanceTimer)
500 d->mAdvanceTimer->stop();
501 delete d->mAdvanceTimer;
507 d->mPauseCounter = calls;
517 if (d->mPauseCounter > 0)
522 else if (d->mPauseCounter < 0)
526 d->mAdvanceCounter++;
527 if (d->mAdvanceCounter >= d->mReactionPeriod)
529 d->mAdvanceCounter = 0;
void signalReaction()
This signal is emitted when your computer player is meant to do something, or better is meant to be a...
void setAdvancePeriod(int ms)
Start a TQTimer which calls advance every ms milli seconds.
virtual void advance()
Works kind of similar to TQCanvas::advance.
int rtti() const
Run time idendification.
void unpause()
Equivalent to pause(0).
void pause(int calls=-1)
Ignore calls number of advance calls.
KGameComputerIO()
Creates a LOCAL computer player.
void setReactionPeriod(int advanceCalls)
The number of advance calls until the player (or rather: the IO) does something (default: 1).
virtual void reaction()
Default implementation simply emits signalReaction.
Base class for IO devices for games.
KGameIO()
Constructs a KGameIO object.
KPlayer * player() const
This function returns the player who owns this IO.
bool sendInput(TQDataStream &stream, bool transmit=true, TQ_UINT32 sender=0)
Send an input message using KPlayer::forwardInput.
virtual void notifyTurn(bool b)
Notifies the IO device that the player's setTurn had been called Called by KPlayer.
void setPlayer(KPlayer *p)
Sets the player to which this IO belongs to.
void signalPrepareTurn(TQDataStream &stream, bool turn, KGameIO *io, bool *send)
Signal generated when KPlayer::myTurn changes.
void Debug()
Gives debug output of the game status.
virtual int rtti() const =0
Run time idendification.
virtual void initIO(KPlayer *p)
Init this device by setting the player and e.g.
KGame * game() const
Equivalent to player()->game()
virtual int rtti() const
The idendification of the IO.
KGameKeyIO(TQWidget *parent)
Create a keyboard input devices.
void signalKeyEvent(KGameIO *io, TQDataStream &stream, TQKeyEvent *m, bool *eatevent)
Signal handler for keyboard events.
bool eventFilter(TQObject *o, TQEvent *e)
Internal method to process the events.
void setMouseTracking(bool b)
Manually activate or deactivate mouse tracking.
bool eventFilter(TQObject *o, TQEvent *e)
Internal event filter.
void signalMouseEvent(KGameIO *io, TQDataStream &stream, TQMouseEvent *m, bool *eatevent)
Signal handler for mouse events.
virtual int rtti() const
The idendification of the IO.
KGameMouseIO(TQWidget *parent, bool trackmouse=false)
Creates a mouse IO device.
The KGameProcessIO class.
virtual ~KGameProcessIO()
Deletes the process input devices.
void signalIOAdded(KGameIO *game, TQDataStream &stream, KPlayer *p, bool *send)
Signal generated when the computer player is added.
int rtti() const
The idendification of the IO.
void initIO(KPlayer *p)
Init this device by setting the player and e.g.
KGameProcessIO(const TQString &name)
Creates a computer player via a separate process.
void receivedMessage(const TQByteArray &receiveBuffer)
Internal message handler to receive data from the process.
void sendSystemMessage(TQDataStream &stream, int msgid, TQ_UINT32 receiver, TQ_UINT32 sender)
Send a system message to the process.
void signalProcessQuery(TQDataStream &stream, KGameProcessIO *me)
A computer query message is received.
virtual void notifyTurn(bool turn)
Notifies the IO device that the player's setTurn had been called Called by KPlayer.
void sendMessage(TQDataStream &stream, int msgid, TQ_UINT32 receiver, TQ_UINT32 sender)
Send a message to the process.
void sendAllMessages(TQDataStream &stream, int msgid, TQ_UINT32 receiver, TQ_UINT32 sender, bool usermsg)
Internal ~ombined function for all message handling.
The main KDE game object.
Base class for a game player.
KGame * game() const
Query to which game the player belongs to.
TQ_UINT32 id() const
Returns the id of the player.
int userId() const
Returns the user defined id of the player This value can be used arbitrary by you to have some user i...
bool addGameIO(KGameIO *input)
Adds an IO device for the player.
bool removeGameIO(KGameIO *input=0, bool deleteit=true)
remove (and delete) a game IO device
virtual bool forwardMessage(TQDataStream &msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
Forwards Message to the game object..internal use only.
virtual bool forwardInput(TQDataStream &msg, bool transmit=true, TQ_UINT32 sender=0)
Forwards input to the game object..internal use only.