aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOystein Eftevaag2007-01-06 17:11:08 +0000
committerOystein Eftevaag2007-01-06 17:11:08 +0000
commit8fbf9a1e238ca0a341b1a79ef9362e0d6eb2bd29 (patch)
treee1ae76674b15f7ffef487839563e58d1f3342ba4
parent5e2bd94f7a22d826be0606baceef10d522aec4d3 (diff)
downloadscummvm-rg350-8fbf9a1e238ca0a341b1a79ef9362e0d6eb2bd29.tar.gz
scummvm-rg350-8fbf9a1e238ca0a341b1a79ef9362e0d6eb2bd29.tar.bz2
scummvm-rg350-8fbf9a1e238ca0a341b1a79ef9362e0d6eb2bd29.zip
A few minor fixes and optimizations (biggest one is splitting decodeFrameDeltaPage() into two functions to avoid a high amount of conditional jumps per decided animation frame
svn-id: r25034
-rw-r--r--engines/kyra/animator.cpp5
-rw-r--r--engines/kyra/scene.cpp2
-rw-r--r--engines/kyra/screen.cpp127
-rw-r--r--engines/kyra/screen.h4
-rw-r--r--engines/kyra/sequences_v2.cpp2
-rw-r--r--engines/kyra/wsamovie.cpp9
-rw-r--r--engines/kyra/wsamovie.h6
7 files changed, 112 insertions, 43 deletions
diff --git a/engines/kyra/animator.cpp b/engines/kyra/animator.cpp
index 8d28bcc934..3a632634cd 100644
--- a/engines/kyra/animator.cpp
+++ b/engines/kyra/animator.cpp
@@ -677,8 +677,9 @@ void ScreenAnimator::animRefreshNPC(int character) {
animObj->x1 = ch->x1;
animObj->y1 = ch->y1;
- _brandonScaleX = _vm->_scaleTable[ch->y1];
- _brandonScaleY = _vm->_scaleTable[ch->y1];
+ int newScale = _vm->_scaleTable[ch->y1];
+ _brandonScaleX = newScale;
+ _brandonScaleY = newScale;
animObj->x1 += (_brandonScaleX * xOffset) >> 8;
animObj->y1 += (_brandonScaleY * yOffset) >> 8;
diff --git a/engines/kyra/scene.cpp b/engines/kyra/scene.cpp
index 66ba0c69a9..05d2c98614 100644
--- a/engines/kyra/scene.cpp
+++ b/engines/kyra/scene.cpp
@@ -147,7 +147,7 @@ void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int
_currentRoom = sceneId;
- int tableId = _roomTable[_currentCharacter->sceneId].nameIndex;
+ int tableId = _roomTable[sceneId].nameIndex;
char fileNameBuffer[32];
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
strcat(fileNameBuffer, ".DAT");
diff --git a/engines/kyra/screen.cpp b/engines/kyra/screen.cpp
index ebfcb63351..1ee12e2522 100644
--- a/engines/kyra/screen.cpp
+++ b/engines/kyra/screen.cpp
@@ -1410,14 +1410,12 @@ void Screen::decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize) {
break;
}
uint8 code = *src++;
- if (!(code & 0x80)) {
- int len = MIN(count, (code >> 4) + 3);
- int offs = ((code & 0xF) << 8) | *src++;
+ if (!(code & 0x80)) { // 8th bit isn't set
+ int len = MIN(count, (code >> 4) + 3); //upper half of code is the length
+ int offs = ((code & 0xF) << 8) | *src++; //lower half of code as byte 2 of offset.
const uint8 *dstOffs = dst - offs;
- while (len--) {
- *dst++ = *dstOffs++;
- }
- } else if (code & 0x40) {
+ memcpy(dst, dstOffs, len); dst += len;
+ } else if (code & 0x40) { // 7th bit is set
int len = (code & 0x3F) + 3;
if (code == 0xFE) {
len = READ_LE_UINT16(src); src += 2;
@@ -1434,15 +1432,12 @@ void Screen::decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize) {
len = count;
}
const uint8 *dstOffs = dstOrig + offs;
- while (len--) {
- *dst++ = *dstOffs++;
- }
+ memcpy(dst, dstOffs, len); dst += len;
}
- } else if (code != 0x80) {
+ } else if (code != 0x80) { // not just the 8th bit set.
+ //Copy some bytes from source to dest.
int len = MIN(count, code & 0x3F);
- while (len--) {
- *dst++ = *src++;
- }
+ memcpy(dst, src, len); dst += len; src += len;
} else {
break;
}
@@ -1492,8 +1487,8 @@ void Screen::decodeFrameDelta(uint8 *dst, const uint8 *src) {
}
}
-void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch, int noXor) {
- debugC(9, kDebugLevelScreen, "Screen::decodeFrameDeltaPage(%p, %p, %d, %d)", (const void *)dst, (const void *)src, pitch, noXor);
+void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch) {
+ debugC(9, kDebugLevelScreen, "Screen::decodeFrameDeltaPage(%p, %p, %d)", (const void *)dst, (const void *)src, pitch);
int count = 0;
uint8 *dstNext = dst;
while (1) {
@@ -1502,11 +1497,7 @@ void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch, int n
uint8 len = *src++;
code = *src++;
while (len--) {
- if (noXor) {
- *dst++ = code;
- } else {
- *dst++ ^= code;
- }
+ *dst++ ^= code;
if (++count == pitch) {
count = 0;
dstNext += SCREEN_W;
@@ -1534,11 +1525,7 @@ void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch, int n
uint16 len = subcode - 0x4000;
code = *src++;
while (len--) {
- if (noXor) {
- *dst++ = code;
- } else {
- *dst++ ^= code;
- }
+ *dst++ ^= code;
if (++count == pitch) {
count = 0;
dstNext += SCREEN_W;
@@ -1547,11 +1534,7 @@ void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch, int n
}
} else {
while (subcode--) {
- if (noXor) {
- *dst++ = *src++;
- } else {
- *dst++ ^= *src++;
- }
+ *dst++ ^= *src++;
if (++count == pitch) {
count = 0;
dstNext += SCREEN_W;
@@ -1573,11 +1556,87 @@ void Screen::decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch, int n
}
} else {
while (code--) {
- if (noXor) {
- *dst++ = *src++;
+ *dst++ ^= *src++;
+ if (++count == pitch) {
+ count = 0;
+ dstNext += SCREEN_W;
+ dst = dstNext;
+ }
+ }
+ }
+ }
+}
+
+void Screen::decodeFrameDeltaPageNoXor(uint8 *dst, const uint8 *src, const int pitch) {
+ debugC(9, kDebugLevelScreen, "Screen::decodeFrameDeltaPageNoXor(%p, %p, %d)", (const void *)dst, (const void *)src, pitch);
+ int count = 0;
+ uint8 *dstNext = dst;
+ while (1) {
+ uint8 code = *src++;
+ if (code == 0) {
+ uint8 len = *src++;
+ code = *src++;
+ while (len--) {
+ *dst++ = code;
+ if (++count == pitch) {
+ count = 0;
+ dstNext += SCREEN_W;
+ dst = dstNext;
+ }
+ }
+ } else if (code & 0x80) {
+ code -= 0x80;
+ if (code != 0) {
+ dst += code;
+
+ count += code;
+ while (count >= pitch) {
+ count -= pitch;
+ dstNext += SCREEN_W;
+ dst = dstNext + count;
+ }
+ } else {
+ uint16 subcode = READ_LE_UINT16(src); src += 2;
+ if (subcode == 0) {
+ break;
+ } else if (subcode & 0x8000) {
+ subcode -= 0x8000;
+ if (subcode & 0x4000) {
+ uint16 len = subcode - 0x4000;
+ code = *src++;
+ while (len--) {
+ *dst++ = code;
+ if (++count == pitch) {
+ count = 0;
+ dstNext += SCREEN_W;
+ dst = dstNext;
+ }
+ }
+ } else {
+ while (subcode--) {
+ *dst++ = *src++;
+ if (++count == pitch) {
+ count = 0;
+ dstNext += SCREEN_W;
+ dst = dstNext;
+ }
+ }
+ }
} else {
- *dst++ ^= *src++;
+ dst += subcode;
+
+ count += subcode;
+ while (count >= pitch) {
+ count -= pitch;
+ dstNext += SCREEN_W;
+ dst = dstNext + count;
+ }
+
}
+ }
+ } else {
+ while (code--) {
+ *dst++ = *src++;
if (++count == pitch) {
count = 0;
dstNext += SCREEN_W;
diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h
index 813ccb9908..b245c938c8 100644
--- a/engines/kyra/screen.h
+++ b/engines/kyra/screen.h
@@ -136,7 +136,9 @@ public:
static void decodeFrame3(const uint8 *src, uint8 *dst, uint32 size);
static void decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize);
static void decodeFrameDelta(uint8 *dst, const uint8 *src);
- static void decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch, int noXor);
+ static void decodeFrameDeltaPage(uint8 *dst, const uint8 *src, const int pitch);
+ static void decodeFrameDeltaPageNoXor(uint8 *dst, const uint8 *src, const int pitch);
+
uint8 *encodeShape(int x, int y, int w, int h, int flags);
void copyRegionToBuffer(int pageNum, int x, int y, int w, int h, uint8 *dest);
void loadBitmap(const char *filename, int tempPage, int dstPage, uint8 *palData);
diff --git a/engines/kyra/sequences_v2.cpp b/engines/kyra/sequences_v2.cpp
index f997317045..c396ac0567 100644
--- a/engines/kyra/sequences_v2.cpp
+++ b/engines/kyra/sequences_v2.cpp
@@ -115,7 +115,7 @@ void KyraEngine_v2::seq_playSequences(int startSeq, int endSeq) {
break;
else {
uint32 loopTime = currTime - startTime;
- delay(loopTime > _tickLength ? loopTime : _tickLength);
+ delay(loopTime < _tickLength ? loopTime : _tickLength);
}
}
diff --git a/engines/kyra/wsamovie.cpp b/engines/kyra/wsamovie.cpp
index ec3670106e..4a2fc3ce14 100644
--- a/engines/kyra/wsamovie.cpp
+++ b/engines/kyra/wsamovie.cpp
@@ -143,7 +143,7 @@ void WSAMovieV1::displayFrame(int frameNum) {
if (_flags & WF_OFFSCREEN_DECODE) {
Screen::decodeFrameDelta(dst, _deltaBuffer);
} else {
- Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width, 1);
+ Screen::decodeFrameDeltaPageNoXor(dst, _deltaBuffer, _width);
}
}
_currentFrame = 0;
@@ -206,7 +206,7 @@ void WSAMovieV1::processFrame(int frameNum, uint8 *dst) {
if (_flags & WF_OFFSCREEN_DECODE) {
Screen::decodeFrameDelta(dst, _deltaBuffer);
} else {
- Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width, 0);
+ Screen::decodeFrameDeltaPage(dst, _deltaBuffer, _width);
}
}
@@ -246,6 +246,11 @@ int WSAMovieV2::open(const char *filename, int unk1, uint8 *palBuf) {
}
}
+ if (flags & 2)
+ {
+ _flags |= WF_MASKED_BLIT;
+ }
+
if (!(unk1 & 2)) {
_flags |= WF_OFFSCREEN_DECODE;
const int offscreenBufferSize = _width * _height;
diff --git a/engines/kyra/wsamovie.h b/engines/kyra/wsamovie.h
index 8f5069ddb7..26d86caef1 100644
--- a/engines/kyra/wsamovie.h
+++ b/engines/kyra/wsamovie.h
@@ -69,15 +69,17 @@ public:
virtual int frames() { return _opened ? _numFrames : -1; }
virtual void displayFrame(int frameNum);
-protected:
- virtual void processFrame(int frameNum, uint8 *dst);
enum WSAFlags {
+ WF_MASKED_BLIT = 0x1,
WF_OFFSCREEN_DECODE = 0x10,
WF_NO_FIRST_FRAME = 0x40,
WF_HAS_PALETTE = 0x100
};
+protected:
+ virtual void processFrame(int frameNum, uint8 *dst);
+
uint16 _currentFrame;
uint16 _numFrames;
uint16 _width;