mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve Game and HalfMoves memory management
This commit is contained in:
parent
a8c59c41bc
commit
4c959fe12e
6 changed files with 19 additions and 3 deletions
|
@ -15,13 +15,19 @@ Game::Game(std::string fen) : current(NULL), moves(NULL), result("*") {
|
||||||
board = chessarbiter::FENParser::Parse(fen).board;
|
board = chessarbiter::FENParser::Parse(fen).board;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Game(HalfMove *m, std::string initial_fen): result("*") {
|
Game::Game(HalfMove *m, std::string initial_fen) : result("*") {
|
||||||
moves = m;
|
moves = m;
|
||||||
current = m;
|
current = m;
|
||||||
this->initial_fen = initial_fen;
|
this->initial_fen = initial_fen;
|
||||||
board = chessarbiter::FENParser::Parse(initial_fen).board;
|
board = chessarbiter::FENParser::Parse(initial_fen).board;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Game::~Game() {
|
||||||
|
if (moves != NULL) {
|
||||||
|
delete moves;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string Game::GetBoard() { return (board); }
|
std::string Game::GetBoard() { return (board); }
|
||||||
|
|
||||||
std::string Game::GetTag(std::string tagname) { return (tags[tagname]); }
|
std::string Game::GetTag(std::string tagname) { return (tags[tagname]); }
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
Game();
|
Game();
|
||||||
Game(std::string fen);
|
Game(std::string fen);
|
||||||
Game(HalfMove *m, std::string initial_fen);
|
Game(HalfMove *m, std::string initial_fen);
|
||||||
|
~Game();
|
||||||
std::string GetBoard();
|
std::string GetBoard();
|
||||||
std::string GetTag(std::string tagname);
|
std::string GetTag(std::string tagname);
|
||||||
void SetTag(std::string tagname, std::string value);
|
void SetTag(std::string tagname, std::string value);
|
||||||
|
|
|
@ -30,6 +30,10 @@ GameTab::GameTab(wxFrame *parent, Game *game)
|
||||||
Bind(GAME_CHANGE, &GameTab::OnGameChange, this, wxID_ANY);
|
Bind(GAME_CHANGE, &GameTab::OnGameChange, this, wxID_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameTab::~GameTab() {
|
||||||
|
delete game;
|
||||||
|
}
|
||||||
|
|
||||||
void GameTab::OnGameChange(wxCommandEvent &event) {
|
void GameTab::OnGameChange(wxCommandEvent &event) {
|
||||||
board_panel->Notify();
|
board_panel->Notify();
|
||||||
editor_panel->Notify();
|
editor_panel->Notify();
|
||||||
|
|
|
@ -17,12 +17,14 @@ class GameTab : public wxPanel, public TabInfos {
|
||||||
GameTabRightPanel *editor_panel;
|
GameTabRightPanel *editor_panel;
|
||||||
GameTabLeftPanel *board_panel;
|
GameTabLeftPanel *board_panel;
|
||||||
Game *game;
|
Game *game;
|
||||||
|
|
||||||
void RefreshLabel();
|
void RefreshLabel();
|
||||||
void OnRefreshTabTitle(wxCommandEvent &event);
|
void OnRefreshTabTitle(wxCommandEvent &event);
|
||||||
void OnGameChange(wxCommandEvent &event);
|
void OnGameChange(wxCommandEvent &event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameTab(wxFrame *parent, Game *game);
|
GameTab(wxFrame *parent, Game *game);
|
||||||
|
~GameTab();
|
||||||
void ApplyPreferences();
|
void ApplyPreferences();
|
||||||
void *GetGame() { return (game); }
|
void *GetGame() { return (game); }
|
||||||
void *GetBase() { return (NULL); };
|
void *GetBase() { return (NULL); };
|
||||||
|
|
|
@ -10,6 +10,9 @@ HalfMove::HalfMove(std::string move, std::string fen) : fen(fen), capture(' ') {
|
||||||
}
|
}
|
||||||
|
|
||||||
HalfMove::~HalfMove() {
|
HalfMove::~HalfMove() {
|
||||||
|
if (mainline != NULL) {
|
||||||
|
delete mainline;
|
||||||
|
}
|
||||||
for (HalfMove *m : variations) {
|
for (HalfMove *m : variations) {
|
||||||
delete m;
|
delete m;
|
||||||
}
|
}
|
||||||
|
@ -221,7 +224,7 @@ void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
|
||||||
BuildAndVerify(m->mainline, arbiter.GetFEN());
|
BuildAndVerify(m->mainline, arbiter.GetFEN());
|
||||||
}
|
}
|
||||||
for (HalfMove *v : m->variations) {
|
for (HalfMove *v : m->variations) {
|
||||||
BuildAndVerify(v,fen);
|
BuildAndVerify(v, fen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void HalfMove::BuildAndVerify(std::string initial_fen) {
|
void HalfMove::BuildAndVerify(std::string initial_fen) {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <wx/filefn.h> // Check file exists etc
|
#include <wx/filefn.h> // Check file exists etc
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#define MAINWIN ((MainWindow *)wxGetApp().GetTopWindow())
|
#define MAINWIN ((MainWindow *)wxGetApp().GetTopWindow())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue