TOLTECS: Fix bugs

- Save scene parameters before playing a movie and restore them afterwards (fixes crash)
- Fix text disappearing too fast
- Implement script function sfGetCameraChanged
- Replace nop script functions with stubs which print debug info when called
- Some cleanup, remove obsolete TODOs
This commit is contained in:
Benjamin Haisch 2011-04-11 11:36:53 +00:00 committed by Willem Jan Palenstijn
parent e1fefefff2
commit acd4d4098f
13 changed files with 59 additions and 24 deletions

View file

@ -147,7 +147,6 @@ void AnimationPlayer::saveState(Common::WriteStream *out) {
}
void AnimationPlayer::loadState(Common::ReadStream *in) {
_resIndex = in->readUint16LE();
_width = in->readUint16LE();
_height = in->readUint16LE();
@ -160,7 +159,6 @@ void AnimationPlayer::loadState(Common::ReadStream *in) {
_firstCurFrameSize = in->readUint32LE();
_firstNextFrameSize = in->readUint32LE();
_firstNextFrameOffset = in->readUint32LE();
}
} // End of namespace Toltecs

View file

@ -94,7 +94,6 @@ protected:
struct Item {
Common::Rect rect;
ItemID id;
//const byte *caption;
Common::String caption;
byte defaultColor, activeColor;
int x, y, w;

View file

@ -41,7 +41,12 @@ MoviePlayer::~MoviePlayer() {
void MoviePlayer::playMovie(uint resIndex) {
uint32 subtitleSlot;
const uint32 subtitleSlot = kMaxScriptSlots - 1;
int16 savedSceneWidth = _vm->_sceneWidth;
int16 savedSceneHeight = _vm->_sceneHeight;
int16 savedCameraHeight = _vm->_cameraHeight;
int16 savedCameraX = _vm->_cameraX;
int16 savedCameraY = _vm->_cameraY;
byte moviePalette[768];
_vm->_isSaveAllowed = false;
@ -53,8 +58,6 @@ void MoviePlayer::playMovie(uint resIndex) {
_vm->_arc->openResource(resIndex);
subtitleSlot = kMaxScriptSlots - 1;
_frameCount = _vm->_arc->readUint32LE();
_chunkCount = _vm->_arc->readUint32LE();
@ -170,6 +173,12 @@ void MoviePlayer::playMovie(uint resIndex) {
debug(0, "playMovie() done");
_vm->_sceneWidth = savedSceneWidth;
_vm->_sceneHeight = savedSceneHeight;
_vm->_cameraHeight = savedCameraHeight;
_vm->_cameraX = savedCameraX;
_vm->_cameraY = savedCameraY;
_vm->_isSaveAllowed = true;
}
@ -187,7 +196,7 @@ void MoviePlayer::fetchAudioChunks() {
byte chunkType = _vm->_arc->readByte();
uint32 chunkSize = _vm->_arc->readUint32LE();
if (chunkType == 4) {
byte *chunkBuffer = new byte[chunkSize];
byte *chunkBuffer = (byte*)malloc(chunkSize);
_vm->_arc->read(chunkBuffer, chunkSize);
_audioStream->queueBuffer(chunkBuffer, chunkSize, DisposeAfterUse::YES, Audio::FLAG_UNSIGNED);
chunkBuffer = NULL;

View file

@ -73,7 +73,6 @@ void RenderQueue::addSprite(SpriteDrawItem &sprite) {
void RenderQueue::addText(int16 x, int16 y, byte color, uint fontResIndex, byte *text, int len) {
// TODO: Font caching?
Font font(_vm->_res->load(fontResIndex)->data);
RenderQueueItem item;
@ -248,8 +247,6 @@ RenderQueueItem *RenderQueue::findItemInQueue(RenderQueueArray *queue, const Ren
bool RenderQueue::hasItemChanged(const RenderQueueItem &item1, const RenderQueueItem &item2) {
// TODO: Clean up.
if (item1.type != item1.type)
return true;

View file

@ -57,7 +57,6 @@ uint32 ArchiveReader::openResource(uint resIndex) {
void ArchiveReader::closeResource() {
}
uint32 ArchiveReader::getResourceSize(uint resIndex) {
return _offsets[resIndex + 1] - _offsets[resIndex];
}

View file

@ -34,7 +34,6 @@
namespace Toltecs {
/* TODO:
- Saveload is working so far but only one slot is supported until the game menu is implemented
- Save with F7; Load with F9
- Saving during an animation (AnimationPlayer) is not working correctly yet
- Maybe switch to SCUMM/Tinsel serialization approach?

View file

@ -444,9 +444,8 @@ void Screen::updateTalkText(int16 slotIndex, int16 slotOffset) {
}
int16 textDurationMultiplier = item->duration + 8;
// TODO: Check sound/text flags
if (*textData == 0xFE) {
//textDurationMultiplier += 100;
if (_vm->_doSpeech && *textData == 0xFE) {
textDurationMultiplier += 100;
}
item->duration = 4 * textDurationMultiplier * durationModifier;
@ -478,7 +477,8 @@ void Screen::addTalkTextItemsToRenderQueue() {
if (item->fontNum == -1 || item->duration == 0)
continue;
item->duration -= _vm->_counter01;
//item->duration -= _vm->_counter01;
item->duration--;
if (item->duration < 0)
item->duration = 0;

View file

@ -66,71 +66,85 @@ typedef Common::Functor0Mem<void, ScriptInterpreter> ScriptFunctionF;
_scriptFuncNames.push_back(#x);
void ScriptInterpreter::setupScriptFunctions() {
// 0
RegisterScriptFunction(sfNop);
RegisterScriptFunction(sfNop);
RegisterScriptFunction(sfGetGameVar);
RegisterScriptFunction(sfSetGameVar);
RegisterScriptFunction(sfUpdateScreen);
// 5
RegisterScriptFunction(sfGetRandomNumber);
RegisterScriptFunction(sfDrawGuiTextMulti);
RegisterScriptFunction(sfUpdateVerbLine);
RegisterScriptFunction(sfSetFontColor);
RegisterScriptFunction(sfGetTalkTextDuration);
// 10
RegisterScriptFunction(sfTalk);
RegisterScriptFunction(sfFindPaletteFragment);
RegisterScriptFunction(sfClearPaletteFragments);
RegisterScriptFunction(sfAddPaletteFragment);
RegisterScriptFunction(sfSetDeltaAnimPalette);
RegisterScriptFunction(sfNop); // TODO
// 15
RegisterScriptFunction(sfSetUnkPaletteEffect);
RegisterScriptFunction(sfBuildColorTransTable);
RegisterScriptFunction(sfSetDeltaMainPalette);
RegisterScriptFunction(sfLoadScript);
RegisterScriptFunction(sfRegisterFont);
// 20
RegisterScriptFunction(sfLoadAddPalette);
RegisterScriptFunction(sfLoadScene);
RegisterScriptFunction(sfSetGuiHeight);
RegisterScriptFunction(sfFindMouseInRectIndex1);
RegisterScriptFunction(sfFindMouseInRectIndex2);
// 25
RegisterScriptFunction(sfDrawGuiImage);
RegisterScriptFunction(sfAddAnimatedSpriteNoLoop);
RegisterScriptFunction(sfAddAnimatedSprite);
RegisterScriptFunction(sfAddStaticSprite);
RegisterScriptFunction(sfAddAnimatedSpriteScaled);
// 30
RegisterScriptFunction(sfFindPath);
RegisterScriptFunction(sfWalk);
RegisterScriptFunction(sfScrollCameraUp);
RegisterScriptFunction(sfScrollCameraDown);
RegisterScriptFunction(sfScrollCameraLeft);
// 35
RegisterScriptFunction(sfScrollCameraRight);
RegisterScriptFunction(sfScrollCameraUpEx);
RegisterScriptFunction(sfScrollCameraDownEx);
RegisterScriptFunction(sfScrollCameraLeftEx);
RegisterScriptFunction(sfScrollCameraRightEx);
// 40
RegisterScriptFunction(sfSetCamera);
RegisterScriptFunction(sfNop); // TODO
RegisterScriptFunction(sfGetCameraChanged);
RegisterScriptFunction(sfGetRgbModifiertAtPoint);
RegisterScriptFunction(sfStartAnim);
RegisterScriptFunction(sfAnimNextFrame);
// 45
RegisterScriptFunction(sfNop);
RegisterScriptFunction(sfGetAnimFrameNumber);
RegisterScriptFunction(sfGetAnimStatus);
RegisterScriptFunction(sfStartShakeScreen);
RegisterScriptFunction(sfStopShakeScreen);
// 50
RegisterScriptFunction(sfStartSequence);
RegisterScriptFunction(sfEndSequence);
RegisterScriptFunction(sfSetSequenceVolume);
RegisterScriptFunction(sfPlayPositionalSound);
RegisterScriptFunction(sfPlaySound2);
// 55
RegisterScriptFunction(sfClearScreen);
RegisterScriptFunction(sfNop);
RegisterScriptFunction(sfHandleInput);
RegisterScriptFunction(sfRunOptionsScreen);
RegisterScriptFunction(sfPrecacheSprites);
// 60
RegisterScriptFunction(sfPrecacheSounds1);
RegisterScriptFunction(sfDeletePrecachedFiles);
RegisterScriptFunction(sfPrecacheSounds2);
RegisterScriptFunction(sfRestoreStackPtr);
RegisterScriptFunction(sfSaveStackPtr);
// 65
RegisterScriptFunction(sfPlayMovie);
RegisterScriptFunction(sfNop);
@ -849,6 +863,11 @@ void ScriptInterpreter::sfSetDeltaAnimPalette() {
_vm->_palette->setDeltaPalette(_vm->_palette->getAnimPalette(), arg8(6), (char)arg8(5), arg8(4), arg8(3));
}
void ScriptInterpreter::sfSetUnkPaletteEffect() {
// TODO
debug("ScriptInterpreter::sfSetUnkPaletteEffect");
}
void ScriptInterpreter::sfBuildColorTransTable() {
_vm->_palette->buildColorTransTable(arg8(4), (char)arg8(3), arg8(5));
}
@ -977,6 +996,10 @@ void ScriptInterpreter::sfSetCamera() {
_vm->setCamera(arg16(5), arg16(3));
}
void ScriptInterpreter::sfGetCameraChanged() {
localWrite16(arg16(3), _vm->getCameraChanged() ? 1 : 0);
}
void ScriptInterpreter::sfGetRgbModifiertAtPoint() {
byte *rgb = getSlotData(arg16(11)) + arg16(9);
_vm->_segmap->getRgbModifiertAtPoint(arg16(5), arg16(3), arg16(7), rgb[0], rgb[1], rgb[2]);
@ -1012,15 +1035,21 @@ void ScriptInterpreter::sfStopShakeScreen() {
void ScriptInterpreter::sfStartSequence() {
// TODO
//_vm->_arc->dump(arg16(3));
// DEBUG: Dump music so we know what's in there
int16 sequenceResIndex = arg16(3);
debug("ScriptInterpreter::sfStartSequence(%d)", sequenceResIndex);
if (sequenceResIndex >= 0)
_vm->_arc->dump(sequenceResIndex, "music");
}
void ScriptInterpreter::sfEndSequence() {
// TODO
debug("ScriptInterpreter::sfEndSequence");
}
void ScriptInterpreter::sfSetSequenceVolume() {
// TODO
//debug("ScriptInterpreter::sfSetSequenceVolume");
}
void ScriptInterpreter::sfPlayPositionalSound() {
@ -1033,6 +1062,7 @@ void ScriptInterpreter::sfPlaySound2() {
void ScriptInterpreter::sfClearScreen() {
// TODO
debug("ScriptInterpreter::sfClearScreen");
}
void ScriptInterpreter::sfHandleInput() {

View file

@ -126,6 +126,7 @@ protected:
void sfClearPaletteFragments();
void sfAddPaletteFragment();
void sfSetDeltaAnimPalette();
void sfSetUnkPaletteEffect();
void sfBuildColorTransTable();
void sfSetDeltaMainPalette();
void sfLoadScript();
@ -151,6 +152,7 @@ protected:
void sfScrollCameraLeftEx();
void sfScrollCameraRightEx();
void sfSetCamera();
void sfGetCameraChanged();
void sfGetRgbModifiertAtPoint();
void sfStartAnim();
void sfAnimNextFrame();

View file

@ -36,8 +36,6 @@ SegmentMap::~SegmentMap() {
void SegmentMap::load(byte *source) {
// TODO: Use MemoryReadStream
freeSegmapMaskRectSurfaces();
_maskRects.clear();
_pathRects.clear();

View file

@ -51,7 +51,7 @@ void Sound::playSound(int16 resIndex, int16 type, int16 volume) {
// TODO: Use the right volumes
debug("playSound(%d, %d, %d)", resIndex, type, volume);
debug(0, "playSound(%d, %d, %d)", resIndex, type, volume);
if (volume == -1 || type == -2) {
if (type == kChannelTypeBackground) {

View file

@ -214,7 +214,6 @@ void ToltecsEngine::requestLoadgame(int slotNum) {
}
void ToltecsEngine::loadScene(uint resIndex) {
// TODO
Resource *sceneResource = _res->load(resIndex);
byte *scene = sceneResource->data;
@ -431,6 +430,10 @@ void ToltecsEngine::setCamera(int16 x, int16 y) {
}
bool ToltecsEngine::getCameraChanged() {
return _cameraX != _newCameraX || _cameraY != _newCameraY;
}
void ToltecsEngine::scrollCameraUp(int16 delta) {
if (_newCameraY > 0) {
if (_newCameraY < delta)

View file

@ -112,6 +112,7 @@ public:
void setGuiHeight(int16 guiHeight);
void setCamera(int16 x, int16 y);
bool getCameraChanged();
void scrollCameraUp(int16 delta);
void scrollCameraDown(int16 delta);
void scrollCameraLeft(int16 delta);