Skip to content

Commit

Permalink
AGI: Cycle event processing changed
Browse files Browse the repository at this point in the history
processEvents() renamed to processScummVMEvents()
mainCycle() renamed to processAGIEvents()
have.key now sets up an inner loop and calls processAGIEvents()
to avoid any further cycle work processing
  • Loading branch information
Martin Kiewitz committed Feb 3, 2016
1 parent c2038e0 commit 778c1dd
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 35 deletions.
6 changes: 3 additions & 3 deletions engines/agi/agi.cpp
Expand Up @@ -62,7 +62,7 @@ void AgiEngine::pollTimer() {
_lastTick += 50;

while (_system->getMillis() < _lastTick) {
processEvents();
processScummVMEvents();
_console->onFrame();
_system->delayMillis(10);
_system->updateScreen();
Expand All @@ -77,7 +77,7 @@ void AgiEngine::pause(uint32 msec) {
_gfx->setMouseCursor(true); // Busy mouse cursor

while (_system->getMillis() < endTime) {
processEvents();
processScummVMEvents();
_system->updateScreen();
_system->delayMillis(10);
}
Expand Down Expand Up @@ -552,7 +552,7 @@ Common::Error AgiEngine::go() {

if (_game.state < STATE_LOADED) {
do {
mainCycle();
processAGIEvents();
} while (_game.state < STATE_RUNNING);
}

Expand Down
7 changes: 4 additions & 3 deletions engines/agi/agi.h
Expand Up @@ -390,7 +390,8 @@ enum CycleInnerLoopType {
CYCLE_INNERLOOP_MENU_VIA_KEYBOARD = 3,
CYCLE_INNERLOOP_MENU_VIA_MOUSE = 4,
CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT = 5,
CYCLE_INNERLOOP_MESSAGEBOX = 6
CYCLE_INNERLOOP_MESSAGEBOX = 6,
CYCLE_INNERLOOP_HAVEKEY = 7
};

enum State {
Expand Down Expand Up @@ -817,7 +818,7 @@ class AgiEngine : public AgiBase {
public:
void decrypt(uint8 *mem, int len);
void releaseSprites();
int mainCycle(bool onlyCheckForEvents = false);
uint16 processAGIEvents(bool doDelay = true);
int viewPictures();
int runGame();
int getAppDir(char *appDir, unsigned int size);
Expand All @@ -831,7 +832,7 @@ class AgiEngine : public AgiBase {
int playGame();

void allowSynthetic(bool);
void processEvents();
void processScummVMEvents();
void checkQuickLoad();

// Objects
Expand Down
32 changes: 13 additions & 19 deletions engines/agi/cycle.cpp
Expand Up @@ -173,12 +173,12 @@ void AgiEngine::interpretCycle() {
//_gfx->doUpdate();
}

// If main_cycle returns false, don't process more events!
int AgiEngine::mainCycle(bool onlyCheckForEvents) {
// We return the current key, or 0 if no key was pressed
uint16 AgiEngine::processAGIEvents(bool doDelay) {
uint16 key;
ScreenObjEntry *screenObjEgo = &_game.screenObjTable[SCREENOBJECTS_EGO_ENTRY];

if (!onlyCheckForEvents) {
if (doDelay) {
pollTimer();
}

Expand All @@ -188,10 +188,8 @@ int AgiEngine::mainCycle(bool onlyCheckForEvents) {
// vars in every interpreter cycle.
//
// We run AGIMOUSE always as a side effect
//if (getFeatures() & GF_AGIMOUSE) {
setVar(VM_VAR_MOUSE_X, _mouse.pos.x / 2);
setVar(VM_VAR_MOUSE_Y, _mouse.pos.y);
//}
setVar(VM_VAR_MOUSE_X, _mouse.pos.x / 2);
setVar(VM_VAR_MOUSE_Y, _mouse.pos.y);

if (!cycleInnerLoopIsActive()) {
// Click-to-walk mouse interface
Expand Down Expand Up @@ -234,6 +232,10 @@ int AgiEngine::mainCycle(bool onlyCheckForEvents) {
}
}

if (_menu->delayedExecuteActive()) {
_menu->execute();
}

} else {
// inner loop active
// call specific workers
Expand All @@ -255,11 +257,11 @@ int AgiEngine::mainCycle(bool onlyCheckForEvents) {
if (key) {
_menu->keyPress(key);
}
return false;
break;

case CYCLE_INNERLOOP_MENU_VIA_MOUSE:
_menu->mouseEvent(key);
return false;
break;

case CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT:
if (key) {
Expand All @@ -278,15 +280,9 @@ int AgiEngine::mainCycle(bool onlyCheckForEvents) {
}
}

if (!onlyCheckForEvents) {
if (_menu->delayedExecuteActive()) {
_menu->execute();
}
}

_gfx->updateScreen();

return true;
return key;
}

int AgiEngine::playGame() {
Expand Down Expand Up @@ -341,9 +337,7 @@ int AgiEngine::playGame() {
nonBlockingText_Forget();

do {

if (!mainCycle())
continue;
processAGIEvents();

inGameTimerUpdate();

Expand Down
2 changes: 1 addition & 1 deletion engines/agi/inv.cpp
Expand Up @@ -148,7 +148,7 @@ void InventoryMgr::show() {
_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_INVENTORY);

do {
_vm->mainCycle();
_vm->processAGIEvents();
} while (_vm->cycleInnerLoopIsActive() && !(_vm->shouldQuit() || _vm->_restartGame));

if (_activeItemNr >= 0) {
Expand Down
4 changes: 2 additions & 2 deletions engines/agi/keyboard.cpp
Expand Up @@ -62,7 +62,7 @@ const uint8 scancodeTable[26] = {
44 // Z
};

void AgiEngine::processEvents() {
void AgiEngine::processScummVMEvents() {
Common::Event event;
int key = 0;

Expand Down Expand Up @@ -569,7 +569,7 @@ int AgiEngine::waitAnyKey() {
}

bool AgiEngine::isKeypress() {
processEvents();
processScummVMEvents();
return _keyQueueStart != _keyQueueEnd;
}

Expand Down
2 changes: 1 addition & 1 deletion engines/agi/menu.cpp
Expand Up @@ -331,7 +331,7 @@ void GfxMenu::execute() {
}

do {
_vm->mainCycle();
_vm->processAGIEvents();
} while (_vm->cycleInnerLoopIsActive() && !(_vm->shouldQuit() || _vm->_restartGame));

if (_drawnMenuNr >= 0) {
Expand Down
8 changes: 5 additions & 3 deletions engines/agi/op_test.cpp
Expand Up @@ -120,19 +120,21 @@ void condController(AgiGame *state, AgiEngine *vm, uint8 *p) {
}

void condHaveKey(AgiGame *state, AgiEngine *vm, uint8 *p) {
// Only check for key when there is not already one set by scripts
if (vm->getVar(VM_VAR_KEY)) {
state->testResult = 1;
return;
}
// Only check for key when there is not already one set by scripts
uint16 key = vm->doPollKeyboard();
// we are not really an inner loop, but we stop processAGIEvents() from doing regular cycle work by setting it up
vm->cycleInnerLoopActive(CYCLE_INNERLOOP_HAVEKEY);
uint16 key = vm->processAGIEvents(false); // also no delay
vm->cycleInnerLoopInactive();
if (key) {
debugC(5, kDebugLevelScripts | kDebugLevelInput, "keypress = %02x", key);
vm->setVar(VM_VAR_KEY, key);
state->testResult = 1;
return;
}
vm->_gfx->updateScreen(); // TODO: Solve this in a better way
state->testResult = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion engines/agi/systemui.cpp
Expand Up @@ -287,7 +287,7 @@ int16 SystemUI::askForSavedGameSlot(const char *slotListText) {

_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT);
do {
_vm->mainCycle();
_vm->processAGIEvents();
} while (_vm->cycleInnerLoopIsActive() && !(_vm->shouldQuit() || _vm->_restartGame));

_text->closeWindow();
Expand Down
4 changes: 2 additions & 2 deletions engines/agi/text.cpp
Expand Up @@ -360,7 +360,7 @@ bool TextMgr::messageBox(const char *textPtr) {
_vm->inGameTimerResetPassedCycles();
_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_MESSAGEBOX);
do {
_vm->mainCycle();
_vm->processAGIEvents();
_vm->inGameTimerUpdate();

if (windowTimer > 0) {
Expand Down Expand Up @@ -786,7 +786,7 @@ void TextMgr::stringEdit(int16 stringMaxLen) {
inputEditOff();

do {
_vm->mainCycle();
_vm->processAGIEvents();
} while (_vm->cycleInnerLoopIsActive() && !(_vm->shouldQuit() || _vm->_restartGame));

inputEditOn();
Expand Down

0 comments on commit 778c1dd

Please sign in to comment.