[Scummvm-git-logs] scummvm master -> f82c3bfa3212cedd7819eda979041575b434b2e0

npjg nathanael.gentrydb8 at gmail.com
Fri Jun 26 04:18:54 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f82c3bfa32 DIRECTOR: Remove score backSurfaces


Commit: f82c3bfa3212cedd7819eda979041575b434b2e0
    https://github.com/scummvm/scummvm/commit/f82c3bfa3212cedd7819eda979041575b434b2e0
Author: Nathanael Gentry (nathanael.gentrydb8 at gmail.com)
Date: 2020-06-26T00:18:22-04:00

Commit Message:
DIRECTOR: Remove score backSurfaces

These are replaced with more descriptive temporary surfaces that are only active
when a transition is being rendered.

Currently, transitions between movies are temporarily disabled as well. This
will be fixed soon, once there is a window for the stage that exists
independently of the score.

Changed paths:
    engines/director/score.cpp
    engines/director/score.h
    engines/director/transitions.cpp


diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index 9086848c58..2db94a2f0d 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -115,8 +115,6 @@ Score::Score(DirectorEngine *vm) {
 	_vm = vm;
 	_surface = nullptr;
 	_maskSurface = nullptr;
-	_backSurface = nullptr;
-	_backSurface2 = nullptr;
 	_lingo = _vm->getLingo();
 	_lingoArchive = kArchMain;
 	_soundManager = _vm->getSoundManager();
@@ -167,14 +165,6 @@ Score::~Score() {
 	if (_maskSurface && _maskSurface->w)
 		_maskSurface->free();
 
-	if (_backSurface && _backSurface->w)
-		_backSurface->free();
-
-	if (_backSurface2 && _backSurface2->w)
-		_backSurface2->free();
-
-	delete _backSurface;
-	delete _backSurface2;
 	delete _maskSurface;
 
 	if (_window)
@@ -374,27 +364,10 @@ void Score::startLoop() {
 	initGraphics(_movieRect.width(), _movieRect.height());
 
 	_surface = _window->getWindowSurface();
-	_maskSurface = new Graphics::ManagedSurface;
-	_backSurface = new Graphics::ManagedSurface;
-	_backSurface2 = new Graphics::ManagedSurface;
+	_vm->_wm->setScreen(_surface);
 
+	_maskSurface = new Graphics::ManagedSurface;
 	_maskSurface->create(_movieRect.width(), _movieRect.height());
-	_backSurface->create(_movieRect.width(), _movieRect.height());
-	_backSurface2->create(_movieRect.width(), _movieRect.height());
-
-	if (_vm->_backSurface.w > 0) {
-		// Persist screen between the movies
-		// TODO: this is a workaround until the rendering pipeline is reworked
-
-		_backSurface2->copyFrom(g_director->_backSurface);
-		_surface->copyFrom(g_director->_backSurface);
-
-		_vm->_backSurface.free();
-	}
-
-	_vm->_backSurface.create(_movieRect.width(), _movieRect.height());
-
-	_vm->_wm->setScreen(_surface);
 
 	_surface->clear(_stageColor);
 
@@ -504,10 +477,6 @@ void Score::update() {
 	}
 
 	debugC(1, kDebugImages, "******************************  Current frame: %d", _currentFrame);
-
-	if (_frames[_currentFrame]->_transType != 0 && !_vm->_newMovieStarted)	// Store screen, so we could draw a nice transition
-		_backSurface2->copyFrom(*_surface);
-
 	_vm->_newMovieStarted = false;
 
 	_lingo->executeImmediateScripts(_frames[_currentFrame]);
@@ -563,29 +532,31 @@ void Score::update() {
 		_nextFrameTime += 1000;
 }
 
-void Score::renderFrame(uint16 frameId,  RenderMode mode) {
+void Score::renderFrame(uint16 frameId, RenderMode mode) {
 	Frame *currentFrame = _frames[frameId];
 
-	renderSprites(frameId, _surface, mode);
-	if (mode != kRenderUpdateStageOnly) {
-		_vm->_wm->renderZoomBox();
+	// When a transition is played, the next frame is rendered as a part of it.
+	if (currentFrame->_transType != 0 && mode != kRenderUpdateStageOnly) {
+		// TODO Handle changing area case
+		playTransition(currentFrame->_transDuration, currentFrame->_transArea, currentFrame->_transChunkSize, currentFrame->_transType);
+	} else {
+		renderSprites(frameId, _surface, mode);
+	}
 
+		_vm->_wm->renderZoomBox();
 		_vm->_wm->draw();
 
-		if (currentFrame->_transType != 0) {
-			// TODO Handle changing area case
-			playTransition(currentFrame->_transDuration, currentFrame->_transArea, currentFrame->_transChunkSize, currentFrame->_transType);
-		}
-
-		if (currentFrame->_sound1 != 0 || currentFrame->_sound2 != 0) {
+		if (currentFrame->_sound1 != 0 || currentFrame->_sound2 != 0)
 			playSoundChannel(frameId);
-		}
-	}
 
-	g_system->copyRectToScreen(_surface->getPixels(), _surface->pitch, 0, 0, _surface->getBounds().width(), _surface->getBounds().height());
+		g_system->copyRectToScreen(_surface->getPixels(), _surface->pitch, 0, 0, _surface->getBounds().width(), _surface->getBounds().height());
 }
 
 void Score::renderSprites(uint16 frameId, Graphics::ManagedSurface *surface, RenderMode mode) {
+	// HACK: Determine a batter way to do this.
+	if (mode == kRenderNoUnrender)
+		_maskSurface->clear(1);
+
 	for (uint16 i = 0; i < _channels.size(); i++) {
 		Channel *channel = _channels[i];
 		Sprite *currentSprite = channel->_sprite;
@@ -623,7 +594,8 @@ void Score::renderSprites(uint16 frameId, Graphics::ManagedSurface *surface, Ren
 		channel->updateLocation();
 
 		// TODO: Understand why conditioning this causes so many problems
-		markDirtyRect(channel->getBbox());
+		if (mode != kRenderNoUnrender)
+			markDirtyRect(channel->getBbox());
 	}
 
 	for (uint id = 0; id < _channels.size(); id++) {
diff --git a/engines/director/score.h b/engines/director/score.h
index 335471a48b..2b50328bbe 100644
--- a/engines/director/score.h
+++ b/engines/director/score.h
@@ -171,10 +171,10 @@ private:
 
 	// transitions.cpp
 	void initTransParams(TransParams &t, Common::Rect &clipRect);
-	void dissolveTrans(TransParams &t, Common::Rect &clipRect);
-	void dissolvePatternsTrans(TransParams &t, Common::Rect &clipRect);
-	void transMultiPass(TransParams &t, Common::Rect &clipRect);
-	void transZoom(TransParams &t, Common::Rect &clipRect);
+	void dissolveTrans(TransParams &t, Common::Rect &clipRect, Graphics::ManagedSurface *tmpSurface);
+	void dissolvePatternsTrans(TransParams &t, Common::Rect &clipRect, Graphics::ManagedSurface *tmpSurface);
+	void transMultiPass(TransParams &t, Common::Rect &clipRect, Graphics::ManagedSurface *tmpSurface);
+	void transZoom(TransParams &t, Common::Rect &clipRect, Graphics::ManagedSurface *tmpSurface);
 
 	// score.cpp
 	void playSoundChannel(uint16 frameId);
diff --git a/engines/director/transitions.cpp b/engines/director/transitions.cpp
index 419827e556..922b17b9e0 100644
--- a/engines/director/transitions.cpp
+++ b/engines/director/transitions.cpp
@@ -134,10 +134,6 @@ struct {
 void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChunkSize, TransitionType transType) {
 	// Play a transition and return the number of subframes rendered
 
-	// HACK: Prevent the tests from crashing
-	if (!_backSurface || !_backSurface2)
-		return;
-
 	TransParams t;
 
 	t.type = transType;
@@ -149,6 +145,15 @@ void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChu
 	if (debugChannelSet(-1, kDebugFast))
 		t.duration = 250;
 
+	// Cache a copy of the frame before the transition.
+	Graphics::ManagedSurface *currentFrame = new Graphics::ManagedSurface(_movieRect.width(), _movieRect.height());
+	currentFrame->copyFrom(*_surface);
+
+	// If a transition is being played, render the frame after the transition.
+	Graphics::ManagedSurface *nextFrame = new Graphics::ManagedSurface(_movieRect.width(), _movieRect.height());
+	nextFrame->clear(_stageColor);
+	renderSprites(_currentFrame, nextFrame, kRenderNoUnrender);
+
 	if (t.area)
 		warning("STUB: Transition over changed area transition");
 
@@ -165,50 +170,50 @@ void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChu
 	switch (transProps[t.type].algo) {
 	case kTransAlgoDissolve:
 		if (t.type == kTransDissolvePatterns)
-			dissolvePatternsTrans(t, clipRect);
+			dissolvePatternsTrans(t, clipRect, nextFrame);
 		else
-			dissolveTrans(t, clipRect);
+			dissolveTrans(t, clipRect, nextFrame);
 		return;
 
 	case kTransAlgoChecker:
 	case kTransAlgoStrips:
 	case kTransAlgoBlinds:
-		transMultiPass(t, clipRect);
+		transMultiPass(t, clipRect, nextFrame);
 		return;
 
 	case kTransAlgoZoom:
-		transZoom(t, clipRect);
+		transZoom(t, clipRect, nextFrame);
 		return;
 
 	case kTransAlgoCenterOut:
 	case kTransAlgoCover:
 	case kTransAlgoWipe:
-		blitFrom = _surface;
+		blitFrom = nextFrame;
 		break;
 
 	case kTransAlgoEdgesIn:
 	case kTransAlgoReveal:
 	case kTransAlgoPush:
-		blitFrom = _backSurface2;
+		blitFrom = currentFrame;
 		fullredraw = true;
 		break;
 
 	default:
-		blitFrom = _surface;
+		blitFrom = currentFrame;
 		break;
 	}
 
 	uint w = clipRect.width();
 	uint h = clipRect.height();
 
-	for (uint16 i = 1; i < t.steps; i++) {
+	for (uint16 i = 1; i < t.steps + 1; i++) {
 		bool stop = false;
 		rto = clipRect;
 		rfrom = clipRect;
 
 		if (transProps[t.type].algo == kTransAlgoReveal ||
 				transProps[t.type].algo == kTransAlgoEdgesIn) {
-			_backSurface->copyFrom(*_surface);
+			_surface->copyFrom(*nextFrame);
 		}
 
 		switch (t.type) {
@@ -278,7 +283,7 @@ void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChu
 
 		case kTransPushLeft:								// 11
 			rto.moveTo(w - t.xStepSize * i, 0);
-			_backSurface->blitFrom(*_surface, rfrom, Common::Point(rto.left, rto.top));
+			_surface->blitFrom(*nextFrame, rfrom, Common::Point(rto.left, rto.top));
 
 			rfrom.moveTo(t.xStepSize * i, 0);
 			rfrom.setWidth(w - t.xStepSize * i);
@@ -288,7 +293,7 @@ void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChu
 		case kTransPushRight:								// 12
 			rfrom.moveTo(w - t.xStepSize * i, 0);
 			rfrom.setWidth(t.xStepSize * i);
-			_backSurface->blitFrom(*_surface, rfrom, Common::Point(rto.left, rto.top));
+			_surface->blitFrom(*nextFrame, rfrom, Common::Point(rto.left, rto.top));
 
 			rto.setWidth(w - t.xStepSize * i);
 			rto.moveTo(t.xStepSize * i, 0);
@@ -299,7 +304,7 @@ void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChu
 		case kTransPushDown:								// 13
 			rfrom.moveTo(0, h - t.yStepSize * i);
 			rfrom.setHeight(t.yStepSize * i);
-			_backSurface->blitFrom(*_surface, rfrom, Common::Point(rto.left, rto.top));
+			_surface->blitFrom(*nextFrame, rfrom, Common::Point(rto.left, rto.top));
 
 			rto.setHeight(h - t.yStepSize * i);
 			rto.moveTo(0, t.yStepSize * i);
@@ -309,7 +314,7 @@ void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChu
 
 		case kTransPushUp:									// 14
 			rto.moveTo(0, h - t.yStepSize * i);
-			_backSurface->blitFrom(*_surface, rfrom, Common::Point(rto.left, rto.top));
+			_backSurface->blitFrom(*nextFrame, rfrom, Common::Point(rto.left, rto.top));
 
 			rfrom.moveTo(0, t.yStepSize * i);
 			rfrom.setHeight(h - t.yStepSize * i);
@@ -427,19 +432,19 @@ void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChu
 		if (stop)
 			break;
 
-		_backSurface->blitFrom(*blitFrom, rfrom, Common::Point(rto.left, rto.top));
+		_surface->blitFrom(*blitFrom, rfrom, Common::Point(rto.left, rto.top));
 
 		g_system->delayMillis(t.stepDuration);
 		if (processQuitEvent(true))
 			break;
 
 		if (fullredraw) {
-			g_system->copyRectToScreen(_backSurface->getPixels(), _backSurface->pitch, 0, 0, w, h);
+			g_system->copyRectToScreen(_surface->getPixels(), _surface->pitch, 0, 0, w, h);
 		} else {
 			rto.clip(clipRect);
 
 			if (rto.height() > 0 && rto.width() > 0) {
-				g_system->copyRectToScreen(_backSurface->getBasePtr(rto.left, rto.top), _backSurface->pitch, rto.left, rto.top, rto.width(), rto.height());
+				g_system->copyRectToScreen(_surface->getBasePtr(rto.left, rto.top), _surface->pitch, rto.left, rto.top, rto.width(), rto.height());
 			}
 		}
 
@@ -447,6 +452,9 @@ void Score::playTransition(uint16 transDuration, uint8 transArea, uint8 transChu
 
 		g_lingo->executePerFrameHook(_currentFrame, i);
 	}
+
+	delete currentFrame;
+	delete nextFrame;
 }
 
 static int getLog2(int n) {
@@ -470,7 +478,7 @@ static uint32 randomSeed[33] = {
 	0x14000000UL, 0x32800000UL, 0x48000000UL, 0xa3000000UL
 };
 
-void Score::dissolveTrans(TransParams &t, Common::Rect &clipRect) {
+void Score::dissolveTrans(TransParams &t, Common::Rect &clipRect, Graphics::ManagedSurface *nextFrame) {
 	uint w = clipRect.width();
 	uint h = clipRect.height();
 	uint realw = w, realh = h;
@@ -552,9 +560,6 @@ void Score::dissolveTrans(TransParams &t, Common::Rect &clipRect) {
 	if (hBits <= 0 || vBits <= 0)
 		return;
 
-	// Get previous frame
-	_backSurface->copyFrom(*_backSurface2);
-
 	rnd = seed = randomSeed[hBits + vBits];
 	int hMask = (1L << hBits) - 1;
 	int vShift = hBits;
@@ -595,14 +600,14 @@ void Score::dissolveTrans(TransParams &t, Common::Rect &clipRect) {
 					if (x < realw && y < realh) {
 						r.moveTo(x, y);
 						r.clip(clipRect);
-						_backSurface->copyRectToSurface(*_surface, x, y, r);
+						_surface->copyRectToSurface(*nextFrame, x, y, r);
 					}
 				} else {
 					mask = pixmask[x % -t.xStepSize];
 					x = x / -t.xStepSize;
 
-					byte *color1 = (byte *)_backSurface->getBasePtr(x, y);
-					byte *color2 = (byte *)_surface->getBasePtr(x, y);
+					byte *color1 = (byte *)_surface->getBasePtr(x, y);
+					byte *color2 = (byte *)nextFrame->getBasePtr(x, y);
 
 					*color1 = ((*color1 & ~mask) | (*color2 & mask)) & 0xff;
 				}
@@ -617,7 +622,7 @@ void Score::dissolveTrans(TransParams &t, Common::Rect &clipRect) {
 			}
 		} while (rnd != seed);
 
-		g_system->copyRectToScreen(_backSurface->getPixels(), _backSurface->pitch, 0, 0, realw, realh);
+		g_system->copyRectToScreen(_surface->getPixels(), _surface->pitch, 0, 0, realw, realh);
 		g_system->updateScreen();
 
 		g_lingo->executePerFrameHook(_currentFrame, i + 1);
@@ -696,21 +701,18 @@ static byte dissolvePatterns[][8] = {
 	{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
 };
 
-void Score::dissolvePatternsTrans(TransParams &t, Common::Rect &clipRect) {
+void Score::dissolvePatternsTrans(TransParams &t, Common::Rect &clipRect, Graphics::ManagedSurface *nextFrame) {
 	uint w = clipRect.width();
 	uint h = clipRect.height();
 
-	// Get previous frame
-	_backSurface->copyFrom(*_backSurface2);
-
 	t.steps = 64;
 	t.stepDuration = t.duration / t.steps;
 
 	for (int i = 0; i < t.steps; i++) {
 		for (uint y = 0; y < h; y++) {
 			byte pat = dissolvePatterns[i][y % 8];
-			byte *dst = (byte *)_backSurface->getBasePtr(0, y);
-			byte *src = (byte *)_surface->getBasePtr(0, y);
+			byte *dst = (byte *)_surface->getBasePtr(0, y);
+			byte *src = (byte *)nextFrame->getBasePtr(0, y);
 
 			for (uint x = 0; x < w;) {
 				byte mask = 0x80;
@@ -725,7 +727,7 @@ void Score::dissolvePatternsTrans(TransParams &t, Common::Rect &clipRect) {
 			}
 		}
 
-		g_system->copyRectToScreen(_backSurface->getPixels(), _backSurface->pitch, 0, 0, w, h);
+		g_system->copyRectToScreen(_surface->getPixels(), _surface->pitch, 0, 0, w, h);
 		g_system->updateScreen();
 
 		g_lingo->executePerFrameHook(_currentFrame, i + 1);
@@ -737,7 +739,7 @@ void Score::dissolvePatternsTrans(TransParams &t, Common::Rect &clipRect) {
 	}
 }
 
-void Score::transMultiPass(TransParams &t, Common::Rect &clipRect) {
+void Score::transMultiPass(TransParams &t, Common::Rect &clipRect, Graphics::ManagedSurface *nextFrame) {
 	Common::Rect rto;
 	uint w = clipRect.width();
 	uint h = clipRect.height();
@@ -892,8 +894,8 @@ void Score::transMultiPass(TransParams &t, Common::Rect &clipRect) {
 			rto.clip(clipRect);
 
 			if (rto.height() > 0 && rto.width() > 0) {
-				_backSurface->blitFrom(*_surface, rto, Common::Point(rto.left, rto.top));
-				g_system->copyRectToScreen(_backSurface->getBasePtr(rto.left, rto.top), _backSurface->pitch, rto.left, rto.top, rto.width(), rto.height());
+				_surface->blitFrom(*nextFrame, rto, Common::Point(rto.left, rto.top));
+				g_system->copyRectToScreen(_surface->getBasePtr(rto.left, rto.top), _surface->pitch, rto.left, rto.top, rto.width(), rto.height());
 			}
 		}
 		rects.clear();
@@ -909,17 +911,16 @@ void Score::transMultiPass(TransParams &t, Common::Rect &clipRect) {
 	}
 }
 
-void Score::transZoom(TransParams &t, Common::Rect &clipRect) {
+void Score::transZoom(TransParams &t, Common::Rect &clipRect, Graphics::ManagedSurface *nextFrame) {
 	Common::Rect r = clipRect;
 	uint w = clipRect.width();
 	uint h = clipRect.height();
 
 	t.steps += 2;
 
-	Graphics::MacPlotData pd(_backSurface, nullptr, &g_director->_wm->getPatterns(), Graphics::kPatternCheckers, 0, 0, 1, 0);
+	Graphics::MacPlotData pd(_surface, nullptr, &g_director->_wm->getPatterns(), Graphics::kPatternCheckers, 0, 0, 1, 0);
 
 	for (uint16 i = 1; i < t.steps; i++) {
-		_backSurface->copyFrom(*_backSurface2);
 
 		for (int s = 2; s >= 0; s--) {
 			if (i - s < 0 || i - s > t.steps - 2)
@@ -945,7 +946,7 @@ void Score::transZoom(TransParams &t, Common::Rect &clipRect) {
 		r.setWidth(t.xStepSize * i * 2);
 		r.moveTo(w / 2 - t.xStepSize * i, h / 2 - t.yStepSize * i);
 
-		g_system->copyRectToScreen(_backSurface->getPixels(), _backSurface->pitch, 0, 0, w, h);
+		g_system->copyRectToScreen(_surface->getPixels(), _surface->pitch, 0, 0, w, h);
 		g_system->updateScreen();
 
 		g_lingo->executePerFrameHook(_currentFrame, i);




More information about the Scummvm-git-logs mailing list