Cute Chess  0.1
gamemanager.h
1 /*
2  This file is part of Cute Chess.
3  Copyright (C) 2008-2018 Cute Chess authors
4 
5  Cute Chess is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Cute Chess is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef GAMEMANAGER_H
20 #define GAMEMANAGER_H
21 
22 #include <QObject>
23 #include <QList>
24 #include <QPointer>
25 class ChessGame;
26 class ChessPlayer;
27 class PlayerBuilder;
28 class GameThread;
29 
30 
40 class LIB_EXPORT GameManager : public QObject
41 {
42  Q_OBJECT
43 
44  public:
46  enum StartMode
47  {
54  Enqueue
55  };
58  {
69  ReusePlayers
70  };
71 
73  GameManager(QObject* parent = nullptr);
74 
83  QList<ChessGame*> activeGames() const;
84 
93  int concurrency() const;
99  void setConcurrency(int concurrency);
100 
112  void cleanupIdleThreads();
113 
143  void newGame(ChessGame* game,
144  const PlayerBuilder* white,
145  const PlayerBuilder* black,
146  StartMode startMode = StartImmediately,
147  CleanupMode cleanupMode = DeletePlayers);
148 
149  public slots:
155  void finish();
156 
157  signals:
159  void gameStarted(ChessGame* game);
166  void gameDestroyed(ChessGame* game);
176  void ready();
182  void finished();
184  void debugMessage(const QString& data);
185 
186  private slots:
187  void onThreadReady();
188  void onThreadQuit();
189  void onGameInitialized(bool success);
190 
191  private:
192  struct GameEntry
193  {
194  ChessGame* game;
195  const PlayerBuilder* white;
196  const PlayerBuilder* black;
197  StartMode startMode;
198  CleanupMode cleanupMode;
199  };
200 
201  GameThread* getThread(const PlayerBuilder* white,
202  const PlayerBuilder* black);
203  void startGame(const GameEntry& entry);
204  void startQueuedGame();
205  void cleanup();
206 
207  bool m_finishing;
208  int m_concurrency;
209  int m_activeQueuedGameCount;
210  QList< QPointer<GameThread> > m_threads;
211  QList<GameThread*> m_activeThreads;
212  QList<GameEntry> m_gameEntries;
213  QList<ChessGame*> m_activeGames;
214 };
215 
216 #endif // GAMEMANAGER_H
Definition: gamemanager.h:63
A class for constructing new chess players.
Definition: playerbuilder.h:38
A chess player, human or AI.
Definition: chessplayer.h:38
CleanupMode
Definition: gamemanager.h:57
Definition: chessgame.h:38
A class for managing chess games and players.
Definition: gamemanager.h:40
StartMode
Definition: gamemanager.h:46
Definition: gamemanager.h:49