• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

libkdegames/libkdegamesprivate/kgame

Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
KGamePropertyBase Class Referenceabstract

#include <KGame/KGameProperty>

Inheritance diagram for KGamePropertyBase:
Inheritance graph
[legend]

Classes

union  Flags
 

Public Types

enum  PropertyCommandIds {
  CmdLock =1, CmdAt =51, CmdResize =52, CmdFill =53,
  CmdSort =54, CmdInsert =61, CmdAppend =62, CmdRemove =63,
  CmdClear =64
}
 
enum  PropertyDataIds {
  IdGroup =1, IdUserId =2, IdAsyncInput =3, IdTurn =4,
  IdName =5, IdGameStatus =6, IdMaxPlayer =7, IdMinPlayer =8,
  IdGrabInput =16, IdReleaseInput =17, IdCommand, IdUser =256,
  IdAutomatic =0x7000
}
 
enum  PropertyPolicy { PolicyUndefined = 0, PolicyClean = 1, PolicyDirty = 2, PolicyLocal = 3 }
 

Public Member Functions

 KGamePropertyBase (int id, KGamePropertyHandler *owner)
 
 KGamePropertyBase (int id, KGame *parent)
 
 KGamePropertyBase (int id, KPlayer *parent)
 
 KGamePropertyBase ()
 
virtual ~KGamePropertyBase ()
 
virtual void command (QDataStream &stream, int msgid, bool isSender=false)
 
int id () const
 
bool isDirty () const
 
bool isEmittingSignal () const
 
bool isLocked () const
 
bool isOptimized () const
 
virtual void load (QDataStream &s)=0
 
bool lock ()
 
PropertyPolicy policy () const
 
int registerData (int id, KGamePropertyHandler *owner, PropertyPolicy p, const QString &name=QString())
 
int registerData (int id, KGamePropertyHandler *owner, const QString &name=QString())
 
int registerData (int id, KGame *owner, const QString &name=QString())
 
int registerData (int id, KPlayer *owner, const QString &name=QString())
 
int registerData (KGamePropertyHandler *owner, PropertyPolicy p=PolicyUndefined, const QString &name=QString())
 
virtual void save (QDataStream &s)=0
 
void setEmittingSignal (bool p)
 
void setOptimized (bool p)
 
void setPolicy (PropertyPolicy p)
 
virtual const type_info * typeinfo ()
 
bool unlock (bool force=false)
 
void unregisterData ()
 

Protected Member Functions

void emitSignal ()
 
bool sendProperty ()
 
bool sendProperty (const QByteArray &b)
 
void setDirty (bool d)
 
void setLock (bool l)
 

Protected Attributes

union KGamePropertyBase::Flags mFlags
 
KGamePropertyHandler * mOwner
 

Detailed Description

Base class of KGameProperty.

The KGamePropertyBase class is the base class of KGameProperty. See KGameProperty for further information.

Author
Andreas Beckermann b_man.nosp@m.n@gm.nosp@m.x.de

Definition at line 45 of file kgameproperty.h.

Member Enumeration Documentation

enum KGamePropertyBase::PropertyCommandIds

Commands for advanced properties (qint8)

Enumerator
CmdLock 
CmdAt 
CmdResize 
CmdFill 
CmdSort 
CmdInsert 
CmdAppend 
CmdRemove 
CmdClear 

Definition at line 74 of file kgameproperty.h.

enum KGamePropertyBase::PropertyDataIds
Enumerator
IdGroup 
IdUserId 
IdAsyncInput 
IdTurn 
IdName 
IdGameStatus 
IdMaxPlayer 
IdMinPlayer 
IdGrabInput 
IdReleaseInput 
IdCommand 
IdUser 
IdAutomatic 

Definition at line 48 of file kgameproperty.h.

enum KGamePropertyBase::PropertyPolicy

The policy of the property.

This can be PolicyClean (setValue uses send), PolicyDirty (setValue uses changeValue) or PolicyLocal (setValue uses setLocal).

A "clean" policy means that the property is always the same on every client. This is achieved by calling send which actually changes the value only when the message from the MessageServer is received.

A "dirty" policy means that as soon as setValue is called the property is changed immediately. And additionally sent over network. This can sometimes lead to bugs as the other clients do not immediately have the same value. For more information see changeValue.

PolicyLocal means that a KGameProperty behaves like ever "normal" variable. Whenever setValue is called (e.g. using "=") the value of the property is changes immediately without sending it over network. You might want to use this if you are sure that all clients set the property at the same time.

Enumerator
PolicyUndefined 
PolicyClean 
PolicyDirty 
PolicyLocal 

