From 175ce5e10859e2831b0e49a4bf768a9217305d8f Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 27 Feb 2022 19:55:30 +0100 Subject: [PATCH] Debug live engine dialog --- libs/uciadapter | 2 +- src/game_tab/editor/EditorPanel.cpp | 12 ++++++++++++ src/game_tab/editor/EditorPanel.hpp | 3 ++- src/game_tab/editor/EditorPanelBF.cpp | 2 +- src/game_tab/editor/EditorPanelBF.h | 1 + src/game_tab/editor/LiveEngineDialog.cpp | 14 +++++++++++++- src/game_tab/editor/LiveEngineDialog.hpp | 1 + tools/wxframebuilder/EditorPanel.fbp | 2 +- 8 files changed, 32 insertions(+), 5 deletions(-) diff --git a/libs/uciadapter b/libs/uciadapter index cce0131..e5e8205 160000 --- a/libs/uciadapter +++ b/libs/uciadapter @@ -1 +1 @@ -Subproject commit cce0131c30a1f5fb4e3930dc03091bf238d9e80e +Subproject commit e5e820575894e31cd4da0c45a7f460fc47bcc9d3 diff --git a/src/game_tab/editor/EditorPanel.cpp b/src/game_tab/editor/EditorPanel.cpp index dfbb35f..b29477a 100644 --- a/src/game_tab/editor/EditorPanel.cpp +++ b/src/game_tab/editor/EditorPanel.cpp @@ -39,9 +39,21 @@ EditorPanel::EditorPanel(wxFrame *parent, Game *game) wxID_ANY); this->Bind(wxEVT_BUTTON, &EditorPanel::OnApply, this, UPDATE_BTN); this->Bind(wxEVT_BUTTON, &EditorPanel::OnDelete, this, DELETE_BTN); + this->Bind(wxEVT_BUTTON, &EditorPanel::OnLiveAnalysis, this, + LIVE_ANALYSIS_GAME_BUTTON); + ApplyPreferences(); } +void EditorPanel::OnLiveAnalysis(wxCommandEvent &event) { + int selection = engine_list->GetSelection(); + if (selection != wxNOT_FOUND) { + LiveEngineDialog *diag = new LiveEngineDialog(this, engine_list->GetString(selection).ToStdString()); + diag->SetFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"); + diag->Show(); + } +} + void EditorPanel::OnTagSelected(wxListEvent &event) { wxListItem item = event.GetItem(); std::string key = item.GetText().ToStdString(); diff --git a/src/game_tab/editor/EditorPanel.hpp b/src/game_tab/editor/EditorPanel.hpp index 8502c14..b0a00ce 100644 --- a/src/game_tab/editor/EditorPanel.hpp +++ b/src/game_tab/editor/EditorPanel.hpp @@ -1,9 +1,9 @@ #include "../Game.hpp" #include "EditorCanvas.hpp" +#include "EditorPanelBF.h" #include "ochess.hpp" #include #include -#include "EditorPanelBF.h" // Local events wxDECLARE_EVENT(GOTO_MOVE_EVENT, wxCommandEvent); @@ -36,5 +36,6 @@ public: void OnDelete(wxCommandEvent &event); void OnPreviousMove(wxCommandEvent &event); void OnNextMove(wxCommandEvent &event); + void OnLiveAnalysis(wxCommandEvent &event); void ApplyPreferences(); }; \ No newline at end of file diff --git a/src/game_tab/editor/EditorPanelBF.cpp b/src/game_tab/editor/EditorPanelBF.cpp index 8aac38e..8928806 100644 --- a/src/game_tab/editor/EditorPanelBF.cpp +++ b/src/game_tab/editor/EditorPanelBF.cpp @@ -88,7 +88,7 @@ EditorPanelBF::EditorPanelBF( wxWindow* parent, wxWindowID id, const wxPoint& po analyze_game_button = new wxButton( engine_page, wxID_ANY, wxT("Analyze game"), wxDefaultPosition, wxDefaultSize, 0 ); engine_page_sizer->Add( analyze_game_button, 0, wxALL|wxEXPAND, 5 ); - live_analysis_button = new wxButton( engine_page, wxID_ANY, wxT("Live analysis"), wxDefaultPosition, wxDefaultSize, 0 ); + live_analysis_button = new wxButton( engine_page, LIVE_ANALYSIS_GAME_BUTTON, wxT("Live analysis"), wxDefaultPosition, wxDefaultSize, 0 ); engine_page_sizer->Add( live_analysis_button, 0, wxALL|wxEXPAND, 5 ); diff --git a/src/game_tab/editor/EditorPanelBF.h b/src/game_tab/editor/EditorPanelBF.h index c5b38d5..b33655e 100644 --- a/src/game_tab/editor/EditorPanelBF.h +++ b/src/game_tab/editor/EditorPanelBF.h @@ -32,6 +32,7 @@ #define COMMENT_INPUT_BOX 1000 #define UPDATE_BTN 1001 #define DELETE_BTN 1002 +#define LIVE_ANALYSIS_GAME_BUTTON 1003 /////////////////////////////////////////////////////////////////////////////// /// Class EditorPanelBF diff --git a/src/game_tab/editor/LiveEngineDialog.cpp b/src/game_tab/editor/LiveEngineDialog.cpp index 07fd782..0fc85b0 100644 --- a/src/game_tab/editor/LiveEngineDialog.cpp +++ b/src/game_tab/editor/LiveEngineDialog.cpp @@ -10,6 +10,7 @@ LiveEngineDialog::LiveEngineDialog(wxWindow *parent, std::string engine_name) InitEngine(); Bind(wxEVT_BUTTON, &LiveEngineDialog::TogglePauseEngine, this, LIVE_ENGINE_PAUSE_BUTTON); + Bind(wxEVT_CLOSE_WINDOW, &LiveEngineDialog::OnClose, this); } void LiveEngineDialog::InitEngine() { @@ -29,7 +30,7 @@ void LiveEngineDialog::InitEngine() { wxString optPath = opt_name + "/"; wxString default_value_wxString = conf->Read(optPath + "value"); std::string default_value = default_value_wxString.ToStdString(); - engine->setoption(opt_name.ToStdString(),default_value); + engine->setoption(opt_name.ToStdString(), default_value); } while (conf->GetNextGroup(opt_name, index)); } @@ -39,6 +40,17 @@ void LiveEngineDialog::InitEngine() { timer.Bind(wxEVT_TIMER, &LiveEngineDialog::OnTimerTick, this); } +void LiveEngineDialog::OnClose(wxCloseEvent &e) { + if (engine != NULL) { + wxLogDebug("Close live engine!!"); + timer.Stop(); + engine->stop(); + engine->quit(); + delete engine; + } + e.Skip(); +} + void LiveEngineDialog::SetFEN(std::string fen) { timer.Stop(); engine->position(fen); diff --git a/src/game_tab/editor/LiveEngineDialog.hpp b/src/game_tab/editor/LiveEngineDialog.hpp index 5b9fccb..703abf8 100644 --- a/src/game_tab/editor/LiveEngineDialog.hpp +++ b/src/game_tab/editor/LiveEngineDialog.hpp @@ -15,4 +15,5 @@ public: void TogglePauseEngine(wxCommandEvent &event); void OnTimerTick(wxTimerEvent &event); void SetFEN(std::string fen); + void OnClose(wxCloseEvent &e); }; \ No newline at end of file diff --git a/tools/wxframebuilder/EditorPanel.fbp b/tools/wxframebuilder/EditorPanel.fbp index 3960615..3676b36 100644 --- a/tools/wxframebuilder/EditorPanel.fbp +++ b/tools/wxframebuilder/EditorPanel.fbp @@ -1086,7 +1086,7 @@ 0 0 - wxID_ANY + LIVE_ANALYSIS_GAME_BUTTON Live analysis 0