[Scummvm-git-logs] scummvm master -> 3d1e511335637c1c8b3f8d9b32b0533c22af6e4e

a-yyg 76591232+a-yyg at users.noreply.github.com
Fri Aug 20 17:50:18 UTC 2021


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

Summary:
719039f0e2 SAGA2: Fix game save/loading on GMM
fbe7d40370 SAGA2: Remove memory manager initialization code
823dfb393b SAGA2: Unstub shutdownGame
88548d38d3 SAGA2: Fix heap-use-after-free for _containerList
89b5a59ed0 SAGA2: Fix _nameList cleanup
21316cc286 SAGA2: Fix various cleanup steps
0c43f21c80 SAGA2: Remove timer callback on cleanup
b6f4609551 SAGA2: Move gameRunning to Saga2Engine
5cd20d58d5 SAGA2: Move mapFeatures to Saga2Engine
3d1e511335 SAGA2: Enable RTL


Commit: 719039f0e22d87c2084af5b99ad2507db360ecfa
    https://github.com/scummvm/scummvm/commit/719039f0e22d87c2084af5b99ad2507db360ecfa
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Fix game save/loading on GMM

Changed paths:
    engines/saga2/gfx.cpp
    engines/saga2/saga2.cpp
    engines/saga2/saveload.cpp
    engines/saga2/saveload.h
    engines/saga2/uidialog.cpp