Definition at line 112 of file kgameproperty.h.

Constructor & Destructor Documentation

KGamePropertyBase::KGamePropertyBase ( int  id,
KGamePropertyHandler *  owner 
)

Constructs a KGamePropertyBase object and calls registerData.

Parameters
idThe id of this property. MUST be UNIQUE! Used to send and receive changes in the property of the playere automatically via network.
ownerThe owner of the object. Must be a KGamePropertyHandler which manages the changes made to this object, i.e. which will send the new data

Definition at line 41 of file kgameproperty.cpp.

KGamePropertyBase::KGamePropertyBase ( int  id,
KGame *  parent 
)

Definition at line 29 of file kgameproperty.cpp.

KGamePropertyBase::KGamePropertyBase ( int  id,
KPlayer *  parent 
)

Definition at line 35 of file kgameproperty.cpp.

KGamePropertyBase::KGamePropertyBase ( )

Creates a KGamePropertyBase object without an owner.

Remember to call registerData!

Definition at line 47 of file kgameproperty.cpp.

KGamePropertyBase::~KGamePropertyBase ( )
virtual

Definition at line 52 of file kgameproperty.cpp.

Member Function Documentation

void KGamePropertyBase::command ( QDataStream &  stream,
int  msgid,
bool  isSender = false 
)
virtual

send a command to advanced properties like arrays

Parameters
streamThe stream containing the data of the comand
msgidThe ID of the command - see PropertyCommandIds
isSenderwhether this client is also the sender of the command

Definition at line 192 of file kgameproperty.cpp.

void KGamePropertyBase::emitSignal ( )
protected

Causes the parent object to emit a signal on value change.

Definition at line 182 of file kgameproperty.cpp.

int KGamePropertyBase::id ( ) const
inline
Returns
The id of this property

Definition at line 241 of file kgameproperty.h.

bool KGamePropertyBase::isDirty ( ) const
inline
Returns
Whether this property is "dirty". See also setDirty

Definition at line 183 of file kgameproperty.h.

bool KGamePropertyBase::isEmittingSignal ( ) const
inline

See also setEmittingSignal.

Returns
Whether this property emits a signal on value change

Definition at line 166 of file kgameproperty.h.

bool KGamePropertyBase::isLocked ( ) const
inline

A locked property can only be changed by the player who has set the lock.

See also setLocked

Returns
Whether this property is currently locked.

Definition at line 190 of file kgameproperty.h.

bool KGamePropertyBase::isOptimized ( ) const
inline

See also setOptimize.

Returns
Whether the property optimizes access (signals,network traffic)

Definition at line 178 of file kgameproperty.h.

virtual void KGamePropertyBase::load ( QDataStream &  s)
pure virtual

This will read the value of this property from the stream.

You MUST overwrite this method in order to use this class

Parameters
sThe stream to read from

Implemented in KGameProperty< type >, KGameProperty< QString >, KGameProperty< int >, KGameProperty< unsigned int >, and KGameProperty< qint8 >.

bool KGamePropertyBase::lock ( )

A locked property can only be changed by the player who has set the lock.

You can only call this if isLocked is false. A message is sent over network so that the property is locked for all players except you.

Returns
returns false if the property can not be locked, i.e. it is already locked

Definition at line 149 of file kgameproperty.cpp.

PropertyPolicy KGamePropertyBase::policy ( ) const
inline
Returns
The default policy of the property

Definition at line 153 of file kgameproperty.h.

int KGamePropertyBase::registerData ( int  id,
KGamePropertyHandler *  owner,
PropertyPolicy  p,
const QString &  name = QString() 
)

You have to register a KGamePropertyBase before you can use it.

You MUST call this before you can use KGamePropertyBase!

Parameters
idthe id of this KGamePropertyBase object. The id MUST be unique, i.e. you cannot have two properties with the same id for one player, although (currently) nothing prevents you from doing so. But you will get strange results!
ownerThe owner of this data. This will send the data using KPropertyHandler::sendProperty whenever you call send
pIf not 0 you can set the policy of the property here
nameif not 0 you can assign a name to this property

Definition at line 88 of file kgameproperty.cpp.

int KGamePropertyBase::registerData ( int  id,
KGamePropertyHandler *  owner,
const QString &  name = QString() 
)

This is an overloaded member function, provided for convenience.

It differs from the above function only in what argument(s) it accepts.

Definition at line 85 of file kgameproperty.cpp.

int KGamePropertyBase::registerData ( int  id,
KGame *  owner,
const QString &  name = QString() 
)

This is an overloaded member function, provided for convenience.

