From 627fde24edd864b4091edf71d246d5da912b4348 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 17 Oct 2020 22:57:33 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E7=A1=AE=E4=BF=9D=E5=85=B3=E9=97=AD?= =?UTF-8?q?=20QT=5FUI=20=E5=AE=8F=E4=B9=9F=E8=83=BD=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/thread.cpp | 12 +++++++++++- src/thread.h | 29 ++++++++++++++++++++--------- src/ui/qt/gamecontroller.cpp | 4 ++++ src/ui/qt/gamecontroller.h | 1 + 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/thread.cpp b/src/thread.cpp index 80057dbe..6c820944 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -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 diff --git a/src/thread.h b/src/thread.h index 3f14b288..f40dd56a 100644 --- a/src/thread.h +++ b/src/thread.h @@ -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 +#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 }; diff --git a/src/ui/qt/gamecontroller.cpp b/src/ui/qt/gamecontroller.cpp index ca272b2e..4fa2d055 100644 --- a/src/ui/qt/gamecontroller.cpp +++ b/src/ui/qt/gamecontroller.cpp @@ -81,6 +81,7 @@ GameController::GameController( qRegisterMetaType("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 // 声音 diff --git a/src/ui/qt/gamecontroller.h b/src/ui/qt/gamecontroller.h index 0cfbe5b1..69b7f185 100644 --- a/src/ui/qt/gamecontroller.h +++ b/src/ui/qt/gamecontroller.h @@ -43,6 +43,7 @@ #include "server.h" #include "client.h" #include "stopwatch.h" +#include "test.h" using namespace std;