[Kde-games-devel] Why a KPlayer is not added ?

Andreas Beckermann b_mann at gmx.de
Wed Jul 13 06:16:46 CEST 2005


On Sunday 03 July 2005 22:40, Kleag wrote:
> Hello,

Hi

> I'm currently converting my game KsirK to use the KGame library in order to
> make it network playable. I first converted some classes to KGame, KPlayer,
> etc. and obtained a usable program. Particularly, I called the KPlayer
> constructor with a pointer to the KGame object and players were added to
> the playersList.
>
> Next, I converted the members of the KGame object to KGameProperty but now
> the last created player seems to be not added, event if debug messages show
> that all my own code is executed as expected...
>
> So, it is probably the addPlayer called by the KPlayer constructor that
> does not end by the player addition. How could it happen ?

I cannot imagine any reason. Are you sure you provided the KGame pointer to 
the KPlayer c'tor ? Otherwise you need to call KGame::addPlayer() yourself.

By default players are added asynchronously, maybe that is your problem?
Why do you think the player isn't added? "seems not to be added" is not very 
descriptive...

> I found the following comment in the KGame class documentation:
> "Note that an added player will first get into a "queue" and won't be in
> the game. It will be added to the game as soon as systemAddPlayer is called
> what will happen as soon as IdAddPlayer is received."
> Could it be linked to my problem ? If so, why "IdAddPlayer" is not received
> by the last created player ?

It could, yes. By default KGame messages work asynchronously, so
kdDebug() << playerCount() << endl;
addPlayer(newPlayer);
kdDebug() << playerCount() << endl;
will output the same playerCount() value twice. The "newPlayer" has not yet 
been added at this point.
So you need to wait until the new player has been added (i.e. 
KGame::signalPlayerJoinedGame() got emitted)

Did you maybe reimplement KGame::networkTransmission() ? If so, make sure that 
you actually call the original implementation as very first line, otherwise 
nonsense will happen

> Thanks in advance.
>
> Kleag

CU
Andi


More information about the kde-games-devel mailing list