It differs from the above function only in what argument(s) it accepts.

Definition at line 76 of file kgameproperty.cpp.

int KGamePropertyBase::registerData ( int  id,
KPlayer *  owner,
const QString &  name = QString() 
)

This is an overloaded member function, provided for convenience.

It differs from the above function only in what argument(s) it accepts.

Definition at line 79 of file kgameproperty.cpp.

int KGamePropertyBase::registerData ( KGamePropertyHandler *  owner,
PropertyPolicy  p = PolicyUndefined,
const QString &  name = QString() 
)

This is an overloaded member function, provided for convenience.

It differs from the above function only in what argument(s) it accepts. In particular you can use this function to create properties which will have an automatic id assigned. The new id is returned.

Definition at line 82 of file kgameproperty.cpp.

virtual void KGamePropertyBase::save ( QDataStream &  s)
pure virtual

Write the value into a stream.

MUST be overwritten

Implemented in KGameProperty< type >, KGameProperty< QString >, KGameProperty< int >, KGameProperty< unsigned int >, and KGameProperty< qint8 >.

bool KGamePropertyBase::sendProperty ( )
protected

Forward the data to the owner of this property which then sends it over network.

save is used to store the data into a stream so you have to make sure that function is working properly if you implement your own property!

Note: this sends the current property!

Might be obsolete - KGamePropertyArray still uses it. Is this a bug or correct?

Definition at line 121 of file kgameproperty.cpp.

bool KGamePropertyBase::sendProperty ( const QByteArray &  b)
protected

Forward the data to the owner of this property which then sends it over network.

save is used to store the data into a stream so you have to make sure that function is working properly if you implement your own property!

This function is used by send to send the data over network. This does not send the current value but the explicitly given value.

Returns
TRUE if the message could be sent successfully, otherwise FALSE

Definition at line 135 of file kgameproperty.cpp.

void KGamePropertyBase::setDirty ( bool  d)
inlineprotected

Sets the "dirty" flag of the property.

If a property is "dirty" i.e. KGameProperty::setLocal has been called there is no guarantee that all clients share the same value. You have to ensure this yourself e.g. by calling KGameProperty::setLocal on every client. You can also ignore the dirty flag and continue working withe the property depending on your situation.

Definition at line 318 of file kgameproperty.h.

void KGamePropertyBase::setEmittingSignal ( bool  p)
inline

Sets this property to emit a signal on value changed.

As the properties do not inherit QObject for optimization this signal is emitted via the KPlayer or KGame object

Definition at line 160 of file kgameproperty.h.

void KGamePropertyBase::setLock ( bool  l)
protected

A locked property can only be changed by the player who has set the lock.

You can only call this if isLocked is false. A message is sent over network so that the property is locked for all players except you. Usually you use lock and unlock to access this property

Definition at line 167 of file kgameproperty.cpp.

void KGamePropertyBase::setOptimized ( bool  p)
inline

Sets this property to try to optimize signal and network handling by not sending it out when the property value is not changed.

Definition at line 172 of file kgameproperty.h.

void KGamePropertyBase::setPolicy ( PropertyPolicy  p)
inline

Changes the consistency policy of a property.

The PropertyPolicy is one of PolicyClean (defaulz), PolicyDirty or PolicyLocal.

It is up to you to decide how you want to work.

Definition at line 148 of file kgameproperty.h.

virtual const type_info* KGamePropertyBase::typeinfo ( )
inlinevirtual
Returns
a type_info of the data this property contains.

Reimplemented in KGameProperty< type >, KGameProperty< QString >, KGameProperty< int >, KGameProperty< unsigned int >, and KGameProperty< qint8 >.

Definition at line 246 of file kgameproperty.h.

bool KGamePropertyBase::unlock ( bool  force = false)

A locked property can only be changed by the player who has set the lock.

You can only call this if isLocked is false. A message is sent over network so that the property is locked for all players except you.

Returns
returns false if the property can not be locked, i.e. it is already locked

Definition at line 158 of file kgameproperty.cpp.

void KGamePropertyBase::unregisterData ( )

Definition at line 112 of file kgameproperty.cpp.

Member Data Documentation

union KGamePropertyBase::Flags KGamePropertyBase::mFlags
protected
KGamePropertyHandler* KGamePropertyBase::mOwner
protected

Definition at line 354 of file kgameproperty.h.


The documentation for this class was generated from the following files:
  • kgameproperty.h
  • kgameproperty.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:54 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdegames/libkdegamesprivate/kgame

Skip menu "libkdegames/libkdegamesprivate/kgame"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal