From e9e654d7db8c6b865c6f168f6f35663af85fce85 Mon Sep 17 00:00:00 2001 From: Nipun Garg Date: Thu, 18 Jul 2019 01:11:53 +0530 Subject: HDB: Convert _surface from struct to pointer --- engines/hdb/gfx.cpp | 44 ++++++++++++++++++++++++-------------------- engines/hdb/gfx.h | 10 +++++----- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/engines/hdb/gfx.cpp b/engines/hdb/gfx.cpp index de897074e0..942fd1d2b6 100644 --- a/engines/hdb/gfx.cpp +++ b/engines/hdb/gfx.cpp @@ -1032,14 +1032,16 @@ void Gfx::drawDebugInfo(Tile *_debugLogo, int fps) { } Picture::Picture() : _width(0), _height(0), _name("") { - _surface.create(_width, _height, g_hdb->_format); + _surface = NULL; } Picture::~Picture() { - _surface.free(); + if (_surface) + _surface->free(); + _surface = NULL; } -Graphics::Surface Picture::load(Common::SeekableReadStream *stream) { +Graphics::ManagedSurface *Picture::load(Common::SeekableReadStream *stream) { _width = stream->readUint32LE(); _height = stream->readUint32LE(); stream->read(_name, 64); @@ -1047,13 +1049,14 @@ Graphics::Surface Picture::load(Common::SeekableReadStream *stream) { debug(8, "Picture: _width: %d, _height: %d", _width, _height); debug(8, "Picture: _name: %s", _name); - _surface.create(_width, _height, g_hdb->_format); + _surface = new Graphics::ManagedSurface; + _surface->create(_width, _height, g_hdb->_format); stream->readUint32LE(); // Skip Win32 Surface uint16 *ptr; for (int y = 0; y < _height; y++) { - ptr = (uint16 *)_surface.getBasePtr(0, y); + ptr = (uint16 *)_surface->getBasePtr(0, y); for (int x = 0; x < _width; x++) { *ptr = TO_LE_16(stream->readUint16LE()); ptr++; @@ -1064,9 +1067,9 @@ Graphics::Surface Picture::load(Common::SeekableReadStream *stream) { } int Picture::draw(int x, int y) { - g_hdb->_gfx->_globalSurface.blitFrom(_surface, Common::Point(x, y)); + g_hdb->_gfx->_globalSurface.blitFrom(*_surface, Common::Point(x, y)); - Common::Rect clip(_surface.getBounds()); + Common::Rect clip(_surface->getBounds()); clip.moveTo(x, y); clip.clip(g_hdb->_gfx->_globalSurface.getBounds()); if (!clip.isEmpty()) { @@ -1077,9 +1080,9 @@ int Picture::draw(int x, int y) { } int Picture::drawMasked(int x, int y, int alpha) { - g_hdb->_gfx->_globalSurface.transBlitFrom(_surface, Common::Point(x, y), 0xf81f, false, 0, alpha & 0xff); + g_hdb->_gfx->_globalSurface.transBlitFrom(*_surface, Common::Point(x, y), 0xf81f, false, 0, alpha & 0xff); - Common::Rect clip(_surface.getBounds()); + Common::Rect clip(_surface->getBounds()); clip.moveTo(x, y); clip.clip(g_hdb->_gfx->_globalSurface.getBounds()); if (!clip.isEmpty()) { @@ -1089,25 +1092,26 @@ int Picture::drawMasked(int x, int y, int alpha) { return 0; } -Tile::Tile() : _flags(0), _name("") { - _surface.create(32, 32, g_hdb->_format); -} +Tile::Tile() : _flags(0), _name(""), _surface(NULL) {} Tile::~Tile() { - _surface.free(); + if (_surface) + _surface->free(); + _surface = NULL; } -Graphics::Surface Tile::load(Common::SeekableReadStream *stream) { +Graphics::ManagedSurface *Tile::load(Common::SeekableReadStream *stream) { _flags = stream->readUint32LE(); stream->read(_name, 64); - _surface.create(32, 32, g_hdb->_format); + _surface = new Graphics::ManagedSurface; + _surface->create(32, 32, g_hdb->_format); stream->readUint32LE(); // Skip Win32 Surface uint16 *ptr; for (uint y = 0; y < 32; y++) { - ptr = (uint16 *)_surface.getBasePtr(0, y); + ptr = (uint16 *)_surface->getBasePtr(0, y); for (uint x = 0; x < 32; x++) { *ptr = TO_LE_16(stream->readUint16LE()); ptr++; @@ -1118,9 +1122,9 @@ Graphics::Surface Tile::load(Common::SeekableReadStream *stream) { } int Tile::draw(int x, int y) { - g_hdb->_gfx->_globalSurface.blitFrom(_surface, Common::Point(x, y)); + g_hdb->_gfx->_globalSurface.blitFrom(*_surface, Common::Point(x, y)); - Common::Rect clip(_surface.getBounds()); + Common::Rect clip(_surface->getBounds()); clip.moveTo(x, y); clip.clip(g_hdb->_gfx->_globalSurface.getBounds()); if (!clip.isEmpty()) { @@ -1131,9 +1135,9 @@ int Tile::draw(int x, int y) { } int Tile::drawMasked(int x, int y, int alpha) { - g_hdb->_gfx->_globalSurface.transBlitFrom(_surface, Common::Point(x, y), 0xf81f, false, 0, alpha & 0xff); + g_hdb->_gfx->_globalSurface.transBlitFrom(*_surface, Common::Point(x, y), 0xf81f, false, 0, alpha & 0xff); - Common::Rect clip(_surface.getBounds()); + Common::Rect clip(_surface->getBounds()); clip.moveTo(x, y); clip.clip(g_hdb->_gfx->_globalSurface.getBounds()); if (!clip.isEmpty()) { diff --git a/engines/hdb/gfx.h b/engines/hdb/gfx.h index ce6ceb6502..1c993ec201 100644 --- a/engines/hdb/gfx.h +++ b/engines/hdb/gfx.h @@ -253,7 +253,7 @@ public: Picture(); ~Picture(); - Graphics::Surface load(Common::SeekableReadStream *stream); + Graphics::ManagedSurface *load(Common::SeekableReadStream *stream); int draw(int x, int y); int drawMasked(int x, int y, int alpha = 0xff); @@ -261,12 +261,12 @@ public: char *getName() { return _name; } - Graphics::ManagedSurface *getSurface() { return &_surface; } + Graphics::ManagedSurface *getSurface() { return _surface; } private: char _name[64]; - Graphics::ManagedSurface _surface; + Graphics::ManagedSurface *_surface; }; class Tile { @@ -275,7 +275,7 @@ public: Tile(); ~Tile(); - Graphics::Surface load(Common::SeekableReadStream *stream); + Graphics::ManagedSurface *load(Common::SeekableReadStream *stream); int draw(int x, int y); int drawMasked(int x, int y, int alpha = 0xff); @@ -285,7 +285,7 @@ public: private: char _name[64]; - Graphics::ManagedSurface _surface; + Graphics::ManagedSurface *_surface; }; } // End of Namespace HDB -- cgit v1.2.3