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.
|
|
|
|
*
|
|
|
|
* Handles scrolling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tinsel/actors.h"
|
|
|
|
#include "tinsel/background.h"
|
|
|
|
#include "tinsel/cursor.h"
|
|
|
|
#include "tinsel/dw.h"
|
|
|
|
#include "tinsel/graphics.h"
|
|
|
|
#include "tinsel/polygons.h"
|
|
|
|
#include "tinsel/rince.h"
|
|
|
|
#include "tinsel/scroll.h"
|
|
|
|
#include "tinsel/sched.h"
|
2008-12-01 20:35:36 +00:00
|
|
|
#include "tinsel/sysvar.h"
|
|
|
|
#include "tinsel/tinsel.h"
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
namespace Tinsel {
|
|
|
|
|
|
|
|
//----------------- LOCAL DEFINES --------------------
|
|
|
|
|
|
|
|
#define LEFT 'L'
|
|
|
|
#define RIGHT 'R'
|
|
|
|
#define UP 'U'
|
|
|
|
#define DOWN 'D'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------- LOCAL GLOBAL DATA --------------------
|
|
|
|
|
2010-11-16 09:53:55 +00:00
|
|
|
// FIXME: Avoid non-const global vars
|
|
|
|
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
static int g_LeftScroll = 0, g_DownScroll = 0; // Number of iterations outstanding
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
static int g_scrollActor = 0;
|
|
|
|
static PMOVER g_pScrollMover = 0;
|
|
|
|
static int g_oldx = 0, g_oldy = 0;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
/** Boundaries and numbers of boundaries */
|
2012-02-22 22:14:29 +00:00
|
|
|
static SCROLLDATA g_sd = {
|
2008-07-23 09:02:47 +00:00
|
|
|
{
|
2009-01-01 15:06:43 +00:00
|
|
|
{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0},
|
2008-07-23 09:02:47 +00:00
|
|
|
{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}
|
|
|
|
},
|
|
|
|
{
|
2009-01-01 15:06:43 +00:00
|
|
|
{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0},
|
2008-07-23 09:02:47 +00:00
|
|
|
{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}
|
|
|
|
},
|
|
|
|
0,
|
2008-12-01 20:35:36 +00:00
|
|
|
0,
|
|
|
|
// DW2 fields
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2008-07-23 09:02:47 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
static int g_ImageH = 0, g_ImageW = 0;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
static bool g_ScrollCursor = 0; // If a TAG or EXIT polygon is clicked on,
|
2008-07-23 09:02:47 +00:00
|
|
|
// the cursor is kept over that polygon
|
|
|
|
// whilst scrolling
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
static int g_scrollPixelsX = SCROLLPIXELS;
|
|
|
|
static int g_scrollPixelsY = SCROLLPIXELS;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the ScrollCursor flag
|
|
|
|
*/
|
2009-11-02 21:54:57 +00:00
|
|
|
void DontScrollCursor() {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_ScrollCursor = false;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the ScrollCursor flag
|
|
|
|
*/
|
2009-11-02 21:54:57 +00:00
|
|
|
void DoScrollCursor() {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_ScrollCursor = true;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Configure a no-scroll boundary for a scene.
|
|
|
|
*/
|
|
|
|
void SetNoScroll(int x1, int y1, int x2, int y2) {
|
|
|
|
if (x1 == x2) {
|
|
|
|
/* Vertical line */
|
2012-02-22 22:14:29 +00:00
|
|
|
assert(g_sd.NumNoH < MAX_HNOSCROLL);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.NoHScroll[g_sd.NumNoH].ln = x1; // X pos of vertical line
|
|
|
|
g_sd.NoHScroll[g_sd.NumNoH].c1 = y1;
|
|
|
|
g_sd.NoHScroll[g_sd.NumNoH].c2 = y2;
|
|
|
|
g_sd.NumNoH++;
|
2008-07-23 09:02:47 +00:00
|
|
|
} else if (y1 == y2) {
|
|
|
|
/* Horizontal line */
|
2012-02-22 22:14:29 +00:00
|
|
|
assert(g_sd.NumNoV < MAX_VNOSCROLL);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.NoVScroll[g_sd.NumNoV].ln = y1; // Y pos of horizontal line
|
|
|
|
g_sd.NoVScroll[g_sd.NumNoV].c1 = x1;
|
|
|
|
g_sd.NoVScroll[g_sd.NumNoV].c2 = x2;
|
|
|
|
g_sd.NumNoV++;
|
2008-07-23 09:02:47 +00:00
|
|
|
} else {
|
|
|
|
/* No-scroll lines must be horizontal or vertical */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from scroll process when it thinks that a scroll is in order.
|
|
|
|
* Checks for no-scroll boundaries and sets off a scroll if allowed.
|
|
|
|
*/
|
|
|
|
static void NeedScroll(int direction) {
|
|
|
|
uint i;
|
|
|
|
int BottomLine, RightCol;
|
|
|
|
int Loffset, Toffset;
|
|
|
|
|
|
|
|
// get background offsets
|
|
|
|
PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset);
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
case LEFT: /* Picture will go left, 'camera' right */
|
|
|
|
|
|
|
|
BottomLine = Toffset + (SCREEN_HEIGHT - 1);
|
|
|
|
RightCol = Loffset + (SCREEN_WIDTH - 1);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
for (i = 0; i < g_sd.NumNoH; i++) {
|
|
|
|
if (RightCol >= g_sd.NoHScroll[i].ln - 1 && RightCol <= g_sd.NoHScroll[i].ln + 1 &&
|
|
|
|
((g_sd.NoHScroll[i].c1 >= Toffset && g_sd.NoHScroll[i].c1 <= BottomLine) ||
|
|
|
|
(g_sd.NoHScroll[i].c2 >= Toffset && g_sd.NoHScroll[i].c2 <= BottomLine) ||
|
|
|
|
(g_sd.NoHScroll[i].c1 < Toffset && g_sd.NoHScroll[i].c2 > BottomLine)))
|
2008-07-23 09:02:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_LeftScroll <= 0) {
|
2008-12-01 20:35:36 +00:00
|
|
|
if (TinselV2) {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsX = g_sd.xSpeed;
|
|
|
|
g_LeftScroll += g_sd.xDistance;
|
2008-12-01 20:35:36 +00:00
|
|
|
} else {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsX = SCROLLPIXELS;
|
|
|
|
g_LeftScroll = RLSCROLL;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIGHT: /* Picture will go right, 'camera' left */
|
|
|
|
|
|
|
|
BottomLine = Toffset + (SCREEN_HEIGHT - 1);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
for (i = 0; i < g_sd.NumNoH; i++) {
|
|
|
|
if (Loffset >= g_sd.NoHScroll[i].ln - 1 && Loffset <= g_sd.NoHScroll[i].ln + 1 &&
|
|
|
|
((g_sd.NoHScroll[i].c1 >= Toffset && g_sd.NoHScroll[i].c1 <= BottomLine) ||
|
|
|
|
(g_sd.NoHScroll[i].c2 >= Toffset && g_sd.NoHScroll[i].c2 <= BottomLine) ||
|
|
|
|
(g_sd.NoHScroll[i].c1 < Toffset && g_sd.NoHScroll[i].c2 > BottomLine)))
|
2008-07-23 09:02:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_LeftScroll >= 0) {
|
2008-12-01 20:35:36 +00:00
|
|
|
if (TinselV2) {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsX = g_sd.xSpeed;
|
|
|
|
g_LeftScroll -= g_sd.xDistance;
|
2008-12-01 20:35:36 +00:00
|
|
|
} else {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsX = SCROLLPIXELS;
|
|
|
|
g_LeftScroll = -RLSCROLL;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UP: /* Picture will go upwards, 'camera' downwards */
|
|
|
|
|
|
|
|
BottomLine = Toffset + (SCREEN_HEIGHT - 1);
|
|
|
|
RightCol = Loffset + (SCREEN_WIDTH - 1);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
for (i = 0; i < g_sd.NumNoV; i++) {
|
|
|
|
if ((BottomLine >= g_sd.NoVScroll[i].ln - 1 && BottomLine <= g_sd.NoVScroll[i].ln + 1) &&
|
|
|
|
((g_sd.NoVScroll[i].c1 >= Loffset && g_sd.NoVScroll[i].c1 <= RightCol) ||
|
|
|
|
(g_sd.NoVScroll[i].c2 >= Loffset && g_sd.NoVScroll[i].c2 <= RightCol) ||
|
|
|
|
(g_sd.NoVScroll[i].c1 < Loffset && g_sd.NoVScroll[i].c2 > RightCol)))
|
2008-07-23 09:02:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_DownScroll <= 0) {
|
2008-12-01 20:35:36 +00:00
|
|
|
if (TinselV2) {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsY = g_sd.ySpeed;
|
|
|
|
g_DownScroll += g_sd.yDistance;
|
2008-12-01 20:35:36 +00:00
|
|
|
} else {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsY = SCROLLPIXELS;
|
|
|
|
g_DownScroll = UDSCROLL;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DOWN: /* Picture will go downwards, 'camera' upwards */
|
|
|
|
|
|
|
|
RightCol = Loffset + (SCREEN_WIDTH - 1);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
for (i = 0; i < g_sd.NumNoV; i++) {
|
|
|
|
if (Toffset >= g_sd.NoVScroll[i].ln - 1 && Toffset <= g_sd.NoVScroll[i].ln + 1 &&
|
|
|
|
((g_sd.NoVScroll[i].c1 >= Loffset && g_sd.NoVScroll[i].c1 <= RightCol) ||
|
|
|
|
(g_sd.NoVScroll[i].c2 >= Loffset && g_sd.NoVScroll[i].c2 <= RightCol) ||
|
|
|
|
(g_sd.NoVScroll[i].c1 < Loffset && g_sd.NoVScroll[i].c2 > RightCol)))
|
2008-07-23 09:02:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_DownScroll >= 0) {
|
2008-12-01 20:35:36 +00:00
|
|
|
if (TinselV2) {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsY = g_sd.ySpeed;
|
|
|
|
g_DownScroll -= g_sd.yDistance;
|
2008-12-01 20:35:36 +00:00
|
|
|
} else {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsY = SCROLLPIXELS;
|
|
|
|
g_DownScroll = -UDSCROLL;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from scroll process - Scrolls the image as appropriate.
|
|
|
|
*/
|
2009-11-02 21:54:57 +00:00
|
|
|
static void ScrollImage() {
|
2008-07-23 09:02:47 +00:00
|
|
|
int OldLoffset = 0, OldToffset = 0; // Used when keeping cursor on a tag
|
|
|
|
int Loffset, Toffset;
|
|
|
|
int curX, curY;
|
|
|
|
|
|
|
|
// get background offsets
|
|
|
|
PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keeping cursor on a tag?
|
|
|
|
*/
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_ScrollCursor) {
|
2008-12-01 20:35:36 +00:00
|
|
|
GetCursorXYNoWait(&curX, &curY, true);
|
2008-07-23 09:02:47 +00:00
|
|
|
if (InPolygon(curX, curY, TAG) != NOPOLY || InPolygon(curX, curY, EXIT) != NOPOLY) {
|
|
|
|
OldLoffset = Loffset;
|
|
|
|
OldToffset = Toffset;
|
|
|
|
} else
|
2012-02-22 22:14:29 +00:00
|
|
|
g_ScrollCursor = false;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Horizontal scrolling
|
|
|
|
*/
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_LeftScroll > 0) {
|
|
|
|
g_LeftScroll -= g_scrollPixelsX;
|
|
|
|
if (g_LeftScroll < 0) {
|
|
|
|
Loffset += g_LeftScroll;
|
|
|
|
g_LeftScroll = 0;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
2012-02-22 22:14:29 +00:00
|
|
|
Loffset += g_scrollPixelsX; // Move right
|
|
|
|
if (Loffset > g_ImageW - SCREEN_WIDTH)
|
|
|
|
Loffset = g_ImageW - SCREEN_WIDTH;// Now at extreme right
|
2008-12-01 20:35:36 +00:00
|
|
|
|
|
|
|
/*** New feature to prop up rickety scroll boundaries ***/
|
|
|
|
if (TinselV2 && SysVar(SV_MaximumXoffset) && (Loffset > SysVar(SV_MaximumXoffset)))
|
|
|
|
Loffset = SysVar(SV_MaximumXoffset);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
} else if (g_LeftScroll < 0) {
|
|
|
|
g_LeftScroll += g_scrollPixelsX;
|
|
|
|
if (g_LeftScroll > 0) {
|
|
|
|
Loffset += g_LeftScroll;
|
|
|
|
g_LeftScroll = 0;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
2012-02-22 22:14:29 +00:00
|
|
|
Loffset -= g_scrollPixelsX; // Move left
|
2008-07-23 09:02:47 +00:00
|
|
|
if (Loffset < 0)
|
|
|
|
Loffset = 0; // Now at extreme left
|
2008-12-01 20:35:36 +00:00
|
|
|
|
|
|
|
/*** New feature to prop up rickety scroll boundaries ***/
|
|
|
|
if (TinselV2 && SysVar(SV_MinimumXoffset) && (Loffset < SysVar(SV_MinimumXoffset)))
|
|
|
|
Loffset = SysVar(SV_MinimumXoffset);
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Vertical scrolling
|
|
|
|
*/
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_DownScroll > 0) {
|
|
|
|
g_DownScroll -= g_scrollPixelsY;
|
|
|
|
if (g_DownScroll < 0) {
|
|
|
|
Toffset += g_DownScroll;
|
|
|
|
g_DownScroll = 0;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
2012-02-22 22:14:29 +00:00
|
|
|
Toffset += g_scrollPixelsY; // Move down
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (Toffset > g_ImageH - SCREEN_HEIGHT)
|
|
|
|
Toffset = g_ImageH - SCREEN_HEIGHT;// Now at extreme bottom
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
/*** New feature to prop up rickety scroll boundaries ***/
|
|
|
|
if (TinselV2 && SysVar(SV_MaximumYoffset) && Toffset > SysVar(SV_MaximumYoffset))
|
|
|
|
Toffset = SysVar(SV_MaximumYoffset);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
} else if (g_DownScroll < 0) {
|
|
|
|
g_DownScroll += g_scrollPixelsY;
|
|
|
|
if (g_DownScroll > 0) {
|
|
|
|
Toffset += g_DownScroll;
|
|
|
|
g_DownScroll = 0;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
2012-02-22 22:14:29 +00:00
|
|
|
Toffset -= g_scrollPixelsY; // Move up
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
if (Toffset < 0)
|
|
|
|
Toffset = 0; // Now at extreme top
|
2008-12-01 20:35:36 +00:00
|
|
|
|
|
|
|
/*** New feature to prop up rickety scroll boundaries ***/
|
|
|
|
if (TinselV2 && SysVar(SV_MinimumYoffset) && Toffset < SysVar(SV_MinimumYoffset))
|
|
|
|
Toffset = SysVar(SV_MinimumYoffset);
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Move cursor if keeping cursor on a tag.
|
|
|
|
*/
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_ScrollCursor)
|
2008-07-23 09:02:47 +00:00
|
|
|
AdjustCursorXY(OldLoffset - Loffset, OldToffset - Toffset);
|
|
|
|
|
|
|
|
PlayfieldSetPos(FIELD_WORLD, Loffset, Toffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See if the actor on whom the camera is is approaching an edge.
|
|
|
|
* Request a scroll if he is.
|
|
|
|
*/
|
2009-11-02 21:54:57 +00:00
|
|
|
static void MonitorScroll() {
|
2008-07-23 09:02:47 +00:00
|
|
|
int newx, newy;
|
|
|
|
int Loffset, Toffset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only do it if the actor is there and is visible
|
|
|
|
*/
|
2012-02-22 22:14:29 +00:00
|
|
|
if (!g_pScrollMover || MoverHidden(g_pScrollMover) || !MoverIs(g_pScrollMover))
|
2008-07-23 09:02:47 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
GetActorPos(g_scrollActor, &newx, &newy);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_oldx == newx && g_oldy == newy)
|
2008-07-23 09:02:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Approaching right side or left side of the screen?
|
|
|
|
*/
|
2012-02-22 22:14:29 +00:00
|
|
|
if (newx > Loffset+SCREEN_WIDTH - RLDISTANCE && Loffset < g_ImageW - SCREEN_WIDTH) {
|
|
|
|
if (newx > g_oldx)
|
2008-07-23 09:02:47 +00:00
|
|
|
NeedScroll(LEFT);
|
|
|
|
} else if (newx < Loffset + RLDISTANCE && Loffset) {
|
2012-02-22 22:14:29 +00:00
|
|
|
if (newx < g_oldx)
|
2008-07-23 09:02:47 +00:00
|
|
|
NeedScroll(RIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Approaching bottom or top of the screen?
|
|
|
|
*/
|
2012-02-22 22:14:29 +00:00
|
|
|
if (newy > Toffset+SCREEN_HEIGHT-DDISTANCE && Toffset < g_ImageH-SCREEN_HEIGHT) {
|
|
|
|
if (newy > g_oldy)
|
2008-07-23 09:02:47 +00:00
|
|
|
NeedScroll(UP);
|
2012-02-22 22:14:29 +00:00
|
|
|
} else if (Toffset && newy < Toffset + UDISTANCE + GetActorBottom(g_scrollActor) - GetActorTop(g_scrollActor)) {
|
|
|
|
if (newy < g_oldy)
|
2008-07-23 09:02:47 +00:00
|
|
|
NeedScroll(DOWN);
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_oldx = newx;
|
|
|
|
g_oldy = newy;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
static void RestoreScrollDefaults() {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.xTrigger = SysVar(SV_SCROLL_XTRIGGER);
|
|
|
|
g_sd.xDistance = SysVar(SV_SCROLL_XDISTANCE);
|
|
|
|
g_sd.xSpeed = SysVar(SV_SCROLL_XSPEED);
|
|
|
|
g_sd.yTriggerTop = SysVar(SV_SCROLL_YTRIGGERTOP);
|
|
|
|
g_sd.yTriggerBottom= SysVar(SV_SCROLL_YTRIGGERBOT);
|
|
|
|
g_sd.yDistance = SysVar(SV_SCROLL_YDISTANCE);
|
|
|
|
g_sd.ySpeed = SysVar(SV_SCROLL_YSPEED);
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the obvious - called at the end of a scene.
|
|
|
|
*/
|
2009-11-02 21:54:57 +00:00
|
|
|
void DropScroll() {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.NumNoH = g_sd.NumNoV = 0;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (TinselV2) {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_LeftScroll = g_DownScroll = 0; // No iterations outstanding
|
|
|
|
g_oldx = g_oldy = 0;
|
|
|
|
g_scrollPixelsX = g_sd.xSpeed;
|
|
|
|
g_scrollPixelsY = g_sd.ySpeed;
|
2008-12-01 20:35:36 +00:00
|
|
|
RestoreScrollDefaults();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-23 09:02:47 +00:00
|
|
|
/**
|
|
|
|
* Decide when to scroll and scroll when decided to.
|
|
|
|
*/
|
2008-07-24 08:59:17 +00:00
|
|
|
void ScrollProcess(CORO_PARAM, const void *) {
|
2008-07-23 09:02:47 +00:00
|
|
|
// COROUTINE
|
|
|
|
CORO_BEGIN_CONTEXT;
|
|
|
|
CORO_END_CONTEXT(_ctx);
|
|
|
|
|
|
|
|
CORO_BEGIN_CODE(_ctx);
|
|
|
|
|
2009-01-01 15:06:43 +00:00
|
|
|
// In Tinsel v2, scenes may play movies, so the background may not always
|
2011-05-25 15:17:11 +00:00
|
|
|
// already be initialized like it is in v1
|
2009-01-01 15:06:43 +00:00
|
|
|
while (!GetBgObject())
|
2008-12-01 20:35:36 +00:00
|
|
|
CORO_SLEEP(1);
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_ImageH = BgHeight(); // Dimensions
|
|
|
|
g_ImageW = BgWidth(); // of this scene.
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
// Give up if there'll be no purpose in this process
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_ImageW == SCREEN_WIDTH && g_ImageH == SCREEN_HEIGHT)
|
2008-07-23 09:02:47 +00:00
|
|
|
CORO_KILL_SELF();
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
if (!TinselV2) {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_LeftScroll = g_DownScroll = 0; // No iterations outstanding
|
|
|
|
g_oldx = g_oldy = 0;
|
|
|
|
g_scrollPixelsX = g_scrollPixelsY = SCROLLPIXELS;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (!g_scrollActor)
|
|
|
|
g_scrollActor = GetLeadId();
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_pScrollMover = GetMover(g_scrollActor);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
MonitorScroll(); // Set scroll requirement
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_LeftScroll || g_DownScroll) // Scroll if required
|
2008-07-23 09:02:47 +00:00
|
|
|
ScrollImage();
|
|
|
|
|
|
|
|
CORO_SLEEP(1); // allow re-scheduling
|
|
|
|
}
|
|
|
|
|
|
|
|
CORO_END_CODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change which actor the camera is following.
|
|
|
|
*/
|
|
|
|
void ScrollFocus(int ano) {
|
2012-02-22 22:14:29 +00:00
|
|
|
if (g_scrollActor != ano) {
|
|
|
|
g_oldx = g_oldy = 0;
|
|
|
|
g_scrollActor = ano;
|
2008-07-23 09:02:47 +00:00
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_pScrollMover = ano ? GetMover(g_scrollActor) : NULL;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the actor which the camera is following
|
|
|
|
*/
|
2009-11-02 21:54:57 +00:00
|
|
|
int GetScrollFocus() {
|
2012-02-22 22:14:29 +00:00
|
|
|
return g_scrollActor;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-23 09:02:47 +00:00
|
|
|
/**
|
|
|
|
* Scroll to abslote position.
|
|
|
|
*/
|
2008-12-01 20:35:36 +00:00
|
|
|
void ScrollTo(int x, int y, int xIter, int yIter) {
|
2008-07-23 09:02:47 +00:00
|
|
|
int Loffset, Toffset; // for background offsets
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_scrollPixelsX = xIter != 0 ? xIter : (TinselV2 ? g_sd.xSpeed : SCROLLPIXELS);
|
|
|
|
g_scrollPixelsY = yIter != 0 ? yIter : (TinselV2 ? g_sd.ySpeed : SCROLLPIXELS);
|
2008-07-23 09:02:47 +00:00
|
|
|
|
|
|
|
PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset); // get background offsets
|
|
|
|
|
2012-02-22 22:14:29 +00:00
|
|
|
g_LeftScroll = x - Loffset;
|
|
|
|
g_DownScroll = y - Toffset;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kill of any current scroll.
|
|
|
|
*/
|
2009-11-02 21:54:57 +00:00
|
|
|
void KillScroll() {
|
2012-02-22 22:14:29 +00:00
|
|
|
g_LeftScroll = g_DownScroll = 0;
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GetNoScrollData(SCROLLDATA *ssd) {
|
2012-02-22 22:14:29 +00:00
|
|
|
memcpy(ssd, &g_sd, sizeof(SCROLLDATA));
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RestoreNoScrollData(SCROLLDATA *ssd) {
|
2012-02-22 22:14:29 +00:00
|
|
|
memcpy(&g_sd, ssd, sizeof(SCROLLDATA));
|
2008-07-23 09:02:47 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 20:35:36 +00:00
|
|
|
/**
|
|
|
|
* SetScrollParameters
|
|
|
|
*/
|
|
|
|
void SetScrollParameters(int xTrigger, int xDistance, int xSpeed, int yTriggerTop,
|
|
|
|
int yTriggerBottom, int yDistance, int ySpeed) {
|
|
|
|
if (xTrigger == 0 && xDistance == 0 && xSpeed == 0
|
|
|
|
&& yTriggerTop == 0 && yTriggerBottom && yDistance == 0 && ySpeed == 0) {
|
|
|
|
// Restore defaults
|
|
|
|
RestoreScrollDefaults();
|
|
|
|
} else {
|
|
|
|
if (xTrigger)
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.xTrigger = xTrigger;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (xDistance)
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.xDistance = xDistance;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (xSpeed)
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.xSpeed = xSpeed;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (yTriggerTop)
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.yTriggerTop = yTriggerTop;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (yTriggerBottom)
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.yTriggerBottom = yTriggerBottom;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (yDistance)
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.yDistance = yDistance;
|
2008-12-01 20:35:36 +00:00
|
|
|
if (ySpeed)
|
2012-02-22 22:14:29 +00:00
|
|
|
g_sd.ySpeed = ySpeed;
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
bool IsScrolling() {
|
2012-02-22 22:14:29 +00:00
|
|
|
return (g_LeftScroll || g_DownScroll);
|
2008-12-01 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Tinsel
|