2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2006-05-23 23:43:52 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2006-05-23 23:43:52 +00:00
|
|
|
*
|
|
|
|
* 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$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "agi/agi.h"
|
|
|
|
#include "agi/sprite.h"
|
|
|
|
#include "agi/graphics.h"
|
|
|
|
|
|
|
|
namespace Agi {
|
|
|
|
|
2006-05-30 19:48:47 +00:00
|
|
|
/**
|
|
|
|
* Sprite structure.
|
|
|
|
* This structure holds information on visible and priority data of
|
|
|
|
* a rectangular area of the AGI screen. Sprites are chained in two
|
|
|
|
* circular lists, one for updating and other for non-updating sprites.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
struct Sprite {
|
|
|
|
VtEntry *v; /**< pointer to view table entry */
|
|
|
|
int16 xPos; /**< x coordinate of the sprite */
|
|
|
|
int16 yPos; /**< y coordinate of the sprite */
|
|
|
|
int16 xSize; /**< width of the sprite */
|
|
|
|
int16 ySize; /**< height of the sprite */
|
2006-05-30 19:48:47 +00:00
|
|
|
uint8 *buffer; /**< buffer to store background data */
|
|
|
|
};
|
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
/*
|
|
|
|
* Sprite pool replaces dynamic allocation
|
|
|
|
*/
|
|
|
|
#undef ALLOC_DEBUG
|
|
|
|
|
2006-05-30 19:48:47 +00:00
|
|
|
|
2006-05-23 23:43:52 +00:00
|
|
|
#define POOL_SIZE 68000 /* Gold Rush mine room needs > 50000 */
|
2006-05-30 19:48:47 +00:00
|
|
|
/* Speeder bike challenge needs > 67000 */
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void *SpritesMgr::poolAlloc(int size) {
|
2006-05-23 23:43:52 +00:00
|
|
|
uint8 *x;
|
|
|
|
|
|
|
|
/* Adjust size to 32-bit boundary to prevent data misalignment
|
|
|
|
* errors.
|
|
|
|
*/
|
|
|
|
size = (size + 3) & ~3;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
x = _poolTop;
|
|
|
|
_poolTop += size;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_poolTop >= (uint8 *)_spritePool + POOL_SIZE) {
|
2006-05-23 23:43:52 +00:00
|
|
|
debugC(1, kDebugLevelMain | kDebugLevelResources, "not enough memory");
|
2007-01-16 12:40:51 +00:00
|
|
|
_poolTop = x;
|
2006-05-23 23:43:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2006-05-26 11:28:03 +00:00
|
|
|
/* Note: it's critical that pool_release() is called in the exact
|
|
|
|
reverse order of pool_alloc()
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::poolRelease(void *s) {
|
|
|
|
_poolTop = (uint8 *)s;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Blitter functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Blit one pixel considering the priorities */
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::blitPixel(uint8 *p, uint8 *end, uint8 col, int spr, int width, int *hidden) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int epr = 0, pr = 0; /* effective and real priorities */
|
|
|
|
|
|
|
|
/* CM: priority 15 overrides control lines and is ignored when
|
|
|
|
* tracking effective priority. This tweak is needed to fix
|
2007-05-07 05:06:22 +00:00
|
|
|
* Sarien bug #451768, and should not affect Sierra games because
|
2006-05-23 23:43:52 +00:00
|
|
|
* sprites shouldn't have priority 15 (like the AGI Mouse
|
|
|
|
* demo "mouse pointer")
|
|
|
|
*
|
|
|
|
* Update: this solution breaks other games, and can't be used.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (p >= end)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check if we're on a control line */
|
|
|
|
if ((pr = *p & 0xf0) < 0x30) {
|
|
|
|
uint8 *p1;
|
|
|
|
/* Yes, get effective priority going down */
|
|
|
|
for (p1 = p; p1 < end && (epr = *p1 & 0xf0) < 0x30;
|
|
|
|
p1 += width);
|
|
|
|
if (p1 >= end)
|
|
|
|
epr = 0x40;
|
|
|
|
} else {
|
|
|
|
epr = pr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spr >= epr) {
|
|
|
|
/* Keep control line information visible, but put our
|
|
|
|
* priority over water (0x30) surface
|
|
|
|
*/
|
|
|
|
*p = (pr < 0x30 ? pr : spr) | col;
|
|
|
|
*hidden = false;
|
|
|
|
|
|
|
|
/* Except if our priority is 15, which should never happen
|
2007-05-07 05:06:22 +00:00
|
|
|
* (fixes Sarien bug #451768)
|
2006-05-23 23:43:52 +00:00
|
|
|
*
|
|
|
|
* Update: breaks other games, can't be used
|
|
|
|
*
|
|
|
|
* if (spr == 0xf0)
|
|
|
|
* *p = spr | col;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
int SpritesMgr::blitCel(int x, int y, int spr, ViewCel *c) {
|
2006-05-23 23:43:52 +00:00
|
|
|
uint8 *p0, *p, *q = NULL, *end;
|
|
|
|
int i, j, t, m, col;
|
|
|
|
int hidden = true;
|
|
|
|
|
2007-05-07 05:06:22 +00:00
|
|
|
/* Fixes Sarien bug #477841 (crash in PQ1 map C4 when y == -2) */
|
2006-05-23 23:43:52 +00:00
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
if (y >= _HEIGHT)
|
|
|
|
y = _HEIGHT - 1;
|
|
|
|
if (x >= _WIDTH)
|
|
|
|
x = _WIDTH - 1;
|
|
|
|
|
|
|
|
q = c->data;
|
|
|
|
t = c->transparency;
|
|
|
|
m = c->mirror;
|
|
|
|
spr <<= 4;
|
2007-01-16 12:40:51 +00:00
|
|
|
p0 = &_vm->_game.sbuf[x + y * _WIDTH + m * (c->width - 1)];
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
end = _vm->_game.sbuf + _WIDTH * _HEIGHT;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
for (i = 0; i < c->height; i++) {
|
|
|
|
p = p0;
|
|
|
|
while (*q) {
|
|
|
|
col = (*q & 0xf0) >> 4;
|
|
|
|
for (j = *q & 0x0f; j; j--, p += 1 - 2 * m) {
|
|
|
|
if (col != t) {
|
2007-01-16 12:40:51 +00:00
|
|
|
blitPixel(p, end, col, spr, _WIDTH, &hidden);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
p0 += _WIDTH;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hidden;
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::objsSaveArea(Sprite *s) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int y;
|
2007-01-16 12:40:51 +00:00
|
|
|
int16 xPos = s->xPos, yPos = s->yPos;
|
|
|
|
int16 xSize = s->xSize, ySize = s->ySize;
|
2006-05-23 23:43:52 +00:00
|
|
|
uint8 *p0, *q;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (xPos + xSize > _WIDTH)
|
|
|
|
xSize = _WIDTH - xPos;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (xPos < 0) {
|
|
|
|
xSize += xPos;
|
|
|
|
xPos = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (yPos + ySize > _HEIGHT)
|
|
|
|
ySize = _HEIGHT - yPos;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (yPos < 0) {
|
|
|
|
ySize += yPos;
|
|
|
|
yPos = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (xSize <= 0 || ySize <= 0)
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
p0 = &_vm->_game.sbuf[xPos + yPos * _WIDTH];
|
2006-05-23 23:43:52 +00:00
|
|
|
q = s->buffer;
|
2007-01-16 12:40:51 +00:00
|
|
|
for (y = 0; y < ySize; y++) {
|
|
|
|
memcpy(q, p0, xSize);
|
|
|
|
q += xSize;
|
2006-05-23 23:43:52 +00:00
|
|
|
p0 += _WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::objsRestoreArea(Sprite *s) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int y, offset;
|
2007-01-16 12:40:51 +00:00
|
|
|
int16 xPos = s->xPos, yPos = s->yPos;
|
|
|
|
int16 xSize = s->xSize, ySize = s->ySize;
|
2006-05-23 23:43:52 +00:00
|
|
|
uint8 *p0, *q;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (xPos + xSize > _WIDTH)
|
|
|
|
xSize = _WIDTH - xPos;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (xPos < 0) {
|
|
|
|
xSize += xPos;
|
|
|
|
xPos = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (yPos + ySize > _HEIGHT)
|
|
|
|
ySize = _HEIGHT - yPos;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (yPos < 0) {
|
|
|
|
ySize += yPos;
|
|
|
|
yPos = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (xSize <= 0 || ySize <= 0)
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
p0 = &_vm->_game.sbuf[xPos + yPos * _WIDTH];
|
2006-05-23 23:43:52 +00:00
|
|
|
q = s->buffer;
|
2007-01-16 12:40:51 +00:00
|
|
|
offset = _vm->_game.lineMinPrint * CHAR_LINES;
|
|
|
|
for (y = 0; y < ySize; y++) {
|
|
|
|
memcpy(p0, q, xSize);
|
|
|
|
_gfx->putPixelsA(xPos, yPos + y + offset, xSize, p0);
|
|
|
|
q += xSize;
|
2006-05-23 23:43:52 +00:00
|
|
|
p0 += _WIDTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Condition to determine whether a sprite will be in the 'updating' list.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
bool SpritesMgr::testUpdating(VtEntry *v, AgiEngine *agi) {
|
2007-05-07 05:06:22 +00:00
|
|
|
/* Sanity check (see Sarien bug #779302) */
|
2007-01-16 12:40:51 +00:00
|
|
|
if (~agi->_game.dirView[v->currentView].flags & RES_LOADED)
|
2006-05-30 19:48:47 +00:00
|
|
|
return false;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
return (v->flags & (ANIMATED | UPDATE | DRAWN)) == (ANIMATED | UPDATE | DRAWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Condition to determine whether a sprite will be in the 'non-updating' list.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
bool SpritesMgr::testNotUpdating(VtEntry *v, AgiEngine *vm) {
|
2007-05-07 05:06:22 +00:00
|
|
|
/* Sanity check (see Sarien bug #779302) */
|
2007-01-16 12:40:51 +00:00
|
|
|
if (~vm->_game.dirView[v->currentView].flags & RES_LOADED)
|
2006-05-30 19:48:47 +00:00
|
|
|
return false;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
return (v->flags & (ANIMATED | UPDATE | DRAWN)) == (ANIMATED | DRAWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert sprite priority to y value.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
INLINE int SpritesMgr::prioToY(int p) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (p == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 167; i >= 0; i--) {
|
2007-01-16 12:40:51 +00:00
|
|
|
if (_vm->_game.priTable[i] < p)
|
2006-05-23 23:43:52 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1; /* (p - 5) * 12 + 48; */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and initialize a new sprite structure.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
Sprite *SpritesMgr::newSprite(VtEntry *v) {
|
|
|
|
Sprite *s;
|
|
|
|
s = (Sprite *)poolAlloc(sizeof(Sprite));
|
2006-05-23 23:43:52 +00:00
|
|
|
if (s == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
s->v = v; /* link sprite to associated view table entry */
|
2007-01-16 12:40:51 +00:00
|
|
|
s->xPos = v->xPos;
|
|
|
|
s->yPos = v->yPos - v->ySize + 1;
|
|
|
|
s->xSize = v->xSize;
|
|
|
|
s->ySize = v->ySize;
|
|
|
|
s->buffer = (uint8 *)poolAlloc(s->xSize * s->ySize);
|
2006-05-23 23:43:52 +00:00
|
|
|
v->s = s; /* link view table entry to this sprite */
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert sprite in the specified sprite list.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::sprAddlist(SpriteList &l, VtEntry *v) {
|
|
|
|
Sprite *s = newSprite(v);
|
2006-05-26 11:28:03 +00:00
|
|
|
l.push_back(s);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort sprites from lower y values to build a sprite list.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::buildList(SpriteList &l, bool (*test)(VtEntry *, AgiEngine *)) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int i, j, k;
|
2007-01-16 12:40:51 +00:00
|
|
|
VtEntry *v;
|
|
|
|
VtEntry *entry[0x100];
|
|
|
|
int yVal[0x100];
|
|
|
|
int minY = 0xff, minIndex = 0;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/* fill the arrays with all sprites that satisfy the 'test'
|
|
|
|
* condition and their y values
|
|
|
|
*/
|
|
|
|
i = 0;
|
2007-01-16 12:40:51 +00:00
|
|
|
for (v = _vm->_game.viewTable; v < &_vm->_game.viewTable[MAX_VIEWTABLE]; v++) {
|
2006-12-06 19:27:02 +00:00
|
|
|
if ((*test)(v, _vm)) {
|
2006-05-23 23:43:52 +00:00
|
|
|
entry[i] = v;
|
2007-01-16 12:40:51 +00:00
|
|
|
yVal[i] = v->flags & FIXED_PRIORITY ? prioToY(v->priority) : v->yPos;
|
2006-05-23 23:43:52 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now look for the smallest y value in the array and put that
|
|
|
|
* sprite in the list
|
|
|
|
*/
|
|
|
|
for (j = 0; j < i; j++) {
|
2007-01-16 12:40:51 +00:00
|
|
|
minY = 0xff;
|
2006-05-23 23:43:52 +00:00
|
|
|
for (k = 0; k < i; k++) {
|
2007-01-16 12:40:51 +00:00
|
|
|
if (yVal[k] < minY) {
|
|
|
|
minIndex = k;
|
|
|
|
minY = yVal[k];
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
yVal[minIndex] = 0xff;
|
|
|
|
sprAddlist(l, entry[minIndex]);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build list of updating sprites.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::buildUpdBlitlist() {
|
|
|
|
buildList(_sprUpd, testUpdating);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build list of non-updating sprites.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::buildNonupdBlitlist() {
|
|
|
|
buildList(_sprNonupd, testNotUpdating);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the given sprite list.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::freeList(SpriteList &l) {
|
2006-05-26 17:38:12 +00:00
|
|
|
SpriteList::iterator iter;
|
|
|
|
for (iter = l.reverse_begin(); iter != l.end(); ) {
|
2007-01-16 12:40:51 +00:00
|
|
|
Sprite* s = *iter;
|
|
|
|
poolRelease(s->buffer);
|
|
|
|
poolRelease(s);
|
2006-05-26 17:38:12 +00:00
|
|
|
iter = l.reverse_erase(iter);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy sprites from the pic buffer to the screen buffer, and check if
|
|
|
|
* sprites of the given list have moved.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::commitSprites(SpriteList &l) {
|
2006-05-26 17:38:12 +00:00
|
|
|
SpriteList::iterator iter;
|
|
|
|
for (iter = l.begin(); iter != l.end(); ++iter) {
|
2007-01-16 12:40:51 +00:00
|
|
|
Sprite *s = *iter;
|
2006-05-23 23:43:52 +00:00
|
|
|
int x1, y1, x2, y2, w, h;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
w = (s->v->celData->width > s->v->celData2->width) ?
|
|
|
|
s->v->celData->width : s->v->celData2->width;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
h = (s->v->celData->height >
|
|
|
|
s->v->celData2->height) ? s->v->celData->
|
|
|
|
height : s->v->celData2->height;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
s->v->celData2 = s->v->celData;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (s->v->xPos < s->v->xPos2) {
|
|
|
|
x1 = s->v->xPos;
|
|
|
|
x2 = s->v->xPos2 + w - 1;
|
2006-05-23 23:43:52 +00:00
|
|
|
} else {
|
2007-01-16 12:40:51 +00:00
|
|
|
x1 = s->v->xPos2;
|
|
|
|
x2 = s->v->xPos + w - 1;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (s->v->yPos < s->v->yPos2) {
|
|
|
|
y1 = s->v->yPos - h + 1;
|
|
|
|
y2 = s->v->yPos2;
|
2006-05-23 23:43:52 +00:00
|
|
|
} else {
|
2007-01-16 12:40:51 +00:00
|
|
|
y1 = s->v->yPos2 - h + 1;
|
|
|
|
y2 = s->v->yPos;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
commitBlock(x1, y1, x2, y2);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (s->v->stepTimeCount != s->v->stepTime)
|
2006-05-23 23:43:52 +00:00
|
|
|
continue;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (s->v->xPos == s->v->xPos2 && s->v->yPos == s->v->yPos2) {
|
2006-05-23 23:43:52 +00:00
|
|
|
s->v->flags |= DIDNT_MOVE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
s->v->xPos2 = s->v->xPos;
|
|
|
|
s->v->yPos2 = s->v->yPos;
|
2006-05-23 23:43:52 +00:00
|
|
|
s->v->flags &= ~DIDNT_MOVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Erase all sprites in the given list.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::eraseSprites(SpriteList &l) {
|
2006-05-26 17:38:12 +00:00
|
|
|
SpriteList::iterator iter;
|
|
|
|
for (iter = l.reverse_begin(); iter != l.end(); --iter) {
|
2007-01-16 12:40:51 +00:00
|
|
|
Sprite *s = *iter;
|
|
|
|
objsRestoreArea(s);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
freeList(l);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blit all sprites in the given list.
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::blitSprites(SpriteList& l) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int hidden;
|
2006-05-26 17:38:12 +00:00
|
|
|
SpriteList::iterator iter;
|
|
|
|
for (iter = l.begin(); iter != l.end(); ++iter) {
|
2007-01-16 12:40:51 +00:00
|
|
|
Sprite *s = *iter;
|
|
|
|
objsSaveArea(s);
|
2006-05-23 23:43:52 +00:00
|
|
|
debugC(8, kDebugLevelSprites, "s->v->entry = %d (prio %d)", s->v->entry, s->v->priority);
|
2007-01-16 12:40:51 +00:00
|
|
|
hidden = blitCel(s->xPos, s->yPos, s->v->priority, s->v->celData);
|
2006-05-23 23:43:52 +00:00
|
|
|
if (s->v->entry == 0) { /* if ego, update f1 */
|
2007-01-16 12:40:51 +00:00
|
|
|
_vm->setflag(fEgoInvisible, hidden);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public functions
|
|
|
|
*/
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::commitUpdSprites() {
|
|
|
|
commitSprites(_sprUpd);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::commitNonupdSprites() {
|
|
|
|
commitSprites(_sprNonupd);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check moves in both lists */
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::commitBoth() {
|
|
|
|
commitUpdSprites();
|
|
|
|
commitNonupdSprites();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Erase updating sprites.
|
|
|
|
* This function follows the list of all updating sprites and restores
|
|
|
|
* the visible and priority data of their background buffers back to
|
|
|
|
* the AGI screen.
|
|
|
|
*
|
|
|
|
* @see erase_nonupd_sprites()
|
|
|
|
* @see erase_both()
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::eraseUpdSprites() {
|
|
|
|
eraseSprites(_sprUpd);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Erase non-updating sprites.
|
|
|
|
* This function follows the list of all non-updating sprites and restores
|
|
|
|
* the visible and priority data of their background buffers back to
|
|
|
|
* the AGI screen.
|
|
|
|
*
|
|
|
|
* @see erase_upd_sprites()
|
|
|
|
* @see erase_both()
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::eraseNonupdSprites() {
|
|
|
|
eraseSprites(_sprNonupd);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Erase all sprites.
|
|
|
|
* This function follows the lists of all updating and non-updating
|
|
|
|
* sprites and restores the visible and priority data of their background
|
|
|
|
* buffers back to the AGI screen.
|
|
|
|
*
|
|
|
|
* @see erase_upd_sprites()
|
|
|
|
* @see erase_nonupd_sprites()
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::eraseBoth() {
|
|
|
|
eraseUpdSprites();
|
|
|
|
eraseNonupdSprites();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blit updating sprites.
|
|
|
|
* This function follows the list of all updating sprites and blits
|
|
|
|
* them on the AGI screen.
|
|
|
|
*
|
|
|
|
* @see blit_nonupd_sprites()
|
|
|
|
* @see blit_both()
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::blitUpdSprites() {
|
2006-05-23 23:43:52 +00:00
|
|
|
debugC(7, kDebugLevelSprites, "blit updating");
|
2007-01-16 12:40:51 +00:00
|
|
|
buildUpdBlitlist();
|
|
|
|
blitSprites(_sprUpd);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blit non-updating sprites.
|
|
|
|
* This function follows the list of all non-updating sprites and blits
|
|
|
|
* them on the AGI screen.
|
|
|
|
*
|
|
|
|
* @see blit_upd_sprites()
|
|
|
|
* @see blit_both()
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::blitNonupdSprites() {
|
2006-05-23 23:43:52 +00:00
|
|
|
debugC(7, kDebugLevelSprites, "blit non-updating");
|
2007-01-16 12:40:51 +00:00
|
|
|
buildNonupdBlitlist();
|
|
|
|
blitSprites(_sprNonupd);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blit all sprites.
|
|
|
|
* This function follows the lists of all updating and non-updating
|
|
|
|
* sprites and blits them on the AGI screen.
|
|
|
|
*
|
|
|
|
* @see blit_upd_sprites()
|
|
|
|
* @see blit_nonupd_sprites()
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::blitBoth() {
|
|
|
|
blitNonupdSprites();
|
|
|
|
blitUpdSprites();
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add view to picture.
|
|
|
|
* This function is used to implement the add.to.pic AGI command. It
|
|
|
|
* copies the specified cel from a view resource on the current picture.
|
|
|
|
* This cel is not a sprite, it can't be moved or removed.
|
|
|
|
* @param view number of view resource
|
|
|
|
* @param loop number of loop in the specified view resource
|
|
|
|
* @param cel number of cel in the specified loop
|
|
|
|
* @param x x coordinate to place the view
|
|
|
|
* @param y y coordinate to place the view
|
|
|
|
* @param pri priority to use
|
|
|
|
* @param mar if < 4, create a margin around the the base of the cel
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::addToPic(int view, int loop, int cel, int x, int y, int pri, int mar) {
|
|
|
|
ViewCel *c = NULL;
|
2006-05-23 23:43:52 +00:00
|
|
|
int x1, y1, x2, y2, y3;
|
|
|
|
uint8 *p1, *p2;
|
|
|
|
|
|
|
|
debugC(3, kDebugLevelSprites, "v=%d, l=%d, c=%d, x=%d, y=%d, p=%d, m=%d", view, loop, cel, x, y, pri, mar);
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_vm->recordImageStackCall(ADD_VIEW, view, loop, cel, x, y, pri, mar);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Was hardcoded to 8, changed to pri_table[y] to fix Gold
|
2007-05-07 05:06:22 +00:00
|
|
|
* Rush (see Sarien bug #587558)
|
2006-05-23 23:43:52 +00:00
|
|
|
*/
|
|
|
|
if (pri == 0)
|
2007-01-16 12:40:51 +00:00
|
|
|
pri = _vm->_game.priTable[y];
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
c = &_vm->_game.views[view].loop[loop].cel[cel];
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
x1 = x;
|
|
|
|
y1 = y - c->height + 1;
|
|
|
|
x2 = x + c->width - 1;
|
|
|
|
y2 = y;
|
|
|
|
|
|
|
|
if (x1 < 0) {
|
|
|
|
x2 -= x1;
|
|
|
|
x1 = 0;
|
|
|
|
}
|
|
|
|
if (y1 < 0) {
|
|
|
|
y2 -= y1;
|
|
|
|
y1 = 0;
|
|
|
|
}
|
|
|
|
if (x2 >= _WIDTH)
|
|
|
|
x2 = _WIDTH - 1;
|
|
|
|
if (y2 >= _HEIGHT)
|
|
|
|
y2 = _HEIGHT - 1;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
eraseBoth();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
debugC(4, kDebugLevelSprites, "blit_cel (%d, %d, %d, c)", x, y, pri);
|
2007-01-16 12:40:51 +00:00
|
|
|
blitCel(x1, y1, pri, c);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
/* If margin is 0, 1, 2, or 3, the base of the cel is
|
|
|
|
* surrounded with a rectangle of the corresponding priority.
|
|
|
|
* If margin >= 4, this extra margin is not shown.
|
|
|
|
*/
|
|
|
|
if (mar < 4) {
|
|
|
|
/* add rectangle around object, don't clobber control
|
|
|
|
* info in priority data. The box extends to the end of
|
|
|
|
* its priority band!
|
|
|
|
*/
|
2007-04-24 15:43:16 +00:00
|
|
|
y3 = (y2 / 12) * 12;
|
|
|
|
|
2007-05-07 05:06:22 +00:00
|
|
|
// SQ1 needs +1 (see Sarien bug #810331)
|
2007-05-06 14:36:02 +00:00
|
|
|
if (_vm->getGameID() == GID_SQ1)
|
2007-04-24 15:43:16 +00:00
|
|
|
y3++;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2006-05-31 19:55:54 +00:00
|
|
|
// don't let box extend below y.
|
|
|
|
if (y3 > y2) y3 = y2;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
p1 = &_vm->_game.sbuf[x1 + y3 * _WIDTH];
|
|
|
|
p2 = &_vm->_game.sbuf[x2 + y3 * _WIDTH];
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
for (y = y3; y <= y2; y++) {
|
|
|
|
if ((*p1 >> 4) >= 4)
|
|
|
|
*p1 = (mar << 4) | (*p1 & 0x0f);
|
|
|
|
if ((*p2 >> 4) >= 4)
|
|
|
|
*p2 = (mar << 4) | (*p2 & 0x0f);
|
|
|
|
p1 += _WIDTH;
|
|
|
|
p2 += _WIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
debugC(4, kDebugLevelSprites, "pri box: %d %d %d %d (%d)", x1, y3, x2, y2, mar);
|
2007-01-16 12:40:51 +00:00
|
|
|
p1 = &_vm->_game.sbuf[x1 + y3 * _WIDTH];
|
|
|
|
p2 = &_vm->_game.sbuf[x1 + y2 * _WIDTH];
|
2006-05-23 23:43:52 +00:00
|
|
|
for (x = x1; x <= x2; x++) {
|
|
|
|
if ((*p1 >> 4) >= 4)
|
|
|
|
*p1 = (mar << 4) | (*p1 & 0x0f);
|
|
|
|
if ((*p2 >> 4) >= 4)
|
|
|
|
*p2 = (mar << 4) | (*p2 & 0x0f);
|
|
|
|
p1++;
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
blitBoth();
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
debugC(4, kDebugLevelSprites, "commit_block (%d, %d, %d, %d)", x1, y1, x2, y2);
|
2007-01-16 12:40:51 +00:00
|
|
|
commitBlock(x1, y1, x2, y2);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show object and description
|
|
|
|
* This function shows an object from the player's inventory, displaying
|
|
|
|
* a message box with the object description.
|
|
|
|
* @param n Number of the object to show
|
|
|
|
*/
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::showObj(int n) {
|
|
|
|
ViewCel *c;
|
|
|
|
Sprite s;
|
2006-05-23 23:43:52 +00:00
|
|
|
int x1, y1, x2, y2;
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_vm->agiLoadResource(rVIEW, n);
|
2007-01-16 12:40:51 +00:00
|
|
|
if (!(c = &_vm->_game.views[n].loop[0].cel[0]))
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
x1 = (_WIDTH - c->width) / 2;
|
|
|
|
y1 = 112;
|
|
|
|
x2 = x1 + c->width - 1;
|
|
|
|
y2 = y1 + c->height - 1;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
s.xPos = x1;
|
|
|
|
s.yPos = y1;
|
|
|
|
s.xSize = c->width;
|
|
|
|
s.ySize = c->height;
|
|
|
|
s.buffer = (uint8 *)malloc(s.xSize * s.ySize);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
objsSaveArea(&s);
|
|
|
|
blitCel(x1, y1, s.xSize, c);
|
|
|
|
commitBlock(x1, y1, x2, y2);
|
|
|
|
_vm->messageBox(_vm->_game.views[n].descr);
|
|
|
|
objsRestoreArea(&s);
|
|
|
|
commitBlock(x1, y1, x2, y2);
|
2006-05-23 23:43:52 +00:00
|
|
|
|
|
|
|
free(s.buffer);
|
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
void SpritesMgr::commitBlock(int x1, int y1, int x2, int y2) {
|
2006-05-23 23:43:52 +00:00
|
|
|
int i, w, offset;
|
|
|
|
uint8 *q;
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
if (!_vm->_game.pictureShown)
|
2006-05-23 23:43:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Clipping */
|
|
|
|
if (x1 < 0)
|
|
|
|
x1 = 0;
|
|
|
|
if (x2 < 0)
|
|
|
|
x2 = 0;
|
|
|
|
if (y1 < 0)
|
|
|
|
y1 = 0;
|
|
|
|
if (y2 < 0)
|
|
|
|
y2 = 0;
|
|
|
|
if (x1 >= _WIDTH)
|
|
|
|
x1 = _WIDTH - 1;
|
|
|
|
if (x2 >= _WIDTH)
|
|
|
|
x2 = _WIDTH - 1;
|
|
|
|
if (y1 >= _HEIGHT)
|
|
|
|
y1 = _HEIGHT - 1;
|
|
|
|
if (y2 >= _HEIGHT)
|
|
|
|
y2 = _HEIGHT - 1;
|
|
|
|
|
|
|
|
debugC(7, kDebugLevelSprites, "%d, %d, %d, %d", x1, y1, x2, y2);
|
|
|
|
|
|
|
|
w = x2 - x1 + 1;
|
2007-01-16 12:40:51 +00:00
|
|
|
q = &_vm->_game.sbuf[x1 + _WIDTH * y1];
|
|
|
|
offset = _vm->_game.lineMinPrint * CHAR_LINES;
|
2006-05-23 23:43:52 +00:00
|
|
|
for (i = y1; i <= y2; i++) {
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->putPixelsA(x1, i + offset, w, q);
|
2006-05-23 23:43:52 +00:00
|
|
|
q += _WIDTH;
|
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
_gfx->flushBlockA(x1, y1 + offset, x2, y2 + offset);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
SpritesMgr::SpritesMgr(AgiEngine *agi, GfxMgr *gfx) {
|
|
|
|
_vm = agi;
|
|
|
|
_gfx = gfx;
|
2006-05-23 23:43:52 +00:00
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
_spritePool = (uint8 *)malloc(POOL_SIZE);
|
|
|
|
_poolTop = _spritePool;
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2006-12-06 19:27:02 +00:00
|
|
|
SpritesMgr::~SpritesMgr() {
|
2007-01-16 12:40:51 +00:00
|
|
|
free(_spritePool);
|
2006-05-23 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-16 12:40:51 +00:00
|
|
|
} // End of namespace Agi
|