aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2017-03-31 20:13:42 -0400
committerPaul Gilbert2017-03-31 20:13:42 -0400
commitf436382fe42dd8c96ea9cab80afd2d062e4d8a83 (patch)
treee7bbd303bd0b1038b2ac42d4e166409e09209cc9
parent33bcc9d058e40f250c0e82686c288d6e98db53e3 (diff)
downloadscummvm-rg350-f436382fe42dd8c96ea9cab80afd2d062e4d8a83.tar.gz
scummvm-rg350-f436382fe42dd8c96ea9cab80afd2d062e4d8a83.tar.bz2
scummvm-rg350-f436382fe42dd8c96ea9cab80afd2d062e4d8a83.zip
TITANIC: Merge fader classes into one, video surface setup fix
-rw-r--r--engines/titanic/star_control/star_view.cpp2
-rw-r--r--engines/titanic/star_control/surface_fader.cpp50
-rw-r--r--engines/titanic/star_control/surface_fader.h48
3 files changed, 40 insertions, 60 deletions
diff --git a/engines/titanic/star_control/star_view.cpp b/engines/titanic/star_control/star_view.cpp
index 60c02b1af8..92f64c46c5 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 79129d9732..7cc39dc429 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 d861186dc5..f562197f15 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