Skip to content

Commit

Permalink
TINSEL: Refactored Tinsel engine to use the Common coroutine scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 17, 2012
1 parent c6810c1 commit 41692ef
Show file tree
Hide file tree
Showing 32 changed files with 137 additions and 777 deletions.
12 changes: 6 additions & 6 deletions engines/tinsel/actors.cpp
Expand Up @@ -340,7 +340,7 @@ void RestoreActorProcess(int id, INT_CONTEXT *pic, bool savegameFlag) {
if (savegameFlag)
pic->resumeState = RES_SAVEGAME;

g_scheduler->createProcess(PID_TCODE, ActorRestoredProcess, &r, sizeof(r));
CoroScheduler.createProcess(PID_TCODE, ActorRestoredProcess, &r, sizeof(r));
}

/**
Expand All @@ -358,7 +358,7 @@ void ActorEvent(int ano, TINSEL_EVENT event, PLR_EVENT be) {
atp.event = event;
atp.bev = be;
atp.pic = NULL;
g_scheduler->createProcess(PID_TCODE, ActorTinselProcess, &atp, sizeof(atp));
CoroScheduler.createProcess(PID_TCODE, ActorTinselProcess, &atp, sizeof(atp));
}
}

Expand All @@ -369,7 +369,7 @@ void ActorEvent(CORO_PARAM, int ano, TINSEL_EVENT tEvent, bool bWait, int myEsca
ATP_INIT atp;
int index;
CORO_BEGIN_CONTEXT;
PPROCESS pProc;
Common::PPROCESS pProc;
CORO_END_CONTEXT(_ctx);

CORO_BEGIN_CODE(_ctx);
Expand All @@ -389,7 +389,7 @@ void ActorEvent(CORO_PARAM, int ano, TINSEL_EVENT tEvent, bool bWait, int myEsca
myEscape);

if (atp.pic != NULL) {
_ctx->pProc = g_scheduler->createProcess(PID_TCODE, ActorTinselProcess, &atp, sizeof(atp));
_ctx->pProc = CoroScheduler.createProcess(PID_TCODE, ActorTinselProcess, &atp, sizeof(atp));
AttachInterpret(atp.pic, _ctx->pProc);

if (bWait)
Expand Down Expand Up @@ -474,8 +474,8 @@ void StartTaggedActors(SCNHANDLE ah, int numActors, bool bRunScript) {
// Run actor's script for this scene
if (bRunScript) {
// Send in reverse order - they get swapped round in the scheduler
ActorEvent(nullContext, taggedActors[i].id, SHOWEVENT, false, 0);
ActorEvent(nullContext, taggedActors[i].id, STARTUP, false, 0);
ActorEvent(Common::nullContext, taggedActors[i].id, SHOWEVENT, false, 0);
ActorEvent(Common::nullContext, taggedActors[i].id, STARTUP, false, 0);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion engines/tinsel/background.h
Expand Up @@ -24,9 +24,9 @@
#ifndef TINSEL_BACKGND_H // prevent multiple includes
#define TINSEL_BACKGND_H

#include "common/coroutines.h"
#include "common/frac.h"
#include "common/rect.h"
#include "tinsel/coroutine.h"
#include "tinsel/dw.h" // for SCNHANDLE
#include "tinsel/palette.h" // palette definitions

Expand Down
6 changes: 3 additions & 3 deletions engines/tinsel/bg.cpp
Expand Up @@ -255,17 +255,17 @@ void StartupBackground(CORO_PARAM, SCNHANDLE hFilm) {
g_BGspeed = ONE_SECOND / FROM_LE_32(pfilm->frate);

// Start display process for each reel in the film
g_scheduler->createProcess(PID_REEL, BGmainProcess, &pfilm->reels[0], sizeof(FREEL));
CoroScheduler.createProcess(PID_REEL, BGmainProcess, &pfilm->reels[0], sizeof(FREEL));

if (TinselV0) {
for (uint i = 1; i < FROM_LE_32(pfilm->numreels); ++i)
g_scheduler->createProcess(PID_REEL, BGotherProcess, &pfilm->reels[i], sizeof(FREEL));
CoroScheduler.createProcess(PID_REEL, BGotherProcess, &pfilm->reels[i], sizeof(FREEL));
}

if (g_pBG[0] == NULL)
ControlStartOff();

if (TinselV2 && (coroParam != nullContext))
if (TinselV2 && (coroParam != Common::nullContext))
CORO_GIVE_WAY;

CORO_END_CODE;
Expand Down
4 changes: 2 additions & 2 deletions engines/tinsel/bmv.cpp
Expand Up @@ -529,7 +529,7 @@ int BMVPlayer::MovieCommand(char cmd, int commandOffset) {
if (cmd & CD_PRINT) {
PRINT_CMD *pCmd = (PRINT_CMD *)(bigBuffer + commandOffset);

MovieText(nullContext, (int16)READ_LE_UINT16(&pCmd->stringId),
MovieText(Common::nullContext, (int16)READ_LE_UINT16(&pCmd->stringId),
(int16)READ_LE_UINT16(&pCmd->x),
(int16)READ_LE_UINT16(&pCmd->y),
pCmd->fontId,
Expand All @@ -542,7 +542,7 @@ int BMVPlayer::MovieCommand(char cmd, int commandOffset) {
TALK_CMD *pCmd = (TALK_CMD *)(bigBuffer + commandOffset);
talkColor = TINSEL_RGB(pCmd->r, pCmd->g, pCmd->b);

MovieText(nullContext, (int16)READ_LE_UINT16(&pCmd->stringId),
MovieText(Common::nullContext, (int16)READ_LE_UINT16(&pCmd->stringId),
(int16)READ_LE_UINT16(&pCmd->x),
(int16)READ_LE_UINT16(&pCmd->y),
0,
Expand Down
2 changes: 1 addition & 1 deletion engines/tinsel/bmv.h
Expand Up @@ -24,12 +24,12 @@
#ifndef TINSEL_BMV_H
#define TINSEL_BMV_H

#include "common/coroutines.h"
#include "common/file.h"

#include "audio/audiostream.h"
#include "audio/mixer.h"

#include "tinsel/coroutine.h"
#include "tinsel/object.h"
#include "tinsel/palette.h"

Expand Down
82 changes: 0 additions & 82 deletions engines/tinsel/coroutine.cpp

This file was deleted.

20 changes: 10 additions & 10 deletions engines/tinsel/dialogs.cpp
Expand Up @@ -1075,7 +1075,7 @@ static void PrimeSceneHopper() {
uint32 vSize;

// Open the file (it's on the CD)
CdCD(nullContext);
CdCD(Common::nullContext);
if (!f.open(HOPPER_FILENAME))
error(CANNOT_FIND_FILE, HOPPER_FILENAME);

Expand Down Expand Up @@ -1191,13 +1191,13 @@ static void HopAction() {
debugC(DEBUG_BASIC, kTinselDebugAnimations, "Scene hopper chose scene %xh,%d\n", hScene, eNumber);

if (FROM_LE_32(pEntry->flags) & fCall) {
SaveScene(nullContext);
NewScene(nullContext, g_pChosenScene->hScene, pEntry->eNumber, TRANS_FADE);
SaveScene(Common::nullContext);
NewScene(Common::nullContext, g_pChosenScene->hScene, pEntry->eNumber, TRANS_FADE);
}
else if (FROM_LE_32(pEntry->flags) & fHook)
HookScene(hScene, eNumber, TRANS_FADE);
else
NewScene(nullContext, hScene, eNumber, TRANS_CUT);
NewScene(Common::nullContext, hScene, eNumber, TRANS_CUT);
}

/**************************************************************************/
Expand Down Expand Up @@ -1406,13 +1406,13 @@ static void InvTinselEvent(INV_OBJECT *pinvo, TINSEL_EVENT event, PLR_EVENT be,
return;

g_GlitterIndex = index;
g_scheduler->createProcess(PID_TCODE, ObjectProcess, &to, sizeof(to));
CoroScheduler.createProcess(PID_TCODE, ObjectProcess, &to, sizeof(to));
}

