TONY: Completed bulk of initial coro refactoring

This commit is contained in:
Paul Gilbert 2012-05-09 00:42:27 +10:00
parent a254f10025
commit 26898dd7ad
21 changed files with 772 additions and 660 deletions

View file

@ -96,7 +96,7 @@ void MainUnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result);
void MainLinkGraphicTask(RMGfxTask *task); void MainLinkGraphicTask(RMGfxTask *task);
void MainFreeze(void); void MainFreeze(void);
void MainUnfreeze(void); void MainUnfreeze(void);
void MainWaitFrame(void); void MainWaitFrame(CORO_PARAM);
void MainShowMouse(void); void MainShowMouse(void);
void MainHideMouse(void); void MainHideMouse(void);
void MainEnableInput(void); void MainEnableInput(void);
@ -104,7 +104,7 @@ void MainDisableInput(void);
void MainPlayMusic(int nChannel, const char *filename, int nFX, bool bLoop, int nSync); void MainPlayMusic(int nChannel, const char *filename, int nFX, bool bLoop, int nSync);
void MainInitWipe(int type); void MainInitWipe(int type);
void MainCloseWipe(void); void MainCloseWipe(void);
void MainWaitWipeEnd(void); void MainWaitWipeEnd(CORO_PARAM);
void MainEnableGUI(void); void MainEnableGUI(void);
void MainDisableGUI(void); void MainDisableGUI(void);
void MainSetPalesati(bool bPalesati); void MainSetPalesati(bool bPalesati);

File diff suppressed because it is too large Load diff

View file

@ -2048,23 +2048,23 @@ RMTextDialog::RMTextDialog() : RMText() {
m_bForceNoTime = false; m_bForceNoTime = false;
m_bAlwaysDisplay = false; m_bAlwaysDisplay = false;
m_bNoTab = false; m_bNoTab = false;
hCustomSkip = INVALID_HANDLE_VALUE; hCustomSkip = INVALID_PID_VALUE;
hCustomSkip2 = INVALID_HANDLE_VALUE; hCustomSkip2 = INVALID_PID_VALUE;
m_input = NULL; m_input = NULL;
// Crea l'evento di fine displaying // Crea l'evento di fine displaying
hEndDisplay = CreateEvent(NULL, false, false, NULL); hEndDisplay = g_scheduler->createEvent(false, false);
} }
RMTextDialog::~RMTextDialog() { RMTextDialog::~RMTextDialog() {
CloseHandle(hEndDisplay); g_scheduler->closeEvent(hEndDisplay);
} }
void RMTextDialog::Show(void) { void RMTextDialog::Show(void) {
m_bShowed = true; m_bShowed = true;
} }
void RMTextDialog::Hide(void) { void RMTextDialog::Hide(CORO_PARAM) {
m_bShowed = false; m_bShowed = false;
} }
@ -2084,7 +2084,7 @@ void RMTextDialog::WriteText(RMString text, RMFontColor *font, int *time) {
void RMTextDialog::SetSkipStatus(bool bEnabled) { void RMTextDialog::SetSkipStatus(bool bEnabled) {
m_bSkipStatus=bEnabled; m_bSkipStatus = bEnabled;
} }
void RMTextDialog::ForceTime(void) { void RMTextDialog::ForceTime(void) {
@ -2107,53 +2107,70 @@ void RMTextDialog::SetAlwaysDisplay(void) {
m_bAlwaysDisplay = true; m_bAlwaysDisplay = true;
} }
bool RMTextDialog::RemoveThis(void) { void RMTextDialog::RemoveThis(CORO_PARAM, bool &result) {
CORO_BEGIN_CONTEXT;
bool expired;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
// Presume successful result
result = true;
// Frase NON di background // Frase NON di background
if (m_bSkipStatus) { if (m_bSkipStatus) {
if (!(bCfgDubbing && hCustomSkip2 != INVALID_HANDLE_VALUE)) if (!(bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE))
if (bCfgTimerizedText) { if (bCfgTimerizedText) {
if (!m_bForceNoTime) if (!m_bForceNoTime)
if (_vm->GetTime() > (uint32)m_time + m_startTime) if (_vm->GetTime() > (uint32)m_time + m_startTime)
return true; return;
} }
if (!m_bNoTab) if (!m_bNoTab)
if ((GetAsyncKeyState(Common::KEYCODE_TAB) & 0x8001) == 0x8001) if ((GetAsyncKeyState(Common::KEYCODE_TAB) & 0x8001) == 0x8001)
return true; return;
if (!m_bNoTab) if (!m_bNoTab)
if (m_input) if (m_input)
if (m_input->MouseLeftClicked() || m_input->MouseRightClicked()) if (m_input->MouseLeftClicked() || m_input->MouseRightClicked())
return true; return;
} }
// Frase di background // Frase di background
else { else {
if (!(bCfgDubbing && hCustomSkip2 != INVALID_HANDLE_VALUE)) if (!(bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE))
if (!m_bForceNoTime) if (!m_bForceNoTime)
if (_vm->GetTime() > (uint32)m_time + m_startTime) if (_vm->GetTime() > (uint32)m_time + m_startTime)
return true; return;
} }
// Se il tempo è forzato // Se il tempo è forzato
if (m_bForceTime) if (m_bForceTime)
if (_vm->GetTime() > (uint32)m_time + m_startTime) if (_vm->GetTime() > (uint32)m_time + m_startTime)
return true; return;
if (hCustomSkip != INVALID_HANDLE_VALUE) if (hCustomSkip != INVALID_PID_VALUE) {
if (WaitForSingleObject(hCustomSkip, 0) == WAIT_OBJECT_0) CORO_INVOKE_3(g_scheduler->waitForSingleObject, hCustomSkip, 0, &_ctx->expired);
return true; // == WAIT_OBJECT_0
if (!_ctx->expired)
return;
}
if (bCfgDubbing && hCustomSkip2 != INVALID_HANDLE_VALUE) if (bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE) {
if (WaitForSingleObject(hCustomSkip2,0) == WAIT_OBJECT_0) CORO_INVOKE_3(g_scheduler->waitForSingleObject, hCustomSkip2, 0, &_ctx->expired);
return true; // == WAIT_OBJECT_0
if (!_ctx->expired)
return;
}
return false; result = false;
CORO_END_CODE;
} }
void RMTextDialog::Unregister(void) { void RMTextDialog::Unregister(void) {
RMGfxTask::Unregister(); RMGfxTask::Unregister();
assert(m_nInList == 0); assert(m_nInList == 0);
SetEvent(hEndDisplay); g_scheduler->setEvent(hEndDisplay);
} }
void RMTextDialog::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) { void RMTextDialog::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) {
@ -2168,16 +2185,16 @@ void RMTextDialog::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) {
} }
} }
void RMTextDialog::SetCustomSkipHandle(HANDLE hCustom) { void RMTextDialog::SetCustomSkipHandle(uint32 hCustom) {
hCustomSkip = hCustom; hCustomSkip = hCustom;
} }
void RMTextDialog::SetCustomSkipHandle2(HANDLE hCustom) { void RMTextDialog::SetCustomSkipHandle2(uint32 hCustom) {
hCustomSkip2 = hCustom; hCustomSkip2 = hCustom;
} }
void RMTextDialog::WaitForEndDisplay(void) { void RMTextDialog::WaitForEndDisplay(CORO_PARAM) {
WaitForSingleObject(hEndDisplay, INFINITE); g_scheduler->waitForSingleObject(coroParam, hEndDisplay, INFINITE);
} }
void RMTextDialog::SetInput(RMInput *input) { void RMTextDialog::SetInput(RMInput *input) {
@ -2231,9 +2248,16 @@ RMTextItemName::~RMTextItemName() {
} }
void RMTextItemName::DoFrame(RMGfxTargetBuffer& bigBuf, RMLocation &loc, RMPointer &ptr, RMInventory &inv) { void RMTextItemName::DoFrame(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMLocation &loc, RMPointer &ptr, RMInventory &inv) {
RMString itemName; CORO_BEGIN_CONTEXT;
RMItem *lastItem = m_item; RMString itemName;
RMItem *lastItem;
uint32 hThread;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
_ctx->lastItem = m_item;
// Si aggiunge alla lista se c'e' bisogno // Si aggiunge alla lista se c'e' bisogno
if (!m_nInList) if (!m_nInList)
@ -2248,27 +2272,29 @@ void RMTextItemName::DoFrame(RMGfxTargetBuffer& bigBuf, RMLocation &loc, RMPoint
else else
m_item = loc.WhichItemIsIn(m_mpos); m_item = loc.WhichItemIsIn(m_mpos);
itemName = ""; _ctx->itemName = "";
// Si fa dare il nuovo nome // Si fa dare il nuovo nome
if (m_item != NULL) if (m_item != NULL)
m_item->GetName(itemName); m_item->GetName(_ctx->itemName);
// Se lo scrive // Se lo scrive
WriteText(itemName, 1); WriteText(_ctx->itemName, 1);
// Se e' diverso dal precedente, e' il caso di aggiornare anche il puntatore con la WhichPointer // Se e' diverso dal precedente, e' il caso di aggiornare anche il puntatore con la WhichPointer
if (lastItem != m_item) { if (_ctx->lastItem != m_item) {
if (m_item == NULL) if (m_item == NULL)
ptr.SetSpecialPointer(RMPointer::PTR_NONE); ptr.SetSpecialPointer(RMPointer::PTR_NONE);
else { else {
HANDLE hThread = mpalQueryDoAction(20, m_item->MpalCode(), 0); _ctx->hThread = mpalQueryDoActionU32(20, m_item->MpalCode(), 0);
if (hThread == INVALID_HANDLE_VALUE) if (_ctx->hThread == INVALID_PID_VALUE)
ptr.SetSpecialPointer(RMPointer::PTR_NONE); ptr.SetSpecialPointer(RMPointer::PTR_NONE);
else else
WaitForSingleObject(hThread,INFINITE); CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->hThread, INFINITE);
} }
} }
CORO_END_CODE;
} }
@ -2318,18 +2344,18 @@ RMDialogChoice::RMDialogChoice() {
DlgText.LoadPaletteWA(dlgpal); DlgText.LoadPaletteWA(dlgpal);
DlgTextLine.LoadPaletteWA(dlgpal); DlgTextLine.LoadPaletteWA(dlgpal);
hUnreg=CreateEvent(NULL, false, false, NULL); hUnreg = g_scheduler->createEvent(false, false);
bRemoveFromOT = false; bRemoveFromOT = false;
} }
RMDialogChoice::~RMDialogChoice() { RMDialogChoice::~RMDialogChoice() {
CloseHandle(hUnreg); g_scheduler->closeEvent(hUnreg);
} }
void RMDialogChoice::Unregister(void) { void RMDialogChoice::Unregister(void) {
RMGfxWoodyBuffer::Unregister(); RMGfxWoodyBuffer::Unregister();
assert(!m_nInList); assert(!m_nInList);
PulseEvent(hUnreg); g_scheduler->pulseEvent(hUnreg);
bRemoveFromOT = false; bRemoveFromOT = false;
} }
@ -2444,7 +2470,16 @@ void RMDialogChoice::SetSelected(int pos) {
m_curSelection = pos; m_curSelection = pos;
} }
void RMDialogChoice::Show(RMGfxTargetBuffer *bigBuf) { void RMDialogChoice::Show(CORO_PARAM, RMGfxTargetBuffer *bigBuf) {
CORO_BEGIN_CONTEXT;
RMPoint destpt;
int deltay;
int starttime;
int elaps;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
Prepare(); Prepare();
m_bShow = false; m_bShow = false;
@ -2454,30 +2489,28 @@ void RMDialogChoice::Show(RMGfxTargetBuffer *bigBuf) {
if (0) { if (0) {
m_bShow = true; m_bShow = true;
} else { } else {
RMPoint destpt; _ctx->starttime = _vm->GetTime();
int deltay; _ctx->deltay = 480 - m_ptDrawPos.y;
int starttime = _vm->GetTime(); _ctx->destpt = m_ptDrawPos;
int elaps;
deltay=480 - m_ptDrawPos.y;
destpt = m_ptDrawPos;
m_ptDrawPos.Set(0, 480); m_ptDrawPos.Set(0, 480);
if (!m_nInList && bigBuf != NULL) if (!m_nInList && bigBuf != NULL)
bigBuf->AddPrim(new RMGfxPrimitive(this)); bigBuf->AddPrim(new RMGfxPrimitive(this));
m_bShow = true; m_bShow = true;
elaps = 0; _ctx->elaps = 0;
while (elaps < 700) { while (_ctx->elaps < 700) {
MainWaitFrame(); CORO_INVOKE_0(MainWaitFrame);
MainFreeze(); MainFreeze();
elaps = _vm->GetTime() - starttime; _ctx->elaps = _vm->GetTime() - _ctx->starttime;
m_ptDrawPos.y = 480 - ((deltay * 100) / 700 * elaps) / 100; m_ptDrawPos.y = 480 - ((_ctx->deltay * 100) / 700 * _ctx->elaps) / 100;
MainUnfreeze(); MainUnfreeze();
} }
m_ptDrawPos.y = destpt.y; m_ptDrawPos.y = _ctx->destpt.y;
} }
CORO_END_CODE;
} }
void RMDialogChoice::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) { void RMDialogChoice::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) {
@ -2489,26 +2522,34 @@ void RMDialogChoice::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) {
} }
void RMDialogChoice::Hide(void) { void RMDialogChoice::Hide(CORO_PARAM) {
if (1) { CORO_BEGIN_CONTEXT;
int deltay; int deltay;
int starttime = _vm->GetTime(); int starttime;
int elaps; int elaps;
CORO_END_CONTEXT(_ctx);
deltay=480 - m_ptDrawPos.y; CORO_BEGIN_CODE(_ctx);
elaps = 0;
while (elaps < 700) { if (1) {
MainWaitFrame(); _ctx->starttime = _vm->GetTime();
_ctx->deltay = 480 - m_ptDrawPos.y;
_ctx->elaps = 0;
while (_ctx->elaps < 700) {
CORO_INVOKE_0(MainWaitFrame);
MainFreeze(); MainFreeze();
elaps=_vm->GetTime()-starttime; _ctx->elaps = _vm->GetTime()-_ctx->starttime;
m_ptDrawPos.y=480-((deltay*100)/700*(700-elaps))/100; m_ptDrawPos.y = 480 - ((_ctx->deltay * 100) / 700 * (700 - _ctx->elaps)) / 100;
MainUnfreeze(); MainUnfreeze();
} }
} }
m_bShow = false; m_bShow = false;
bRemoveFromOT = true; bRemoveFromOT = true;
WaitForSingleObject(hUnreg, INFINITE); CORO_INVOKE_2(g_scheduler->waitForSingleObject, hUnreg, INFINITE);
CORO_END_CODE;
} }

