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