aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2012-05-09 23:15:41 +1000
committerPaul Gilbert2012-05-09 23:15:41 +1000
commit5a069cdc861538fe763de48de8628d7d754f7959 (patch)
tree7f8739b2e82bdc1b6792e9f3de1a4e24beae2bd3
parent26898dd7ad399a641f63eabf04aa2d839f8508fc (diff)
downloadscummvm-rg350-5a069cdc861538fe763de48de8628d7d754f7959.tar.gz
scummvm-rg350-5a069cdc861538fe763de48de8628d7d754f7959.tar.bz2
scummvm-rg350-5a069cdc861538fe763de48de8628d7d754f7959.zip
TONY: Refactored out usage of nullContext in favour of proper coroutines
-rw-r--r--engines/tony/adv.h4
-rw-r--r--engines/tony/custom.cpp34
-rw-r--r--engines/tony/font.cpp16
-rw-r--r--engines/tony/game.cpp170
-rw-r--r--engines/tony/game.h2
-rw-r--r--engines/tony/gfxengine.cpp206
-rw-r--r--engines/tony/gfxengine.h6
-rw-r--r--engines/tony/loc.cpp4
-rw-r--r--engines/tony/mpal/mpal.cpp368
-rw-r--r--engines/tony/mpal/mpal.h59
-rw-r--r--engines/tony/mpal/stubs.h3
-rw-r--r--engines/tony/sound.cpp6
-rw-r--r--engines/tony/tony.cpp77
-rw-r--r--engines/tony/tony.h3
-rw-r--r--engines/tony/tonychar.cpp37
-rw-r--r--engines/tony/window.cpp8
16 files changed, 601 insertions, 402 deletions
diff --git a/engines/tony/adv.h b/engines/tony/adv.h
index 22205cf05b..a1b21c1e08 100644
--- a/engines/tony/adv.h
+++ b/engines/tony/adv.h
@@ -91,8 +91,8 @@ enum RMTonyAction {
};
// Funzioni globali
-HANDLE MainLoadLocation(int nLoc, RMPoint pt, RMPoint start);
-void MainUnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result);
+uint32 MainLoadLocation(int nLoc, RMPoint pt, RMPoint start);
+void MainUnloadLocation(CORO_PARAM, bool bDoOnExit, uint32 *result);
void MainLinkGraphicTask(RMGfxTask *task);
void MainFreeze(void);
void MainUnfreeze(void);
diff --git a/engines/tony/custom.cpp b/engines/tony/custom.cpp
index 9d46d7e6b7..150e199fc8 100644
--- a/engines/tony/custom.cpp
+++ b/engines/tony/custom.cpp
@@ -72,8 +72,8 @@ RMLocation *Loc;
RMInventory *Inventory;
RMInput *Input;
-HANDLE (*LoadLocation)(int, RMPoint, RMPoint start);
-void (*UnloadLocation)(CORO_PARAM, bool bDoOnExit, HANDLE *result);
+uint32 (*LoadLocation)(int, RMPoint, RMPoint start);
+void (*UnloadLocation)(CORO_PARAM, bool bDoOnExit, uint32 *result);
void (*LinkGraphicTask)(RMGfxTask *task);
void (*Freeze)(void);
void (*Unfreeze)(void);
@@ -521,7 +521,7 @@ DECLARE_CUSTOM_FUNCTION(CustLoadLocation)(CORO_PARAM, uint32 nLoc, uint32 tX, ui
LoadLocation(nLoc, RMPoint(tX, tY), RMPoint(-1, -1));
Unfreeze();
- _ctx->h = mpalQueryDoActionU32(0, nLoc, 0);
+ _ctx->h = mpalQueryDoAction(0, nLoc, 0);
// On Enter?
if (_ctx->h != INVALID_PID_VALUE)
@@ -698,7 +698,7 @@ DECLARE_CUSTOM_FUNCTION(ChangeLocation)(CORO_PARAM, uint32 nLoc, uint32 tX, uint
Unfreeze();
- _ctx->h = mpalQueryDoActionU32(0, nLoc, 0);
+ _ctx->h = mpalQueryDoAction(0, nLoc, 0);
if (!bNoOcchioDiBue) {
CORO_INVOKE_0(WaitWipeEnd);
@@ -1842,7 +1842,7 @@ DECLARE_CUSTOM_FUNCTION(MCharSendMessage)(CORO_PARAM, uint32 nChar, uint32 dwMes
// Cerca di eseguire la funzione custom per inizializzare la parlata
if (MCharacter[nChar].item) {
- _ctx->h = mpalQueryDoActionU32(30, MCharacter[nChar].item->MpalCode(), _ctx->parm);
+ _ctx->h = mpalQueryDoAction(30, MCharacter[nChar].item->MpalCode(), _ctx->parm);
if (_ctx->h != INVALID_PID_VALUE) {
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
}
@@ -1923,7 +1923,7 @@ DECLARE_CUSTOM_FUNCTION(MCharSendMessage)(CORO_PARAM, uint32 nChar, uint32 dwMes
// Cerca di eseguire la funzione custom per chiudere la parlata
if (MCharacter[nChar].item) {
- _ctx->h = mpalQueryDoActionU32(31, MCharacter[nChar].item->MpalCode(), _ctx->parm);
+ _ctx->h = mpalQueryDoAction(31, MCharacter[nChar].item->MpalCode(), _ctx->parm);
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
}
@@ -2034,7 +2034,7 @@ DECLARE_CUSTOM_FUNCTION(SendDialogMessage)(CORO_PARAM, uint32 nPers, uint32 nMsg
MCharacter[nPers].numtexts--;
} else {
// Cerca di eseguire la funzione custom per inizializzare la parlata
- _ctx->h = mpalQueryDoActionU32(30, MCharacter[nPers].item->MpalCode(), _ctx->parm);
+ _ctx->h = mpalQueryDoAction(30, MCharacter[nPers].item->MpalCode(), _ctx->parm);
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
@@ -2098,7 +2098,7 @@ DECLARE_CUSTOM_FUNCTION(SendDialogMessage)(CORO_PARAM, uint32 nPers, uint32 nMsg
if ((MCharacter[nPers].bInTexts && MCharacter[nPers].numtexts== 0) || !MCharacter[nPers].bInTexts) {
// Cerca di eseguire la funzione custom per chiudere la parlata
MCharacter[nPers].curTalk = (MCharacter[nPers].curTalk%10) + MCharacter[nPers].curgroup*10;
- _ctx->h = mpalQueryDoActionU32(31,MCharacter[nPers].item->MpalCode(),MCharacter[nPers].curTalk);
+ _ctx->h = mpalQueryDoAction(31,MCharacter[nPers].item->MpalCode(),MCharacter[nPers].curTalk);
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
@@ -2142,7 +2142,7 @@ DECLARE_CUSTOM_FUNCTION(StartDialog)(CORO_PARAM, uint32 nDialog, uint32 nStartGr
curDialog = nDialog;
// Call MPAL to start the dialog
- mpalQueryDoDialogU32(nDialog, nStartGroup);
+ mpalQueryDoDialog(nDialog, nStartGroup);
// Wait until a choice is selected
mpalQueryDialogWaitForChoice(&_ctx->nChoice);
@@ -2154,7 +2154,7 @@ DECLARE_CUSTOM_FUNCTION(StartDialog)(CORO_PARAM, uint32 nDialog, uint32 nStartGr
// Se c'e' una sola opzione, la fa automaticamente, e aspetta la prossima scelta
if (_ctx->num == 1) {
- mpalQueryDialogSelectionU32(_ctx->nChoice, _ctx->sl[0]);
+ mpalQueryDialogSelection(_ctx->nChoice, _ctx->sl[0]);
GlobalFree(_ctx->sl);
continue;
}
@@ -2190,7 +2190,7 @@ DECLARE_CUSTOM_FUNCTION(StartDialog)(CORO_PARAM, uint32 nDialog, uint32 nStartGr
MainHideMouse();
CORO_INVOKE_0(_ctx->dc.Hide);
- mpalQueryDialogSelectionU32(_ctx->nChoice, _ctx->sl[_ctx->sel]);
+ mpalQueryDialogSelection(_ctx->nChoice, _ctx->sl[_ctx->sel]);
// Chiude la scelta
_ctx->dc.Close();
@@ -2501,10 +2501,18 @@ DECLARE_CUSTOM_FUNCTION(PlayItemSfx)(CORO_PARAM, uint32 nItem, uint32 nSFX, uint
}
-void RestoreMusic(void) {
- PlaySonoriz(nullContext, lastMusic, 0, 0, 0);
+void RestoreMusic(CORO_PARAM) {
+ CORO_BEGIN_CONTEXT;
+ CORO_END_CONTEXT(_ctx);
+
+ CORO_BEGIN_CODE(_ctx);
+
+ CORO_INVOKE_4(PlaySonoriz, lastMusic, 0, 0, 0);
+
if (lastTappeto != 0)
CustPlayMusic(4, tappetiFile[lastTappeto], 0, true);
+
+ CORO_END_CODE;
}
void SaveMusic(Common::OutSaveFile *f) {
diff --git a/engines/tony/font.cpp b/engines/tony/font.cpp
index d04e1f0a13..5dbbd3f71f 100644
--- a/engines/tony/font.cpp
+++ b/engines/tony/font.cpp
@@ -2236,7 +2236,7 @@ void RMTextDialogScrolling::ClipOnScreen(RMGfxPrimitive *prim) {
/****************************************************************************\
-* Metodi di RMTextItemName
+* RMTextItemName Methods
\****************************************************************************/
RMTextItemName::RMTextItemName() : RMText() {
@@ -2259,14 +2259,14 @@ void RMTextItemName::DoFrame(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMLocation &
_ctx->lastItem = m_item;
- // Si aggiunge alla lista se c'e' bisogno
+ // Adds to the list if there is need
if (!m_nInList)
bigBuf.AddPrim(new RMGfxPrimitive(this));
- // Aggiorna le coordinate di scrolling
+ // Update the scrolling co-ordinates
m_curscroll = loc.ScrollPosition();
- // Controlla se siamo sopra l'inventario
+ // Check if we are on the inventory
if (inv.ItemInFocus(m_mpos))
m_item = inv.WhichItemIsIn(m_mpos);
else
@@ -2274,19 +2274,19 @@ void RMTextItemName::DoFrame(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMLocation &
_ctx->itemName = "";
- // Si fa dare il nuovo nome
+ // If there an item, get it's name
if (m_item != NULL)
m_item->GetName(_ctx->itemName);
- // Se lo scrive
+ // Write it
WriteText(_ctx->itemName, 1);
- // Se e' diverso dal precedente, e' il caso di aggiornare anche il puntatore con la WhichPointer
+ // Handle the change If the selected item is different from the previous one
if (_ctx->lastItem != m_item) {
if (m_item == NULL)
ptr.SetSpecialPointer(RMPointer::PTR_NONE);
else {
- _ctx->hThread = mpalQueryDoActionU32(20, m_item->MpalCode(), 0);
+ _ctx->hThread = mpalQueryDoAction(20, m_item->MpalCode(), 0);
if (_ctx->hThread == INVALID_PID_VALUE)
ptr.SetSpecialPointer(RMPointer::PTR_NONE);
else
diff --git a/engines/tony/game.cpp b/engines/tony/game.cpp
index 59196ec18a..377ec73673 100644
--- a/engines/tony/game.cpp
+++ b/engines/tony/game.cpp
@@ -92,11 +92,11 @@ bool bPatIrqFreeze;
/* Funzioni globali per la DLL Custom */
/****************************************/
-HANDLE MainLoadLocation(int nLoc, RMPoint pt, RMPoint start) {
+uint32 MainLoadLocation(int nLoc, RMPoint pt, RMPoint start) {
return _vm->GetEngine()->LoadLocation(nLoc, pt,start);
}
-void MainUnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result) {
+void MainUnloadLocation(CORO_PARAM, bool bDoOnExit, uint32 *result) {
_vm->GetEngine()->UnloadLocation(coroParam, bDoOnExit, result);
}
@@ -934,110 +934,110 @@ void RMOptionScreen::ChangeState(STATE newState) {
InitState();
}
-void RMOptionScreen::DoFrame(RMInput *input) {
- bool bLeftClick, bRightClick;
- RMPoint mousePos;
- bool bRefresh;
- int i;
+void RMOptionScreen::DoFrame(CORO_PARAM, RMInput *input) {
+ CORO_BEGIN_CONTEXT;
+ bool bLeftClick, bRightClick;
+ RMPoint mousePos;
+ bool bRefresh;
+ int i;
+ CORO_END_CONTEXT(_ctx);
+
+ CORO_BEGIN_CODE(_ctx);
+
// Se non è completamente aperto, non fare nulla
if (m_FadeStep != 6)
return;
// Legge l'input
- mousePos = input->MousePos();
- bLeftClick = input->MouseLeftClicked();
- bRightClick = input->MouseRightClicked();
+ _ctx->mousePos = input->MousePos();
+ _ctx->bLeftClick = input->MouseLeftClicked();
+ _ctx->bRightClick = input->MouseRightClicked();
- bRefresh = false;
+ _ctx->bRefresh = false;
if (m_bQuitConfirm) {
- bRefresh |= m_ButtonQuitYes->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonQuitNo->DoFrame(mousePos, bLeftClick, bRightClick);
+ _ctx->bRefresh |= m_ButtonQuitYes->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonQuitNo->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
} else {
- bRefresh |= m_ButtonExit->DoFrame(mousePos, bLeftClick, bRightClick);
+ _ctx->bRefresh |= m_ButtonExit->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
// Controlla se ha clickato sull'uscita
if (m_nState == MENUGAME || m_nState == MENUGFX || m_nState == MENUSOUND) {
// bottoni senza grafica...
- m_ButtonGameMenu->DoFrame(mousePos, bLeftClick, bRightClick);
- m_ButtonGfxMenu->DoFrame(mousePos, bLeftClick, bRightClick);
- m_ButtonSoundMenu->DoFrame(mousePos, bLeftClick, bRightClick);
+ m_ButtonGameMenu->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ m_ButtonGfxMenu->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ m_ButtonSoundMenu->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
// bottoni con grafica
if (!m_bNoLoadSave) {
if (!_vm->getIsDemo()) {
- bRefresh |= m_ButtonLoad->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonSave->DoFrame(mousePos, bLeftClick, bRightClick);
+ _ctx->bRefresh |= m_ButtonLoad->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonSave->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
}
- bRefresh |= m_ButtonQuit->DoFrame(mousePos, bLeftClick, bRightClick);
+ _ctx->bRefresh |= m_ButtonQuit->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
}
}
- switch (m_nState) {
- case MENUGAME:
- bRefresh |= m_ButtonGame_Lock->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonGame_TimerizedText->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonGame_Scrolling->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonGame_InterUp->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_SlideTextSpeed->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_SlideTonySpeed->DoFrame(mousePos, bLeftClick, bRightClick);
- break;
-
- case MENUGFX:
- bRefresh |= m_ButtonGfx_Anni30->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonGfx_AntiAlias->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonGfx_Sottotitoli->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonGfx_Tips->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonGfx_Trans->DoFrame(mousePos, bLeftClick, bRightClick);
- break;
-
- case MENUSOUND:
- bRefresh |= m_SliderSound_Dubbing->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_SliderSound_Music->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_SliderSound_SFX->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonSound_DubbingOn->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonSound_MusicOn->DoFrame(mousePos, bLeftClick, bRightClick);
- bRefresh |= m_ButtonSound_SFXOn->DoFrame(mousePos, bLeftClick, bRightClick);
- break;
-
- case MENULOAD:
- case MENUSAVE:
- for (i=0;i<6;i++)
- m_ButtonSave_States[i]->DoFrame(mousePos, bLeftClick, bRightClick);
+ if (m_nState == MENUGAME) {
+ _ctx->bRefresh |= m_ButtonGame_Lock->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonGame_TimerizedText->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonGame_Scrolling->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonGame_InterUp->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_SlideTextSpeed->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_SlideTonySpeed->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+
+ } else if (m_nState == MENUGFX) {
+ _ctx->bRefresh |= m_ButtonGfx_Anni30->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonGfx_AntiAlias->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonGfx_Sottotitoli->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonGfx_Tips->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonGfx_Trans->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+
+ } else if (m_nState == MENUSOUND) {
+ _ctx->bRefresh |= m_SliderSound_Dubbing->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_SliderSound_Music->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_SliderSound_SFX->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonSound_DubbingOn->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonSound_MusicOn->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+ _ctx->bRefresh |= m_ButtonSound_SFXOn->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+
+ } else if (m_nState == MENULOAD || m_nState == MENUSAVE) {
+ for (_ctx->i=0;_ctx->i<6;_ctx->i++)
+ m_ButtonSave_States[_ctx->i]->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
if (m_statePos > 0)
- bRefresh |= m_ButtonSave_ArrowLeft->DoFrame(mousePos, bLeftClick, bRightClick);
+ _ctx->bRefresh |= m_ButtonSave_ArrowLeft->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
if (m_statePos < 90)
- bRefresh |= m_ButtonSave_ArrowRight->DoFrame(mousePos, bLeftClick, bRightClick);
- break;
+ _ctx->bRefresh |= m_ButtonSave_ArrowRight->DoFrame(_ctx->mousePos, _ctx->bLeftClick, _ctx->bRightClick);
+
}
}
#define KEYPRESS(c) ((GetAsyncKeyState(c)&0x8001)==0x8001)
#define PROCESS_CHAR(cod,c) if (KEYPRESS(cod)) { \
- m_EditName[strlen(m_EditName) +1 ] = '\0'; m_EditName[strlen(m_EditName)] = c; bRefresh = true; }
+ m_EditName[strlen(m_EditName) +1 ] = '\0'; m_EditName[strlen(m_EditName)] = c; _ctx->bRefresh = true; }
/**************** STATO BOTTONI **************/
if (m_bEditSaveName) {
if (KEYPRESS(Common::KEYCODE_BACKSPACE)) {
if (m_EditName[0] != '\0') {
m_EditName[strlen(m_EditName) - 1] = '\0';
- bRefresh = true;
+ _ctx->bRefresh = true;
}
}
- for (i=0;i<26 && strlen(m_EditName)<12;i++)
+ for (_ctx->i=0;_ctx->i<26 && strlen(m_EditName)<12;_ctx->i++)
if ((GetAsyncKeyState(Common::KEYCODE_LSHIFT) & 0x8000) ||
(GetAsyncKeyState(Common::KEYCODE_RSHIFT) & 0x8000)) {
- PROCESS_CHAR((Common::KeyCode)((int)'a' + i), i + 'A');
+ PROCESS_CHAR((Common::KeyCode)((int)'a' + _ctx->i), _ctx->i + 'A');
} else {
- PROCESS_CHAR((Common::KeyCode)((int)'a' + i), i + 'a');
+ PROCESS_CHAR((Common::KeyCode)((int)'a' + _ctx->i), _ctx->i + 'a');
}
- for (i = 0; i < 10 && strlen(m_EditName) < 12; i++)
- PROCESS_CHAR((Common::KeyCode)((int)'0' + i), i + '0');
+ for (_ctx->i = 0; _ctx->i < 10 && strlen(m_EditName) < 12; _ctx->i++)
+ PROCESS_CHAR((Common::KeyCode)((int)'0' + _ctx->i), _ctx->i + '0');
if (strlen(m_EditName) < 12)
PROCESS_CHAR(Common::KEYCODE_SPACE,' ');
@@ -1056,7 +1056,7 @@ void RMOptionScreen::DoFrame(RMInput *input) {
// ANNULLA
if (KEYPRESS(Common::KEYCODE_ESCAPE)) {
m_bEditSaveName = false;
- bRefresh = true;
+ _ctx->bRefresh = true;
}
// OK
@@ -1066,7 +1066,7 @@ void RMOptionScreen::DoFrame(RMInput *input) {
Close();
}
- } else if (bLeftClick) {
+ } else if (_ctx->bLeftClick) {
if (m_nState == MENULOAD || m_nState == MENUSAVE) {
if (m_ButtonExit->IsActive()) {
if (m_bLoadMenuOnly) {
@@ -1074,14 +1074,14 @@ void RMOptionScreen::DoFrame(RMInput *input) {
Close();
} else {
ChangeState(m_nLastState);
- bRefresh = true;
+ _ctx->bRefresh = true;
}
} else if (m_ButtonSave_ArrowLeft->IsActive()) {
if (m_statePos > 0) {
m_statePos -= 6;
if (m_statePos < 0) m_statePos = 0;
m_ButtonSave_ArrowLeft->SetActiveState(false);
- bRefresh = true;
+ _ctx->bRefresh = true;
RefreshThumbnails();
}
} else if (m_ButtonSave_ArrowRight->IsActive()) {
@@ -1089,25 +1089,25 @@ void RMOptionScreen::DoFrame(RMInput *input) {
m_statePos += 6;
if (m_statePos > 90) m_statePos = 90;
m_ButtonSave_ArrowRight->SetActiveState(false);
- bRefresh = true;
+ _ctx->bRefresh = true;
RefreshThumbnails();
}
} else {
- for (i = 0; i < 6; i++)
- if (m_ButtonSave_States[i]->IsActive()) {
+ for (_ctx->i = 0; _ctx->i < 6; _ctx->i++)
+ if (m_ButtonSave_States[_ctx->i]->IsActive()) {
// C'è da effettuare il salvataggio o il caricamento!!!!
- if (m_nState == MENULOAD && m_curThumb[i] != NULL) {
+ if (m_nState == MENULOAD && m_curThumb[_ctx->i] != NULL) {
// Caricamento
- _vm->LoadState(m_statePos+i);
+ CORO_INVOKE_1(_vm->LoadState, m_statePos+_ctx->i);
Close();
- } else if (m_nState == MENUSAVE && (m_statePos != 0 || i != 0)) {
+ } else if (m_nState == MENUSAVE && (m_statePos != 0 || _ctx->i != 0)) {
// Attiva la modalità di editing
m_bEditSaveName = true;
- m_nEditPos = i;
- strcpy(m_EditName, m_curThumbName[i]);
- bRefresh = true;
+ m_nEditPos = _ctx->i;
+ strcpy(m_EditName, m_curThumbName[_ctx->i]);
+ _ctx->bRefresh = true;
- //_vm->SaveState(m_statePos+i,"No name");
+ //_vm->SaveState(m_statePos+_ctx->i,"No name");
//Close();
}
@@ -1120,10 +1120,10 @@ void RMOptionScreen::DoFrame(RMInput *input) {
if (m_bQuitConfirm) {
if (m_ButtonQuitNo->IsActive()) {
m_bQuitConfirm = false;
- bRefresh = true;
+ _ctx->bRefresh = true;
} else if (m_ButtonQuitYes->IsActive()) {
m_bQuitConfirm = false;
- bRefresh = true;
+ _ctx->bRefresh = true;
_vm->Quit();
}
@@ -1132,24 +1132,24 @@ void RMOptionScreen::DoFrame(RMInput *input) {
m_bQuitConfirm = true;
m_ButtonQuitNo->SetActiveState(false);
m_ButtonQuitYes->SetActiveState(false);
- bRefresh = true;
+ _ctx->bRefresh = true;
} else if (m_ButtonExit->IsActive())
Close();
else if (m_ButtonLoad->IsActive()) {
ChangeState(MENULOAD);
- bRefresh = true;
+ _ctx->bRefresh = true;
} else if (m_ButtonSave->IsActive()) {
ChangeState(MENUSAVE);
- bRefresh = true;
+ _ctx->bRefresh = true;
} else if (m_ButtonGameMenu->IsActive() && m_nState != MENUGAME) {
ChangeState(MENUGAME);
- bRefresh = true;
+ _ctx->bRefresh = true;
} else if (m_ButtonGfxMenu->IsActive() && m_nState != MENUGFX) {
ChangeState(MENUGFX);
- bRefresh = true;
+ _ctx->bRefresh = true;
} else if (m_ButtonSoundMenu->IsActive() && m_nState != MENUSOUND) {
ChangeState(MENUSOUND);
- bRefresh = true;
+ _ctx->bRefresh = true;
}
if (m_nState == MENUGFX) {
@@ -1177,8 +1177,10 @@ void RMOptionScreen::DoFrame(RMInput *input) {
if (!m_bQuitConfirm && KEYPRESS(Common::KEYCODE_ESCAPE))
Close();
- if (bRefresh)
+ if (_ctx->bRefresh)
RefreshAll();
+
+ CORO_END_CODE;
}
diff --git a/engines/tony/game.h b/engines/tony/game.h
index 593203e443..55fed71380 100644
--- a/engines/tony/game.h
+++ b/engines/tony/game.h
@@ -300,7 +300,7 @@ public:
bool RemoveThis();
// Polling per l'option screen
- void DoFrame(RMInput *m_input);
+ void DoFrame(CORO_PARAM, RMInput *m_input);
protected:
diff --git a/engines/tony/gfxengine.cpp b/engines/tony/gfxengine.cpp
index 12de3573eb..3952d0c227 100644
--- a/engines/tony/gfxengine.cpp
+++ b/engines/tony/gfxengine.cpp
@@ -165,7 +165,7 @@ void RMGfxEngine::DoFrame(CORO_PARAM, bool bDrawLocation) {
}
if (m_bOption) {
- m_opt.DoFrame(&m_input);
+ CORO_INVOKE_1(m_opt.DoFrame, &m_input);
m_bOption = !m_opt.IsClosing();
if (!m_bOption) {
DisableMouse();
@@ -220,15 +220,15 @@ void RMGfxEngine::DoFrame(CORO_PARAM, bool bDrawLocation) {
if (m_bGUIOption) {
if (!m_tony.InAction() && m_bInput) {
if ((m_input.MouseLeftClicked() && m_input.MousePos().x < 3 && m_input.MousePos().y < 3)) {
- OpenOptionScreen(nullContext, 0);
+ CORO_INVOKE_1(OpenOptionScreen, 0);
goto SKIPCLICKSINISTRO;
} else if ((GetAsyncKeyState(Common::KEYCODE_ESCAPE)&0x8001) == 0x8001)
- OpenOptionScreen(nullContext, 0);
+ CORO_INVOKE_1(OpenOptionScreen, 0);
else if (_vm->getIsDemo()) {
if ((GetAsyncKeyState(Common::KEYCODE_F3) & 0x8001) == 0x8001)
- OpenOptionScreen(nullContext, 3);
+ CORO_INVOKE_1(OpenOptionScreen, 3);
else if ((GetAsyncKeyState(Common::KEYCODE_F2) & 0x8001) == 0x8001)
- OpenOptionScreen(nullContext, 4);
+ CORO_INVOKE_1(OpenOptionScreen, 4);
}
}
}
@@ -494,7 +494,7 @@ void RMGfxEngine::InitForNewLocation(int nLoc, RMPoint ptTonyStart, RMPoint star
mpalStartIdlePoll(m_nCurLoc);
}
-HANDLE RMGfxEngine::LoadLocation(int nLoc, RMPoint ptTonyStart, RMPoint start) {
+uint32 RMGfxEngine::LoadLocation(int nLoc, RMPoint ptTonyStart, RMPoint start) {
bool bLoaded;
int i;
@@ -529,10 +529,10 @@ HANDLE RMGfxEngine::LoadLocation(int nLoc, RMPoint ptTonyStart, RMPoint start) {
m_bLocationLoaded = true;
// On Enter per la locazion
- return INVALID_HANDLE_VALUE; //mpalQueryDoAction(0,m_nCurLoc,0);
+ return INVALID_PID_VALUE; //mpalQueryDoAction(0,m_nCurLoc,0);
}
-void RMGfxEngine::UnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result) {
+void RMGfxEngine::UnloadLocation(CORO_PARAM, bool bDoOnExit, uint32 *result) {
CORO_BEGIN_CONTEXT;
uint32 h;
CORO_END_CONTEXT(_ctx);
@@ -544,7 +544,7 @@ void RMGfxEngine::UnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result) {
// On Exit?
if (bDoOnExit) {
- _ctx->h = mpalQueryDoActionU32(1, m_nCurLoc, 0);
+ _ctx->h = mpalQueryDoAction(1, m_nCurLoc, 0);
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
}
@@ -557,7 +557,7 @@ void RMGfxEngine::UnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result) {
m_loc.Unload();
if (result != NULL)
- *result = INVALID_HANDLE_VALUE;
+ *result = INVALID_PID_VALUE;
CORO_END_CODE;
}
@@ -707,7 +707,7 @@ void SaveChangedHotspot(Common::OutSaveFile *f);
void LoadChangedHotspot(Common::InSaveFile *f);
void ReapplyChangedHotspot(void);
-void RestoreMusic(void);
+void RestoreMusic(CORO_PARAM);
void SaveMusic(Common::OutSaveFile *f);
void LoadMusic(Common::InSaveFile *f);
@@ -827,153 +827,159 @@ void RMGfxEngine::SaveState(const char *fn, byte *curThumb, const char *name, bo
delete f;
}
-void RMGfxEngine::LoadState(const char *fn) {
+void RMGfxEngine::LoadState(CORO_PARAM, const char *fn) {
// PROBLEMA: Bisognerebbe caricare la locazione in un thread a parte per fare la OnEnter ...
- Common::InSaveFile *f;
- byte *state, *statecmp;
- uint size, sizecmp;
- char buf[4];
- RMPoint tp;
- int loc;
- int ver;
- int i;
+ CORO_BEGIN_CONTEXT;
+ Common::InSaveFile *f;
+ byte *state, *statecmp;
+ uint size, sizecmp;
+ char buf[4];
+ RMPoint tp;
+ int loc;
+ int ver;
+ int i;
+ CORO_END_CONTEXT(_ctx);
+
+ CORO_BEGIN_CODE(_ctx);
- f = g_system->getSavefileManager()->openForLoading(fn);
- if (f == NULL) return;
- f->read(buf, 4);
- if (buf[0] != 'R' || buf[1] != 'M' || buf[2] != 'S') {
- delete f;
+ _ctx->f = g_system->getSavefileManager()->openForLoading(fn);
+ if (_ctx->f == NULL) return;
+ _ctx->f->read(_ctx->buf, 4);
+ if (_ctx->buf[0] != 'R' || _ctx->buf[1] != 'M' || _ctx->buf[2] != 'S') {
+ delete _ctx->f;
return;
}
- ver = buf[3];
+ _ctx->ver = _ctx->buf[3];
- if (ver != 0x1 && ver != 0x2 && ver != 0x3 && ver != 0x4 && ver != 0x5 && ver != 0x6 && ver != 0x7) {
- delete f;
+ if (_ctx->ver != 0x1 && _ctx->ver != 0x2 && _ctx->ver != 0x3 && _ctx->ver != 0x4 && _ctx->ver != 0x5 && _ctx->ver != 0x6 && _ctx->ver != 0x7) {
+ delete _ctx->f;
return;
}
- if (ver >= 0x3) {
- // C'è il thumbnail. Se ver >= 5, è compresso
- if (ver >= 0x5) {
- i = 0;
- i = f->readUint32LE();
- f->seek(i);
+ if (_ctx->ver >= 0x3) {
+ // C'è il thumbnail. Se _ctx->ver >= 5, è compresso
+ if (_ctx->ver >= 0x5) {
+ _ctx->i = 0;
+ _ctx->i = _ctx->f->readUint32LE();
+ _ctx->f->seek(_ctx->i);
} else
- f->seek(160 * 120 * 2, SEEK_CUR);
+ _ctx->f->seek(160 * 120 * 2, SEEK_CUR);
}
- if (ver >= 0x5) {
+ if (_ctx->ver >= 0x5) {
// Skip del livello di difficoltà
- f->seek(1, SEEK_CUR);
+ _ctx->f->seek(1, SEEK_CUR);
}
- if (ver >= 0x4) { // Skippa il nome, che non serve a nessuno
- i = f->readByte();
- f->seek(i, SEEK_CUR);
+ if (_ctx->ver >= 0x4) { // Skippa il nome, che non serve a nessuno
+ _ctx->i = _ctx->f->readByte();
+ _ctx->f->seek(_ctx->i, SEEK_CUR);
}
- loc = f->readUint32LE();
- loc = f->readUint32LE();
- tp.x = f->readUint32LE();
- tp.y = f->readUint32LE();
- size = f->readUint32LE();
+ _ctx->loc = _ctx->f->readUint32LE();
+ _ctx->loc = _ctx->f->readUint32LE();
+ _ctx->tp.x = _ctx->f->readUint32LE();
+ _ctx->tp.y = _ctx->f->readUint32LE();
+ _ctx->size = _ctx->f->readUint32LE();
- if (ver >= 0x5) {
+ if (_ctx->ver >= 0x5) {
// Stato MPAL compresso!
- sizecmp = f->readUint32LE();
- state = new byte[size];
- statecmp = new byte[sizecmp];
- f->read(statecmp, sizecmp);
- lzo1x_decompress(statecmp,sizecmp,state,&size);
- delete[] statecmp;
+ _ctx->sizecmp = _ctx->f->readUint32LE();
+ _ctx->state = new byte[_ctx->size];
+ _ctx->statecmp = new byte[_ctx->sizecmp];
+ _ctx->f->read(_ctx->statecmp, _ctx->sizecmp);
+ lzo1x_decompress(_ctx->statecmp,_ctx->sizecmp,_ctx->state,&_ctx->size);
+ delete[] _ctx->statecmp;
} else {
- state = new byte[size];
- f->read(state, size);
+ _ctx->state = new byte[_ctx->size];
+ _ctx->f->read(_ctx->state, _ctx->size);
}
- mpalLoadState(state);
- delete[] state;
+ mpalLoadState(_ctx->state);
+ delete[] _ctx->state;
// inventario
- size = f->readUint32LE();
- state = new byte[size];
- f->read(state, size);
- m_inv.LoadState(state);
- delete[] state;
-
- if (ver >= 0x2) { // Versione 2: box please
- size = f->readUint32LE();
- state = new byte[size];
- f->read(state, size);
- _vm->_theBoxes.LoadState(state);
- delete[] state;
+ _ctx->size = _ctx->f->readUint32LE();
+ _ctx->state = new byte[_ctx->size];
+ _ctx->f->read(_ctx->state, _ctx->size);
+ m_inv.LoadState(_ctx->state);
+ delete[] _ctx->state;
+
+ if (_ctx->ver >= 0x2) { // Versione 2: box please
+ _ctx->size = _ctx->f->readUint32LE();
+ _ctx->state = new byte[_ctx->size];
+ _ctx->f->read(_ctx->state, _ctx->size);
+ _vm->_theBoxes.LoadState(_ctx->state);
+ delete[] _ctx->state;
}
- if (ver >= 5) {
+ if (_ctx->ver >= 5) {
// Versione 5:
bool bStat = false;
- bStat = f->readByte();
+ bStat = _ctx->f->readByte();
m_tony.SetPastorella(bStat);
- bStat = f->readByte();
+ bStat = _ctx->f->readByte();
m_inter.SetPalesati(bStat);
- CharsLoadAll(f);
+ CharsLoadAll(_ctx->f);
}
- if (ver >= 6) {
+ if (_ctx->ver >= 6) {
// Carica le opzioni
- bCfgInvLocked = f->readByte();
- bCfgInvNoScroll = f->readByte();
- bCfgTimerizedText = f->readByte();
- bCfgInvUp = f->readByte();
- bCfgAnni30 = f->readByte();
- bCfgAntiAlias = f->readByte();
- bCfgSottotitoli = f->readByte();
- bCfgTransparence = f->readByte();
- bCfgInterTips = f->readByte();
- bCfgDubbing = f->readByte();
- bCfgMusic = f->readByte();
- bCfgSFX = f->readByte();
- nCfgTonySpeed = f->readByte();
- nCfgTextSpeed = f->readByte();
- nCfgDubbingVolume = f->readByte();
- nCfgMusicVolume = f->readByte();
- nCfgSFXVolume = f->readByte();
+ bCfgInvLocked = _ctx->f->readByte();
+ bCfgInvNoScroll = _ctx->f->readByte();
+ bCfgTimerizedText = _ctx->f->readByte();
+ bCfgInvUp = _ctx->f->readByte();
+ bCfgAnni30 = _ctx->f->readByte();
+ bCfgAntiAlias = _ctx->f->readByte();
+ bCfgSottotitoli = _ctx->f->readByte();
+ bCfgTransparence = _ctx->f->readByte();
+ bCfgInterTips = _ctx->f->readByte();
+ bCfgDubbing = _ctx->f->readByte();
+ bCfgMusic = _ctx->f->readByte();
+ bCfgSFX = _ctx->f->readByte();
+ nCfgTonySpeed = _ctx->f->readByte();
+ nCfgTextSpeed = _ctx->f->readByte();
+ nCfgDubbingVolume = _ctx->f->readByte();
+ nCfgMusicVolume = _ctx->f->readByte();
+ nCfgSFXVolume = _ctx->f->readByte();
// Carica gli hotspot
- LoadChangedHotspot(f);
+ LoadChangedHotspot(_ctx->f);
}
- if (ver >= 7) {
- LoadMusic(f);
+ if (_ctx->ver >= 7) {
+ LoadMusic(_ctx->f);
}
- delete f;
+ delete _ctx->f;
- UnloadLocation(nullContext, false, NULL);
- LoadLocation(loc,tp,RMPoint(-1, -1));
+ CORO_INVOKE_2(UnloadLocation, false, NULL);
+ LoadLocation(_ctx->loc,_ctx->tp,RMPoint(-1, -1));
m_tony.SetPattern(RMTony::PAT_STANDRIGHT);
MainUnfreeze();
// Le versioni vecchie necessitano di On enter
- if (ver < 5)
- mpalQueryDoActionU32(0, loc, 0);
+ if (_ctx->ver < 5)
+ mpalQueryDoAction(0, _ctx->loc, 0);
else {
// In quelle nuove, ci basta resettare gli mcode
MCharResetCodes();
}
- if (ver >= 6)
+ if (_ctx->ver >= 6)
ReapplyChangedHotspot();
- RestoreMusic();
+ CORO_INVOKE_0(RestoreMusic);
m_bGUIInterface = true;
m_bGUIInventory = true;
m_bGUIOption = true;
+
+ CORO_END_CODE;
}
void RMGfxEngine::PauseSound(bool bPause) {
diff --git a/engines/tony/gfxengine.h b/engines/tony/gfxengine.h
index 11d591b408..d119bb07a6 100644
--- a/engines/tony/gfxengine.h
+++ b/engines/tony/gfxengine.h
@@ -137,8 +137,8 @@ public:
void LinkGraphicTask(RMGfxTask *task) { m_bigBuf.AddPrim(new RMGfxPrimitive(task)); };
// Manage a location
- HANDLE LoadLocation(int nLoc, RMPoint ptTonyStart, RMPoint start);
- void UnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result);
+ uint32 LoadLocation(int nLoc, RMPoint ptTonyStart, RMPoint start);
+ void UnloadLocation(CORO_PARAM, bool bDoOnExit, uint32 *result);
// Freeze and unfreeze
void Freeze(void);
@@ -146,7 +146,7 @@ public:
// State management
void SaveState(const char *fn, byte *curThumb, const char *name, bool bFastCompress = false);
- void LoadState(const char *fn);
+ void LoadState(CORO_PARAM, const char *fn);
// Selects a location
void SelectLocation(RMPoint ptTonyStart=RMPoint(-1,-1), RMPoint start=RMPoint(-1,-1));
diff --git a/engines/tony/loc.cpp b/engines/tony/loc.cpp
index a412f9cfd2..bba1ad2f23 100644
--- a/engines/tony/loc.cpp
+++ b/engines/tony/loc.cpp
@@ -1376,7 +1376,7 @@ void RMCharacter::NewBoxEntered(int nBox) {
bool bOldReverse;
// Richiama la On ExitBox
- mpalQueryDoActionU32(3, curLocation, curbox);
+ mpalQueryDoAction(3, curLocation, curbox);
cur = theBoxes->GetBoxes(curLocation);
bOldReverse = cur->boxes[curbox].bReversed;
@@ -1410,7 +1410,7 @@ void RMCharacter::NewBoxEntered(int nBox) {
}
// Richiama la On EnterBox
- mpalQueryDoActionU32(2, curLocation, curbox);
+ mpalQueryDoAction(2, curLocation, curbox);
}
void RMCharacter::DoFrame(RMGfxTargetBuffer* bigBuf, int loc) {
diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp
index d6230d7768..c21d84cd9b 100644
--- a/engines/tony/mpal/mpal.cpp
+++ b/engines/tony/mpal/mpal.cpp
@@ -1570,7 +1570,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) {
* uint32 dwParam Eventuale parametro per l'azione
*
* Return: Handle del thread che sta eseguendo l'azione, oppure
-* INVALID_HANDLE_VALUE se l'azione non e' definita, o l'item
+* INVALID_PID_VALUE se l'azione non e' definita, o l'item
* e' disattivato.
*
* Note: Si puo' ottenere l'indice dell'item a partire dal suo numero
@@ -1580,7 +1580,7 @@ void DoChoice(CORO_PARAM, uint32 nChoice) {
*
\****************************************************************************/
-static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) {
+static uint32 DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) {
LPMPALITEM item = lpmiItems;
int i;
LPMPALITEM newitem;
@@ -1589,7 +1589,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) {
item+=ordItem;
Common::String buf = Common::String::format("Status.%u", item->nObj);
if (varGetValue(buf.c_str()) <= 0)
- return INVALID_HANDLE_VALUE;
+ return INVALID_PID_VALUE;
for (i = 0; i < item->nActions; i++) {
if (item->Action[i].num != nAction)
@@ -1607,7 +1607,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) {
// Duplichiamo l'item corrente e copiamo la azione #i nella #0
newitem = (LPMPALITEM)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(MPALITEM));
if (newitem == NULL)
- return INVALID_HANDLE_VALUE;
+ return INVALID_PID_VALUE;
// Nella nuova versione scriviamo il numero dell'azione in dwRes
Common::copy((byte *)item, (byte *)item + sizeof(MPALITEM), (byte *)newitem);
@@ -1621,26 +1621,18 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) {
// !!! New thread management
if ((h = g_scheduler->createProcess(ActionThread, &newitem, sizeof(LPMPALITEM))) == NULL)
- return INVALID_HANDLE_VALUE;
+ return INVALID_PID_VALUE;
- if ((h = g_scheduler->createProcess(ShutUpActionThread, &h, sizeof(uint32))) == NULL)
- return INVALID_HANDLE_VALUE;
+ if (g_scheduler->createProcess(ShutUpActionThread, &h, sizeof(uint32)) == NULL)
+ return INVALID_PID_VALUE;
-/*
- if ((h=(void*)_beginthread(ActionThread, 10240,(void *)newitem))==(void*)-1)
- return INVALID_HANDLE_VALUE;
-
- if ((h=(void*)_beginthread(ShutUpActionThread, 10240,(void *)h))==(void*)-1)
- return INVALID_HANDLE_VALUE;
-
-*/
nExecutingAction = item->nObj;
bExecutingAction = true;
- return (HANDLE)h;
+ return h;
}
- return INVALID_HANDLE_VALUE;
+ return INVALID_PID_VALUE;
}
/**
@@ -1649,7 +1641,7 @@ static HANDLE DoAction(uint32 nAction, uint32 ordItem, uint32 dwParam) {
* @param nDlgOrd The index of the dialog in the dialog list
* @param nGroup Number of the group to perform
* @returns The process Id of the process running the dialog
- * or INVALID_HANDLE_VALUE on error
+ * or INVALID_PID_VALUE on error
* @remarks The dialogue runs in a thread created on purpose,
* so that must inform through an event and when 'necessary to you make a choice.
* The data on the choices may be obtained through various queries.
@@ -1669,14 +1661,14 @@ static uint32 DoDialog(uint32 nDlgOrd, uint32 nGroup) {
// Create a thread that performs the dialogue group
// Create the process
- if ((h = g_scheduler->createProcess(GroupThread, &nGroup, sizeof(uint32))) == 0)
- return 0;
+ if ((h = g_scheduler->createProcess(GroupThread, &nGroup, sizeof(uint32))) == INVALID_PID_VALUE)
+ return INVALID_PID_VALUE;
// Create a thread that waits until the end of the dialog process, and will restore the global variables
- if (g_scheduler->createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == 0) {
+ if (g_scheduler->createProcess(ShutUpDialogThread, &h, sizeof(uint32)) == INVALID_PID_VALUE) {
// Something went wrong, so kill the previously started dialog process
g_scheduler->killMatchingProcess(h);
- return 0;
+ return INVALID_PID_VALUE;
}
return h;
@@ -1912,16 +1904,23 @@ bool mpalInit(const char *lpszMpcFileName, const char *lpszMprFileName,
*
\****************************************************************************/
-#define GETARG(type) va_arg(v,type)
+#define GETARG(type) va_arg(v, type)
-void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) {
- CORO_BEGIN_CONTEXT;
- int x, y, z;
- char *n;
- Common::String buf;
- CORO_END_CONTEXT(_ctx);
+/**
+ * MPAL Query variation #1 - dword return
+ * This variation handles mpal query types that need to return a dword result.
+ *
+ * @param wQueryType Query type
+ * @param v Variable length argument list
+ */
+uint32 mpalQueryDWORD(uint16 wQueryType, ...) {
+ int x, y, z;
+ Common::String buf;
+ uint32 dwRet = 0;
+ char *n;
- CORO_BEGIN_CODE(_ctx);
+ va_list v;
+ va_start(v, wQueryType);
mpalError = OK;
@@ -1929,31 +1928,30 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) {
/*
* uint32 mpalQuery(MPQ_VERSION);
*/
- *dwRet = HEX_VERSION;
+ dwRet = HEX_VERSION;
} else if (wQueryType == MPQ_GLOBAL_VAR) {
/*
* uint32 mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName);
*/
LockVar();
- *dwRet = (uint32)varGetValue(GETARG(char *));
+ dwRet = (uint32)varGetValue(GETARG(char *));
UnlockVar();
} else if (wQueryType == MPQ_MESSAGE) {
/*
* char * mpalQuery(MPQ_MESSAGE, uint32 nMsg);
*/
- LockMsg();
- *dwRet = (uint32)DuplicateMessage(msgGetOrderFromNum(GETARG(uint32)));
- UnlockMsg();
+ error("mpalQuery(MPQ_MESSAGE, uint32 nMsg) used incorrect method variant");
+
} else if (wQueryType == MPQ_ITEM_PATTERN) {
/*
* uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem);
*/
LockVar();
- _ctx->buf = Common::String::format("Pattern.%u", GETARG(uint32));
- *dwRet = (uint32)varGetValue(_ctx->buf.c_str());
+ buf = Common::String::format("Pattern.%u", GETARG(uint32));
+ dwRet = (uint32)varGetValue(buf.c_str());
UnlockVar();
} else if (wQueryType == MPQ_LOCATION_SIZE) {
@@ -1961,61 +1959,56 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) {
* uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord);
*/
LockLocations();
- _ctx->x = locGetOrderFromNum(GETARG(uint32));
- _ctx->y = GETARG(uint32);
- if (_ctx->x != -1) {
- if (_ctx->y == MPQ_X)
- *dwRet = lpmlLocations[_ctx->x].dwXlen;
- else if (_ctx->y == MPQ_Y)
- *dwRet = lpmlLocations[_ctx->x].dwYlen;
+ x = locGetOrderFromNum(GETARG(uint32));
+ y = GETARG(uint32);
+ if (x != -1) {
+ if (y == MPQ_X)
+ dwRet = lpmlLocations[x].dwXlen;
+ else if (y == MPQ_Y)
+ dwRet = lpmlLocations[x].dwYlen;
else
mpalError = 1;
} else
mpalError = 1;
+
UnlockLocations();
} else if (wQueryType == MPQ_LOCATION_IMAGE) {
/*
* HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc);
*/
- LockLocations();
- _ctx->x = locGetOrderFromNum(GETARG(uint32));
- *dwRet = (uint32)resLoad(lpmlLocations[_ctx->x].dwPicRes);
- UnlockLocations();
+ error("mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc) used incorrect variant");
} else if (wQueryType == MPQ_RESOURCE) {
/*
* HGLOBAL mpalQuery(MPQ_RESOURCE, uint32 dwRes);
*/
- *dwRet = (uint32)resLoad(GETARG(uint32));
+ error("mpalQuery(MPQ_RESOURCE, uint32 dwRes) used incorrect variant");
} else if (wQueryType == MPQ_ITEM_LIST) {
/*
* uint32 mpalQuery(MPQ_ITEM_LIST, uint32 nLoc);
*/
- LockVar();
- *dwRet = (uint32)GetItemList(GETARG(uint32));
- LockVar();
+ error("mpalQuery(MPQ_ITEM_LIST, uint32 nLoc) used incorrect variant");
} else if (wQueryType == MPQ_ITEM_DATA) {
/*
* LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem);
*/
- LockItems();
- *dwRet = (uint32)GetItemData(itemGetOrderFromNum(GETARG(uint32)));
- UnlockItems();
+ error("mpalQuery(MPQ_ITEM_DATA, uint32 nItem) used incorrect variant");
} else if (wQueryType == MPQ_ITEM_IS_ACTIVE) {
/*
* bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem);
*/
LockVar();
- _ctx->x = GETARG(uint32);
- _ctx->buf = Common::String::format("Status.%u", _ctx->x);
- if (varGetValue(_ctx->buf.c_str()) <= 0)
- *dwRet = (uint32)false;
+ x = GETARG(uint32);
+ buf = Common::String::format("Status.%u", x);
+ if (varGetValue(buf.c_str()) <= 0)
+ dwRet = (uint32)false;
else
- *dwRet = (uint32)true;
+ dwRet = (uint32)true;
+
UnlockVar();
} else if (wQueryType == MPQ_ITEM_NAME) {
@@ -2023,15 +2016,15 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) {
* uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char * lpszName);
*/
LockVar();
- _ctx->x = GETARG(uint32);
- _ctx->n = GETARG(char *);
- _ctx->buf = Common::String::format("Status.%u", _ctx->x);
- if (varGetValue(_ctx->buf.c_str()) <= 0)
- _ctx->n[0]='\0';
+ x = GETARG(uint32);
+ n = GETARG(char *);
+ buf = Common::String::format("Status.%u", x);
+ if (varGetValue(buf.c_str()) <= 0)
+ n[0]='\0';
else {
LockItems();
- _ctx->y = itemGetOrderFromNum(_ctx->x);
- CopyMemory(_ctx->n, (char *)(lpmiItems+_ctx->y)->lpszDescribe, MAX_DESCRIBE_SIZE);
+ y = itemGetOrderFromNum(x);
+ CopyMemory(n, (char *)(lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE);
UnlockItems();
}
@@ -2039,43 +2032,31 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) {
} else if (wQueryType == MPQ_DIALOG_PERIOD) {
/*
- * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod);
+ * char *mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod);
*/
- LockDialogs();
- _ctx->y = GETARG(uint32);
- *dwRet = (uint32)DuplicateDialogPeriod(_ctx->y);
- UnlockDialogs();
+ error("mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod) used incorrect variant");
} else if (wQueryType == MPQ_DIALOG_WAITFORCHOICE) {
/*
* void mpalQuery(MPQ_DIALOG_WAITFORCHOICE);
*/
- CORO_INVOKE_2(g_scheduler->waitForSingleObject, hAskChoice, INFINITE);
-
- g_scheduler->resetEvent(hAskChoice);
-
- if (bExecutingDialog)
- *dwRet = (uint32)nExecutingChoice;
- else
- *dwRet = (uint32)((int)-1);
+ error("mpalQuery(MPQ_DIALOG_WAITFORCHOICE) used incorrect variant");
} else if (wQueryType == MPQ_DIALOG_SELECTLIST) {
/*
* uint32 *mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice);
*/
- LockDialogs();
- *dwRet = (uint32)GetSelectList(GETARG(uint32));
- UnlockDialogs();
- break;
+ error("mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice) used incorrect variant");
} else if (wQueryType == MPQ_DIALOG_SELECTION) {
/*
* bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData);
*/
LockDialogs();
- _ctx->x = GETARG(uint32);
- _ctx->y = GETARG(uint32);
- *dwRet = (uint32)DoSelection(_ctx->x,_ctx->y);
+ x = GETARG(uint32);
+ y = GETARG(uint32);
+ dwRet = (uint32)DoSelection(x, y);
+
UnlockDialogs();
} else if (wQueryType == MPQ_DO_ACTION) {
@@ -2084,15 +2065,16 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) {
*/
LockItems();
LockVar();
- _ctx->x = GETARG(uint32);
- _ctx->z = GETARG(uint32);
- _ctx->y = itemGetOrderFromNum(_ctx->z);
- if (_ctx->y!=-1) {
- *dwRet = (uint32)DoAction(_ctx->x, _ctx->y, GETARG(uint32));
+ x = GETARG(uint32);
+ z = GETARG(uint32);
+ y = itemGetOrderFromNum(z);
+ if (y != -1) {
+ dwRet = DoAction(x, y, GETARG(uint32));
} else {
- *dwRet = (uint32)INVALID_HANDLE_VALUE;
+ dwRet = INVALID_PID_VALUE;
mpalError = 1;
}
+
UnlockVar();
UnlockItems();
@@ -2103,9 +2085,9 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) {
if (!bExecutingDialog) {
LockDialogs();
- _ctx->x = dialogGetOrderFromNum(GETARG(uint32));
- _ctx->y = GETARG(uint32);
- *dwRet = DoDialog(_ctx->x, _ctx->y);
+ x = dialogGetOrderFromNum(GETARG(uint32));
+ y = GETARG(uint32);
+ dwRet = DoDialog(x, y);
UnlockDialogs();
}
} else {
@@ -2115,26 +2097,201 @@ void mpalQueryInner(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, va_list v) {
mpalError = 1;
}
- CORO_END_CODE;
+ va_end(v);
+ return dwRet;
}
-uint32 mpalQuery(uint16 wQueryType, ...) {
- uint32 dwRet;
+/**
+ * MPAL Query variation #1 - dword return
+ * This variation handles mpal query types that need to return a pointer/handle result
+ *
+ * @param wQueryType Query type
+ * @param v Variable length argument list
+ */
+HANDLE mpalQueryHANDLE(uint16 wQueryType, ...) {
+ int x, y;
+ char *n;
+ Common::String buf;
va_list v;
va_start(v, wQueryType);
+ void *hRet = NULL;
+
+ mpalError = OK;
- mpalQueryInner(nullContext, wQueryType, &dwRet, v);
+ if (wQueryType == MPQ_VERSION) {
+ /*
+ * uint32 mpalQuery(MPQ_VERSION);
+ */
+ error("mpalQuery(MPQ_VERSION) used incorrect variant");
- va_end(v);
+ } else if (wQueryType == MPQ_GLOBAL_VAR) {
+ /*
+ * uint32 mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName);
+ */
+ error("mpalQuery(MPQ_GLOBAL_VAR, char * lpszVarName) used incorrect variant");
- return dwRet;
+ } else if (wQueryType == MPQ_MESSAGE) {
+ /*
+ * char * mpalQuery(MPQ_MESSAGE, uint32 nMsg);
+ */
+ LockMsg();
+ hRet = DuplicateMessage(msgGetOrderFromNum(GETARG(uint32)));
+ UnlockMsg();
+
+ } else if (wQueryType == MPQ_ITEM_PATTERN) {
+ /*
+ * uint32 mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem);
+ */
+ error("mpalQuery(MPQ_ITEM_PATTERN, uint32 nItem) used incorrect variant");
+
+ } else if (wQueryType == MPQ_LOCATION_SIZE) {
+ /*
+ * uint32 mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord);
+ */
+ error("mpalQuery(MPQ_LOCATION_SIZE, uint32 nLoc, uint32 dwCoord) used incorrect variant");
+
+ } else if (wQueryType == MPQ_LOCATION_IMAGE) {
+ /*
+ * HGLOBAL mpalQuery(MPQ_LOCATION_IMAGE, uint32 nLoc);
+ */
+ LockLocations();
+ x = locGetOrderFromNum(GETARG(uint32));
+ hRet = resLoad(lpmlLocations[x].dwPicRes);
+ UnlockLocations();
+
+ } else if (wQueryType == MPQ_RESOURCE) {
+ /*
+ * HGLOBAL mpalQuery(MPQ_RESOURCE, uint32 dwRes);
+ */
+ hRet = resLoad(GETARG(uint32));
+
+ } else if (wQueryType == MPQ_ITEM_LIST) {
+ /*
+ * uint32 mpalQuery(MPQ_ITEM_LIST, uint32 nLoc);
+ */
+ LockVar();
+ hRet = GetItemList(GETARG(uint32));
+ LockVar();
+
+ } else if (wQueryType == MPQ_ITEM_DATA) {
+ /*
+ * LPITEM mpalQuery(MPQ_ITEM_DATA, uint32 nItem);
+ */
+ LockItems();
+ hRet = GetItemData(itemGetOrderFromNum(GETARG(uint32)));
+ UnlockItems();
+
+ } else if (wQueryType == MPQ_ITEM_IS_ACTIVE) {
+ /*
+ * bool mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem);
+ */
+ error("mpalQuery(MPQ_ITEM_IS_ACTIVE, uint32 nItem) used incorrect variant");
+
+ } else if (wQueryType == MPQ_ITEM_NAME) {
+ /*
+ * uint32 mpalQuery(MPQ_ITEM_NAME, uint32 nItem, char *lpszName);
+ */
+ LockVar();
+ x = GETARG(uint32);
+ n = GETARG(char *);
+ buf = Common::String::format("Status.%u", x);
+ if (varGetValue(buf.c_str()) <= 0)
+ n[0]='\0';
+ else {
+ LockItems();
+ y = itemGetOrderFromNum(x);
+ CopyMemory(n, (char *)(lpmiItems + y)->lpszDescribe, MAX_DESCRIBE_SIZE);
+ UnlockItems();
+ }
+
+ UnlockVar();
+
+ } else if (wQueryType == MPQ_DIALOG_PERIOD) {
+ /*
+ * char * mpalQuery(MPQ_DIALOG_PERIOD, uint32 nDialog, uint32 nPeriod);
+ */
+ LockDialogs();
+ y = GETARG(uint32);
+ hRet = DuplicateDialogPeriod(y);
+ UnlockDialogs();
+
+ } else if (wQueryType == MPQ_DIALOG_WAITFORCHOICE) {
+ /*
+ * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE);
+ */
+ error("mpalQuery(MPQ_DIALOG_WAITFORCHOICE) used incorrect variant");
+
+ } else if (wQueryType == MPQ_DIALOG_SELECTLIST) {
+ /*
+ * uint32 *mpalQuery(MPQ_DIALOG_SELECTLIST, uint32 nChoice);
+ */
+ LockDialogs();
+ hRet = GetSelectList(GETARG(uint32));
+ UnlockDialogs();
+
+ } else if (wQueryType == MPQ_DIALOG_SELECTION) {
+ /*
+ * bool mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData);
+ */
+ error("mpalQuery(MPQ_DIALOG_SELECTION, uint32 nChoice, uint32 dwData) used incorrect variant");
+
+ } else if (wQueryType == MPQ_DO_ACTION) {
+ /*
+ * int mpalQuery(MPQ_DO_ACTION, uint32 nAction, uint32 nItem, uint32 dwParam);
+ */
+ error("mpalQuery(MPQ_DO_ACTION, uint32 nAction, uint32 nItem, uint32 dwParam) used incorrect variant");
+
+ } else if (wQueryType == MPQ_DO_DIALOG) {
+ /*
+ * int mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup);
+ */
+ error("mpalQuery(MPQ_DO_DIALOG, uint32 nDialog, uint32 nGroup) used incorrect variant");
+ } else {
+ /*
+ * DEFAULT -> ERROR
+ */
+ mpalError = 1;
+ }
+
+ va_end(v);
+ return hRet;
}
-void mpalQueryCoro(CORO_PARAM, uint32 *dwRet, uint16 wQueryType, ...) {
+/**
+ * MPAL Query variation #1 - dword return
+ * This variation handles mpal query types that need to return a pointer/handle result
+ *
+ * @param wQueryType Query type
+ * @param dwRet DWORD return value (when coroutine method completes)
+ * @param v Variable length argument list
+ */
+void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...) {
+ CORO_BEGIN_CONTEXT;
+ uint32 dwRet;
+ CORO_END_CONTEXT(_ctx);
+
va_list v;
- va_start(v, wQueryType);
+ va_start(v, dwRet);
+
+ CORO_BEGIN_CODE(_ctx);
+
+ if (wQueryType == MPQ_DIALOG_WAITFORCHOICE) {
+ /*
+ * void mpalQuery(MPQ_DIALOG_WAITFORCHOICE);
+ */
+ CORO_INVOKE_2(g_scheduler->waitForSingleObject, hAskChoice, INFINITE);
+
+ g_scheduler->resetEvent(hAskChoice);
- mpalQueryInner(coroParam, wQueryType, dwRet, v);
+ if (bExecutingDialog)
+ *dwRet = (uint32)nExecutingChoice;
+ else
+ *dwRet = (uint32)((int)-1);
+ } else {
+ error("mpalQueryCORO called with unsupported query type");
+ }
+
+ CORO_END_CODE;
va_end(v);
}
@@ -2171,7 +2328,6 @@ uint32 mpalGetError(void) {
bool EXPORT mpalExecuteScript(int nScript) {
int n;
LPMPALSCRIPT s;
- uint32 dwId;
LockScripts();
n = scriptGetOrderFromNum(nScript);
diff --git a/engines/tony/mpal/mpal.h b/engines/tony/mpal/mpal.h
index 5517a6518c..9a85f2df17 100644
--- a/engines/tony/mpal/mpal.h
+++ b/engines/tony/mpal/mpal.h
@@ -156,7 +156,7 @@ enum QueryCoordinates {
/****************************************************************************\
* enum QueryTypes
* ---------------
-* Description: Query can be used with mpalQuery (). In practice corresponds
+* Description: Query can be used with mpalQuery methods. In practice corresponds
* all claims that can do at the library
\****************************************************************************/
@@ -252,7 +252,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryVersion() \
- (uint16)mpalQuery(MPQ_VERSION)
+ (uint16)mpalQueryDWORD(MPQ_VERSION)
@@ -273,7 +273,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryGlobalVar(lpszVarName) \
- (uint32)mpalQuery(MPQ_GLOBAL_VAR,(const char *)(lpszVarName))
+ mpalQueryDWORD(MPQ_GLOBAL_VAR, (const char *)(lpszVarName))
@@ -291,7 +291,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryResource(dwResId) \
- (HGLOBAL)mpalQuery(MPQ_RESOURCE,(uint32)(dwResId))
+ mpalQueryHANDLE(MPQ_RESOURCE, (uint32)(dwResId))
@@ -311,7 +311,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryMessage(nMsg) \
- (LPSTR)mpalQuery(MPQ_MESSAGE,(uint32)(nMsg))
+ (LPSTR)mpalQueryHANDLE(MPQ_MESSAGE, (uint32)(nMsg))
@@ -328,7 +328,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryLocationImage(nLoc) \
- (HGLOBAL)mpalQuery(MPQ_LOCATION_IMAGE,(uint32)(nLoc))
+ mpalQueryHANDLE(MPQ_LOCATION_IMAGE, (uint32)(nLoc))
@@ -346,7 +346,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryLocationSize(nLoc,dwCoord) \
- (uint32)mpalQuery(MPQ_LOCATION_SIZE,(uint32)(nLoc),(uint32)(dwCoord))
+ mpalQueryDWORD(MPQ_LOCATION_SIZE,(uint32)(nLoc),(uint32)(dwCoord))
@@ -361,9 +361,9 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
* Return: List of objects (accessible by Item [0], Item [1], etc.)
*
\****************************************************************************/
-
+// TODO: Check if the results of this are endian safe
#define mpalQueryItemList(nLoc) \
- (uint32 *)mpalQuery(MPQ_ITEM_LIST,(uint32)(nLoc))
+ (uint32 *)mpalQueryHANDLE(MPQ_ITEM_LIST,(uint32)(nLoc))
@@ -380,7 +380,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryItemData(nItem) \
- (LPITEM)mpalQuery(MPQ_ITEM_DATA,(uint32)(nItem))
+ (LPITEM)mpalQueryHANDLE(MPQ_ITEM_DATA,(uint32)(nItem))
@@ -400,7 +400,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryItemPattern(nItem) \
- (uint32)mpalQuery(MPQ_ITEM_PATTERN,(uint32)(nItem))
+ mpalQueryDWORD(MPQ_ITEM_PATTERN,(uint32)(nItem))
@@ -417,7 +417,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryItemIsActive(nItem) \
- (bool)mpalQuery(MPQ_ITEM_IS_ACTIVE,(uint32)(nItem))
+ (bool)mpalQueryDWORD(MPQ_ITEM_IS_ACTIVE,(uint32)(nItem))
/****************************************************************************\
@@ -435,8 +435,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
*
\****************************************************************************/
-#define mpalQueryItemName(nItem,lpszName) \
- (uint32)mpalQuery(MPQ_ITEM_NAME,(uint32)(nItem),(LPSTR)(lpszName))
+#define mpalQueryItemName(nItem, lpszName) \
+ mpalQueryHANDLE(MPQ_ITEM_NAME,(uint32)(nItem), (LPSTR)(lpszName))
@@ -459,7 +459,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryDialogPeriod(nPeriod) \
- (LPSTR)mpalQuery(MPQ_DIALOG_PERIOD,(uint32)(nPeriod))
+ (LPSTR)mpalQueryHANDLE(MPQ_DIALOG_PERIOD, (uint32)(nPeriod))
@@ -475,7 +475,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryDialogWaitForChoice(dwRet) \
- CORO_INVOKE_2(mpalQueryCoro, dwRet, MPQ_DIALOG_WAITFORCHOICE)
+ CORO_INVOKE_2(mpalQueryCORO, MPQ_DIALOG_WAITFORCHOICE, dwRet)
/****************************************************************************\
*
@@ -496,7 +496,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryDialogSelectList(nChoice) \
- (uint32 *)mpalQuery(MPQ_DIALOG_SELECTLIST,(uint32)(nChoice))
+ (uint32 *)mpalQueryHANDLE(MPQ_DIALOG_SELECTLIST,(uint32)(nChoice))
@@ -521,10 +521,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryDialogSelection(nChoice,dwData) \
- (bool)mpalQuery(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData))
+ (bool)mpalQueryDWORD(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData))
-#define mpalQueryDialogSelectionU32(nChoice, dwData) \
- mpalQuery(MPQ_DIALOG_SELECTION,(uint32)(nChoice),(uint32)(dwData))
/****************************************************************************\
*
@@ -539,7 +537,7 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
* uint32 dwParam Action parameter
*
* Return: Handle to the thread that is performing the action, or
-* INVALID_HANDLE_VALUE if the action is not 'defined for
+* INVALID_PID_VALUE if the action is not 'defined for
* the item, or the item and 'off.
*
* Note: The parameter is used primarily to implement actions
@@ -549,10 +547,8 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
\****************************************************************************/
#define mpalQueryDoAction(nAction, nItem, dwParam) \
- (HANDLE)mpalQuery(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam))
+ mpalQueryDWORD(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam))
-#define mpalQueryDoActionU32(nAction, nItem, dwParam) \
- mpalQuery(MPQ_DO_ACTION, (uint32)(nAction), (uint32)(nItem), (uint32)(dwParam))
/****************************************************************************\
@@ -565,15 +561,12 @@ typedef LPITEMIRQFUNCTION* LPLPITEMIRQFUNCTION;
* uint32 nGroup Group number to use
*
* Return: Handle to the thread that is running the box, or
-* INVALID_HANDLE_VALUE if the dialogue does not exist.
+* INVALID_PID_VALUE if the dialogue does not exist.
*
\****************************************************************************/
#define mpalQueryDoDialog(nDialog,nGroup) \
- (HANDLE)mpalQuery(MPQ_DO_DIALOG,(uint32)(nDialog),(uint32)(nGroup))
-
-#define mpalQueryDoDialogU32(nDialog, nGroup) \
- mpalQuery(MPQ_DO_DIALOG,(uint32)(nDialog),(uint32)(nGroup))
+ mpalQueryHANDLE(MPQ_DO_DIALOG, (uint32)(nDialog),(uint32)(nGroup))
/****************************************************************************\
@@ -623,9 +616,13 @@ bool EXPORT mpalInit(const char *lpszFileName, const char *lpszMprFileName,
*
\****************************************************************************/
-uint32 EXPORT mpalQuery(uint16 wQueryType, ...);
+typedef void *HANDLE;
+
+uint32 mpalQueryDWORD(uint16 wQueryType, ...);
+
+HANDLE mpalQueryHANDLE(uint16 wQueryType, ...);
-void mpalQueryCoro(CORO_PARAM, uint32 *dwRet, uint16 wQueryType, ...);
+void mpalQueryCORO(CORO_PARAM, uint16 wQueryType, uint32 *dwRet, ...);
/****************************************************************************\
*
diff --git a/engines/tony/mpal/stubs.h b/engines/tony/mpal/stubs.h
index 082974898c..ae25f7127e 100644
--- a/engines/tony/mpal/stubs.h
+++ b/engines/tony/mpal/stubs.h
@@ -71,9 +71,6 @@ Out CopyMemory(Out dst, In first, int size) {
* Methods
\****************************************************************************/
-// Horrendously bad cast
-#define INVALID_HANDLE_VALUE (void *)-1
-
extern uint16 GetAsyncKeyState(Common::KeyCode kc);
} // end of namespace MPAL
diff --git a/engines/tony/sound.cpp b/engines/tony/sound.cpp
index b376d14149..a2b3d7c8ce 100644
--- a/engines/tony/sound.cpp
+++ b/engines/tony/sound.cpp
@@ -1021,7 +1021,7 @@ FPSFX::FPSFX(LPDIRECTSOUND lpds, HWND hWnd, bool bSoundOn) {
lpDSNotify = NULL;
lpDS = lpds;
lastVolume = 63;
- hEndOfBuffer = INVALID_HANDLE_VALUE;
+ hEndOfBuffer = INVALID_PID_VALUE;
bIsVoice = false;
if (bSoundSupported == false)
@@ -1053,7 +1053,7 @@ FPSFX::~FPSFX() {
RELEASE(lpDSNotify);
- if (hEndOfBuffer != INVALID_HANDLE_VALUE)
+ if (hEndOfBuffer != INVALID_PID_VALUE)
CloseHandle(hEndOfBuffer);
RELEASE(lpDSBuffer);
@@ -1415,7 +1415,7 @@ bool FPSFX::LoadFile(const char *lpszFileName, uint32 dwCodec) {
bool FPSFX::Play() {
#ifdef REFACTOR_ME
if (bFileLoaded) {
- if (hEndOfBuffer != INVALID_HANDLE_VALUE)
+ if (hEndOfBuffer != INVALID_PID_VALUE)
ResetEvent(hEndOfBuffer);
lpDSBuffer->SetCurrentPosition(0);
diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp
index ef27f509b9..d8ea05d06a 100644
--- a/engines/tony/tony.cpp
+++ b/engines/tony/tony.cpp
@@ -322,11 +322,17 @@ void TonyEngine::SaveState(int n, const char *name) {
}
-void TonyEngine::LoadState(int n) {
- char buf[256];
+void TonyEngine::LoadState(CORO_PARAM, int n) {
+ CORO_BEGIN_CONTEXT;
+ char buf[256];
+ CORO_END_CONTEXT(_ctx);
- GetSaveStateFileName(n, buf);
- _theEngine.LoadState(buf);
+ CORO_BEGIN_CODE(_ctx);
+
+ GetSaveStateFileName(n, _ctx->buf);
+ CORO_INVOKE_1(_theEngine.LoadState, _ctx->buf);
+
+ CORO_END_CODE;
}
bool TonyEngine::OpenVoiceDatabase() {
@@ -393,35 +399,66 @@ void TonyEngine::Abort(void) {
m_bQuitNow = true;
}
-void TonyEngine::Play(void) {
- // Main game loop
- while (!shouldQuit() && !m_bQuitNow) {
- // Se siamo in pausa, entra nel loop appropriato
- if (m_bPaused)
- PauseLoop();
+/**
+ * Main process for playing the game.
+ *
+ * @remarks This needs to be in a separate process, since there are some things that can briefly
+ * block the execution of process. For now, all ScummVm event handling is dispatched to within the context of this
+ * process. If it ever proves a problem, we may have to look into whether it's feasible to have it still remain
+ * in the outer 'main' process.
+ */
+void TonyEngine::PlayProcess(CORO_PARAM, const void *param) {
+ CORO_BEGIN_CONTEXT;
+ CORO_END_CONTEXT(_ctx);
- g_system->delayMillis(50);
+ CORO_BEGIN_CODE(_ctx);
- // Call any scheduled processes
- _scheduler.schedule();
+ // Infinite loop. We rely on the outer main process to detect if a shutdown is required,
+ // and kill the scheudler and all the processes, including this one
+ for (;;) {
+ // Se siamo in pausa, entra nel loop appropriato
+ if (_vm->m_bPaused)
+ _vm->PauseLoop();
+
+ // Wait for the next frame
+ CORO_INVOKE_1(g_scheduler->sleep, 50);
// Call the engine to handle the next frame
// FIXME: This needs to be moved into it's own process
- _theEngine.DoFrame(nullContext, m_bDrawLocation);
+ CORO_INVOKE_1(_vm->_theEngine.DoFrame, _vm->m_bDrawLocation);
// Warns that a frame is finished
- g_scheduler->pulseEvent(m_hEndOfFrame);
+ g_scheduler->pulseEvent(_vm->m_hEndOfFrame);
// Handle drawing the frame
- if (!m_bPaused) {
- if (!_theEngine.m_bWiping)
- _window.GetNewFrame(_theEngine, NULL);
+ if (!_vm->m_bPaused) {
+ if (!_vm->_theEngine.m_bWiping)
+ _vm->_window.GetNewFrame(_vm->_theEngine, NULL);
else
- _window.GetNewFrame(_theEngine, &_theEngine.m_rcWipeEllipse);
+ _vm->_window.GetNewFrame(_vm->_theEngine, &_vm->_theEngine.m_rcWipeEllipse);
}
// Paint the frame onto the screen
- _window.Repaint();
+ _vm->_window.Repaint();
+ }
+
+ CORO_END_CODE;
+}
+
+/**
+ * Play the game
+ */
+void TonyEngine::Play(void) {
+ // Create the game player process
+ g_scheduler->createProcess(PlayProcess, NULL);
+
+ // Loop through calling the scheduler until it's time for the game to quit
+ while (!shouldQuit() && !m_bQuitNow) {
+ // Delay for a brief amount
+ g_system->delayMillis(10);
+
+ // Call any scheduled processes
+ _scheduler.schedule();
}
}
diff --git a/engines/tony/tony.h b/engines/tony/tony.h
index fdb92e3795..935f805912 100644
--- a/engines/tony/tony.h
+++ b/engines/tony/tony.h
@@ -82,6 +82,7 @@ private:
bool OpenVoiceDatabase();
void CloseVoiceDatabase();
void InitCustomFunctionMap();
+ static void PlayProcess(CORO_PARAM, const void *param);
protected:
// Engine APIs
virtual Common::Error run();
@@ -193,7 +194,7 @@ public:
// Salvataggio
void AutoSave(CORO_PARAM);
void SaveState(int n, const char *name);
- void LoadState(int n);
+ void LoadState(CORO_PARAM, int n);
void GetSaveStateFileName(int n, char *buf);
// Prende il thumbnail
diff --git a/engines/tony/tonychar.cpp b/engines/tony/tonychar.cpp
index ea233233d2..06adcd15b8 100644
--- a/engines/tony/tonychar.cpp
+++ b/engines/tony/tonychar.cpp
@@ -213,53 +213,48 @@ void RMTony::MoveAndDoAction(RMPoint dst, RMItem *item, int nAction, int nAction
void RMTony::ExecuteAction(int nAction, int nActionItem, int nParm) {
// fixme: See if hThread can be converted to uint32
- HANDLE hThread;
uint32 pid;
if (nAction == TA_COMBINE) {
- hThread = mpalQueryDoAction(TA_COMBINE, nParm, nActionItem);
+ pid = mpalQueryDoAction(TA_COMBINE, nParm, nActionItem);
// Se è fallito il combine, proviamo con il ReceiveCombine
- if (hThread == INVALID_HANDLE_VALUE) {
- hThread = mpalQueryDoAction(TA_RECEIVECOMBINE, nActionItem, nParm);
+ if (pid == INVALID_PID_VALUE) {
+ pid = mpalQueryDoAction(TA_RECEIVECOMBINE, nActionItem, nParm);
// Se è fallito il receive, andiamo con quelli generici
// @@@ CombineGive!
- if (hThread == INVALID_HANDLE_VALUE) {
- hThread = mpalQueryDoAction(TA_COMBINE, nParm, 0);
+ if (pid == INVALID_PID_VALUE) {
+ pid = mpalQueryDoAction(TA_COMBINE, nParm, 0);
- if (hThread == INVALID_HANDLE_VALUE){
- hThread = mpalQueryDoAction(TA_RECEIVECOMBINE, nActionItem, 0);
+ if (pid == INVALID_PID_VALUE){
+ pid = mpalQueryDoAction(TA_RECEIVECOMBINE, nActionItem, 0);
}
}
}
} else {
// Perform the action
- hThread = mpalQueryDoAction(nAction, nActionItem, 0);
+ pid = mpalQueryDoAction(nAction, nActionItem, 0);
}
- if (hThread != INVALID_HANDLE_VALUE) {
+ if (pid != INVALID_PID_VALUE) {
m_bAction = true;
- pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = pid;
} else if (nAction != TA_GOTO) {
if (nAction == TA_TALK) {
- hThread = mpalQueryDoAction(6, 1, 0);
+ pid = mpalQueryDoAction(6, 1, 0);
m_bAction = true;
- pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = pid;
} else if (nAction == TA_PALESATI) {
- hThread = mpalQueryDoAction(7, 1, 0);
+ pid = mpalQueryDoAction(7, 1, 0);
m_bAction = true;
- pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = pid;
} else {
- hThread = mpalQueryDoAction(5, 1, 0);
+ pid = mpalQueryDoAction(5, 1, 0);
m_bAction = true;
- pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = pid;
}
@@ -285,21 +280,21 @@ void RMTony::StopNoAction(CORO_PARAM) {
void RMTony::Stop(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
- uint32 hThread;
+ uint32 pid;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
if (m_ActionItem != NULL) {
// Richiama l'MPAL per scegliere la direzione
- _ctx->hThread = mpalQueryDoActionU32(21, m_ActionItem->MpalCode(), 0);
+ _ctx->pid = mpalQueryDoAction(21, m_ActionItem->MpalCode(), 0);
- if (_ctx->hThread == INVALID_PID_VALUE)
+ if (_ctx->pid == INVALID_PID_VALUE)
RMCharacter::Stop();
else {
bNeedToStop = false; // Se facciamo la OnWhichDirection, almeno dopo non dobbiamo fare la Stop()
bMoving = false;
- CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->hThread, INFINITE); // @@@ Mettere un assert dopo 10 secondi
+ CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->pid, INFINITE); // @@@ Mettere un assert dopo 10 secondi
}
} else {
RMCharacter::Stop();
diff --git a/engines/tony/window.cpp b/engines/tony/window.cpp
index 8ac36a5693..f68c612911 100644
--- a/engines/tony/window.cpp
+++ b/engines/tony/window.cpp
@@ -149,7 +149,7 @@ byte RMSnapshot::rgb[RM_SX * RM_SY * 3];
bool RMSnapshot::GetFreeSnapName(char *fn) {
#ifdef REFACTOR_ME
int i, j, k;
- HANDLE h;
+ uint32 h;
theGame.GetDataDirectory(RMGame::DD_SHOTS, fn);
_splitpath(fn, bufDrive, bufDir, NULL, NULL);
@@ -158,7 +158,7 @@ bool RMSnapshot::GetFreeSnapName(char *fn) {
wsprintf(bufName,"rm%d00",i);
_makepath(fn,bufDrive,bufDir,bufName,".bmp");
h = CreateFile(fn,GENERIC_READ,FILE_SHARE_READ, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
- if (h == INVALID_HANDLE_VALUE)
+ if (h == INVALID_PID_VALUE)
break;
CloseHandle(h);
}
@@ -169,7 +169,7 @@ bool RMSnapshot::GetFreeSnapName(char *fn) {
wsprintf(bufName,"rm%d%d0",i,j);
_makepath(fn,bufDrive,bufDir,bufName,".bmp");
h=CreateFile(fn,GENERIC_READ,FILE_SHARE_READ, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
- if (h==INVALID_HANDLE_VALUE)
+ if (h==INVALID_PID_VALUE)
break;
CloseHandle(h);
}
@@ -180,7 +180,7 @@ bool RMSnapshot::GetFreeSnapName(char *fn) {
wsprintf(bufName,"rm%d%d%d",i,j,k);
_makepath(fn,bufDrive,bufDir,bufName,".bmp");
h = CreateFile(fn,GENERIC_READ,FILE_SHARE_READ, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
- if (h==INVALID_HANDLE_VALUE)
+ if (h==INVALID_PID_VALUE)
break;
CloseHandle(h);
}