aboutsummaryrefslogtreecommitdiff
path: root/engines/toon
diff options
context:
space:
mode:
authorMatthew Hoops2011-07-20 09:27:39 -0400
committerMatthew Hoops2011-07-20 09:27:39 -0400
commitad293b249e74dd1cfbdbd721d02145efbdaf9eca (patch)
treee568d96f6d7f64c5e58b4c7cd1c4fda7e649bfc7 /engines/toon
parentd7411acc2b1c7702280dbff1c3e1bafee528184b (diff)
parente25e85fbb047fef895ede97c3c2c73451631052c (diff)
downloadscummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.tar.gz
scummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.tar.bz2
scummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.zip
Merge remote branch 'upstream/master' into pegasus
Diffstat (limited to 'engines/toon')
-rw-r--r--engines/toon/anim.cpp12
-rw-r--r--engines/toon/anim.h1
-rw-r--r--engines/toon/character.cpp9
-rw-r--r--engines/toon/font.cpp14
-rw-r--r--engines/toon/movie.cpp3
-rw-r--r--engines/toon/path.cpp28
-rw-r--r--engines/toon/picture.cpp11
-rw-r--r--engines/toon/picture.h2
-rw-r--r--engines/toon/tools.cpp2
-rw-r--r--engines/toon/toon.cpp19
-rw-r--r--engines/toon/toon.h6
11 files changed, 80 insertions, 27 deletions
diff --git a/engines/toon/anim.cpp b/engines/toon/anim.cpp
index 23bd0f6487..07d51ef1b9 100644
--- a/engines/toon/anim.cpp
+++ b/engines/toon/anim.cpp
@@ -271,6 +271,18 @@ void Animation::applyPalette(int32 offset, int32 srcOffset, int32 numEntries) {
_vm->setPaletteEntries(_palette + srcOffset, offset, numEntries);
}
+Common::Rect Animation::getFrameRect(int32 frame) {
+ debugC(4, kDebugAnim, "getFrameRect(%d)", frame);
+ if ((frame < 0) || (frame >= _numFrames)) {
+ return Common::Rect();
+ }
+
+ if (_frames[frame]._ref != -1)
+ frame = _frames[frame]._ref;
+
+ return Common::Rect(_frames[frame]._x1, _frames[frame]._y1, _frames[frame]._x2, _frames[frame]._y2);
+}
+
int32 Animation::getFrameWidth(int32 frame) {
debugC(4, kDebugAnim, "getFrameWidth(%d)", frame);
if ((frame < 0) || (frame >= _numFrames))
diff --git a/engines/toon/anim.h b/engines/toon/anim.h
index 13c501b910..4b95b6cf40 100644
--- a/engines/toon/anim.h
+++ b/engines/toon/anim.h
@@ -68,6 +68,7 @@ public:
void drawFrameWithMaskAndScale(Graphics::Surface &surface, int32 frame, int32 xx, int32 yy, int32 zz, Picture *mask, int32 scale);
void drawStrip(int32 offset = 0);
void applyPalette(int32 offset, int32 srcOffset, int32 numEntries);
+ Common::Rect getFrameRect(int32 frame);
int32 getFrameWidth(int32 frame);
int32 getFrameHeight(int32 frame);
int32 getWidth() const;
diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp
index 06c6e21d21..022214157a 100644
--- a/engines/toon/character.cpp
+++ b/engines/toon/character.cpp
@@ -596,7 +596,8 @@ int32 Character::getId() {
void Character::save(Common::WriteStream *stream) {
debugC(1, kDebugCharacter, "save(stream)");
- stream->writeSint32LE(_flags);
+ // we have to save visibility too, put in flags to not invalidate old savegames.
+ stream->writeSint32LE(_flags | ((_visible == false) ? 0x100 : 0));
stream->writeSint32LE(_x);
stream->writeSint32LE(_y);
stream->writeSint32LE(_z);
@@ -633,6 +634,12 @@ void Character::load(Common::ReadStream *stream) {
if (_sceneAnimationId > -1) {
setAnimationInstance(_vm->getSceneAnimation(_sceneAnimationId)->_animInstance);
}
+
+ // "not visible" flag.
+ if (_flags & 0x100) {
+ _flags &= ~0x100;
+ setVisible(false);
+ }
}
void Character::setAnimScript(int32 animScriptId) {
diff --git a/engines/toon/font.cpp b/engines/toon/font.cpp
index 4c491ae2b3..63304c905f 100644
--- a/engines/toon/font.cpp
+++ b/engines/toon/font.cpp
@@ -21,6 +21,7 @@
*/
#include "common/debug.h"
+#include "common/rect.h"
#include "toon/font.h"
@@ -80,7 +81,7 @@ void FontRenderer::renderText(int32 x, int32 y, Common::String origText, int32 m
x -= xx / 2;
}
- _vm->addDirtyRect(x, y, x + xx + 2, y + yy);
+ _vm->addDirtyRect(x, y, x + xx, y + yy);
int32 curX = x;
int32 curY = y;
@@ -110,6 +111,7 @@ void FontRenderer::computeSize(Common::String origText, int32 *retX, int32 *retY
int32 lineHeight = 0;
int32 totalHeight = 0;
int32 totalWidth = 0;
+ int32 lastLineHeight = 0;
const byte *text = (const byte *)origText.c_str();
while (*text) {
@@ -122,17 +124,25 @@ void FontRenderer::computeSize(Common::String origText, int32 *retX, int32 *retY
totalHeight += lineHeight;
lineHeight = 0;
lineWidth = 0;
+ lastLineHeight = 0;
} else {
curChar = textToFont(curChar);
int32 charWidth = _currentFont->getFrameWidth(curChar) - 1;
int32 charHeight = _currentFont->getFrameHeight(curChar);
lineWidth += charWidth;
lineHeight = MAX(lineHeight, charHeight);
+
+ // The character may be offset, so the height doesn't
+ // really tell how far it will stick out. For now,
+ // assume we only need to take the lower bound into
+ // consideration.
+ Common::Rect charRect = _currentFont->getFrameRect(curChar);
+ lastLineHeight = MAX<int32>(lastLineHeight, charRect.bottom);
}
text++;
}
- totalHeight += lineHeight;
+ totalHeight += lastLineHeight;
totalWidth = MAX(totalWidth, lineWidth);
*retX = totalWidth;
diff --git a/engines/toon/movie.cpp b/engines/toon/movie.cpp
index 2318eaaac7..7637f4e62f 100644
--- a/engines/toon/movie.cpp
+++ b/engines/toon/movie.cpp
@@ -94,7 +94,7 @@ void Movie::play(Common::String video, int32 flags) {
_vm->getAudioManager()->setMusicVolume(0);
_decoder->loadFile(video.c_str());
playVideo(isFirstIntroVideo);
- _vm->flushPalette(false);
+ _vm->flushPalette(true);
if (flags & 1)
_vm->getAudioManager()->setMusicVolume(_vm->getAudioManager()->isMusicMuted() ? 0 : 255);
_decoder->close();
@@ -103,7 +103,6 @@ void Movie::play(Common::String video, int32 flags) {
bool Movie::playVideo(bool isFirstIntroVideo) {
debugC(1, kDebugMovie, "playVideo(isFirstIntroVideo: %d)", isFirstIntroVideo);
-
while (!_vm->shouldQuit() && !_decoder->endOfVideo()) {
if (_decoder->needsUpdate()) {
const Graphics::Surface *frame = _decoder->decodeNextFrame();
diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp
index c116d63663..43a134e39b 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -342,8 +342,15 @@ next:
curX = destx;
curY = desty;
- int32 retPathX[4096];
- int32 retPathY[4096];
+ int32 *retPathX = (int32 *)malloc(4096 * sizeof(int32));
+ int32 *retPathY = (int32 *)malloc(4096 * sizeof(int32));
+ if (!retPathX || !retPathY) {
+ free(retPathX);
+ free(retPathY);
+
+ error("[PathFinding::findPath] Cannot allocate pathfinding buffers");
+ }
+
int32 numpath = 0;
retPathX[numpath] = curX;
@@ -377,8 +384,12 @@ next:
}
}
- if (bestX < 0 || bestY < 0)
+ if (bestX < 0 || bestY < 0) {
+ free(retPathX);
+ free(retPathY);
+
return 0;
+ }
retPathX[numpath] = bestX;
retPathY[numpath] = bestY;
@@ -389,6 +400,10 @@ next:
memcpy(_tempPathX, retPathX, sizeof(int32) * numpath);
memcpy(_tempPathY, retPathY, sizeof(int32) * numpath);
+
+ free(retPathX);
+ free(retPathY);
+
return true;
}
@@ -396,6 +411,9 @@ next:
curY = bestY;
}
+ free(retPathX);
+ free(retPathY);
+
return false;
}
@@ -406,8 +424,8 @@ void PathFinding::init(Picture *mask) {
_height = mask->getHeight();
_currentMask = mask;
_heap->unload();
- // In order to reduce memory fragmentation on small devices, we use the maximum
- // possible size here which is TOON_BACKBUFFER_WIDTH. Even though this is
+ // In order to reduce memory fragmentation on small devices, we use the maximum
+ // possible size here which is TOON_BACKBUFFER_WIDTH. Even though this is
// 1280 as opposed to the possible 640, it actually helps memory allocation on
// those devices.
_heap->init(TOON_BACKBUFFER_WIDTH * _height); // should really be _width
diff --git a/engines/toon/picture.cpp b/engines/toon/picture.cpp
index 0257964fb5..295e304765 100644
--- a/engines/toon/picture.cpp
+++ b/engines/toon/picture.cpp
@@ -29,16 +29,14 @@
namespace Toon {
-bool Picture::loadPicture(Common::String file, bool totalPalette /*= false*/) {
- debugC(1, kDebugPicture, "loadPicture(%s, %d)", file.c_str(), (totalPalette) ? 1 : 0);
+bool Picture::loadPicture(Common::String file) {
+ debugC(1, kDebugPicture, "loadPicture(%s)", file.c_str());
uint32 size = 0;
uint8 *fileData = _vm->resources()->getFileData(file, &size);
if (!fileData)
return false;
- _useFullPalette = totalPalette;
-
uint32 compId = READ_BE_UINT32(fileData);
switch (compId) {
@@ -57,6 +55,8 @@ bool Picture::loadPicture(Common::String file, bool totalPalette /*= false*/) {
// do we have a palette ?
_paletteEntries = (dstsize & 0x7ff) / 3;
+ _useFullPalette = (_paletteEntries == 256);
+ // _useFullPalette = true;
if (_paletteEntries) {
_palette = new uint8[_paletteEntries * 3];
memcpy(_palette, _data + dstsize - (dstsize & 0x7ff), _paletteEntries * 3);
@@ -70,7 +70,8 @@ bool Picture::loadPicture(Common::String file, bool totalPalette /*= false*/) {
uint32 decSize = READ_LE_UINT32(fileData + 10);
_data = new uint8[decSize + 100];
_paletteEntries = READ_LE_UINT16(fileData + 14) / 3;
-
+ _useFullPalette = (_paletteEntries == 256);
+
if (_paletteEntries) {
_palette = new uint8[_paletteEntries * 3];
memcpy(_palette, fileData + 16, _paletteEntries * 3);
diff --git a/engines/toon/picture.h b/engines/toon/picture.h
index 23edbc91da..ee0e006702 100644
--- a/engines/toon/picture.h
+++ b/engines/toon/picture.h
@@ -38,7 +38,7 @@ class Picture {
public:
Picture(ToonEngine *vm);
~Picture();
- bool loadPicture(Common::String file, bool totalPalette = false);
+ bool loadPicture(Common::String file);
void setupPalette();
void draw(Graphics::Surface &surface, int32 x, int32 y, int32 dx, int32 dy);
void drawWithRectList(Graphics::Surface& surface, int32 x, int32 y, int32 dx, int32 dy, Common::Array<Common::Rect>& rectArray);
diff --git a/engines/toon/tools.cpp b/engines/toon/tools.cpp
index c9aa470deb..c2ee8acf8a 100644
--- a/engines/toon/tools.cpp
+++ b/engines/toon/tools.cpp
@@ -372,7 +372,7 @@ int32 RncDecoder::unpackM1(const void *input, uint16 inputSize, void *output) {
_dstPtr += inputLength;
_srcPtr += inputLength;
_inputByteLeft -= inputLength;
- uint16 a;
+ uint16 a;
if (_inputByteLeft <= 0)
a = 0;
else if (_inputByteLeft == 1)
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 0e0978b3d6..cff6c24469 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -114,7 +114,7 @@ void ToonEngine::init() {
_drew = _characters[0];
_flux = _characters[1];
-
+
// preload walk anim for flux and drew
_drew->loadWalkAnimation("STNDWALK.CAF");
@@ -614,7 +614,7 @@ struct MainMenuEntry {
bool ToonEngine::showMainmenu(bool &loadedGame) {
Picture *mainmenuPicture = new Picture(this);
- mainmenuPicture->loadPicture("TITLESCR.CPS", true);
+ mainmenuPicture->loadPicture("TITLESCR.CPS");
mainmenuPicture->setupPalette();
flushPalette(false);
@@ -690,6 +690,11 @@ bool ToonEngine::showMainmenu(bool &loadedGame) {
}
}
+ if (_needPaletteFlush) {
+ flushPalette(false);
+ _needPaletteFlush = false;
+ }
+
parseInput();
copyToVirtualScreen(true);
_system->delayMillis(17);
@@ -1547,7 +1552,7 @@ void ToonEngine::clickEvent() {
return;
}
} else {
- if (!_drew->walkTo(_mouseX, _mouseY)) {
+ if (!_drew->walkTo(_mouseX + _gameState->_currentScrollValue, _mouseY)) {
// walk was canceled ?
return;
}
@@ -2600,7 +2605,7 @@ int32 ToonEngine::showInventory() {
delete _inventoryPicture;
_inventoryPicture = new Picture(this);
fadeOut(5);
- _inventoryPicture->loadPicture("SACK128.CPS", true);
+ _inventoryPicture->loadPicture("SACK128.CPS");
_inventoryPicture->setupPalette();
dirtyAllScreen();
@@ -2695,7 +2700,7 @@ int32 ToonEngine::showInventory() {
}
renderInventory();
-
+ _system->delayMillis(10);
}
_gameState->_currentScrollValue = oldScrollValue;
@@ -2786,7 +2791,7 @@ void ToonEngine::showCutaway(Common::String cutawayPicture) {
if (cutawayPicture == "") {
cutawayPicture = Common::String(_gameState->_locations[_gameState->_currentScene]._cutaway) + ".CPS";
}
- _currentCutaway->loadPicture(cutawayPicture, false);
+ _currentCutaway->loadPicture(cutawayPicture);
_currentCutaway->setupPalette();
_oldScrollValue = _gameState->_currentScrollValue;
_gameState->_currentScrollValue = 0;
@@ -3418,7 +3423,7 @@ void ToonEngine::viewInventoryItem(Common::String str, int32 lineId, int32 itemD
fadeOut(5);
Picture *pic = new Picture(this);
- pic->loadPicture(str, false);
+ pic->loadPicture(str);
pic->setupPalette();
dirtyAllScreen();
flushPalette();
diff --git a/engines/toon/toon.h b/engines/toon/toon.h
index 65c6ba0234..cad684d590 100644
--- a/engines/toon/toon.h
+++ b/engines/toon/toon.h
@@ -204,7 +204,7 @@ public:
void viewInventoryItem(Common::String str, int32 lineId, int32 itemDest);
void storePalette();
void restorePalette();
- const char *getSpecialConversationMusic(int32 locationId);
+ const char *getSpecialConversationMusic(int32 locationId);
void playRoomMusic();
void waitForScriptStep();
void doMagnifierEffect();
@@ -320,7 +320,7 @@ public:
}
Common::Error saveGameState(int slot, const Common::String &desc) {
-
+
return (saveGame(slot, desc) ? Common::kWritingFailed : Common::kNoError);
}
@@ -381,7 +381,7 @@ protected:
Common::Array<Common::Rect> _oldDirtyRects;
bool _dirtyAll;
-
+
AnimationInstance *_cursorAnimationInstance;
Animation *_cursorAnimation;