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

dreammaster dreammaster at scummvm.org
Sat Apr 1 02:13:49 CEST 2017


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:
f436382fe4 TITANIC: Merge fader classes into one, video surface setup fix


Commit: f436382fe42dd8c96ea9cab80afd2d062e4d8a83
    https://github.com/scummvm/scummvm/commit/f436382fe42dd8c96ea9cab80afd2d062e4d8a83
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-03-31T20:13:42-04:00

Commit Message:
TITANIC: Merge fader classes into one, video surface setup fix

Changed paths:
    engines/titanic/star_control/star_view.cpp
    engines/titanic/star_control/surface_fader.cpp
    engines/titanic/star_control/surface_fader.h


diff --git a/engines/titanic/star_control/star_view.cpp b/engines/titanic/star_control/star_view.cpp
index 60c02b1..92f64c4 100644
--- a/engines/titanic/star_control/star_view.cpp
+++ b/engines/titanic/star_control/star_view.cpp
@@ -81,7 +81,7 @@ void CStarView::draw(CScreenManager *screenManager) {
 
 	if (_fader.isActive()) {
 		CVideoSurface *surface = _showingPhoto ? _videoSurface2 : _videoSurface;
-		surface = _fader.fade(screenManager, surface);
+		surface = _fader.draw(screenManager, surface);
 		screenManager->blitFrom(SURFACE_PRIMARY, surface);
 	} else {
 		Point destPos(20, 10);
diff --git a/engines/titanic/star_control/surface_fader.cpp b/engines/titanic/star_control/surface_fader.cpp
index 79129d9..7cc39dc 100644
--- a/engines/titanic/star_control/surface_fader.cpp
+++ b/engines/titanic/star_control/surface_fader.cpp
@@ -27,19 +27,24 @@
 namespace Titanic {
 
 
-CSurfaceFaderBase::CSurfaceFaderBase() : _index(-1), _count(32),
-		_videoSurface(nullptr) {
+CSurfaceFader::CSurfaceFader() : _index(-1), _count(32), _fadeIn(false), _videoSurface(nullptr) {
+	_dataP = new byte[_count];
+
+	for (int idx = 0; idx < _count; ++idx)
+		_dataP[idx] = (byte)(pow((double)idx / (double)_count, 1.299999952316284)
+			* (double)_count + 0.5);
 }
 
-CSurfaceFaderBase::~CSurfaceFaderBase() {
+CSurfaceFader::~CSurfaceFader() {
 	delete _videoSurface;
+	delete[] _dataP;
 }
 
-void CSurfaceFaderBase::reset() {
+void CSurfaceFader::reset() {
 	_index = 0;
 }
 
-bool CSurfaceFaderBase::setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface) {
+bool CSurfaceFader::setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface) {
 	int width = srcSurface->getWidth();
 	int height = srcSurface->getHeight();
 
@@ -56,38 +61,21 @@ bool CSurfaceFaderBase::setupSurface(CScreenManager *screenManager, CVideoSurfac
 	return true;
 }
 
-/*------------------------------------------------------------------------*/
-
-CSurfaceFader::CSurfaceFader() : CSurfaceFaderBase() {
-	_dataP = new byte[_count];
-
-	for (int idx = 0; idx < _count; ++idx)
-		_dataP[idx] = (byte)(pow((double)idx / (double)_count, 1.299999952316284)
-			* (double)_count + 0.5);
-}
-
-CSurfaceFader::~CSurfaceFader() {
-	delete[] _dataP;
-}
-
-void CSurfaceFader::setFadeIn(bool fadeIn) {
-	_fadeIn = fadeIn;
-}
-
-CVideoSurface *CSurfaceFader::fade(CScreenManager *screenManager, CVideoSurface *srcSurface) {
+CVideoSurface *CSurfaceFader::draw(CScreenManager *screenManager, CVideoSurface *srcSurface) {
 	if (_index == -1 || _index >= _count)
 		return srcSurface;
 
-	if (!_count && !setupSurface(screenManager, srcSurface))
+	// On the first iteration, set up a temporary surface
+	if (_index == 0 && !setupSurface(screenManager, srcSurface))
 		return nullptr;
 
 	srcSurface->lock();
 	_videoSurface->lock();
-	CSurfaceArea srCSurfaceArea(srcSurface);
-	CSurfaceArea destSurfaceObj(_videoSurface);
+	CSurfaceArea srcSurfaceArea(srcSurface);
+	CSurfaceArea destSurfaceArea(_videoSurface);
 
 	// Copy the surface with fading
-	copySurface(srCSurfaceArea, destSurfaceObj);
+	step(srcSurfaceArea, destSurfaceArea);
 
 	srcSurface->unlock();
 	_videoSurface->unlock();
@@ -96,7 +84,7 @@ CVideoSurface *CSurfaceFader::fade(CScreenManager *screenManager, CVideoSurface
 	return _videoSurface;
 }
 
-void CSurfaceFader::copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface) {
+void CSurfaceFader::step(CSurfaceArea &srcSurface, CSurfaceArea &destSurface) {
 	const uint16 *srcPixelP = (const uint16 *)srcSurface._pixelsPtr;
 	uint16 *destPixelP = (uint16 *)destSurface._pixelsPtr;
 
@@ -124,4 +112,8 @@ void CSurfaceFader::copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurf
 	}
 }
 
+void CSurfaceFader::setFadeIn(bool fadeIn) {
+	_fadeIn = fadeIn;
+}
+
 } // End of namespace Titanic
diff --git a/engines/titanic/star_control/surface_fader.h b/engines/titanic/star_control/surface_fader.h
index d861186..f562197 100644
--- a/engines/titanic/star_control/surface_fader.h
+++ b/engines/titanic/star_control/surface_fader.h
@@ -29,8 +29,16 @@
 
 namespace Titanic {
 
-class CSurfaceFaderBase {
-protected:
+class CSurfaceFader {
+private:
+	byte *_dataP;
+	bool _fadeIn;
+private:
+	/**
+	 * Create a faded version of the source surface for the new step
+	 */
+	void step(CSurfaceArea &srcSurface, CSurfaceArea &destSurface);
+
 	/**
 	 * Sets up an internal surface to match the size of the specified one
 	 */
@@ -40,49 +48,29 @@ public:
 	int _count;
 	CVideoSurface *_videoSurface;
 public:
-	CSurfaceFaderBase();
-	virtual ~CSurfaceFaderBase();
+	CSurfaceFader();
+	~CSurfaceFader();
 
 	/**
 	 * Reset fading back to the start
 	 */
-	virtual void reset();
+	void reset();
 
 	/**
 	 * Creates a faded version of the passed source surface, based on a percentage
 	 * visibility specified by _index of _count
 	 */
-	virtual CVideoSurface *fade(CScreenManager *screenManager, CVideoSurface *srcSurface) = 0;
+	CVideoSurface *draw(CScreenManager *screenManager, CVideoSurface *srcSurface);
 
 	/**
-	 * Returns true if a fade is in progress
-	 */
-	bool isActive() const { return _index != -1 && _index < _count; }
-};
-
-class CSurfaceFader: public CSurfaceFaderBase {
-private:
-	byte *_dataP;
-	bool _fadeIn;
-private:
-	/**
-	 * Create a faded version of the source surface at the given dest
-	 */
-	void copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface);
-public:
-	CSurfaceFader();
-	virtual ~CSurfaceFader();
-
-	/**
-	 * Creates a faded version of the passed source surface, based on a percentage
-	 * visibility specified by _index of _count
+	 * Sets whether a fade in (versus a fade out) should be done
 	 */
-	virtual CVideoSurface *fade(CScreenManager *screenManager, CVideoSurface *srcSurface);
+	void setFadeIn(bool fadeIn);
 
 	/**
-	 * Sets whether a fade in (versus a fade out) should be done
+	 * Returns true if a fade is in progress
 	 */
-	void setFadeIn(bool fadeIn);
+	bool isActive() const { return _index != -1 && _index < _count; }
 };
 
 } // End of namespace Titanic





More information about the Scummvm-git-logs mailing list