Migrate to std::shared_ptr<Game>

This commit is contained in:
Loic Guegan 2022-02-28 20:16:57 +01:00
parent 4c959fe12e
commit 44ea0a50a3
16 changed files with 44 additions and 49 deletions

View file

@ -3,7 +3,7 @@
wxDEFINE_EVENT(GAME_CHANGE, wxCommandEvent);
GameTab::GameTab(wxFrame *parent, Game *game)
GameTab::GameTab(wxFrame *parent, std::shared_ptr<Game> game)
: wxPanel(parent), game(game), TabInfos(TabInfos::GAME) {
// Splitter
wxSplitterWindow *splitter = new wxSplitterWindow(this, wxID_ANY);
@ -30,10 +30,6 @@ GameTab::GameTab(wxFrame *parent, Game *game)
Bind(GAME_CHANGE, &GameTab::OnGameChange, this, wxID_ANY);
}
GameTab::~GameTab() {
delete game;
}
void GameTab::OnGameChange(wxCommandEvent &event) {
board_panel->Notify();
editor_panel->Notify();

View file

@ -16,16 +16,15 @@ wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
class GameTab : public wxPanel, public TabInfos {
GameTabRightPanel *editor_panel;
GameTabLeftPanel *board_panel;
Game *game;
std::shared_ptr<Game> game;
void RefreshLabel();
void OnRefreshTabTitle(wxCommandEvent &event);
void OnGameChange(wxCommandEvent &event);
public:
GameTab(wxFrame *parent, Game *game);
~GameTab();
GameTab(wxFrame *parent, std::shared_ptr<Game> game);
void ApplyPreferences();
void *GetGame() { return (game); }
std::shared_ptr<Game> GetGame() { return (std::shared_ptr<Game>(game)); }
void *GetBase() { return (NULL); };
};

View file

@ -1,7 +1,7 @@
#include "GameTabLeftPanel.hpp"
#include <wx/clipbrd.h>
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, Game *game)
GameTabLeftPanel::GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game)
: TabGameLeftPanel(parent), game(game) {
// Add board

View file

@ -9,12 +9,12 @@ wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
class GameTabLeftPanel : public TabGameLeftPanel {
Game *game;
std::shared_ptr<Game> game;
BoardCanvas *board_canvas;
void NotifyEditor();
public:
GameTabLeftPanel(wxFrame *parent, Game *game);
GameTabLeftPanel(wxFrame *parent, std::shared_ptr<Game> game);
void Notify();
void OnPlay(wxCommandEvent &event);
void OnGotoMove(wxCommandEvent &event);

View file

@ -7,7 +7,7 @@ wxDEFINE_EVENT(SET_AS_MAINLINE_EVENT, wxCommandEvent);
wxDEFINE_EVENT(PREVIOUS_MOVE_EVENT, wxCommandEvent);
wxDEFINE_EVENT(NEXT_MOVE_EVENT, wxCommandEvent);
GameTabRightPanel::GameTabRightPanel(wxFrame *parent, Game *game)
GameTabRightPanel::GameTabRightPanel(wxFrame *parent, std::shared_ptr<Game> game)
: TabGameRightPanel(parent), game(game), selected_item(-1),
live_engine(NULL) {
editor_canvas = new EditorCanvas((wxFrame *)editor_page);

View file

@ -16,13 +16,13 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
wxDECLARE_EVENT(GAME_CHANGE, wxCommandEvent);
class GameTabRightPanel : public TabGameRightPanel {
Game *game;
std::shared_ptr<Game> game;
EditorCanvas *editor_canvas;
long selected_item;
LiveEngineDialog *live_engine;
public:
GameTabRightPanel(wxFrame *parent, Game *game);
GameTabRightPanel(wxFrame *parent, std::shared_ptr<Game> game);
void NotifyBoard();
void Notify();
void OnCommentChange(wxCommandEvent &event);