aboutsummaryrefslogtreecommitdiff
path: root/kyra
diff options
context:
space:
mode:
authorJohannes Schickel2005-10-18 20:38:30 +0000
committerJohannes Schickel2005-10-18 20:38:30 +0000
commit6d5cdb6c546f54eda6120547280d1d8ec65d70d5 (patch)
tree2177752ce4e9736afebcccc9fa5ac03a9cf79d77 /kyra
parent2e60e19a37d5247a8cb6c9f8233b242868e9efb7 (diff)
downloadscummvm-rg350-6d5cdb6c546f54eda6120547280d1d8ec65d70d5.tar.gz
scummvm-rg350-6d5cdb6c546f54eda6120547280d1d8ec65d70d5.tar.bz2
scummvm-rg350-6d5cdb6c546f54eda6120547280d1d8ec65d70d5.zip
Commited patch # 1324980. Thanks to vinterstum.
svn-id: r19163
Diffstat (limited to 'kyra')
-rw-r--r--kyra/screen.cpp57
-rw-r--r--kyra/screen.h7
-rw-r--r--kyra/sprites.cpp133
-rw-r--r--kyra/sprites.h9
4 files changed, 136 insertions, 70 deletions
diff --git a/kyra/screen.cpp b/kyra/screen.cpp
index 7af494c376..0463ff2b2c 100644
--- a/kyra/screen.cpp
+++ b/kyra/screen.cpp
@@ -207,24 +207,65 @@ void Screen::copyToPage0(int y, int h, uint8 page, uint8 *seqBuf) {
memcpy(getPagePtr(0) + y * SCREEN_W, src, h * SCREEN_W);
}
-void Screen::copyRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPage, int dstPage) {
- debug(9, "Screen::copyRegion(%d, %d, %d, %d, %d, %d, %d, %d)", x1, y1, x2, y2, w, h, srcPage, dstPage);
+void Screen::copyRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPage, int dstPage, int flags) {
+ debug(9, "Screen::copyRegion(%d, %d, %d, %d, %d, %d, %d, %d, %d)", x1, y1, x2, y2, w, h, srcPage, dstPage, flags);
+
+ if (flags & CR_CLIPPED) {
+ if (x2 < 0) {
+ if (x2 <= -w)
+ return;
+ w += x2;
+ x1 -= x2;
+ x2 = 0;
+ } else if (x2 + w >= SCREEN_W) {
+ if (x2 > SCREEN_W)
+ return;
+ w = SCREEN_W - x2;
+ }
+
+ if (y2 < 0) {
+ if (y2 <= -h )
+ return;
+ h += y2;
+ y1 -= y2;
+ y2 = 0;
+ } else if (y2 + h >= SCREEN_H) {
+ if (y2 > SCREEN_H)
+ return;
+ h = SCREEN_H - y2;
+ }
+ }
+
assert(x1 + w <= SCREEN_W && y1 + h <= SCREEN_H);
const uint8 *src = getPagePtr(srcPage) + y1 * SCREEN_W + x1;
assert(x2 + w <= SCREEN_W && y2 + h <= SCREEN_H);
uint8 *dst = getPagePtr(dstPage) + y2 * SCREEN_W + x2;
- while (h--) {
- for (int i = 0; i < w; ++i) {
- if (src[i]) {
- dst[i] = src[i];
+
+ if (flags & CR_X_FLIPPED) {
+ while (h--) {
+ for (int i = 0; i < w; ++i) {
+ if (src[i]) {
+ dst[w-i] = src[i];
+ }
}
+ src += SCREEN_W;
+ dst += SCREEN_W;
+ }
+ } else {
+ while (h--) {
+ for (int i = 0; i < w; ++i) {
+ if (src[i]) {
+ dst[i] = src[i];
+ }
+ }
+ src += SCREEN_W;
+ dst += SCREEN_W;
}
- src += SCREEN_W;
- dst += SCREEN_W;
}
}
void Screen::copyRegionToBuffer(int pageNum, int x, int y, int w, int h, uint8 *dest) {
+ debug(9, "Screen::copyRegionToBuffer(%d, %d, %d, %d, %d)", pageNum, x, y, w, h);
assert(x >= 0 && x < Screen::SCREEN_W && y >= 0 && y < Screen::SCREEN_H && dest);
uint8 *pagePtr = getPagePtr(pageNum);
for (int i = y; i < y + h; i++) {
diff --git a/kyra/screen.h b/kyra/screen.h
index f66f06604b..0b6936cfda 100644
--- a/kyra/screen.h
+++ b/kyra/screen.h
@@ -60,6 +60,11 @@ public:
SCREEN_PAGE_NUM = 16
};
+ enum CopyRegionFlags {
+ CR_X_FLIPPED = 0x01,
+ CR_CLIPPED = 0x02
+ };
+
enum DrawShapeFlags {
DSF_X_FLIPPED = 0x01,
DSF_Y_FLIPPED = 0x02,
@@ -89,7 +94,7 @@ public:
void fadePalette(const uint8 *palData, int delay);
void setScreenPalette(const uint8 *palData);
void copyToPage0(int y, int h, uint8 page, uint8 *seqBuf);
- void copyRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPage, int dstPage);
+ void copyRegion(int x1, int y1, int x2, int y2, int w, int h, int srcPage, int dstPage, int flags=0);
void copyBlockToPage(int pageNum, int x, int y, int w, int h, const uint8 *src);
void copyCurPageBlock(int x, int y, int h, int w, uint8 *dst);
void shuffleScreen(int sx, int sy, int w, int h, int srcPage, int dstPage, int ticks, bool transparent);
diff --git a/kyra/sprites.cpp b/kyra/sprites.cpp
index 669e4e7f6a..3486324c50 100644
--- a/kyra/sprites.cpp
+++ b/kyra/sprites.cpp
@@ -50,8 +50,10 @@ Sprite Sprites::getSprite(uint8 spriteID) {
}
void Sprites::drawSprites(uint8 srcPage, uint8 dstPage) {
+ int flags;
+
for (int i = 0; i < MAX_NUM_ANIMS; i++) {
- if (_anims[i].script == 0)
+ if (_anims[i].script == 0 || !_anims[i].play)
break;
if (_anims[i].sprite >= 0) {
assert( _anims[i].sprite < MAX_NUM_SPRITES);
@@ -59,8 +61,11 @@ void Sprites::drawSprites(uint8 srcPage, uint8 dstPage) {
//debug(1, "Drawing from X %i, Y %i, to X %i, Y %i, width %i, height %i, srcPage %i, dstPage %i",
// sprite.x, sprite.y, _anims[i].x, _anims[i].y, sprite.width, sprite.height, srcPage, dstPage);
-
- _screen->copyRegion(sprite.x, sprite.y, _anims[i].x, _anims[i].y, sprite.width, sprite.height, srcPage, dstPage);
+ flags = Screen::CR_CLIPPED;
+ if (_anims[i].flipX)
+ flags |= Screen::CR_X_FLIPPED;
+
+ _screen->copyRegion(sprite.x, sprite.y, _anims[i].x, _anims[i].y, sprite.width, sprite.height, srcPage, dstPage, flags);
}
}
}
@@ -68,10 +73,7 @@ void Sprites::drawSprites(uint8 srcPage, uint8 dstPage) {
void Sprites::doAnims() {
uint32 currTime = _system->getMillis();
for (int i = 0; i < MAX_NUM_ANIMS; i++) {
- if (_anims[i].script == 0)
- break;
-
- if (!_anims[i].play || _anims[i].nextRun != 0 && _anims[i].nextRun > currTime)
+ if (_anims[i].script == 0 || !_anims[i].play || _anims[i].nextRun != 0 && _anims[i].nextRun > currTime)
continue;
uint8 *data;
@@ -88,17 +90,22 @@ void Sprites::doAnims() {
//debug(1, "Default Y of sprite: %i", READ_LE_UINT16(data + 0x16) );
_anims[i].y = READ_LE_UINT16(data + 0x16);
- //debug(1, "Anim %i data: 0h: %i, 2h: %i,4h: %i,6h: %i,8h: %i,ah: %i,ch: %i", i, READ_LE_UINT16(data + 0x0),
- //READ_LE_UINT16(data + 0x2), READ_LE_UINT16(data + 0x4),READ_LE_UINT16(data + 0x6),READ_LE_UINT16(data + 0x8),
- //READ_LE_UINT16(data + 0xa),READ_LE_UINT16(data + 0xc));
+ //debug(1, "Anim %i flags: 22h: %i, 1ah: %i", i, READ_LE_UINT16(data + 0x22), READ_LE_UINT16(data + 0x1a));
+
+ /*
+ debug(1, "Anim %i data: 0h: %i, 2h: %i,4h: %i,6h: %i,8h: %i,ah: %i,ch: %i", i, READ_LE_UINT16(data + 0x0),
+ READ_LE_UINT16(data + 0x2), READ_LE_UINT16(data + 0x4),READ_LE_UINT16(data + 0x6),READ_LE_UINT16(data + 0x8),
+ READ_LE_UINT16(data + 0xa),READ_LE_UINT16(data + 0xc));
- //debug(1, "Anim %i data: eh: %i, 10h: %i,12h: %i,14h: %i,16h: %i,18h: %i,1ah: %i", i, READ_LE_UINT16(data + 0xe),
- //READ_LE_UINT16(data + 0x10), READ_LE_UINT16(data + 0x12),READ_LE_UINT16(data + 0x14),READ_LE_UINT16(data + 0x16),
- //READ_LE_UINT16(data + 0x18),READ_LE_UINT16(data + 0x1a));
+ debug(1, "Anim %i data: eh: %i, 10h: %i,12h: %i,14h: %i,16h: %i,18h: %i,1ah: %i", i, READ_LE_UINT16(data + 0xe),
+ READ_LE_UINT16(data + 0x10), READ_LE_UINT16(data + 0x12),READ_LE_UINT16(data + 0x14),READ_LE_UINT16(data + 0x16),
+ READ_LE_UINT16(data + 0x18),READ_LE_UINT16(data + 0x1a));
+
+ debug(1, "Anim %i data: 1ch: %i, 1fh: %i,22h: %i,24h: %i,26h: %i,28h: %i,2ah: %i", i, READ_LE_UINT16(data + 0x1c),
+ READ_LE_UINT16(data + 0x1f), READ_LE_UINT16(data + 0x22),READ_LE_UINT16(data + 0x24),READ_LE_UINT16(data + 0x26),
+ READ_LE_UINT16(data + 0x28),READ_LE_UINT16(data + 0x2a));
+ */
- //debug(1, "Anim %i data: 1ch: %i, 1fh: %i,22h: %i,24h: %i,26h: %i,28h: %i,2ah: %i", i, READ_LE_UINT16(data + 0x1c),
- //READ_LE_UINT16(data + 0x1f), READ_LE_UINT16(data + 0x22),READ_LE_UINT16(data + 0x24),READ_LE_UINT16(data + 0x26),
- //READ_LE_UINT16(data + 0x28),READ_LE_UINT16(data + 0x2a));
// TODO: Find out what the rest of this data (next 38h bytes) does.
data += 0x38;
@@ -115,55 +122,56 @@ void Sprites::doAnims() {
switch (READ_LE_UINT16(data)) {
case 0xFF88:
data += 2;
- debug(9, "func: Set sprite image, and set flag0");
- debug(9, "Sprite index %i", READ_LE_UINT16(data));
+ debug(5, "func: Set sprite image.");
+ debug(5, "Sprite index %i", READ_LE_UINT16(data));
_anims[i].sprite = READ_LE_UINT16(data);
data += 2;
- debug(9, "Unused %i", READ_LE_UINT16(data));
+ //debug(5, "Unused %i", READ_LE_UINT16(data));
data += 2;
- debug(9, "X %i", READ_LE_UINT16(data));
+ debug(5, "X %i", READ_LE_UINT16(data));
_anims[i].x = READ_LE_UINT16(data);
data += 2;
- debug(9, "Y %i", READ_LE_UINT16(data));
+ debug(5, "Y %i", READ_LE_UINT16(data));
_anims[i].y = READ_LE_UINT16(data);
data += 2;
- _anims[i].flag0 = true;
+ _anims[i].flipX = false;
break;
case 0xFF8D:
data += 2;
- debug(9, "func: Set sprite image, and reset flag0");
+ debug(5, "func: Set sprite image, flipped.");
+ debug(5, "Sprite index %i", READ_LE_UINT16(data));
_anims[i].sprite = READ_LE_UINT16(data);
data += 2;
//debug(9, "Unused %i", READ_LE_UINT16(data));
data += 2;
- debug(9, "X %i", READ_LE_UINT16(data));
+ debug(5, "X %i", READ_LE_UINT16(data));
_anims[i].x = READ_LE_UINT16(data);
data += 2;
- debug(9, "Y %i", READ_LE_UINT16(data));
+ debug(5, "Y %i", READ_LE_UINT16(data));
_anims[i].y = READ_LE_UINT16(data);
data += 2;
- _anims[i].flag0 = false;
+ _anims[i].flipX = true;
break;
case 0xFF8A:
data += 2;
- debug(9, "func: Set time to wait");
- debug(9, "Time %i", READ_LE_UINT16(data));
+ debug(5, "func: Set time to wait");
+ debug(5, "Time %i", READ_LE_UINT16(data));
_anims[i].nextRun = _system->getMillis() + READ_LE_UINT16(data) * _animDelay;
data += 2;
break;
case 0xFFB3:
data += 2;
- debug(9, "func: Set time to wait to random value");
+ debug(5, "func: Set time to wait to random value");
rndNr = READ_LE_UINT16(data) + _rnd.getRandomNumber( READ_LE_UINT16(data) + 2);
- debug(9, "Minimum time %i", READ_LE_UINT16(data));
+ debug(5, "Minimum time %i", READ_LE_UINT16(data));
data += 2;
- debug(9, "Maximum time %i", READ_LE_UINT16(data));
+ debug(5, "Maximum time %i", READ_LE_UINT16(data));
data += 2;
_anims[i].nextRun = _system->getMillis() + rndNr * _animDelay;
break;
case 0xFF8C:
data += 2;
- debug(9, "func: Wait until wait time has elapsed");
+ debug(5, "func: Wait until wait time has elapsed");
_anims[i].reentry = data;
endLoop = true;
//assert( _anims[i].nextRun > _system->getMillis());
@@ -178,35 +186,35 @@ void Sprites::doAnims() {
break;
case 0xFF97:
data += 2;
- debug(9, "func: Set default X coordinate of sprite");
- debug(9, "X %i", READ_LE_UINT16(data));
+ debug(5, "func: Set default X coordinate of sprite");
+ debug(5, "X %i", READ_LE_UINT16(data));
_anims[i].x = READ_LE_UINT16(data);
data += 2;
break;
case 0xFF98:
data += 2;
- debug(9, "func: Set default Y coordinate of sprite");
- debug(9, "Y %i", READ_LE_UINT16(data));
+ debug(5, "func: Set default Y coordinate of sprite");
+ debug(5, "Y %i", READ_LE_UINT16(data));
_anims[i].y = READ_LE_UINT16(data);
data += 2;
break;
case 0xFF8B:
- debug(9, "func: Jump to start of script section");
+ debug(5, "func: Jump to start of script section");
//data = scriptStart;
_anims[i].nextRun = _system->getMillis();
endLoop = true;
break;
case 0xFF8E:
data += 2;
- debug(9, "func: Begin for () loop");
- debug(9, "Iterations: %i", READ_LE_UINT16(data));
+ debug(5, "func: Begin for () loop");
+ debug(5, "Iterations: %i", READ_LE_UINT16(data));
_anims[i].loopsLeft = READ_LE_UINT16(data);
data += 2;
_anims[i].loopStart = data;
break;
case 0xFF8F:
data += 2;
- debug(9, "func: End for () loop");
+ debug(5, "func: End for () loop");
if (_anims[i].loopsLeft > 0) {
_anims[i].loopsLeft--;
data = _anims[i].loopStart;
@@ -214,55 +222,58 @@ void Sprites::doAnims() {
break;
case 0xFF90:
data += 2;
- debug(9, "func: Set sprite image using default X and Y (and set flag0)");
- debug(9, "Sprite index %i", READ_LE_UINT16(data));
+ debug(5, "func: Set sprite image using default X and Y");
+ debug(5, "Sprite index %i", READ_LE_UINT16(data));
_anims[i].sprite = READ_LE_UINT16(data);
- _anims[i].flag0 = true;
+ _anims[i].flipX = false;
data += 2;
break;
case 0xFF91:
data += 2;
- debug(9, "func: Set sprite image using default X and Y (and reset flag0)");
- debug(9, "Sprite index %i", READ_LE_UINT16(data));
+ debug(5, "func: Set sprite image using default X and Y, flipped.");
+ debug(5, "Sprite index %i", READ_LE_UINT16(data));
_anims[i].sprite = READ_LE_UINT16(data);
- _anims[i].flag0 = false;
+ _anims[i].flipX = true;
data += 2;
break;
case 0xFF92:
data += 2;
- debug(9, "func: Increase value of default X-coordinate");
- debug(9, "Increment %i", READ_LE_UINT16(data));
+ debug(5, "func: Increase value of default X-coordinate");
+ debug(5, "Increment %i", READ_LE_UINT16(data));
_anims[i].x += READ_LE_UINT16(data);
data += 2;
break;
case 0xFF93:
data += 2;
- debug(9, "func: Increase value of default Y-coordinate");
- debug(9, "Increment %i", READ_LE_UINT16(data));
+ debug(5, "func: Increase value of default Y-coordinate");
+ debug(5, "Increment %i", READ_LE_UINT16(data));
_anims[i].y += READ_LE_UINT16(data);
data += 2;
break;
case 0xFF94:
data += 2;
- debug(9, "func: Decrease value of default X-coordinate");
- debug(9, "Decrement %i", READ_LE_UINT16(data));
+ debug(5, "func: Decrease value of default X-coordinate");
+ debug(5, "Decrement %i", READ_LE_UINT16(data));
_anims[i].x -= READ_LE_UINT16(data);
data += 2;
break;
case 0xFF95:
data += 2;
- debug(9, "func: Decrease value of default Y-coordinate");
- debug(9, "Decrement %i", READ_LE_UINT16(data));
+ debug(5, "func: Decrease value of default Y-coordinate");
+ debug(5, "Decrement %i", READ_LE_UINT16(data));
_anims[i].y -= READ_LE_UINT16(data);
data += 2;
break;
case 0xFF96:
data += 2;
- debug(1, "TODO func: Set value of animation property 34h to 1(?)");
- debug(1, "Arg1 %i", READ_LE_UINT16(data));
- data += 2;
- debug(1, "Arg2 %i", READ_LE_UINT16(data));
+ debug(9, "func: Stop animation");
+ debug(9, "Animation index %i", READ_LE_UINT16(data));
+ uint16 anim = READ_LE_UINT16(data);
data += 2;
+ _anims[anim].play = false;
+ _anims[anim].sprite = -1;
+ //debug(1, "Arg2 %i", READ_LE_UINT16(data));
+ //data += 2;
break;
/* case 0xFF97:
data += 2;
@@ -316,6 +327,12 @@ void Sprites::doAnims() {
debug(1, "Percentage %i", READ_LE_UINT16(data));
data += 2;
break;
+ case 0xFFA7:
+ data += 2;
+ debug(1, "TODO func: Unknown FFA7");
+ debug(1, " %i", READ_LE_UINT16(data));
+ data += 2;
+ break;
default:
debug(1, "Unsupported anim command %X", READ_LE_UINT16(data));
//endLoop = true;
diff --git a/kyra/sprites.h b/kyra/sprites.h
index 183c7043fb..348f7da247 100644
--- a/kyra/sprites.h
+++ b/kyra/sprites.h
@@ -37,9 +37,9 @@ struct Sprite {
struct Anim {
uint8 *script;
uint16 length;
- uint16 x;
- uint16 y;
- bool flag0;
+ int16 x;
+ int16 y;
+ bool flipX;
int8 sprite;
uint8 *loopStart;
uint16 loopsLeft;
@@ -58,6 +58,9 @@ public:
void loadDAT(const char* filename);
Sprite getSprite(uint8 spriteID);
void drawSprites(uint8 srcPage, uint8 dstPage);
+
+ void enableAnim(uint8 anim) { _anims[anim].play = true; }
+ void disableAnim(uint8 anim) { _anims[anim].play = false; }
protected:
KyraEngine *_engine;