diff options
Diffstat (limited to 'engines/toon')
-rw-r--r-- | engines/toon/anim.cpp | 12 | ||||
-rw-r--r-- | engines/toon/anim.h | 1 | ||||
-rw-r--r-- | engines/toon/detection.cpp | 37 | ||||
-rw-r--r-- | engines/toon/font.cpp | 14 | ||||
-rw-r--r-- | engines/toon/path.cpp | 28 | ||||
-rw-r--r-- | engines/toon/tools.cpp | 2 | ||||
-rw-r--r-- | engines/toon/toon.cpp | 5 | ||||
-rw-r--r-- | engines/toon/toon.h | 9 |
8 files changed, 67 insertions, 41 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/detection.cpp b/engines/toon/detection.cpp index 1056f6ec0d..810a37720a 100644 --- a/engines/toon/detection.cpp +++ b/engines/toon/detection.cpp @@ -28,7 +28,7 @@ #include "graphics/thumbnail.h" #include "toon/toon.h" -static const PlainGameDescriptor ToonGames[] = { +static const PlainGameDescriptor toonGames[] = { { "toon", "Toonstruck" }, { 0, 0 } }; @@ -117,34 +117,17 @@ static const char * const directoryGlobs[] = { 0 }; -static const ADParams detectionParams = { - // Pointer to ADGameDescription or its superset structure - (const byte *)Toon::gameDescriptions, - // Size of that superset structure - sizeof(ADGameDescription), - // Number of bytes to compute MD5 sum for - 5000, - // List of all engine targets - ToonGames, - // Structure for autoupgrading obsolete targets - 0, - // Name of single gameid (optional) - "toon", - // List of files for file-based fallback detection (optional) - Toon::fileBasedFallback, - // Flags - 0, - // Additional GUI options (for every game} - Common::GUIO_NONE, - // Maximum directory depth - 3, - // List of directory globs - directoryGlobs -}; - class ToonMetaEngine : public AdvancedMetaEngine { public: - ToonMetaEngine() : AdvancedMetaEngine(detectionParams) {} + ToonMetaEngine() : AdvancedMetaEngine(Toon::gameDescriptions, sizeof(ADGameDescription), toonGames) { + _singleid = "toon"; + _maxScanDepth = 3; + _directoryGlobs = directoryGlobs; + } + + virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { + return detectGameFilebased(allFiles, Toon::fileBasedFallback); + } virtual const char *getName() const { return "Toon"; 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/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/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 93da20fb47..26639d71f7 100644 --- a/engines/toon/toon.cpp +++ b/engines/toon/toon.cpp @@ -28,6 +28,7 @@ #include "common/savefile.h" #include "common/memstream.h" +#include "engines/advancedDetector.h" #include "engines/util.h" #include "graphics/palette.h" #include "graphics/surface.h" @@ -113,7 +114,7 @@ void ToonEngine::init() { _drew = _characters[0]; _flux = _characters[1]; - + // preload walk anim for flux and drew _drew->loadWalkAnimation("STNDWALK.CAF"); @@ -2694,7 +2695,7 @@ int32 ToonEngine::showInventory() { } renderInventory(); - + _system->delayMillis(10); } _gameState->_currentScrollValue = oldScrollValue; diff --git a/engines/toon/toon.h b/engines/toon/toon.h index 02828f26d1..cad684d590 100644 --- a/engines/toon/toon.h +++ b/engines/toon/toon.h @@ -23,7 +23,6 @@ #ifndef TOON_TOON_H #define TOON_TOON_H -#include "engines/advancedDetector.h" #include "engines/engine.h" #include "graphics/surface.h" #include "common/random.h" @@ -44,6 +43,8 @@ namespace Common { class MemoryWriteStreamDynamic; } +struct ADGameDescription; + #define TOON_DAT_VER_MAJ 0 // 1 byte #define TOON_DAT_VER_MIN 3 // 1 byte #define TOON_SAVEGAME_VERSION 4 @@ -203,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(); @@ -319,7 +320,7 @@ public: } Common::Error saveGameState(int slot, const Common::String &desc) { - + return (saveGame(slot, desc) ? Common::kWritingFailed : Common::kNoError); } @@ -380,7 +381,7 @@ protected: Common::Array<Common::Rect> _oldDirtyRects; bool _dirtyAll; - + AnimationInstance *_cursorAnimationInstance; Animation *_cursorAnimation; |