diff --git a/engines/saga2/gfx.cpp b/engines/saga2/gfx.cpp
index 78b572569e..e455e527e3 100644
--- a/engines/saga2/gfx.cpp
+++ b/engines/saga2/gfx.cpp
@@ -50,7 +50,7 @@ void Renderer::saveBackBuffer(BackBufferSource source) {
 
 		Graphics::Surface *surf = g_system->lockScreen();
 		int size = surf->w * surf->h;
-		
+
 		_savedBackBuffers[source] = new byte[size];
 		memcpy(_savedBackBuffers[source], surf->getPixels(), size);
 
diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index f8f35d75b6..7d0f8f8a1e 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -187,9 +187,9 @@ Common::Error Saga2Engine::saveGameState(int slot, const Common::String &desc, b
 	_renderer->saveBackBuffer(kBeforeTakingThumbnail);
 
 	if (_renderer->hasSavedBackBuffer(kBeforeOpeningMenu))
-		_renderer->restoreSavedBackBuffer(kBeforeOpeningMenu);
+		_renderer->popSavedBackBuffer(kBeforeOpeningMenu);
 
-	getMetaEngine()->appendExtendedSaveToStream(out, g_vm->getTotalPlayTime() / 1000, desc, false, pos);
+	getMetaEngine()->appendExtendedSaveToStream(out, g_vm->getTotalPlayTime() / 1000, desc, isAutosave, pos);
 
 	_renderer->popSavedBackBuffer(kBeforeTakingThumbnail);
 	CHUNK_END;
@@ -204,7 +204,7 @@ Common::Error Saga2Engine::saveGameState(int slot, const Common::String &desc, b
 }
 
 Common::Error Saga2Engine::loadGameState(int slot) {
-	loadSavedGameState(slot);
+	loadGame(slot);
 
 	return Common::kNoError;
 }
diff --git a/engines/saga2/saveload.cpp b/engines/saga2/saveload.cpp
index b742065707..21083a4e71 100644
--- a/engines/saga2/saveload.cpp
+++ b/engines/saga2/saveload.cpp
@@ -46,6 +46,11 @@
 
 namespace Saga2 {
 
+void updateMainDisplay(void);
+void fadeUp();
+void fadeDown();
+void enablePaletteChanges();
+
 const ChunkID   gameID = MKTAG('F', 'T', 'A', '2');
 
 void SaveFileHeader::read(Common::InSaveFile *in) {
@@ -513,6 +518,23 @@ void loadSavedGameState(int16 saveNo) {
 	resumeTimer();
 }
 
+void loadGame(int16 saveNo) {
+	disableUserControls();
+	cleanupGameState();
+	fadeDown();
+	loadSavedGameState(saveNo);
+	if (GameMode::newmodeFlag)
+		GameMode::update();
+	updateActiveRegions();
+	enableUserControls();
+	updateMainDisplay();
+	drawMainDisplay();
+	enablePaletteChanges();
+	updateAllUserControls();
+	fadeUp();
+	reDrawScreen();
+}
+
 //----------------------------------------------------------------------
 //	Cleanup the game state
 
diff --git a/engines/saga2/saveload.h b/engines/saga2/saveload.h
index 62f96a6eb3..2533dd3105 100644
--- a/engines/saga2/saveload.h
+++ b/engines/saga2/saveload.h
@@ -66,6 +66,9 @@ void saveGame(Common::OutSaveFile *out, Common::String saveName);
 //  Load a previously saved game state
 void loadSavedGameState(int16 saveNo);
 
+// Perform a cleanup and load process with fade-in
+void loadGame(int16 saveNo);
+
 //  Cleanup the game state
 void cleanupGameState(void);
 
diff --git a/engines/saga2/uidialog.cpp b/engines/saga2/uidialog.cpp
index bb8d69cbbd..7997f31548 100644
--- a/engines/saga2/uidialog.cpp
+++ b/engines/saga2/uidialog.cpp
@@ -966,6 +966,9 @@ int16 OptionsDialog(bool disableSaveResume) {
 		mainWindow->invalidate(&optionsWindowRect);
 	}
 
+	// Pop back buffer
+	g_vm->_renderer->popSavedBackBuffer(kBeforeOpeningMenu);
+
 	// return the result code
 	return rInfo.result;
 }


Commit: fbe7d40370da3f83b457472c49d001d1374ac138
    https://github.com/scummvm/scummvm/commit/fbe7d40370da3f83b457472c49d001d1374ac138
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Remove memory manager initialization code

Changed paths:
    engines/saga2/fta.h
    engines/saga2/main.cpp
    engines/saga2/mainmap.cpp
    engines/saga2/mainmap.h
    engines/saga2/towerfta.cpp
    engines/saga2/towerfta.h


diff --git a/engines/saga2/fta.h b/engines/saga2/fta.h
index 52e13cca29..c57b4c2a5b 100644
--- a/engines/saga2/fta.h
+++ b/engines/saga2/fta.h
@@ -168,10 +168,6 @@ Common::SeekableReadStream *loadResourceToStream(hResContext *con, uint32 id, co
 
 void restoreProgramDir(void);                // chdir() to program directory
 
-//  Memory allocation
-
-void  *mustAlloc(uint32 size, const char desc[]);                // alloc 'size' bytes or fail
-
 // Returns Random Number
 
 int16 GetRandomBetween(int start, int end);
diff --git a/engines/saga2/main.cpp b/engines/saga2/main.cpp
index 9ec7a99dc1..d929755c32 100644
--- a/engines/saga2/main.cpp
+++ b/engines/saga2/main.cpp
@@ -75,9 +75,6 @@ uint32 cliMemory        = 0;
 //  Display variables
 BackWindow              *mainWindow;            // main window...
 
-//  Memory allocation heap
-long                    memorySize = 8000000L;
-
 //  Global game state
 bool                    gameRunning = true;     // true while game running
 bool                    allPlayerActorsDead = false;
@@ -110,10 +107,6 @@ bool                    gameInitialized = false;        // true when game initia
 bool                    fullInitialized = false;
 bool                    delayReDraw = false;
 
-// main heap
-static uint8            *heapMemory;
-
-
 /* ===================================================================== *
    Debug
  * ===================================================================== */
@@ -853,50 +846,4 @@ APPFUNC(cmdWindowFunc) {
 	}
 }
 
-/********************************************************************/
-/*                                                                  */
-/* MEMORY MANAGEMENT CODE                                           */
-/*                                                                  */
-/********************************************************************/
-
-/* ===================================================================== *
-   Functions to initialize the memory manager.
- * ===================================================================== */
-
-//-----------------------------------------------------------------------
-//	Initialize memory manager
-
-bool initMemPool(void) {
-	uint32 take = pickHeapSize(memorySize);
-	memorySize = take;
-	if (NULL == (heapMemory = (uint8 *)malloc(take)))
-		return false;
-	//initMemHandler();
-	return true;
-}
-
-//-----------------------------------------------------------------------
-//	De-initialize memory manager
-
-void cleanupMemPool(void) {
-	//clearMemHandler();
-	if (heapMemory) {
-		free(heapMemory);
-		heapMemory = nullptr;
-	}
-}
-
-//-----------------------------------------------------------------------
-//	Allocates memory, or throws exception if allocation fails.
-
-void *mustAlloc(uint32 size, const char desc[]) {
-	void            *ptr;
-
-	ptr = malloc(size);
-	//  REM: Before we give up completely, try unloading some things...
-	if (ptr == NULL)
-		error("Local heap allocation size %d bytes failed.", size);
-	return ptr;
-}
-
 } // end of namespace Saga2
diff --git a/engines/saga2/mainmap.cpp b/engines/saga2/mainmap.cpp
index a97f14d4f2..451b34c8cd 100644
--- a/engines/saga2/mainmap.cpp
+++ b/engines/saga2/mainmap.cpp
@@ -35,11 +35,6 @@ void parseCommandLine(int argc, char *argv[]) {
 	warning("STUB: parseCommandLine()");
 }
 
-uint32 pickHeapSize(uint32 minHeap) {
-	warning("STUB: pickHeapSize()");
-	return 0;
-}
-
 void initCleanup() {
 	warning("STUB: initCleanup()");
 }
diff --git a/engines/saga2/mainmap.h b/engines/saga2/mainmap.h
index e45aba034d..b49c6744d7 100644
--- a/engines/saga2/mainmap.h
+++ b/engines/saga2/mainmap.h
@@ -35,9 +35,6 @@ void main_saga2();
 //extern char *commandLineHelp;
 void parseCommandLine(int argc, char *argv[]);
 
-// memory access
-uint32 pickHeapSize(uint32 minHeap);
-
 // initialization & cleanup
 void initCleanup(void);
 
diff --git a/engines/saga2/towerfta.cpp b/engines/saga2/towerfta.cpp
index 5ab18f02ec..2fa47e4ce9 100644
--- a/engines/saga2/towerfta.cpp
+++ b/engines/saga2/towerfta.cpp
@@ -55,7 +55,6 @@ TowerLayer tower[fullyInitialized] = {
 	{ delayedErrInitialized,     &initDelayedErrors,    &termDelayedErrors },
 	{ activeErrInitialized,      &initActiveErrors,     &termActiveErrors },
 	{ configTestInitialized,     &initSystemConfig,     &termTowerBase },
-	{ memoryInitialized,         &initMemPool,          &termMemPool },
 	{ introInitialized,          &initPlayIntro,        &termPlayOutro },
 	{ timerInitialized,          &initSystemTimer,      &termSystemTimer },
 	{ audioInitialized,          &initAudio,            &termAudio},
@@ -93,8 +92,6 @@ TowerLayer tower[fullyInitialized] = {
 bool initGUIMessagers(void);
 void cleanupMessagers(void);
 void cleanupGUIMessagers(void);
-bool initMemPool(void);
-void cleanupMemPool(void);
 bool openResources(void);
 void closeResources(void);
 void initServers(void);
@@ -124,15 +121,6 @@ INITIALIZER(initSystemConfig) {
 
 // uses null cleanup
 
-// ------------------------------------------------------------------------
-
-extern INITIALIZER(initMemPool);
-
-TERMINATOR(termMemPool) {
-	cleanupMemPool();                       // deallocate memory buffers
-}
-
-
 // ------------------------------------------------------------------------
 
 INITIALIZER(initPlayIntro) {
diff --git a/engines/saga2/towerfta.h b/engines/saga2/towerfta.h
index aeb9c0eecb..f7e4dafacd 100644
--- a/engines/saga2/towerfta.h
+++ b/engines/saga2/towerfta.h
@@ -34,9 +34,6 @@ namespace Saga2 {
 INITIALIZER(initSystemConfig);
 // uses null cleanup
 
-INITIALIZER(initMemPool);
-TERMINATOR(termMemPool);
-
 INITIALIZER(initPlayIntro);
 TERMINATOR(termPlayOutro);
 


Commit: 823dfb393bd7786f2091aa7f25fda604f7744f01
    https://github.com/scummvm/scummvm/commit/823dfb393bd7786f2091aa7f25fda604f7744f01
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Unstub shutdownGame

Changed paths:
    engines/saga2/mainmap.cpp


diff --git a/engines/saga2/mainmap.cpp b/engines/saga2/mainmap.cpp
index 451b34c8cd..0caac0e059 100644
--- a/engines/saga2/mainmap.cpp
+++ b/engines/saga2/mainmap.cpp
@@ -45,7 +45,7 @@ bool initializeGame() {
 	return false;
 }
 void shutdownGame() {
-	warning("STUB: shutdownGame");
+	cleanupGame();
 }
 
 bool initSystemTimer() {


Commit: 88548d38d3b62df541cfaaa6638d8de9e64eb5f2
    https://github.com/scummvm/scummvm/commit/88548d38d3b62df541cfaaa6638d8de9e64eb5f2
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Fix heap-use-after-free for _containerList

Changed paths:
    engines/saga2/contain.cpp
    engines/saga2/floating.cpp
    engines/saga2/saga2.cpp


diff --git a/engines/saga2/contain.cpp b/engines/saga2/contain.cpp
index 3ac4f77daa..a44ef22c8e 100644
--- a/engines/saga2/contain.cpp
+++ b/engines/saga2/contain.cpp
@@ -1761,7 +1761,6 @@ void cleanupContainers(void) {
 
 	selImage = NULL;
 	containerRes = NULL;
-	delete g_vm->_containerList;
 }
 
 void initContainerNodes(void) {
@@ -1845,6 +1844,9 @@ void loadContainerNodes(Common::InSaveFile *in) {
 }
 
 void cleanupContainerNodes(void) {
+	if (g_vm->_containerList == nullptr)
+		return;
+
 	Common::Array<ContainerNode *> deletionArray;
 
 	for (Common::List<ContainerNode *>::iterator it = g_vm->_containerList->_list.begin(); it != g_vm->_containerList->_list.end(); ++it) {
diff --git a/engines/saga2/floating.cpp b/engines/saga2/floating.cpp
index 7bec32f7f0..196d0e6b66 100644
--- a/engines/saga2/floating.cpp
+++ b/engines/saga2/floating.cpp
@@ -238,8 +238,11 @@ void DecoratedWindow::removeDecorations(void) {
 		g_vm->_imageCache->releaseImage(dec->image);
 	}
 
-	if (decorations)
+	if (decorations) {
 		delete[] decorations;
+		decorations = nullptr;
+	}
+
 	numDecorations = 0;
 }
 
diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index 7d0f8f8a1e..eb0beb2ed2 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -126,6 +126,7 @@ Saga2Engine::~Saga2Engine() {
 	delete _properties;
 	delete _aTaskList;
 	delete _grandMasterFTA;
+	delete _containerList;
 }
 
 Common::Error Saga2Engine::run() {


Commit: 89b5a59ed0073b38a95fc09b3b94e5c4f8bd2b24
    https://github.com/scummvm/scummvm/commit/89b5a59ed0073b38a95fc09b3b94e5c4f8bd2b24
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Fix _nameList cleanup

Changed paths:
    engines/saga2/objects.cpp


diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index 96b8b7950c..46d25627e5 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -2700,10 +2700,10 @@ void cleanupPrototypes(void) {
 	for (uint i = 0; i < nameListCount; ++i) {
 		if (g_vm->_nameList[i])
 			delete[] g_vm->_nameList[i];
-
-		g_vm->_nameList.clear();
 	}
 
+	g_vm->_nameList.clear();
+
 	for (uint i = 0; i < g_vm->_actorProtos.size(); ++i) {
 		if (g_vm->_actorProtos[i])
 			delete g_vm->_actorProtos[i];


Commit: 21316cc2862363905b2728d911e11f0867e7ad7b
    https://github.com/scummvm/scummvm/commit/21316cc2862363905b2728d911e11f0867e7ad7b
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Fix various cleanup steps

Changed paths:
    engines/saga2/speldata.cpp
    engines/saga2/speldraw.cpp
    engines/saga2/tile.cpp


diff --git a/engines/saga2/speldata.cpp b/engines/saga2/speldata.cpp
index c05a6ba35f..3408ef80ee 100644
--- a/engines/saga2/speldata.cpp
+++ b/engines/saga2/speldata.cpp
@@ -152,7 +152,7 @@ void cleanupMagic(void) {
 	for (int i = 0; i < maxSpells; i++) {
 		spellBook[i].killEffects();
 	}
-	delete spellBook;
+	delete[] spellBook;
 
 	g_vm->_sdpList->cleanup();
 	g_vm->_edpList->cleanup();
diff --git a/engines/saga2/speldraw.cpp b/engines/saga2/speldraw.cpp
index 2acdcee3ab..012b20c161 100644
--- a/engines/saga2/speldraw.cpp
+++ b/engines/saga2/speldraw.cpp
@@ -174,7 +174,7 @@ void SpellDisplayPrototypeList::cleanup(void) {
 				delete spells[i];
 				spells[i] = nullptr;
 			}
-		delete spells;
+		delete[] spells;
 		spells = nullptr;
 		maxCount = 0;
 	}
diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp
index a37e307d69..bf1afda18a 100644
--- a/engines/saga2/tile.cpp
+++ b/engines/saga2/tile.cpp
@@ -1503,9 +1503,6 @@ void cleanupMaps(void) {
 	//  Dump all of the tile terrain banks
 	for (i = 0; i < maxBanks; i++) {
 		if (tileBanks[i] != nullptr) {
-			if (tileBanks[i]->_tileArray != nullptr)
-				delete[] tileBanks[i]->_tileArray;
-
 			delete tileBanks[i];
 			tileBanks[i] = nullptr;
 		}


Commit: 0c43f21c8017a29b3c5d916cfe7bccb34239a9cf
    https://github.com/scummvm/scummvm/commit/0c43f21c8017a29b3c5d916cfe7bccb34239a9cf
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Remove timer callback on cleanup

Changed paths:
    engines/saga2/fta.h
    engines/saga2/timers.cpp
    engines/saga2/timers.h


diff --git a/engines/saga2/fta.h b/engines/saga2/fta.h
index c57b4c2a5b..8dff458ac3 100644
--- a/engines/saga2/fta.h
+++ b/engines/saga2/fta.h
@@ -124,9 +124,6 @@ void initTimer(void);
 void saveTimer(Common::OutSaveFile *out);
 void loadTimer(Common::InSaveFile *in);
 
-//  Cleanup the timer -- nothing to do
-inline void cleanupTimer(void) {}
-
 void pauseTimer(void);               // pause game clock
 void resumeTimer(void);                  // resume game clock
 
diff --git a/engines/saga2/timers.cpp b/engines/saga2/timers.cpp
index a482a3e881..3e3cced104 100644
--- a/engines/saga2/timers.cpp
+++ b/engines/saga2/timers.cpp
@@ -76,6 +76,10 @@ void loadTimer(Common::InSaveFile *in) {
 	debugC(3, kDebugSaveload, "... time = %d", gameTime);
 }
 
+void cleanupTimer() {
+	g_vm->getTimerManager()->removeTimerProc(&timerCallback);
+}
+
 /* ====================================================================== *
    Alarms
  * ====================================================================== */
diff --git a/engines/saga2/timers.h b/engines/saga2/timers.h
index dac3c747ea..63facd5d77 100644
--- a/engines/saga2/timers.h
+++ b/engines/saga2/timers.h
@@ -48,6 +48,7 @@ void checkTimers(void);
 void initTimers(void);
 void saveTimers(Common::OutSaveFile *outS);
 void loadTimers(Common::InSaveFile *in);
+void cleanupTimer();
 //  Cleanup the active Timers
 void cleanupTimers(void);
 


Commit: b6f46095519172e7e254553b592f4753a119c953
    https://github.com/scummvm/scummvm/commit/b6f46095519172e7e254553b592f4753a119c953
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Move gameRunning to Saga2Engine

Changed paths:
    engines/saga2/display.cpp
    engines/saga2/fta.h
    engines/saga2/main.cpp
    engines/saga2/msgbox.cpp
    engines/saga2/playmode.cpp
    engines/saga2/saga2.cpp
    engines/saga2/saga2.h
    engines/saga2/spelcast.cpp
    engines/saga2/tromode.cpp


diff --git a/engines/saga2/display.cpp b/engines/saga2/display.cpp
index 389bc39de1..1dacaeb0f3 100644
--- a/engines/saga2/display.cpp
+++ b/engines/saga2/display.cpp
@@ -34,7 +34,6 @@
 
 namespace Saga2 {
 
-extern bool             gameRunning;
 extern bool             delayReDraw;
 extern BackWindow       *mainWindow;            // main window...
 
@@ -76,7 +75,7 @@ static void switchOff(void);
 void endGame(void) {
 	blackOut();
 	displayDisable(GameEnded);
-	gameRunning = false;
+	g_vm->_gameRunning = false;
 }
 
 
diff --git a/engines/saga2/fta.h b/engines/saga2/fta.h
index 8dff458ac3..8e206f89e5 100644
--- a/engines/saga2/fta.h
+++ b/engines/saga2/fta.h
@@ -217,8 +217,6 @@ extern int16            extendedThreadLevel;
    Misc Globals
  * ===================================================================== */
 
-extern bool         gameRunning;            // true while game running
-
 extern volatile int32 gameTime;             // current timer
 
 //  Resource files
diff --git a/engines/saga2/main.cpp b/engines/saga2/main.cpp
index d929755c32..f5583d417d 100644
--- a/engines/saga2/main.cpp
+++ b/engines/saga2/main.cpp
@@ -76,7 +76,6 @@ uint32 cliMemory        = 0;
 BackWindow              *mainWindow;            // main window...
 
 //  Global game state
-bool                    gameRunning = true;     // true while game running
 bool                    allPlayerActorsDead = false;
 //bool                  graphicsInit = false;   // true if graphics init OK
 bool                    checkExit = false;      // true while game running
@@ -202,7 +201,7 @@ static void mainLoop(bool &cleanExit_, int argc, char *argv[]) {
 		displayUpdate();
 	checkRestartGame(exeFile);
 	fullInitialized = true;
-	EventLoop(gameRunning, false);
+	EventLoop(g_vm->_gameRunning, false);
 }
 
 /********************************************************************/
@@ -254,7 +253,7 @@ void processEventLoop(bool updateScreen = true);
 
 void EventLoop(bool &running, bool) {
 	//  Our typical main loop
-	while (running && gameRunning)
+	while (running && g_vm->_gameRunning)
 		processEventLoop(displayEnabled());
 }
 
@@ -268,7 +267,7 @@ void processEventLoop(bool updateScreen) {
 	debugC(1, kDebugEventLoop, "EventLoop: starting event loop");
 
 	if (checkExit && verifyUserExit()) {
-		//gameRunning=false;
+		//g_vm->_gameRunning=false;
 		endGame();
 		return;
 	}
@@ -386,7 +385,7 @@ void SystemEventLoop(void) {
 #ifdef DO_OUTRO_IN_CLEANUP
 	    whichOutro == -1 &&
 #endif
-	    !gameRunning)
+	    !g_vm->_gameRunning)
 		TroModeExternEvent();
 
 	Common::Event event;
@@ -711,7 +710,7 @@ void loadGlobals(Common::InSaveFile *in) {
 // pops up a window to see if the user really wants to exit
 
 bool verifyUserExit(void) {
-	if (!gameRunning)
+	if (!g_vm->_gameRunning)
 		return true;
 	if (FTAMessageBox("Are you sure you want to exit", ERROR_YE_BUTTON, ERROR_NO_BUTTON) != 0)
 		return true;
diff --git a/engines/saga2/msgbox.cpp b/engines/saga2/msgbox.cpp
index d0b8632c26..768d0e624b 100644
--- a/engines/saga2/msgbox.cpp
+++ b/engines/saga2/msgbox.cpp
@@ -54,7 +54,6 @@ static gFont    *mbButtonFont = &ThinFix8Font;
    Imports
  * ===================================================================== */
 
-extern bool             gameRunning;        // true while game running
 extern BackWindow       *mainWindow;
 
 /* ===================================================================== *
diff --git a/engines/saga2/playmode.cpp b/engines/saga2/playmode.cpp
index d209c463c4..739dc76d26 100644
--- a/engines/saga2/playmode.cpp
+++ b/engines/saga2/playmode.cpp
@@ -130,13 +130,11 @@ static StaticPixelMap objPointerMap = {{0, 0}, nullptr};          // bitmap for
 
 hResContext         *imageRes;              // image resource handle
 
-extern bool gameRunning;
-
 //-----------------------------------------------------------------------
 //	Initialize the Play mode
 
 bool checkTileAreaPort(void) {
-	if (gameRunning && g_vm->_tileDrawMap.data == nullptr) {
+	if (g_vm->_gameRunning && g_vm->_tileDrawMap.data == nullptr) {
 		//  Allocate back buffer for tile rendering
 		g_vm->_tileDrawMap.size.x = (kTileRectWidth + kTileWidth - 1) & ~kTileDXMask;
 		g_vm->_tileDrawMap.size.y = (kTileRectHeight + kTileWidth - 1) & ~kTileDXMask;
@@ -147,7 +145,7 @@ bool checkTileAreaPort(void) {
 }
 
 void clearTileAreaPort(void) {
-	if (gameRunning && g_vm->_tileDrawMap.data != nullptr) {
+	if (g_vm->_gameRunning && g_vm->_tileDrawMap.data != nullptr) {
 		_FillRect(g_vm->_tileDrawMap.data, g_vm->_tileDrawMap.size.x, g_vm->_tileDrawMap.size.x, g_vm->_tileDrawMap.size.y, 0);
 	}
 
diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index eb0beb2ed2..707c3aa4d0 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -69,6 +69,7 @@ Saga2Engine::Saga2Engine(OSystem *syst)
 	_videoX = _videoY = 0;
 	_loadedWeapons = 0;
 
+	_gameRunning = true;
 	_autoAggression = true;
 	_autoWeapon = true;
 	_showNight = true;
diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h
index 602efacbb1..ed233ac389 100644
--- a/engines/saga2/saga2.h
+++ b/engines/saga2/saga2.h
@@ -173,6 +173,7 @@ public:
 	gPort _backPort;
 	gPixelMap _tileDrawMap;
 
+	bool _gameRunning;
 	bool _autoAggression;
 	bool _autoWeapon;
 	bool _showNight;
diff --git a/engines/saga2/spelcast.cpp b/engines/saga2/spelcast.cpp
index a8ad3aea57..70a2a53c2b 100644
--- a/engines/saga2/spelcast.cpp
+++ b/engines/saga2/spelcast.cpp
@@ -36,7 +36,6 @@ namespace Saga2 {
 
 extern WorldMapData                     *mapList;
 extern SpellStuff                       *spellBook;
-extern bool                             gameRunning;  // kludge
 extern PlatformHandle   platformList;       // platform resource hunk
 
 /* ===================================================================== *
@@ -634,7 +633,7 @@ SpellInstance::SpellInstance(SpellCaster *newCaster, TilePoint &newTarget, Spell
 
 
 SpellInstance::~SpellInstance() {
-	if (age < implementAge && gameRunning)
+	if (age < implementAge && g_vm->_gameRunning)
 		spellBook[spell].implement(caster, target);
 	for (int32 i = 0; i < eList.count; i++) {
 		if (eList.displayList[i].efx)
diff --git a/engines/saga2/tromode.cpp b/engines/saga2/tromode.cpp
index a7880ef335..9f9e209ffc 100644
--- a/engines/saga2/tromode.cpp
+++ b/engines/saga2/tromode.cpp
@@ -51,7 +51,6 @@ namespace Saga2 {
 #define VIDEO_X 0
 #define VIDEO_Y 0
 
-extern bool gameRunning;
 extern bool allPlayerActorsDead;
 
 int16 OptionsDialog(bool disableSaveResume = false);


Commit: 5cd20d58d5886d8ef906286fd18ca46a6ce2b579
    https://github.com/scummvm/scummvm/commit/5cd20d58d5886d8ef906286fd18ca46a6ce2b579
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Move mapFeatures to Saga2Engine

Changed paths:
    engines/saga2/console.cpp
    engines/saga2/mapfeatr.cpp
    engines/saga2/saga2.h


diff --git a/engines/saga2/console.cpp b/engines/saga2/console.cpp
index ca7f8bb984..497d1849e6 100644
--- a/engines/saga2/console.cpp
+++ b/engines/saga2/console.cpp
@@ -35,9 +35,6 @@
 
 namespace Saga2 {
 
-#define MAX_MAP_FEATURES 128
-
-extern pCMapFeature mapFeatures[];
 extern GameObject *objectList;
 extern WorldMapData *mapList;
 extern int16 currentMapNum;
@@ -353,9 +350,15 @@ bool Console::cmdGotoPlace(int argc, const char **argv) {
 	if (argc != 2)
 		debugPrintf("Usage: %s <place id>\n", argv[0]);
 	else {
-		int placeID = atoi(argv[1]);
-		int u = mapFeatures[placeID]->getU();
-		int v = mapFeatures[placeID]->getV();
+		uint placeID = atoi(argv[1]);
+
+		if (placeID > g_vm->_mapFeatures.size()) {
+			debugPrintf("Invalid place id > %d", g_vm->_mapFeatures.size());
+			return true;
+		}
+
+		int u = g_vm->_mapFeatures[placeID]->getU();
+		int v = g_vm->_mapFeatures[placeID]->getV();
 
 		Actor *a = getCenterActor();
 
@@ -376,9 +379,9 @@ bool Console::cmdListPlaces(int argc, const char **argv) {
 	if (argc != 1)
 		debugPrintf("Usage: %s\n", argv[0]);
 	else {
-		for (int i = 0; i < MAX_MAP_FEATURES; ++i) {
-			if (mapFeatures[i])
-				debugPrintf("%d: %s\n", i, mapFeatures[i]->getText());
+		for (uint i = 0; i < g_vm->_mapFeatures.size(); ++i) {
+			if (g_vm->_mapFeatures[i])
+				debugPrintf("%d: %s\n", i, g_vm->_mapFeatures[i]->getText());
 		}
 	}
 
diff --git a/engines/saga2/mapfeatr.cpp b/engines/saga2/mapfeatr.cpp
index 19ad96c094..f885341de8 100644
--- a/engines/saga2/mapfeatr.cpp
+++ b/engines/saga2/mapfeatr.cpp
@@ -35,29 +35,20 @@ namespace Saga2 {
    Constants
  * ===================================================================== */
 
-#define MAX_MAP_FEATURES 128
-
 #define STARGATE_COLOR  (164+9)
 #define VILLAGE_COLOR   (66+9)
 #define CAVE_COLOR      (10+9)
 
-/* ===================================================================== *
-   Locals
- * ===================================================================== */
-
-int32 mapFeatureCount = 0;
-pCMapFeature mapFeatures[MAX_MAP_FEATURES];
-
 /* ===================================================================== *
    Prototypes and inlines
  * ===================================================================== */
 
-#define MAP_VILLAGE(u,v,n)  mapFeatures[mapFeatureCount++]=\
-        new CStaticMapFeature(TilePoint(u,v,0),0,n,VILLAGE_COLOR);
-#define MAP_CAVE(u,v,n)  mapFeatures[mapFeatureCount++]=\
-        new CStaticMapFeature(TilePoint(u,v,0),0,n,CAVE_COLOR);
-#define MAP_STARGATE(u,v,n) mapFeatures[mapFeatureCount++]=\
-        new CStaticMapFeature(TilePoint(u,v,0),0,n,STARGATE_COLOR);
+#define MAP_VILLAGE(u,v,n)  g_vm->_mapFeatures.push_back(\
+        new CStaticMapFeature(TilePoint(u,v,0),0,n,VILLAGE_COLOR))
+#define MAP_CAVE(u,v,n)  g_vm->_mapFeatures.push_back(\
+        new CStaticMapFeature(TilePoint(u,v,0),0,n,CAVE_COLOR))
+#define MAP_STARGATE(u,v,n) g_vm->_mapFeatures.push_back(\
+        new CStaticMapFeature(TilePoint(u,v,0),0,n,STARGATE_COLOR))
 
 /* ===================================================================== *
    Map feature list maintainence
@@ -67,10 +58,6 @@ pCMapFeature mapFeatures[MAX_MAP_FEATURES];
 // init
 
 void initMapFeatures(void) {
-	for (int i = 0; i < MAX_MAP_FEATURES; i++) {
-		mapFeatures[i] = NULL;
-	}
-
 	//MAP_VILLAGE(13000,12535,"DummyVillage");
 	//MAP_STARGATE(1,2,"DummyGate");
 
@@ -248,12 +235,12 @@ void updateMapFeatures(int16 cWorld) {
 
 	uint16          *mapData = wMap->map->mapData;
 
-	for (int i = 0; i < mapFeatureCount; i++) {
-		if (mapFeatures[i]->getWorld() == cWorld) {
+	for (uint i = 0; i < g_vm->_mapFeatures.size(); i++) {
+		if (g_vm->_mapFeatures[i]->getWorld() == cWorld) {
 			uint16   *mapRow;
-			mapRow = &mapData[(mapFeatures[i]->getU() >> (kTileUVShift + kPlatShift)) * wMap->mapSize];
-			uint16   mtile = mapRow[(mapFeatures[i]->getV() >> (kTileUVShift + kPlatShift))];
-			mapFeatures[i]->expose(mtile & metaTileVisited);
+			mapRow = &mapData[(g_vm->_mapFeatures[i]->getU() >> (kTileUVShift + kPlatShift)) * wMap->mapSize];
+			uint16   mtile = mapRow[(g_vm->_mapFeatures[i]->getV() >> (kTileUVShift + kPlatShift))];
+			g_vm->_mapFeatures[i]->expose(mtile & metaTileVisited);
 		}
 	}
 }
@@ -265,8 +252,8 @@ void drawMapFeatures(TileRegion viewRegion,
                      int16 inWorld,
                      TilePoint baseCoords,
                      gPort &tPort) {
-	for (int i = 0; i < mapFeatureCount; i++) {
-		mapFeatures[i]->draw(viewRegion, inWorld, baseCoords, tPort);
+	for (uint i = 0; i < g_vm->_mapFeatures.size(); i++) {
+		g_vm->_mapFeatures[i]->draw(viewRegion, inWorld, baseCoords, tPort);
 	}
 
 }
@@ -282,9 +269,9 @@ char *getMapFeaturesText(TileRegion viewRegion,
                          Point16 mouseCoords) {
 	TilePoint m2 = TilePoint(mouseCoords.x, mouseCoords.y, 0);
 
-	for (int i = 0; i < mapFeatureCount; i++) {
-		if (mapFeatures[i]->hitCheck(viewRegion, inWorld, baseCoords, m2))
-			return mapFeatures[i]->getText();
+	for (uint i = 0; i < g_vm->_mapFeatures.size(); i++) {
+		if (g_vm->_mapFeatures[i]->hitCheck(viewRegion, inWorld, baseCoords, m2))
+			return g_vm->_mapFeatures[i]->getText();
 	}
 	return noMFText;
 
@@ -294,11 +281,12 @@ char *getMapFeaturesText(TileRegion viewRegion,
 // cleanup
 
 void termMapFeatures(void) {
-	for (int i = 0; i < MAX_MAP_FEATURES; i++) {
-		if (mapFeatures[i])
-			delete mapFeatures[i];
-		mapFeatures[i] = nullptr;
+	for (uint i = 0; i < g_vm->_mapFeatures.size(); i++) {
+		if (g_vm->_mapFeatures[i])
+			delete g_vm->_mapFeatures[i];
 	}
+
+	g_vm->_mapFeatures.clear();
 }
 
 
diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h
index ed233ac389..57548414f3 100644
--- a/engines/saga2/saga2.h
+++ b/engines/saga2/saga2.h
@@ -77,6 +77,7 @@ class TaskList;
 class Deejay;
 class frameSmoother;
 class frameCounter;
+class CMapFeature;
 
 enum {
 	kDebugResources = 1 << 0,
@@ -140,6 +141,7 @@ public:
 	Common::Array<PlayerActor *> _playerList;
 	Common::Array<ProtoObj *> _objectProtos;
 	Common::Array<ActorProto *> _actorProtos;
+	Common::Array<CMapFeature *> _mapFeatures;
 	Common::List<TimerList *> _timerLists;
 	Common::List<Timer *> _timers;
 	Common::List<ActorAppearance *> _appearanceLRU;


Commit: 3d1e511335637c1c8b3f8d9b32b0533c22af6e4e
    https://github.com/scummvm/scummvm/commit/3d1e511335637c1c8b3f8d9b32b0533c22af6e4e
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-21T02:48:51+09:00

Commit Message:
SAGA2: Enable RTL

Changed paths:
    engines/saga2/main.cpp


diff --git a/engines/saga2/main.cpp b/engines/saga2/main.cpp
index f5583d417d..c0b14cd453 100644
--- a/engines/saga2/main.cpp
+++ b/engines/saga2/main.cpp
@@ -266,7 +266,7 @@ void processEventLoop(bool updateScreen) {
 
 	debugC(1, kDebugEventLoop, "EventLoop: starting event loop");
 
-	if (checkExit && verifyUserExit()) {
+	if (g_vm->shouldQuit()) {
 		//g_vm->_gameRunning=false;
 		endGame();
 		return;




More information about the Scummvm-git-logs mailing list