summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quacker/macondo.cpp28
-rw-r--r--quacker/macondo.h24
-rw-r--r--quacker/macondobackend.cpp4
-rw-r--r--quacker/macondobackend.h2
-rw-r--r--quacker/quacker.cpp46
-rw-r--r--quacker/quacker.h15
-rw-r--r--quacker/view.cpp5
-rw-r--r--quacker/view.h4
8 files changed, 78 insertions, 50 deletions
diff --git a/quacker/macondo.cpp b/quacker/macondo.cpp
index 55d5deb..3b941e1 100644
--- a/quacker/macondo.cpp
+++ b/quacker/macondo.cpp
@@ -1,26 +1,28 @@
+/*
+TODO:
+- configurable execPath
+- set Macondo lexicon based on game
+*/
+
#include "macondo.h"
#include "macondobackend.h"
-#include "movebox.h"
-#include "quacker.h"
#include <QGridLayout>
#include <QPushButton>
#include <QCheckBox>
-Macondo::Macondo(Quackle::Game *game, MoveBox *moveBox) : View() {
+Macondo::Macondo(Quackle::Game *game) : View() {
m_game = game;
- m_moveBox = moveBox;
QGridLayout *layout = new QGridLayout(this);
m_useMacondo = new QCheckBox(tr("Use Macondo for 'Simulate'"));
layout->setAlignment(Qt::AlignTop);
layout->addWidget(m_useMacondo, 0, 0);
const char *home = getenv("HOME");
- // TODO: configurable path
std::string execPath = home ? home : "/";
execPath += "/apps/macondo/macondo";
initOptions = std::make_unique<MacondoInitOptions>(execPath);
m_backend = new MacondoBackend(game, *initOptions);
- connect(m_backend, SIGNAL(gotSimMoves(const Quackle::MoveList *)), this, SIGNAL(newMoves(const Quackle::MoveList *)));
+ connect(m_backend, SIGNAL(gotSimMoves(const Quackle::MoveList &)), this, SLOT(gotSimMoves(const Quackle::MoveList &)));
}
Macondo::~Macondo() {
@@ -28,16 +30,14 @@ Macondo::~Macondo() {
}
void Macondo::simulate() {
- if (m_backend->isRunning()) {
- // stop analysis
+ if (m_backend->isRunning())
stop();
- return;
- }
+ clearMoves();
MacondoSimulateOptions options;
m_backend->simulate(options);
}
-void Macondo::setGame(Quackle::Game *game) {
+void Macondo::gameChanged(Quackle::Game *game) {
delete m_backend;
m_backend = new MacondoBackend(game, *initOptions);
m_game = game;
@@ -45,8 +45,14 @@ void Macondo::setGame(Quackle::Game *game) {
void Macondo::stop() {
m_backend->stop();
+ m_anyUpdates = false;
}
bool Macondo::useForSimulation() const {
return m_useMacondo->isChecked();
}
+
+void Macondo::gotSimMoves(const Quackle::MoveList &moves) {
+ m_moves = moves;
+ m_anyUpdates = true;
+}
diff --git a/quacker/macondo.h b/quacker/macondo.h
index de12fe1..f34117e 100644
--- a/quacker/macondo.h
+++ b/quacker/macondo.h
@@ -5,35 +5,39 @@
#include "game.h"
class QCheckBox;
-class QTimer;
-namespace Quackle {
- class Game;
- class MoveList;
-}
class MacondoBackend;
struct MacondoInitOptions;
class MoveBox;
class Macondo : public View {
Q_OBJECT
public:
- Macondo(Quackle::Game *, MoveBox *);
+ Macondo(Quackle::Game *game);
~Macondo();
- void setGame(Quackle::Game *);
// stop current analysis
void stop();
// should Macondo be used for simulations?
bool useForSimulation() const;
-signals:
- void newMoves(const Quackle::MoveList *);
+ inline const Quackle::MoveList &getMoves() const { return m_moves; }
+ inline bool hasMoves() const { return !m_moves.empty(); }
+ inline void clearMoves() { m_moves.clear(); }
+ // returns whether there have been any updates to moves since last time anyUpdates() was called.
+ inline bool anyUpdates() {
+ bool any = m_anyUpdates;
+ m_anyUpdates = false;
+ return any;
+ }
public slots:
void simulate();
+ virtual void gameChanged(Quackle::Game *game);
+private slots:
+ void gotSimMoves(const Quackle::MoveList &moves);
private:
QCheckBox *m_useMacondo;
Quackle::Game *m_game;
MacondoBackend *m_backend;
Quackle::MoveList m_moves;
int m_viewingPlyNumber = 0;
- MoveBox *m_moveBox;
+ bool m_anyUpdates = false;
std::unique_ptr<MacondoInitOptions> initOptions;
};
diff --git a/quacker/macondobackend.cpp b/quacker/macondobackend.cpp
index 2712512..b74fcea 100644
--- a/quacker/macondobackend.cpp
+++ b/quacker/macondobackend.cpp
@@ -1,5 +1,5 @@
-#include "datamanager.h"
#include "macondobackend.h"
+#include "datamanager.h"
#include "quackleio/gcgio.h"
#include "game.h"
@@ -218,7 +218,7 @@ void MacondoBackend::timer() {
if (!moves.empty()) {
// at this point the GCG is definitely fully loaded
removeTempGCG();
- emit gotSimMoves(&moves);
+ emit gotSimMoves(moves);
}
}
break;
diff --git a/quacker/macondobackend.h b/quacker/macondobackend.h
index 9d327d2..6e5b8af 100644
--- a/quacker/macondobackend.h
+++ b/quacker/macondobackend.h
@@ -32,7 +32,7 @@ public:
// stop current Macondo analysis
void stop();
signals:
- void gotSimMoves(const Quackle::MoveList *moves);
+ void gotSimMoves(const Quackle::MoveList &moves);
private slots:
void processStarted();
void processFinished(int, QProcess::ExitStatus);
diff --git a/quacker/quacker.cpp b/quacker/quacker.cpp
index 6bb25fc..b54e364 100644
--- a/quacker/quacker.cpp
+++ b/quacker/quacker.cpp
@@ -401,7 +401,7 @@ void TopLevel::setCandidateMove(const Quackle::Move *move, bool *carryOnPtr)
// a check if we have simulation results -- but we don't want to send out
// a moves changed signal if we don't have results because
// we just sent out a position changed signal
- if (m_simulator->hasSimulationResults())
+ if (m_simulator->hasSimulationResults() || m_macondo->hasMoves())
updateMoveViews();
}
@@ -619,11 +619,11 @@ void TopLevel::updatePositionViews()
updateListerDialogWithRack();
}
-void TopLevel::updateMoveViews(const Quackle::MoveList *providedList)
+void TopLevel::updateMoveViews()
{
Quackle::MoveList list;
- if (providedList) {
- list = *providedList;
+ if (m_macondo->hasMoves()) {
+ list = m_macondo->getMoves();
}
else if (m_simulator->hasSimulationResults())
{
@@ -843,6 +843,7 @@ void TopLevel::plugIntoMatrix(View *view)
connect(view, SIGNAL(commit()), this, SLOT(commit()));
connect(view, SIGNAL(setRack(const Quackle::Rack &)), this, SLOT(setRack(const Quackle::Rack &)));
connect(view, SIGNAL(setNote(const UVString &)), this, SLOT(setNote(const UVString &)));
+ connect(this, SIGNAL(gameChanged(Quackle::Game *)), view, SLOT(gameChanged(Quackle::Game *)));
}
void TopLevel::plugIntoPositionMatrix(View *view)
@@ -1055,7 +1056,12 @@ void TopLevel::simulate(bool startSimulation)
// it's not so useful to have sim control show/hide
// like this
//m_simulatorWidget->setVisible(startSimulation);
-
+ if (m_macondo->useForSimulation()) {
+ if (startSimulation)
+ m_macondo->simulate();
+ else
+ m_macondo->stop();
+ }
if (startSimulation)
{
logfileChanged();
@@ -1070,15 +1076,6 @@ void TopLevel::simulateToggled(bool startSimulation)
if (!m_game->hasPositions())
return;
- if (m_macondo->useForSimulation()) {
- if (startSimulation) {
- m_macondo->simulate();
- } else {
- m_macondo->stop();
- }
- return;
- }
-
simulate(startSimulation);
if (startSimulation)
@@ -1254,8 +1251,19 @@ void TopLevel::showSimulationDetails()
void TopLevel::incrementSimulation()
{
- if (m_simulateAction->isChecked())
- {
+ if (!m_simulateAction->isChecked())
+ return;
+
+ if (m_macondo->useForSimulation()) {
+ if (m_macondo->anyUpdates()) {
+ updateMoveViews();
+ updateSimViews();
+ }
+ // check again in 100ms
+ m_simulationTimer->start(100);
+ } else {
+ // clear Macondo moves to make way for Simulator moves
+ m_macondo->clearMoves();
m_simulator->simulate(m_plies);
m_simulationTimer->start(0);
@@ -1307,7 +1315,7 @@ void TopLevel::loadFile(const QString &filename)
QTextStream stream(&file);
delete m_game;
m_game = logania->read(stream, QuackleIO::Logania::MaintainBoardPreparation);
- m_macondo->setGame(m_game);
+ emit gameChanged(m_game);
file.close();
@@ -2015,9 +2023,9 @@ void TopLevel::createWidgets()
m_history = new History;
plugIntoHistoryMatrix(m_history);
- m_macondo = new Macondo(m_game, m_moveBox);
+ m_macondo = new Macondo(m_game);
plugIntoMatrix(m_macondo);
- connect(m_macondo, SIGNAL(newMoves(const Quackle::MoveList *)), this, SLOT(updateMoveViews(const Quackle::MoveList *)));
+ plugIntoPositionMatrix(m_macondo);
m_tabWidget = new QTabWidget;
m_tabWidget->addTab(m_history, tr("Histor&y"));
diff --git a/quacker/quacker.h b/quacker/quacker.h
index b9a9602..399deee 100644
--- a/quacker/quacker.h
+++ b/quacker/quacker.h
@@ -66,7 +66,6 @@ class BaseView;
class HistoryView;
class Letterbox;
class ListerDialog;
-class MoveBox;
class QuackerSettings;
class Settings;
class SimViewer;
@@ -201,6 +200,10 @@ protected slots:
// update *positional* views - emit positionChanged
void updatePositionViews();
+ // updates move views from either simulation results if available
+ // or kibitzed moves
+ void updateMoveViews();
+
// update history views when a new position is added
void updateHistoryViews();
@@ -229,11 +232,6 @@ protected slots:
void startBirthday();
void birthdayBash();
void birthdayGram(int index, bool on);
-public slots:
- // updates move views from either provided list,
- // or simulation results if available,
- // or kibitzed moves
- void updateMoveViews(const Quackle::MoveList *list = nullptr);
signals:
// emitted when views (eg board) should update based on the
@@ -246,6 +244,9 @@ signals:
// emitted when views of history must update
void historyChanged(const Quackle::History &history);
+ // emitted when game pointer is changed
+ void gameChanged(Quackle::Game *game);
+
protected:
Quackle::DataManager m_dataManager;
Quackle::Game *m_game;
@@ -323,7 +324,7 @@ private:
HistoryView *m_dashboard;
QWidget *m_choicesWidget;
- MoveBox *m_moveBox;
+ View *m_moveBox;
View *m_noteEditor;
QFrame *m_frameWidget;
diff --git a/quacker/view.cpp b/quacker/view.cpp
index 2d5bbe2..0957307 100644
--- a/quacker/view.cpp
+++ b/quacker/view.cpp
@@ -54,6 +54,11 @@ void View::movesChanged(const Quackle::MoveList *moves)
it->movesChanged(moves);
}
+void View::gameChanged(Quackle::Game *game) {
+ for (auto& it : m_subviews)
+ it->gameChanged(game);
+}
+
void View::connectSubviewSignals()
{
for (auto& it : m_subviews)
diff --git a/quacker/view.h b/quacker/view.h
index ce72f82..c75cf1f 100644
--- a/quacker/view.h
+++ b/quacker/view.h
@@ -26,6 +26,7 @@
namespace Quackle
{
+ class Game;
class GamePosition;
class History;
class HistoryLocation;
@@ -86,6 +87,9 @@ public slots:
// supercede that from the position
virtual void movesChanged(const Quackle::MoveList *moves);
+ // called whenever the game pointer changes
+ virtual void gameChanged(Quackle::Game *);
+
virtual void grabFocus();
protected: