#include <kgameio.h>
Inheritance diagram for KGameIO:


Public Types | |
| enum | IOMode { GenericIO = 1, KeyIO = 2, MouseIO = 4, ProcessIO = 8, ComputerIO = 16 } |
| Identifies the KGameIO via the rtti function. More... | |
Signals | |
| void | signalPrepareTurn (QDataStream &stream, bool turn, KGameIO *io, bool *send) |
| Signal generated when KPlayer::myTurn changes. | |
Public Member Functions | |
| KGameIO () | |
| Constructs a KGameIO object. | |
| KGameIO (KPlayer *) | |
| virtual | ~KGameIO () |
| void | Debug () |
| Gives debug output of the game status. | |
| virtual int | rtti () const =0 |
| Run time idendification. | |
| KPlayer * | player () const |
| This function returns the player who owns this IO. | |
| KGame * | game () const |
| Equivalent to player()->game(). | |
| void | setPlayer (KPlayer *p) |
| Sets the player to which this IO belongs to. | |
| virtual void | initIO (KPlayer *p) |
| Init this device by setting the player and e.g. | |
| virtual void | notifyTurn (bool b) |
| Notifies the IO device that the player's setTurn had been called Called by KPlayer. | |
| bool | sendInput (QDataStream &stream, bool transmit=true, Q_UINT32 sender=0) |
| Send an input message using KPlayer::forwardInput. | |
This is the master class for creating IO game devices. You cannot use it directly. Either take one of the classes derived from it or you have to create your own IO class derived from it (more probably).
The idea behind this class is to provide a common interface for input devices into your game. By programming a KGameIO device you need not distinguish the actual IO in the game anymore. All work is done by the IO's. This allows very easy reuse in other games as well. A further advantage of using the IO's is that you can exchange the control of a player at runtime. E.g. you switch a player to be controlled by the computer or vice versa.
To achieve this you have to make all of your player inputs through a KGameIO. You will usually call KGameIO::sendInput to do so.
Definition at line 55 of file kgameio.h.
|
|
Identifies the KGameIO via the rtti function.
|
|
|
Constructs a KGameIO object.
Definition at line 40 of file kgameio.cpp. |
|
|
Definition at line 46 of file kgameio.cpp. References KPlayer::addGameIO(), and player(). Here is the call graph for this function: ![]() |
|
|
Definition at line 56 of file kgameio.cpp. References player(), and KPlayer::removeGameIO(). Here is the call graph for this function: ![]() |
|
|
Gives debug output of the game status.
Definition at line 109 of file kgameio.cpp. References player(), and rtti(). Here is the call graph for this function: ![]() |
|
|
Equivalent to player()->game().
Definition at line 91 of file kgameio.cpp. References KPlayer::game(), and player(). Here is the call graph for this function: ![]() |
|
|
Init this device by setting the player and e.g. sending an init message to the device. This initialisation message is very useful for computer players as you can transmit the game status to them and only update this status in the setTurn commands. Called by KPlayer::addGameIO only! Reimplemented in KGameProcessIO. Definition at line 66 of file kgameio.cpp. References setPlayer(). Referenced by KPlayer::addGameIO(), and KGameProcessIO::initIO(). Here is the call graph for this function: ![]() |
|
|
Notifies the IO device that the player's setTurn had been called Called by KPlayer. This emits signalPrepareTurn and sends the turn if the send parameter is set to true.
Reimplemented in KGameProcessIO. Definition at line 71 of file kgameio.cpp. References KPlayer::id(), player(), sendInput(), and signalPrepareTurn(). Here is the call graph for this function: ![]() |
|
|
This function returns the player who owns this IO.
Definition at line 89 of file kgameio.h. Referenced by Debug(), KGameMouseIO::eventFilter(), KGameKeyIO::eventFilter(), game(), KGameIO(), KGameProcessIO::notifyTurn(), notifyTurn(), KGameProcessIO::receivedMessage(), sendInput(), ~KGameIO(), and KGameProcessIO::~KGameProcessIO(). |
|
|
Run time idendification. Predefined values are from IOMode You MUST overwrite this in derived classes!
Implemented in KGameKeyIO, KGameMouseIO, KGameProcessIO, and KGameComputerIO. Referenced by Debug(). |
|
||||||||||||||||
|
Send an input message using KPlayer::forwardInput.
Definition at line 100 of file kgameio.cpp. References KPlayer::forwardInput(), and player(). Referenced by KGameMouseIO::eventFilter(), KGameKeyIO::eventFilter(), notifyTurn(), and KGameProcessIO::receivedMessage(). Here is the call graph for this function: ![]() |
|
|
Sets the player to which this IO belongs to. This is done automatically when adding a device to a player
Definition at line 104 of file kgameio.h. Referenced by initIO(), and KPlayer::removeGameIO(). |
|
||||||||||||||||||||
|
Signal generated when KPlayer::myTurn changes. This can either be when you get the turn status or when you lose it. The datastream has to be filled with a move. If you set (or leave) the send parameter to FALSE then nothing happens: the datastream will be ignored. If you set it to TRUE sendInput is used to send the move. Often you want to ignore this signal (leave send=FALSE) and send the message later. This is usually the case for a human player as he probably doesn't react immediately. But you can still use this e.g. to notify the player about the turn change. Example: void GameWindow::slotPrepareTurn(QDataStream &stream,bool b,KGameIO *input,bool * ) { KPlayer *player=input->player(); if (!player->myTurn()) return ; if (!b) return ; // only do something on setTurn(true) stream << 1 << 2 << 3; // Some data for the process }
Referenced by KGameProcessIO::notifyTurn(), and notifyTurn(). |
1.4.6