aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/star_control
diff options
context:
space:
mode:
authorPaul Gilbert2016-07-02 16:11:19 -0400
committerPaul Gilbert2016-07-15 19:26:21 -0400
commit79b4754b3318c21479dfccaf91dcf09fabf23fd4 (patch)
tree1eea4ac019a1d08b0bb8a7a84039787389a1421b /engines/titanic/star_control
parented2a716790255c93a75db3570de0d821978cfe68 (diff)
downloadscummvm-rg350-79b4754b3318c21479dfccaf91dcf09fabf23fd4.tar.gz
scummvm-rg350-79b4754b3318c21479dfccaf91dcf09fabf23fd4.tar.bz2
scummvm-rg350-79b4754b3318c21479dfccaf91dcf09fabf23fd4.zip
TITANIC: Finish and better name fader classes
Diffstat (limited to 'engines/titanic/star_control')
-rw-r--r--engines/titanic/star_control/star_control_sub15.cpp31
-rw-r--r--engines/titanic/star_control/star_view.h4
-rw-r--r--engines/titanic/star_control/surface_area.cpp (renamed from engines/titanic/star_control/surface_obj.cpp)6
-rw-r--r--engines/titanic/star_control/surface_area.h (renamed from engines/titanic/star_control/surface_obj.h)4
-rw-r--r--engines/titanic/star_control/surface_fader.cpp73
-rw-r--r--engines/titanic/star_control/surface_fader.h (renamed from engines/titanic/star_control/star_control_sub15.h)30
-rw-r--r--engines/titanic/star_control/surface_fader_base.cpp (renamed from engines/titanic/star_control/star_control_sub16.cpp)30
-rw-r--r--engines/titanic/star_control/surface_fader_base.h (renamed from engines/titanic/star_control/star_control_sub16.h)27
8 files changed, 132 insertions, 73 deletions
diff --git a/engines/titanic/star_control/star_control_sub15.cpp b/engines/titanic/star_control/star_control_sub15.cpp
deleted file mode 100644
index 07ed80ccc5..0000000000
--- a/engines/titanic/star_control/star_control_sub15.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "titanic/star_control/star_control_sub15.h"
-
-namespace Titanic {
-
-CStarControlSub15::CStarControlSub15() : _field4(-1),
- _field8(32), _fieldC(0), _field10(0), _field14(0) {
-}
-
-} // End of namespace Titanic
diff --git a/engines/titanic/star_control/star_view.h b/engines/titanic/star_control/star_view.h
index 47d138a0dc..d625d9bf0f 100644
--- a/engines/titanic/star_control/star_view.h
+++ b/engines/titanic/star_control/star_view.h
@@ -27,7 +27,7 @@
#include "titanic/support/video_surface.h"
#include "titanic/star_control/star_control_sub12.h"
#include "titanic/star_control/star_control_sub13.h"
-#include "titanic/star_control/star_control_sub15.h"
+#include "titanic/star_control/surface_fader.h"
namespace Titanic {
@@ -39,7 +39,7 @@ private:
CStarControlSub12 _sub12;
int _field118;
CStarControlSub13 _sub13;
- CStarControlSub15 _sub15;
+ CSurfaceFader _fader;
int _field20C;
int _field210;
int _field214;
diff --git a/engines/titanic/star_control/surface_obj.cpp b/engines/titanic/star_control/surface_area.cpp
index 93f46e5ad4..77f8222dad 100644
--- a/engines/titanic/star_control/surface_obj.cpp
+++ b/engines/titanic/star_control/surface_area.cpp
@@ -20,11 +20,11 @@
*
*/
-#include "titanic/star_control/surface_obj.h"
+#include "titanic/star_control/surface_area.h"
namespace Titanic {
-CSurfaceObj::CSurfaceObj(CVideoSurface *surface) {
+CSurfaceArea::CSurfaceArea(CVideoSurface *surface) {
_width = surface->getWidth();
_height = surface->getHeight();
_pitch = surface->getPitch();
@@ -37,7 +37,7 @@ CSurfaceObj::CSurfaceObj(CVideoSurface *surface) {
initialize();
}
-void CSurfaceObj::initialize() {
+void CSurfaceArea::initialize() {
_bounds = Rect(0, 0, _width - 1, _height - 1);
_centroid = Point(_width / 2, _height / 2);
_field22 = _field21 = _field20 = 0xFF;
diff --git a/engines/titanic/star_control/surface_obj.h b/engines/titanic/star_control/surface_area.h
index 518f85b502..4d1913123c 100644
--- a/engines/titanic/star_control/surface_obj.h
+++ b/engines/titanic/star_control/surface_area.h
@@ -28,7 +28,7 @@
namespace Titanic {
-class CSurfaceObj {
+class CSurfaceArea {
private:
/**
* Initialize data for the class
@@ -57,7 +57,7 @@ public:
int _field38;
Rect _bounds;
public:
- CSurfaceObj(CVideoSurface *surface);
+ CSurfaceArea(CVideoSurface *surface);
};
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/surface_fader.cpp b/engines/titanic/star_control/surface_fader.cpp
new file mode 100644
index 0000000000..089ad51717
--- /dev/null
+++ b/engines/titanic/star_control/surface_fader.cpp
@@ -0,0 +1,73 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/star_control/surface_fader.h"
+#include "common/system.h"
+#include "graphics/pixelformat.h"
+
+namespace Titanic {
+
+CSurfaceFader::CSurfaceFader() : CSurfaceFaderBase() {
+ _dataP = new byte[_count];
+
+ for (int idx = 0; idx < _count; ++idx) {
+ // TODO: Setup data bytes
+ }
+}
+
+CSurfaceFader::~CSurfaceFader() {
+ delete[] _dataP;
+}
+
+void CSurfaceFader::copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface) {
+ const uint16 *srcPixelP = srcSurface._pixelsPtr;
+ uint16 *destPixelP = destSurface._pixelsPtr;
+
+ // Currently we only support 2 bytes per pixel surfaces
+ assert(srcSurface._bpp == 2);
+
+ byte dataVal = _dataP[_index];
+ double fraction = (double)dataVal / ((double)(_count - 1));
+ if (!_fadeIn)
+ // For fade outs, reverse the percentage visibility
+ fraction = 1.0 - fraction;
+
+ // Iterate through the pixels
+ byte r, g, b;
+ Graphics::PixelFormat format = g_system->getScreenFormat();
+
+ for (int yp = 0; yp < srcSurface._height; ++yp) {
+ for (int xp = 0; xp < srcSurface._width; ++xp, ++srcPixelP, ++destPixelP) {
+ format.colorToRGB(*srcPixelP, r, g, b);
+ r = (byte)((double)r * fraction);
+ g = (byte)((double)g * fraction);
+ b = (byte)((double)b * fraction);
+ *destPixelP = format.RGBToColor(r, g, b);
+ }
+ }
+}
+
+void CSurfaceFader::setFadeIn(bool fadeIn) {
+ _fadeIn = fadeIn;
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/star_control/star_control_sub15.h b/engines/titanic/star_control/surface_fader.h
index 0e0d2e41c0..650cbbb19b 100644
--- a/engines/titanic/star_control/star_control_sub15.h
+++ b/engines/titanic/star_control/surface_fader.h
@@ -20,24 +20,32 @@
*
*/
-#ifndef TITANIC_STAR_CONTROL_SUB15_H
-#define TITANIC_STAR_CONTROL_SUB15_H
+#ifndef TITANIC_SURFACE_FADER_H
+#define TITANIC_SURFACE_FADER_H
-#include "titanic/support/simple_file.h"
+#include "titanic/star_control/surface_fader_base.h"
namespace Titanic {
-class CStarControlSub15 {
+class CSurfaceFader: public CSurfaceFaderBase {
private:
- double _field4;
- double _field8;
- double _fieldC;
- double _field10;
- double _field14;
+ byte *_dataP;
+ bool _fadeIn;
+protected:
+ /**
+ * Create a faded version of the source surface at the given dest
+ */
+ virtual void copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface);
public:
- CStarControlSub15();
+ CSurfaceFader();
+ virtual ~CSurfaceFader();
+
+ /**
+ * Sets whether a fade in (versus a fade out) should be done
+ */
+ void setFadeIn(bool fadeIn);
};
} // End of namespace Titanic
-#endif /* TITANIC_STAR_CONTROL_SUB15_H */
+#endif /* TITANIC_SURFACE_SHADER_H */
diff --git a/engines/titanic/star_control/star_control_sub16.cpp b/engines/titanic/star_control/surface_fader_base.cpp
index 1465ac6a3e..dfd7c4ab1d 100644
--- a/engines/titanic/star_control/star_control_sub16.cpp
+++ b/engines/titanic/star_control/surface_fader_base.cpp
@@ -20,19 +20,23 @@
*
*/
-#include "titanic/star_control/star_control_sub16.h"
+#include "titanic/star_control/surface_fader_base.h"
namespace Titanic {
-CStarControlSub16::CStarControlSub16() : _field4(-1), _field8(32),
+CSurfaceFaderBase::CSurfaceFaderBase() : _index(-1), _count(32),
_videoSurface(nullptr) {
}
-void CStarControlSub16::reset() {
- _field4 = 0;
+CSurfaceFaderBase::~CSurfaceFaderBase() {
+ delete _videoSurface;
}
-bool CStarControlSub16::setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface) {
+void CSurfaceFaderBase::reset() {
+ _index = 0;
+}
+
+bool CSurfaceFaderBase::setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface) {
int width = srcSurface->getWidth();
int height = srcSurface->getHeight();
@@ -49,26 +53,26 @@ bool CStarControlSub16::setupSurface(CScreenManager *screenManager, CVideoSurfac
return true;
}
-CVideoSurface *CStarControlSub16::loadSurface(CScreenManager *screenManager, CVideoSurface *srcSurface) {
- if (_field4 < 0 || _field4 >= _field8)
+CVideoSurface *CSurfaceFaderBase::fade(CScreenManager *screenManager, CVideoSurface *srcSurface) {
+ if (_index == -1 || _index >= _count)
return srcSurface;
- if (!_field8 && !setupSurface(screenManager, srcSurface))
+ if (!_count && !setupSurface(screenManager, srcSurface))
return nullptr;
srcSurface->lock();
_videoSurface->lock();
- CSurfaceObj srcSurfaceObj(srcSurface);
- CSurfaceObj destSurfaceObj(_videoSurface);
+ CSurfaceArea srCSurfaceArea(srcSurface);
+ CSurfaceArea destSurfaceObj(_videoSurface);
- proc4(srcSurfaceObj, destSurfaceObj);
+ // Copy the surface with fading
+ copySurface(srCSurfaceArea, destSurfaceObj);
srcSurface->unlock();
_videoSurface->unlock();
- ++_field4;
+ ++_index;
return _videoSurface;
}
-
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/star_control_sub16.h b/engines/titanic/star_control/surface_fader_base.h
index 64e463ca5b..ead4460521 100644
--- a/engines/titanic/star_control/star_control_sub16.h
+++ b/engines/titanic/star_control/surface_fader_base.h
@@ -20,38 +20,43 @@
*
*/
-#ifndef TITANIC_STAR_CONTROL_SUB16_H
-#define TITANIC_STAR_CONTROL_SUB16_H
+#ifndef TITANIC_SURFACE_FADER_BASE_H
+#define TITANIC_SURFACE_FADER_BASE_H
#include "titanic/support/video_surface.h"
#include "titanic/support/screen_manager.h"
-#include "titanic/star_control/surface_obj.h"
+#include "titanic/star_control/surface_area.h"
namespace Titanic {
-class CStarControlSub16 {
+class CSurfaceFaderBase {
private:
/**
* Sets up an internal surface to match the size of the specified one
*/
bool setupSurface(CScreenManager *screenManager, CVideoSurface *srcSurface);
protected:
- int _field4;
- int _field8;
+ int _index;
+ int _count;
CVideoSurface *_videoSurface;
protected:
- virtual void proc4(CSurfaceObj &srcSurface, CSurfaceObj &destSurface) = 0;
+ /**
+ * Create a faded version of the source surface at the given dest
+ */
+ virtual void copySurface(CSurfaceArea &srcSurface, CSurfaceArea &destSurface) = 0;
public:
- CStarControlSub16();
+ CSurfaceFaderBase();
+ virtual ~CSurfaceFaderBase();
virtual void reset();
/**
- * Loads from a given source surface
+ * Creates a faded version of the passed source surface, based on a percentage
+ * visibility specified by _index of _count
*/
- virtual CVideoSurface *loadSurface(CScreenManager *screenManager, CVideoSurface *srcSurface);
+ virtual CVideoSurface *fade(CScreenManager *screenManager, CVideoSurface *srcSurface);
};
} // End of namespace Titanic
-#endif /* TITANIC_STAR_CONTROL_SUB16_H */
+#endif /* TITANIC_SURFACE_FADER_BASE_H */