extern void ObjectEvent(CORO_PARAM, int objId, TINSEL_EVENT event, bool bWait, int myEscape, bool *result) {
// COROUTINE
CORO_BEGIN_CONTEXT;
PROCESS *pProc;
Common::PROCESS *pProc;
INV_OBJECT *pInvo;
OP_INIT op;
CORO_END_CONTEXT(_ctx);
Expand All @@ -1428,7 +1428,7 @@ extern void ObjectEvent(CORO_PARAM, int objId, TINSEL_EVENT event, bool bWait, i
_ctx->op.event = event;
_ctx->op.myEscape = myEscape;

g_scheduler->createProcess(PID_TCODE, ObjectProcess, &_ctx->op, sizeof(_ctx->op));
CoroScheduler.createProcess(PID_TCODE, ObjectProcess, &_ctx->op, sizeof(_ctx->op));

if (bWait)
CORO_INVOKE_2(WaitInterpret, _ctx->pProc, result);
Expand Down Expand Up @@ -3540,9 +3540,9 @@ extern void ConvAction(int index) {
}

if (g_thisConvPoly != NOPOLY)
PolygonEvent(nullContext, g_thisConvPoly, CONVERSE, 0, false, 0);
PolygonEvent(Common::nullContext, g_thisConvPoly, CONVERSE, 0, false, 0);
else
ActorEvent(nullContext, g_thisConvActor, CONVERSE, false, 0);
ActorEvent(Common::nullContext, g_thisConvActor, CONVERSE, false, 0);
}

}
Expand Down Expand Up @@ -5128,7 +5128,7 @@ static void InvPickup(int index) {
if (TinselV2)
InvPutDown(index);
else
g_scheduler->createProcess(PID_TCODE, InvPdProcess, &index, sizeof(index));
CoroScheduler.createProcess(PID_TCODE, InvPdProcess, &index, sizeof(index));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions engines/tinsel/drives.cpp
Expand Up @@ -48,13 +48,13 @@ void CdCD(CORO_PARAM) {
CORO_BEGIN_CODE(_ctx);

while (g_bChangingCD) {
if (g_scheduler->getCurrentProcess()) {
// FIXME: CdCD gets passed a nullContext in RegisterGlobals() and
if (CoroScheduler.getCurrentProcess()) {
// FIXME: CdCD gets passed a Common::nullContext in RegisterGlobals() and
// PrimeSceneHopper(), because I didn't know how to get a proper
// context without converting the whole calling stack to CORO'd
// functions. If these functions really get called while a CD
// change is requested, this needs to be resolved.
if (coroParam == nullContext)
if (coroParam == Common::nullContext)
error("CdCD needs context");
CORO_SLEEP(1);
} else
Expand Down
2 changes: 1 addition & 1 deletion engines/tinsel/drives.h
Expand Up @@ -24,9 +24,9 @@
#ifndef TINSEL_DRIVES_H
#define TINSEL_DRIVES_H

#include "common/coroutines.h"
#include "common/stream.h"
#include "tinsel/dw.h"
#include "tinsel/coroutine.h"

namespace Tinsel {

Expand Down
2 changes: 1 addition & 1 deletion engines/tinsel/effect.cpp
Expand Up @@ -108,7 +108,7 @@ static void FettleEffectPolys(int x, int y, int index, PMOVER pActor) {
epi.hEpoly = hPoly;
epi.pMover = pActor;
epi.index = index;
g_scheduler->createProcess(PID_TCODE, EffectProcess, &epi, sizeof(epi));
CoroScheduler.createProcess(PID_TCODE, EffectProcess, &epi, sizeof(epi));
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions engines/tinsel/events.cpp
Expand Up @@ -22,10 +22,10 @@
* Also provides a couple of utility functions.
*/

#include "common/coroutines.h"
#include "tinsel/actors.h"
#include "tinsel/background.h"
#include "tinsel/config.h"
#include "tinsel/coroutine.h"
#include "tinsel/cursor.h"
#include "tinsel/dw.h"
#include "tinsel/events.h"
Expand Down Expand Up @@ -276,7 +276,7 @@ static void WalkProcess(CORO_PARAM, const void *param) {
void WalkTo(int x, int y) {
WP_INIT to = { x, y };

g_scheduler->createProcess(PID_TCODE, WalkProcess, &to, sizeof(to));
CoroScheduler.createProcess(PID_TCODE, WalkProcess, &to, sizeof(to));
}

/**
Expand All @@ -295,15 +295,15 @@ static void ProcessUserEvent(TINSEL_EVENT uEvent, const Common::Point &coOrds, P
if ((actor = GetTaggedActor()) != 0) {
// Event for a tagged actor
if (TinselV2)
ActorEvent(nullContext, actor, uEvent, false, 0);
ActorEvent(Common::nullContext, actor, uEvent, false, 0);
else
ActorEvent(actor, uEvent, be);
} else if ((hPoly = GetTaggedPoly()) != NOPOLY) {
// Event for active tagged polygon
if (!TinselV2)
RunPolyTinselCode(hPoly, uEvent, be, false);
else if (uEvent != PROV_WALKTO)
PolygonEvent(nullContext, hPoly, uEvent, 0, false, 0);
PolygonEvent(Common::nullContext, hPoly, uEvent, 0, false, 0);

} else {
GetCursorXY(&aniX, &aniY, true);
Expand All @@ -312,7 +312,7 @@ static void ProcessUserEvent(TINSEL_EVENT uEvent, const Common::Point &coOrds, P
if ((hPoly = InPolygon(aniX, aniY, TAG)) != NOPOLY ||
(!TinselV2 && ((hPoly = InPolygon(aniX, aniY, EXIT)) != NOPOLY))) {
if (TinselV2 && (uEvent != PROV_WALKTO))
PolygonEvent(nullContext, hPoly, uEvent, 0, false, 0);
PolygonEvent(Common::nullContext, hPoly, uEvent, 0, false, 0);
else if (!TinselV2)
RunPolyTinselCode(hPoly, uEvent, be, false);
} else if ((uEvent == PROV_WALKTO) || (uEvent == WALKTO)) {
Expand Down Expand Up @@ -604,7 +604,7 @@ void PolyTinselProcess(CORO_PARAM, const void *param) {
void PolygonEvent(CORO_PARAM, HPOLYGON hPoly, TINSEL_EVENT tEvent, int actor, bool bWait,
int myEscape, bool *result) {
CORO_BEGIN_CONTEXT;
PPROCESS pProc;
Common::PPROCESS pProc;
CORO_END_CONTEXT(_ctx);

CORO_BEGIN_CODE(_ctx);
Expand All @@ -623,7 +623,7 @@ void PolygonEvent(CORO_PARAM, HPOLYGON hPoly, TINSEL_EVENT tEvent, int actor, bo
NULL, // No Object
myEscape);
if (to.pic != NULL) {
_ctx->pProc = g_scheduler->createProcess(PID_TCODE, PolyTinselProcess, &to, sizeof(to));
_ctx->pProc = CoroScheduler.createProcess(PID_TCODE, PolyTinselProcess, &to, sizeof(to));
AttachInterpret(to.pic, _ctx->pProc);

if (bWait)
Expand All @@ -640,14 +640,14 @@ void RunPolyTinselCode(HPOLYGON hPoly, TINSEL_EVENT event, PLR_EVENT be, bool tc
PTP_INIT to = { hPoly, event, be, tc, 0, NULL };

assert(!TinselV2);
g_scheduler->createProcess(PID_TCODE, PolyTinselProcess, &to, sizeof(to));
CoroScheduler.createProcess(PID_TCODE, PolyTinselProcess, &to, sizeof(to));
}

void effRunPolyTinselCode(HPOLYGON hPoly, TINSEL_EVENT event, int actor) {
PTP_INIT to = { hPoly, event, PLR_NOEVENT, false, actor, NULL };

assert(!TinselV2);
g_scheduler->createProcess(PID_TCODE, PolyTinselProcess, &to, sizeof(to));
CoroScheduler.createProcess(PID_TCODE, PolyTinselProcess, &to, sizeof(to));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions engines/tinsel/events.h
Expand Up @@ -24,9 +24,9 @@
#ifndef TINSEL_EVENTS_H
#define TINSEL_EVENTS_H

#include "tinsel/dw.h"
#include "tinsel/coroutine.h"
#include "common/coroutines.h"
#include "common/rect.h"
#include "tinsel/dw.h"

namespace Tinsel {

Expand Down

0 comments on commit 41692ef

Please sign in to comment.