diff options
author | Paul Gilbert | 2016-03-20 17:07:23 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-03-20 17:07:23 -0400 |
commit | 6ebb0312ffa87316e816c4ebc31e17564450d48e (patch) | |
tree | 7ae8b7fb335a117c0e7f36978f968d0df4a04540 | |
parent | 3c852cc240221785598023de56e5a71a0d8806fa (diff) | |
download | scummvm-rg350-6ebb0312ffa87316e816c4ebc31e17564450d48e.tar.gz scummvm-rg350-6ebb0312ffa87316e816c4ebc31e17564450d48e.tar.bz2 scummvm-rg350-6ebb0312ffa87316e816c4ebc31e17564450d48e.zip |
TITANIC: Refactor out DirectDrawSurface to it's own class
-rw-r--r-- | engines/titanic/direct_draw.cpp | 37 | ||||
-rw-r--r-- | engines/titanic/direct_draw.h | 35 | ||||
-rw-r--r-- | engines/titanic/direct_draw_surface.cpp | 87 | ||||
-rw-r--r-- | engines/titanic/direct_draw_surface.h | 110 | ||||
-rw-r--r-- | engines/titanic/module.mk | 1 | ||||
-rw-r--r-- | engines/titanic/pet_control/pet_control_sub12.cpp | 1 | ||||
-rw-r--r-- | engines/titanic/video_surface.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/video_surface.h | 2 |
8 files changed, 207 insertions, 72 deletions
diff --git a/engines/titanic/direct_draw.cpp b/engines/titanic/direct_draw.cpp index 551be5b87e..79ca968f8d 100644 --- a/engines/titanic/direct_draw.cpp +++ b/engines/titanic/direct_draw.cpp @@ -48,9 +48,7 @@ void DirectDraw::diagnostics() { DirectDrawSurface *DirectDraw::createSurfaceFromDesc(const DDSurfaceDesc &desc) { DirectDrawSurface *surface = new DirectDrawSurface(); - - Graphics::PixelFormat pixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); - surface->create(desc._w, desc._h, pixelFormat); + surface->create(desc._w, desc._h); return surface; } @@ -95,11 +93,9 @@ void DirectDrawManager::initFullScreen() { _directDraw._bpp, 0); _mainSurface = new DirectDrawSurface(); - _mainSurface->create(_directDraw._width, _directDraw._height, - Graphics::PixelFormat::createFormatCLUT8()); + _mainSurface->create(_directDraw._width, _directDraw._height); _backSurfaces[0] = new DirectDrawSurface(); - _backSurfaces[0]->create(_directDraw._width, _directDraw._height, - Graphics::PixelFormat::createFormatCLUT8()); + _backSurfaces[0]->create(_directDraw._width, _directDraw._height); } DirectDrawSurface *DirectDrawManager::createSurface(int w, int h, int surfaceNum) { @@ -110,31 +106,4 @@ DirectDrawSurface *DirectDrawManager::createSurface(int w, int h, int surfaceNum return _directDraw.createSurfaceFromDesc(DDSurfaceDesc(w, h)); } -/*------------------------------------------------------------------------*/ - -Graphics::Surface *DirectDrawSurface::lock(const Common::Rect *bounds, int flags) { - assert(w != 0 && h != 0); - return this; -} - -void DirectDrawSurface::unlock() { - assert(w != 0 && h != 0); -} - -void DirectDrawSurface::fill(const Common::Rect *bounds, uint32 color) { - Common::Rect tempBounds; - - if (bounds) { - // Bounds are provided, clip them to the bounds of this surface - tempBounds = *bounds; - tempBounds.clip(Common::Rect(0, 0, this->w, this->h)); - } else { - // No bounds provided, so use the entire surface - tempBounds = Common::Rect(0, 0, this->w, this->h); - } - - // Fill the area - fillRect(tempBounds, color); -} - } // End of namespace Titanic diff --git a/engines/titanic/direct_draw.h b/engines/titanic/direct_draw.h index 5ec0f3d5c7..cf21c98095 100644 --- a/engines/titanic/direct_draw.h +++ b/engines/titanic/direct_draw.h @@ -25,45 +25,12 @@ #include "common/scummsys.h" #include "common/array.h" -#include "graphics/surface.h" +#include "titanic/direct_draw_surface.h" namespace Titanic { class TitanicEngine; -struct DDSurfaceDesc { - int _w; - int _h; - int _flags; - int _caps; - - DDSurfaceDesc(int w, int h) : _w(w), _h(h), _flags(0x1006), _caps(64) {} -}; - -class DirectDrawSurface : public Graphics::Surface { -public: - /** - * Return the size of the surface in ytes - */ - int getSize() const { return pitch * h; } - - /** - * Lock the surface for access - */ - Graphics::Surface *lock(const Common::Rect *bounds, int flags); - - /** - * Unlocks the surface at the end of direct accesses - */ - void unlock(); - - /** - * Fills an area of the surfae with the specified color. If no bounds are passed, - * then the entire surface is filled - */ - void fill(const Common::Rect *bounds, uint32 color); -}; - class DirectDraw { private: TitanicEngine *_vm; diff --git a/engines/titanic/direct_draw_surface.cpp b/engines/titanic/direct_draw_surface.cpp new file mode 100644 index 0000000000..6ce6f2411a --- /dev/null +++ b/engines/titanic/direct_draw_surface.cpp @@ -0,0 +1,87 @@ +/* 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 "common/rect.h" +#include "titanic/direct_draw_surface.h" + +namespace Titanic { + +DirectDrawSurface::DirectDrawSurface() : _surface(nullptr), + _disposeAfterUse(DisposeAfterUse::YES) { +} + +DirectDrawSurface::~DirectDrawSurface() { + free(); +} + +void DirectDrawSurface::create(Graphics::ManagedSurface *surface) { + free(); + _surface = surface; + _disposeAfterUse = DisposeAfterUse::NO; +} + +void DirectDrawSurface::create(int w, int h) { + Graphics::PixelFormat pixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); + _surface = new Graphics::ManagedSurface(w, h, pixelFormat); + _disposeAfterUse = DisposeAfterUse::YES; +} + +void DirectDrawSurface::free() { + if (_disposeAfterUse == DisposeAfterUse::YES) + delete _surface; + _surface = nullptr; + _disposeAfterUse = DisposeAfterUse::NO; +} + +Graphics::ManagedSurface *DirectDrawSurface::lock(const Common::Rect *bounds, int flags) { + assert(!_surface->empty()); + return _surface; +} + +void DirectDrawSurface::unlock() { + assert(_surface->w != 0 && _surface->h != 0); +} + +void DirectDrawSurface::fill(const Common::Rect *bounds, uint32 color) { + Common::Rect tempBounds; + + if (bounds) { + // Bounds are provided, clip them to the bounds of this surface + tempBounds = *bounds; + tempBounds.clip(Common::Rect(0, 0, _surface->w, _surface->h)); + } else { + // No bounds provided, so use the entire surface + tempBounds = Common::Rect(0, 0, _surface->w, _surface->h); + } + + // Fill the area + _surface->fillRect(tempBounds, color); +} + +void DirectDrawSurface::blitFast(const Common::Point &destPos, DirectDrawSurface *srcSurface, Common::Rect *bounds) { + if (bounds) + _surface->blitFrom(*srcSurface->_surface, *bounds, destPos); + else + _surface->blitFrom(*srcSurface->_surface, destPos); +} + +} // End of namespace Titanic diff --git a/engines/titanic/direct_draw_surface.h b/engines/titanic/direct_draw_surface.h new file mode 100644 index 0000000000..14988583f0 --- /dev/null +++ b/engines/titanic/direct_draw_surface.h @@ -0,0 +1,110 @@ +/* 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. + * + */ + +#ifndef TITANIC_DIRECT_DRAW_SURFACE_H +#define TITANIC_DIRECT_DRAW_SURFACE_H + +#include "common/scummsys.h" +#include "common/array.h" +#include "graphics/managed_surface.h" + +namespace Titanic { + +class TitanicEngine; + +struct DDSurfaceDesc { + int _w; + int _h; + int _flags; + int _caps; + + DDSurfaceDesc(int w, int h) : _w(w), _h(h), _flags(0x1006), _caps(64) {} +}; + +class DirectDrawSurface { +private: + Graphics::ManagedSurface *_surface; + DisposeAfterUse::Flag _disposeAfterUse; +public: + DirectDrawSurface(); + ~DirectDrawSurface(); + + /** + * Create a surface + */ + void create(int w, int h); + + /** + * Create a surface based on a passed surface + */ + void create(Graphics::ManagedSurface *surface); + + /** + * Frees the surface + */ + void free(); + + /** + * Return the size of the surface in ytes + */ + int getSize() const { return _surface->pitch * _surface->h; } + + /** + * Return the surface width + */ + int getWidth() const { return _surface->w; } + + /** + * Return the surface width + */ + int getHeight() const { return _surface->h; } + + /** + * Return the surface pitch + */ + int getPitch() const { return _surface->pitch; } + + /** + * Lock the surface for access + */ + Graphics::ManagedSurface *lock(const Common::Rect *bounds, int flags); + + /** + * Unlocks the surface at the end of direct accesses + */ + void unlock(); + + /** + * Fills an area of the surfae with the specified color. If no bounds are passed, + * then the entire surface is filled + */ + void fill(const Common::Rect *bounds, uint32 color); + + /** + * Copy data from a source surfcae into this one + */ + void blitFast(const Common::Point &destPos, DirectDrawSurface *srcSurface, Common::Rect *bounds); +}; + +} // End of namespace Titanic + +#endif /* TITANIC_DIRECT_DRAW_SURFACE_H */ diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index f62ef96d0b..285a1c8157 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS := \ debugger.o \ detection.o \ direct_draw.o \ + direct_draw_surface.o \ events.o \ files_manager.o \ font.o \ diff --git a/engines/titanic/pet_control/pet_control_sub12.cpp b/engines/titanic/pet_control/pet_control_sub12.cpp index 616d6920ae..5daf826ae6 100644 --- a/engines/titanic/pet_control/pet_control_sub12.cpp +++ b/engines/titanic/pet_control/pet_control_sub12.cpp @@ -67,6 +67,7 @@ void CPetControlSub12::load(SimpleFile *file, int param) { _field70 = file->readNumber(); _field74 = file->readNumber(); + warning("TODO: CPetControlSub12::load %d,%d", var1, var2); assert(_array.size() >= count); for (uint idx = 0; idx < count; ++idx) { _array[idx]._string1 = file->readString(); diff --git a/engines/titanic/video_surface.cpp b/engines/titanic/video_surface.cpp index 08ba64ac75..503fd6bfc7 100644 --- a/engines/titanic/video_surface.cpp +++ b/engines/titanic/video_surface.cpp @@ -123,17 +123,17 @@ bool OSVideoSurface::hasSurface() { int OSVideoSurface::getWidth() const { assert(_ddSurface); - return _ddSurface->w; + return _ddSurface->getWidth(); } int OSVideoSurface::getHeight() const { assert(_ddSurface); - return _ddSurface->h; + return _ddSurface->getHeight(); } int OSVideoSurface::getPitch() const { assert(_ddSurface); - return _ddSurface->pitch; + return _ddSurface->getPitch(); } void OSVideoSurface::resize(int width, int height) { diff --git a/engines/titanic/video_surface.h b/engines/titanic/video_surface.h index 47caffdcaf..7efd8b5c37 100644 --- a/engines/titanic/video_surface.h +++ b/engines/titanic/video_surface.h @@ -45,7 +45,7 @@ protected: CScreenManager *_screenManager; CResourceKey _resourceKey; DirectDrawSurface *_ddSurface; - Graphics::Surface *_rawSurface; + Graphics::ManagedSurface *_rawSurface; void *_field34; bool _pendingLoad; int _field40; |