2008-07-23 09:02:47 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Handles effect polygons.
|
|
|
|
//
|
|
|
|
// EffectPolyProcess() monitors triggering of effect code (i.e. a moving
|
|
|
|
// actor entering an effect polygon).
|
|
|
|
// EffectProcess() runs the appropriate effect code.
|
|
|
|
//
|
|
|
|
// NOTE: Currently will only run one effect process at a time, i.e.
|
|
|
|
// effect polygons will not currently nest. It won't be very difficult
|
|
|
|
// to fix this if required.
|
|
|
|
|
|
|
|
#include "tinsel/actors.h"
|
|
|
|
#include "tinsel/dw.h"
|
|
|
|
#include "tinsel/events.h"
|
|
|
|
#include "tinsel/pid.h"
|
|
|
|
#include "tinsel/pcode.h" // LEAD_ACTOR
|
|
|
|
#include "tinsel/polygons.h"
|
|
|
|
#include "tinsel/rince.h"
|
|
|
|
#include "tinsel/sched.h"
|
2008-12-01 20:35:36 +00:00
|
|
|
#include "tinsel/tinsel.h"
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace Tinsel {
|
|
|
|
|
|
|
|
struct EP_INIT {
|
|
|
|
HPOLYGON hEpoly;
|
2008-12-01 20:35:36 +00:00
|
|
|
PMOVER pMover;
|
2008-07-23 09:02:47 +00:00
|
|
|
int index;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs an effect polygon's Glitter code with ENTER event, waits for the
|
|
|
|
* actor to leave that polygon. Then runs the polygon's Glitter code
|
|
|
|
* with LEAVE event.
|
|
|
|
*/
|
2008-07-24 08:59:17 +00:00
|
|
|
static void EffectProcess(CORO_PARAM, const void *param) {
|
2008-07-23 09:02:47 +00:00
|
|
|
// COROUTINE
|
|
|
|
CORO_BEGIN_CONTEXT;
|
|
|
|
CORO_END_CONTEXT(_ctx);
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
const EP_INIT *to = (const EP_INIT *)param; // get the stuff copied to process when it was created
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
CORO_BEGIN_CODE(_ctx);
|
|
|
|
|
|
|
|
int x, y; // Lead actor position
|
|
|
|
|
|
|
|
// Run effect poly enter script
|
2008-12-01 20:35:36 +00:00
|
|
|
if (TinselV2)
|
|
|
|
CORO_INVOKE_ARGS(PolygonEvent, (CORO_SUBCTX, to->hEpoly, WALKIN,
|
|
|
|
GetMoverId(to->pMover), false, 0));
|
|
|
|
else
|
|
|
|
effRunPolyTinselCode(to->hEpoly, WALKIN, to->pMover->actorID);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
CORO_SLEEP(1);
|
2008-12-01 20:35:36 +00:00
|
|
|
GetMoverPosition(to->pMover, &x, &y);
|
2008-07-23 09:02:47 +00:00
|
|
|
} while (InPolygon(x, y, EFFECT) == to->hEpoly);
|
|
|
|
|
|
|
|
// Run effect poly leave script
|
2008-12-01 20:35:36 +00:00
|
|
|
if (TinselV2)
|
|
|
|
CORO_INVOKE_ARGS(PolygonEvent, (CORO_SUBCTX, to->hEpoly, WALKOUT,
|
|
|
|
GetMoverId(to->pMover), false, 0));
|
|
|
|
else
|
|
|
|
effRunPolyTinselCode(to->hEpoly, WALKOUT, to->pMover->actorID);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
SetMoverInEffect(to->index, false);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
CORO_END_CODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the actor was not already in an effect polygon, checks to see if
|
|
|
|
* it has just entered one. If it has, a process is started up to run
|
|
|
|
* the polygon's Glitter code.
|
|
|
|
*/
|
2008-12-01 20:35:36 +00:00
|
|
|
static void FettleEffectPolys(int x, int y, int index, PMOVER pActor) {
|
2008-07-23 09:02:47 +00:00
|
|
|
HPOLYGON hPoly;
|
|
|
|
EP_INIT epi;
|
|
|
|
|
|
|
|
// If just entered an effect polygon, the effect should be triggered.
|
|
|
|
if (!IsMAinEffectPoly(index)) {
|
|
|
|
hPoly = InPolygon(x, y, EFFECT);
|
|
|
|
if (hPoly != NOPOLY) {
|
|
|
|
//Just entered effect polygon
|
2008-12-01 20:35:36 +00:00
|
|
|
SetMoverInEffect(index, true);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
epi.hEpoly = hPoly;
|
2008-12-01 20:35:36 +00:00
|
|
|
epi.pMover = pActor;
|
2008-07-23 09:02:47 +00:00
|
|
|
epi.index = index;
|
2008-07-24 08:59:17 +00:00
|
|
|
g_scheduler->createProcess(PID_TCODE, EffectProcess, &epi, sizeof(epi));
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Just calls FettleEffectPolys() every clock tick.
|
|
|
|
*/
|
2008-07-24 08:59:17 +00:00
|
|
|
void EffectPolyProcess(CORO_PARAM, const void *param) {
|
2008-07-23 09:02:47 +00:00
|
|
|
// COROUTINE
|
|
|
|
CORO_BEGIN_CONTEXT;
|
|
|
|
CORO_END_CONTEXT(_ctx);
|
|
|
|
|
|
|
|
CORO_BEGIN_CODE(_ctx);
|
|
|
|
while (1) {
|
|
|
|
for (int i = 0; i < MAX_MOVERS; i++) {
|
2008-12-01 20:35:36 +00:00
|
|
|
PMOVER pActor = GetLiveMover(i);
|
2008-07-23 09:02:47 +00:00
|
|
|
if (pActor != NULL) {
|
|
|
|
int x, y;
|
2008-12-01 20:35:36 +00:00
|
|
|
GetMoverPosition(pActor, &x, &y);
|
2008-07-23 09:02:47 +00:00
|
|
|
FettleEffectPolys(x, y, i, pActor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CORO_SLEEP(1); // allow re-scheduling
|
|
|
|
}
|
|
|
|
CORO_END_CODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Tinsel
|