Merged _game_run() inside game_run(). Some cleanup
svn-id: r49513
This commit is contained in:
parent
3d0ac2a676
commit
67690e89a3
3 changed files with 24 additions and 42 deletions
|
@ -79,7 +79,9 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) {
|
||||||
|
|
||||||
switch (curEvent.type) {
|
switch (curEvent.type) {
|
||||||
case SCI_EVENT_QUIT:
|
case SCI_EVENT_QUIT:
|
||||||
quit_vm(s);
|
s->script_abort_flag = 1; // Terminate VM
|
||||||
|
g_debugState.seeking = kDebugSeekNothing;
|
||||||
|
g_debugState.runningStep = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCI_EVENT_KEYBOARD:
|
case SCI_EVENT_KEYBOARD:
|
||||||
|
|
|
@ -1687,17 +1687,31 @@ static void _init_stack_base_with_selector(EngineState *s, Selector selector) {
|
||||||
s->stack_base[1] = NULL_REG;
|
s->stack_base[1] = NULL_REG;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EngineState *_game_run(EngineState *&s) {
|
void game_run(EngineState **_s) {
|
||||||
bool restoring = false;
|
EngineState *s = *_s;
|
||||||
|
|
||||||
|
debugC(2, kDebugLevelVM, "Calling %s::play()", g_sci->getGameID());
|
||||||
|
_init_stack_base_with_selector(s, g_sci->getKernel()->_selectorCache.play); // Call the play selector
|
||||||
|
|
||||||
|
// Now: Register the first element on the execution stack
|
||||||
|
if (!send_selector(s, s->_gameObj, s->_gameObj, s->stack_base, 2, s->stack_base)) {
|
||||||
|
g_sci->getSciDebugger()->printObject(s->_gameObj);
|
||||||
|
error("Failed to run the game! Aborting...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// and ENGAGE!
|
||||||
|
|
||||||
|
// Attach the debug console on game startup, if requested
|
||||||
if (DebugMan.isDebugChannelEnabled(kDebugLevelOnStartup))
|
if (DebugMan.isDebugChannelEnabled(kDebugLevelOnStartup))
|
||||||
g_sci->getSciDebugger()->attach();
|
g_sci->getSciDebugger()->attach();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
s->_executionStackPosChanged = false;
|
s->_executionStackPosChanged = false;
|
||||||
run_vm(s, restoring);
|
run_vm(s, s->restoring);
|
||||||
|
|
||||||
if (s->restarting_flags & SCI_GAME_IS_RESTARTING_NOW) { // Restart was requested?
|
if (s->restarting_flags & SCI_GAME_IS_RESTARTING_NOW) { // Restart was requested?
|
||||||
restoring = false;
|
s->restoring = false;
|
||||||
s->_executionStack.clear();
|
s->_executionStack.clear();
|
||||||
s->_executionStackPosChanged = false;
|
s->_executionStackPosChanged = false;
|
||||||
|
|
||||||
|
@ -1715,8 +1729,7 @@ static EngineState *_game_run(EngineState *&s) {
|
||||||
s->restarting_flags = SCI_GAME_WAS_RESTARTED;
|
s->restarting_flags = SCI_GAME_WAS_RESTARTED;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
restoring = s->restoring;
|
if (s->restoring) {
|
||||||
if (restoring) {
|
|
||||||
game_exit(s);
|
game_exit(s);
|
||||||
s->restoring = false;
|
s->restoring = false;
|
||||||
if (s->script_abort_flag == 2) {
|
if (s->script_abort_flag == 2) {
|
||||||
|
@ -1735,34 +1748,7 @@ static EngineState *_game_run(EngineState *&s) {
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
int game_run(EngineState **_s) {
|
|
||||||
EngineState *s = *_s;
|
|
||||||
|
|
||||||
debugC(2, kDebugLevelVM, "Calling %s::play()", g_sci->getGameID());
|
|
||||||
_init_stack_base_with_selector(s, g_sci->getKernel()->_selectorCache.play); // Call the play selector
|
|
||||||
|
|
||||||
// Now: Register the first element on the execution stack-
|
|
||||||
if (!send_selector(s, s->_gameObj, s->_gameObj, s->stack_base, 2, s->stack_base)) {
|
|
||||||
Console *con = g_sci->getSciDebugger();
|
|
||||||
con->printObject(s->_gameObj);
|
|
||||||
warning("Failed to run the game! Aborting...");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
// and ENGAGE!
|
|
||||||
_game_run(*_s);
|
|
||||||
|
|
||||||
debugC(2, kDebugLevelVM, "Game::play() finished.");
|
debugC(2, kDebugLevelVM, "Game::play() finished.");
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void quit_vm(EngineState *s) {
|
|
||||||
s->script_abort_flag = 1; // Terminate VM
|
|
||||||
g_debugState.seeking = kDebugSeekNothing;
|
|
||||||
g_debugState.runningStep = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reg_t *ObjVarRef::getPointer(SegManager *segMan) const {
|
reg_t *ObjVarRef::getPointer(SegManager *segMan) const {
|
||||||
|
|
|
@ -375,9 +375,8 @@ int game_init_sound(EngineState *s, int sound_flags, SciVersion soundVersion);
|
||||||
* Note that, EngineState *s may be changed during the game, e.g. if a game
|
* Note that, EngineState *s may be changed during the game, e.g. if a game
|
||||||
* state is restored.
|
* state is restored.
|
||||||
* @param[in] s Pointer to the pointer of the state to operate on
|
* @param[in] s Pointer to the pointer of the state to operate on
|
||||||
* @return 0 on success, 1 if an error occured.
|
|
||||||
*/
|
*/
|
||||||
int game_run(EngineState **s);
|
void game_run(EngineState **s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores an SCI game state and runs the game
|
* Restores an SCI game state and runs the game
|
||||||
|
@ -397,11 +396,6 @@ int game_restore(EngineState **s, char *savegame_name);
|
||||||
*/
|
*/
|
||||||
int game_exit(EngineState *s);
|
int game_exit(EngineState *s);
|
||||||
|
|
||||||
/**
|
|
||||||
* Instructs the virtual machine to abort
|
|
||||||
*/
|
|
||||||
void quit_vm(EngineState *s);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a PMachine instruction from a memory buffer and return its length.
|
* Read a PMachine instruction from a memory buffer and return its length.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue