Skip to content

Commit d87145f

Browse files
committed
- Fixed save details crash when hovering empty rows.
- Fixed save performance drop in Debug mode.
1 parent 6d48b2f commit d87145f

6 files changed

Lines changed: 30 additions & 39 deletions

File tree

‎src/Menu/SaveState.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void SaveState::updateList()
8585
{
8686
_lstSaves->clearList();
8787
_lstSaves->addRow(1, tr("STR_NEW_SAVED_GAME").c_str());
88-
_saves = SavedGame::getList(_lstSaves, _game->getLanguage());
88+
_saves = SavedGame::getList(_lstSaves, _game->getLanguage(), &_details);
8989
}
9090

9191
/**

‎src/Menu/SavedGameState.cpp‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ SavedGameState::SavedGameState(Game *game, OptionsOrigin origin, int firstValidR
116116

117117
_txtDetails->setColor(Palette::blockOffset(15)-1);
118118
_txtDetails->setSecondaryColor(Palette::blockOffset(8)+10);
119-
_txtDetails->setText(L"");
119+
_txtDetails->setText(tr("STR_DETAILS").arg(L""));
120120
}
121121

122122
/**
@@ -191,7 +191,7 @@ void SavedGameState::init()
191191
void SavedGameState::updateList()
192192
{
193193
_lstSaves->clearList();
194-
_saves = SavedGame::getList(_lstSaves, _game->getLanguage());
194+
_saves = SavedGame::getList(_lstSaves, _game->getLanguage(), &_details);
195195
}
196196

197197
/**
@@ -217,38 +217,17 @@ void SavedGameState::btnCancelClick(Action *)
217217
void SavedGameState::lstSavesMouseOver(Action *)
218218
{
219219
int sel = _lstSaves->getSelectedRow() - _firstValidRow;
220-
if (0 > sel)
220+
std::wstring wstr;
221+
if (sel >= 0 && sel < _saves.size())
221222
{
222-
_txtDetails->setText(L"");
223-
return;
224-
}
225-
std::string fullname = Options::getUserFolder() + _saves[sel];
226-
std::wstring wstr=L"";
227-
try
228-
{
229-
YAML::Node doc = YAML::LoadFile(fullname);
230-
if (doc["turn"])
231-
{
232-
wstr = tr("STR_BATTLESCAPE"); wstr += L": ";
233-
wstr += tr(doc["mission"].as<std::string>()); wstr += L", ";
234-
wstr += tr("STR_TURN").arg(Language::utf8ToWstr(doc["turn"].as<std::string>()));
235-
}
236-
else wstr = tr("STR_GEOSCAPE");
237-
}
238-
catch (Exception &e)
239-
{
240-
Log(LOG_ERROR) << e.what();
241-
}
242-
catch (YAML::Exception &e)
243-
{
244-
Log(LOG_ERROR) << e.what();
223+
wstr = _details[sel];
245224
}
246225
_txtDetails->setText(tr("STR_DETAILS").arg(wstr));
247226
}
248227

249228
void SavedGameState::lstSavesMouseOut(Action *)
250229
{
251-
_txtDetails->setText(L"");
230+
_txtDetails->setText(tr("STR_DETAILS").arg(L""));
252231
}
253232

254233
}

‎src/Menu/SavedGameState.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class SavedGameState : public State
4646
OptionsOrigin _origin;
4747
bool _showMsg, _noUI;
4848
std::vector<std::string> _saves;
49+
std::vector<std::wstring> _details;
4950
int _firstValidRow;
5051
public:
5152
/// Creates the Saved Game state.

‎src/Savegame/SavedGame.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ SavedGame::~SavedGame()
151151
* and adds them to a text list.
152152
* @param list Text list.
153153
* @param lang Loaded language.
154+
* @param details List of savegame details.
154155
*/
155-
std::vector<std::string> SavedGame::getList(TextList *list, Language *lang)
156+
std::vector<std::string> SavedGame::getList(TextList *list, Language *lang, std::vector<std::wstring> *details)
156157
{
158+
details->clear();
157159
std::vector<std::string> saves = CrossPlatform::getFolderContents(Options::getUserFolder(), "sav");
158160

159161
for (std::vector<std::string>::iterator i = saves.begin(); i != saves.end(); ++i)
@@ -171,6 +173,18 @@ std::vector<std::string> SavedGame::getList(TextList *list, Language *lang)
171173
saveMonth << lang->getString(time.getMonthString());
172174
saveYear << time.getYear();
173175

176+
std::wstringstream info;
177+
if (doc["turn"])
178+
{
179+
info << lang->getString("STR_BATTLESCAPE") << L": " << lang->getString(doc["mission"].as<std::string>()) << L", ";
180+
info << lang->getString("STR_TURN").arg(doc["turn"].as<int>());
181+
}
182+
else
183+
{
184+
info << lang->getString("STR_GEOSCAPE");
185+
}
186+
details->push_back(info.str());
187+
174188
std::wstring wstr;
175189
if (doc["name"])
176190
{

‎src/Savegame/SavedGame.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SavedGame
9393
/// Cleans up the saved game.
9494
~SavedGame();
9595
/// Gets list of saves in the user directory.
96-
static std::vector<std::string> getList(TextList *list, Language *lang);
96+
static std::vector<std::string> getList(TextList *list, Language *lang, std::vector<std::wstring> *details);
9797
/// Loads a saved game from YAML.
9898
void load(const std::string &filename, Ruleset *rule);
9999
/// Saves a saved game to YAML.

‎src/Savegame/Ufo.cpp‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
* You should have received a copy of the GNU General Public License
1717
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19-
20-
// this MUST be the first line:
21-
#define _USE_MATH_DEFINES
22-
2319
#include "Ufo.h"
20+
#include <assert.h>
21+
#define _USE_MATH_DEFINES
22+
#include <cmath>
23+
#include <sstream>
24+
#include <algorithm>
25+
#include "../aresame.h"
2426
#include "Craft.h"
2527
#include "AlienMission.h"
2628
#include "../Engine/Exception.h"
@@ -30,11 +32,6 @@
3032
#include "../Ruleset/UfoTrajectory.h"
3133
#include "SavedGame.h"
3234
#include "Waypoint.h"
33-
#include "../aresame.h"
34-
#include <assert.h>
35-
#include <cmath>
36-
#include <sstream>
37-
#include <algorithm>
3835

3936
namespace OpenXcom
4037
{

0 commit comments

Comments
 (0)