[Scummvm-git-logs] scummvm master -> 49a2fac05e06f60bff311e0405d56edd0c5acfcb

sluicebox noreply at scummvm.org
Fri Nov 17 02:46:26 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
49a2fac05e SCI: Reduce global engine usage


Commit: 49a2fac05e06f60bff311e0405d56edd0c5acfcb
    https://github.com/scummvm/scummvm/commit/49a2fac05e06f60bff311e0405d56edd0c5acfcb
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2023-11-16T18:44:42-08:00

Commit Message:
SCI: Reduce global engine usage

Changed paths:
    engines/sci/graphics/animate.cpp
    engines/sci/graphics/animate.h
    engines/sci/graphics/cursor.cpp
    engines/sci/graphics/frameout.cpp
    engines/sci/graphics/maciconbar.cpp
    engines/sci/graphics/maciconbar.h
    engines/sci/graphics/paint16.cpp
    engines/sci/graphics/text16.cpp
    engines/sci/metaengine.cpp
    engines/sci/sci.cpp


diff --git a/engines/sci/graphics/animate.cpp b/engines/sci/graphics/animate.cpp
index 8ee952fe7a3..b7af374f173 100644
--- a/engines/sci/graphics/animate.cpp
+++ b/engines/sci/graphics/animate.cpp
@@ -44,8 +44,8 @@
 
 namespace Sci {
 
-GfxAnimate::GfxAnimate(EngineState *state, ScriptPatcher *scriptPatcher, GfxCache *cache, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen, GfxPalette *palette, GfxCursor *cursor, GfxTransitions *transitions)
-	: _s(state), _scriptPatcher(scriptPatcher), _cache(cache), _ports(ports), _paint16(paint16), _screen(screen), _palette(palette), _cursor(cursor), _transitions(transitions) {
+GfxAnimate::GfxAnimate(EngineState *state, ScriptPatcher *scriptPatcher, GfxCache *cache, GfxCompare *compare, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen, GfxPalette *palette, GfxCursor *cursor, GfxTransitions *transitions)
+	: _s(state), _scriptPatcher(scriptPatcher), _cache(cache), _compare(compare), _ports(ports), _paint16(paint16), _screen(screen), _palette(palette), _cursor(cursor), _transitions(transitions) {
 	init();
 }
 
@@ -369,7 +369,7 @@ void GfxAnimate::setNsRect(GfxView *view, AnimateList::iterator it) {
 		//  This special handling is not included in the other SCI1.1 interpreters and MUST NOT be
 		//  checked in those cases, otherwise we will break games (e.g. EcoQuest 2, room 200)
 		if ((g_sci->getGameId() == GID_HOYLE4) && (it->scaleSignal & kScaleSignalHoyle4SpecialHandling)) {
-			it->celRect = g_sci->_gfxCompare->getNSRect(it->object);
+			it->celRect = _compare->getNSRect(it->object);
 			view->getCelSpecialHoyle4Rect(it->loopNo, it->celNo, it->x, it->y, it->z, it->celRect);
 			shouldSetNsRect = false;
 		} else {
@@ -378,7 +378,7 @@ void GfxAnimate::setNsRect(GfxView *view, AnimateList::iterator it) {
 	}
 
 	if (shouldSetNsRect) {
-		g_sci->_gfxCompare->setNSRect(it->object, it->celRect);
+		_compare->setNSRect(it->object, it->celRect);
 	}
 }
 
@@ -600,7 +600,7 @@ void GfxAnimate::addToPicDrawCels() {
 				applyGlobalScaling(it, view);
 			}
 			view->getCelScaledRect(it->loopNo, it->celNo, it->x, it->y, it->z, it->scaleX, it->scaleY, it->celRect);
-			g_sci->_gfxCompare->setNSRect(curObject, it->celRect);
+			_compare->setNSRect(curObject, it->celRect);
 		} else {
 			view->getCelRect(it->loopNo, it->celNo, it->x, it->y, it->z, it->celRect);
 		}
diff --git a/engines/sci/graphics/animate.h b/engines/sci/graphics/animate.h
index c6fcb156b51..c23f1bb7e28 100644
--- a/engines/sci/graphics/animate.h
+++ b/engines/sci/graphics/animate.h
@@ -86,7 +86,7 @@ class GfxView;
  */
 class GfxAnimate {
 public:
-	GfxAnimate(EngineState *state, ScriptPatcher *scriptPatcher, GfxCache *cache, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen, GfxPalette *palette, GfxCursor *cursor, GfxTransitions *transitions);
+	GfxAnimate(EngineState *state, ScriptPatcher *scriptPatcher, GfxCache *cache, GfxCompare *compare, GfxPorts *ports, GfxPaint16 *paint16, GfxScreen *screen, GfxPalette *palette, GfxCursor *cursor, GfxTransitions *transitions);
 	virtual ~GfxAnimate();
 
 	bool isFastCastEnabled() {
@@ -124,6 +124,7 @@ private:
 	EngineState *_s;
 	ScriptPatcher *_scriptPatcher;
 	GfxCache *_cache;
+	GfxCompare *_compare;
 	GfxPorts *_ports;
 	GfxPaint16 *_paint16;
 	GfxScreen *_screen;
diff --git a/engines/sci/graphics/cursor.cpp b/engines/sci/graphics/cursor.cpp
index ae471594b41..f2e446b6e43 100644
--- a/engines/sci/graphics/cursor.cpp
+++ b/engines/sci/graphics/cursor.cpp
@@ -178,7 +178,7 @@ void GfxCursor::kernelSetShape(GuiResourceId resourceId) {
 	CursorMan.replaceCursor(rawBitmap->getUnsafeDataAt(0, heightWidth * heightWidth), heightWidth, heightWidth, hotspot.x, hotspot.y, SCI_CURSOR_SCI0_TRANSPARENCYCOLOR);
 	if (g_system->getScreenFormat().bytesPerPixel != 1) {
 		byte buf[3*256];
-		g_sci->_gfxScreen->grabPalette(buf, 0, 256);
+		_screen->grabPalette(buf, 0, 256);
 		CursorMan.replaceCursorPalette(buf, 0, 256);
 	}
 
@@ -255,7 +255,7 @@ void GfxCursor::kernelSetView(GuiResourceId viewNum, int loopNum, int celNum, Co
 	}
 	if (g_system->getScreenFormat().bytesPerPixel != 1) {
 		byte buf[3*256];
-		g_sci->_gfxScreen->grabPalette(buf, 0, 256);
+		_screen->grabPalette(buf, 0, 256);
 		CursorMan.replaceCursorPalette(buf, 0, 256);
 	}
 
@@ -412,7 +412,7 @@ void GfxCursor::refreshPosition() {
 		CursorMan.replaceCursor(_cursorSurface->getUnsafeDataAt(0, cursorCelInfo->width * cursorCelInfo->height), cursorCelInfo->width, cursorCelInfo->height, cursorHotspot.x, cursorHotspot.y, cursorCelInfo->clearKey);
 		if (g_system->getScreenFormat().bytesPerPixel != 1) {
 			byte buf[3*256];
-			g_sci->_gfxScreen->grabPalette(buf, 0, 256);
+			_screen->grabPalette(buf, 0, 256);
 			CursorMan.replaceCursorPalette(buf, 0, 256);
 		}
 	}
diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp
index e3d6d5c4bfb..4c717398526 100644
--- a/engines/sci/graphics/frameout.cpp
+++ b/engines/sci/graphics/frameout.cpp
@@ -328,7 +328,7 @@ void GfxFrameout::kernelDeletePlane(const reg_t object) {
 		_planes.erase(plane);
 	} else {
 		plane->_created = 0;
-		plane->_deleted = g_sci->_gfxFrameout->getScreenCount();
+		plane->_deleted = getScreenCount();
 	}
 }
 
diff --git a/engines/sci/graphics/maciconbar.cpp b/engines/sci/graphics/maciconbar.cpp
index 383f3c32597..640a3dd5fa9 100644
--- a/engines/sci/graphics/maciconbar.cpp
+++ b/engines/sci/graphics/maciconbar.cpp
@@ -34,7 +34,8 @@
 
 namespace Sci {
 
-GfxMacIconBar::GfxMacIconBar() {
+GfxMacIconBar::GfxMacIconBar(ResourceManager *resMan, EventManager *eventMan, SegManager *segMan, GfxScreen *screen, GfxPalette *palette) :
+	_resMan(resMan), _eventMan(eventMan), _segMan(segMan), _screen(screen), _palette(palette)  {
 	if (g_sci->getGameId() == GID_FREDDYPHARKAS)
 		_inventoryIndex = 5;
 	else
@@ -43,7 +44,7 @@ GfxMacIconBar::GfxMacIconBar() {
 	_inventoryIcon = nullptr;
 	_allDisabled = true;
 	
-	_isUpscaled = (g_sci->_gfxScreen->getUpscaledHires() == GFX_SCREEN_UPSCALED_640x400);
+	_isUpscaled = (_screen->getUpscaledHires() == GFX_SCREEN_UPSCALED_640x400);
 }
 
 GfxMacIconBar::~GfxMacIconBar() {
@@ -83,7 +84,7 @@ void GfxMacIconBar::freeIcons() {
 
 void GfxMacIconBar::addIcon(reg_t obj) {
 	IconBarItem item;
-	uint32 iconIndex = readSelectorValue(g_sci->getEngineState()->_segMan, obj, SELECTOR(iconIndex));
+	uint32 iconIndex = readSelectorValue(_segMan, obj, SELECTOR(iconIndex));
 
 	item.object = obj;
 	item.nonSelectedImage = createImage(iconIndex, false);
@@ -99,7 +100,7 @@ void GfxMacIconBar::addIcon(reg_t obj) {
 	uint16 x = _iconBarItems.empty() ? 0 : _iconBarItems.back().rect.right;
 
 	// Start below the main viewing window and add a two pixel buffer
-	uint16 y = g_sci->_gfxScreen->getHeight() + 2;
+	uint16 y = _screen->getHeight() + 2;
 
 	if (item.nonSelectedImage)
 		item.rect = Common::Rect(x, y, MIN<uint32>(x + item.nonSelectedImage->w, 320), y + item.nonSelectedImage->h);
@@ -249,7 +250,7 @@ void GfxMacIconBar::setInventoryIcon(int16 icon) {
 }
 
 Graphics::Surface *GfxMacIconBar::loadPict(ResourceId id) {
-	Resource *res = g_sci->getResMan()->findResource(id, false);
+	Resource *res = _resMan->findResource(id, false);
 
 	if (!res || res->size() == 0)
 		return nullptr;
@@ -282,7 +283,7 @@ void GfxMacIconBar::remapColors(Graphics::Surface *surf, const byte *palette) {
 		byte g = palette[color * 3 + 1];
 		byte b = palette[color * 3 + 2];
 
-		*pixels++ = g_sci->_gfxPalette16->findMacIconBarColor(r, g, b);
+		*pixels++ = _palette->findMacIconBarColor(r, g, b);
 	}
 }
 
@@ -291,7 +292,6 @@ bool GfxMacIconBar::pointOnIcon(uint32 iconIndex, Common::Point point) {
 }
 
 bool GfxMacIconBar::handleEvents(SciEvent evt, reg_t &iconObj) {
-	EventManager *evtMgr = g_sci->getEventManager();
 	iconObj = NULL_REG;
 
 	// Not a mouse press
@@ -299,7 +299,7 @@ bool GfxMacIconBar::handleEvents(SciEvent evt, reg_t &iconObj) {
 		return false;
 
 	// If the mouse is not over the icon bar, return
-	if (evt.mousePos.y < g_sci->_gfxScreen->getHeight())
+	if (evt.mousePos.y < _screen->getHeight())
 		return false;
 
 	// Mouse press on the icon bar, check the icon rectangles
@@ -325,7 +325,7 @@ bool GfxMacIconBar::handleEvents(SciEvent evt, reg_t &iconObj) {
 			drawIcon(iconNr, isSelected);
 		}
 
-		evt = evtMgr->getSciEvent(kSciEventMouseRelease);
+		evt = _eventMan->getSciEvent(kSciEventMouseRelease);
 		g_system->delayMillis(10);
 	}
 
diff --git a/engines/sci/graphics/maciconbar.h b/engines/sci/graphics/maciconbar.h
index b8941e89529..7900ec9ef26 100644
--- a/engines/sci/graphics/maciconbar.h
+++ b/engines/sci/graphics/maciconbar.h
@@ -35,7 +35,7 @@ namespace Sci {
 
 class GfxMacIconBar {
 public:
-	GfxMacIconBar();
+	GfxMacIconBar(ResourceManager *resMan, EventManager *eventMan, SegManager *segMan, GfxScreen *screen, GfxPalette *palette);
 	~GfxMacIconBar();
 
 	void initIcons(uint16 count, reg_t *objs);
@@ -45,6 +45,12 @@ public:
 	bool handleEvents(SciEvent evt, reg_t &iconObj);
 
 private:
+	ResourceManager *_resMan;
+	EventManager *_eventMan;
+	SegManager *_segMan;
+	GfxScreen *_screen;
+	GfxPalette *_palette;
+
 	struct IconBarItem {
 		reg_t object;
 		Graphics::Surface *nonSelectedImage;
diff --git a/engines/sci/graphics/paint16.cpp b/engines/sci/graphics/paint16.cpp
index 6cd0cc37ca3..a86e03e22e9 100644
--- a/engines/sci/graphics/paint16.cpp
+++ b/engines/sci/graphics/paint16.cpp
@@ -630,12 +630,12 @@ reg_t GfxPaint16::kernelDisplay(const char *text, uint16 languageSplitter, int a
 }
 
 reg_t GfxPaint16::kernelPortraitLoad(const Common::String &resourceName) {
-	//Portrait *myPortrait = new Portrait(g_sci->getResMan(), _screen, _palette, resourceName);
+	//Portrait *myPortrait = new Portrait(_resMan, _screen, _palette, resourceName);
 	return NULL_REG;
 }
 
 void GfxPaint16::kernelPortraitShow(const Common::String &resourceName, Common::Point position, uint16 resourceId, uint16 noun, uint16 verb, uint16 cond, uint16 seq) {
-	Portrait *myPortrait = new Portrait(g_sci->getResMan(), g_sci->getEventManager(), _screen, _palette, _audio, resourceName);
+	Portrait *myPortrait = new Portrait(_resMan, g_sci->getEventManager(), _screen, _palette, _audio, resourceName);
 	// TODO: cache portraits
 	// adjust given coordinates to curPort (but dont adjust coordinates on upscaledHires_Save_Box and give us hires coordinates
 	//  on kDrawCel, yeah this whole stuff makes sense)
diff --git a/engines/sci/graphics/text16.cpp b/engines/sci/graphics/text16.cpp
index d409af4e015..764a54ce1ee 100644
--- a/engines/sci/graphics/text16.cpp
+++ b/engines/sci/graphics/text16.cpp
@@ -908,7 +908,7 @@ void GfxText16::macTextSize(const Common::String &text, GuiResourceId sciFontId,
 	*textHeight = lineCount * (font->getFontHeight() + font->getFontLeading());
 
 	if (_macFontManager->usesSystemFonts() && 
-		g_sci->_gfxScreen->getUpscaledHires() == GFX_SCREEN_UPSCALED_640x400) {
+		_screen->getUpscaledHires() == GFX_SCREEN_UPSCALED_640x400) {
 		// QFG1VGA and LSL6 make this adjustment when the large font is used.
 		*textHeight -= (lineCount + 1);
 	}
@@ -927,7 +927,7 @@ void GfxText16::macDraw(const Common::String &text, Common::Rect rect, TextAlign
 	// Use the large font in hires mode, otherwise use the small font
 	const Graphics::Font *font;
 	uint16 scale;
-	if (g_sci->_gfxScreen->getUpscaledHires() == GFX_SCREEN_UPSCALED_640x400) {
+	if (_screen->getUpscaledHires() == GFX_SCREEN_UPSCALED_640x400) {
 		font = _macFontManager->getLargeFont(sciFontId);
 		scale = 2;
 	} else {
@@ -936,7 +936,7 @@ void GfxText16::macDraw(const Common::String &text, Common::Rect rect, TextAlign
 	}
 
 	if (color == -1) {
-		color = g_sci->_gfxPorts->_curPort->penClr;
+		color = _ports->_curPort->penClr;
 	}
 
 	rect.left *= scale;
@@ -946,7 +946,7 @@ void GfxText16::macDraw(const Common::String &text, Common::Rect rect, TextAlign
 
 	// Draw each line of text
 	int16 maxWidth = rect.width();
-	int16 y = (g_sci->_gfxPorts->_curPort->top * scale) + rect.top;
+	int16 y = (_ports->_curPort->top * scale) + rect.top;
 	for (uint i = 0; i < text.size(); ++i) {
 		int16 lineWidth;
 		int16 lineCharCount = macGetLongest(text, i, font, maxWidth, &lineWidth);
@@ -962,10 +962,10 @@ void GfxText16::macDraw(const Common::String &text, Common::Rect rect, TextAlign
 		}
 
 		// Draw each character in the line
-		int16 x = (g_sci->_gfxPorts->_curPort->left * scale) + rect.left + offset;
+		int16 x = (_ports->_curPort->left * scale) + rect.left + offset;
 		for (int16 j = 0; j < lineCharCount; ++j) {
 			char ch = text[i + j];
-			g_sci->_gfxScreen->putMacChar(font, x, y, ch, color);
+			_screen->putMacChar(font, x, y, ch, color);
 			x += font->getCharWidth(ch);
 		}
 
diff --git a/engines/sci/metaengine.cpp b/engines/sci/metaengine.cpp
index 811f2bead01..6ebc45011b5 100644
--- a/engines/sci/metaengine.cpp
+++ b/engines/sci/metaengine.cpp
@@ -443,9 +443,9 @@ Common::Error SciEngine::loadGameState(int slot) {
 
 Common::Error SciEngine::saveGameState(int slot, const Common::String &desc, bool isAutosave) {
 	const char *version = "";
-	g_sci->_soundCmd->pauseAll(false); // unpause music (we can't have it paused during save)
+	_soundCmd->pauseAll(false); // unpause music (we can't have it paused during save)
 	const bool res = gamestate_save(_gamestate, slot, desc, version);
-	g_sci->_soundCmd->pauseAll(true); // pause music
+	_soundCmd->pauseAll(true); // pause music
 	return res ? Common::kNoError : Common::kWritingFailed;
 }
 
diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp
index 3d7179007cc..e048d582cd9 100644
--- a/engines/sci/sci.cpp
+++ b/engines/sci/sci.cpp
@@ -587,9 +587,6 @@ bool SciEngine::initGame() {
 }
 
 void SciEngine::initGraphics() {
-	if (hasMacIconBar())
-		_gfxMacIconBar = new GfxMacIconBar();
-
 #ifdef ENABLE_SCI32
 	if (getSciVersion() >= SCI_VERSION_2) {
 		_gfxPalette32 = new GfxPalette32(_resMan);
@@ -630,7 +627,7 @@ void SciEngine::initGraphics() {
 		_gfxCompare = new GfxCompare(_gamestate->_segMan, _gfxCache, _gfxScreen, _gfxCoordAdjuster);
 		_gfxTransitions = new GfxTransitions(_gfxScreen, _gfxPalette16);
 		_gfxPaint16 = new GfxPaint16(_resMan, _gamestate->_segMan, _gfxCache, _gfxPorts, _gfxCoordAdjuster, _gfxScreen, _gfxPalette16, _gfxTransitions, _audio);
-		_gfxAnimate = new GfxAnimate(_gamestate, _scriptPatcher, _gfxCache, _gfxPorts, _gfxPaint16, _gfxScreen, _gfxPalette16, _gfxCursor, _gfxTransitions);
+		_gfxAnimate = new GfxAnimate(_gamestate, _scriptPatcher, _gfxCache, _gfxCompare, _gfxPorts, _gfxPaint16, _gfxScreen, _gfxPalette16, _gfxCursor, _gfxTransitions);
 		_gfxText16 = new GfxText16(_gfxCache, _gfxPorts, _gfxPaint16, _gfxScreen, _gfxMacFontManager);
 		_gfxControls16 = new GfxControls16(_gamestate->_segMan, _gfxPorts, _gfxPaint16, _gfxText16, _gfxScreen);
 		_gfxMenu = new GfxMenu(_eventMan, _gamestate->_segMan, _gfxPorts, _gfxPaint16, _gfxText16, _gfxScreen, _gfxCursor);
@@ -640,6 +637,9 @@ void SciEngine::initGraphics() {
 		_gfxPorts->init(_features->usesOldGfxFunctions(), _gfxPaint16, _gfxText16);
 		_gfxPaint16->init(_gfxAnimate, _gfxText16);
 
+		if (hasMacIconBar()) {
+			_gfxMacIconBar = new GfxMacIconBar(_resMan, _eventMan, _gamestate->_segMan, _gfxScreen, _gfxPalette16);
+		}
 #ifdef ENABLE_SCI32
 	}
 #endif
@@ -718,8 +718,7 @@ void SciEngine::runGame() {
 void SciEngine::errorString(const char *buf_input, char *buf_output, int buf_output_size) {
 	// Detailed context can only be included if VM execution has begun.
 	EngineState *s = _gamestate;
-	Kernel *kernel = g_sci ? g_sci->getKernel() : nullptr;
-	if (s != nullptr && !s->_executionStack.empty() && kernel != nullptr) {
+	if (s != nullptr && !s->_executionStack.empty() && _kernel != nullptr) {
 		// Determine the name of the current function and the pc
 		Common::String function;
 		// Query the top-most stack frame even if it's not committed yet within the VM cycle.
@@ -729,7 +728,7 @@ void SciEngine::errorString(const char *buf_input, char *buf_output, int buf_out
 		case EXEC_STACK_TYPE_CALL: { // Script function
 			if (call.debugSelector != -1) {
 				const char *objectName = s->_segMan->getObjectName(call.sendp);
-				function = Common::String::format("%s::%s", objectName, kernel->getSelectorName(call.debugSelector).c_str());
+				function = Common::String::format("%s::%s", objectName, _kernel->getSelectorName(call.debugSelector).c_str());
 			} else if (call.debugExportId != -1) {
 				function = Common::String::format("export %d", call.debugExportId);
 			} else if (call.debugLocalCallOffset != -1) {
@@ -739,9 +738,9 @@ void SciEngine::errorString(const char *buf_input, char *buf_output, int buf_out
 		}
 		case EXEC_STACK_TYPE_KERNEL: { // Kernel function
 			if (call.debugKernelSubFunction == -1) {
-				function = Common::String::format("k%s", kernel->getKernelName(call.debugKernelFunction).c_str());
+				function = Common::String::format("k%s", _kernel->getKernelName(call.debugKernelFunction).c_str());
 			} else {
-				function = Common::String::format("k%s", kernel->getKernelName(call.debugKernelFunction, call.debugKernelSubFunction).c_str());
+				function = Common::String::format("k%s", _kernel->getKernelName(call.debugKernelFunction, call.debugKernelSubFunction).c_str());
 			}
 			// Kernel calls do not have a pc. walk the stack back to the most recent for script number.
 			Common::List<ExecStack>::const_iterator it;
@@ -1055,7 +1054,7 @@ void SciEngine::loadMacFonts() {
 	// If we're unable to load Mac fonts, then fall back to using SCI fonts.
 	// Mac font support was added after these games were supported, so it's
 	// important to not require that fonts be present.
-	switch (g_sci->getGameId()) {
+	switch (getGameId()) {
 	case GID_CASTLEBRAIN:
 	case GID_FREDDYPHARKAS:
 	// case GID_KQ5: // not supported yet




More information about the Scummvm-git-logs mailing list