HDB: Change init functions to handle errors

This commit is contained in:
Strangerke 2019-08-19 00:47:34 +02:00 committed by Eugene Sandulenko
parent 23c7dc8ebd
commit 2178770898
16 changed files with 29 additions and 64 deletions

View file

@ -1012,7 +1012,7 @@ AI::~AI() {
} }
} }
bool AI::init() { void AI::init() {
_debugQMark = g_hdb->_gfx->loadIcon("icon_question_mark"); _debugQMark = g_hdb->_gfx->loadIcon("icon_question_mark");
// Clear Waypoint list and load Waypoint graphics // Clear Waypoint list and load Waypoint graphics
@ -1114,7 +1114,6 @@ bool AI::init() {
_weaponSelGfx = NULL; _weaponSelGfx = NULL;
restartSystem(); restartSystem();
return true;
} }
void AI::clearPersistent() { void AI::clearPersistent() {

View file

@ -300,7 +300,7 @@ void AI::newDelivery(const char *itemTextName, const char *itemGfxName, const ch
} }
bool AI::completeDelivery(const char *id) { bool AI::completeDelivery(const char *id) {
for (int i = 0; i < _numDeliveries; i++) for (int i = 0; i < _numDeliveries; i++) {
if (!scumm_stricmp(_deliveries[i].id, id)) { if (!scumm_stricmp(_deliveries[i].id, id)) {
for (; i < _numDeliveries; i++) for (; i < _numDeliveries; i++)
memcpy(&_deliveries[i], &_deliveries[i + 1], sizeof(_deliveries[0])); memcpy(&_deliveries[i], &_deliveries[i + 1], sizeof(_deliveries[0]));
@ -311,6 +311,7 @@ bool AI::completeDelivery(const char *id) {
g_hdb->_sound->playVoice(GUY_COMPLETED, 1); g_hdb->_sound->playVoice(GUY_COMPLETED, 1);
return true; return true;
} }
}
return false; return false;
} }

View file

@ -803,7 +803,7 @@ public:
AI(); AI();
~AI(); ~AI();
bool init(); void init();
void clearPersistent(); void clearPersistent();
void restartSystem(); void restartSystem();
const char *funcLookUp(void(*function)(AIEntity *e)); const char *funcLookUp(void(*function)(AIEntity *e));

View file

@ -39,33 +39,27 @@ FileMan::~FileMan() {
delete _dir[i]; delete _dir[i];
} }
bool FileMan::openMPC(const Common::String &filename) { void FileMan::openMPC(const Common::String &filename) {
uint32 offset;
if (!_mpcFile->open(filename)) { if (!_mpcFile->open(filename)) {
error("FileMan::openMPC(): Error reading the MSD/MPC file %s", filename.c_str()); error("FileMan::openMPC(): Error reading the MSD/MPC file %s", filename.c_str());
return false;
} }
_dataHeader.id = _mpcFile->readUint32BE(); _dataHeader.id = _mpcFile->readUint32BE();
if (_dataHeader.id == MKTAG('M', 'P', 'C', 'C')) { if (_dataHeader.id == MKTAG('M', 'P', 'C', 'C')) {
debug("COMPRESSED MPC FILE"); error("FileMan::openMPC: Compressed MPC File");
return false;
} else if (_dataHeader.id == MKTAG('M', 'P', 'C', 'U')) { } else if (_dataHeader.id == MKTAG('M', 'P', 'C', 'U')) {
// we're fine // we're fine
} else if (_dataHeader.id == MKTAG('M', 'S', 'D', 'C')) { } else if (_dataHeader.id == MKTAG('M', 'S', 'D', 'C')) {
// we're fine // we're fine
} else if (_dataHeader.id == MKTAG('M', 'S', 'D', 'U')) { } else if (_dataHeader.id == MKTAG('M', 'S', 'D', 'U')) {
debug("UNCOMPRESSED MSD FILE"); error("FileMan::openMPC: Uncompressed MSD File");
return false;
} else { } else {
error("Invalid MPC/MSD File."); error("FileMan::openMPC: Invalid MPC/MSD File.");
return false;
} }
// read the directory // read the directory
offset = _mpcFile->readUint32LE(); uint32 offset = _mpcFile->readUint32LE();
_mpcFile->seek((int32)offset); _mpcFile->seek((int32)offset);
// Note: The MPC archive format assumes the offset to be uint32, // Note: The MPC archive format assumes the offset to be uint32,
@ -91,8 +85,6 @@ bool FileMan::openMPC(const Common::String &filename) {
_dir.push_back(dirEntry); _dir.push_back(dirEntry);
} }
return true;
} }
void FileMan::closeMPC() { void FileMan::closeMPC() {

View file

@ -68,7 +68,7 @@ public:
uint32 dirSize; uint32 dirSize;
} _dataHeader; } _dataHeader;
bool openMPC(const Common::String &filename); void openMPC(const Common::String &filename);
void closeMPC(); void closeMPC();
void seek(int32 offset, int flag); void seek(int32 offset, int flag);

View file

@ -85,8 +85,7 @@ Gfx::~Gfx() {
delete _skyClouds; delete _skyClouds;
} }
bool Gfx::init() { void Gfx::init() {
// Set the default cursor pos & char clipping // Set the default cursor pos & char clipping
setCursor(0, 0); setCursor(0, 0);
@ -109,12 +108,12 @@ bool Gfx::init() {
// Load Game Font // Load Game Font
if (!loadFont(HDB_FONT)) if (!loadFont(HDB_FONT))
return false; error("Gfx::init: Couldn't load fonts");
// Read total number of tiles in game // Read total number of tiles in game
_numTiles = g_hdb->_fileMan->getCount("t32_", TYPE_TILE32); _numTiles = g_hdb->_fileMan->getCount("t32_", TYPE_TILE32);
if (!_numTiles) if (!_numTiles)
return false; error("Gfx::init: No tiles in game");
// Setup Tile Lookup Array // Setup Tile Lookup Array
_tLookupArray = new TileLookup[_numTiles]; _tLookupArray = new TileLookup[_numTiles];
@ -199,7 +198,6 @@ bool Gfx::init() {
} }
_systemInit = true; _systemInit = true;
return true;
} }
void Gfx::save(Common::OutSaveFile *out) { void Gfx::save(Common::OutSaveFile *out) {
@ -835,7 +833,6 @@ int Gfx::animateTile(int tileIndex) {
} }
bool Gfx::loadFont(const char *string) { bool Gfx::loadFont(const char *string) {
Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(string, TYPE_FONT); Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(string, TYPE_FONT);
if (!stream) if (!stream)
return false; return false;

View file

@ -77,7 +77,7 @@ public:
Graphics::ManagedSurface _globalSurface; Graphics::ManagedSurface _globalSurface;
bool init(); void init();
void save(Common::OutSaveFile *out); void save(Common::OutSaveFile *out);
void loadSaveFile(Common::InSaveFile *in); void loadSaveFile(Common::InSaveFile *in);
void fillScreen(uint32 color); void fillScreen(uint32 color);

View file

@ -137,28 +137,14 @@ bool HDBGame::init() {
// Init fileMan // Init fileMan
if (!_fileMan->openMPC(getGameFile())) { _fileMan->openMPC(getGameFile());
error("FileMan::openMPC: Cannot find the %s data file", getGameFile());
}
if (!_gfx->init()) {
error("Gfx::init: Couldn't initialize Gfx");
}
if (!_sound->init()) {
error("Window::init: Couldn't initialize Sound");
}
if (!_ai->init()) {
error("AI::init: Couldn't initialize AI");
}
if (!_window->init()) {
error("Window::init: Couldn't initialize Window");
}
if (!_input->init()) {
error("Input::init: Couldn't initialize Input");
}
if (!_lua->init()) {
error("LuaScript::init: Couldn't load the GLOBAL.LUA code.");
}
_gfx->init();
_sound->init();
_ai->init();
_window->init();
_input->init();
_lua->init();
_menu->init(); _menu->init();
_debugLogo = _gfx->loadIcon("icon_debug_logo"); _debugLogo = _gfx->loadIcon("icon_debug_logo");

View file

@ -31,7 +31,7 @@
namespace HDB { namespace HDB {
bool Input::init() { void Input::init() {
_stylusDown = false; _stylusDown = false;
_buttons = 0; _buttons = 0;
@ -49,8 +49,6 @@ bool Input::init() {
_mouseY = g_hdb->_screenHeight / 2; _mouseY = g_hdb->_screenHeight / 2;
_mouseLButton = _mouseMButton = _mouseRButton = 0; _mouseLButton = _mouseMButton = _mouseRButton = 0;
return true;
} }
void Input::setButtons(uint16 b) { void Input::setButtons(uint16 b) {

View file

@ -42,7 +42,7 @@ enum Button {
class Input { class Input {
public: public:
bool init(); void init();
void setButtons(uint16 b); void setButtons(uint16 b);
uint16 getButtons(); uint16 getButtons();

View file

@ -125,16 +125,13 @@ LuaScript::~LuaScript() {
delete _globalLuaStream; delete _globalLuaStream;
} }
bool LuaScript::init() { void LuaScript::init() {
// Load Global Lua Code // Load Global Lua Code
_globalLuaStream = g_hdb->_fileMan->findFirstData("GLOBAL.LUA", TYPE_BINARY); _globalLuaStream = g_hdb->_fileMan->findFirstData("GLOBAL.LUA", TYPE_BINARY);
_globalLuaLength = g_hdb->_fileMan->getLength("GLOBAL.LUA", TYPE_BINARY); _globalLuaLength = g_hdb->_fileMan->getLength("GLOBAL.LUA", TYPE_BINARY);
if (_globalLuaStream == NULL || _globalLuaLength == 0) { if (_globalLuaStream == NULL || _globalLuaLength == 0) {
error("LuaScript::initScript: 'global code' failed to load"); error("LuaScript::initScript: 'global code' failed to load");
return false;
} }
return true;
} }
bool LuaScript::loadLua(const char *name) { bool LuaScript::loadLua(const char *name) {

View file

@ -52,7 +52,7 @@ public:
void save(Common::OutSaveFile *out); void save(Common::OutSaveFile *out);
void loadSaveFile(Common::InSaveFile *in); void loadSaveFile(Common::InSaveFile *in);
bool init(); void init();
bool initScript(Common::SeekableReadStream *stream, const char *scriptName, int32 length); bool initScript(Common::SeekableReadStream *stream, const char *scriptName, int32 length);
void pushInt(int value); void pushInt(int value);

View file

@ -1418,7 +1418,7 @@ void Sound::test() {
#endif #endif
} }
bool Sound::init() { void Sound::init() {
_song1.playing = _song2.playing = false; _song1.playing = _song2.playing = false;
// //
@ -1448,8 +1448,6 @@ bool Sound::init() {
// voices are on by default // voices are on by default
_voicesOn = 1; _voicesOn = 1;
memset(&_voicePlayed[0], 0, sizeof(_voicePlayed)); memset(&_voicePlayed[0], 0, sizeof(_voicePlayed));
return true;
} }
void Sound::save(Common::OutSaveFile *out) { void Sound::save(Common::OutSaveFile *out) {

View file

@ -1487,7 +1487,7 @@ public:
void test(); // FIXME. Remove void test(); // FIXME. Remove
bool init(); void init();
void save(Common::OutSaveFile *out); void save(Common::OutSaveFile *out);
void loadSaveFile(Common::InSaveFile *in); void loadSaveFile(Common::InSaveFile *in);
void setMusicVolume(int value); void setMusicVolume(int value);

View file

@ -131,8 +131,7 @@ Window::~Window() {
delete _gemGfx; delete _gemGfx;
} }
bool Window::init() { void Window::init() {
_gfxTL = g_hdb->_gfx->loadPic(MENU_BACK_TOPLEFT); _gfxTL = g_hdb->_gfx->loadPic(MENU_BACK_TOPLEFT);
_gfxTM = g_hdb->_gfx->loadPic(MENU_BACK_TOP); _gfxTM = g_hdb->_gfx->loadPic(MENU_BACK_TOP);
_gfxTR = g_hdb->_gfx->loadPic(MENU_BACK_TOPRIGHT); _gfxTR = g_hdb->_gfx->loadPic(MENU_BACK_TOPRIGHT);
@ -207,8 +206,6 @@ bool Window::init() {
_gemGfx = NULL; _gemGfx = NULL;
restartSystem(); restartSystem();
return true;
} }
void Window::save(Common::OutSaveFile *out) { void Window::save(Common::OutSaveFile *out) {

View file

@ -171,7 +171,7 @@ public:
Window(); Window();
~Window(); ~Window();
bool init(); void init();
void save(Common::OutSaveFile *out); void save(Common::OutSaveFile *out);
void loadSaveFile(Common::InSaveFile *in); void loadSaveFile(Common::InSaveFile *in);
void restartSystem(); void restartSystem();