mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-30 23:43:10 +00:00
Added Engine::init() method; added return value to Engine::go()
svn-id: r15865
This commit is contained in:
parent
8ac347fd95
commit
aad9f122c0
@ -41,9 +41,20 @@ protected:
|
||||
public:
|
||||
Engine(OSystem *syst);
|
||||
virtual ~Engine();
|
||||
|
||||
/**
|
||||
* Init the engine.
|
||||
* @return 0 for success, else an error code.
|
||||
*/
|
||||
virtual int init() = 0;
|
||||
|
||||
/** Start the main engine loop. */
|
||||
virtual void go() = 0;
|
||||
/**
|
||||
* Start the main engine loop.
|
||||
* The return value is not yet used, but could indicate whether the user
|
||||
* wants to return to the launch or to fully quit ScummVM.
|
||||
* @return a result code
|
||||
*/
|
||||
virtual int go() = 0;
|
||||
|
||||
/** Get the path to the save game directory. */
|
||||
virtual const char *getSavePath() const;
|
||||
|
@ -190,11 +190,7 @@ static int launcherDialog(GameDetector &detector, OSystem *system) {
|
||||
// Set the user specified graphics mode (if any).
|
||||
system->setGraphicsMode(ConfMan.get("gfx_mode").c_str());
|
||||
|
||||
// FIXME - we need to call initSize() here so that we can display for example
|
||||
// the launcher dialog. But the Engine object will also call it again (possibly
|
||||
// with a different widht/height!9 However, this method is not for all OSystem
|
||||
// implementations reentrant (it is so now for the SDL backend). Thus we need
|
||||
// to fix all backends to support it, if they don't already.
|
||||
// GUI is (currently) always running at 320x200
|
||||
system->initSize(320, 200);
|
||||
system->endGFXTransaction();
|
||||
|
||||
@ -239,7 +235,7 @@ static int launcherDialog(GameDetector &detector, OSystem *system) {
|
||||
return dlg.runModal();
|
||||
}
|
||||
|
||||
static void runGame(GameDetector &detector, OSystem *system) {
|
||||
static int runGame(GameDetector &detector, OSystem *system) {
|
||||
// Set the window caption to the game name
|
||||
Common::String caption(ConfMan.get("description", detector._targetName));
|
||||
|
||||
@ -256,6 +252,20 @@ static void runGame(GameDetector &detector, OSystem *system) {
|
||||
!scumm_stricmp(ConfMan.get("gfx_mode", detector._targetName).c_str(), "normal") ||
|
||||
!scumm_stricmp(ConfMan.get("gfx_mode", detector._targetName).c_str(), "default");
|
||||
|
||||
// Create the game engine
|
||||
Engine *engine = detector.createEngine(system);
|
||||
assert(engine);
|
||||
|
||||
// Add extrapath (if any) to the directory search list
|
||||
if (ConfMan.hasKey("extrapath"))
|
||||
File::addDefaultDirectory(ConfMan.get("extrapath"));
|
||||
|
||||
if (ConfMan.hasKey("extrapath", Common::ConfigManager::kApplicationDomain))
|
||||
File::addDefaultDirectory(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain));
|
||||
|
||||
int result;
|
||||
|
||||
// Start GFX transaction
|
||||
system->beginGFXTransaction();
|
||||
|
||||
// See if the game should default to 1x scaler
|
||||
@ -274,39 +284,23 @@ static void runGame(GameDetector &detector, OSystem *system) {
|
||||
// (De)activate fullscreen mode as determined by the config settings
|
||||
system->setFeatureState(OSystem::kFeatureFullscreenMode, ConfMan.getBool("fullscreen"));
|
||||
|
||||
// TODO / FIXME: this transaction sould also contain the initial call to initSize
|
||||
// which all engines perform. However, as long as that is contained within
|
||||
// the "engine->go()", this is not possible.
|
||||
// Multiple solutions come to mind, including these:
|
||||
// * Don't let the engine invoke initSize(); rather, add a method to them which we can
|
||||
// use to query their desired res, then we set it for them
|
||||
// * Move the setGraphicsMode/setFeatureState calls here to the Engine class, which the
|
||||
// engines invoke (in other words: move this transaction into the engines
|
||||
// * Add an explicit Engine::init() method, which all engines have to implement,
|
||||
// and into which they should put their call to initSize. Then, make sure this transaction
|
||||
// surrounds the call to engine->init();
|
||||
// Init the engine (this might change the screen parameters
|
||||
result = engine->init();
|
||||
|
||||
system->endGFXTransaction();
|
||||
|
||||
// Create the game engine
|
||||
Engine *engine = detector.createEngine(system);
|
||||
assert(engine);
|
||||
|
||||
// Add extrapath (if any) to the directory search list
|
||||
if (ConfMan.hasKey("extrapath"))
|
||||
File::addDefaultDirectory(ConfMan.get("extrapath"));
|
||||
|
||||
if (ConfMan.hasKey("extrapath", Common::ConfigManager::kApplicationDomain))
|
||||
File::addDefaultDirectory(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain));
|
||||
|
||||
// Run the game engine
|
||||
engine->go();
|
||||
// Run the game engine if the initialization was successful.
|
||||
if (result == 0) {
|
||||
result = engine->go();
|
||||
}
|
||||
|
||||
// Free up memory
|
||||
delete engine;
|
||||
|
||||
// Stop all sound processing now (this prevents some race conditions later on)
|
||||
system->clearSoundCallback();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
@ -419,7 +413,12 @@ extern "C" int scummvm_main(GameDetector &detector, int argc, char *argv[]) {
|
||||
// to save memory
|
||||
PluginManager::instance().unloadPluginsExcept(detector._plugin);
|
||||
|
||||
runGame(detector, system);
|
||||
int result = runGame(detector, system);
|
||||
// TODO: for now, return code 0 (which is currently the only return
|
||||
// code anyway) is interpreted to mean "return to launcher". This is
|
||||
// *not* fixed, we could (and probably will) change the meaning etc.
|
||||
if (result != 0)
|
||||
running = false;
|
||||
|
||||
// There are some command-line options that it's
|
||||
// unlikely that we want to preserve now that we're
|
||||
|
@ -121,6 +121,9 @@ KyraEngine::KyraEngine(GameDetector *detector, OSystem *syst)
|
||||
} else {
|
||||
error("unknown game");
|
||||
}
|
||||
}
|
||||
|
||||
int KyraEngine::init() {
|
||||
|
||||
// Initialize backen
|
||||
syst->initSize(320, 200);
|
||||
@ -169,6 +172,8 @@ KyraEngine::KyraEngine(GameDetector *detector, OSystem *syst)
|
||||
|
||||
assert(_npcScript);
|
||||
assert(_currentScript);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
KyraEngine::~KyraEngine() {
|
||||
@ -185,7 +190,7 @@ void KyraEngine::errorString(const char *buf1, char *buf2) {
|
||||
strcpy(buf2, buf1);
|
||||
}
|
||||
|
||||
void KyraEngine::go() {
|
||||
int KyraEngine::go() {
|
||||
warning("Kyrandia Engine ::go()");
|
||||
// starts the init script
|
||||
/* if (!_currentScript->startScript(kSetupScene)) {
|
||||
@ -259,6 +264,8 @@ void KyraEngine::go() {
|
||||
delete movie;
|
||||
delete image;
|
||||
delete [] _buffer;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void KyraEngine::shutdown() {
|
||||
|
@ -67,7 +67,8 @@ public:
|
||||
uint8 game(void) { return _game; }
|
||||
|
||||
protected:
|
||||
void go();
|
||||
int go();
|
||||
int init();
|
||||
void shutdown();
|
||||
Resourcemanager* _resMgr;
|
||||
MusicPlayer* _midiDriver;
|
||||
|
@ -288,12 +288,7 @@ void QueenEngine::errorString(const char *buf1, char *buf2) {
|
||||
strcpy(buf2, buf1);
|
||||
}
|
||||
|
||||
void QueenEngine::go() {
|
||||
initialise();
|
||||
|
||||
registerDefaultSettings();
|
||||
readOptionSettings();
|
||||
|
||||
int QueenEngine::go() {
|
||||
_logic->oldRoom(0);
|
||||
_logic->newRoom(_logic->currentRoom());
|
||||
|
||||
@ -319,9 +314,11 @@ void QueenEngine::go() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QueenEngine::initialise(void) {
|
||||
int QueenEngine::init() {
|
||||
_system->initSize(GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT);
|
||||
|
||||
_bam = new BamScene(this);
|
||||
@ -361,6 +358,11 @@ void QueenEngine::initialise(void) {
|
||||
|
||||
_sound = Sound::giveSound(_mixer, this, _resource->compression());
|
||||
_walk = new Walk(this);
|
||||
|
||||
registerDefaultSettings();
|
||||
readOptionSettings();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // End of namespace Queen
|
||||
|
@ -123,9 +123,8 @@ protected:
|
||||
|
||||
void errorString(const char *buf_input, char *buf_output);
|
||||
|
||||
void go();
|
||||
|
||||
void initialise();
|
||||
int go();
|
||||
int init();
|
||||
|
||||
|
||||
int _talkSpeed;
|
||||
|
@ -124,9 +124,7 @@ void SagaEngine::errorString(const char *buf1, char *buf2) {
|
||||
strcpy(buf2, buf1);
|
||||
}
|
||||
|
||||
void SagaEngine::go() {
|
||||
int msec = 0;
|
||||
|
||||
int SagaEngine::init() {
|
||||
_soundEnabled = 1;
|
||||
_musicEnabled = 1;
|
||||
|
||||
@ -156,7 +154,7 @@ void SagaEngine::go() {
|
||||
|
||||
// Detect game and open resource files
|
||||
if (GAME_Init() != SUCCESS) {
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize engine modules
|
||||
@ -174,7 +172,8 @@ void SagaEngine::go() {
|
||||
|
||||
if (!_scene->initialized()) {
|
||||
warning("Couldn't initialize scene module");
|
||||
return;
|
||||
// TODO/FIXME: We are leaking here
|
||||
return -1;
|
||||
}
|
||||
|
||||
// System initialization
|
||||
@ -214,7 +213,8 @@ void SagaEngine::go() {
|
||||
|
||||
_render = new Render(this, _system);
|
||||
if (!_render->initialized()) {
|
||||
return;
|
||||
// TODO/FIXME: We are leaking here
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize system specific sound
|
||||
@ -232,6 +232,12 @@ void SagaEngine::go() {
|
||||
_render->reg();
|
||||
_anim->reg();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SagaEngine::go() {
|
||||
int msec = 0;
|
||||
|
||||
_previousTicks = _system->getMillis();
|
||||
|
||||
_sprite->loadList(ITE_MAIN_SPRITES, &_mainSprites);
|
||||
@ -265,6 +271,8 @@ void SagaEngine::go() {
|
||||
_render->drawScene();
|
||||
_system->delayMillis(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SagaEngine::shutdown() {
|
||||
|
@ -88,7 +88,8 @@ class SagaEngine : public Engine {
|
||||
void errorString(const char *buf_input, char *buf_output);
|
||||
|
||||
protected:
|
||||
void go();
|
||||
int go();
|
||||
int init();
|
||||
|
||||
public:
|
||||
SagaEngine(GameDetector * detector, OSystem * syst);
|
||||
|
@ -972,16 +972,11 @@ ScummEngine_v70he::ScummEngine_v70he(GameDetector *detector, OSystem *syst, cons
|
||||
_heSndSoundFreq = 0;
|
||||
}
|
||||
|
||||
void ScummEngine::go() {
|
||||
mainInit();
|
||||
mainRun();
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark --- Initialization ---
|
||||
#pragma mark -
|
||||
|
||||
void ScummEngine::mainInit() {
|
||||
int ScummEngine::init() {
|
||||
|
||||
// Initialize backend
|
||||
_system->initSize(_screenWidth, _screenHeight);
|
||||
@ -1119,6 +1114,8 @@ void ScummEngine::mainInit() {
|
||||
} else {
|
||||
_saveLoadFlag = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ScummEngine::scummInit() {
|
||||
@ -1397,7 +1394,7 @@ void ScummEngine::setupMusic(int midi) {
|
||||
#pragma mark --- Main loop ---
|
||||
#pragma mark -
|
||||
|
||||
void ScummEngine::mainRun() {
|
||||
int ScummEngine::go() {
|
||||
int delta = 0;
|
||||
int diff = _system->getMillis();
|
||||
|
||||
@ -1418,6 +1415,8 @@ void ScummEngine::mainRun() {
|
||||
// TODO: Maybe perform an autosave on exit?
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ScummEngine::waitForTimer(int msec_delay) {
|
||||
|
@ -385,10 +385,10 @@ public:
|
||||
virtual ~ScummEngine();
|
||||
|
||||
/** Startup function: Calls mainInit and then mainRun. */
|
||||
void go();
|
||||
int go();
|
||||
|
||||
// Init functions
|
||||
void mainInit();
|
||||
int init();
|
||||
|
||||
virtual void setupScummVars();
|
||||
void initScummVars();
|
||||
@ -399,7 +399,6 @@ public:
|
||||
void setupMusic(int midi);
|
||||
|
||||
// Scumm main loop
|
||||
void mainRun();
|
||||
int scummLoop(int delta);
|
||||
|
||||
// Event handling
|
||||
|
@ -659,7 +659,9 @@ SimonEngine::SimonEngine(GameDetector *detector, OSystem *syst)
|
||||
_vc_10_base_ptr_old = 0;
|
||||
memcpy (_hebrew_char_widths,
|
||||
"\x5\x5\x4\x6\x5\x3\x4\x5\x6\x3\x5\x5\x4\x6\x5\x3\x4\x6\x5\x6\x6\x6\x5\x5\x5\x6\x5\x6\x6\x6\x6\x6", 32);
|
||||
}
|
||||
|
||||
int SimonEngine::init() {
|
||||
// Setup mixer
|
||||
if (!_mixer->isReady())
|
||||
warning("Sound initialization failed. "
|
||||
@ -718,6 +720,8 @@ SimonEngine::SimonEngine(GameDetector *detector, OSystem *syst)
|
||||
|
||||
// FIXME Use auto dirty rects cleanup code to reduce CPU usage
|
||||
g_system->setFeatureState(OSystem::kFeatureAutoComputeDirtyRects, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SimonEngine::~SimonEngine() {
|
||||
@ -4668,7 +4672,7 @@ void SimonEngine::fadeUpPalette() {
|
||||
} while (!done);
|
||||
}
|
||||
|
||||
void SimonEngine::go() {
|
||||
int SimonEngine::go() {
|
||||
if (!_dump_file)
|
||||
_dump_file = stdout;
|
||||
|
||||
@ -4728,6 +4732,8 @@ void SimonEngine::go() {
|
||||
handle_verb_clicked(_verb_hitarea);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SimonEngine::shutdown() {
|
||||
|
@ -740,7 +740,8 @@ protected:
|
||||
|
||||
void resfile_read(void *dst, uint32 offs, uint32 size);
|
||||
|
||||
void go();
|
||||
int init();
|
||||
int go();
|
||||
void openGameFile();
|
||||
|
||||
static int CDECL game_thread_proc(void *param);
|
||||
|
10
sky/sky.cpp
10
sky/sky.cpp
@ -183,9 +183,7 @@ void SkyEngine::handleKey(void) {
|
||||
_key_pressed = 0;
|
||||
}
|
||||
|
||||
void SkyEngine::go() {
|
||||
|
||||
initialise();
|
||||
int SkyEngine::go() {
|
||||
|
||||
_sdl_mouse_x = GAME_SCREEN_WIDTH / 2;
|
||||
_sdl_mouse_y = GAME_SCREEN_HEIGHT / 2;
|
||||
@ -243,9 +241,11 @@ void SkyEngine::go() {
|
||||
_skyScreen->flip();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SkyEngine::initialise(void) {
|
||||
int SkyEngine::init() {
|
||||
_system->initSize(320, 200);
|
||||
|
||||
if (!_mixer->isReady())
|
||||
@ -359,6 +359,8 @@ void SkyEngine::initialise(void) {
|
||||
_skyMusic->setVolume(ConfMan.getInt("music_volume") >> 1);
|
||||
|
||||
_debugger = new Debugger(_skyLogic, _skyMouse, _skyScreen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SkyEngine::initItemList() {
|
||||
|
@ -93,14 +93,14 @@ protected:
|
||||
|
||||
void logic_engine();
|
||||
void delay(uint amount);
|
||||
void go();
|
||||
int go();
|
||||
void doCheat(uint8 num);
|
||||
void handleKey(void);
|
||||
|
||||
uint32 _lastSaveTime;
|
||||
|
||||
Text *getText();
|
||||
void initialise();
|
||||
int init();
|
||||
void initItemList();
|
||||
|
||||
void initVirgin();
|
||||
|
@ -123,7 +123,7 @@ SwordEngine::~SwordEngine() {
|
||||
delete _resMan;
|
||||
}
|
||||
|
||||
void SwordEngine::initialize(void) {
|
||||
int SwordEngine::init() {
|
||||
|
||||
// Add default file directories
|
||||
File::addDefaultDirectory(_gameDataPath + "CLUSTERS/");
|
||||
@ -198,6 +198,8 @@ void SwordEngine::initialize(void) {
|
||||
_objectMan->initialize();
|
||||
_mouse->initialize();
|
||||
_control = new Control(_saveFileMan, _resMan, _objectMan, _system, _mouse, _sound, _music, getSavePath());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SwordEngine::reinitialize(void) {
|
||||
@ -1129,9 +1131,8 @@ void SwordEngine::checkCdFiles(void) { // check if we're running from cd, hdd or
|
||||
}
|
||||
}
|
||||
|
||||
void SwordEngine::go(void) {
|
||||
int SwordEngine::go() {
|
||||
|
||||
initialize();
|
||||
checkCdFiles();
|
||||
|
||||
uint8 startPos = ConfMan.getInt("boot_param");
|
||||
@ -1163,6 +1164,8 @@ void SwordEngine::go(void) {
|
||||
_systemVars.controlPanelMode = CP_NORMAL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SwordEngine::checkCd(void) {
|
||||
|
@ -75,10 +75,10 @@ public:
|
||||
|
||||
uint32 _features;
|
||||
protected:
|
||||
void go();
|
||||
int go();
|
||||
int init();
|
||||
private:
|
||||
void delay(uint amount);
|
||||
void initialize(void);
|
||||
|
||||
void checkCdFiles(void);
|
||||
void checkCd(void);
|
||||
|
@ -223,7 +223,7 @@ void Sword2Engine::setupPersistentResources() {
|
||||
_resman->openResource(CUR_PLAYER_ID);
|
||||
}
|
||||
|
||||
void Sword2Engine::mainInit() {
|
||||
int Sword2Engine::init() {
|
||||
// Get some falling RAM and put it in your pocket, never let it slip
|
||||
// away
|
||||
|
||||
@ -288,7 +288,7 @@ void Sword2Engine::mainInit() {
|
||||
// will either have killed the music, or done a crossfade.
|
||||
|
||||
if (_quit)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
if (result)
|
||||
startGame();
|
||||
@ -296,9 +296,11 @@ void Sword2Engine::mainInit() {
|
||||
startGame();
|
||||
|
||||
_graphics->initialiseRenderCycle();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sword2Engine::mainRun() {
|
||||
int Sword2Engine::go() {
|
||||
while (1) {
|
||||
if (_debugger->isAttached())
|
||||
_debugger->onFrame();
|
||||
@ -370,11 +372,8 @@ void Sword2Engine::mainRun() {
|
||||
buildDisplay();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Sword2Engine::go() {
|
||||
mainInit();
|
||||
mainRun();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Sword2Engine::closeGame() {
|
||||
|
@ -170,9 +170,8 @@ private:
|
||||
public:
|
||||
Sword2Engine(GameDetector *detector, OSystem *syst);
|
||||
~Sword2Engine();
|
||||
void go();
|
||||
void mainInit();
|
||||
void mainRun();
|
||||
int go();
|
||||
int init();
|
||||
|
||||
void setupPersistentResources();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user