Skip to content

Commit

Permalink
TONY: Fixed some missed methods to coroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 10, 2012
1 parent 9a7393e commit 82361a3
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 57 deletions.
4 changes: 2 additions & 2 deletions engines/tony/custom.cpp
Expand Up @@ -1337,7 +1337,7 @@ DECLARE_CUSTOM_FUNCTION(MoveTonyAndWait)(CORO_PARAM, uint32 nX, uint32 nY, uint3

CORO_BEGIN_CODE(_ctx);

Tony->Move(RMPoint(nX, nY));
CORO_INVOKE_1(Tony->Move, RMPoint(nX, nY));

if (!bSkipIdle)
CORO_INVOKE_0(Tony->WaitForEndMovement);
Expand All @@ -1346,7 +1346,7 @@ DECLARE_CUSTOM_FUNCTION(MoveTonyAndWait)(CORO_PARAM, uint32 nX, uint32 nY, uint3
}

DECLARE_CUSTOM_FUNCTION(MoveTony)(CORO_PARAM, uint32 nX, uint32 nY, uint32, uint32) {
Tony->Move(RMPoint(nX, nY));
Tony->Move(coroParam, RMPoint(nX, nY));
}

DECLARE_CUSTOM_FUNCTION(ScrollLocation)(CORO_PARAM, uint32 nX, uint32 nY, uint32 sX, uint32 sY) {
Expand Down
10 changes: 5 additions & 5 deletions engines/tony/gfxengine.cpp
Expand Up @@ -208,7 +208,7 @@ void RMGfxEngine::DoFrame(CORO_PARAM, bool bDrawLocation) {
// ***************
if (m_input.MouseRightReleased()) {
if (m_inv.RightRelease(m_input.MousePos(), m_curAction)) {
m_tony.MoveAndDoAction(m_itemName.GetHotspot(),m_itemName.GetSelectedItem(),m_curAction);
CORO_INVOKE_3(m_tony.MoveAndDoAction, m_itemName.GetHotspot(), m_itemName.GetSelectedItem(), m_curAction);

m_curAction = TA_GOTO;
m_point.SetAction(m_curAction);
Expand Down Expand Up @@ -240,9 +240,9 @@ void RMGfxEngine::DoFrame(CORO_PARAM, bool bDrawLocation) {
//if (m_itemName.IsItemSelected())
{
if (m_curAction != TA_COMBINE)
m_tony.MoveAndDoAction(m_itemName.GetHotspot(), m_itemName.GetSelectedItem(), m_point.CurAction());
CORO_INVOKE_3(m_tony.MoveAndDoAction, m_itemName.GetHotspot(), m_itemName.GetSelectedItem(), m_point.CurAction());
else if (m_itemName.GetSelectedItem() != NULL)
m_tony.MoveAndDoAction(m_itemName.GetHotspot(), m_itemName.GetSelectedItem(), TA_COMBINE, m_curActionObj);
CORO_INVOKE_3(m_tony.MoveAndDoAction, m_itemName.GetHotspot(), m_itemName.GetSelectedItem(), TA_COMBINE, m_curActionObj);
}

if (m_curAction == TA_COMBINE) {
Expand Down Expand Up @@ -283,7 +283,7 @@ void RMGfxEngine::DoFrame(CORO_PARAM, bool bDrawLocation) {
if (m_bGUIInterface) {
if (m_inter.Released(m_input.MousePos(),m_curAction)) {
m_point.SetAction(m_curAction);
m_tony.MoveAndDoAction(m_itemName.GetHotspot(),m_itemName.GetSelectedItem(), m_curAction);
CORO_INVOKE_3(m_tony.MoveAndDoAction, m_itemName.GetHotspot(), m_itemName.GetSelectedItem(), m_curAction);

m_curAction = TA_GOTO;
m_point.SetAction(m_curAction);
Expand All @@ -304,7 +304,7 @@ void RMGfxEngine::DoFrame(CORO_PARAM, bool bDrawLocation) {
}

// Anima Tony
m_tony.DoFrame(&m_bigBuf, m_nCurLoc);
CORO_INVOKE_2(m_tony.DoFrame, &m_bigBuf, m_nCurLoc);

// Aggiorna lo scrolling per tenere Tony dentro lo schermo
if (m_tony.MustUpdateScrolling() && m_bLocationLoaded) {
Expand Down
107 changes: 71 additions & 36 deletions engines/tony/loc.cpp
Expand Up @@ -1087,10 +1087,15 @@ short RMCharacter::FindPath(short source, short destination) {
}


void RMCharacter::GoTo(RMPoint destcoord, bool bReversed) {
void RMCharacter::GoTo(CORO_PARAM, RMPoint destcoord, bool bReversed) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);

CORO_BEGIN_CODE(_ctx);

if (m_pos == destcoord) {
if (minpath == 0) {
Stop();
CORO_INVOKE_0(Stop);
g_scheduler->pulseEvent(hEndOfPath);
return;
}
Expand Down Expand Up @@ -1149,6 +1154,7 @@ void RMCharacter::GoTo(RMPoint destcoord, bool bReversed) {
olddy = dy;

// ResetEvent(hTonyEndMovement); @@@
CORO_END_CODE;
}


Expand Down Expand Up @@ -1413,10 +1419,15 @@ void RMCharacter::NewBoxEntered(int nBox) {
mpalQueryDoAction(2, curLocation, curbox);
}

void RMCharacter::DoFrame(RMGfxTargetBuffer* bigBuf, int loc) {
bool bEndNow;
void RMCharacter::DoFrame(CORO_PARAM, RMGfxTargetBuffer* bigBuf, int loc) {
CORO_BEGIN_CONTEXT;
bool bEndNow;
RMBoxLoc *cur;
CORO_END_CONTEXT(_ctx);

bEndNow = false;
CORO_BEGIN_CODE(_ctx);

_ctx->bEndNow = false;
bEndOfPath = false;
bDrawNow = (curLocation == loc);

Expand All @@ -1435,7 +1446,7 @@ void RMCharacter::DoFrame(RMGfxTargetBuffer* bigBuf, int loc) {
if (((walkspeed > 0) && (m_pos.x > lineend.x)) || ((walkspeed < 0) && (m_pos.x < lineend.x))) {
m_pos = lineend;
status = STAND;
bEndNow = true;
_ctx->bEndNow = true;
}
}

Expand All @@ -1450,7 +1461,7 @@ void RMCharacter::DoFrame(RMGfxTargetBuffer* bigBuf, int loc) {
if (((walkspeed > 0) && (m_pos.y > lineend.y)) || ((walkspeed < 0) && (m_pos.y < lineend.y))) {
m_pos = lineend;
status = STAND;
bEndNow = true;
_ctx->bEndNow = true;
}
}

Expand All @@ -1463,9 +1474,9 @@ void RMCharacter::DoFrame(RMGfxTargetBuffer* bigBuf, int loc) {

// Se siamo appena arrivati alla destinazione temporanea ed è finito il percorso minimo,
// ci fermiamo definitivamente
if (bEndNow && minpath == 0) {
if (_ctx->bEndNow && minpath == 0) {
if (!bEndOfPath)
Stop();
CORO_INVOKE_0(Stop);
bEndOfPath = true;
g_scheduler->pulseEvent(hEndOfPath);
}
Expand All @@ -1487,23 +1498,23 @@ void RMCharacter::DoFrame(RMGfxTargetBuffer* bigBuf, int loc) {
if (status == STAND) {
// Controlliamo se c'è ancora percorso minimo da calcolare
if (minpath == 1) {
RMBoxLoc *cur = theBoxes->GetBoxes(curLocation);
_ctx->cur = theBoxes->GetBoxes(curLocation);

// Se dobbiamo ancora attraversare un box
if (pathcount < pathlenght) {
// Controlliamo che il box su cui stiamo entrando sia attivo
if (cur->boxes[path[pathcount-1]].attivo) {
if (_ctx->cur->boxes[path[pathcount-1]].attivo) {
// Muoviti in linea retta verso l'hotspot più vicino, tenendo conto del reversing please
// NEWBOX = path[pathcount-1]
GoTo(NearestHotSpot(path[pathcount-1], path[pathcount]), cur->boxes[path[pathcount-1]].bReversed);
CORO_INVOKE_2(GoTo, NearestHotSpot(path[pathcount-1], path[pathcount]), _ctx->cur->boxes[path[pathcount-1]].bReversed);
pathcount++;
} else {
// Se il box è disattivato, possiamo solo bloccare tutto
// @@@ Questo non dovrebbe più avvenire, dato che abbiamo migliorato
// la ricerca del percorso minimo
minpath = 0;
if (!bEndOfPath)
Stop();
CORO_INVOKE_0(Stop);
bEndOfPath = true;
g_scheduler->pulseEvent(hEndOfPath);
}
Expand All @@ -1512,7 +1523,7 @@ void RMCharacter::DoFrame(RMGfxTargetBuffer* bigBuf, int loc) {
// punto di arrivo
// NEWBOX = InWhichBox(pathend)
minpath = 0;
GoTo(pathend, cur->boxes[InWhichBox(pathend)].bReversed);
CORO_INVOKE_2(GoTo, pathend, _ctx->cur->boxes[InWhichBox(pathend)].bReversed);
}
}
}
Expand All @@ -1521,9 +1532,16 @@ void RMCharacter::DoFrame(RMGfxTargetBuffer* bigBuf, int loc) {

// Richiama il DoFrame dell'item
RMItem::DoFrame(bigBuf);

CORO_END_CODE;
}

void RMCharacter::Stop(void) {
void RMCharacter::Stop(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);

CORO_BEGIN_CODE(_ctx);

bMoving = false;

// Non si sa mai...
Expand Down Expand Up @@ -1558,48 +1576,57 @@ void RMCharacter::Stop(void) {
SetPattern(PAT_STANDDOWN);
break;
}

CORO_END_CODE;
}

inline int RMCharacter::InWhichBox(RMPoint pt) {
return theBoxes->WhichBox(curLocation,pt);
}


bool RMCharacter::Move(RMPoint pt) {
RMPoint dest;
int numbox;
void RMCharacter::Move(CORO_PARAM, RMPoint pt, bool *result) {
CORO_BEGIN_CONTEXT;
RMPoint dest;
int numbox;
RMBoxLoc *cur;
CORO_END_CONTEXT(_ctx);

CORO_BEGIN_CODE(_ctx);

bMoving = true;

// Se 0,0, non fare nulla, anzi fermati
if (pt.x == 0 && pt.y == 0) {
minpath = 0;
status = STAND;
Stop();
return true;
CORO_INVOKE_0(Stop);
if (result)
*result = true;
return;
}

// Se clicko fuori dai box
numbox = InWhichBox(pt);
if (numbox == -1) {
_ctx->numbox = InWhichBox(pt);
if (_ctx->numbox == -1) {
// Trova il punto più vicino dentro i box
dest = NearestPoint(pt);
_ctx->dest = NearestPoint(pt);

// ???!??
if (dest == pt)
dest = InvScanLine(pt);
if (_ctx->dest == pt)
_ctx->dest = InvScanLine(pt);

pt = dest;
numbox = InWhichBox(pt);
pt = _ctx->dest;
_ctx->numbox = InWhichBox(pt);
}

RMBoxLoc *cur = theBoxes->GetBoxes(curLocation);
_ctx->cur = theBoxes->GetBoxes(curLocation);

minpath = 0;
status = STAND;
bMovingWithoutMinpath = true;
if (ScanLine(pt))
GoTo(pt, cur->boxes[numbox].bReversed);
CORO_INVOKE_2(GoTo, pt, _ctx->cur->boxes[_ctx->numbox].bReversed);
else if (FindPath(InWhichBox(m_pos), InWhichBox(pt))) {
bMovingWithoutMinpath = false;
minpath = 1;
Expand All @@ -1609,22 +1636,30 @@ bool RMCharacter::Move(RMPoint pt) {
// @@@ Questo caso è se un hotspot è dentro un box
// ma non c'è un path per arrivarci. Usiamo quindi
// la invscanline per cercare un punto intorno
dest = InvScanLine(pt);
pt = dest;
_ctx->dest = InvScanLine(pt);
pt = _ctx->dest;

if (ScanLine(pt))
GoTo(pt,cur->boxes[numbox].bReversed);
CORO_INVOKE_2(GoTo, pt, _ctx->cur->boxes[_ctx->numbox].bReversed);
else if (FindPath(InWhichBox(m_pos), InWhichBox(pt))) {
bMovingWithoutMinpath = false;
minpath = 1;
pathcount = 1;
pathend = pt;
return true;
} else
return false;
if (result)
*result = true;
} else {
if (result)
*result = false;
}

return;
}

return true;
if (result)
*result = true;

CORO_END_CODE;
}

void RMCharacter::SetPosition(RMPoint pt, int newloc) {
Expand Down
8 changes: 4 additions & 4 deletions engines/tony/loc.h
Expand Up @@ -439,7 +439,7 @@ class RMCharacter : protected RMItem {
RMPoint Searching(char UP, char DOWN, char RIGHT, char LEFT, RMPoint punto);
RMPoint NearestPoint(RMPoint punto);

void GoTo(RMPoint destcoord, bool bReversed=false);
void GoTo(CORO_PARAM, RMPoint destcoord, bool bReversed=false);
short ScanLine(RMPoint punto);
RMPoint InvScanLine(RMPoint punto);
RMPoint NearestHotSpot(int sourcebox, int destbox);
Expand All @@ -461,7 +461,7 @@ class RMCharacter : protected RMItem {
virtual bool RemoveThis(void);

// Aggiorna la posizione del personaggio
void DoFrame(RMGfxTargetBuffer* bigBuf, int loc);
void DoFrame(CORO_PARAM, RMGfxTargetBuffer *bigBuf, int loc);

// Overloading del Draw
void Draw(RMGfxTargetBuffer& bigBuf, RMGfxPrimitive* prim);
Expand All @@ -470,13 +470,13 @@ class RMCharacter : protected RMItem {
bool EndOfPath() { return bEndOfPath; }

// Cambia il pattern del personaggio per fermarlo
virtual void Stop(void);
virtual void Stop(CORO_PARAM);

// Controlla se il personaggio si sta muovendo
bool IsMoving() { return bMoving; }

// Muove il personaggio a una certa posizione
bool Move(RMPoint pt);
void Move(CORO_PARAM, RMPoint pt, bool *result = NULL);

// Posiziona il personaggio a una certa posizione SENZA farlo muovere
void SetPosition(RMPoint pt, int newloc=-1);
Expand Down

0 comments on commit 82361a3

Please sign in to comment.