aboutsummaryrefslogtreecommitdiff
path: root/engines/toon
diff options
context:
space:
mode:
Diffstat (limited to 'engines/toon')
-rw-r--r--engines/toon/audio.cpp1
-rw-r--r--engines/toon/character.cpp10
-rw-r--r--engines/toon/detection.cpp7
-rw-r--r--engines/toon/drew.cpp1
-rw-r--r--engines/toon/hotspot.cpp1
-rw-r--r--engines/toon/movie.cpp3
-rw-r--r--engines/toon/path.cpp100
-rw-r--r--engines/toon/path.h17
-rw-r--r--engines/toon/picture.cpp11
-rw-r--r--engines/toon/picture.h2
-rw-r--r--engines/toon/script.cpp1
-rw-r--r--engines/toon/script.h1
-rw-r--r--engines/toon/toon.cpp15
13 files changed, 91 insertions, 79 deletions
diff --git a/engines/toon/audio.cpp b/engines/toon/audio.cpp
index 0bf3316209..4a4a84e62c 100644
--- a/engines/toon/audio.cpp
+++ b/engines/toon/audio.cpp
@@ -613,4 +613,3 @@ void AudioManager::updateAmbientSFX()
}
} // End of namespace Toon
-
diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp
index 06c6e21d21..7d9a31c170 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) {
@@ -1102,4 +1109,3 @@ void Character::updateIdle() {
}
}
} // End of namespace Toon
-
diff --git a/engines/toon/detection.cpp b/engines/toon/detection.cpp
index 810a37720a..ac4caae8b2 100644
--- a/engines/toon/detection.cpp
+++ b/engines/toon/detection.cpp
@@ -224,12 +224,7 @@ SaveStateDescriptor ToonMetaEngine::querySaveMetaInfos(const char *target, int s
SaveStateDescriptor desc(slot, saveName);
- Graphics::Surface *thumbnail = new Graphics::Surface();
- assert(thumbnail);
- if (!Graphics::loadThumbnail(*file, *thumbnail)) {
- delete thumbnail;
- thumbnail = 0;
- }
+ Graphics::Surface *const thumbnail = Graphics::loadThumbnail(*file);
desc.setThumbnail(thumbnail);
desc.setDeletableFlag(true);
diff --git a/engines/toon/drew.cpp b/engines/toon/drew.cpp
index 89438fb35c..df5cfcfa03 100644
--- a/engines/toon/drew.cpp
+++ b/engines/toon/drew.cpp
@@ -129,4 +129,3 @@ void CharacterDrew::resetScale()
setPosition(_x, _y);
}
} // End of namespace Toon
-
diff --git a/engines/toon/hotspot.cpp b/engines/toon/hotspot.cpp
index 62458ad800..ee81b87417 100644
--- a/engines/toon/hotspot.cpp
+++ b/engines/toon/hotspot.cpp
@@ -149,4 +149,3 @@ HotspotData *Hotspots::Get(int32 id) {
}
} // End of namespace Toon
-
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 43a134e39b..60ca007930 100644
--- a/engines/toon/path.cpp
+++ b/engines/toon/path.cpp
@@ -28,54 +28,69 @@ namespace Toon {
PathFindingHeap::PathFindingHeap() {
_count = 0;
- _alloc = 0;
+ _size = 0;
_data = NULL;
}
PathFindingHeap::~PathFindingHeap() {
- delete[] _data;
+ free(_data);
}
-int32 PathFindingHeap::init(int32 size) {
+void PathFindingHeap::init(int32 size) {
debugC(1, kDebugPath, "init(%d)", size);
+ _size = size;
- delete[] _data;
- _data = new HeapDataGrid[size * 2];
- memset(_data, 0, sizeof(HeapDataGrid) * size * 2);
+ free(_data);
+ _data = (HeapDataGrid *)malloc(sizeof(HeapDataGrid) * _size);
+ memset(_data, 0, sizeof(HeapDataGrid) * _size);
_count = 0;
- _alloc = size;
- return size;
}
-int32 PathFindingHeap::unload() {
- delete[] _data;
+void PathFindingHeap::unload() {
+ _count = 0;
+ _size = 0;
+ free(_data);
_data = NULL;
- return 0;
}
-int32 PathFindingHeap::clear() {
- //debugC(1, kDebugPath, "clear()");
+void PathFindingHeap::clear() {
+ debugC(1, kDebugPath, "clear()");
_count = 0;
- memset(_data, 0, sizeof(HeapDataGrid) * _alloc * 2);
- return 1;
+ memset(_data, 0, sizeof(HeapDataGrid) * _size);
}
-int32 PathFindingHeap::push(int32 x, int32 y, int32 weight) {
- //debugC(6, kDebugPath, "push(%d, %d, %d)", x, y, weight);
+void PathFindingHeap::push(int32 x, int32 y, int32 weight) {
+ debugC(2, kDebugPath, "push(%d, %d, %d)", x, y, weight);
+
+ if (_count == _size) {
+ // Increase size by 50%
+ int newSize = _size + (_size >> 1) + 1;
+ HeapDataGrid *newData;
+
+ newData = (HeapDataGrid *)realloc(_data, sizeof(HeapDataGrid) * newSize);
+ if (newData == NULL) {
+ warning("Aborting attempt to push onto PathFindingHeap at maximum size: %d", _count);
+ return;
+ }
+
+ memset(newData + _size, 0, sizeof(HeapDataGrid) * (newSize - _size));
+ _data = newData;
+ _size = newSize;
+ }
- _count++;
_data[_count]._x = x;
_data[_count]._y = y;
_data[_count]._weight = weight;
+ _count++;
- int32 lMax = _count;
+ int32 lMax = _count-1;
int32 lT = 0;
while (1) {
- lT = lMax / 2;
- if (lT < 1)
+ if (lMax <= 0)
break;
+ lT = (lMax-1) / 2;
if (_data[lT]._weight > _data[lMax]._weight) {
HeapDataGrid temp;
@@ -87,31 +102,31 @@ int32 PathFindingHeap::push(int32 x, int32 y, int32 weight) {
break;
}
}
- return 1;
}
-int32 PathFindingHeap::pop(int32 *x, int32 *y, int32 *weight) {
- //debugC(6, kDebugPath, "pop(x, y, weight)");
+void PathFindingHeap::pop(int32 *x, int32 *y, int32 *weight) {
+ debugC(2, kDebugPath, "pop(x, y, weight)");
- if (!_count)
- return 0;
+ if (!_count) {
+ warning("Attempt to pop empty PathFindingHeap!");
+ return;
+ }
- *x = _data[1]._x;
- *y = _data[1]._y;
- *weight = _data[1]._weight;
+ *x = _data[0]._x;
+ *y = _data[0]._y;
+ *weight = _data[0]._weight;
- _data[1] = _data[_count];
- _count--;
+ _data[0] = _data[--_count];
if (!_count)
- return 0;
+ return;
- int32 lMin = 1;
- int32 lT = 1;
+ int32 lMin = 0;
+ int32 lT = 0;
while (1) {
- lT = lMin << 1;
- if (lT <= _count) {
- if (lT < _count) {
+ lT = (lMin << 1) + 1;
+ if (lT < _count) {
+ if (lT < _count-1) {
if (_data[lT + 1]._weight < _data[lT]._weight)
lT++;
}
@@ -129,7 +144,6 @@ int32 PathFindingHeap::pop(int32 *x, int32 *y, int32 *weight) {
break;
}
}
- return 0;
}
PathFinding::PathFinding(ToonEngine *vm) : _vm(vm) {
@@ -164,7 +178,7 @@ bool PathFinding::isLikelyWalkable(int32 x, int32 y) {
}
bool PathFinding::isWalkable(int32 x, int32 y) {
- //debugC(6, kDebugPath, "isWalkable(%d, %d)", x, y);
+ debugC(2, kDebugPath, "isWalkable(%d, %d)", x, y);
bool maskWalk = (_currentMask->getData(x, y) & 0x1f) > 0;
@@ -299,7 +313,7 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
_heap->push(curX, curY, abs(destx - x) + abs(desty - y));
int wei = 0;
- while (_heap->_count) {
+ while (_heap->getCount()) {
wei = 0;
_heap->pop(&curX, &curY, &curWeight);
int curNode = curX + curY * _width;
@@ -424,11 +438,7 @@ 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
- // 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
+ _heap->init(500);
delete[] _gridTemp;
_gridTemp = new int32[_width*_height];
}
diff --git a/engines/toon/path.h b/engines/toon/path.h
index 329127c9ce..2de58064f0 100644
--- a/engines/toon/path.h
+++ b/engines/toon/path.h
@@ -38,17 +38,18 @@ public:
PathFindingHeap();
~PathFindingHeap();
- int32 _alloc;
- int32 _count;
-
- int32 push(int32 x, int32 y, int32 weight);
- int32 pop(int32 *x, int32 *y, int32 *weight);
- int32 init(int32 size);
- int32 clear();
- int32 unload();
+ void push(int32 x, int32 y, int32 weight);
+ void pop(int32 *x, int32 *y, int32 *weight);
+ void init(int32 size);
+ void clear();
+ void unload();
+ int32 getCount() { return _count; }
private:
HeapDataGrid *_data;
+
+ int32 _size;
+ int32 _count;
};
class PathFinding {
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/script.cpp b/engines/toon/script.cpp
index eed781295a..69ae727bb5 100644
--- a/engines/toon/script.cpp
+++ b/engines/toon/script.cpp
@@ -502,4 +502,3 @@ void EMCInterpreter::loadState(EMCState *script, Common::ReadStream *stream) {
}
} // End of namespace Toon
-
diff --git a/engines/toon/script.h b/engines/toon/script.h
index 9dd00dca80..8ef085f383 100644
--- a/engines/toon/script.h
+++ b/engines/toon/script.h
@@ -148,4 +148,3 @@ private:
} // End of namespace Toon
#endif
-
diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp
index 26639d71f7..cff6c24469 100644
--- a/engines/toon/toon.cpp
+++ b/engines/toon/toon.cpp
@@ -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();
@@ -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();