[Scummvm-git-logs] scummvm master -> 07bc3e58e8802a1ac15d485f469def093c5743ac

djsrv dservilla at gmail.com
Fri Jul 3 19:57:40 UTC 2020


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

Summary:
2c41b3f291 DIRECTOR: Give Stage ownership of movies
07bc3e58e8 DIRECTOR: Remove vm arg from constructors


Commit: 2c41b3f291b6e5a3f190ea661560f3a1a5c39c05
    https://github.com/scummvm/scummvm/commit/2c41b3f291b6e5a3f190ea661560f3a1a5c39c05
Author: djsrv (dservilla at gmail.com)
Date: 2020-07-03T15:55:14-04:00

Commit Message:
DIRECTOR: Give Stage ownership of movies

Changed paths:
    engines/director/director.cpp
    engines/director/director.h
    engines/director/lingo/lingo-funcs.cpp
    engines/director/resource.cpp
    engines/director/score.cpp
    engines/director/stage.cpp
    engines/director/stage.h
    engines/director/tests.cpp


diff --git a/engines/director/director.cpp b/engines/director/director.cpp
index 12d999609f..f4f1b36c6c 100644
--- a/engines/director/director.cpp
+++ b/engines/director/director.cpp
@@ -23,9 +23,7 @@
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
 #include "common/error.h"
-#include "common/substream.h"
-
-#include "common/macresman.h"
+#include "common/file.h"
 
 #include "graphics/macgui/macwindowmanager.h"
 
@@ -36,7 +34,6 @@
 #include "director/score.h"
 #include "director/sound.h"
 #include "director/stage.h"
-#include "director/util.h"
 #include "director/lingo/lingo.h"
 
 namespace Director {
@@ -81,19 +78,11 @@ DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gam
 	// Load key codes
 	loadKeyCodes();
 
-	_currentMovie = nullptr;
 	_soundManager = nullptr;
 	_currentPalette = nullptr;
 	_currentPaletteLength = 0;
 	_lingo = nullptr;
 
-	_mainArchive = nullptr;
-	_macBinary = nullptr;
-
-	_movies = nullptr;
-
-	_nextMovie.frameI = -1;
-
 	_wm = nullptr;
 
 	const Common::FSNode gameDataDir(ConfMan.get("path"));
@@ -114,26 +103,19 @@ DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gam
 
 	_draggingSprite = false;
 	_draggingSpriteId = 0;
-
-	_newMovieStarted = true;
 }
 
 DirectorEngine::~DirectorEngine() {
-	delete _currentMovie;
-
-	_wm->removeWindow(_currentStage);
-
-	if (_macBinary) {
-		delete _macBinary;
-		_macBinary = nullptr;
-	}
-
 	delete _soundManager;
 	delete _lingo;
 	delete _wm;
 	delete _surface;
 }
 
