[Scummvm-git-logs] scummvm master -> d766d8d2702b8760a1702ff8e999cd49dd045f7b

a-yyg 76591232+a-yyg at users.noreply.github.com
Sat Aug 21 22:29:11 UTC 2021


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

Summary:
06de8af3f6 SAGA2: Move some globaL variables to Saga2Engine
e23ba98f05 SAGA2: Fix timer cleanup
d766d8d270 SAGA2: Objectify vpal.cpp


Commit: 06de8af3f6b54e2a9fe03fc09698510ee633fe43
    https://github.com/scummvm/scummvm/commit/06de8af3f6b54e2a9fe03fc09698510ee633fe43
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-22T07:26:40+09:00

Commit Message:
SAGA2: Move some globaL variables to Saga2Engine

Changed paths:
    engines/saga2/floating.cpp
    engines/saga2/intrface.cpp
    engines/saga2/saga2.cpp
    engines/saga2/saga2.h
    engines/saga2/transit.cpp


diff --git a/engines/saga2/floating.cpp b/engines/saga2/floating.cpp
index 196d0e6b66..83e173ac53 100644
--- a/engines/saga2/floating.cpp
+++ b/engines/saga2/floating.cpp
@@ -609,8 +609,6 @@ void FloatingWindow::close(void) {
 
 bool checkTileAreaPort(void);
 
-extern bool userControlsSetup;
-
 void updateWindowSection(const Rect16 &r) {
 	gPixelMap       tempMap;
 	gPort           tempPort;
@@ -679,7 +677,7 @@ void updateWindowSection(const Rect16 &r) {
 
 	//  For each window, both background and float, that overlaps
 	//  the clip, draw the window's imagery
-	if (userControlsSetup) {
+	if (g_vm->_userControlsSetup) {
 		for (Common::List<gWindow *>::iterator it = g_vm->_toolBase->bottomWindowIterator(); it != g_vm->_toolBase->topWindowIterator(); --it)
 			(*it)->drawClipped(tempPort, offset, clip);
 	}
diff --git a/engines/saga2/intrface.cpp b/engines/saga2/intrface.cpp
index ed5f36dcba..0e232ff706 100644
--- a/engines/saga2/intrface.cpp
+++ b/engines/saga2/intrface.cpp
@@ -239,14 +239,6 @@ APPFUNC(cmdMassInd);
 APPFUNC(cmdBulkInd);
 APPFUNC(cmdManaInd);
 
-/* ===================================================================== *
-   Globals
- * ===================================================================== */
-static bool indivControlsFlag = false;
-
-bool userControlsSetup = false;
-
-
 /* ===================================================================== *
    User control metrics
  * ===================================================================== */
@@ -1350,7 +1342,7 @@ void CHealthIndicator::updateStar(GfxCompImage *starCtl, int32 bro, int32 baseVi
 }
 
 void CHealthIndicator::update(void) {
-	if (indivControlsFlag) {
+	if (g_vm->_indivControlsFlag) {
 		// get the stats for the selected brother
 		int16 baseVitality  = g_vm->_playerList[translatePanID(uiIndiv)]->getBaseStats().vitality;
 		int16 currVitality  = g_vm->_playerList[translatePanID(uiIndiv)]->getEffStats()->vitality;
@@ -1705,21 +1697,21 @@ void SetupUserControls(void) {
 
 	//The controls need to be enabled but undrawn at startup
 	//if ( displayEnabled() )
-	//  userControlsSetup = true;
+	//  g_vm->_userControlsSetup = true;
 	updateAllUserControls();
 }
 
 void enableUserControls(void) {
-	userControlsSetup = true;
+	g_vm->_userControlsSetup = true;
 }
 
 void disableUserControls(void) {
-	userControlsSetup = false;
+	g_vm->_userControlsSetup = false;
 }
 
 // defines the cleanup for ALL user interface controls
 void CleanupUserControls(void) {
-	userControlsSetup = false;
+	g_vm->_userControlsSetup = false;
 	CleanupButtonImages();
 }
 
@@ -1850,7 +1842,7 @@ uint16 getBulkRatio(GameObject *obj, uint16 &maxRatio, bool bReturnMaxRatio = tr
 
 void updateReadyContainers(void) {
 	// if in individual mode
-	if (indivControlsFlag) {
+	if (g_vm->_indivControlsFlag) {
 		indivCviewTop->invalidate();
 		indivCviewBot->invalidate();
 	} else if (TrioCviews[getCenterActorPlayerID()]) {
@@ -1864,7 +1856,7 @@ void setEnchantmentDisplay(void) {
 
 // sets the individual brother control state buttons
 void setIndivBtns(uint16 brotherID) {    // top = 0, mid = 1, bot = 2
-	indivControlsFlag = true;
+	g_vm->_indivControlsFlag = true;
 
 	// set the indiv bro
 	indivBrother = brotherID;
@@ -1904,7 +1896,7 @@ void setIndivBtns(uint16 brotherID) {    // top = 0, mid = 1, bot = 2
 
 // sets the trio brothers control state buttons
 void setTrioBtns(void) {
-	indivControlsFlag = false;
+	g_vm->_indivControlsFlag = false;
 
 	// reset any value that might have changed in idividual mode
 	centerBtns[indivBrother]->select(indivCenterBtn->isSelected());
@@ -1934,7 +1926,7 @@ void setControlPanelsToTrioMode(void) {
 }
 
 void toggleIndivMode(void) {
-	if (indivControlsFlag) setControlPanelsToTrioMode();
+	if (g_vm->_indivControlsFlag) setControlPanelsToTrioMode();
 	else setControlPanelsToIndividualMode(getCenterActorPlayerID());
 }
 
@@ -1956,7 +1948,7 @@ uint16 translatePanID(uint16 panID) {
 }
 
 void updateBrotherPortrait(uint16 brotherID, int16 pType) {
-	if (userControlsSetup) {
+	if (g_vm->_userControlsSetup) {
 		Portrait->set(brotherID, (PortraitType)pType);
 
 		if (brotherID == indivBrother)
@@ -1965,7 +1957,7 @@ void updateBrotherPortrait(uint16 brotherID, int16 pType) {
 }
 
 void updateBrotherAggressionButton(uint16 brotherID, bool aggressive) {
-	if (userControlsSetup) {
+	if (g_vm->_userControlsSetup) {
 		aggressBtns[brotherID]->select(aggressive);
 		aggressBtns[brotherID]->ghost(isBrotherDead(brotherID));
 
@@ -1980,7 +1972,7 @@ void updateBrotherAggressionButton(uint16 brotherID, bool aggressive) {
 }
 
 void updateBrotherBandingButton(uint16 brotherID, bool banded) {
-	if (userControlsSetup) {
+	if (g_vm->_userControlsSetup) {
 		bandingBtns[brotherID]->select(banded);
 		bandingBtns[brotherID]->ghost(isBrotherDead(brotherID));
 
@@ -1992,7 +1984,7 @@ void updateBrotherBandingButton(uint16 brotherID, bool banded) {
 }
 
 void updateBrotherRadioButtons(uint16 brotherID) {
-	if (userControlsSetup) {
+	if (g_vm->_userControlsSetup) {
 		bool    jul = (uiJulian == brotherID);
 		bool    phi = (uiPhillip == brotherID);
 		bool    kev = (uiKevin == brotherID);
@@ -2020,13 +2012,13 @@ void updateBrotherRadioButtons(uint16 brotherID) {
 			indivCenterBtn->ghost(isBrotherDead(brotherID));
 		}
 
-		if (indivControlsFlag)
+		if (g_vm->_indivControlsFlag)
 			setControlPanelsToIndividualMode(brotherID);
 	}
 }
 
 void updateBrotherArmor(uint16 brotherID) {
-	if (userControlsSetup) {
+	if (g_vm->_userControlsSetup) {
 		armorInd[brotherID]->setValue(brotherID);
 		armorInd[brotherID]->ghost(isBrotherDead(brotherID));
 
@@ -2039,11 +2031,11 @@ void updateBrotherArmor(uint16 brotherID) {
 
 void updateAllUserControls(void) {
 	if (displayEnabled()) {
-		if (userControlsSetup) {
+		if (g_vm->_userControlsSetup) {
 			uint16      centerBrotherID = getCenterActorPlayerID(),
 			            brotherID;
 
-			if (indivControlsFlag)
+			if (g_vm->_indivControlsFlag)
 				setControlPanelsToIndividualMode(indivBrother);
 			else
 				setControlPanelsToTrioMode();
@@ -2073,7 +2065,7 @@ void updateAllUserControls(void) {
 }
 
 void updateBrotherControls(PlayerActorID brotherID) {
-	if (userControlsSetup) {
+	if (g_vm->_userControlsSetup) {
 		bool    dead = isBrotherDead(brotherID);
 
 		updateBrotherRadioButtons(getCenterActorPlayerID());
@@ -2567,11 +2559,11 @@ APPFUNC(cmdManaInd) {
 }
 
 bool isIndivMode(void) {
-	return indivControlsFlag;
+	return g_vm->_indivControlsFlag;
 }
 
 void initUIState(void) {
-	indivControlsFlag = false;
+	g_vm->_indivControlsFlag = false;
 	indivBrother = 0;
 
 	//updateAllUserControls();
@@ -2583,21 +2575,21 @@ void saveUIState(Common::OutSaveFile *outS) {
 	outS->write("UIST", 4);
 
 	CHUNK_BEGIN;
-	out->writeUint16LE(indivControlsFlag);
+	out->writeUint16LE(g_vm->_indivControlsFlag);
 	out->writeUint16LE(indivBrother);
 	CHUNK_END;
 
-	debugC(3, kDebugSaveload, "... indivControlsFlag = %d", indivControlsFlag);
+	debugC(3, kDebugSaveload, "..._indivControlsFlag = %d", g_vm->_indivControlsFlag);
 	debugC(3, kDebugSaveload, "... indivBrother = %d", indivBrother);
 }
 
 void loadUIState(Common::InSaveFile *in) {
 	debugC(2, kDebugSaveload, "Loading UIState");
 
-	indivControlsFlag = in->readUint16LE();
+	g_vm->_indivControlsFlag = in->readUint16LE();
 	indivBrother = in->readUint16LE();
 
-	debugC(3, kDebugSaveload, "... indivControlsFlag = %d", indivControlsFlag);
+	debugC(3, kDebugSaveload, "... _indivControlsFlag = %d", g_vm->_indivControlsFlag);
 	debugC(3, kDebugSaveload, "... indivBrother = %d", indivBrother);
 
 	updateAllUserControls();
diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index 759ae6d6f0..a60b1fc133 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -85,6 +85,10 @@ Saga2Engine::Saga2Engine(OSystem *syst)
 	_teleportOnClick = false;
 	_teleportOnMap = false;
 
+	_indivControlsFlag = false;
+	_userControlsSetup = false;
+	_fadeDepth = 1;
+
 	SearchMan.addSubDirectoryMatching(gameDataDir, "res");
 	SearchMan.addSubDirectoryMatching(gameDataDir, "dos/drivers"); // For Miles Sound files
 	SearchMan.addSubDirectoryMatching(gameDataDir, "drivers");
diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h
index ce89adcdfb..d3809e7628 100644
--- a/engines/saga2/saga2.h
+++ b/engines/saga2/saga2.h
@@ -190,6 +190,11 @@ public:
 	bool _showPosition;
 	bool _showStats;
 
+	bool _indivControlsFlag;
+	bool _userControlsSetup;
+	int _fadeDepth;
+
+
 private:
 	Video::SmackerDecoder *_smkDecoder;
 	int _videoX, _videoY;
diff --git a/engines/saga2/transit.cpp b/engines/saga2/transit.cpp
index a3295a4c6d..ce5243413b 100644
--- a/engines/saga2/transit.cpp
+++ b/engines/saga2/transit.cpp
@@ -105,7 +105,6 @@ void SystemEventLoop(void);
 //-----------------------------------------------------------------------
 //	Fade to black
 
-static int fadeDepth = 1;
 void clearTileAreaPort(void);
 void reDrawScreen(void) ;
 void updateMainDisplay(void);
@@ -119,7 +118,7 @@ void disableUserControls(void);
 void enableUserControls(void);
 
 void fadeDown(void) {
-	if (fadeDepth++ == 0) {
+	if (g_vm->_fadeDepth++ == 0) {
 		beginFade(darkPalette, 20);
 		while (updatePalette());
 		clearTileAreaPort();
@@ -132,7 +131,7 @@ void fadeDown(void) {
 //	Fade to many colors
 
 void fadeUp(void) {
-	if (--fadeDepth == 0) {
+	if (--g_vm->_fadeDepth == 0) {
 		enableUserControls();
 		updateMainDisplay();
 		drawMainDisplay();


Commit: e23ba98f05b516c2784712446faeb154033a6677
    https://github.com/scummvm/scummvm/commit/e23ba98f05b516c2784712446faeb154033a6677
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-22T07:26:40+09:00

Commit Message:
SAGA2: Fix timer cleanup

Changed paths:
    engines/saga2/mainmap.cpp
    engines/saga2/saveload.cpp


diff --git a/engines/saga2/mainmap.cpp b/engines/saga2/mainmap.cpp
index 0caac0e059..cfb3aa6852 100644
--- a/engines/saga2/mainmap.cpp
+++ b/engines/saga2/mainmap.cpp
@@ -28,6 +28,7 @@
 #include "saga2/saga2.h"
 #include "saga2/fta.h"
 #include "saga2/mainmap.h"
+#include "saga2/timers.h"
 
 namespace Saga2 {
 
@@ -49,11 +50,12 @@ void shutdownGame() {
 }
 
 bool initSystemTimer() {
-	warning("STUB: initSystemTimer()");
+	initTimer();
 	return true;
 }
+
 void cleanupSystemTimer() {
-	warning("STUB: cleanupSystemTimer()");
+	cleanupTimer();
 }
 
 void cleanupSystemTasks() {
diff --git a/engines/saga2/saveload.cpp b/engines/saga2/saveload.cpp
index 21083a4e71..9067bfcbcf 100644
--- a/engines/saga2/saveload.cpp
+++ b/engines/saga2/saveload.cpp
@@ -115,7 +115,6 @@ void initGameState(void) {
 	pauseTimer();
 
 	initGlobals();
-	initTimer();
 	initCalender();
 	initWorlds();
 	initActors();
@@ -133,7 +132,6 @@ void initGameState(void) {
 	initTileTasks();
 	initSpeechTasks();
 	initActiveRegions();
-	initTimers();
 	initSensors();
 	initTempActorCount();
 	initMissions();
@@ -566,7 +564,6 @@ void cleanupGameState(void) {
 	cleanupObjects();
 	cleanupActors();
 	cleanupWorlds();
-	cleanupTimer();
 	cleanupGlobals();
 }
 


Commit: d766d8d2702b8760a1702ff8e999cd49dd045f7b
    https://github.com/scummvm/scummvm/commit/d766d8d2702b8760a1702ff8e999cd49dd045f7b
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-22T07:26:40+09:00

Commit Message:
SAGA2: Objectify vpal.cpp

Changed paths:
    engines/saga2/display.cpp
    engines/saga2/display.h
    engines/saga2/main.cpp
    engines/saga2/mainmap.cpp
    engines/saga2/palette.h
    engines/saga2/saga2.cpp
    engines/saga2/saga2.h
    engines/saga2/towerfta.cpp
    engines/saga2/transit.cpp
    engines/saga2/tromode.cpp
    engines/saga2/videobox.cpp
    engines/saga2/vpal.cpp
    engines/saga2/vpal.h


diff --git a/engines/saga2/display.cpp b/engines/saga2/display.cpp
index 1dacaeb0f3..ef822a092d 100644
--- a/engines/saga2/display.cpp
+++ b/engines/saga2/display.cpp
@@ -31,6 +31,7 @@
 #include "saga2/intrface.h"
 #include "saga2/loadmsg.h"
 #include "saga2/grabinfo.h"
+#include "saga2/vpal.h"
 
 namespace Saga2 {
 
@@ -57,12 +58,8 @@ static bool paletteSuspendFlag = false;
  * ===================================================================== */
 
 void reDrawScreen(void);
-void quickSavePalette(void);
-void quickRestorePalette(void);
 void localCursorOn(void);
 void localCursorOff(void);
-void setPaletteToBlack(void);
-void lightsOut(void);
 void loadingScreen(void);
 void resetInputDevices(void);
 APPFUNC(cmdWindowFunc);                      // main window event handler
@@ -241,7 +238,7 @@ void reDrawScreen(void) {
 		delayReDraw = false;
 		if (paletteMayHaveChanged) {
 			paletteMayHaveChanged = false;
-			assertCurrentPalette();
+			g_vm->_pal->assertCurrentPalette();
 			paletteMayHaveChanged = false;
 		}
 	} else
@@ -258,7 +255,7 @@ void blackOut(void) {
 	g_vm->_mainPort.drawMode = drawModeReplace;
 	g_vm->_mainPort.setColor(0);            //  fill screen with color
 	g_vm->_mainPort.fillRect(Rect16(0, 0, 640, 480));
-	lightsOut();
+	g_vm->_pal->lightsOut();
 }
 
 
diff --git a/engines/saga2/display.h b/engines/saga2/display.h
index 808c5565fa..c71595b00d 100644
--- a/engines/saga2/display.h
+++ b/engines/saga2/display.h
@@ -95,7 +95,6 @@ void resumeAudio(void);
 // ------------------------------------------------------------------------
 // The display may be disabled for several reasons these track them
 void blackOut(void);
-void assertCurrentPalette(void);
 
 } // end of namespace Saga2
 
diff --git a/engines/saga2/main.cpp b/engines/saga2/main.cpp
index c0b14cd453..a74c07be47 100644
--- a/engines/saga2/main.cpp
+++ b/engines/saga2/main.cpp
@@ -140,7 +140,6 @@ bool setupGame(void);
 
 void mainEnable(void);
 void mainDisable(void);
-void lightsOut(void);
 void updateMainDisplay(void);
 
 void cleanupGame(void);                  // auto-cleanup function
diff --git a/engines/saga2/mainmap.cpp b/engines/saga2/mainmap.cpp
index cfb3aa6852..21a63330d3 100644
--- a/engines/saga2/mainmap.cpp
+++ b/engines/saga2/mainmap.cpp
@@ -29,6 +29,7 @@
 #include "saga2/fta.h"
 #include "saga2/mainmap.h"
 #include "saga2/timers.h"
+#include "saga2/vpal.h"
 
 namespace Saga2 {
 
@@ -61,8 +62,9 @@ void cleanupSystemTimer() {
 void cleanupSystemTasks() {
 	warning("STUB: cleanupSystemTasks()");
 }
+
 void cleanupPaletteData() {
-	warning("STUB: cleanupPaletteData()");
+	g_vm->_pal->cleanupPalettes();
 }
 
 } // end of namespace Saga2
diff --git a/engines/saga2/palette.h b/engines/saga2/palette.h
index 7c0d52b997..0a0dcdd136 100644
--- a/engines/saga2/palette.h
+++ b/engines/saga2/palette.h
@@ -27,51 +27,14 @@
 #ifndef SAGA2_PALETTE_H
 #define SAGA2_PALETTE_H
 
-namespace Saga2 {
-
-/* ===================================================================== *
-   Typedefs
- * ===================================================================== */
+#include "saga2/vpal.h"
 
-typedef gPalette        *gPalettePtr;
-
-/* ===================================================================== *
-   Exports
- * ===================================================================== */
-
-//  Global palette resource handles
-extern gPalettePtr   midnightPalette,
-       noonPalette,
-       darkPalette;
+namespace Saga2 {
 
 /* ===================================================================== *
    Function prototypes
  * ===================================================================== */
 
-//  Initialize global palette resources
-void loadPalettes(void);
-//  Dump global palette resources
-void cleanupPalettes(void);
-
-//  Begin fade up/down
-void beginFade(gPalettePtr newPalette, int32 fadeDuration);
-//  Update state of palette fade up/down
-bool updatePalette(void);
-
-//  Linearly interpolate between two specified palettes
-void createPalette(
-    gPalettePtr newP,
-    gPalettePtr srcP,
-    gPalettePtr dstP,
-    int32       elapsedTime,
-    int32       totalTime);
-//  Set the current palette
-void setCurrentPalette(gPalettePtr newPal);
-//  Return the current palette
-void getCurrentPalette(gPalettePtr pal);
-
-void setPaletteToBlack(void);
-
 //  Initialize the state of the current palette and fade up/down.
 void initPaletteState(void);
 //  Save the current state of the current palette and fade up/down in
diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index a60b1fc133..df3bf9f03e 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -47,6 +47,7 @@
 #include "saga2/music.h"
 #include "saga2/panel.h"
 #include "saga2/spelshow.h"
+#include "saga2/vpal.h"
 
 namespace Saga2 {
 
@@ -66,6 +67,7 @@ Saga2Engine::Saga2Engine(OSystem *syst)
 	_console = nullptr;
 	_renderer = nullptr;
 	_audio = nullptr;
+	_pal = nullptr;
 
 	_bandList = nullptr;
 	_mouseInfo = nullptr;
@@ -125,6 +127,7 @@ Saga2Engine::~Saga2Engine() {
 	// Dispose your resources here
 	delete _rnd;
 	delete _renderer;
+	delete _pal;
 
 	delete _imageCache;
 	delete _mTaskList;
@@ -151,6 +154,8 @@ Common::Error Saga2Engine::run() {
 
 	_renderer = new Renderer();
 
+	_pal = new PaletteManager;
+
 	readConfig();
 
 	loadExeResources();
diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h
index d3809e7628..d852285aec 100644
--- a/engines/saga2/saga2.h
+++ b/engines/saga2/saga2.h
@@ -79,6 +79,7 @@ class frameSmoother;
 class frameCounter;
 class CMapFeature;
 class AudioInterface;
+class PaletteManager;
 
 enum {
 	kDebugResources = 1 << 0,
@@ -136,6 +137,7 @@ public:
 	Console *_console;
 	Renderer *_renderer;
 	AudioInterface *_audio;
+	PaletteManager *_pal;
 
 	WeaponStuff _weaponRack[kMaxWeapons];
 	weaponID _loadedWeapons;
diff --git a/engines/saga2/towerfta.cpp b/engines/saga2/towerfta.cpp
index 2fa47e4ce9..4ecc3ce463 100644
--- a/engines/saga2/towerfta.cpp
+++ b/engines/saga2/towerfta.cpp
@@ -40,6 +40,7 @@
 #include "saga2/saveload.h"
 #include "saga2/display.h"
 #include "saga2/tile.h"
+#include "saga2/vpal.h"
 
 namespace Saga2 {
 
@@ -236,7 +237,7 @@ TERMINATOR(termResourceHandles) {
 // ------------------------------------------------------------------------
 
 INITIALIZER(initPalettes) {
-	loadPalettes();
+	g_vm->_pal->loadPalettes();
 	return true;
 }
 
diff --git a/engines/saga2/transit.cpp b/engines/saga2/transit.cpp
index ce5243413b..188a37a9c1 100644
--- a/engines/saga2/transit.cpp
+++ b/engines/saga2/transit.cpp
@@ -79,25 +79,25 @@ void dayNightUpdate(void) {
 	if (lightLevel != prevLightLevel) {
 		prevLightLevel = lightLevel;
 
-		createPalette(
+		g_vm->_pal->createPalette(
 		    &newPalette,
-		    midnightPalette,
-		    noonPalette,
+		    g_vm->_pal->_midnightPalette,
+		    g_vm->_pal->_noonPalette,
 		    lightLevel,
 		    MAX_LIGHT);
 
 		if (currentMapNum == 0)
-			beginFade(&newPalette, 100);
+			g_vm->_pal->beginFade(&newPalette, 100);
 	}
 
-	if (!updatePalette()) {
+	if (!g_vm->_pal->updatePalette()) {
 		gPalettePtr     neededPalette;
 		gPalette        currentPalette;
 
-		neededPalette = currentMapNum == 0 ? &newPalette : noonPalette;
-		getCurrentPalette(&currentPalette);
+		neededPalette = currentMapNum == 0 ? &newPalette : g_vm->_pal->_noonPalette;
+		g_vm->_pal->getCurrentPalette(&currentPalette);
 		if (memcmp(&currentPalette, neededPalette, sizeof(gPalette)) != 0)
-			setCurrentPalette(neededPalette);
+			g_vm->_pal->setCurrentPalette(neededPalette);
 	}
 }
 
@@ -119,8 +119,8 @@ void enableUserControls(void);
 
 void fadeDown(void) {
 	if (g_vm->_fadeDepth++ == 0) {
-		beginFade(darkPalette, 20);
-		while (updatePalette());
+		g_vm->_pal->beginFade(g_vm->_pal->_darkPalette, 20);
+		while (g_vm->_pal->updatePalette());
 		clearTileAreaPort();
 		blackOut();
 		disablePaletteChanges();
@@ -137,8 +137,8 @@ void fadeUp(void) {
 		drawMainDisplay();
 		reDrawScreen();
 		enablePaletteChanges();
-		beginFade(currentMapNum != 0 ? noonPalette : &newPalette, 20);
-		while (updatePalette()) ;
+		g_vm->_pal->beginFade(currentMapNum != 0 ? g_vm->_pal->_noonPalette : &newPalette, 20);
+		while (g_vm->_pal->updatePalette()) ;
 	}
 }
 
diff --git a/engines/saga2/tromode.cpp b/engines/saga2/tromode.cpp
index 9f9e209ffc..fca0c18ffd 100644
--- a/engines/saga2/tromode.cpp
+++ b/engines/saga2/tromode.cpp
@@ -31,6 +31,7 @@
 #include "saga2/player.h"
 #include "saga2/display.h"
 #include "saga2/panel.h"
+#include "saga2/vpal.h"
 
 namespace Saga2 {
 
@@ -58,8 +59,6 @@ void SystemEventLoop(void);
 void freeAllTileBanks(void);
 void resetInputDevices(void);
 void blackOut(void);
-void quickSavePalette(void);
-void quickRestorePalette(void);
 void cursorFullHide(bool onOff);
 
 static void doIntro(void);
@@ -146,7 +145,7 @@ void TroModeExternEvent(void) {
 static void TroModeSetup(void) {
 	suspendAudio();
 	g_vm->_pointer->hide();
-	quickSavePalette();
+	g_vm->_pal->quickSavePalette();
 	blackOut();
 	displayDisable(PlayingVideo);
 	pushVidState();
@@ -162,7 +161,7 @@ static void TroModeCleanup(void) {
 	popVidState();
 	displayEnable(PlayingVideo);
 	blackOut();
-	quickRestorePalette();
+	g_vm->_pal->quickRestorePalette();
 	resumeAudio();
 	g_vm->_pointer->show();
 //	g_vm->_pointer->manditoryShow();                     //  hide mouse pointer
diff --git a/engines/saga2/videobox.cpp b/engines/saga2/videobox.cpp
index d5598f5146..1d59645c4a 100644
--- a/engines/saga2/videobox.cpp
+++ b/engines/saga2/videobox.cpp
@@ -26,6 +26,7 @@
 
 #include "saga2/saga2.h"
 #include "saga2/videobox.h"
+#include "saga2/vpal.h"
 
 namespace Saga2 {
 
@@ -168,14 +169,12 @@ int16 CVideoBox::openVidBox(char *fileName) {
 	return rInfo.result;
 }
 
-void quickSavePalette(void);
-void quickRestorePalette(void);
 // this opens a video box for business
 int16 openVidBox(char *fileName) {
 	// get the area of the vid box
 	Rect16 area = CVideoBox::getAreaRect();
 
-	quickSavePalette();
+	g_vm->_pal->quickSavePalette();
 	// create a video box
 	CVideoBox videoBox(area, 0, NULL);
 
@@ -185,7 +184,7 @@ int16 openVidBox(char *fileName) {
 	// get rid of the box when done
 	videoBox.~CVideoBox();
 
-	quickRestorePalette();
+	g_vm->_pal->quickRestorePalette();
 	// replace the damaged area
 	mainWindow->invalidate(&area);
 
diff --git a/engines/saga2/vpal.cpp b/engines/saga2/vpal.cpp
index 26518b3c3d..ec178b671d 100644
--- a/engines/saga2/vpal.cpp
+++ b/engines/saga2/vpal.cpp
@@ -48,41 +48,29 @@ extern hResContext      *tileRes;           // tile resource handle
 extern volatile int32   gameTime;
 
 /* ===================================================================== *
-   Exports
- * ===================================================================== */
-
-void lightsOut(void);
-
-gPalettePtr             midnightPalette,
-                        noonPalette = nullptr,
-                        darkPalette;
-
-/* ===================================================================== *
-   Globals
+   Functions
  * ===================================================================== */
 
-static gPalette         currentPalette;     //  Currently loaded palette
-
-//  Fade up/down data
-static gPalette         oldPalette,         //  Palette at start of fade
-       destPalette,        //  Destination palette of fade
-       quickPalette;
-static int32            startTime,          //  Time index of start of fade
-       totalTime;          //  Total fade duration
+PaletteManager::PaletteManager() {
+	_midnightPalette = nullptr;
+	_noonPalette = nullptr;
+	_darkPalette = nullptr;
 
-//  palette state
+	memset(_currentPalette.entry, 0, sizeof(_currentPalette.entry));
+	memset(_oldPalette.entry, 0, sizeof(_oldPalette.entry));
+	memset(_destPalette.entry, 0, sizeof(_destPalette.entry));
+	memset(_quickPalette.entry, 0, sizeof(_quickPalette.entry));
 
-/* ===================================================================== *
-   Functions
- * ===================================================================== */
+	_startTime = _totalTime = 0;
+}
 
-void assertCurrentPalette(void) {
+void PaletteManager::assertCurrentPalette(void) {
 	if (paletteChangesEnabled()) {
 		byte palette[256 * 3];
 		for (int i = 0; i < 256; i++) {
-			palette[i * 3 + 0] = ((byte *)&currentPalette)[i * 3 + 0] << 2;
-			palette[i * 3 + 1] = ((byte *)&currentPalette)[i * 3 + 1] << 2;
-			palette[i * 3 + 2] = ((byte *)&currentPalette)[i * 3 + 2] << 2;
+			palette[i * 3 + 0] = ((byte *)&_currentPalette)[i * 3 + 0] << 2;
+			palette[i * 3 + 1] = ((byte *)&_currentPalette)[i * 3 + 1] << 2;
+			palette[i * 3 + 2] = ((byte *)&_currentPalette)[i * 3 + 2] << 2;
 		}
 		g_system->getPaletteManager()->setPalette(palette, 0, 256);
 	}
@@ -112,22 +100,22 @@ static inline int16 bscale(int16 s) {
 	else return (63 + s) / 2;
 }
 
-void loadPalettes(void) {
+void PaletteManager::loadPalettes(void) {
 	int     i;
 
 	//  Create a black palette for fades
-	darkPalette = new gPalette;
-	memset(darkPalette, 0, sizeof(gPalette));
+	g_vm->_pal->_darkPalette = new gPalette;
+	memset(g_vm->_pal->_darkPalette, 0, sizeof(gPalette));
 
 
 	//  Load standard palette
-	noonPalette = (gPalettePtr)LoadResource(tileRes, paletteID, "noon palette");
+	g_vm->_pal->_noonPalette = (gPalettePtr)LoadResource(tileRes, paletteID, "noon palette");
 
 	//  Create a midnight palette for night time effect
-	midnightPalette = new gPalette;
+	g_vm->_pal->_midnightPalette = new gPalette;
 
-	gPalette    *dayPal = noonPalette;
-	gPalette    *nightPal = midnightPalette;
+	gPalette    *dayPal = g_vm->_pal->_noonPalette;
+	gPalette    *nightPal = g_vm->_pal->_midnightPalette;
 
 	// these colors darkened
 	for (i = 10; i < 240; i++) {
@@ -163,69 +151,69 @@ void loadPalettes(void) {
 //----------------------------------------------------------------------
 //	Dump global palette resources
 
-void cleanupPalettes(void) {
-	if (noonPalette) {
-		free(noonPalette);
-		noonPalette = nullptr;
+void PaletteManager::cleanupPalettes(void) {
+	if (g_vm->_pal->_noonPalette) {
+		free(g_vm->_pal->_noonPalette);
+		g_vm->_pal->_noonPalette = nullptr;
 	}
 
-	if (darkPalette) {
-		delete darkPalette;
-		darkPalette = nullptr;
+	if (g_vm->_pal->_darkPalette) {
+		delete g_vm->_pal->_darkPalette;
+		g_vm->_pal->_darkPalette = nullptr;
 	}
 
-	if (midnightPalette) {
-		delete midnightPalette;
-		midnightPalette = nullptr;
+	if (g_vm->_pal->_midnightPalette) {
+		delete g_vm->_pal->_midnightPalette;
+		g_vm->_pal->_midnightPalette = nullptr;
 	}
 }
 
 //----------------------------------------------------------------------
 //	Begin fade up/down
 
-void beginFade(gPalettePtr newPalette, int32 fadeDuration) {
-	startTime = gameTime;
-	totalTime = fadeDuration;
+void PaletteManager::beginFade(gPalettePtr newPalette, int32 fadeDuration) {
+	_startTime = gameTime;
+	_totalTime = fadeDuration;
 
 	//  Save the current palette for interpolation
-	memcpy(&oldPalette, &currentPalette, sizeof(gPalette));
+	memcpy(&_oldPalette, &_currentPalette, sizeof(gPalette));
 
 	//  Copy the destination palette
-	memcpy(&destPalette, newPalette, sizeof(gPalette));
+	memcpy(&_destPalette, newPalette, sizeof(gPalette));
 }
 
 //----------------------------------------------------------------------
 //	Update state of palette fade up/down
 
-bool updatePalette() {
+bool PaletteManager::updatePalette() {
 	int32           elapsedTime;
 
-	elapsedTime = gameTime - startTime;
-	if (totalTime == 0)
+	elapsedTime = gameTime - _startTime;
+	if (_totalTime == 0)
 		return false;
 
-	if (elapsedTime >= totalTime) {
+	if (elapsedTime >= _totalTime) {
 		//  Fade is completed
-		totalTime = 0;
-		memcpy(&currentPalette, &destPalette, sizeof(gPalette));
+		_totalTime = 0;
+		memcpy(&_currentPalette, &_destPalette, sizeof(gPalette));
 		assertCurrentPalette();
 		return false;
 	} else {
 		gPalette        tempPalette;
 
-		debugC(2, kDebugPalettes, "Fade: %d/%d", elapsedTime, totalTime);
+		debugC(2, kDebugPalettes, "Fade: %d/%d", elapsedTime, _totalTime);
 
 		createPalette(
 		    &tempPalette,
-		    &oldPalette,
-		    &destPalette,
+		    &_oldPalette,
+		    &_destPalette,
 		    elapsedTime,
-		    totalTime);
+		    _totalTime);
 
-		if (memcmp(&tempPalette, &currentPalette, sizeof(gPalette)) != 0) {
-			debugC(2, kDebugPalettes, "Fade:*%d/%d", elapsedTime, totalTime);
+		if (memcmp(&tempPalette, &_currentPalette, sizeof(gPalette)) != 0) {
+			debugC(2, kDebugPalettes, "Fade:*%d/%d", elapsedTime, _totalTime);
 
-			memcpy(&currentPalette, &tempPalette, sizeof(gPalette));
+			memcpy(&_currentPalette, &tempPalette, sizeof(gPalette));
 			assertCurrentPalette();
 
 			g_system->updateScreen();
@@ -238,16 +226,16 @@ bool updatePalette() {
 //----------------------------------------------------------------------
 //	Linearly interpolate between two specified palettes
 
-void createPalette(
+void PaletteManager::createPalette(
     gPalettePtr newP,
     gPalettePtr srcP,
     gPalettePtr dstP,
     int32       elapsedTime,
-    int32       totalTime_) {
-	assert(totalTime_ != 0);
+    int32       _totalTime_) {
+	assert(_totalTime_ != 0);
 
 	int             i;
-	uint32          fadeProgress = (elapsedTime << 8) / totalTime_;
+	uint32          fadeProgress = (elapsedTime << 8) / _totalTime_;
 
 	for (i = 0; i < (long)ARRAYSIZE(newP->entry); i++) {
 		gPaletteEntry   *srcPal = &srcP->entry[i];
@@ -264,98 +252,90 @@ void createPalette(
 //----------------------------------------------------------------------
 //	Set the current palette
 
-void setCurrentPalette(gPalettePtr newPal) {
-	memcpy(&currentPalette, newPal, sizeof(gPalette));
+void PaletteManager::setCurrentPalette(gPalettePtr newPal) {
+	memcpy(&_currentPalette, newPal, sizeof(gPalette));
 	assertCurrentPalette();
 }
 
 //----------------------------------------------------------------------
 //	Return the current palette
 
-void getCurrentPalette(gPalettePtr pal) {
-	memcpy(pal, &currentPalette, sizeof(gPalette));
+void PaletteManager::getCurrentPalette(gPalettePtr pal) {
+	memcpy(pal, &_currentPalette, sizeof(gPalette));
 }
 
-//----------------------------------------------------------------------
-
-void setPaletteToBlack(void) {
-	setCurrentPalette(darkPalette);
-}
-
-
 //----------------------------------------------------------------------
 //	Initialize the state of the current palette and fade up/down.
 
-void initPaletteState(void) {
+void PaletteManager::initPaletteState(void) {
 	//setCurrentPalette( *noonPalette );
-	totalTime = startTime = 0;
+	_totalTime = _startTime = 0;
 }
 
 //----------------------------------------------------------------------
 // routines to suspend & restore a palette state (during videos)
 
-void lightsOut(void) {
-	memset(&currentPalette, 0, sizeof(currentPalette));
-	assertCurrentPalette();
-}
-
-void lightsOn(void) {
-	setCurrentPalette(noonPalette);
-	totalTime = startTime = 0;
-	assertCurrentPalette();
-}
-
-void usePalette(void *p, size_t s) {
-	memcpy(&currentPalette, p, s);
+void PaletteManager::lightsOut(void) {
+	memset(&_currentPalette, 0, sizeof(_currentPalette));
 	assertCurrentPalette();
 }
 
-
 //----------------------------------------------------------------------
 // routines to suspend & restore a palette state (during videos)
 
-void quickSavePalette(void) {
-	memcpy(&quickPalette, &currentPalette, sizeof(gPalette));
+void PaletteManager::quickSavePalette(void) {
+	memcpy(&_quickPalette, &_currentPalette, sizeof(gPalette));
 }
 
-void quickRestorePalette(void) {
-	memcpy(&currentPalette, &quickPalette, sizeof(gPalette));
+void PaletteManager::quickRestorePalette(void) {
+	memcpy(&_currentPalette, &_quickPalette, sizeof(gPalette));
 	assertCurrentPalette();
 }
 
-
-void savePaletteState(Common::OutSaveFile *outS) {
+void PaletteManager::savePaletteState(Common::OutSaveFile *outS) {
 	debugC(2, kDebugSaveload, "Saving Palette States");
 
 	outS->write("PALE", 4);
 
 	CHUNK_BEGIN;
-	currentPalette.write(out);
-	oldPalette.write(out);
-	destPalette.write(out);
-	out->writeSint32LE(startTime);
-	out->writeSint32LE(totalTime);
+	_currentPalette.write(out);
+	_oldPalette.write(out);
+	_destPalette.write(out);
+	out->writeSint32LE(_startTime);
+	out->writeSint32LE(_totalTime);
 	CHUNK_END;
 
-	debugC(3, kDebugSaveload, "... startTime = %d", startTime);
-	debugC(3, kDebugSaveload, "... totalTime = %d", totalTime);
+	debugC(3, kDebugSaveload, "... _startTime = %d", _startTime);
+	debugC(3, kDebugSaveload, "... _totalTime = %d", _totalTime);
 }
 
-void loadPaletteState(Common::InSaveFile *in) {
+void PaletteManager::loadPaletteState(Common::InSaveFile *in) {
 	debugC(2, kDebugSaveload, "Loading Palette States");
 
 	gPalette tempPalette;
 
 	tempPalette.read(in);
-	oldPalette.read(in);
-	destPalette.read(in);
-	startTime = in->readSint32LE();
-	totalTime = in->readSint32LE();
+	_oldPalette.read(in);
+	_destPalette.read(in);
+	_startTime = in->readSint32LE();
+	_totalTime = in->readSint32LE();
 
-	debugC(3, kDebugSaveload, "... startTime = %d", startTime);
-	debugC(3, kDebugSaveload, "... totalTime = %d", totalTime);
+	debugC(3, kDebugSaveload, "... _startTime = %d", _startTime);
+	debugC(3, kDebugSaveload, "... _totalTime = %d", _totalTime);
 
 	setCurrentPalette(&tempPalette);
 }
 
+void initPaletteState(void) {
+	g_vm->_pal->initPaletteState();
+}
+
+void savePaletteState(Common::OutSaveFile *outS) {
+	g_vm->_pal->savePaletteState(outS);
+}
+
+void loadPaletteState(Common::InSaveFile *in) {
+	g_vm->_pal->loadPaletteState(in);
+}
+
 } // end of namespace Saga2
diff --git a/engines/saga2/vpal.h b/engines/saga2/vpal.h
index 5131fd250b..f22776bf48 100644
--- a/engines/saga2/vpal.h
+++ b/engines/saga2/vpal.h
@@ -48,6 +48,8 @@ struct gPalette {
 	void write(Common::MemoryWriteStreamDynamic *out);
 };
 
+typedef gPalette *gPalettePtr;
+
 /* ===================================================================== *
                              Prototypes
  * ===================================================================== */
@@ -56,6 +58,43 @@ void LoadPalette(gPalette &palette);
 int32 ColorDistance(gPaletteEntry &c1, gPaletteEntry &c2);
 void CalcPens(gPalette &, gPaletteEntry *, gPen *, int16, bool);
 
+class PaletteManager {
+private:
+	gPalette _currentPalette;
+
+	gPalette _oldPalette,
+             _destPalette,
+             _quickPalette;
+
+	int32 _startTime,
+		  _totalTime;
+
+
+public:
+	gPalettePtr _midnightPalette,
+			    _noonPalette,
+			    _darkPalette;
+
+	PaletteManager();
+	//~PaletteManager() {}
+
+	void assertCurrentPalette();
+	void loadPalettes();
+	void cleanupPalettes();
+	void beginFade(gPalettePtr newPalette, int32 fadeDuration);
+	bool updatePalette();
+	void createPalette(gPalettePtr newP, gPalettePtr srcP, gPalettePtr dstP,
+	                   int32 elapsedTime, int32 totalTime_);
+	void setCurrentPalette(gPalettePtr newPal);
+	void getCurrentPalette(gPalettePtr pal);
+	void initPaletteState();
+	void lightsOut();
+	void quickSavePalette();
+	void quickRestorePalette();
+	void savePaletteState(Common::OutSaveFile *outS);
+	void loadPaletteState(Common::InSaveFile *in);
+};
+
 } // end of namespace Saga2
 
 #endif




More information about the Scummvm-git-logs mailing list