[Scummvm-git-logs] scummvm master -> 1fdfe5f77532a37300d85a8900006ea4d966efd7
OMGPizzaGuy
noreply at scummvm.org
Tue Dec 6 03:30:52 UTC 2022
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
1fdfe5f775 ULTIMA8: Expand use of common error to in engine to show savegame load errors
Commit: 1fdfe5f77532a37300d85a8900006ea4d966efd7
https://github.com/scummvm/scummvm/commit/1fdfe5f77532a37300d85a8900006ea4d966efd7
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2022-12-05T21:30:12-06:00
Commit Message:
ULTIMA8: Expand use of common error to in engine to show savegame load errors
Changed paths:
engines/ultima/ultima8/games/start_crusader_process.cpp
engines/ultima/ultima8/games/start_u8_process.cpp
engines/ultima/ultima8/gumps/u8_save_gump.cpp
engines/ultima/ultima8/ultima8.cpp
engines/ultima/ultima8/ultima8.h
diff --git a/engines/ultima/ultima8/games/start_crusader_process.cpp b/engines/ultima/ultima8/games/start_crusader_process.cpp
index 363f6f43483..29ba3beae0a 100644
--- a/engines/ultima/ultima8/games/start_crusader_process.cpp
+++ b/engines/ultima/ultima8/games/start_crusader_process.cpp
@@ -65,7 +65,13 @@ void StartCrusaderProcess::run() {
}
// Try to load the save game, if succeeded this pointer will no longer be valid
- if (_saveSlot >= 0 && Ultima8Engine::get_instance()->loadGameState(_saveSlot).getCode() == Common::kNoError) {
+ if (_saveSlot >= 0) {
+ Common::Error loadError = Ultima8Engine::get_instance()->loadGameState(_saveSlot);
+ if (loadError.getCode() != Common::kNoError) {
+ Ultima8Engine::get_instance()->setError(loadError);
+ return;
+ }
+
return;
}
diff --git a/engines/ultima/ultima8/games/start_u8_process.cpp b/engines/ultima/ultima8/games/start_u8_process.cpp
index 3083a6556d5..bed7cd44313 100644
--- a/engines/ultima/ultima8/games/start_u8_process.cpp
+++ b/engines/ultima/ultima8/games/start_u8_process.cpp
@@ -56,7 +56,13 @@ void StartU8Process::run() {
}
// Try to load the save game, if succeeded this pointer will no longer be valid
- if (_saveSlot >= 0 &&Ultima8Engine::get_instance()->loadGameState(_saveSlot).getCode() == Common::kNoError) {
+ if (_saveSlot >= 0) {
+ Common::Error loadError = Ultima8Engine::get_instance()->loadGameState(_saveSlot);
+ if (loadError.getCode() != Common::kNoError) {
+ Ultima8Engine::get_instance()->setError(loadError);
+ return;
+ }
+
PaletteFaderProcess::I_fadeFromBlack(0, 0);
return;
}
diff --git a/engines/ultima/ultima8/gumps/u8_save_gump.cpp b/engines/ultima/ultima8/gumps/u8_save_gump.cpp
index 242ce8a2820..9ed67a32ebf 100644
--- a/engines/ultima/ultima8/gumps/u8_save_gump.cpp
+++ b/engines/ultima/ultima8/gumps/u8_save_gump.cpp
@@ -34,6 +34,7 @@
#include "common/config-manager.h"
#include "common/savefile.h"
#include "common/translation.h"
+#include "gui/message.h"
namespace Ultima {
namespace Ultima8 {
@@ -258,11 +259,16 @@ bool U8SaveGump::OnKeyDown(int key, int mod) {
bool U8SaveGump::loadgame(int saveIndex) {
if (saveIndex == 1) {
- Ultima8Engine::get_instance()->newGame();
- return true;
- } else {
- return Ultima8Engine::get_instance()->loadGameState(saveIndex).getCode() == Common::kNoError;
+ return Ultima8Engine::get_instance()->newGame();
}
+
+ Common::Error loadError = Ultima8Engine::get_instance()->loadGameState(saveIndex);
+ if (loadError.getCode() != Common::kNoError) {
+ GUI::MessageDialog errorDialog(loadError.getDesc());
+ errorDialog.runModal();
+ return false;
+ }
+ return true;
}
bool U8SaveGump::savegame(int saveIndex, const Std::string &name) {
diff --git a/engines/ultima/ultima8/ultima8.cpp b/engines/ultima/ultima8/ultima8.cpp
index cbfd97e64a8..31e64fa0d33 100644
--- a/engines/ultima/ultima8/ultima8.cpp
+++ b/engines/ultima/ultima8/ultima8.cpp
@@ -124,7 +124,7 @@ Ultima8Engine *Ultima8Engine::_instance = nullptr;
Ultima8Engine::Ultima8Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
Shared::UltimaEngine(syst, gameDesc),
_isRunning(false), _gameInfo(nullptr), _fileSystem(nullptr),
- _configFileMan(nullptr), _saveCount(0), _game(nullptr),
+ _configFileMan(nullptr), _saveCount(0), _game(nullptr), _lastError(Common::kNoError),
_kernel(nullptr), _objectManager(nullptr), _mouse(nullptr), _ucMachine(nullptr),
_screen(nullptr), _fontManager(nullptr), _paletteManager(nullptr), _gameData(nullptr),
_world(nullptr), _desktopGump(nullptr), _gameMapGump(nullptr), _avatarMoverProcess(nullptr),
@@ -158,20 +158,17 @@ Ultima8Engine::~Ultima8Engine() {
}
Common::Error Ultima8Engine::run() {
- bool result = true;
+ Common::Error result;
if (initialize()) {
result = startup();
- if (result)
+ if (result.getCode() == Common::kNoError)
result = runGame();
deinitialize();
shutdown();
}
- if (result)
- return Common::kNoError;
- else
- return Common::kNoGameDataFoundError;
+ return result;
}
@@ -207,7 +204,7 @@ bool Ultima8Engine::hasFeature(EngineFeature f) const {
(f == kSupportsChangingOptionsDuringRuntime);
}
-bool Ultima8Engine::startup() {
+Common::Error Ultima8Engine::startup() {
setDebugger(new Debugger());
pout << "-- Initializing Pentagram -- " << Std::endl;
@@ -335,14 +332,15 @@ bool Ultima8Engine::startup() {
if (setupGame()) {
GraphicSysInit();
- if (!startupGame())
- return false;
+ Common::Error result = startupGame();
+ if (result.getCode() != Common::kNoError)
+ return result;
} else {
// Couldn't setup the game, should never happen?
CANT_HAPPEN_MSG("game failed to initialize");
}
paint();
- return true;
+ return Common::kNoError;
}
bool Ultima8Engine::setupGame() {
@@ -369,7 +367,7 @@ bool Ultima8Engine::setupGame() {
return true;
}
-bool Ultima8Engine::startupGame() {
+Common::Error Ultima8Engine::startupGame() {
pout << Std::endl << "-- Initializing Game: " << _gameInfo->_name << " --" << Std::endl;
GraphicSysInit();
@@ -437,7 +435,7 @@ bool Ultima8Engine::startupGame() {
bool loaded = _game->loadFiles();
if (!loaded)
- return false;
+ return Common::kNoGameDataFoundError;
applyGameSettings();
@@ -452,7 +450,7 @@ bool Ultima8Engine::startupGame() {
newGame(saveSlot);
pout << "-- Game Initialized --" << Std::endl << Std::endl;
- return true;
+ return Common::kNoError;
}
void Ultima8Engine::shutdown() {
@@ -526,7 +524,7 @@ static uint32 _fastTicksNow() {
return g_system->getMillis() * 3;
}
-bool Ultima8Engine::runGame() {
+Common::Error Ultima8Engine::runGame() {
_isRunning = true;
int32 next_ticks = _fastTicksNow(); // Next time is right now!
@@ -586,16 +584,14 @@ bool Ultima8Engine::runGame() {
// Paint Screen
paint();
- if (!_errorMessage.empty()) {
- MessageBoxGump::Show(_errorTitle, _errorMessage, 0xFF8F3030);
- _errorTitle.clear();
- _errorMessage.clear();
+ if (_lastError.getCode() != Common::kNoError) {
+ return _lastError;
}
// Do a delay
g_system->delayMillis(5);
}
- return true;
+ return Common::kNoError;
}
// Paint the _screen
@@ -1260,15 +1256,13 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
SavegameReader *sg = new SavegameReader(stream);
SavegameReader::State state = sg->isValid();
if (state == SavegameReader::SAVE_CORRUPT) {
- Error("Invalid or corrupt savegame", "Error Loading savegame");
delete sg;
- return Common::kReadingFailed;
+ return Common::Error(Common::kReadingFailed, "Invalid or corrupt savegame");
}
if (state != SavegameReader::SAVE_VALID) {
- Error("Unsupported savegame version", "Error Loading savegame");
delete sg;
- return Common::kReadingFailed;
+ return Common::Error(Common::kReadingFailed, "Unsupported savegame version");
}
_mouse->pushMouseCursor();
@@ -1284,9 +1278,8 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
bool ok = saveinfo.load(ds, version);
if (!ok) {
- Error("Invalid or corrupt savegame: missing GameInfo", "Error Loading savegame");
delete sg;
- return Common::kReadingFailed;
+ return Common::Error(Common::kReadingFailed, "Invalid or corrupt savegame: missing GameInfo");
}
if (!_gameInfo->match(saveinfo)) {
@@ -1303,9 +1296,8 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
}
perr << message << Std::endl;
#else
- Error(message, "Error Loading savegame");
delete sg;
- return Common::kReadingFailed;
+ return Common::Error(Common::kReadingFailed, message);
#endif
}
@@ -1416,9 +1408,8 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
*/
if (!totalok) {
- Error(message, "Error Loading savegame");
delete sg;
- return Common::kReadingFailed;
+ return Common::Error(Common::kReadingFailed, message);
}
pout << "Done" << Std::endl;
@@ -1427,13 +1418,8 @@ Common::Error Ultima8Engine::loadGameStream(Common::SeekableReadStream *stream)
return Common::kNoError;
}
-void Ultima8Engine::Error(Std::string message, Std::string title) {
- if (title.empty()) title = "Error";
-
- perr << title << ": " << message << Std::endl;
-
- _errorMessage = message;
- _errorTitle = title;
+void Ultima8Engine::setError(Common::Error &error) {
+ _lastError = error;
}
Gump *Ultima8Engine::getGump(uint16 gumpid) {
diff --git a/engines/ultima/ultima8/ultima8.h b/engines/ultima/ultima8/ultima8.h
index 2e8dae0b8bc..606ce81e3d7 100644
--- a/engines/ultima/ultima8/ultima8.h
+++ b/engines/ultima/ultima8/ultima8.h
@@ -83,8 +83,7 @@ private:
// full system
Game *_game;
- Std::string _errorMessage;
- Std::string _errorTitle;
+ Common::Error _lastError;
Kernel *_kernel;
ObjectManager *_objectManager;
@@ -189,11 +188,11 @@ public:
bool hasFeature(EngineFeature f) const override;
- bool startup();
+ Common::Error startup();
void shutdown();
bool setupGame();
- bool startupGame();
+ Common::Error startupGame();
void shutdownGame(bool reloading = true);
void changeVideoMode(int width, int height);
@@ -209,7 +208,7 @@ public:
Graphics::Screen *getScreen() const override;
- bool runGame();
+ Common::Error runGame();
virtual void handleEvent(const Common::Event &event);
void paint();
@@ -351,9 +350,9 @@ public:
//! \return true if successful.
bool newGame(int saveSlot = -1);
- //! Display an error message box
- //! \param message The message to display on the box
- void Error(Std::string message, Std::string title = Std::string());
+ //! Sets an error to end the engine run loop
+ //! \param error The error to return from the engine
+ void setError(Common::Error &error);
public:
unsigned int getInversion() const {
return _inversion;
More information about the Scummvm-git-logs
mailing list