build: 确保关闭 QT_UI 宏也能编译通过

This commit is contained in:
Calcitem 2020-10-17 22:57:33 +08:00
parent 924554206d
commit 627fde24ed
4 changed files with 36 additions and 10 deletions

View File

@ -42,9 +42,15 @@ using namespace std;
/// Thread constructor launches the thread and waits until it goes to sleep
/// in idle_loop(). Note that 'searching' and 'exit' should be already set.
Thread::Thread(int color, QObject *parent) :
Thread::Thread(int color
#ifdef QT_UI
, QObject *parent
#endif
) :
stdThread(&Thread::idle_loop, this),
#ifdef QT_UI
QObject(parent),
#endif
timeLimit(3600)
{
this->us = color;
@ -168,11 +174,15 @@ void Thread::idle_loop()
if (search() == 3) {
loggerDebug("Draw\n\n");
strCommand = "draw";
#ifdef QT_UI
emitCommand();
#endif
} else {
strCommand = nextMove();
if (strCommand != "" && strCommand != "error!") {
#ifdef QT_UI
emitCommand();
#endif
}
}
#ifdef OPENING_BOOK

View File

@ -32,16 +32,19 @@
#include "search.h"
#include "thread_win32_osx.h"
#include "server.h"
#include "client.h"
#include "test.h"
#include "config.h"
#ifdef QT_UI
#include <QObject>
#endif QT_UI
/// Thread class keeps together all the thread-related stuff. We use
/// per-thread pawn and material hash tables so that once we get a
/// pointer to an entry its life time is unlimited and we don't have
/// to care about someone changing the entry under our feet.
class Thread : public QObject
class Thread
#ifdef QT_UI
: public QObject
#endif
{
public:
std::mutex mutex;
@ -52,8 +55,16 @@ public:
string strCommand;
explicit Thread(QObject *parent = nullptr);
explicit Thread(int color, QObject *parent = nullptr);
explicit Thread(
#ifdef QT_UI
QObject *parent = nullptr
#endif
);
explicit Thread(int color
#ifdef QT_UI
, QObject *parent = nullptr
#endif
);
virtual ~Thread();
int search();
void clear();
@ -142,15 +153,15 @@ public:
private:
int timeLimit;
#ifdef QT_UI
Q_OBJECT
public:
#ifdef QT_UI
void emitCommand();
#endif // QT_UI
signals:
void command(const string &cmdline, bool update = true);
#endif // QT_UI
};

View File

@ -81,6 +81,7 @@ GameController::GameController(
qRegisterMetaType<std::string>("string");
#ifdef QT_UI
// 关联AI和控制器的着法命令行
connect(aiThread[BLACK], SIGNAL(command(const string &, bool)),
this, SLOT(command(const string &, bool)));
@ -89,6 +90,7 @@ GameController::GameController(
connect(this->gameTest, SIGNAL(command(const string &, bool)),
this, SLOT(command(const string &, bool)));
#endif // QT_UI
#ifdef NET_FIGHT_SUPPORT
#ifndef TRAINING_MODE
@ -941,12 +943,14 @@ bool GameController::command(const string &cmd, bool update /* = true */)
Q_UNUSED(hasSound)
#endif
#ifdef QT_UI
// 防止接收滞后结束的线程发送的指令
if (sender() == aiThread[BLACK] && !isAiPlayer[BLACK])
return false;
if (sender() == aiThread[WHITE] && !isAiPlayer[WHITE])
return false;
#endif // QT_UI
#ifndef TRAINING_MODE
// 声音

View File

@ -43,6 +43,7 @@
#include "server.h"
#include "client.h"
#include "stopwatch.h"
#include "test.h"
using namespace std;