diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index 71df87d9cf1..79f55d4413a 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -433,7 +433,9 @@ MODULE_OBJS := \ star_control/star_control_sub14.o \ star_control/star_control_sub15.o \ star_control/star_control_sub16.o \ - star_control/surface_obj.o \ + star_control/surface_area.o \ + star_control/surface_fader_base.o \ + star_control/surface_fader.o \ support/direct_draw.o \ support/direct_draw_surface.o \ support/exe_resources.o \ 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 07ed80ccc5e..00000000000 --- 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 47d138a0dc2..d625d9bf0fd 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 similarity index 91% rename from engines/titanic/star_control/surface_obj.cpp rename to engines/titanic/star_control/surface_area.cpp index 93f46e5ad4f..77f8222dad1 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 similarity index 96% rename from engines/titanic/star_control/surface_obj.h rename to engines/titanic/star_control/surface_area.h index 518f85b5025..4d1913123c9 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 00000000000..089ad517171 --- /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 similarity index 65% rename from engines/titanic/star_control/star_control_sub15.h rename to engines/titanic/star_control/surface_fader.h index 0e0d2e41c0b..650cbbb19b3 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 similarity index 70% rename from engines/titanic/star_control/star_control_sub16.cpp rename to engines/titanic/star_control/surface_fader_base.cpp index 1465ac6a3eb..dfd7c4ab1d0 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 similarity index 67% rename from engines/titanic/star_control/star_control_sub16.h rename to engines/titanic/star_control/surface_fader_base.h index 64e463ca5bd..ead4460521e 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 */