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 MainFreeze(void);
void MainUnfreeze(void);
void MainWaitFrame(void);
void MainWaitFrame(CORO_PARAM);
void MainShowMouse(void);
void MainHideMouse(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 MainInitWipe(int type);
void MainCloseWipe(void);
void MainWaitWipeEnd(void);
void MainWaitWipeEnd(CORO_PARAM);
void MainEnableGUI(void);
void MainDisableGUI(void);
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_bAlwaysDisplay = false;
m_bNoTab = false;
hCustomSkip = INVALID_HANDLE_VALUE;
hCustomSkip2 = INVALID_HANDLE_VALUE;
hCustomSkip = INVALID_PID_VALUE;
hCustomSkip2 = INVALID_PID_VALUE;
m_input = NULL;
// Crea l'evento di fine displaying
hEndDisplay = CreateEvent(NULL, false, false, NULL);
hEndDisplay = g_scheduler->createEvent(false, false);
}
RMTextDialog::~RMTextDialog() {
CloseHandle(hEndDisplay);
g_scheduler->closeEvent(hEndDisplay);
}
void RMTextDialog::Show(void) {
m_bShowed = true;
}
void RMTextDialog::Hide(void) {
void RMTextDialog::Hide(CORO_PARAM) {
m_bShowed = false;
}
@ -2107,53 +2107,70 @@ void RMTextDialog::SetAlwaysDisplay(void) {
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
if (m_bSkipStatus) {
if (!(bCfgDubbing && hCustomSkip2 != INVALID_HANDLE_VALUE))
if (!(bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE))
if (bCfgTimerizedText) {
if (!m_bForceNoTime)
if (_vm->GetTime() > (uint32)m_time + m_startTime)
return true;
return;
}
if (!m_bNoTab)
if ((GetAsyncKeyState(Common::KEYCODE_TAB) & 0x8001) == 0x8001)
return true;
return;
if (!m_bNoTab)
if (m_input)
if (m_input->MouseLeftClicked() || m_input->MouseRightClicked())
return true;
return;
}
// Frase di background
else {
if (!(bCfgDubbing && hCustomSkip2 != INVALID_HANDLE_VALUE))
if (!(bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE))
if (!m_bForceNoTime)
if (_vm->GetTime() > (uint32)m_time + m_startTime)
return true;
return;
}
// Se il tempo è forzato
if (m_bForceTime)
if (_vm->GetTime() > (uint32)m_time + m_startTime)
return true;
return;
if (hCustomSkip != INVALID_HANDLE_VALUE)
if (WaitForSingleObject(hCustomSkip, 0) == WAIT_OBJECT_0)
return true;
if (hCustomSkip != INVALID_PID_VALUE) {
CORO_INVOKE_3(g_scheduler->waitForSingleObject, hCustomSkip, 0, &_ctx->expired);
// == WAIT_OBJECT_0
if (!_ctx->expired)
return;
}
if (bCfgDubbing && hCustomSkip2 != INVALID_HANDLE_VALUE)
if (WaitForSingleObject(hCustomSkip2,0) == WAIT_OBJECT_0)
return true;
if (bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE) {
CORO_INVOKE_3(g_scheduler->waitForSingleObject, hCustomSkip2, 0, &_ctx->expired);
// == WAIT_OBJECT_0
if (!_ctx->expired)
return;
}
return false;
result = false;
CORO_END_CODE;
}
void RMTextDialog::Unregister(void) {
RMGfxTask::Unregister();
assert(m_nInList == 0);
SetEvent(hEndDisplay);
g_scheduler->setEvent(hEndDisplay);
}
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;
}
void RMTextDialog::SetCustomSkipHandle2(HANDLE hCustom) {
void RMTextDialog::SetCustomSkipHandle2(uint32 hCustom) {
hCustomSkip2 = hCustom;
}
void RMTextDialog::WaitForEndDisplay(void) {
WaitForSingleObject(hEndDisplay, INFINITE);
void RMTextDialog::WaitForEndDisplay(CORO_PARAM) {
g_scheduler->waitForSingleObject(coroParam, hEndDisplay, INFINITE);
}
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) {
CORO_BEGIN_CONTEXT;
RMString itemName;
RMItem *lastItem = m_item;
RMItem *lastItem;
uint32 hThread;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
_ctx->lastItem = m_item;
// Si aggiunge alla lista se c'e' bisogno
if (!m_nInList)
@ -2248,27 +2272,29 @@ void RMTextItemName::DoFrame(RMGfxTargetBuffer& bigBuf, RMLocation &loc, RMPoint
else
m_item = loc.WhichItemIsIn(m_mpos);
itemName = "";
_ctx->itemName = "";
// Si fa dare il nuovo nome
if (m_item != NULL)
m_item->GetName(itemName);
m_item->GetName(_ctx->itemName);
// 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
if (lastItem != m_item) {
if (_ctx->lastItem != m_item) {
if (m_item == NULL)
ptr.SetSpecialPointer(RMPointer::PTR_NONE);
else {
HANDLE hThread = mpalQueryDoAction(20, m_item->MpalCode(), 0);
if (hThread == INVALID_HANDLE_VALUE)
_ctx->hThread = mpalQueryDoActionU32(20, m_item->MpalCode(), 0);
if (_ctx->hThread == INVALID_PID_VALUE)
ptr.SetSpecialPointer(RMPointer::PTR_NONE);
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);
DlgTextLine.LoadPaletteWA(dlgpal);
hUnreg=CreateEvent(NULL, false, false, NULL);
hUnreg = g_scheduler->createEvent(false, false);
bRemoveFromOT = false;
}
RMDialogChoice::~RMDialogChoice() {
CloseHandle(hUnreg);
g_scheduler->closeEvent(hUnreg);
}
void RMDialogChoice::Unregister(void) {
RMGfxWoodyBuffer::Unregister();
assert(!m_nInList);
PulseEvent(hUnreg);
g_scheduler->pulseEvent(hUnreg);
bRemoveFromOT = false;
}
@ -2444,7 +2470,16 @@ void RMDialogChoice::SetSelected(int 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();
m_bShow = false;
@ -2454,30 +2489,28 @@ void RMDialogChoice::Show(RMGfxTargetBuffer *bigBuf) {
if (0) {
m_bShow = true;
} else {
RMPoint destpt;
int deltay;
int starttime = _vm->GetTime();
int elaps;
deltay=480 - m_ptDrawPos.y;
destpt = m_ptDrawPos;
_ctx->starttime = _vm->GetTime();
_ctx->deltay = 480 - m_ptDrawPos.y;
_ctx->destpt = m_ptDrawPos;
m_ptDrawPos.Set(0, 480);
if (!m_nInList && bigBuf != NULL)
bigBuf->AddPrim(new RMGfxPrimitive(this));
m_bShow = true;
elaps = 0;
while (elaps < 700) {
MainWaitFrame();
_ctx->elaps = 0;
while (_ctx->elaps < 700) {
CORO_INVOKE_0(MainWaitFrame);
MainFreeze();
elaps = _vm->GetTime() - starttime;
m_ptDrawPos.y = 480 - ((deltay * 100) / 700 * elaps) / 100;
_ctx->elaps = _vm->GetTime() - _ctx->starttime;
m_ptDrawPos.y = 480 - ((_ctx->deltay * 100) / 700 * _ctx->elaps) / 100;
MainUnfreeze();
}
m_ptDrawPos.y = destpt.y;
m_ptDrawPos.y = _ctx->destpt.y;
}
CORO_END_CODE;
}
void RMDialogChoice::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) {
@ -2489,26 +2522,34 @@ void RMDialogChoice::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) {
}
void RMDialogChoice::Hide(void) {
if (1) {
void RMDialogChoice::Hide(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
int deltay;
int starttime = _vm->GetTime();
int starttime;
int elaps;
CORO_END_CONTEXT(_ctx);
deltay=480 - m_ptDrawPos.y;
elaps = 0;
while (elaps < 700) {
MainWaitFrame();
CORO_BEGIN_CODE(_ctx);
if (1) {
_ctx->starttime = _vm->GetTime();
_ctx->deltay = 480 - m_ptDrawPos.y;
_ctx->elaps = 0;
while (_ctx->elaps < 700) {
CORO_INVOKE_0(MainWaitFrame);
MainFreeze();
elaps=_vm->GetTime()-starttime;
m_ptDrawPos.y=480-((deltay*100)/700*(700-elaps))/100;
_ctx->elaps = _vm->GetTime()-_ctx->starttime;
m_ptDrawPos.y = 480 - ((_ctx->deltay * 100) / 700 * (700 - _ctx->elaps)) / 100;
MainUnfreeze();
}
}
m_bShow = false;
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 "tony/gfxcore.h"
#include "tony/resid.h"
#include "tony/sched.h"
namespace Tony {
@ -247,12 +248,12 @@ class RMTextDialog : public RMText {
int m_time;
bool m_bSkipStatus;
RMPoint dst;
HANDLE hEndDisplay;
uint32 hEndDisplay;
bool m_bShowed;
bool m_bForceTime;
bool m_bForceNoTime;
HANDLE hCustomSkip;
HANDLE hCustomSkip2;
uint32 hCustomSkip;
uint32 hCustomSkip2;
RMInput *m_input;
bool m_bAlwaysDisplay;
bool m_bNoTab;
@ -267,7 +268,7 @@ class RMTextDialog : public RMText {
// Overloading della funzione ereditata da RMGfxTask per decidere
// 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
// quando ci leviamo di torno
@ -280,9 +281,9 @@ class RMTextDialog : public RMText {
void SetPosition(RMPoint pt) { dst=pt; }
// Aspetta che venga finita la visualizzazione
void WaitForEndDisplay(void);
void SetCustomSkipHandle(HANDLE hCustomSkip);
void SetCustomSkipHandle2(HANDLE hCustomSkip);
void WaitForEndDisplay(CORO_PARAM);
void SetCustomSkipHandle(uint32 hCustomSkip);
void SetCustomSkipHandle2(uint32 hCustomSkip);
void SetSkipStatus(bool bEnabled);
void SetForcedTime(uint32 dwTime);
void SetNoTab(void);
@ -294,7 +295,7 @@ class RMTextDialog : public RMText {
void SetInput(RMInput* input);
void Show(void);
void Hide(void);
void Hide(CORO_PARAM);
};
class RMTextDialogScrolling : public RMTextDialog {
@ -332,7 +333,7 @@ public:
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);
RMPoint GetHotspot();
@ -358,7 +359,7 @@ private:
RMGfxSourceBuffer8 DlgText;
RMGfxSourceBuffer8 DlgTextLine;
RMPoint m_ptDrawPos;
HANDLE hUnreg;
uint32 hUnreg;
bool bRemoveFromOT;
protected:
@ -389,8 +390,8 @@ public:
// Mostra e nasconde la scelta, con eventuali animazioni
// NOTA: Se non viene passato parametro alla Show(), è obbligo del
// chiamante assicurarsi che la classe venga inserita alla OTlist
void Show(RMGfxTargetBuffer* bigBuf = NULL);
void Hide(void);
void Show(CORO_PARAM, RMGfxTargetBuffer* bigBuf = NULL);
void Hide(CORO_PARAM);
// Polling di aggiornamento
void DoFrame(RMPoint ptMousePos);

View file

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

View file

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

View file

@ -85,7 +85,7 @@ private:
OSystem::MutexRef csMainLoop;
int m_nWipeType;
HANDLE m_hWipeEvent;
uint32 m_hWipeEvent;
int m_nWipeStep;
bool m_bMustEnterMenu;
@ -103,7 +103,7 @@ public:
virtual ~RMGfxEngine();
// Draw the next frame
void DoFrame(bool bDrawLocation);
void DoFrame(CORO_PARAM, bool bDrawLocation);
// Initialises the graphics engine
void Init();
@ -118,7 +118,7 @@ public:
void GDIControl(bool bCon);
// Warns when entering or exits the options menu
void OpenOptionScreen(int type);
void OpenOptionScreen(CORO_PARAM, int type);
// Enables or disables mouse input
void EnableInput(void);
@ -157,7 +157,7 @@ public:
// Wipe
void InitWipe(int type);
void CloseWipe(void);
void WaitWipeEnd(void);
void WaitWipeEnd(CORO_PARAM);
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;
}
int RMPattern::Update(HANDLE hEndPattern, byte &bFlag, RMSfx *sfx) {
int RMPattern::Update(uint32 hEndPattern, byte &bFlag, RMSfx *sfx) {
int CurTime = _vm->GetTime();
// Se la speed e' 0, il pattern non avanza mai
if (m_speed == 0) {
PulseEvent(hEndPattern);
g_scheduler->pulseEvent(hEndPattern);
bFlag=m_slots[m_nCurSlot].m_flag;
return m_nCurSprite;
}
@ -266,7 +266,8 @@ int RMPattern::Update(HANDLE hEndPattern, byte &bFlag, RMSfx *sfx) {
if (m_nCurSlot == m_nSlots) {
m_nCurSlot = 0;
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 rimane sull'ultimo frame
@ -705,9 +706,8 @@ bool RMItem::DoFrame(RMGfxTargetBuffer *bigBuf, bool bAddToList) {
return false;
// Facciamo un update del pattern, che ci ritorna anche il frame corrente
// FIXME: Get rid of HANDLE cast
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
if (m_nCurSprite == -1) {
@ -844,7 +844,7 @@ RMItem::~RMItem() {
}
//FIXME: Pass uint32 directly for hCustomSkip
void RMItem::WaitForEndPattern(CORO_PARAM, HANDLE hCustomSkip) {
void RMItem::WaitForEndPattern(CORO_PARAM, uint32 hCustomSkip) {
CORO_BEGIN_CONTEXT;
uint32 h[2];
CORO_END_CONTEXT(_ctx);
@ -852,10 +852,10 @@ void RMItem::WaitForEndPattern(CORO_PARAM, HANDLE hCustomSkip) {
CORO_BEGIN_CODE(_ctx);
if (m_nCurPattern != 0) {
if (hCustomSkip == INVALID_HANDLE_VALUE)
if (hCustomSkip == INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, m_hEndPattern, INFINITE);
else {
_ctx->h[0] = (uint32)hCustomSkip;
_ctx->h[0] = hCustomSkip;
_ctx->h[1] = m_hEndPattern;
CORO_INVOKE_4(g_scheduler->waitForMultipleObjects, 2, &_ctx->h[0], false, INFINITE);
}
@ -888,13 +888,13 @@ void RMItem::PauseSound(bool bPause) {
RMWipe::RMWipe() {
m_hUnregistered=CreateEvent(NULL,false,false,NULL);
m_hEndOfFade=CreateEvent(NULL,false,false,NULL);
m_hUnregistered = g_scheduler->createEvent(false, false);
m_hEndOfFade = g_scheduler->createEvent(false, false);
}
RMWipe::~RMWipe() {
CloseHandle(m_hUnregistered);
CloseHandle(m_hEndOfFade);
g_scheduler->closeEvent(m_hUnregistered);
g_scheduler->closeEvent(m_hEndOfFade);
}
int RMWipe::Priority(void) {
@ -904,19 +904,28 @@ int RMWipe::Priority(void) {
void RMWipe::Unregister(void) {
RMGfxTask::Unregister();
assert(m_nInList == 0);
SetEvent(m_hUnregistered);
g_scheduler->setEvent(m_hUnregistered);
}
bool RMWipe::RemoveThis(void) {
return m_bUnregister;
}
void RMWipe::WaitForFadeEnd(void) {
WaitForSingleObject(m_hEndOfFade, INFINITE);
void RMWipe::WaitForFadeEnd(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
CORO_INVOKE_2(g_scheduler->waitForSingleObject, m_hEndOfFade, INFINITE);
m_bEndFade = true;
m_bFading = false;
MainWaitFrame();
MainWaitFrame();
CORO_INVOKE_0(MainWaitFrame);
CORO_INVOKE_0(MainWaitFrame);
CORO_END_CODE;
}
void RMWipe::CloseFade(void) {
@ -958,7 +967,7 @@ void RMWipe::DoFrame(RMGfxTargetBuffer &bigBuf) {
m_nFadeStep++;
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
// any associated commands
int Update(HANDLE hEndPattern, byte& bFlag, RMSfx* sfx);
int Update(uint32 hEndPattern, byte &bFlag, RMSfx *sfx);
// Stop a sound effect
void StopSfx(RMSfx *sfx);
@ -292,7 +292,7 @@ public:
void Unload(void);
// 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
void ChangeHotspot(RMPoint pt);
@ -494,9 +494,9 @@ private:
bool m_bFading;
bool m_bEndFade;
bool m_bUnregister;
HANDLE m_hUnregistered;
uint32 m_hUnregistered;
int m_nFadeStep;
HANDLE m_hEndOfFade;
uint32 m_hEndOfFade;
bool m_bMustRegister;
RMItem m_wip0r;
@ -510,7 +510,7 @@ public:
void InitFade(int type);
void CloseFade(void);
void WaitForFadeEnd(void);
void WaitForFadeEnd(CORO_PARAM);
virtual void Unregister(void);
virtual bool RemoveThis(void);

View file

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

View file

@ -138,7 +138,7 @@ bool bExecutingAction;
bool bExecutingDialog;
uint32 nPollingLocations[MAXPOLLINGLOCATIONS];
HANDLE hEndPollingLocations[MAXPOLLINGLOCATIONS];
uint32 hEndPollingLocations[MAXPOLLINGLOCATIONS];
uint32 PollingThreads[MAXPOLLINGLOCATIONS];
uint32 hAskChoice;
@ -830,14 +830,20 @@ static LPITEM GetItemData(uint32 nOrdItem) {
*
\****************************************************************************/
void PASCAL CustomThread(LPCFCALL p) {
// FIXME: Convert to proper corotuine call
warning("FIXME: CustomThread call");
void CustomThread(CORO_PARAM, const void *param) {
CORO_BEGIN_CONTEXT;
LPCFCALL p;
CORO_END_CONTEXT(_ctx);
lplpFunctions[p->nCf](nullContext, p->arg1, p->arg2, p->arg3, p->arg4);
GlobalFree(p);
ExitThread(1);
// _endthread();
CORO_BEGIN_CODE(_ctx);
_ctx->p = *(LPCFCALL *)param;
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) {
CORO_BEGIN_CONTEXT;
uint i, j, k;
uint32 dwStartTime = timeGetTime();
uint32 dwStartTime;
uint32 dwCurTime;
uint32 dwId;
static HANDLE cfHandles[MAX_COMMANDS_PER_MOMENT];
int numHandles = 0;
int numHandles;
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);
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
if (s->Moment[i].dwTime == -1) {
WaitForMultipleObjects(numHandles, cfHandles, true, INFINITE);
dwStartTime = timeGetTime();
if (s->Moment[_ctx->i].dwTime == -1) {
CORO_INVOKE_4(g_scheduler->waitForMultipleObjects, _ctx->numHandles, cfHandles, true, INFINITE);
_ctx->dwStartTime = _vm->GetTime();
} else {
dwCurTime = timeGetTime();
if (dwCurTime < dwStartTime + (s->Moment[i].dwTime * 100)) {
// warning("PlayScript(): Sleeping %lums\n",dwStartTime+(s->Moment[i].dwTime*100)-dwCurTime);
Sleep(dwStartTime+(s->Moment[i].dwTime * 100) - dwCurTime);
_ctx->dwCurTime = _vm->GetTime();
if (_ctx->dwCurTime < _ctx->dwStartTime + (s->Moment[_ctx->i].dwTime * 100)) {
// warning("PlayScript(): Sleeping %lums\n",_ctx->dwStartTime+(s->Moment[_ctx->i].dwTime*100)-_ctx->dwCurTime);
CORO_INVOKE_1(g_scheduler->sleep, _ctx->dwStartTime+(s->Moment[_ctx->i].dwTime * 100) - _ctx->dwCurTime);
}
}
numHandles = 0;
for (j = 0;j<s->Moment[i].nCmds; j++) {
k=s->Moment[i].CmdNum[j];
_ctx->numHandles = 0;
for (_ctx->j = 0; _ctx->j<s->Moment[_ctx->i].nCmds; _ctx->j++) {
_ctx->k = s->Moment[_ctx->i].CmdNum[_ctx->j];
switch (s->Command[k].type) {
case 1:
p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL));
if (p == NULL) {
if (s->Command[_ctx->k].type == 1) {
_ctx->p=(LPCFCALL)GlobalAlloc(GMEM_FIXED, sizeof(CFCALL));
if (_ctx->p == NULL) {
mpalError = 1;
ExitThread(0);
// _endthread();
CORO_KILL_SELF();
return;
}
p->nCf=s->Command[k].nCf;
p->arg1=s->Command[k].arg1;
p->arg2=s->Command[k].arg2;
p->arg3=s->Command[k].arg3;
p->arg4=s->Command[k].arg4;
_ctx->p->nCf=s->Command[_ctx->k].nCf;
_ctx->p->arg1=s->Command[_ctx->k].arg1;
_ctx->p->arg2=s->Command[_ctx->k].arg2;
_ctx->p->arg3=s->Command[_ctx->k].arg3;
_ctx->p->arg4=s->Command[_ctx->k].arg4;
// !!! Nuova gestione dei thread
if ((cfHandles[numHandles++] = CreateThread(NULL, 10240, (LPTHREAD_START_ROUTINE)CustomThread,(void *)p, 0, &dwId)) == NULL) {
//if ((cfHandles[numHandles++]=(void*)_beginthread(CustomThread, 10240, (void *)p))==(void*)-1)
if ((cfHandles[_ctx->numHandles++] = g_scheduler->createProcess(CustomThread, &_ctx->p, sizeof(LPCFCALL))) == 0) {
mpalError = 1;
ExitThread(0);
// _endthread();
}
break;
case 2:
CORO_KILL_SELF();
return;
}
} else if (s->Command[_ctx->k].type == 2) {
LockVar();
varSetValue(
s->Command[k].lpszVarName,
EvaluateExpression(s->Command[k].expr)
s->Command[_ctx->k].lpszVarName,
EvaluateExpression(s->Command[_ctx->k].expr)
);
UnlockVar();
break;
default:
} else {
mpalError = 1;
GlobalFree(s);
ExitThread(0);
// _endthread();
CORO_KILL_SELF();
return;
}
}
}
GlobalFree(s);
ExitThread(1);
//_endthread();
CORO_KILL_SELF();
CORO_END_CODE;
}
@ -1063,6 +1078,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
uint32 dwId;
int ord;
bool delayExpired;
bool expired;
MYACTION *MyActions;
MYTHREAD *MyThreads;
@ -1122,7 +1138,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
}
/* Inizializziamo le routine random */
//curTime = timeGetTime();
//curTime = _vm->GetTime();
//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,
MAX_COMMANDS_PER_ACTION * sizeof(uint16));
_ctx->MyActions[_ctx->k].dwLastTime = timeGetTime();
_ctx->MyActions[_ctx->k].dwLastTime = _vm->GetTime();
_ctx->k++;
}
}
@ -1172,7 +1188,7 @@ void LocationPollThread(CORO_PARAM, const void *param) {
while (1) {
/* Cerchiamo tra tutte le idle actions quella a cui manca meno tempo per
l'esecuzione */
_ctx->curTime = timeGetTime();
_ctx->curTime = _vm->GetTime();
_ctx->dwSleepTime = (uint32)-1L;
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
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;
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->curTime = timeGetTime();
_ctx->curTime = _vm->GetTime();
/* Cerchiamo all'interno delle idle actions quale e' necessario eseguire */
for (_ctx->k = 0; _ctx->k < _ctx->nIdleActions; _ctx->k++)
@ -2164,8 +2183,7 @@ bool EXPORT mpalExecuteScript(int nScript) {
UnlockScripts();
// !!! Nuova gestione dei thread
if (CreateThread(NULL, 10240,(LPTHREAD_START_ROUTINE)ScriptThread,(void *)s, 0, &dwId) == NULL)
//if ((void*)_beginthread(ScriptThread, 10240,(void *)s)==(void*)-1)
if (g_scheduler->createProcess(ScriptThread, &s, sizeof(LPMPALSCRIPT)) == INVALID_PID_VALUE)
return false;
return true;
@ -2215,7 +2233,7 @@ bool mpalStartIdlePoll(int nLoc) {
if (nPollingLocations[i] == 0) {
nPollingLocations[i] = nLoc;
hEndPollingLocations[i] = CreateEvent(NULL, true, false, NULL);
hEndPollingLocations[i] = g_scheduler->createEvent(true, false);
// !!! Nuova gestione dei thread
if ((PollingThreads[i] = g_scheduler->createProcess(LocationPollThread, &i, sizeof(uint32))) == 0)
// 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++) {
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);
CloseHandle(hEndPollingLocations[_ctx->i]);
g_scheduler->closeEvent(hEndPollingLocations[_ctx->i]);
nPollingLocations[_ctx->i] = 0;
if (result)

View file

@ -36,76 +36,6 @@ namespace Tony {
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) {
return 0;
}

View file

@ -71,42 +71,8 @@ Out CopyMemory(Out dst, In first, int size) {
* Methods
\****************************************************************************/
extern void MessageBox(const Common::String &msg);
extern uint32 timeGetTime();
#define INFINITE 0xffffffff
#define WAIT_OBJECT_0 -2
// Horrendously bad cast
#define INVALID_HANDLE_VALUE (void *)-3
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);
#define INVALID_HANDLE_VALUE (void *)-1
extern uint16 GetAsyncKeyState(Common::KeyCode kc);

View file

@ -437,6 +437,40 @@ void Scheduler::waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *pidList,
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.

View file

@ -37,6 +37,7 @@ namespace Tony {
#define MAX_PROCESSES 100
#define INFINITE 0xffffffff
#define INVALID_PID_VALUE 0
typedef void (*CORO_ADDR)(CoroContext &, const void *);
@ -126,6 +127,7 @@ public:
void waitForSingleObject(CORO_PARAM, int pid, uint32 duration, bool *expired = NULL);
void waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *pidList, bool bWaitAll,
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) {

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());
// warning(buf);
This->lpDSBuffer->Stop();
#endif
ExitThread(0);
#endif
}

View file

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

View file

@ -68,7 +68,7 @@ Common::Error TonyEngine::run() {
* Initialise the game
*/
Common::ErrorCode TonyEngine::Init() {
m_hEndOfFrame = CreateEvent(NULL, false, false, NULL);
m_hEndOfFrame = g_scheduler->createEvent(false, false);
m_bPaused = false;
m_bDrawLocation = true;
@ -295,16 +295,22 @@ void TonyEngine::GetSaveStateFileName(int n, char *buf) {
name += ".sav";
}
void TonyEngine::AutoSave(void) {
void TonyEngine::AutoSave(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
char buf[256];
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
GrabThumbnail();
MainWaitFrame();
MainWaitFrame();
CORO_INVOKE_0(MainWaitFrame);
CORO_INVOKE_0(MainWaitFrame);
MainFreeze();
GetSaveStateFileName(0,buf);
_theEngine.SaveState(buf, (byte *)m_curThumbnail, "Autosave", true);
GetSaveStateFileName(0, _ctx->buf);
_theEngine.SaveState(_ctx->buf, (byte *)m_curThumbnail, "Autosave", true);
MainUnfreeze();
CORO_END_CODE;
}
@ -375,12 +381,12 @@ void TonyEngine::GrabThumbnail(void) {
void TonyEngine::OptionScreen(void) {
}
void TonyEngine::OpenInitLoadMenu(void) {
_theEngine.OpenOptionScreen(1);
void TonyEngine::OpenInitLoadMenu(CORO_PARAM) {
_theEngine.OpenOptionScreen(coroParam, 1);
}
void TonyEngine::OpenInitOptions(void) {
_theEngine.OpenOptionScreen(2);
void TonyEngine::OpenInitOptions(CORO_PARAM) {
_theEngine.OpenOptionScreen(coroParam, 2);
}
void TonyEngine::Abort(void) {
@ -400,10 +406,11 @@ void TonyEngine::Play(void) {
_scheduler.schedule();
// 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
PulseEvent(m_hEndOfFrame);
g_scheduler->pulseEvent(m_hEndOfFrame);
// Handle drawing the frame
if (!m_bPaused) {
@ -422,7 +429,7 @@ void TonyEngine::Play(void) {
void TonyEngine::Close(void) {
CloseMusic();
CloseHandle(m_hEndOfFrame);
g_scheduler->closeEvent(m_hEndOfFrame);
_theBoxes.Close();
_theEngine.Close();
_window.Close();

View file

@ -92,7 +92,7 @@ public:
Common::RandomSource _randomSource;
MPAL::MemoryManager _memoryManager;
RMResUpdate _resUpdate;
HANDLE m_hEndOfFrame;
uint32 m_hEndOfFrame;
Common::File _vdbFP;
Common::Array<VoiceHeader> _voices;
FPSOUND _theSound;
@ -191,7 +191,7 @@ public:
int GetMusicVolume(int nChannel);
// Salvataggio
void AutoSave(void);
void AutoSave(CORO_PARAM);
void SaveState(int n, const char *name);
void LoadState(int n);
void GetSaveStateFileName(int n, char *buf);
@ -202,8 +202,8 @@ public:
void Quit(void) { m_bQuitNow = true; }
void OpenInitLoadMenu(void);
void OpenInitOptions(void);
void OpenInitLoadMenu(CORO_PARAM);
void OpenInitOptions(CORO_PARAM);
};
// 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) {
// fixme: See if hThread can be converted to uint32
HANDLE hThread;
uint32 pid;
@ -241,53 +242,64 @@ void RMTony::ExecuteAction(int nAction, int nActionItem, int nParm) {
m_bAction = true;
pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = hThread;
hActionThread = pid;
} else if (nAction != TA_GOTO) {
if (nAction == TA_TALK) {
hThread = mpalQueryDoAction(6, 1, 0);
m_bAction = true;
pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread = hThread;
hActionThread = pid;
} else if (nAction == TA_PALESATI) {
hThread = mpalQueryDoAction(7, 1, 0);
m_bAction = true;
pid = (uint32)hThread;
g_scheduler->createProcess(WaitEndOfAction, &pid, sizeof(uint32));
hActionThread=hThread;
hActionThread = pid;
} else {
hThread = mpalQueryDoAction(5, 1, 0);
m_bAction = true;
pid = (uint32)hThread;
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)
WaitForSingleObject(hActionThread, INFINITE);
CORO_INVOKE_2(g_scheduler->waitForSingleObject, hActionThread, INFINITE);
m_bActionPending = false;
m_ActionItem = NULL;
Stop();
CORO_INVOKE_0(Stop);
CORO_END_CODE;
}
void RMTony::Stop(void) {
HANDLE hThread;
void RMTony::Stop(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
uint32 hThread;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
if (m_ActionItem != NULL) {
// 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();
else {
bNeedToStop = false; // Se facciamo la OnWhichDirection, almeno dopo non dobbiamo fare la Stop()
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 {
RMCharacter::Stop();
@ -301,6 +313,8 @@ void RMTony::Stop(void) {
ExecuteAction(m_Action, m_ActionItem->MpalCode(), m_ActionParm);
m_ActionItem=NULL;
CORO_END_CODE;
}

View file

@ -123,7 +123,7 @@ private:
int m_nTimeLastStep;
RMItem m_body;
HANDLE hActionThread;
uint32 hActionThread;
protected:
// 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);
// Ferma Tony (dalla parte giusta rispetto a un eventuale oggetto)
virtual void Stop(void);
void StopNoAction(void);
virtual void Stop(CORO_PARAM);
void StopNoAction(CORO_PARAM);
// Setta un pattern
void SetPattern(int npatt, bool bPlayP0 = false);
@ -408,7 +408,7 @@ public:
int GetCurPattern();
// 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);
}