MOHAWK: Fix LBCode seek/seekToFrame.

This commit is contained in:
Alyssa Milburn 2011-11-27 21:01:46 +01:00
parent 3f30105fff
commit 1e9ea08495
4 changed files with 49 additions and 1 deletions

View File

@ -1859,6 +1859,35 @@ void LBAnimation::seek(uint16 pos) {
}
}
void LBAnimation::seekToTime(uint32 time) {
_lastTime = 0;
_currentFrame = 0;
if (_currentSound != 0xffff) {
_vm->_sound->stopSound(_currentSound);
_currentSound = 0xffff;
}
for (uint32 i = 0; i < _nodes.size(); i++)
_nodes[i]->reset();
uint32 elapsed = 0;
while (elapsed <= time) {
bool ranSomething = false;
// nodes don't wait while seeking
for (uint32 i = 0; i < _nodes.size(); i++)
ranSomething |= (_nodes[i]->update(true) != kLBNodeDone);
elapsed += _tempo;
_currentFrame++;
if (!ranSomething) {
_running = false;
break;
}
}
}
void LBAnimation::stop() {
_running = false;
if (_currentSound != 0xffff) {
@ -3612,6 +3641,10 @@ void LBAnimationItem::seek(uint16 pos) {
_anim->seek(pos);
}
void LBAnimationItem::seekToTime(uint32 time) {
_anim->seekToTime(time);
}
void LBAnimationItem::startPhase(uint phase) {
if (phase == _phase)
seek(1);

View File

@ -331,6 +331,7 @@ public:
void start();
void seek(uint16 pos);
void seekToTime(uint32 time);
void stop();
void playSound(uint16 resourceId);
@ -393,6 +394,7 @@ public:
virtual void done(bool onlyNotify); // 0x10
virtual void init(); // 0x11
virtual void seek(uint16 pos) { } // 0x13
virtual void seekToTime(uint32 time) { }
virtual void setFocused(bool focused) { } // 0x14
virtual void setVisible(bool visible); // 0x17
virtual void setGlobalVisible(bool enabled);
@ -567,6 +569,7 @@ public:
void done(bool onlyNotify);
void init();
void seek(uint16 pos);
void seekToTime(uint32 time);
void startPhase(uint phase);
void stop();

View File

@ -1177,7 +1177,7 @@ CodeCommandInfo itemCommandInfo[NUM_ITEM_COMMANDS] = {
{ "mute", 0 },
{ "play", 0 },
{ "seek", &LBCode::itemSeek },
{ "seekToFrame", 0 },
{ "seekToFrame", &LBCode::itemSeekToFrame },
{ "setParent", &LBCode::itemSetParent },
{ "setZOrder", 0 },
{ "setText", 0 },
@ -1220,6 +1220,17 @@ void LBCode::itemSeek(const Common::Array<LBValue> &params) {
if (!item)
error("attempted seek on invalid item (%s)", params[0].toString().c_str());
uint seekTo = params[1].toInt();
item->seekToTime(seekTo);
}
void LBCode::itemSeekToFrame(const Common::Array<LBValue> &params) {
if (params.size() != 2)
error("incorrect number of parameters (%d) to seekToFrame", params.size());
LBItem *item = resolveItem(params[0]);
if (!item)
error("attempted seekToFrame on invalid item (%s)", params[0].toString().c_str());
uint seekTo = params[1].toInt();
item->seek(seekTo);
}

View File

@ -275,6 +275,7 @@ public:
void itemIsPlaying(const Common::Array<LBValue> &params);
void itemMoveTo(const Common::Array<LBValue> &params);
void itemSeek(const Common::Array<LBValue> &params);
void itemSeekToFrame(const Common::Array<LBValue> &params);
void itemSetParent(const Common::Array<LBValue> &params);
};