TITANIC: Finish and better name fader classes

This commit is contained in:
Paul Gilbert 2016-07-02 16:11:19 -04:00
parent ed2a716790
commit 79b4754b33
9 changed files with 135 additions and 74 deletions

View File

@ -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 \

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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 */

View File

@ -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

View File

@ -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 */