Improve pgn save performance

This commit is contained in:
Loic Guegan 2022-02-25 11:42:46 +01:00
parent 64dec753e7
commit c6f648cfb4
8 changed files with 48 additions and 24 deletions

View file

@ -2,7 +2,7 @@
#include <wx/filename.h>
BaseTab::BaseTab(wxFrame *parent, std::string base_file)
: BasePanelBF(parent), TabInfos(TabInfos::BASE), base(NULL) {
: BasePanelBF(parent), base_file(base_file), TabInfos(TabInfos::BASE), base(NULL) {
game_list->InsertColumn(0, L"id", wxLIST_FORMAT_LEFT, 50);
game_list->InsertColumn(1, L"White", wxLIST_FORMAT_LEFT, 200);
@ -16,7 +16,7 @@ BaseTab::BaseTab(wxFrame *parent, std::string base_file)
this->Bind(wxEVT_BUTTON, &BaseTab::OnSave, this, ID_SAVE_BUTTON);
this->Bind(wxEVT_LIST_ITEM_ACTIVATED, &BaseTab::OnOpenGame, this, wxID_ANY);
current_base->SetLabel(base_file);
LoadFile(base_file);
LoadFile();
}
void BaseTab::OnDelete(wxCommandEvent &event) {
@ -39,8 +39,9 @@ void BaseTab::OnSave(wxCommandEvent &event) {
std::vector<GameBase *> new_games_bases;
std::vector<Game *> new_games;
base->Save(deleted, new_games_bases, new_games);
game_list->ClearAll();
game_list->DeleteAllItems();
deleted.clear();
LoadFile();
}
void BaseTab::OnOpenGame(wxListEvent &event) {
@ -57,11 +58,11 @@ void BaseTab::OnOpenGame(wxListEvent &event) {
void BaseTab::ApplyPreferences() {}
void BaseTab::LoadFile(std::string path) {
wxFileName file(path);
void BaseTab::LoadFile() {
wxFileName file(base_file);
wxString ext = file.GetExt().Lower();
if (ext == "pgn") {
base = new PGNGameBase(path);
base = new PGNGameBase(base_file);
SetLabel(file.GetName() + "(PGN)");
}

View file

@ -11,11 +11,12 @@ wxDECLARE_EVENT(REFRESH_TAB_TITLE, wxCommandEvent);
class BaseTab : public BasePanelBF, public TabInfos {
GameBase *base;
std::vector<std::uint32_t> deleted;
std::string base_file;
public:
BaseTab(wxFrame *parent, std::string base_file);
void ApplyPreferences();
void LoadFile(std::string path);
void LoadFile();
void OnDelete(wxCommandEvent &event);
void OnSave(wxCommandEvent &event);
void OnOpenGame(wxListEvent &event);

View file

@ -31,7 +31,8 @@ Game *PGNGameBase::GetCurrentGame() {
if (pgn->HasTag("FEN")) {
fen = pgn->GetTagValue("FEN");
}
HalfMove *m = new HalfMove(pgnp_moves, fen);
HalfMove *m = new HalfMove(pgnp_moves);
m->SetFen(fen);
Game *g = new Game(m, fen);
for (std::string &s : pgn->GetTagList()) {
g->SetTag(s, pgn->GetTagValue(s));