From 1907b5f74140793453b33f9265ac065db218ec30 Mon Sep 17 00:00:00 2001 From: fracturehill Date: Mon, 22 Mar 2021 18:56:52 +0200 Subject: [PATCH] NANCY: Remove static members of GraphicsManager Made GraphicsManager's static members non-static. --- engines/nancy/action/leverpuzzle.cpp | 4 ++-- engines/nancy/action/orderingpuzzle.cpp | 6 +++--- engines/nancy/action/passwordpuzzle.cpp | 6 +++--- engines/nancy/action/rotatinglockpuzzle.cpp | 4 ++-- engines/nancy/action/secondarymovie.cpp | 2 +- engines/nancy/action/secondaryvideo.cpp | 2 +- engines/nancy/action/sliderpuzzle.cpp | 6 +++--- engines/nancy/action/telephone.cpp | 6 +++--- engines/nancy/cursor.cpp | 2 +- engines/nancy/font.cpp | 4 ++-- engines/nancy/graphics.cpp | 12 +++++++++--- engines/nancy/graphics.h | 15 ++++++++------- engines/nancy/renderobject.cpp | 2 +- engines/nancy/resource.cpp | 4 ++-- engines/nancy/ui/inventorybox.cpp | 6 +++--- engines/nancy/ui/textbox.cpp | 2 +- engines/nancy/video.cpp | 3 ++- 17 files changed, 47 insertions(+), 39 deletions(-) diff --git a/engines/nancy/action/leverpuzzle.cpp b/engines/nancy/action/leverpuzzle.cpp index 7a7d5794cea..a7e672191f5 100644 --- a/engines/nancy/action/leverpuzzle.cpp +++ b/engines/nancy/action/leverpuzzle.cpp @@ -33,8 +33,8 @@ namespace Nancy { namespace Action { void LeverPuzzle::init() { - _drawSurface.create(_screenPosition.width(), _screenPosition.height(), GraphicsManager::getInputPixelFormat()); - _drawSurface.clear(GraphicsManager::getTransColor()); + _drawSurface.create(_screenPosition.width(), _screenPosition.height(), g_nancy->_graphicsManager->getInputPixelFormat()); + _drawSurface.clear(g_nancy->_graphicsManager->getTransColor()); setTransparent(true); diff --git a/engines/nancy/action/orderingpuzzle.cpp b/engines/nancy/action/orderingpuzzle.cpp index e9be9770b24..b83f513d84d 100644 --- a/engines/nancy/action/orderingpuzzle.cpp +++ b/engines/nancy/action/orderingpuzzle.cpp @@ -40,7 +40,7 @@ namespace Action { void OrderingPuzzle::init() { // Screen position is initialized in readData and fits exactly the bounds of all elements on screen. // This is a hacky way to make this particular action record work with this implementation's graphics manager - _drawSurface.create(_screenPosition.width(), _screenPosition.height(), GraphicsManager::getInputPixelFormat()); + _drawSurface.create(_screenPosition.width(), _screenPosition.height(), g_nancy->_graphicsManager->getInputPixelFormat()); clearAllElements(); setTransparent(true); @@ -223,12 +223,12 @@ void OrderingPuzzle::undrawElement(uint id) { Common::Rect bounds = _destRects[id]; bounds.translate(-_screenPosition.left, -_screenPosition.top); - _drawSurface.fillRect(bounds, GraphicsManager::getTransColor()); + _drawSurface.fillRect(bounds, g_nancy->_graphicsManager->getTransColor()); _needsRedraw = true; } void OrderingPuzzle::clearAllElements() { - _drawSurface.clear(GraphicsManager::getTransColor()); + _drawSurface.clear(g_nancy->_graphicsManager->getTransColor()); setVisible(false); _clickedSequence.clear(); return; diff --git a/engines/nancy/action/passwordpuzzle.cpp b/engines/nancy/action/passwordpuzzle.cpp index 0f7bb6f3a4f..b4b1f00a0f5 100644 --- a/engines/nancy/action/passwordpuzzle.cpp +++ b/engines/nancy/action/passwordpuzzle.cpp @@ -35,8 +35,8 @@ namespace Nancy { namespace Action { void PasswordPuzzle::init() { - _drawSurface.create(_screenPosition.width(), _screenPosition.height(), GraphicsManager::getInputPixelFormat()); - _drawSurface.clear(GraphicsManager::getTransColor()); + _drawSurface.create(_screenPosition.width(), _screenPosition.height(), g_nancy->_graphicsManager->getInputPixelFormat()); + _drawSurface.clear(g_nancy->_graphicsManager->getTransColor()); setTransparent(true); @@ -219,7 +219,7 @@ void PasswordPuzzle::onPause(bool pause) { } void PasswordPuzzle::drawText() { - _drawSurface.clear(GraphicsManager::getTransColor()); + _drawSurface.clear(g_nancy->_graphicsManager->getTransColor()); const Graphics::Font *font = g_nancy->_graphicsManager->getFont(_fontID); Common::Rect bounds = _nameBounds; diff --git a/engines/nancy/action/rotatinglockpuzzle.cpp b/engines/nancy/action/rotatinglockpuzzle.cpp index 4e9f1d05bf4..6e1f6043614 100644 --- a/engines/nancy/action/rotatinglockpuzzle.cpp +++ b/engines/nancy/action/rotatinglockpuzzle.cpp @@ -35,8 +35,8 @@ namespace Nancy { namespace Action { void RotatingLockPuzzle::init() { - _drawSurface.create(_screenPosition.width(), _screenPosition.height(), GraphicsManager::getInputPixelFormat()); - _drawSurface.clear(GraphicsManager::getTransColor()); + _drawSurface.create(_screenPosition.width(), _screenPosition.height(), g_nancy->_graphicsManager->getInputPixelFormat()); + _drawSurface.clear(g_nancy->_graphicsManager->getTransColor()); setTransparent(true); diff --git a/engines/nancy/action/secondarymovie.cpp b/engines/nancy/action/secondarymovie.cpp index ecfc65c977a..c1e2b3f5450 100644 --- a/engines/nancy/action/secondarymovie.cpp +++ b/engines/nancy/action/secondarymovie.cpp @@ -72,7 +72,7 @@ void PlaySecondaryMovie::init() { } _decoder.loadFile(_videoName + ".avf"); - _drawSurface.create(_decoder.getWidth(), _decoder.getHeight(), GraphicsManager::getInputPixelFormat()); + _drawSurface.create(_decoder.getWidth(), _decoder.getHeight(), g_nancy->_graphicsManager->getInputPixelFormat()); _screenPosition = _drawSurface.getBounds(); RenderObject::init(); diff --git a/engines/nancy/action/secondaryvideo.cpp b/engines/nancy/action/secondaryvideo.cpp index 318bd10ffc1..c8bd4b4b4f1 100644 --- a/engines/nancy/action/secondaryvideo.cpp +++ b/engines/nancy/action/secondaryvideo.cpp @@ -49,7 +49,7 @@ void PlaySecondaryVideo::init() { // Every secondary video frame (in nancy1) plays exactly 12ms slower than what its metadata says. // I'm still not sure how/why that happens so for now I'm using this hack to fix the timings _decoder.addFrameTime(12); - _drawSurface.create(_decoder.getWidth(), _decoder.getHeight(), GraphicsManager::getInputPixelFormat()); + _drawSurface.create(_decoder.getWidth(), _decoder.getHeight(), g_nancy->_graphicsManager->getInputPixelFormat()); if (_paletteFilename.size()) { GraphicsManager::loadSurfacePalette(_drawSurface, _paletteFilename); diff --git a/engines/nancy/action/sliderpuzzle.cpp b/engines/nancy/action/sliderpuzzle.cpp index d808a56e7ba..cf8706ca00d 100644 --- a/engines/nancy/action/sliderpuzzle.cpp +++ b/engines/nancy/action/sliderpuzzle.cpp @@ -35,8 +35,8 @@ namespace Nancy { namespace Action { void SliderPuzzle::init() { - _drawSurface.create(_screenPosition.width(), _screenPosition.height(), GraphicsManager::getInputPixelFormat()); - _drawSurface.clear(GraphicsManager::getTransColor()); + _drawSurface.create(_screenPosition.width(), _screenPosition.height(), g_nancy->_graphicsManager->getInputPixelFormat()); + _drawSurface.clear(g_nancy->_graphicsManager->getTransColor()); setTransparent(true); @@ -310,7 +310,7 @@ void SliderPuzzle::drawTile(int tileID, uint posX, uint posY) { void SliderPuzzle::undrawTile(uint posX, uint posY) { Common::Rect bounds = _destRects[posY][posX]; bounds.translate(-_screenPosition.left, -_screenPosition.top); - _drawSurface.fillRect(bounds, GraphicsManager::getTransColor()); + _drawSurface.fillRect(bounds, g_nancy->_graphicsManager->getTransColor()); _needsRedraw = true; } diff --git a/engines/nancy/action/telephone.cpp b/engines/nancy/action/telephone.cpp index 486d2fa7ddb..f3c08e866fe 100644 --- a/engines/nancy/action/telephone.cpp +++ b/engines/nancy/action/telephone.cpp @@ -39,8 +39,8 @@ namespace Nancy { namespace Action { void Telephone::init() { - _drawSurface.create(_screenPosition.width(), _screenPosition.height(), GraphicsManager::getInputPixelFormat()); - _drawSurface.clear(GraphicsManager::getTransColor()); + _drawSurface.create(_screenPosition.width(), _screenPosition.height(), g_nancy->_graphicsManager->getInputPixelFormat()); + _drawSurface.clear(g_nancy->_graphicsManager->getTransColor()); setTransparent(true); @@ -316,7 +316,7 @@ void Telephone::undrawButton(uint id) { Common::Rect bounds = _destRects[id]; bounds.translate(-_screenPosition.left, -_screenPosition.top); - _drawSurface.fillRect(bounds, GraphicsManager::getTransColor()); + _drawSurface.fillRect(bounds, g_nancy->_graphicsManager->getTransColor()); _needsRedraw = true; } diff --git a/engines/nancy/cursor.cpp b/engines/nancy/cursor.cpp index 60944185850..170b260dec4 100644 --- a/engines/nancy/cursor.cpp +++ b/engines/nancy/cursor.cpp @@ -117,7 +117,7 @@ void CursorManager::setCursor(CursorType type, int16 itemID) { s.copyRectToSurface(*surf, 0, 0, bounds); // TODO hotspots are terrible for arrow cursors, fix that?? - CursorMan.replaceCursor(s.getPixels(), s.w, s.h, hotspot.x, hotspot.y, GraphicsManager::getTransColor(), false, &GraphicsManager::getInputPixelFormat()); + CursorMan.replaceCursor(s.getPixels(), s.w, s.h, hotspot.x, hotspot.y, g_nancy->_graphicsManager->getTransColor(), false, &g_nancy->_graphicsManager->getInputPixelFormat()); s.free(); diff --git a/engines/nancy/font.cpp b/engines/nancy/font.cpp index dbe484a5d64..820dbb08ecd 100644 --- a/engines/nancy/font.cpp +++ b/engines/nancy/font.cpp @@ -30,7 +30,7 @@ namespace Nancy { void Font::read(Common::SeekableReadStream &stream) { - _transColor = GraphicsManager::getTransColor(); + _transColor = g_nancy->_graphicsManager->getTransColor(); _maxCharWidth = 0; _fontHeight = 0; @@ -97,7 +97,7 @@ void Font::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 col for (uint curY = 0; curY < height; ++curY) { for (uint curX = 0; curX < width; ++curX) { - switch (GraphicsManager::getInputPixelFormat().bytesPerPixel) { + switch (g_nancy->_graphicsManager->getInputPixelFormat().bytesPerPixel) { case 1: // TODO break; diff --git a/engines/nancy/graphics.cpp b/engines/nancy/graphics.cpp index 9ecb63deb97..76dd952dfd4 100644 --- a/engines/nancy/graphics.cpp +++ b/engines/nancy/graphics.cpp @@ -39,9 +39,11 @@ namespace Nancy { -const Graphics::PixelFormat GraphicsManager::_inputPixelFormat = Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); -const Graphics::PixelFormat GraphicsManager::_screenPixelFormat = Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); -const Graphics::PixelFormat GraphicsManager::_clut8Format = Graphics::PixelFormat::createFormatCLUT8(); +GraphicsManager::GraphicsManager() : + _objects(objectComparator), + _inputPixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), + _screenPixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), + _clut8Format(Graphics::PixelFormat::createFormatCLUT8()) {} void GraphicsManager::init() { initGraphics(640, 480, &_screenPixelFormat); @@ -232,6 +234,10 @@ const Graphics::PixelFormat &GraphicsManager::getInputPixelFormat() { } } +const Graphics::PixelFormat &GraphicsManager::getScreenPixelFormat() { + return _screenPixelFormat; +} + uint GraphicsManager::getTransColor() { if (g_nancy->getGameFlags() & NGF_8BITCOLOR) { return 1; // If this isn't correct, try picking the pixel at [0, 0] inside the palette bitmap diff --git a/engines/nancy/graphics.h b/engines/nancy/graphics.h index 31ffae87fb1..7be0d3ab16f 100644 --- a/engines/nancy/graphics.h +++ b/engines/nancy/graphics.h @@ -37,7 +37,7 @@ class NancyEngine; // Graphics class that handles multilayered surface rendering with minimal redraw class GraphicsManager { public: - GraphicsManager() : _objects(objectComparator) {} + GraphicsManager(); void init(); void draw(); @@ -50,16 +50,17 @@ public: const Font *getFont(uint id) const { return id < _fonts.size() ? &_fonts[id] : nullptr; } + const Graphics::PixelFormat &getInputPixelFormat(); + const Graphics::PixelFormat &getScreenPixelFormat(); + uint getTransColor(); + static void loadSurfacePalette(Graphics::ManagedSurface &inSurf, const Common::String paletteFilename); static void copyToManaged(const Graphics::Surface &src, Graphics::ManagedSurface &dst, bool verticalFlip = false, bool doubleSize = false); static void copyToManaged(void *src, Graphics::ManagedSurface &dst, uint srcW, uint srcH, const Graphics::PixelFormat &format, bool verticalFlip = false, bool doubleSize = false); - static const Graphics::PixelFormat &getInputPixelFormat(); - static uint getTransColor(); - Graphics::ManagedSurface _object0; - static const Graphics::PixelFormat _screenPixelFormat; + Graphics::PixelFormat _screenPixelFormat; private: void loadFonts(); @@ -69,8 +70,8 @@ private: Common::SortedArray _objects; - static const Graphics::PixelFormat _inputPixelFormat; - static const Graphics::PixelFormat _clut8Format; + Graphics::PixelFormat _inputPixelFormat; + Graphics::PixelFormat _clut8Format; Graphics::Screen _screen; Common::Array _fonts; diff --git a/engines/nancy/renderobject.cpp b/engines/nancy/renderobject.cpp index ae31613b9f3..70e57b43d14 100644 --- a/engines/nancy/renderobject.cpp +++ b/engines/nancy/renderobject.cpp @@ -60,7 +60,7 @@ void RenderObject::setVisible(bool visible) { void RenderObject::setTransparent(bool isTransparent) { if (isTransparent) { - _drawSurface.setTransparentColor(GraphicsManager::getTransColor()); + _drawSurface.setTransparentColor(g_nancy->_graphicsManager->getTransColor()); } else { _drawSurface.clearTransparentColor(); } diff --git a/engines/nancy/resource.cpp b/engines/nancy/resource.cpp index 2a8eb34b6ba..a303af92f16 100644 --- a/engines/nancy/resource.cpp +++ b/engines/nancy/resource.cpp @@ -789,7 +789,7 @@ bool ResourceManager::loadImage(const Common::String &name, Graphics::Surface &s surf.h = info.height; surf.pitch = info.pitch; surf.setPixels(buf); - surf.format = GraphicsManager::getInputPixelFormat(); + surf.format = g_nancy->_graphicsManager->getInputPixelFormat(); return true; } @@ -830,7 +830,7 @@ bool ResourceManager::loadImage(const Common::String &name, Graphics::ManagedSur return false; } - GraphicsManager::copyToManaged(buf, surf, info.width, info.height, GraphicsManager::getInputPixelFormat()); + GraphicsManager::copyToManaged(buf, surf, info.width, info.height, g_nancy->_graphicsManager->getInputPixelFormat()); return true; } } diff --git a/engines/nancy/ui/inventorybox.cpp b/engines/nancy/ui/inventorybox.cpp index ee5cbcad331..badfcafd151 100644 --- a/engines/nancy/ui/inventorybox.cpp +++ b/engines/nancy/ui/inventorybox.cpp @@ -74,7 +74,7 @@ void InventoryBox::init() { g_nancy->_resource->loadImage(inventoryBoxIconsImageName, _iconsSurface); uint numItems = 11; // TODO - _fullInventorySurface.create(_screenPosition.width(), _screenPosition.height() * ((numItems / 4) + 1), GraphicsManager::_screenPixelFormat); + _fullInventorySurface.create(_screenPosition.width(), _screenPosition.height() * ((numItems / 4) + 1), g_nancy->_graphicsManager->getScreenPixelFormat()); Common::Rect sourceRect = _screenPosition; sourceRect.moveTo(0, 0); _drawSurface.create(_fullInventorySurface, sourceRect); @@ -223,7 +223,7 @@ void InventoryBox::InventoryScrollbar::init() { void InventoryBox::Shades::init() { Common::Rect bounds = _parent->getBounds(); - _drawSurface.create(bounds.width(), bounds.height(), GraphicsManager::_screenPixelFormat); + _drawSurface.create(bounds.width(), bounds.height(), g_nancy->_graphicsManager->getScreenPixelFormat()); _screenPosition = _parent->getScreenPosition(); _nextFrameTime = 0; setAnimationFrame(_curFrame); @@ -274,7 +274,7 @@ void InventoryBox::Shades::setAnimationFrame(uint frame) { setVisible(true); } - _drawSurface.clear(GraphicsManager::getTransColor()); + _drawSurface.clear(g_nancy->_graphicsManager->getTransColor()); // Draw left shade srcRect = _parent->_shadesSrc[frame * 2]; diff --git a/engines/nancy/ui/textbox.cpp b/engines/nancy/ui/textbox.cpp index 9db17ef1d4c..f560847e572 100644 --- a/engines/nancy/ui/textbox.cpp +++ b/engines/nancy/ui/textbox.cpp @@ -55,7 +55,7 @@ void Textbox::init() { chunk->seek(0x20); Common::Rect innerBoundingBox; readRect(*chunk, innerBoundingBox); - _fullSurface.create(innerBoundingBox.width(), innerBoundingBox.height(), GraphicsManager::_screenPixelFormat); + _fullSurface.create(innerBoundingBox.width(), innerBoundingBox.height(), g_nancy->_graphicsManager->getScreenPixelFormat()); _scrollbarDefaultDest.x = chunk->readUint16LE(); _scrollbarDefaultDest.y = chunk->readUint16LE(); diff --git a/engines/nancy/video.cpp b/engines/nancy/video.cpp index 32ca875f98a..41b3d4e14ae 100644 --- a/engines/nancy/video.cpp +++ b/engines/nancy/video.cpp @@ -23,6 +23,7 @@ #include "engines/nancy/video.h" #include "engines/nancy/decompress.h" #include "engines/nancy/graphics.h" +#include "engines/nancy/nancy.h" #include "common/endian.h" #include "common/stream.h" @@ -110,7 +111,7 @@ AVFDecoder::AVFVideoTrack::AVFVideoTrack(Common::SeekableReadStream *stream, uin error("Unknown compression type %d found in AVF", comp); _surface = new Graphics::Surface(); - _pixelFormat = GraphicsManager::getInputPixelFormat(); + _pixelFormat = g_nancy->_graphicsManager->getInputPixelFormat(); _surface->create(_width, _height, _pixelFormat); _frameSize = _width * _height * _pixelFormat.bytesPerPixel;