View file

@ -51,6 +51,7 @@
#include "common/system.h" #include "common/system.h"
#include "tony/gfxcore.h" #include "tony/gfxcore.h"
#include "tony/resid.h" #include "tony/resid.h"
#include "tony/sched.h"
namespace Tony { namespace Tony {
@ -247,12 +248,12 @@ class RMTextDialog : public RMText {
int m_time; int m_time;
bool m_bSkipStatus; bool m_bSkipStatus;
RMPoint dst; RMPoint dst;
HANDLE hEndDisplay; uint32 hEndDisplay;
bool m_bShowed; bool m_bShowed;
bool m_bForceTime; bool m_bForceTime;
bool m_bForceNoTime; bool m_bForceNoTime;
HANDLE hCustomSkip; uint32 hCustomSkip;
HANDLE hCustomSkip2; uint32 hCustomSkip2;
RMInput *m_input; RMInput *m_input;
bool m_bAlwaysDisplay; bool m_bAlwaysDisplay;
bool m_bNoTab; bool m_bNoTab;
@ -267,7 +268,7 @@ class RMTextDialog : public RMText {
// Overloading della funzione ereditata da RMGfxTask per decidere // Overloading della funzione ereditata da RMGfxTask per decidere
// quando eliminare un oggetto dalla OTLIST // quando eliminare un oggetto dalla OTLIST
virtual bool RemoveThis(void); virtual void RemoveThis(CORO_PARAM, bool &result);
// Overloading della funzione di deregistrazione, utilizzata per capire // Overloading della funzione di deregistrazione, utilizzata per capire
// quando ci leviamo di torno // quando ci leviamo di torno
@ -280,9 +281,9 @@ class RMTextDialog : public RMText {
void SetPosition(RMPoint pt) { dst=pt; } void SetPosition(RMPoint pt) { dst=pt; }
// Aspetta che venga finita la visualizzazione // Aspetta che venga finita la visualizzazione
void WaitForEndDisplay(void); void WaitForEndDisplay(CORO_PARAM);
void SetCustomSkipHandle(HANDLE hCustomSkip); void SetCustomSkipHandle(uint32 hCustomSkip);
void SetCustomSkipHandle2(HANDLE hCustomSkip); void SetCustomSkipHandle2(uint32 hCustomSkip);
void SetSkipStatus(bool bEnabled); void SetSkipStatus(bool bEnabled);
void SetForcedTime(uint32 dwTime); void SetForcedTime(uint32 dwTime);
void SetNoTab(void); void SetNoTab(void);
@ -294,7 +295,7 @@ class RMTextDialog : public RMText {
void SetInput(RMInput* input); void SetInput(RMInput* input);
void Show(void); void Show(void);
void Hide(void); void Hide(CORO_PARAM);
}; };
class RMTextDialogScrolling : public RMTextDialog { class RMTextDialogScrolling : public RMTextDialog {
@ -332,7 +333,7 @@ public:
void SetMouseCoord(RMPoint m) { m_mpos=m; } void SetMouseCoord(RMPoint m) { m_mpos=m; }
void DoFrame(RMGfxTargetBuffer &bigBuf, RMLocation &loc, RMPointer &ptr, RMInventory &inv); void DoFrame(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMLocation &loc, RMPointer &ptr, RMInventory &inv);
virtual void Draw(RMGfxTargetBuffer& bigBuf, RMGfxPrimitive* prim); virtual void Draw(RMGfxTargetBuffer& bigBuf, RMGfxPrimitive* prim);
RMPoint GetHotspot(); RMPoint GetHotspot();
@ -358,7 +359,7 @@ private:
RMGfxSourceBuffer8 DlgText; RMGfxSourceBuffer8 DlgText;
RMGfxSourceBuffer8 DlgTextLine; RMGfxSourceBuffer8 DlgTextLine;
RMPoint m_ptDrawPos; RMPoint m_ptDrawPos;
HANDLE hUnreg; uint32 hUnreg;
bool bRemoveFromOT; bool bRemoveFromOT;
protected: protected:
@ -389,8 +390,8 @@ public:
// Mostra e nasconde la scelta, con eventuali animazioni // Mostra e nasconde la scelta, con eventuali animazioni
// NOTA: Se non viene passato parametro alla Show(), è obbligo del // NOTA: Se non viene passato parametro alla Show(), è obbligo del
// chiamante assicurarsi che la classe venga inserita alla OTlist // chiamante assicurarsi che la classe venga inserita alla OTlist
void Show(RMGfxTargetBuffer* bigBuf = NULL); void Show(CORO_PARAM, RMGfxTargetBuffer* bigBuf = NULL);
void Hide(void); void Hide(CORO_PARAM);
// Polling di aggiornamento // Polling di aggiornamento
void DoFrame(RMPoint ptMousePos); void DoFrame(RMPoint ptMousePos);

View file

@ -112,8 +112,8 @@ void MainUnfreeze(void) {
_vm->GetEngine()->Unfreeze(); _vm->GetEngine()->Unfreeze();
} }
void MainWaitFrame(void) { void MainWaitFrame(CORO_PARAM) {
WaitForSingleObject(_vm->m_hEndOfFrame, INFINITE); g_scheduler->waitForSingleObject(coroParam, _vm->m_hEndOfFrame, INFINITE);
} }
void MainShowMouse(void) { void MainShowMouse(void) {
@ -144,8 +144,8 @@ void MainCloseWipe(void) {
_vm->GetEngine()->CloseWipe(); _vm->GetEngine()->CloseWipe();
} }
void MainWaitWipeEnd(void) { void MainWaitWipeEnd(CORO_PARAM) {
_vm->GetEngine()->WaitWipeEnd(); _vm->GetEngine()->WaitWipeEnd(coroParam);
} }
void MainEnableGUI(void) { void MainEnableGUI(void) {

View file

@ -65,10 +65,12 @@ extern bool bSkipSfxNoLoop;
bool bIdleExited; bool bIdleExited;
void ExitAllIdles(CORO_PARAM, int nCurLoc) { void ExitAllIdles(CORO_PARAM, const void *param) {
CORO_BEGIN_CONTEXT; CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx); CORO_END_CONTEXT(_ctx);
int nCurLoc = *(const int *)param;
CORO_BEGIN_CODE(_ctx); CORO_BEGIN_CODE(_ctx);
// Chiude le idle // Chiude le idle
@ -96,28 +98,27 @@ RMGfxEngine::~RMGfxEngine() {
g_system->deleteMutex(csMainLoop); g_system->deleteMutex(csMainLoop);
} }
void RMGfxEngine::OpenOptionScreen(int type) { void RMGfxEngine::OpenOptionScreen(CORO_PARAM, int type) {
bool bRes = false; CORO_BEGIN_CONTEXT;
bool bRes;
CORO_END_CONTEXT(_ctx);
switch (type) { CORO_BEGIN_CODE(_ctx);
case 0:
bRes = m_opt.Init(m_bigBuf);
break;
case 1:
bRes = m_opt.InitLoadMenuOnly(m_bigBuf,true);
break;
case 2:
bRes = m_opt.InitNoLoadSave(m_bigBuf);
break;
case 3:
bRes = m_opt.InitLoadMenuOnly(m_bigBuf,false);
break;
case 4:
bRes = m_opt.InitSaveMenuOnly(m_bigBuf,false);
break;
}
if (bRes) { _ctx->bRes = false;
if (type == 0)
_ctx->bRes = m_opt.Init(m_bigBuf);
else if (type == 1)
_ctx->bRes = m_opt.InitLoadMenuOnly(m_bigBuf, true);
else if (type == 2)
_ctx->bRes = m_opt.InitNoLoadSave(m_bigBuf);
else if (type == 3)
_ctx->bRes = m_opt.InitLoadMenuOnly(m_bigBuf, false);
else if (type == 4)
_ctx->bRes = m_opt.InitSaveMenuOnly(m_bigBuf, false);
if (_ctx->bRes) {
_vm->PauseSound(true); _vm->PauseSound(true);
DisableInput(); DisableInput();
@ -135,16 +136,23 @@ void RMGfxEngine::OpenOptionScreen(int type) {
if (type == 1 || type == 2) { if (type == 1 || type == 2) {
bIdleExited = true; bIdleExited = true;
} else { } else {
m_tony.StopNoAction(); CORO_INVOKE_0(m_tony.StopNoAction);
uint32 id;
bIdleExited = false; bIdleExited = false;
CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)ExitAllIdles, (void *)m_nCurLoc, 0, &id);
g_scheduler->createProcess(ExitAllIdles, &m_nCurLoc, sizeof(int));
} }
} }
CORO_END_CODE;
} }
void RMGfxEngine::DoFrame(bool bDrawLocation) { void RMGfxEngine::DoFrame(CORO_PARAM, bool bDrawLocation) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
g_system->lockMutex(csMainLoop); g_system->lockMutex(csMainLoop);
// Poll dei dispositivi di input // Poll dei dispositivi di input
@ -212,15 +220,15 @@ void RMGfxEngine::DoFrame(bool bDrawLocation) {
if (m_bGUIOption) { if (m_bGUIOption) {
if (!m_tony.InAction() && m_bInput) { if (!m_tony.InAction() && m_bInput) {
if ((m_input.MouseLeftClicked() && m_input.MousePos().x < 3 && m_input.MousePos().y < 3)) { if ((m_input.MouseLeftClicked() && m_input.MousePos().x < 3 && m_input.MousePos().y < 3)) {
OpenOptionScreen(0); OpenOptionScreen(nullContext, 0);
goto SKIPCLICKSINISTRO; goto SKIPCLICKSINISTRO;
} else if ((GetAsyncKeyState(Common::KEYCODE_ESCAPE)&0x8001) == 0x8001) } else if ((GetAsyncKeyState(Common::KEYCODE_ESCAPE)&0x8001) == 0x8001)
OpenOptionScreen(0); OpenOptionScreen(nullContext, 0);
else if (_vm->getIsDemo()) { else if (_vm->getIsDemo()) {
if ((GetAsyncKeyState(Common::KEYCODE_F3) & 0x8001) == 0x8001) if ((GetAsyncKeyState(Common::KEYCODE_F3) & 0x8001) == 0x8001)
OpenOptionScreen(3); OpenOptionScreen(nullContext, 3);
else if ((GetAsyncKeyState(Common::KEYCODE_F2) & 0x8001) == 0x8001) else if ((GetAsyncKeyState(Common::KEYCODE_F2) & 0x8001) == 0x8001)
OpenOptionScreen(4); OpenOptionScreen(nullContext, 4);
} }
} }
} }
@ -287,7 +295,7 @@ SKIPCLICKSINISTRO:
// Aggiorna il nome sotto il puntatore del mouse // Aggiorna il nome sotto il puntatore del mouse
m_itemName.SetMouseCoord(m_input.MousePos()); m_itemName.SetMouseCoord(m_input.MousePos());
if (!m_inter.Active() && !m_inv.MiniActive()) if (!m_inter.Active() && !m_inv.MiniActive())
m_itemName.DoFrame(m_bigBuf,m_loc,m_point,m_inv); CORO_INVOKE_4(m_itemName.DoFrame, m_bigBuf, m_loc, m_point, m_inv);
} }
// Inventario & interfaccia // Inventario & interfaccia
@ -325,7 +333,7 @@ SKIPCLICKSINISTRO:
switch (m_nWipeType) { switch (m_nWipeType) {
case 1: case 1:
if (!(m_rcWipeEllipse.bottom - m_rcWipeEllipse.top >= FSTEP * 2)) { if (!(m_rcWipeEllipse.bottom - m_rcWipeEllipse.top >= FSTEP * 2)) {
SetEvent(m_hWipeEvent); g_scheduler->setEvent(m_hWipeEvent);
m_nWipeType = 3; m_nWipeType = 3;
break; break;
} }
@ -338,7 +346,7 @@ SKIPCLICKSINISTRO:
case 2: case 2:
if (!(m_rcWipeEllipse.bottom - m_rcWipeEllipse.top < 480 - FSTEP)) { if (!(m_rcWipeEllipse.bottom - m_rcWipeEllipse.top < 480 - FSTEP)) {
SetEvent(m_hWipeEvent); g_scheduler->setEvent(m_hWipeEvent);
m_nWipeType = 3; m_nWipeType = 3;
break; break;
} }
@ -352,6 +360,8 @@ SKIPCLICKSINISTRO:
} }
g_system->unlockMutex(csMainLoop); g_system->unlockMutex(csMainLoop);
CORO_END_CODE;
} }
@ -524,7 +534,7 @@ HANDLE RMGfxEngine::LoadLocation(int nLoc, RMPoint ptTonyStart, RMPoint start) {
void RMGfxEngine::UnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result) { void RMGfxEngine::UnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result) {
CORO_BEGIN_CONTEXT; CORO_BEGIN_CONTEXT;
HANDLE h; uint32 h;
CORO_END_CONTEXT(_ctx); CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx); CORO_BEGIN_CODE(_ctx);
@ -534,9 +544,9 @@ void RMGfxEngine::UnloadLocation(CORO_PARAM, bool bDoOnExit, HANDLE *result) {
// On Exit? // On Exit?
if (bDoOnExit) { if (bDoOnExit) {
_ctx->h = mpalQueryDoAction(1, m_nCurLoc, 0); _ctx->h = mpalQueryDoActionU32(1, m_nCurLoc, 0);
if (_ctx->h != INVALID_HANDLE_VALUE) if (_ctx->h != INVALID_PID_VALUE)
WaitForSingleObject(_ctx->h, INFINITE); CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
} }
MainFreeze(); MainFreeze();
@ -588,7 +598,7 @@ void RMGfxEngine::Init(/*HINSTANCE hInst*/) {
bIdleExited = false; bIdleExited = false;
m_bOption = false; m_bOption = false;
m_bWiping = false; m_bWiping = false;
m_hWipeEvent = CreateEvent(NULL, false, false, NULL); m_hWipeEvent = g_scheduler->createEvent(false, false);
// Crea l'evento di freeze // Crea l'evento di freeze
csMainLoop = g_system->createMutex(); csMainLoop = g_system->createMutex();
@ -986,8 +996,8 @@ void RMGfxEngine::CloseWipe(void) {
m_bWiping = false; m_bWiping = false;
} }
void RMGfxEngine::WaitWipeEnd(void) { void RMGfxEngine::WaitWipeEnd(CORO_PARAM) {
WaitForSingleObject(m_hWipeEvent,INFINITE); g_scheduler->waitForSingleObject(coroParam, m_hWipeEvent, INFINITE);
} }
} // End of namespace Tony } // End of namespace Tony

View file

@ -85,7 +85,7 @@ private:
OSystem::MutexRef csMainLoop; OSystem::MutexRef csMainLoop;
int m_nWipeType; int m_nWipeType;
HANDLE m_hWipeEvent; uint32 m_hWipeEvent;
int m_nWipeStep; int m_nWipeStep;
bool m_bMustEnterMenu; bool m_bMustEnterMenu;
@ -103,7 +103,7 @@ public:
virtual ~RMGfxEngine(); virtual ~RMGfxEngine();
// Draw the next frame // Draw the next frame
void DoFrame(bool bDrawLocation); void DoFrame(CORO_PARAM, bool bDrawLocation);
// Initialises the graphics engine // Initialises the graphics engine
void Init(); void Init();
@ -118,7 +118,7 @@ public:
void GDIControl(bool bCon); void GDIControl(bool bCon);
// Warns when entering or exits the options menu // Warns when entering or exits the options menu
void OpenOptionScreen(int type); void OpenOptionScreen(CORO_PARAM, int type);
// Enables or disables mouse input // Enables or disables mouse input
void EnableInput(void); void EnableInput(void);
@ -157,7 +157,7 @@ public:
// Wipe // Wipe
void InitWipe(int type); void InitWipe(int type);
void CloseWipe(void); void CloseWipe(void);
void WaitWipeEnd(void); void WaitWipeEnd(CORO_PARAM);
void SetPalesati(bool bpal) { m_inter.SetPalesati(bpal); } void SetPalesati(bool bpal) { m_inter.SetPalesati(bpal); }
}; };

View file

@ -248,12 +248,12 @@ int RMPattern::Init(RMSfx *sfx, bool bPlayP0, byte *bFlag) {
return m_nCurSprite; return m_nCurSprite;
} }
int RMPattern::Update(HANDLE hEndPattern, byte &bFlag, RMSfx *sfx) { int RMPattern::Update(uint32 hEndPattern, byte &bFlag, RMSfx *sfx) {
int CurTime = _vm->GetTime(); int CurTime = _vm->GetTime();
// Se la speed e' 0, il pattern non avanza mai // Se la speed e' 0, il pattern non avanza mai
if (m_speed == 0) { if (m_speed == 0) {
PulseEvent(hEndPattern); g_scheduler->pulseEvent(hEndPattern);
bFlag=m_slots[m_nCurSlot].m_flag; bFlag=m_slots[m_nCurSlot].m_flag;
return m_nCurSprite; return m_nCurSprite;
} }
@ -266,7 +266,8 @@ int RMPattern::Update(HANDLE hEndPattern, byte &bFlag, RMSfx *sfx) {
if (m_nCurSlot == m_nSlots) { if (m_nCurSlot == m_nSlots) {
m_nCurSlot = 0; m_nCurSlot = 0;
bFlag = m_slots[m_nCurSlot].m_flag; bFlag = m_slots[m_nCurSlot].m_flag;
PulseEvent(hEndPattern);
g_scheduler->pulseEvent(hEndPattern);
// @@@ Se non c'e' loop avverte che il pattern e' finito // @@@ Se non c'e' loop avverte che il pattern e' finito
// Se non c'e' loop rimane sull'ultimo frame // Se non c'e' loop rimane sull'ultimo frame
@ -705,9 +706,8 @@ bool RMItem::DoFrame(RMGfxTargetBuffer *bigBuf, bool bAddToList) {
return false; return false;
// Facciamo un update del pattern, che ci ritorna anche il frame corrente // Facciamo un update del pattern, che ci ritorna anche il frame corrente
// FIXME: Get rid of HANDLE cast
if (m_nCurPattern != 0) if (m_nCurPattern != 0)
m_nCurSprite = m_patterns[m_nCurPattern].Update((HANDLE)m_hEndPattern, m_bCurFlag, m_sfx); m_nCurSprite = m_patterns[m_nCurPattern].Update(m_hEndPattern, m_bCurFlag, m_sfx);
// Se la funzione ha ritornato -1, vuol dire che il pattern e' finito // Se la funzione ha ritornato -1, vuol dire che il pattern e' finito
if (m_nCurSprite == -1) { if (m_nCurSprite == -1) {
@ -844,7 +844,7 @@ RMItem::~RMItem() {
} }
//FIXME: Pass uint32 directly for hCustomSkip //FIXME: Pass uint32 directly for hCustomSkip
void RMItem::WaitForEndPattern(CORO_PARAM, HANDLE hCustomSkip) { void RMItem::WaitForEndPattern(CORO_PARAM, uint32 hCustomSkip) {
CORO_BEGIN_CONTEXT; CORO_BEGIN_CONTEXT;
uint32 h[2]; uint32 h[2];
CORO_END_CONTEXT(_ctx); CORO_END_CONTEXT(_ctx);
@ -852,10 +852,10 @@ void RMItem::WaitForEndPattern(CORO_PARAM, HANDLE hCustomSkip) {
CORO_BEGIN_CODE(_ctx); CORO_BEGIN_CODE(_ctx);
if (m_nCurPattern != 0) { if (m_nCurPattern != 0) {
if (hCustomSkip == INVALID_HANDLE_VALUE) if (hCustomSkip == INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, m_hEndPattern, INFINITE); CORO_INVOKE_2(g_scheduler->waitForSingleObject, m_hEndPattern, INFINITE);
else { else {
_ctx->h[0] = (uint32)hCustomSkip; _ctx->h[0] = hCustomSkip;
_ctx->h[1] = m_hEndPattern; _ctx->h[1] = m_hEndPattern;
CORO_INVOKE_4(g_scheduler->waitForMultipleObjects, 2, &_ctx->h[0], false, INFINITE); CORO_INVOKE_4(g_scheduler->waitForMultipleObjects, 2, &_ctx->h[0], false, INFINITE);
} }
@ -888,13 +888,13 @@ void RMItem::PauseSound(bool bPause) {
RMWipe::RMWipe() { RMWipe::RMWipe() {
m_hUnregistered=CreateEvent(NULL,false,false,NULL); m_hUnregistered = g_scheduler->createEvent(false, false);
m_hEndOfFade=CreateEvent(NULL,false,false,NULL); m_hEndOfFade = g_scheduler->createEvent(false, false);
} }
RMWipe::~RMWipe() { RMWipe::~RMWipe() {
CloseHandle(m_hUnregistered); g_scheduler->closeEvent(m_hUnregistered);
CloseHandle(m_hEndOfFade); g_scheduler->closeEvent(m_hEndOfFade);
} }
int RMWipe::Priority(void) { int RMWipe::Priority(void) {
@ -904,19 +904,28 @@ int RMWipe::Priority(void) {
void RMWipe::Unregister(void) { void RMWipe::Unregister(void) {
RMGfxTask::Unregister(); RMGfxTask::Unregister();
assert(m_nInList == 0); assert(m_nInList == 0);
SetEvent(m_hUnregistered); g_scheduler->setEvent(m_hUnregistered);
} }
bool RMWipe::RemoveThis(void) { bool RMWipe::RemoveThis(void) {
return m_bUnregister; return m_bUnregister;
} }
void RMWipe::WaitForFadeEnd(void) { void RMWipe::WaitForFadeEnd(CORO_PARAM) {
WaitForSingleObject(m_hEndOfFade, INFINITE); CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
CORO_INVOKE_2(g_scheduler->waitForSingleObject, m_hEndOfFade, INFINITE);
m_bEndFade = true; m_bEndFade = true;
m_bFading = false; m_bFading = false;
MainWaitFrame();
MainWaitFrame(); CORO_INVOKE_0(MainWaitFrame);
CORO_INVOKE_0(MainWaitFrame);
CORO_END_CODE;
} }
void RMWipe::CloseFade(void) { void RMWipe::CloseFade(void) {
@ -958,7 +967,7 @@ void RMWipe::DoFrame(RMGfxTargetBuffer &bigBuf) {
m_nFadeStep++; m_nFadeStep++;
if (m_nFadeStep == 10) { if (m_nFadeStep == 10) {
SetEvent(m_hEndOfFade); g_scheduler->setEvent(m_hEndOfFade);
} }
} }
} }

View file

@ -171,7 +171,7 @@ public:
// Update the pattern, checking to see if it's time to change slot and executing // Update the pattern, checking to see if it's time to change slot and executing
// any associated commands // any associated commands
int Update(HANDLE hEndPattern, byte& bFlag, RMSfx* sfx); int Update(uint32 hEndPattern, byte &bFlag, RMSfx *sfx);
// Stop a sound effect // Stop a sound effect
void StopSfx(RMSfx *sfx); void StopSfx(RMSfx *sfx);
@ -292,7 +292,7 @@ public:
void Unload(void); void Unload(void);
// Aspetta la fine del pattern in play // Aspetta la fine del pattern in play
void WaitForEndPattern(CORO_PARAM, HANDLE hCustomSkip = INVALID_HANDLE_VALUE); void WaitForEndPattern(CORO_PARAM, uint32 hCustomSkip = INVALID_PID_VALUE);
// Setta un nuovo hotspot per l'oggetto // Setta un nuovo hotspot per l'oggetto
void ChangeHotspot(RMPoint pt); void ChangeHotspot(RMPoint pt);
@ -494,9 +494,9 @@ private:
bool m_bFading; bool m_bFading;
bool m_bEndFade; bool m_bEndFade;
bool m_bUnregister; bool m_bUnregister;
HANDLE m_hUnregistered; uint32 m_hUnregistered;
int m_nFadeStep; int m_nFadeStep;
HANDLE m_hEndOfFade; uint32 m_hEndOfFade;
bool m_bMustRegister; bool m_bMustRegister;
RMItem m_wip0r; RMItem m_wip0r;
@ -510,7 +510,7 @@ public:
void InitFade(int type); void InitFade(int type);
void CloseFade(void); void CloseFade(void);
void WaitForFadeEnd(void); void WaitForFadeEnd(CORO_PARAM);
virtual void Unregister(void); virtual void Unregister(void);
virtual bool RemoveThis(void); virtual bool RemoveThis(void);

View file

@ -174,10 +174,8 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) {
/* Periodi */ /* Periodi */
num = READ_LE_UINT16(lpBuf); lpBuf += 2; num = READ_LE_UINT16(lpBuf); lpBuf += 2;
if (num >= MAX_PERIODS_PER_DIALOG - 1) { if (num >= MAX_PERIODS_PER_DIALOG - 1)
Common::String msg = Common::String::format("Too much periods in dialog #%d", lpmdDialog->nObj); error("Too much periods in dialog #%d", lpmdDialog->nObj);
MessageBox(msg);
}
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
lpmdDialog->PeriodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2; lpmdDialog->PeriodNums[i] = READ_LE_UINT16(lpBuf); lpBuf += 2;
@ -195,19 +193,15 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) {
num = READ_LE_UINT16(lpBuf); lpBuf += 2; num = READ_LE_UINT16(lpBuf); lpBuf += 2;
curCmd = 0; curCmd = 0;
if (num >= MAX_GROUPS_PER_DIALOG) { if (num >= MAX_GROUPS_PER_DIALOG)
Common::String msg = Common::String::format("Too much groups in dialog #%d", lpmdDialog->nObj); error("Too much groups in dialog #%d", lpmdDialog->nObj);
MessageBox(msg);
}
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
lpmdDialog->Group[i].num = READ_LE_UINT16(lpBuf); lpBuf += 2; lpmdDialog->Group[i].num = READ_LE_UINT16(lpBuf); lpBuf += 2;
lpmdDialog->Group[i].nCmds = *lpBuf; lpBuf++; lpmdDialog->Group[i].nCmds = *lpBuf; lpBuf++;
if (lpmdDialog->Group[i].nCmds >= MAX_COMMANDS_PER_GROUP) { if (lpmdDialog->Group[i].nCmds >= MAX_COMMANDS_PER_GROUP)
Common::String msg = Common::String::format("Too much commands in group #%d in dialog #%d",lpmdDialog->Group[i].num,lpmdDialog->nObj); error("Too much commands in group #%d in dialog #%d",lpmdDialog->Group[i].num,lpmdDialog->nObj);
MessageBox(msg);
}
for (j = 0; j < lpmdDialog->Group[i].nCmds; j++) { for (j = 0; j < lpmdDialog->Group[i].nCmds; j++) {
lpmdDialog->Command[curCmd].type = *lpBuf; lpmdDialog->Command[curCmd].type = *lpBuf;
@ -262,28 +256,22 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) {
} }
} }
if (curCmd >= MAX_COMMANDS_PER_DIALOG) { if (curCmd >= MAX_COMMANDS_PER_DIALOG)
Common::String msg = Common::String::format("Too much commands in dialog #%d",lpmdDialog->nObj); error("Too much commands in dialog #%d",lpmdDialog->nObj);
MessageBox(msg);
}
/* Choices */ /* Choices */
num=*(uint16 *)lpBuf; lpBuf += 2; num=*(uint16 *)lpBuf; lpBuf += 2;
if (num >= MAX_CHOICES_PER_DIALOG) { if (num >= MAX_CHOICES_PER_DIALOG)
Common::String msg = Common::String::format("Too much choices in dialog #%d",lpmdDialog->nObj); error("Too much choices in dialog #%d",lpmdDialog->nObj);
MessageBox(msg);
}
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
lpmdDialog->Choice[i].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2; lpmdDialog->Choice[i].nChoice = READ_LE_UINT16(lpBuf); lpBuf += 2;
num2 = *lpBuf++; num2 = *lpBuf++;
if (num2 >= MAX_SELECTS_PER_CHOICE) { if (num2 >= MAX_SELECTS_PER_CHOICE)
Common::String msg = Common::String::format("Too much selects in choice #%d in dialog #%d",lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj); error("Too much selects in choice #%d in dialog #%d",lpmdDialog->Choice[i].nChoice,lpmdDialog->nObj);
MessageBox(msg);
}
for (j = 0; j < num2; j++) { for (j = 0; j < num2; j++) {
// When // When
@ -311,10 +299,8 @@ static const byte *ParseDialog(const byte *lpBuf, LPMPALDIALOG lpmdDialog) {
// PlayGroup // PlayGroup
num3 = *lpBuf; *lpBuf++; num3 = *lpBuf; *lpBuf++;
if (num3 >= MAX_PLAYGROUPS_PER_SELECT) { if (num3 >= MAX_PLAYGROUPS_PER_SELECT)
Common::String msg = Common::String::format("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->Choice[i].nChoice, lpmdDialog->nObj); error("Too much playgroups in select #%d in choice #%d in dialog #%d", j, lpmdDialog->Choice[i].nChoice, lpmdDialog->nObj);
MessageBox(msg);
}
for (z = 0; z < num3; z++) { for (z = 0; z < num3; z++) {
lpmdDialog->Choice[i].Select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2; lpmdDialog->Choice[i].Select[j].wPlayGroup[z] = READ_LE_UINT16(lpBuf); lpBuf += 2;
@ -365,10 +351,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) {
CopyMemory(lpmiItem->lpszDescribe,lpBuf, MIN((byte)127, len)); CopyMemory(lpmiItem->lpszDescribe,lpBuf, MIN((byte)127, len));
lpBuf+=len; lpBuf+=len;
if (len >= MAX_DESCRIBE_SIZE) { if (len >= MAX_DESCRIBE_SIZE)
Common::String msg = Common::String::format("Describe too long in item #%d",lpmiItem->nObj); error("Describe too long in item #%d",lpmiItem->nObj);
MessageBox(msg);
}
lpmiItem->nActions=*lpBuf; lpmiItem->nActions=*lpBuf;
lpBuf++; lpBuf++;
@ -408,10 +392,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) {
lpmiItem->Action[i].nCmds=*lpBuf; lpmiItem->Action[i].nCmds=*lpBuf;
lpBuf++; lpBuf++;
if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION) { if (lpmiItem->Action[i].nCmds >= MAX_COMMANDS_PER_ACTION)
Common::String msg = Common::String::format("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj); error("Too much commands in action #%d in item #%d",lpmiItem->Action[i].num,lpmiItem->nObj);
MessageBox(msg);
}
for (j=0;j<lpmiItem->Action[i].nCmds;j++) { for (j=0;j<lpmiItem->Action[i].nCmds;j++) {
lpmiItem->Command[curCmd].type=*lpBuf; lpmiItem->Command[curCmd].type=*lpBuf;
@ -455,9 +437,8 @@ static const byte *ParseItem(const byte *lpBuf, LPMPALITEM lpmiItem) {
curCmd++; curCmd++;
if (curCmd >= MAX_COMMANDS_PER_ITEM) { if (curCmd >= MAX_COMMANDS_PER_ITEM) {
Common::String msg = Common::String::format("Too much commands in item #%d",lpmiItem->nObj); error("Too much commands in item #%d",lpmiItem->nObj);
MessageBox(msg); //curCmd=0;
curCmd=0;
} }
} }
} }

View file

@ -137,9 +137,9 @@ uint32 * lpResources;
bool bExecutingAction; bool bExecutingAction;
bool bExecutingDialog; bool bExecutingDialog;
uint32 nPollingLocations[MAXPOLLINGLOCATIONS]; uint32 nPollingLocations[MAXPOLLINGLOCATIONS];
HANDLE hEndPollingLocations[MAXPOLLINGLOCATIONS]; uint32 hEndPollingLocations[MAXPOLLINGLOCATIONS];
uint32 PollingThreads[MAXPOLLINGLOCATIONS]; uint32 PollingThreads[MAXPOLLINGLOCATIONS];
uint32 hAskChoice; uint32 hAskChoice;
uint32 hDoneChoice; uint32 hDoneChoice;
@ -830,14 +830,20 @@ static LPITEM GetItemData(uint32 nOrdItem) {
* *
\****************************************************************************/ \****************************************************************************/
void PASCAL CustomThread(LPCFCALL p) { void CustomThread(CORO_PARAM, const void *param) {
// FIXME: Convert to proper corotuine call CORO_BEGIN_CONTEXT;
warning("FIXME: CustomThread call"); LPCFCALL p;
CORO_END_CONTEXT(_ctx);
lplpFunctions[p->nCf](nullContext, p->arg1, p->arg2, p->arg3, p->arg4); CORO_BEGIN_CODE(_ctx);
GlobalFree(p);
ExitThread(1); _ctx->p = *(LPCFCALL *)param;
// _endthread();
CORO_INVOKE_4(lplpFunctions[_ctx->p->nCf], _ctx->p->arg1, _ctx->p->arg2, _ctx->p->arg3, _ctx->p->arg4);
GlobalFree(_ctx->p);
CORO_END_CODE;
} }
@ -855,78 +861,87 @@ void PASCAL CustomThread(LPCFCALL p) {
* *
\****************************************************************************/ \****************************************************************************/
void PASCAL ScriptThread(LPMPALSCRIPT s) { void ScriptThread(CORO_PARAM, const void *param) {
uint i,j,k; CORO_BEGIN_CONTEXT;
uint32 dwStartTime = timeGetTime(); uint i, j, k;
uint32 dwCurTime; uint32 dwStartTime;
uint32 dwId; uint32 dwCurTime;
static HANDLE cfHandles[MAX_COMMANDS_PER_MOMENT]; uint32 dwId;
int numHandles = 0; int numHandles;
LPCFCALL p; LPCFCALL p;
CORO_END_CONTEXT(_ctx);
static uint32 cfHandles[MAX_COMMANDS_PER_MOMENT];
LPMPALSCRIPT s = *(const LPMPALSCRIPT *)param;
CORO_BEGIN_CODE(_ctx);
_ctx->dwStartTime = _vm->GetTime();
_ctx->numHandles = 0;
// warning("PlayScript(): Moments: %u\n",s->nMoments); // warning("PlayScript(): Moments: %u\n",s->nMoments);
for (i = 0; i < s->nMoments; i++) { for (_ctx->i = 0; _ctx->i < s->nMoments; _ctx->i++) {
// Dorme il tempo necessario per arrivare al momento successivo // Dorme il tempo necessario per arrivare al momento successivo
if (s->Moment[i].dwTime == -1) { if (s->Moment[_ctx->i].dwTime == -1) {
WaitForMultipleObjects(numHandles, cfHandles, true, INFINITE); CORO_INVOKE_4(g_scheduler->waitForMultipleObjects, _ctx->numHandles, cfHandles, true, INFINITE);
dwStartTime = timeGetTime(); _ctx->dwStartTime = _vm->GetTime();
} else { } else {
dwCurTime = timeGetTime(); _ctx->dwCurTime = _vm->GetTime();
if (dwCurTime < dwStartTime + (s->Moment[i].dwTime * 100)) { if (_ctx->dwCurTime < _ctx->dwStartTime + (s->Moment[_ctx->i].dwTime * 100)) {
// warning("PlayScript(): Sleeping %lums\n",dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime); // warning("PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime);
Sleep(dwStartTime+(s->Moment[i].dwTime * 100) - dwCurTime); CORO_INVOKE_1(g_scheduler->sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime);
} }
} }
numHandles = 0; _ctx->numHandles = 0;
for (j = 0;j<s->Moment[i].nCmds; j++) { for (_ctx->j = 0; _ctx->j<s->Moment[_ctx->i].nCmds; _ctx->j++) {
k=s->Moment[i].CmdNum[j]; _ctx->k = s->Moment[_ctx->i].CmdNum[_ctx->j];
switch (s->Command[k].type) { if (s->Command[_ctx->k].type == 1) {
case 1: _ctx->p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL));
p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL)); if (_ctx->p == NULL) {
if (p == NULL) {
mpalError = 1; mpalError = 1;
ExitThread(0);
// _endthread(); CORO_KILL_SELF();
return;
} }
p->nCf=s->Command[k].nCf; _ctx->p->nCf=s->Command[_ctx->k].nCf;
p->arg1=s->Command[k].arg1; _ctx->p->arg1=s->Command[_ctx->k].arg1;
p->arg2=s->Command[k].arg2; _ctx->p->arg2=s->Command[_ctx->k].arg2;
p->arg3=s->Command[k].arg3; _ctx->p->arg3=s->Command[_ctx->k].arg3;
p->arg4=s->Command[k].arg4; _ctx->p->arg4=s->Command[_ctx->k].arg4;
// !!! Nuova gestione dei thread // !!! Nuova gestione dei thread
if ((cfHandles[numHandles++] = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)CustomThread,(void *)p, 0, &dwId)) == NULL) { if ((cfHandles[_ctx->numHandles++] = g_scheduler->createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) {
//if ((cfHandles[numHandles++]=(void*)_beginthread(CustomThread, 10240, (void *)p))==(void*)-1)
mpalError = 1; mpalError = 1;
ExitThread(0);
// _endthread();
}
break;
case 2: CORO_KILL_SELF();
return;
}
} else if (s->Command[_ctx->k].type == 2) {
LockVar(); LockVar();
varSetValue( varSetValue(
s->Command[k].lpszVarName, s->Command[_ctx->k].lpszVarName,
EvaluateExpression(s->Command[k].expr) EvaluateExpression(s->Command[_ctx->k].expr)
); );
UnlockVar(); UnlockVar();
break;
default: } else {
mpalError = 1; mpalError = 1;
GlobalFree(s); GlobalFree(s);
ExitThread(0);
// _endthread(); CORO_KILL_SELF();
return;
} }
} }
} }
GlobalFree(s); GlobalFree(s);
ExitThread(1);
//_endthread(); CORO_KILL_SELF();
CORO_END_CODE;
} }
@ -1063,6 +1078,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
uint32 dwId; uint32 dwId;
int ord; int ord;
bool delayExpired; bool delayExpired;
bool expired;
MYACTION *MyActions; MYACTION *MyActions;
MYTHREAD *MyThreads; MYTHREAD *MyThreads;
@ -1122,7 +1138,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
} }
/* Inizializziamo le routine random */ /* Inizializziamo le routine random */
//curTime = timeGetTime(); //curTime = _vm->GetTime();
//srand(curTime); //srand(curTime);
@ -1157,7 +1173,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
CopyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum, CopyMemory(_ctx->MyActions[_ctx->k].CmdNum, _ctx->curItem->Action[_ctx->j].CmdNum,
MAX_COMMANDS_PER_ACTION * sizeof(uint16)); MAX_COMMANDS_PER_ACTION * sizeof(uint16));
_ctx->MyActions[_ctx->k].dwLastTime = timeGetTime(); _ctx->MyActions[_ctx->k].dwLastTime = _vm->GetTime();
_ctx->k++; _ctx->k++;
} }
} }
@ -1172,7 +1188,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
while (1) { while (1) {
/* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per /* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per
l'esecuzione */ l'esecuzione */
_ctx->curTime = timeGetTime(); _ctx->curTime = _vm->GetTime();
_ctx->dwSleepTime = (uint32)-1L; _ctx->dwSleepTime = (uint32)-1L;
for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++) for (_ctx->k = 0;_ctx->k<_ctx->nIdleActions;_ctx->k++)
@ -1184,8 +1200,11 @@ void LocationPollThread(CORO_PARAM, const void *param) {
/* Ci addormentiamo, ma controllando sempre l'evento che viene settato /* Ci addormentiamo, ma controllando sempre l'evento che viene settato
quando viene richiesta la nostra chiusura */ quando viene richiesta la nostra chiusura */
_ctx->k = WaitForSingleObject(hEndPollingLocations[id], _ctx->dwSleepTime);
if (_ctx->k == WAIT_OBJECT_0) CORO_INVOKE_3(g_scheduler->waitForSingleObject, hEndPollingLocations[id], _ctx->dwSleepTime, &_ctx->expired);
//if (_ctx->k == WAIT_OBJECT_0)
if (!_ctx->expired)
break; break;
for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++) for (_ctx->i = 0; _ctx->i < _ctx->nRealItems; _ctx->i++)
@ -1197,7 +1216,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
_ctx->MyThreads[_ctx->i].nItem = 0; _ctx->MyThreads[_ctx->i].nItem = 0;
} }
_ctx->curTime = timeGetTime(); _ctx->curTime = _vm->GetTime();
/* Cerchiamo all'interno delle idle actions quale e' necessario eseguire */ /* Cerchiamo all'interno delle idle actions quale e' necessario eseguire */
for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++) for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++)
@ -2163,10 +2182,9 @@ bool EXPORT mpalExecuteScript(int nScript) {
CopyMemory(s, lpmsScripts+n, sizeof(MPALSCRIPT)); CopyMemory(s, lpmsScripts+n, sizeof(MPALSCRIPT));
UnlockScripts(); UnlockScripts();
// !!! Nuova gestione dei thread // !!! Nuova gestione dei thread
if (CreateThread(NULL, 10240,(LPTHREAD_START_ROUTINE)ScriptThread,(void *)s, 0, &dwId) == NULL) if (g_scheduler->createProcess(ScriptThread, &s, sizeof(LPMPALSCRIPT)) == INVALID_PID_VALUE)
//if ((void*)_beginthread(ScriptThread, 10240,(void *)s)==(void*)-1) return false;
return false;
return true; return true;
} }
@ -2213,9 +2231,9 @@ bool mpalStartIdlePoll(int nLoc) {
for (i = 0; i < MAXPOLLINGLOCATIONS; i++) { for (i = 0; i < MAXPOLLINGLOCATIONS; i++) {
if (nPollingLocations[i] == 0) { if (nPollingLocations[i] == 0) {
nPollingLocations[i]=nLoc; nPollingLocations[i] = nLoc;
hEndPollingLocations[i] = CreateEvent(NULL, true, false, NULL); hEndPollingLocations[i] = g_scheduler->createEvent(true, false);
// !!! Nuova gestione dei thread // !!! Nuova gestione dei thread
if ((PollingThreads[i] = g_scheduler->createProcess(LocationPollThread, &i, sizeof(uint32))) == 0) if ((PollingThreads[i] = g_scheduler->createProcess(LocationPollThread, &i, sizeof(uint32))) == 0)
// if ((hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1) // if ((hEndPollingLocations[i]=(void*)_beginthread(LocationPollThread, 10240,(void *)i))==(void*)-1)
@ -2252,11 +2270,11 @@ void mpalEndIdlePoll(CORO_PARAM, int nLoc, bool *result) {
for (_ctx->i = 0; _ctx->i < MAXPOLLINGLOCATIONS; _ctx->i++) { for (_ctx->i = 0; _ctx->i < MAXPOLLINGLOCATIONS; _ctx->i++) {
if (nPollingLocations[_ctx->i] == (uint32)nLoc) { if (nPollingLocations[_ctx->i] == (uint32)nLoc) {
SetEvent(hEndPollingLocations[_ctx->i]); g_scheduler->setEvent(hEndPollingLocations[_ctx->i]);
CORO_INVOKE_2(g_scheduler->waitForSingleObject, PollingThreads[_ctx->i], INFINITE); CORO_INVOKE_2(g_scheduler->waitForSingleObject, PollingThreads[_ctx->i], INFINITE);
CloseHandle(hEndPollingLocations[_ctx->i]); g_scheduler->closeEvent(hEndPollingLocations[_ctx->i]);
nPollingLocations[_ctx->i] = 0; nPollingLocations[_ctx->i] = 0;
if (result) if (result)

View file

@ -36,76 +36,6 @@ namespace Tony {
namespace MPAL { namespace MPAL {
/**
* Display a message
* @param msg Message to display
*/
void MessageBox(const Common::String &msg) {
_vm->GUIError(msg);
}
/**
* Gets the current time in milliseconds
*/
uint32 timeGetTime() {
return g_system->getMillis();
}
HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter,
uint32 dwCreationFlags, uint32 *lpThreadId) {
*lpThreadId = 0;
return 0;
}
void _beginthread(LPTHREAD_ROUTINE lpStartAddress, size_t dwStackSize, void *lpParameter) {
}
void ExitThread(int ThreadId) {
}
void _endthread() {
}
void TerminateThread(HANDLE ThreadId, uint32 dwExitCode) {
}
void CloseHandle(HANDLE ThreadId) {
}
void Sleep(uint32 time) {
}
int WaitForSingleObject(HANDLE ThreadId, uint32 dwSleepTime) {
warning("TODO: Old style WaitForSingleObject");
return 0;
}
uint32 WaitForMultipleObjects(uint32 nCount, const HANDLE *lpHandles, bool bWaitAll, uint32 dwMilliseconds) {
warning("TODO: Old style WaitForMultipleObjects");
return 0;
}
HANDLE CreateEvent(void *lpEventAttributes, bool bManualReset, bool bInitialState, const char *lpName) {
warning("TODO: Refactor call to old style CreateEvent method");
return 0;
}
void SetEvent(HANDLE hEvent) {
warning("TODO: Refactor call to old style SetEvent method");
}
void ResetEvent(HANDLE hEvent) {
warning("TODO: Refactor call to old style ResetEvent method");
}
void PulseEvent(HANDLE hEvent) {
warning("TODO: Refactor call to old style PulseEvent method");
}
uint16 GetAsyncKeyState(Common::KeyCode kc) { uint16 GetAsyncKeyState(Common::KeyCode kc) {
return 0; return 0;
} }

View file

@ -71,42 +71,8 @@ Out CopyMemory(Out dst, In first, int size) {
* Methods * Methods
\****************************************************************************/ \****************************************************************************/
extern void MessageBox(const Common::String &msg);
extern uint32 timeGetTime();
#define INFINITE 0xffffffff
#define WAIT_OBJECT_0 -2
// Horrendously bad cast // Horrendously bad cast
#define INVALID_HANDLE_VALUE (void *)-3 #define INVALID_HANDLE_VALUE (void *)-1
extern HANDLE CreateThread(void *lpThreadAttributes, size_t dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress, void *lpParameter,
uint32 dwCreationFlags, uint32 *lpThreadId);
extern void _beginthread(LPTHREAD_ROUTINE lpStartAddress, size_t dwStackSize, void *lpParameter);
extern void ExitThread(int ThreadId);
extern void _endthread();
extern void TerminateThread(HANDLE ThreadId, uint32 dwExitCode);
extern void CloseHandle(HANDLE ThreadId);
extern void Sleep(uint32 time);
extern int WaitForSingleObject(HANDLE ThreadId, uint32 dwSleepTime);
extern uint32 WaitForMultipleObjects(uint32 nCount, const HANDLE *lpHandles, bool bWaitAll, uint32 dwMilliseconds);
extern HANDLE CreateEvent(void *lpEventAttributes, bool bManualReset, bool bInitialState, const char *lpName);
extern void SetEvent(HANDLE hEvent);
extern void ResetEvent(HANDLE hEvent);
extern void PulseEvent(HANDLE hEvent);
extern uint16 GetAsyncKeyState(Common::KeyCode kc); extern uint16 GetAsyncKeyState(Common::KeyCode kc);

View file

@ -437,6 +437,40 @@ void Scheduler::waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *pidList,
CORO_END_CODE; CORO_END_CODE;
} }
/**
* Make the active process sleep for the given duration in milliseconds
* @param duration Duration in milliseconds
* @remarks This duration won't be precise, since it relies on the frequency the
* scheduler is called.
*/
void Scheduler::sleep(CORO_PARAM, uint32 duration) {
if (!pCurrent)
error("Called Scheduler::waitForSingleObject from the main process");
CORO_BEGIN_CONTEXT;
uint32 endTime;
PROCESS *pProcess;
EVENT *pEvent;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
// Signal as waiting
pCurrent->waiting = true;
_ctx->endTime = g_system->getMillis() + duration;
// Outer loop for doing checks until expiry
while (g_system->getMillis() < _ctx->endTime) {
// Sleep until the next cycle
CORO_SLEEP(1);
}
// Signal waiting is done
pCurrent->waiting = false;
CORO_END_CODE;
}
/** /**
* Creates a new process. * Creates a new process.

View file

@ -37,6 +37,7 @@ namespace Tony {
#define MAX_PROCESSES 100 #define MAX_PROCESSES 100
#define INFINITE 0xffffffff #define INFINITE 0xffffffff
#define INVALID_PID_VALUE 0
typedef void (*CORO_ADDR)(CoroContext &, const void *); typedef void (*CORO_ADDR)(CoroContext &, const void *);
@ -125,7 +126,8 @@ public:
void giveWay(PPROCESS pReSchedProc = NULL); void giveWay(PPROCESS pReSchedProc = NULL);
void waitForSingleObject(CORO_PARAM, int pid, uint32 duration, bool *expired = NULL); void waitForSingleObject(CORO_PARAM, int pid, uint32 duration, bool *expired = NULL);
void waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *pidList, bool bWaitAll, void waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *pidList, bool bWaitAll,
uint32 duration, bool *expired = NULL); uint32 duration, bool *expired = NULL);
void Scheduler::sleep(CORO_PARAM, uint32 duration);
uint32 createProcess(CORO_ADDR coroAddr, const void *pParam, int sizeParam); uint32 createProcess(CORO_ADDR coroAddr, const void *pParam, int sizeParam);
uint32 createProcess(CORO_ADDR coroAddr, const void *pParam) { uint32 createProcess(CORO_ADDR coroAddr, const void *pParam) {

View file

@ -2179,8 +2179,9 @@ void PASCAL FPSTREAM::PlayThread(FPSTREAM *This) {
// sprintf(buf, "Exiting thread. Buffer = %x, MyThread = 0x%x\n", This->lpDSBuffer, GetCurrentThreadId()); // sprintf(buf, "Exiting thread. Buffer = %x, MyThread = 0x%x\n", This->lpDSBuffer, GetCurrentThreadId());
// warning(buf); // warning(buf);
This->lpDSBuffer->Stop(); This->lpDSBuffer->Stop();
#endif
ExitThread(0); ExitThread(0);
#endif
} }

View file

@ -240,7 +240,7 @@ private:
// DSBPOSITIONNOTIFY dspnHot[2]; // DSBPOSITIONNOTIFY dspnHot[2];
public: public:
HANDLE hEndOfBuffer; uint32 hEndOfBuffer;
private: private:

View file

@ -68,7 +68,7 @@ Common::Error TonyEngine::run() {
* Initialise the game * Initialise the game
*/ */
Common::ErrorCode TonyEngine::Init() { Common::ErrorCode TonyEngine::Init() {
m_hEndOfFrame = CreateEvent(NULL, false, false, NULL); m_hEndOfFrame = g_scheduler->createEvent(false, false);
m_bPaused = false; m_bPaused = false;
m_bDrawLocation = true; m_bDrawLocation = true;
@ -295,16 +295,22 @@ void TonyEngine::GetSaveStateFileName(int n, char *buf) {
name += ".sav"; name += ".sav";
} }
void TonyEngine::AutoSave(void) { void TonyEngine::AutoSave(CORO_PARAM) {
char buf[256]; CORO_BEGIN_CONTEXT;
char buf[256];
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
GrabThumbnail(); GrabThumbnail();
MainWaitFrame(); CORO_INVOKE_0(MainWaitFrame);
MainWaitFrame(); CORO_INVOKE_0(MainWaitFrame);
MainFreeze(); MainFreeze();
GetSaveStateFileName(0,buf); GetSaveStateFileName(0, _ctx->buf);
_theEngine.SaveState(buf, (byte *)m_curThumbnail, "Autosave", true); _theEngine.SaveState(_ctx->buf, (byte *)m_curThumbnail, "Autosave", true);
MainUnfreeze(); MainUnfreeze();
CORO_END_CODE;
} }
@ -375,12 +381,12 @@ void TonyEngine::GrabThumbnail(void) {
void TonyEngine::OptionScreen(void) { void TonyEngine::OptionScreen(void) {
} }
void TonyEngine::OpenInitLoadMenu(void) { void TonyEngine::OpenInitLoadMenu(CORO_PARAM) {
_theEngine.OpenOptionScreen(1); _theEngine.OpenOptionScreen(coroParam, 1);
} }
void TonyEngine::OpenInitOptions(void) { void TonyEngine::OpenInitOptions(CORO_PARAM) {
_theEngine.OpenOptionScreen(2); _theEngine.OpenOptionScreen(coroParam, 2);
} }
void TonyEngine::Abort(void) { void TonyEngine::Abort(void) {
@ -400,10 +406,11 @@ void TonyEngine::Play(void) {
_scheduler.schedule(); _scheduler.schedule();
// Call the engine to handle the next frame // Call the engine to handle the next frame
_theEngine.DoFrame(m_bDrawLocation); // FIXME: This needs to be moved into it's own process
_theEngine.DoFrame(nullContext, m_bDrawLocation);
// Warns that a frame is finished // Warns that a frame is finished
PulseEvent(m_hEndOfFrame); g_scheduler->pulseEvent(m_hEndOfFrame);
// Handle drawing the frame // Handle drawing the frame
if (!m_bPaused) { if (!m_bPaused) {
@ -422,7 +429,7 @@ void TonyEngine::Play(void) {
void TonyEngine::Close(void) { void TonyEngine::Close(void) {
CloseMusic(); CloseMusic();
CloseHandle(m_hEndOfFrame); g_scheduler->closeEvent(m_hEndOfFrame);
_theBoxes.Close(); _theBoxes.Close();
_theEngine.Close(); _theEngine.Close();
_window.Close(); _window.Close();

View file

@ -92,7 +92,7 @@ public:
Common::RandomSource _randomSource; Common::RandomSource _randomSource;
MPAL::MemoryManager _memoryManager; MPAL::MemoryManager _memoryManager;
RMResUpdate _resUpdate; RMResUpdate _resUpdate;
HANDLE m_hEndOfFrame; uint32 m_hEndOfFrame;
Common::File _vdbFP; Common::File _vdbFP;
Common::Array<VoiceHeader> _voices; Common::Array<VoiceHeader> _voices;
FPSOUND _theSound; FPSOUND _theSound;
@ -191,7 +191,7 @@ public:
int GetMusicVolume(int nChannel); int GetMusicVolume(int nChannel);
// Salvataggio // Salvataggio
void AutoSave(void); void AutoSave(CORO_PARAM);
void SaveState(int n, const char *name); void SaveState(int n, const char *name);
void LoadState(int n); void LoadState(int n);
void GetSaveStateFileName(int n, char *buf); void GetSaveStateFileName(int n, char *buf);
@ -202,8 +202,8 @@ public:
void Quit(void) { m_bQuitNow = true; } void Quit(void) { m_bQuitNow = true; }
void OpenInitLoadMenu(void); void OpenInitLoadMenu(CORO_PARAM);
void OpenInitOptions(void); void OpenInitOptions(CORO_PARAM);
}; };
// Global reference to the TonyEngine object // Global reference to the TonyEngine object

View file

@ -212,6 +212,7 @@ void RMTony::MoveAndDoAction(RMPoint dst, RMItem *item, int nAction, int nAction
void RMTony::ExecuteAction(int nAction, int nActionItem, int nParm) { void RMTony::ExecuteAction(int nAction, int nActionItem, int nParm) {
// fixme: See if hThread can be converted to uint32
HANDLE hThread; HANDLE hThread;
uint32 pid; uint32 pid;
@ -241,53 +242,64 @@ void RMTony::ExecuteAction(int nAction, int nActionItem, int nParm) {
m_bAction = true; m_bAction = true;
pid = (uint32)hThread; pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32)); g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = hThread; hActionThread = pid;
} else if (nAction != TA_GOTO) { } else if (nAction != TA_GOTO) {
if (nAction == TA_TALK) { if (nAction == TA_TALK) {
hThread = mpalQueryDoAction(6, 1, 0); hThread = mpalQueryDoAction(6, 1, 0);
m_bAction = true; m_bAction = true;
pid = (uint32)hThread; pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32)); g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = hThread; hActionThread = pid;
} else if (nAction == TA_PALESATI) { } else if (nAction == TA_PALESATI) {
hThread = mpalQueryDoAction(7, 1, 0); hThread = mpalQueryDoAction(7, 1, 0);
m_bAction = true; m_bAction = true;
pid = (uint32)hThread; pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32)); g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread=hThread; hActionThread = pid;
} else { } else {
hThread = mpalQueryDoAction(5, 1, 0); hThread = mpalQueryDoAction(5, 1, 0);
m_bAction = true; m_bAction = true;
pid = (uint32)hThread; pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32)); g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = hThread; hActionThread = pid;
} }
} }
} }
void RMTony::StopNoAction(void) { void RMTony::StopNoAction(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
if (m_bAction) if (m_bAction)
WaitForSingleObject(hActionThread, INFINITE); CORO_INVOKE_2(g_scheduler->waitForSingleObject, hActionThread, INFINITE);
m_bActionPending = false; m_bActionPending = false;
m_ActionItem = NULL; m_ActionItem = NULL;
Stop(); CORO_INVOKE_0(Stop);
CORO_END_CODE;
} }
void RMTony::Stop(void) { void RMTony::Stop(CORO_PARAM) {
HANDLE hThread; CORO_BEGIN_CONTEXT;
uint32 hThread;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
if (m_ActionItem != NULL) { if (m_ActionItem != NULL) {
// Richiama l'MPAL per scegliere la direzione // Richiama l'MPAL per scegliere la direzione
hThread = mpalQueryDoAction(21, m_ActionItem->MpalCode(), 0); _ctx->hThread = mpalQueryDoActionU32(21, m_ActionItem->MpalCode(), 0);
if (hThread==INVALID_HANDLE_VALUE) if (_ctx->hThread == INVALID_PID_VALUE)
RMCharacter::Stop(); RMCharacter::Stop();
else { else {
bNeedToStop = false; // Se facciamo la OnWhichDirection, almeno dopo non dobbiamo fare la Stop() bNeedToStop = false; // Se facciamo la OnWhichDirection, almeno dopo non dobbiamo fare la Stop()
bMoving = false; bMoving = false;
WaitForSingleObject(hThread, INFINITE); // @@@ Mettere un assert dopo 10 secondi CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->hThread, INFINITE); // @@@ Mettere un assert dopo 10 secondi
} }
} else { } else {
RMCharacter::Stop(); RMCharacter::Stop();
@ -301,6 +313,8 @@ void RMTony::Stop(void) {
ExecuteAction(m_Action, m_ActionItem->MpalCode(), m_ActionParm); ExecuteAction(m_Action, m_ActionItem->MpalCode(), m_ActionParm);
m_ActionItem=NULL; m_ActionItem=NULL;
CORO_END_CODE;
} }

View file

@ -123,7 +123,7 @@ private:
int m_nTimeLastStep; int m_nTimeLastStep;
RMItem m_body; RMItem m_body;
HANDLE hActionThread; uint32 hActionThread;
protected: protected:
// Overload dell'allocazione degli sprites per cambiare il tipo // Overload dell'allocazione degli sprites per cambiare il tipo
@ -398,8 +398,8 @@ public:
void MoveAndDoAction(RMPoint dst, RMItem *item, int nAction, int nActionParm = 0); void MoveAndDoAction(RMPoint dst, RMItem *item, int nAction, int nActionParm = 0);
// Ferma Tony (dalla parte giusta rispetto a un eventuale oggetto) // Ferma Tony (dalla parte giusta rispetto a un eventuale oggetto)
virtual void Stop(void); virtual void Stop(CORO_PARAM);
void StopNoAction(void); void StopNoAction(CORO_PARAM);
// Setta un pattern // Setta un pattern
void SetPattern(int npatt, bool bPlayP0 = false); void SetPattern(int npatt, bool bPlayP0 = false);
@ -408,7 +408,7 @@ public:
int GetCurPattern(); int GetCurPattern();
// Attende la fine di un pattern // Attende la fine di un pattern
void WaitForEndPattern(CORO_PARAM, HANDLE hCustomSkip = INVALID_HANDLE_VALUE) { void WaitForEndPattern(CORO_PARAM, uint32 hCustomSkip = INVALID_PID_VALUE) {
RMCharacter::WaitForEndPattern(coroParam, hCustomSkip); RMCharacter::WaitForEndPattern(coroParam, hCustomSkip);
} }