Skip to content

Commit

Permalink
TONY: Refactored Tony to use the Common coroutine scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 11, 2012
1 parent 2c1ef3a commit 68c1b0b
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 293 deletions.
2 changes: 1 addition & 1 deletion engines/tony/adv.h
Expand Up @@ -48,8 +48,8 @@
#ifndef TONY_ADV_H
#define TONY_ADV_H

#include "common/coroutines.h"
#include "tony/mpal/memory.h"
#include "tony/coroutine.h"
#include "tony/gfxcore.h"


Expand Down
6 changes: 3 additions & 3 deletions engines/tony/coroutine.h
Expand Up @@ -113,7 +113,7 @@ class CoroContextHolder {
* context, and so compilers won't complain about ";" following the macro.
*/
#define CORO_BEGIN_CONTEXT \
struct CoroContextTag : CoroBaseContext { \
struct CoroContextTag : Common::CoroBaseContext { \
CoroContextTag() : CoroBaseContext(SCUMMVM_CURRENT_FUNCTION) {} \
int DUMMY

Expand Down Expand Up @@ -156,8 +156,8 @@ class CoroContextHolder {
return; case __LINE__:;\
} while (0)

#define CORO_GIVE_WAY do { g_scheduler->giveWay(); CORO_SLEEP(1); } while (0)
#define CORO_RESCHEDULE do { g_scheduler->reschedule(); CORO_SLEEP(1); } while (0)
#define CORO_GIVE_WAY do { CoroScheduler.giveWay(); CORO_SLEEP(1); } while (0)
#define CORO_RESCHEDULE do { CoroScheduler.reschedule(); CORO_SLEEP(1); } while (0)

/**
* Stop the currently running coroutine and all calling coroutines.
Expand Down
50 changes: 25 additions & 25 deletions engines/tony/custom.cpp
Expand Up @@ -327,7 +327,7 @@ DECLARE_CUSTOM_FUNCTION(MySleep)(CORO_PARAM, uint32 dwTime, uint32, uint32, uint
CORO_BEGIN_CODE(_ctx);

if (!bSkipIdle)
CORO_INVOKE_1(g_scheduler->sleep, dwTime);
CORO_INVOKE_1(CoroScheduler.sleep, dwTime);

CORO_END_CODE;
}
Expand Down Expand Up @@ -524,8 +524,8 @@ DECLARE_CUSTOM_FUNCTION(CustLoadLocation)(CORO_PARAM, uint32 nLoc, uint32 tX, ui
_ctx->h = mpalQueryDoAction(0, nLoc, 0);

// On Enter?
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
if (_ctx->h != CORO_INVALID_PID_VALUE)
CORO_INVOKE_2(CoroScheduler.waitForSingleObject, _ctx->h, CORO_INFINITE);

CORO_END_CODE;
}
Expand Down Expand Up @@ -708,8 +708,8 @@ DECLARE_CUSTOM_FUNCTION(ChangeLocation)(CORO_PARAM, uint32 nLoc, uint32 tX, uint
bNoOcchioDiBue = false;

// On Enter?
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
if (_ctx->h != CORO_INVALID_PID_VALUE)
CORO_INVOKE_2(CoroScheduler.waitForSingleObject, _ctx->h, CORO_INFINITE);

CORO_END_CODE;
}
Expand Down Expand Up @@ -1843,8 +1843,8 @@ DECLARE_CUSTOM_FUNCTION(MCharSendMessage)(CORO_PARAM, uint32 nChar, uint32 dwMes
// Cerca di eseguire la funzione custom per inizializzare la parlata
if (MCharacter[nChar].item) {
_ctx->h = mpalQueryDoAction(30, MCharacter[nChar].item->MpalCode(), _ctx->parm);
if (_ctx->h != INVALID_PID_VALUE) {
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
if (_ctx->h != CORO_INVALID_PID_VALUE) {
CORO_INVOKE_2(CoroScheduler.waitForSingleObject, _ctx->h, CORO_INFINITE);
}
}

Expand Down Expand Up @@ -1924,8 +1924,8 @@ DECLARE_CUSTOM_FUNCTION(MCharSendMessage)(CORO_PARAM, uint32 nChar, uint32 dwMes
// Cerca di eseguire la funzione custom per chiudere la parlata
if (MCharacter[nChar].item) {
_ctx->h = mpalQueryDoAction(31, MCharacter[nChar].item->MpalCode(), _ctx->parm);
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
if (_ctx->h != CORO_INVALID_PID_VALUE)
CORO_INVOKE_2(CoroScheduler.waitForSingleObject, _ctx->h, CORO_INFINITE);
}

CORO_END_CODE;
Expand Down Expand Up @@ -2035,8 +2035,8 @@ DECLARE_CUSTOM_FUNCTION(SendDialogMessage)(CORO_PARAM, uint32 nPers, uint32 nMsg
} else {
// Cerca di eseguire la funzione custom per inizializzare la parlata
_ctx->h = mpalQueryDoAction(30, MCharacter[nPers].item->MpalCode(), _ctx->parm);
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
if (_ctx->h != CORO_INVALID_PID_VALUE)
CORO_INVOKE_2(CoroScheduler.waitForSingleObject, _ctx->h, CORO_INFINITE);

MCharacter[nPers].curTalk = _ctx->parm;

Expand Down Expand Up @@ -2099,8 +2099,8 @@ DECLARE_CUSTOM_FUNCTION(SendDialogMessage)(CORO_PARAM, uint32 nPers, uint32 nMsg
// Cerca di eseguire la funzione custom per chiudere la parlata
MCharacter[nPers].curTalk = (MCharacter[nPers].curTalk%10) + MCharacter[nPers].curgroup*10;
_ctx->h = mpalQueryDoAction(31,MCharacter[nPers].item->MpalCode(),MCharacter[nPers].curTalk);
if (_ctx->h != INVALID_PID_VALUE)
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->h, INFINITE);
if (_ctx->h != CORO_INVALID_PID_VALUE)
CORO_INVOKE_2(CoroScheduler.waitForSingleObject, _ctx->h, CORO_INFINITE);

MCharacter[nPers].bInTexts = false;
MCharacter[nPers].numtexts = 0;
Expand Down Expand Up @@ -2214,7 +2214,7 @@ DECLARE_CUSTOM_FUNCTION(StartDialog)(CORO_PARAM, uint32 nDialog, uint32 nStartGr

DECLARE_CUSTOM_FUNCTION(TakeOwnership)(CORO_PARAM, uint32 num, uint32, uint32, uint32) {
// EnterCriticalSection(&cs[num]);
// WaitForSingleObject(mut[num],INFINITE);
// WaitForSingleObject(mut[num],CORO_INFINITE);
warning("TODO");
}

Expand Down Expand Up @@ -2264,7 +2264,7 @@ void ThreadFadeInMusic(CORO_PARAM, const void *nMusic) {
for (_ctx->i = 0; _ctx->i < 16; _ctx->i++) {
_vm->SetMusicVolume(nChannel, _ctx->i * 4);

CORO_INVOKE_1(g_scheduler->sleep, 100);
CORO_INVOKE_1(CoroScheduler.sleep, 100);
}
_vm->SetMusicVolume(nChannel, 64);

Expand Down Expand Up @@ -2293,7 +2293,7 @@ void ThreadFadeOutMusic(CORO_PARAM, const void *nMusic) {
if (_ctx->i * 4 < _ctx->startVolume)
_vm->SetMusicVolume(nChannel, _ctx->i * 4);

CORO_INVOKE_1(g_scheduler->sleep, 100);
CORO_INVOKE_1(CoroScheduler.sleep, 100);
}

if (!bFadeOutStop)
Expand All @@ -2311,23 +2311,23 @@ void ThreadFadeOutMusic(CORO_PARAM, const void *nMusic) {
}

DECLARE_CUSTOM_FUNCTION(FadeInSonoriz)(CORO_PARAM, uint32, uint32, uint32, uint32) {
g_scheduler->createProcess(ThreadFadeInMusic, &curSonoriz, sizeof(int));
CoroScheduler.createProcess(ThreadFadeInMusic, &curSonoriz, sizeof(int));
}

DECLARE_CUSTOM_FUNCTION(FadeOutSonoriz)(CORO_PARAM, uint32, uint32, uint32, uint32) {
bFadeOutStop = false;
g_scheduler->createProcess(ThreadFadeOutMusic, &curSonoriz, sizeof(int));
CoroScheduler.createProcess(ThreadFadeOutMusic, &curSonoriz, sizeof(int));
}

DECLARE_CUSTOM_FUNCTION(FadeOutStacchetto)(CORO_PARAM, uint32, uint32, uint32, uint32) {
bFadeOutStop = false;
int channel = 2;
g_scheduler->createProcess(ThreadFadeOutMusic, &channel, sizeof(int));
CoroScheduler.createProcess(ThreadFadeOutMusic, &channel, sizeof(int));
}

DECLARE_CUSTOM_FUNCTION(FadeInStacchetto)(CORO_PARAM, uint32, uint32, uint32, uint32) {
int channel = 2;
g_scheduler->createProcess(ThreadFadeInMusic, &channel, sizeof(int));
CoroScheduler.createProcess(ThreadFadeInMusic, &channel, sizeof(int));
}

DECLARE_CUSTOM_FUNCTION(StopSonoriz)(CORO_PARAM, uint32, uint32, uint32, uint32) {
Expand Down Expand Up @@ -2557,12 +2557,12 @@ DECLARE_CUSTOM_FUNCTION(StacchettoFadeEnd)(CORO_PARAM, uint32 nStacc, uint32 bLo

DECLARE_CUSTOM_FUNCTION(MustSkipIdleStart)(CORO_PARAM, uint32, uint32, uint32, uint32) {
bSkipIdle = true;
g_scheduler->setEvent(hSkipIdle);
CoroScheduler.setEvent(hSkipIdle);
}

DECLARE_CUSTOM_FUNCTION(MustSkipIdleEnd)(CORO_PARAM, uint32, uint32, uint32, uint32) {
bSkipIdle = false;
g_scheduler->resetEvent(hSkipIdle);
CoroScheduler.resetEvent(hSkipIdle);
}

DECLARE_CUSTOM_FUNCTION(PatIrqFreeze)(CORO_PARAM, uint32 bStatus, uint32, uint32, uint32) {
Expand Down Expand Up @@ -2608,7 +2608,7 @@ DECLARE_CUSTOM_FUNCTION(DoCredits)(CORO_PARAM, uint32 nMsg, uint32 dwTime, uint3
CORO_BEGIN_CODE(_ctx);

_ctx->msg = new RMMessage(nMsg);
_ctx->hDisable = g_scheduler->createEvent(true, false);
_ctx->hDisable = CoroScheduler.createEvent(true, false);

_ctx->text = new RMTextDialog[_ctx->msg->NumPeriods()];

Expand Down Expand Up @@ -2649,7 +2649,7 @@ DECLARE_CUSTOM_FUNCTION(DoCredits)(CORO_PARAM, uint32 nMsg, uint32 dwTime, uint3
break;
}

g_scheduler->setEvent(_ctx->hDisable);
CoroScheduler.setEvent(_ctx->hDisable);

CORO_INVOKE_0(WaitFrame);
CORO_INVOKE_0(WaitFrame);
Expand Down Expand Up @@ -2882,7 +2882,7 @@ void SetupGlobalVars(RMTony *tony, RMPointer *ptr, RMGameBoxes *box, RMLocation


// Crea l'evento per skippare le idle
hSkipIdle = g_scheduler->createEvent(true, false);
hSkipIdle = CoroScheduler.createEvent(true, false);
}

} // end of namespace Tony
36 changes: 18 additions & 18 deletions engines/tony/font.cpp
Expand Up @@ -2048,16 +2048,16 @@ RMTextDialog::RMTextDialog() : RMText() {
m_bForceNoTime = false;
m_bAlwaysDisplay = false;
m_bNoTab = false;
hCustomSkip = INVALID_PID_VALUE;
hCustomSkip2 = INVALID_PID_VALUE;
hCustomSkip = CORO_INVALID_PID_VALUE;
hCustomSkip2 = CORO_INVALID_PID_VALUE;
m_input = NULL;

// Crea l'evento di fine displaying
hEndDisplay = g_scheduler->createEvent(false, false);
hEndDisplay = CoroScheduler.createEvent(false, false);
}

RMTextDialog::~RMTextDialog() {
g_scheduler->closeEvent(hEndDisplay);
CoroScheduler.closeEvent(hEndDisplay);
}

void RMTextDialog::Show(void) {
Expand Down Expand Up @@ -2119,7 +2119,7 @@ void RMTextDialog::RemoveThis(CORO_PARAM, bool &result) {

// Frase NON di background
if (m_bSkipStatus) {
if (!(bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE))
if (!(bCfgDubbing && hCustomSkip2 != CORO_INVALID_PID_VALUE))
if (bCfgTimerizedText) {
if (!m_bForceNoTime)
if (_vm->GetTime() > (uint32)m_time + m_startTime)
Expand All @@ -2137,7 +2137,7 @@ void RMTextDialog::RemoveThis(CORO_PARAM, bool &result) {
}
// Frase di background
else {
if (!(bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE))
if (!(bCfgDubbing && hCustomSkip2 != CORO_INVALID_PID_VALUE))
if (!m_bForceNoTime)
if (_vm->GetTime() > (uint32)m_time + m_startTime)
return;
Expand All @@ -2148,15 +2148,15 @@ void RMTextDialog::RemoveThis(CORO_PARAM, bool &result) {
if (_vm->GetTime() > (uint32)m_time + m_startTime)
return;

if (hCustomSkip != INVALID_PID_VALUE) {
CORO_INVOKE_3(g_scheduler->waitForSingleObject, hCustomSkip, 0, &_ctx->expired);
if (hCustomSkip != CORO_INVALID_PID_VALUE) {
CORO_INVOKE_3(CoroScheduler.waitForSingleObject, hCustomSkip, 0, &_ctx->expired);
// == WAIT_OBJECT_0
if (!_ctx->expired)
return;
}

if (bCfgDubbing && hCustomSkip2 != INVALID_PID_VALUE) {
CORO_INVOKE_3(g_scheduler->waitForSingleObject, hCustomSkip2, 0, &_ctx->expired);
if (bCfgDubbing && hCustomSkip2 != CORO_INVALID_PID_VALUE) {
CORO_INVOKE_3(CoroScheduler.waitForSingleObject, hCustomSkip2, 0, &_ctx->expired);
// == WAIT_OBJECT_0
if (!_ctx->expired)
return;
Expand All @@ -2170,7 +2170,7 @@ void RMTextDialog::RemoveThis(CORO_PARAM, bool &result) {
void RMTextDialog::Unregister(void) {
RMGfxTask::Unregister();
assert(m_nInList == 0);
g_scheduler->setEvent(hEndDisplay);
CoroScheduler.setEvent(hEndDisplay);
}

void RMTextDialog::Draw(RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim) {
Expand All @@ -2194,7 +2194,7 @@ void RMTextDialog::SetCustomSkipHandle2(uint32 hCustom) {
}

void RMTextDialog::WaitForEndDisplay(CORO_PARAM) {
g_scheduler->waitForSingleObject(coroParam, hEndDisplay, INFINITE);
CoroScheduler.waitForSingleObject(coroParam, hEndDisplay, CORO_INFINITE);
}

void RMTextDialog::SetInput(RMInput *input) {
Expand Down Expand Up @@ -2287,10 +2287,10 @@ void RMTextItemName::DoFrame(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMLocation &
ptr.SetSpecialPointer(RMPointer::PTR_NONE);
else {
_ctx->hThread = mpalQueryDoAction(20, m_item->MpalCode(), 0);
if (_ctx->hThread == INVALID_PID_VALUE)
if (_ctx->hThread == CORO_INVALID_PID_VALUE)
ptr.SetSpecialPointer(RMPointer::PTR_NONE);
else
CORO_INVOKE_2(g_scheduler->waitForSingleObject, _ctx->hThread, INFINITE);
CORO_INVOKE_2(CoroScheduler.waitForSingleObject, _ctx->hThread, CORO_INFINITE);
}
}

Expand Down Expand Up @@ -2344,18 +2344,18 @@ RMDialogChoice::RMDialogChoice() {
DlgText.LoadPaletteWA(dlgpal);
DlgTextLine.LoadPaletteWA(dlgpal);

hUnreg = g_scheduler->createEvent(false, false);
hUnreg = CoroScheduler.createEvent(false, false);
bRemoveFromOT = false;
}

RMDialogChoice::~RMDialogChoice() {
g_scheduler->closeEvent(hUnreg);
CoroScheduler.closeEvent(hUnreg);
}

void RMDialogChoice::Unregister(void) {
RMGfxWoodyBuffer::Unregister();
assert(!m_nInList);
g_scheduler->pulseEvent(hUnreg);
CoroScheduler.pulseEvent(hUnreg);

bRemoveFromOT = false;
}
Expand Down Expand Up @@ -2547,7 +2547,7 @@ void RMDialogChoice::Hide(CORO_PARAM) {

m_bShow = false;
bRemoveFromOT = true;
CORO_INVOKE_2(g_scheduler->waitForSingleObject, hUnreg, INFINITE);
CORO_INVOKE_2(CoroScheduler.waitForSingleObject, hUnreg, CORO_INFINITE);

CORO_END_CODE;
}
Expand Down
1 change: 1 addition & 0 deletions engines/tony/font.h
Expand Up @@ -49,6 +49,7 @@
#define TONY_FONT_H

#include "common/system.h"
#include "common/coroutines.h"
#include "tony/gfxcore.h"
#include "tony/resid.h"
#include "tony/sched.h"
Expand Down
2 changes: 1 addition & 1 deletion engines/tony/game.cpp
Expand Up @@ -113,7 +113,7 @@ void MainUnfreeze(void) {
}

void MainWaitFrame(CORO_PARAM) {
g_scheduler->waitForSingleObject(coroParam, _vm->m_hEndOfFrame, INFINITE);
CoroScheduler.waitForSingleObject(coroParam, _vm->m_hEndOfFrame, CORO_INFINITE);
}

void MainShowMouse(void) {
Expand Down

0 comments on commit 68c1b0b

Please sign in to comment.