Skip to content

Commit

Permalink
DIRECTOR: Ensure channel sprite information is up to date
Browse files Browse the repository at this point in the history
Previously there was a gap between loading a new frame, and copying the
sprite information from that new frame back to the channels (if
required). Scripts could run in this gap, and in this case they would
be operating on the old sprite information instead of the new.

Score::renderFrame has been renamed to Score::updateFrame; the method
doesn't actually render anything, it reconciles the difference
between the frame data and the channel data, updates the channel data,
and produces a list of dirty rects.

Fixes the menu screen of Majestic: Alien Encounter.
Fixes director-tests/D4-unit/T_SPRT02 and T_SPRT03
  • Loading branch information
moralrecordings authored and sev- committed May 25, 2024
1 parent 41cea48 commit ff7cdff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions engines/director/lingo/lingo-the.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ void Lingo::setTheEntity(int entity, Datum &id, int field, Datum &d) {
g_director->getCurrentWindow()->setStageColor(g_director->transformColor(d.asInt()));

// Redraw the stage
score->renderSprites(kRenderForceUpdate);
score->updateSprites(kRenderForceUpdate);
g_director->getCurrentWindow()->render();
break;
case kTheSwitchColorDepth:
Expand Down Expand Up @@ -1493,8 +1493,8 @@ void Lingo::setTheSprite(Datum &id1, int field, Datum &d) {
((DigitalVideoCastMember *)castMember)->setChannel(channel);
((DigitalVideoCastMember *)castMember)->startVideo();
// b_updateStage needs to have _videoPlayback set to render video
// in the regular case Score::renderSprites sets it.
// However Score::renderSprites is not in the current code path.
// in the regular case Score::updateSprites sets it.
// However Score::updateSprites is not in the current code path.
movie->_videoPlayback = true;
}
}
Expand Down Expand Up @@ -1655,7 +1655,7 @@ void Lingo::setTheSprite(Datum &id1, int field, Datum &d) {
break;
case kTheRect:
if (d.type == RECT || (d.type == ARRAY && d.u.farr->arr.size() >= 4)) {
score->renderSprites(kRenderForceUpdate);
score->updateSprites(kRenderForceUpdate);
channel->setBbox(
d.u.farr->arr[0].u.i, d.u.farr->arr[1].u.i,
d.u.farr->arr[2].u.i, d.u.farr->arr[3].u.i
Expand Down
15 changes: 9 additions & 6 deletions engines/director/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,9 @@ void Score::updateCurrentFrame() {

// this copies in the frame data and updates _curFrameNumber
loadFrame(nextFrameNumberToLoad, true);

// finally, update the channels and buffer any dirty rectangles
updateSprites();
}
return;
}
Expand Down Expand Up @@ -677,12 +680,12 @@ void Score::renderFrame(uint16 frameId, RenderMode mode) {
_window->render();
_skipTransition = false;
} else if (g_director->_playbackPaused) {
renderSprites(mode);
updateSprites(mode);
_window->render();
} else if (!renderTransition(frameId, mode)) {
bool skip = renderPrePaletteCycle(mode);
setLastPalette();
renderSprites(mode);
updateSprites(mode);
_window->render();
if (!skip)
renderPaletteCycle(mode);
Expand Down Expand Up @@ -726,11 +729,11 @@ bool Score::renderTransition(uint16 frameId, RenderMode mode) {
return false;
}

void Score::renderSprites(RenderMode mode) {
void Score::updateSprites(RenderMode mode) {
if (_window->_newMovieStarted)
mode = kRenderForceUpdate;

debugC(5, kDebugImages, "Score::renderSprites(): starting render cycle, mode %d", mode);
debugC(5, kDebugImages, "Score::updateSprites(): starting render cycle, mode %d", mode);

_movie->_videoPlayback = false;

Expand Down Expand Up @@ -773,14 +776,14 @@ void Score::renderSprites(RenderMode mode) {
if (currentSprite) {
Common::Rect bbox = channel->getBbox();
debugC(5, kDebugImages,
"Score::renderSprites(): CH: %-3d castId: %s invalid: %d [ink: %d, puppet: %d, moveable: %d, trails: %d, visible: %d] [bbox: %d,%d,%d,%d] [type: %d fg: %d bg: %d] [script: %s]",
"Score::updateSprites(): CH: %-3d castId: %s invalid: %d [ink: %d, puppet: %d, moveable: %d, trails: %d, visible: %d] [bbox: %d,%d,%d,%d] [type: %d fg: %d bg: %d] [script: %s]",
i, currentSprite->_castId.asString().c_str(), invalidCastMember,
currentSprite->_ink, currentSprite->_puppet, currentSprite->_moveable,
currentSprite->_trails, channel->_visible,
PRINT_RECT(bbox), currentSprite->_spriteType, currentSprite->_foreColor, currentSprite->_backColor,
currentSprite->_scriptId.asString().c_str());
} else {
debugC(5, kDebugImages, "Score::renderSprites(): CH: %-3d: No sprite", i);
debugC(5, kDebugImages, "Score::updateSprites(): CH: %-3d: No sprite", i);
}
} else {
channel->setClean(nextSprite, true);
Expand Down
2 changes: 1 addition & 1 deletion engines/director/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Score {

bool renderTransition(uint16 frameId, RenderMode mode);
void renderFrame(uint16 frameId, RenderMode mode = kRenderModeNormal);
void renderSprites(RenderMode mode = kRenderModeNormal);
void updateSprites(RenderMode mode = kRenderModeNormal);
bool renderPrePaletteCycle(RenderMode mode = kRenderModeNormal);
void setLastPalette();
bool isPaletteColorCycling();
Expand Down
4 changes: 2 additions & 2 deletions engines/director/transitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void Window::playTransition(uint frame, RenderMode mode, uint16 transDuration, u
Score *score = g_director->getCurrentMovie()->getScore();
if (t.area) {
// Changed area transition
score->renderSprites(mode);
score->updateSprites(mode);

if (_dirtyRects.size() == 0)
return;
Expand All @@ -222,7 +222,7 @@ void Window::playTransition(uint frame, RenderMode mode, uint16 transDuration, u
render(false, &nextFrame);
} else {
// Full stage transition
score->renderSprites(mode);
score->updateSprites(mode);
render(true, &nextFrame);

clipRect = _innerDims;
Expand Down

0 comments on commit ff7cdff

Please sign in to comment.