+Archive *DirectorEngine::getMainArchive() const { return _currentStage->getMainArchive(); }
+Movie *DirectorEngine::getCurrentMovie() const { return _currentStage->getCurrentMovie(); }
+Common::String DirectorEngine::getCurrentPath() const { return _currentStage->getCurrentPath(); }
+
 Common::Error DirectorEngine::run() {
 	debug("Starting v%d Director game", getVersion());
 
@@ -143,14 +125,13 @@ Common::Error DirectorEngine::run() {
 
 	_currentPalette = nullptr;
 
-	_macBinary = nullptr;
 	_soundManager = nullptr;
 
 	wmMode = debugChannelSet(-1, kDebugDesktop) ? wmModeDesktop : wmModeFullscreen;
 	_wm = new Graphics::MacWindowManager(wmMode, &_director3QuickDrawPatterns);
 	_wm->setEngine(this);
 
-	_currentStage = new Stage(_wm->getNextId(), false, false, false, _wm);
+	_currentStage = new Stage(_wm->getNextId(), false, false, false, _wm, this);
 
 	if (!debugChannelSet(-1, kDebugDesktop))
 		_currentStage->disableBorder();
@@ -164,16 +145,12 @@ Common::Error DirectorEngine::run() {
 	_soundManager = new DirectorSound(this);
 
 	if (getGameGID() == GID_TEST) {
-		runTests();
+		_currentStage->runTests();
 		return Common::kNoError;
 	} else if (getGameGID() == GID_TESTALL) {
-		enqueueAllMovies();
+		_currentStage->enqueueAllMovies();
 	}
 
-	// FIXME
-	//_mainArchive = new RIFFArchive();
-	//_mainArchive->openFile("bookshelf_example.mmm");
-
 	if (getPlatform() == Common::kPlatformWindows)
 		_machineType = 256; // IBM PC-type machine
 
@@ -191,141 +168,14 @@ Common::Error DirectorEngine::run() {
 		_sharedCastFile = "Shared.dir";
 	}
 
-	debug(0, "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\nObtaining score name\n");
-
-	if (getGameGID() == GID_TESTALL)  {
-		_nextMovie = getNextMovieFromQueue();
-		loadInitialMovie(_nextMovie.movie);
-	} else {
-		loadInitialMovie(getEXEName());
-
-		if (!_mainArchive) {
-			warning("Cannot open main movie");
-			return Common::kNoGameDataFoundError;
-		}
-
-		// Let's check if it is a projector file
-		// So far tested with Spaceship Warlock, D2
-		if (_mainArchive->hasResource(MKTAG('B', 'N', 'D', 'L'), "Projector")) {
-			warning("Detected Projector file");
-
-			if (_mainArchive->hasResource(MKTAG('X', 'C', 'O', 'D'), -1)) {
-				Common::Array<uint16> xcod = _mainArchive->getResourceIDList(MKTAG('X', 'C', 'O', 'D'));
-				for (Common::Array<uint16>::iterator iterator = xcod.begin(); iterator != xcod.end(); ++iterator) {
-					Resource res = _mainArchive->getResourceDetail(MKTAG('X', 'C', 'O', 'D'), *iterator);
-					debug(0, "Detected XObject '%s'", res.name.c_str());
-					g_lingo->openXLib(res.name, kXObj);
-				}
-			}
-
-			if (_mainArchive->hasResource(MKTAG('S', 'T', 'R', '#'), 0)) {
-				_currentMovie->setArchive(_mainArchive);
-
-				Common::SeekableSubReadStreamEndian *name = _mainArchive->getResource(MKTAG('S', 'T', 'R', '#'), 0);
-				int num = name->readUint16();
-				if (num != 1) {
-					warning("Incorrect number of strings in Projector file");
-				}
-
-				if (num == 0)
-					error("No strings in Projector file");
-
-				Common::String sname = name->readPascalString();
-
-				_nextMovie.movie = pathMakeRelative(sname);
-				warning("Replaced score name with: %s (from %s)", _nextMovie.movie.c_str(), sname.c_str());
-
-				delete _currentMovie;
-				_currentMovie = nullptr;
-
-				delete name;
-			}
-		}
-	}
-
-	if (_currentMovie)
-		_currentMovie->setArchive(_mainArchive);
+	Common::Error err = _currentStage->loadInitialMovie();
+	if (err.getCode() != Common::kNoError)
+		return err;
 
 	bool loop = true;
 
 	while (loop) {
-		loop = false;
-
-		if (_currentMovie) {
-			debug(0, "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
-			debug(0, "@@@@   Movie name '%s' in '%s'", _currentMovie->getMacName().c_str(), _currentPath.c_str());
-			debug(0, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
-
-			bool goodMovie = _currentMovie->loadArchive();
-
-			// If we came in a loop, then skip as requested
-			if (!_nextMovie.frameS.empty()) {
-				_currentMovie->getScore()->setStartToLabel(_nextMovie.frameS);
-				_nextMovie.frameS.clear();
-			}
-
-			if (_nextMovie.frameI != -1) {
-				_currentMovie->getScore()->setCurrentFrame(_nextMovie.frameI);
-				_nextMovie.frameI = -1;
-			}
-
-			if (!debugChannelSet(-1, kDebugCompileOnly) && goodMovie) {
-				debugC(1, kDebugEvents, "Starting playback of movie '%s'", _currentMovie->getMacName().c_str());
-
-				_currentMovie->getScore()->startLoop();
-
-				debugC(1, kDebugEvents, "Finished playback of movie '%s'", _currentMovie->getMacName().c_str());
-			}
-		}
-
-		if (getGameGID() == GID_TESTALL) {
-			_nextMovie = getNextMovieFromQueue();
-		}
-
-		// If a loop was requested, do it
-		if (!_nextMovie.movie.empty()) {
-			_newMovieStarted = true;
-
-			_currentPath = getPath(_nextMovie.movie, _currentPath);
-
-			Cast *sharedCast = nullptr;
-			if (_currentMovie) {
-				sharedCast = _currentMovie->getSharedCast();
-				_currentMovie->_sharedCast = nullptr;
-			}
-
-			delete _currentMovie;
-			_currentMovie = nullptr;
-
-			Archive *mov = openMainArchive(_currentPath + Common::lastPathComponent(_nextMovie.movie, '/'));
-
-			if (!mov) {
-				warning("nextMovie: No movie is loaded");
-
-				if (getGameGID() == GID_TESTALL) {
-					loop = true;
-					continue;
-				}
-
-				return Common::kNoError;
-			}
-
-			_currentMovie = new Movie(this);
-			_currentMovie->setArchive(mov);
-			debug(0, "Switching to movie '%s'", _currentMovie->getMacName().c_str());
-
-			_lingo->resetLingo();
-			if (sharedCast && sharedCast->_castArchive
-					&& sharedCast->_castArchive->getFileName().equalsIgnoreCase(_currentPath + _sharedCastFile)) {
-				_currentMovie->_sharedCast = sharedCast;
-			} else {
-				delete sharedCast;
-				_currentMovie->loadSharedCastsFrom(_currentPath + _sharedCastFile);
-			}
-
-			_nextMovie.movie.clear();
-			loop = true;
-		}
+		loop = _currentStage->step();
 	}
 
 	return Common::kNoError;
diff --git a/engines/director/director.h b/engines/director/director.h
index b1e7b7bbf3..786ea10591 100644
--- a/engines/director/director.h
+++ b/engines/director/director.h
@@ -135,11 +135,11 @@ public:
 	Common::String getEXEName() const;
 	DirectorSound *getSoundManager() const { return _soundManager; }
 	Graphics::MacWindowManager *getMacWindowManager() const { return _wm; }
-	Archive *getMainArchive() const { return _mainArchive; }
+	Archive *getMainArchive() const;
 	Lingo *getLingo() const { return _lingo; }
 	Stage *getStage() const { return _currentStage; }
-	Movie *getCurrentMovie() const { return _currentMovie; }
-	Common::String getCurrentPath() const { return _currentPath; }
+	Movie *getCurrentMovie() const;
+	Common::String getCurrentPath() const;
 	void setPalette(int id);
 	void setPalette(byte *palette, uint16 count);
 	bool hasFeature(EngineFeature f) const override;
@@ -153,8 +153,6 @@ public:
 
 	void loadKeyCodes();
 
-	void loadInitialMovie(const Common::String movie);
-	Archive *openMainArchive(const Common::String movie);
 	Archive *createArchive();
 
 	// events.cpp
@@ -165,8 +163,6 @@ public:
 	void waitForClick();
 
 public:
-	Common::HashMap<Common::String, Score *> *_movies;
-
 	Common::RandomSource _rnd;
 	Graphics::ManagedSurface *_surface;
 	Graphics::MacWindowManager *_wm;
@@ -180,10 +176,7 @@ public:
 	bool _playbackPaused;
 	bool _skipFrameAdvance;
 
-	MovieReference _nextMovie;
-	Common::List<MovieReference> _movieStack;
-
-	bool _newMovieStarted;
+	Common::String _sharedCastFile;
 
 protected:
 	Common::Error run() override;
@@ -191,49 +184,21 @@ protected:
 private:
 	const DirectorGameDescription *_gameDescription;
 
-	Common::HashMap<Common::String, Movie *> *scanMovies(const Common::String &folder);
-	void loadEXE(const Common::String movie);
-	void loadEXEv3(Common::SeekableReadStream *stream);
-	void loadEXEv4(Common::SeekableReadStream *stream);
-	void loadEXEv5(Common::SeekableReadStream *stream);
-	void loadEXEv7(Common::SeekableReadStream *stream);
-	void loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset);
-	void loadMac(const Common::String movie);
-
-	Archive *_mainArchive;
-	Common::MacResManager *_macBinary;
 	DirectorSound *_soundManager;
 	byte *_currentPalette;
 	uint16 _currentPaletteLength;
 	Lingo *_lingo;
 
 	Stage *_currentStage;
-	Movie *_currentMovie;
-	Common::String _currentPath;
 
 	Graphics::MacPatterns _director3Patterns;
 	Graphics::MacPatterns _director3QuickDrawPatterns;
 
 	Common::HashMap<int, PaletteV4 *> _director4Palettes;
 
-	Common::String _sharedCastFile;
-
 	bool _draggingSprite;
 	uint16 _draggingSpriteId;
 	Common::Point _draggingSpritePos;
-
-	Common::StringArray _movieQueue;
-
-
-// tests.cpp
-private:
-	void testFontScaling();
-	void testFonts();
-
-	void enqueueAllMovies();
-	MovieReference getNextMovieFromQueue();
-
-	void runTests();
 };
 
 extern DirectorEngine *g_director;
diff --git a/engines/director/lingo/lingo-funcs.cpp b/engines/director/lingo/lingo-funcs.cpp
index 4fa622cd42..c12e86ea04 100644
--- a/engines/director/lingo/lingo-funcs.cpp
+++ b/engines/director/lingo/lingo-funcs.cpp
@@ -33,6 +33,7 @@
 #include "director/movie.h"
 #include "director/score.h"
 #include "director/sound.h"
+#include "director/stage.h"
 #include "director/util.h"
 
 #include "director/lingo/lingo.h"
@@ -226,21 +227,23 @@ void Lingo::func_goto(Datum &frame, Datum &movie) {
 			return;
 		}
 
-		_vm->_nextMovie.movie = cleanedFilename;
-		_vm->getCurrentMovie()->getScore()->_stopPlay = true;
+		Stage *stage = _vm->getStage();
 
-		_vm->_nextMovie.frameS.clear();
-		_vm->_nextMovie.frameI = -1;
+		stage->_nextMovie.movie = cleanedFilename;
+		stage->getCurrentMovie()->getScore()->_stopPlay = true;
+
+		stage->_nextMovie.frameS.clear();
+		stage->_nextMovie.frameI = -1;
 
 		if (frame.type == VOID)
 			return;
 
 		if (frame.type == STRING) {
-			_vm->_nextMovie.frameS = *frame.u.s;
+			stage->_nextMovie.frameS = *frame.u.s;
 			return;
 		}
 
-		_vm->_nextMovie.frameI = frame.asInt();
+		stage->_nextMovie.frameI = frame.asInt();
 
 		return;
 	}
@@ -289,6 +292,8 @@ void Lingo::func_gotoprevious() {
 
 void Lingo::func_play(Datum &frame, Datum &movie) {
 	MovieReference ref;
+	Stage *stage = _vm->getStage();
+
 
 	// play #done
 	if (frame.type == SYMBOL) {
@@ -296,12 +301,12 @@ void Lingo::func_play(Datum &frame, Datum &movie) {
 			warning("Lingo::func_play: unknown symbol: #%s", frame.u.s->c_str());
 			return;
 		}
-		if (_vm->_movieStack.empty()) {	// No op if no nested movies
+		if (stage->_movieStack.empty()) {	// No op if no nested movies
 			return;
 		}
-		ref = _vm->_movieStack.back();
+		ref = stage->_movieStack.back();
 
-		_vm->_movieStack.pop_back();
+		stage->_movieStack.pop_back();
 
 		Datum m, f;
 
@@ -327,7 +332,7 @@ void Lingo::func_play(Datum &frame, Datum &movie) {
 
 	ref.frameI = _vm->getCurrentMovie()->getScore()->getCurrentFrame();
 
-	_vm->_movieStack.push_back(ref);
+	stage->_movieStack.push_back(ref);
 
 	func_goto(frame, movie);
 }
diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp
index a7d13ceae9..b9b7d70c7a 100644
--- a/engines/director/resource.cpp
+++ b/engines/director/resource.cpp
@@ -21,13 +21,16 @@
  */
 
 #include "common/config-manager.h"
-#include "common/macresman.h"
+#include "common/error.h"
 #include "common/file.h"
+#include "common/macresman.h"
+#include "common/substream.h"
 
 #include "director/director.h"
 #include "director/cast.h"
 #include "director/castmember.h"
 #include "director/movie.h"
+#include "director/stage.h"
 #include "director/lingo/lingo.h"
 #include "director/util.h"
 
@@ -47,21 +50,72 @@ Archive *DirectorEngine::createArchive() {
 	}
 }
 
-void DirectorEngine::loadInitialMovie(const Common::String movie) {
-	if (getPlatform() == Common::kPlatformWindows)
+Common::Error Stage::loadInitialMovie() {
+	debug(0, "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\nObtaining movie name\n");
+	Common::String movie = (_vm->getGameGID() == GID_TESTALL) ? getNextMovieFromQueue().movie : _vm->getEXEName();
+
+	if (g_director->getPlatform() == Common::kPlatformWindows)
 		loadEXE(movie);
 	else
 		loadMac(movie);
-	
-	_currentMovie = new Movie(this);
-	_currentPath = getPath(getEXEName(), _currentPath);
-	_currentMovie->loadSharedCastsFrom(_currentPath + _sharedCastFile);
+
+	if (!_mainArchive) {
+		warning("Cannot open main movie");
+		return Common::kNoGameDataFoundError;
+	}
+
+	_currentMovie = new Movie(_vm);
+	_currentPath = getPath(movie, _currentPath);
+	_currentMovie->loadSharedCastsFrom(_currentPath + g_director->_sharedCastFile);
+
+	// Let's check if it is a projector file
+	// So far tested with Spaceship Warlock, D2
+	if (_mainArchive->hasResource(MKTAG('B', 'N', 'D', 'L'), "Projector")) {
+		warning("Detected Projector file");
+
+		if (_mainArchive->hasResource(MKTAG('X', 'C', 'O', 'D'), -1)) {
+			Common::Array<uint16> xcod = _mainArchive->getResourceIDList(MKTAG('X', 'C', 'O', 'D'));
+			for (Common::Array<uint16>::iterator iterator = xcod.begin(); iterator != xcod.end(); ++iterator) {
+				Resource res = _mainArchive->getResourceDetail(MKTAG('X', 'C', 'O', 'D'), *iterator);
+				debug(0, "Detected XObject '%s'", res.name.c_str());
+				g_lingo->openXLib(res.name, kXObj);
+			}
+		}
+
+		if (_mainArchive->hasResource(MKTAG('S', 'T', 'R', '#'), 0)) {
+			_currentMovie->setArchive(_mainArchive);
+
+			Common::SeekableSubReadStreamEndian *name = _mainArchive->getResource(MKTAG('S', 'T', 'R', '#'), 0);
+			int num = name->readUint16();
+			if (num != 1) {
+				warning("Incorrect number of strings in Projector file");
+			}
+
+			if (num == 0)
+				error("No strings in Projector file");
+
+			Common::String sname = name->readPascalString();
+
+			_nextMovie.movie = pathMakeRelative(sname);
+			warning("Replaced score name with: %s (from %s)", _nextMovie.movie.c_str(), sname.c_str());
+
+			delete _currentMovie;
+			_currentMovie = nullptr;
+
+			delete name;
+		}
+	}
+
+	if (_currentMovie)
+		_currentMovie->setArchive(_mainArchive);
+
+	return Common::kNoError;
 }
 
-Archive *DirectorEngine::openMainArchive(const Common::String movie) {
+Archive *Stage::openMainArchive(const Common::String movie) {
 	debug(1, "openMainArchive(\"%s\")", movie.c_str());
 
-	_mainArchive = createArchive();
+	_mainArchive = g_director->createArchive();
 
 	if (!_mainArchive->openFile(movie)) {
 		delete _mainArchive;
@@ -74,15 +128,15 @@ Archive *DirectorEngine::openMainArchive(const Common::String movie) {
 	return _mainArchive;
 }
 
-void DirectorEngine::loadEXE(const Common::String movie) {
+void Stage::loadEXE(const Common::String movie) {
 	Common::SeekableReadStream *iniStream = SearchMan.createReadStreamForMember("LINGO.INI");
 	if (iniStream) {
 		char *script = (char *)calloc(iniStream->size() + 1, 1);
 		iniStream->read(script, iniStream->size());
 
-		_currentMovie = new Movie(this);
+		_currentMovie = new Movie(_vm);
 		_currentMovie->getMainLingoArch()->addCode(script, kMovieScript, 0);
-		_lingo->processEvent(kEventStartUp);
+		g_lingo->processEvent(kEventStartUp);
 		delete _currentMovie;
 		_currentMovie = nullptr;
 
@@ -93,7 +147,7 @@ void DirectorEngine::loadEXE(const Common::String movie) {
 
 	Common::SeekableReadStream *exeStream = SearchMan.createReadStreamForMember(movie);
 	if (!exeStream)
-		error("Failed to open EXE '%s'", getEXEName().c_str());
+		error("Failed to open EXE '%s'", g_director->getEXEName().c_str());
 
 	uint32 initialTag = exeStream->readUint32LE();
 	if (initialTag == MKTAG('R', 'I', 'F', 'X') || initialTag == MKTAG('X', 'F', 'I', 'R')) {
@@ -108,7 +162,7 @@ void DirectorEngine::loadEXE(const Common::String movie) {
 		exeStream->seek(-4, SEEK_END);
 		exeStream->seek(exeStream->readUint32LE());
 
-		switch (getVersion()) {
+		switch (g_director->getVersion()) {
 		case 2:
 		case 3:
 			loadEXEv3(exeStream);
@@ -123,14 +177,14 @@ void DirectorEngine::loadEXE(const Common::String movie) {
 			loadEXEv7(exeStream);
 			break;
 		default:
-			error("Unhandled Windows EXE version %d", getVersion());
+			error("Unhandled Windows EXE version %d", g_director->getVersion());
 		}
 	}
 
 	_mainArchive->setFileName(movie);
 }
 
-void DirectorEngine::loadEXEv3(Common::SeekableReadStream *stream) {
+void Stage::loadEXEv3(Common::SeekableReadStream *stream) {
 	uint16 entryCount = stream->readUint16LE();
 	if (entryCount != 1)
 		error("Unhandled multiple entry v3 EXE");
@@ -183,7 +237,7 @@ void DirectorEngine::loadEXEv3(Common::SeekableReadStream *stream) {
 	openMainArchive(mmmFileName);
 }
 
-void DirectorEngine::loadEXEv4(Common::SeekableReadStream *stream) {
+void Stage::loadEXEv4(Common::SeekableReadStream *stream) {
 	if (stream->readUint32BE() != MKTAG('P', 'J', '9', '3'))
 		error("Invalid projector tag found in v4 EXE");
 
@@ -201,7 +255,7 @@ void DirectorEngine::loadEXEv4(Common::SeekableReadStream *stream) {
 	loadEXERIFX(stream, rifxOffset);
 }
 
-void DirectorEngine::loadEXEv5(Common::SeekableReadStream *stream) {
+void Stage::loadEXEv5(Common::SeekableReadStream *stream) {
 	uint32 ver = stream->readUint32LE();
 
 	if (ver != MKTAG('P', 'J', '9', '5'))
@@ -223,7 +277,7 @@ void DirectorEngine::loadEXEv5(Common::SeekableReadStream *stream) {
 	loadEXERIFX(stream, rifxOffset);
 }
 
-void DirectorEngine::loadEXEv7(Common::SeekableReadStream *stream) {
+void Stage::loadEXEv7(Common::SeekableReadStream *stream) {
 	if (stream->readUint32LE() != MKTAG('P', 'J', '0', '0'))
 		error("Invalid projector tag found in v7 EXE");
 
@@ -237,15 +291,15 @@ void DirectorEngine::loadEXEv7(Common::SeekableReadStream *stream) {
 	loadEXERIFX(stream, rifxOffset);
 }
 
-void DirectorEngine::loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset) {
+void Stage::loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset) {
 	_mainArchive = new RIFXArchive();
 
 	if (!_mainArchive->openStream(stream, offset))
 		error("Failed to load RIFX from EXE");
 }
 
-void DirectorEngine::loadMac(const Common::String movie) {
-	if (getVersion() < 4) {
+void Stage::loadMac(const Common::String movie) {
+	if (g_director->getVersion() < 4) {
 		// The data is part of the resource fork of the executable
 		openMainArchive(movie);
 	} else {
diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index 846f774db2..feca0747d6 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -448,7 +448,7 @@ void Score::update() {
 	if (g_system->getMillis() < _nextFrameTime && !debugChannelSet(-1, kDebugFast)) {
 		_vm->_wm->renderZoomBox(true);
 
-		if (!_vm->_newMovieStarted)
+		if (!_vm->getStage()->_newMovieStarted)
 			_vm->_wm->draw();
 
 		return;
@@ -516,7 +516,7 @@ void Score::update() {
 
 	// Stage is drawn between the prepareFrame and enterFrame events (Lingo in a Nutshell, p.100)
 	renderFrame(_currentFrame);
-	_vm->_newMovieStarted = false;
+	_vm->getStage()->_newMovieStarted = false;
 
 	// Enter and exit from previous frame
 	if (!_vm->_playbackPaused) {
@@ -597,7 +597,7 @@ bool Score::renderTransition(uint16 frameId) {
 }
 
 void Score::renderSprites(uint16 frameId, RenderMode mode) {
-	if (_vm->_newMovieStarted)
+	if (_vm->getStage()->_newMovieStarted)
 		mode = kRenderForceUpdate;
 
 	for (uint16 i = 0; i < _channels.size(); i++) {
diff --git a/engines/director/stage.cpp b/engines/director/stage.cpp
index 44d1fc024f..a55945913d 100644
--- a/engines/director/stage.cpp
+++ b/engines/director/stage.cpp
@@ -21,23 +21,42 @@
  */
 
 #include "common/system.h"
+#include "common/macresman.h"
 
 #include "graphics/primitives.h"
 #include "graphics/macgui/macwindowmanager.h"
 
 #include "director/director.h"
+#include "director/cast.h"
+#include "director/lingo/lingo.h"
 #include "director/movie.h"
 #include "director/stage.h"
 #include "director/score.h"
 #include "director/castmember.h"
 #include "director/sprite.h"
+#include "director/util.h"
 
 namespace Director {
 
-Stage::Stage(int id, bool scrollable, bool resizable, bool editable, Graphics::MacWindowManager *wm)
+Stage::Stage(int id, bool scrollable, bool resizable, bool editable, Graphics::MacWindowManager *wm, DirectorEngine *vm)
 	: MacWindow(id, scrollable, resizable, editable, wm) {
+	_vm = vm;
 	_stageColor = 0;
 	_puppetTransition = nullptr;
+
+	_currentMovie = nullptr;
+	_mainArchive = nullptr;
+	_macBinary = nullptr;
+	_nextMovie.frameI = -1;
+	_newMovieStarted = true;
+}
+
+Stage::~Stage() {
+	delete _currentMovie;
+	if (_macBinary) {
+		delete _macBinary;
+		_macBinary = nullptr;
+	}
 }
 
 bool Stage::render(bool forceRedraw, Graphics::ManagedSurface *blitTo) {
@@ -203,4 +222,85 @@ Common::Point Stage::getMousePos() {
 	return g_system->getEventManager()->getMousePos() - Common::Point(_dims.left, _dims.top);
 }
 
+bool Stage::step() {
+	bool loop = false;
+
+	if (_currentMovie) {
+		debug(0, "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
+		debug(0, "@@@@   Movie name '%s' in '%s'", _currentMovie->getMacName().c_str(), _currentPath.c_str());
+		debug(0, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
+
+		bool goodMovie = _currentMovie->loadArchive();
+
+		// If we came in a loop, then skip as requested
+		if (!_nextMovie.frameS.empty()) {
+			_currentMovie->getScore()->setStartToLabel(_nextMovie.frameS);
+			_nextMovie.frameS.clear();
+		}
+
+		if (_nextMovie.frameI != -1) {
+			_currentMovie->getScore()->setCurrentFrame(_nextMovie.frameI);
+			_nextMovie.frameI = -1;
+		}
+
+		if (!debugChannelSet(-1, kDebugCompileOnly) && goodMovie) {
+			debugC(1, kDebugEvents, "Starting playback of movie '%s'", _currentMovie->getMacName().c_str());
+
+			_currentMovie->getScore()->startLoop();
+
+			debugC(1, kDebugEvents, "Finished playback of movie '%s'", _currentMovie->getMacName().c_str());
+		}
+	}
+
+	if (_vm->getGameGID() == GID_TESTALL) {
+		_nextMovie = getNextMovieFromQueue();
+	}
+
+	// If a loop was requested, do it
+	if (!_nextMovie.movie.empty()) {
+		_newMovieStarted = true;
+
+		_currentPath = getPath(_nextMovie.movie, _currentPath);
+
+		Cast *sharedCast = nullptr;
+		if (_currentMovie) {
+			sharedCast = _currentMovie->getSharedCast();
+			_currentMovie->_sharedCast = nullptr;
+		}
+
+		delete _currentMovie;
+		_currentMovie = nullptr;
+
+		Archive *mov = openMainArchive(_currentPath + Common::lastPathComponent(_nextMovie.movie, '/'));
+
+		if (!mov) {
+			warning("nextMovie: No movie is loaded");
+
+			if (_vm->getGameGID() == GID_TESTALL) {
+				return true;
+			}
+
+			return false;
+		}
+
+		_currentMovie = new Movie(_vm);
+		_currentMovie->setArchive(mov);
+		debug(0, "Switching to movie '%s'", _currentMovie->getMacName().c_str());
+
+		g_lingo->resetLingo();
+		if (sharedCast && sharedCast->_castArchive
+				&& sharedCast->_castArchive->getFileName().equalsIgnoreCase(_currentPath + _vm->_sharedCastFile)) {
+			_currentMovie->_sharedCast = sharedCast;
+		} else {
+			delete sharedCast;
+			_currentMovie->loadSharedCastsFrom(_currentPath + _vm->_sharedCastFile);
+		}
+
+		_nextMovie.movie.clear();
+		loop = true;
+	}
+
+	return loop;
+}
+
 } // end of namespace Director
diff --git a/engines/director/stage.h b/engines/director/stage.h
index 920819696c..1d384d6001 100644
--- a/engines/director/stage.h
+++ b/engines/director/stage.h
@@ -25,6 +25,10 @@
 
 #include "graphics/macgui/macwindow.h"
 
+namespace Common {
+class Error;
+}
+
 namespace Graphics {
 class ManagedSurface;
 class MacWindow;
@@ -38,8 +42,8 @@ struct TransParams;
 
 class Stage : public Graphics::MacWindow {
  public:
-	Stage(int id, bool scrollable, bool resizable, bool editable, Graphics::MacWindowManager *wm);
-	// ~Stage();
+	Stage(int id, bool scrollable, bool resizable, bool editable, Graphics::MacWindowManager *wm, DirectorEngine *vm);
+	~Stage();
 
 	bool render(bool forceRedraw = false, Graphics::ManagedSurface *blitTo = nullptr);
 
@@ -60,16 +64,52 @@ class Stage : public Graphics::MacWindow {
 
 	Common::Point getMousePos();
 
+	Archive *getMainArchive() const { return _mainArchive; }
+	Movie *getCurrentMovie() const { return _currentMovie; }
+	Common::String getCurrentPath() const { return _currentPath; }
+
+	bool step();
+
+	// tests.cpp
+	Common::HashMap<Common::String, Movie *> *scanMovies(const Common::String &folder);
+	void testFontScaling();
+	void testFonts();
+	void enqueueAllMovies();
+	MovieReference getNextMovieFromQueue();
+	void runTests();
+
+	// resource.cpp
+	Common::Error loadInitialMovie();
+	Archive *openMainArchive(const Common::String movie);
+	void loadEXE(const Common::String movie);
+	void loadEXEv3(Common::SeekableReadStream *stream);
+	void loadEXEv4(Common::SeekableReadStream *stream);
+	void loadEXEv5(Common::SeekableReadStream *stream);
+	void loadEXEv7(Common::SeekableReadStream *stream);
+	void loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset);
+	void loadMac(const Common::String movie);
+
 public:
 	Common::List<Common::Rect> _dirtyRects;
 	Common::List<Channel *> _dirtyChannels;
 	TransParams *_puppetTransition;
 
+	MovieReference _nextMovie;
+	Common::List<MovieReference> _movieStack;
+	bool _newMovieStarted;
+
 private:
 	uint _stageColor;
 	void inkBlitFrom(Channel *channel, Common::Rect destRect, Graphics::ManagedSurface *blitTo = nullptr);
 	void drawReverseSprite(Channel *channel, Common::Rect &srcRect, Common::Rect &destRect, Graphics::ManagedSurface *blitTo);
 	void drawMatteSprite(Channel *channel, Common::Rect &srcRect, Common::Rect &destRect, Graphics::ManagedSurface *blitTo);
+
+	DirectorEngine *_vm;
+	Archive *_mainArchive;
+	Common::MacResManager *_macBinary;
+	Movie *_currentMovie;
+	Common::String _currentPath;
+	Common::StringArray _movieQueue;
 };
 
 } // end of namespace Director
diff --git a/engines/director/tests.cpp b/engines/director/tests.cpp
index 2c6bfa1269..019a7c5ab3 100644
--- a/engines/director/tests.cpp
+++ b/engines/director/tests.cpp
@@ -36,6 +36,7 @@
 #include "director/director.h"
 #include "director/archive.h"
 #include "director/movie.h"
+#include "director/stage.h"
 #include "director/lingo/lingo.h"
 
 namespace Director {
@@ -43,13 +44,13 @@ namespace Director {
 //////////////////////
 // Graphics tests
 //////////////////////
-void DirectorEngine::testFontScaling() {
+void Stage::testFontScaling() {
 	int x = 10;
 	int y = 10;
 	int w = g_system->getWidth();
 	int h = g_system->getHeight();
 
-	setPalette(-1);
+	_vm->setPalette(-1);
 
 	Graphics::ManagedSurface surface;
 
@@ -92,7 +93,7 @@ void DirectorEngine::testFontScaling() {
 
 			for (x = x1; x < x1 + 6; x++)
 				for (y = y1; y < y1 + 6; y++)
-					*((byte *)surface.getBasePtr(x, y)) = transformColor(i * 16 + j);
+					*((byte *)surface.getBasePtr(x, y)) = _vm->transformColor(i * 16 + j);
 		}
 	}
 
@@ -110,7 +111,7 @@ void DirectorEngine::testFontScaling() {
 	}
 }
 
-void DirectorEngine::testFonts() {
+void Stage::testFonts() {
 	Common::String fontName("Helvetica");
 
 	Common::MacResManager *fontFile = new Common::MacResManager();
@@ -136,12 +137,12 @@ void DirectorEngine::testFonts() {
 //////////////////////
 // Movie iteration
 //////////////////////
-Common::HashMap<Common::String, Movie *> *DirectorEngine::scanMovies(const Common::String &folder) {
+Common::HashMap<Common::String, Movie *> *Stage::scanMovies(const Common::String &folder) {
 	Common::FSNode directory(folder);
 	Common::FSList movies;
 	const char *sharedMMMname;
 
-	if (getPlatform() == Common::kPlatformWindows)
+	if (_vm->getPlatform() == Common::kPlatformWindows)
 		sharedMMMname = "SHARDCST.MMM";
 	else
 		sharedMMMname = "Shared Cast";
@@ -156,17 +157,17 @@ Common::HashMap<Common::String, Movie *> *DirectorEngine::scanMovies(const Commo
 			debugC(2, kDebugLoading, "File: %s", i->getName().c_str());
 
 			if (Common::matchString(i->getName().c_str(), sharedMMMname, true)) {
-				_sharedCastFile = i->getName();
+				_vm->_sharedCastFile = i->getName();
 
 				debugC(2, kDebugLoading, "Shared cast detected: %s", i->getName().c_str());
 				continue;
 			}
 
-			Archive *arc = createArchive();
+			Archive *arc = _vm->createArchive();
 
 			warning("name: %s", i->getName().c_str());
 			arc->openFile(i->getName());
-			Movie *m = new Movie(this);
+			Movie *m = new Movie(_vm);
 			m->setArchive(arc);
 			nameMap->setVal(m->getMacName(), m);
 
@@ -177,7 +178,7 @@ Common::HashMap<Common::String, Movie *> *DirectorEngine::scanMovies(const Commo
 	return nameMap;
 }
 
-void DirectorEngine::enqueueAllMovies() {
+void Stage::enqueueAllMovies() {
 	Common::FSNode dir(ConfMan.get("path"));
 	Common::FSList files;
 	if (!dir.getChildren(files, Common::FSNode::kListFilesOnly)) {
@@ -193,7 +194,7 @@ void DirectorEngine::enqueueAllMovies() {
 	debug(1, "=========> Enqueued %d movies", _movieQueue.size());
 }
 
-MovieReference DirectorEngine::getNextMovieFromQueue() {
+MovieReference Stage::getNextMovieFromQueue() {
 	MovieReference res;
 
 	if (_movieQueue.empty())
@@ -277,7 +278,7 @@ const byte testMovie[] = {
 	0x00, 0x00
 };
 
-void DirectorEngine::runTests() {
+void Stage::runTests() {
 	Common::MemoryReadStream *movie = new Common::MemoryReadStream(testMovie, ARRAYSIZE(testMovie));
 	Common::SeekableReadStream *stream = Common::wrapCompressedReadStream(movie);
 
@@ -287,7 +288,7 @@ void DirectorEngine::runTests() {
 	if (!_mainArchive->openStream(stream, 0)) {
 		error("DirectorEngine::runTests(): Bad movie data");
 	}
-	_currentMovie = new Movie(this);
+	_currentMovie = new Movie(_vm);
 	_currentMovie->setArchive(_mainArchive);
 	_currentMovie->loadArchive();
 
@@ -296,7 +297,7 @@ void DirectorEngine::runTests() {
 		testFonts();
 	}
 
-	_lingo->runTests();
+	g_lingo->runTests();
 }
 
 } // End of namespace Director


Commit: 07bc3e58e8802a1ac15d485f469def093c5743ac
    https://github.com/scummvm/scummvm/commit/07bc3e58e8802a1ac15d485f469def093c5743ac
Author: djsrv (dservilla at gmail.com)
Date: 2020-07-03T15:55:14-04:00

Commit Message:
DIRECTOR: Remove vm arg from constructors

Pass the object's direct parent instead, and get things like the stage
from that instead of from the _vm when possible.

Changed paths:
    engines/director/cast.cpp
    engines/director/cast.h
    engines/director/movie.cpp
    engines/director/movie.h
    engines/director/resource.cpp
    engines/director/score.cpp
    engines/director/score.h
    engines/director/stage.cpp
    engines/director/stage.h
    engines/director/tests.cpp


diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp
index ea5d187ea7..4403e732bc 100644
--- a/engines/director/cast.cpp
+++ b/engines/director/cast.cpp
@@ -59,10 +59,12 @@ const char *scriptType2str(ScriptType scr) {
 	return scriptTypes[scr];
 }
 
-Cast::Cast(DirectorEngine *vm, Movie *movie) {
-	_vm = vm;
-	_lingo = _vm->getLingo();
+Cast::Cast(Movie *movie, bool isShared) {
 	_movie = movie;
+	_vm = _movie->getVM();
+	_lingo = _vm->getLingo();
+
+	_isShared = isShared;
 
 	_lingoArchive = new LingoArchive;
 
@@ -208,13 +210,13 @@ bool Cast::loadArchive() {
 	if (_castArchive->hasResource(MKTAG('V', 'W', 'C', 'F'), -1)) {
 		loadConfig(*(r = _castArchive->getFirstResource(MKTAG('V', 'W', 'C', 'F'))));
 		delete r;
-	} else if (_movie) {
+	} else if (!_isShared) {
 		// TODO: Source this from somewhere!
 		_movie->_movieRect = Common::Rect(0, 0, 639, 479);
 		_movie->_stageColor = 1;
 	}
 
-	if (_movie) {
+	if (!_isShared) {
 		// TODO: Can shared casts have palettes?
 		if (clutList.size() > 1)
 			warning("More than one palette was found (%d)", clutList.size());
@@ -372,13 +374,13 @@ void Cast::loadConfig(Common::SeekableSubReadStreamEndian &stream) {
 	uint16 len = stream.readUint16();
 	uint16 ver1 = stream.readUint16();
 	Common::Rect movieRect = Movie::readRect(stream);
-	if (_movie)
+	if (!_isShared)
 		_movie->_movieRect = movieRect;
 
 	_castArrayStart = stream.readUint16();
 	_castArrayEnd = stream.readUint16();
 	byte currentFrameRate = stream.readByte();
-	if (_movie) {
+	if (!_isShared) {
 		_movie->getScore()->_currentFrameRate = currentFrameRate;
 		if (_movie->getScore()->_currentFrameRate == 0)
 			_movie->getScore()->_currentFrameRate = 20;
@@ -391,7 +393,7 @@ void Cast::loadConfig(Common::SeekableSubReadStreamEndian &stream) {
 	uint16 commentStyle = stream.readUint16();
 	uint32 stageColor = _vm->transformColor(stream.readUint16());
 
-	if (_movie)
+	if (!_isShared)
 		_movie->_stageColor = stageColor;
 
 	uint16 bitdepth = stream.readUint16();
diff --git a/engines/director/cast.h b/engines/director/cast.h
index fcb2f24b24..6ca998db4a 100644
--- a/engines/director/cast.h
+++ b/engines/director/cast.h
@@ -48,7 +48,7 @@ class TextCastMember;
 
 class Cast {
 public:
-	Cast(DirectorEngine *vm, Movie *movie = nullptr);
+	Cast(Movie *movie, bool shared = false);
 	~Cast();
 
 	bool loadArchive();
@@ -100,6 +100,8 @@ private:
 	Lingo *_lingo;
 	Movie *_movie;
 
+	bool _isShared;
+
 	Common::String _macName;
 
 	Common::HashMap<uint16, CastMemberInfo *> _castsInfo;
diff --git a/engines/director/movie.cpp b/engines/director/movie.cpp
index eb289ce482..b72d75bd8b 100644
--- a/engines/director/movie.cpp
+++ b/engines/director/movie.cpp
@@ -33,8 +33,9 @@
 
 namespace Director {
 
-Movie::Movie(DirectorEngine *vm) {
-	_vm = vm;
+Movie::Movie(Stage *stage) {
+	_stage = stage;
+	_vm = _stage->getVM();
 	_lingo = _vm->getLingo();
 
 	_flags = 0;
@@ -49,9 +50,9 @@ Movie::Movie(DirectorEngine *vm) {
 
 	_movieArchive = nullptr;
 
-	_cast = new Cast(_vm, this);
+	_cast = new Cast(this);
 	_sharedCast = nullptr;
-	_score = new Score(_vm, this);
+	_score = new Score(this);
 }
 
 Movie::~Movie() {
@@ -94,12 +95,10 @@ bool Movie::loadArchive() {
 
 	// _movieRect and _stageColor are in VWCF, which the cast handles
 
-	Stage *stage = g_director->getStage();
-
 	// If the stage dimensions are different, delete it and start again.
 	// Otherwise, do not clear it so there can be a nice transition.
-	if (stage->getSurface()->w != _movieRect.width() || stage->getSurface()->h != _movieRect.height()) {
-		stage->resize(_movieRect.width(), _movieRect.height());
+	if (_stage->getSurface()->w != _movieRect.width() || _stage->getSurface()->h != _movieRect.height()) {
+		_stage->resize(_movieRect.width(), _movieRect.height());
 	}
 	// TODO: Add more options for desktop dimensions
 	uint16 windowWidth = debugChannelSet(-1, kDebugDesktop) ? 1024 : _movieRect.width();
@@ -109,7 +108,7 @@ bool Movie::loadArchive() {
 		g_director->_surface->create(windowWidth, windowHeight, Graphics::PixelFormat::createFormatCLUT8());
 	}
 
-	stage->setStageColor(_stageColor);
+	_stage->setStageColor(_stageColor);
 
 	// Score
 	if (!_movieArchive->hasResource(MKTAG('V', 'W', 'S', 'C'), -1)) {
@@ -231,7 +230,7 @@ void Movie::loadSharedCastsFrom(Common::String filename) {
 	debug(0, "@@@@ Loading Shared cast '%s'", filename.c_str());
 	debug(0, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
 
-	_sharedCast = new Cast(_vm);
+	_sharedCast = new Cast(this, true);
 	_sharedCast->setArchive(sharedCast);
 	_sharedCast->loadArchive();
 }
diff --git a/engines/director/movie.h b/engines/director/movie.h
index f2b68126b8..f98cf2c15d 100644
--- a/engines/director/movie.h
+++ b/engines/director/movie.h
@@ -38,11 +38,12 @@ class DirectorEngine;
 class Lingo;
 struct LingoArchive;
 class ScriptContext;
+class Stage;
 struct Symbol;
 
 class Movie {
 public:
-	Movie(DirectorEngine *vm);
+	Movie(Stage *stage);
 	~Movie();
 
 	static Common::Rect readRect(Common::ReadStreamEndian &stream);
@@ -52,9 +53,11 @@ public:
 	void setArchive(Archive *archive);
 	Archive *getArchive() const { return _movieArchive; };
 	Common::String getMacName() const { return _macName; }
-	Cast *getCast() { return _cast; }
-	Cast *getSharedCast() { return _sharedCast; }
-	Score *getScore() { return _score; }
+	Stage *getStage() const { return _stage; }
+	DirectorEngine *getVM() const { return _vm; }
+	Cast *getCast() const { return _cast; }
+	Cast *getSharedCast() const { return _sharedCast; }
+	Score *getScore() const { return _score; }
 
 	void clearSharedCast();
 	void loadSharedCastsFrom(Common::String filename);
@@ -86,6 +89,7 @@ public:
 	Cast *_sharedCast;
 
 private:
+	Stage *_stage;
 	DirectorEngine *_vm;
 	Lingo *_lingo;
 	Cast *_cast;
diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp
index b9b7d70c7a..bbbb97dc29 100644
--- a/engines/director/resource.cpp
+++ b/engines/director/resource.cpp
@@ -64,7 +64,7 @@ Common::Error Stage::loadInitialMovie() {
 		return Common::kNoGameDataFoundError;
 	}
 
-	_currentMovie = new Movie(_vm);
+	_currentMovie = new Movie(this);
 	_currentPath = getPath(movie, _currentPath);
 	_currentMovie->loadSharedCastsFrom(_currentPath + g_director->_sharedCastFile);
 
@@ -134,7 +134,7 @@ void Stage::loadEXE(const Common::String movie) {
 		char *script = (char *)calloc(iniStream->size() + 1, 1);
 		iniStream->read(script, iniStream->size());
 
-		_currentMovie = new Movie(_vm);
+		_currentMovie = new Movie(this);
 		_currentMovie->getMainLingoArch()->addCode(script, kMovieScript, 0);
 		g_lingo->processEvent(kEventStartUp);
 		delete _currentMovie;
diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index feca0747d6..f60fb5ea0b 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -242,10 +242,11 @@ MacShape *Channel::getShape() {
 	return shape;
 }
 
-Score::Score(DirectorEngine *vm, Movie *movie) {
-	_vm = vm;
-	_lingo = _vm->getLingo();
+Score::Score(Movie *movie) {
 	_movie = movie;
+	_stage = movie->getStage();
+	_vm = _movie->getVM();
+	_lingo = _vm->getLingo();
 
 	_soundManager = _vm->getSoundManager();
 	_puppetTempo = 0x00;
@@ -448,7 +449,7 @@ void Score::update() {
 	if (g_system->getMillis() < _nextFrameTime && !debugChannelSet(-1, kDebugFast)) {
 		_vm->_wm->renderZoomBox(true);
 
-		if (!_vm->getStage()->_newMovieStarted)
+		if (!_stage->_newMovieStarted)
 			_vm->_wm->draw();
 
 		return;
@@ -516,7 +517,7 @@ void Score::update() {
 
 	// Stage is drawn between the prepareFrame and enterFrame events (Lingo in a Nutshell, p.100)
 	renderFrame(_currentFrame);
-	_vm->getStage()->_newMovieStarted = false;
+	_stage->_newMovieStarted = false;
 
 	// Enter and exit from previous frame
 	if (!_vm->_playbackPaused) {
@@ -571,7 +572,7 @@ void Score::renderFrame(uint16 frameId, RenderMode mode) {
 		renderSprites(frameId, mode);
 
 	_vm->_wm->renderZoomBox();
-	g_director->getStage()->render();
+	_stage->render();
 	_vm->_wm->draw();
 
 	if (_frames[frameId]->_sound1 || _frames[frameId]->_sound2)
@@ -580,16 +581,16 @@ void Score::renderFrame(uint16 frameId, RenderMode mode) {
 
 bool Score::renderTransition(uint16 frameId) {
 	Frame *currentFrame = _frames[frameId];
-	TransParams *tp = g_director->getStage()->_puppetTransition;
+	TransParams *tp = _stage->_puppetTransition;
 
 	if (tp) {
-		g_director->getStage()->playTransition(tp->duration, tp->area, tp->chunkSize, tp->type, frameId);
+		_stage->playTransition(tp->duration, tp->area, tp->chunkSize, tp->type, frameId);
 
-		delete g_director->getStage()->_puppetTransition;;
-		g_director->getStage()->_puppetTransition = nullptr;
+		delete _stage->_puppetTransition;;
+		_stage->_puppetTransition = nullptr;
 		return true;
 	} else if (currentFrame->_transType) {
-		g_director->getStage()->playTransition(currentFrame->_transDuration, currentFrame->_transArea, currentFrame->_transChunkSize, currentFrame->_transType, frameId);
+		_stage->playTransition(currentFrame->_transDuration, currentFrame->_transArea, currentFrame->_transChunkSize, currentFrame->_transType, frameId);
 		return true;
 	} else {
 		return false;
@@ -597,7 +598,7 @@ bool Score::renderTransition(uint16 frameId) {
 }
 
 void Score::renderSprites(uint16 frameId, RenderMode mode) {
-	if (_vm->getStage()->_newMovieStarted)
+	if (_stage->_newMovieStarted)
 		mode = kRenderForceUpdate;
 
 	for (uint16 i = 0; i < _channels.size(); i++) {
@@ -608,17 +609,17 @@ void Score::renderSprites(uint16 frameId, RenderMode mode) {
 		bool needsUpdate = channel->isDirty(nextSprite) || mode == kRenderForceUpdate;
 
 		if (needsUpdate && !currentSprite->_trails)
-			g_director->getStage()->addDirtyRect(channel->getBbox());
+			_stage->addDirtyRect(channel->getBbox());
 
 		channel->setClean(nextSprite, i);
 
 		if (needsUpdate)
-			g_director->getStage()->addDirtyRect(channel->getBbox());
+			_stage->addDirtyRect(channel->getBbox());
 	}
 }
 
 void Score::screenShot() {
-	Graphics::Surface rawSurface = g_director->getStage()->getSurface()->rawSurface();
+	Graphics::Surface rawSurface = _stage->getSurface()->rawSurface();
 	const Graphics::PixelFormat requiredFormat_4byte(4, 8, 8, 8, 8, 0, 8, 16, 24);
 	Graphics::Surface *newSurface = rawSurface.convertTo(requiredFormat_4byte, _vm->getPalette());
 	Common::String currentPath = _vm->getCurrentPath().c_str();
diff --git a/engines/director/score.h b/engines/director/score.h
index 804a2a8187..85e7e8a5f8 100644
--- a/engines/director/score.h
+++ b/engines/director/score.h
@@ -126,7 +126,7 @@ struct Channel {
 
 class Score {
 public:
-	Score(DirectorEngine *vm, Movie *movie);
+	Score(Movie *movie);
 	~Score();
 
 	void loadFrames(Common::SeekableSubReadStreamEndian &stream);
@@ -188,6 +188,7 @@ private:
 	DirectorEngine *_vm;
 	Lingo *_lingo;
 	Movie *_movie;
+	Stage *_stage;
 
 	uint16 _currentFrame;
 	uint16 _nextFrame;
diff --git a/engines/director/stage.cpp b/engines/director/stage.cpp
index a55945913d..770ccd2cd8 100644
--- a/engines/director/stage.cpp
+++ b/engines/director/stage.cpp
@@ -283,7 +283,7 @@ bool Stage::step() {
 			return false;
 		}
 
-		_currentMovie = new Movie(_vm);
+		_currentMovie = new Movie(this);
 		_currentMovie->setArchive(mov);
 		debug(0, "Switching to movie '%s'", _currentMovie->getMacName().c_str());
 
diff --git a/engines/director/stage.h b/engines/director/stage.h
index 1d384d6001..86f001afad 100644
--- a/engines/director/stage.h
+++ b/engines/director/stage.h
@@ -64,6 +64,7 @@ class Stage : public Graphics::MacWindow {
 
 	Common::Point getMousePos();
 
+	DirectorEngine *getVM() const { return _vm; }
 	Archive *getMainArchive() const { return _mainArchive; }
 	Movie *getCurrentMovie() const { return _currentMovie; }
 	Common::String getCurrentPath() const { return _currentPath; }
diff --git a/engines/director/tests.cpp b/engines/director/tests.cpp
index 019a7c5ab3..f1ed48e629 100644
--- a/engines/director/tests.cpp
+++ b/engines/director/tests.cpp
@@ -167,7 +167,7 @@ Common::HashMap<Common::String, Movie *> *Stage::scanMovies(const Common::String
 
 			warning("name: %s", i->getName().c_str());
 			arc->openFile(i->getName());
-			Movie *m = new Movie(_vm);
+			Movie *m = new Movie(this);
 			m->setArchive(arc);
 			nameMap->setVal(m->getMacName(), m);
 
@@ -288,7 +288,7 @@ void Stage::runTests() {
 	if (!_mainArchive->openStream(stream, 0)) {
 		error("DirectorEngine::runTests(): Bad movie data");
 	}
-	_currentMovie = new Movie(_vm);
+	_currentMovie = new Movie(this);
 	_currentMovie->setArchive(_mainArchive);
 	_currentMovie->loadArchive();
 




More information about the Scummvm-git-logs mailing list