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

a-yyg 76591232+a-yyg at users.noreply.github.com
Wed Aug 25 19:43:51 UTC 2021


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:
db33d0ccac SAGA2: Move global variables in beegee.cpp to Deejay class
e6db9ded56 SAGA2: Move calender to Saga2Engine


Commit: db33d0ccaca76e3c78f871377943b9913a100bd3
    https://github.com/scummvm/scummvm/commit/db33d0ccaca76e3c78f871377943b9913a100bd3
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-26T04:07:30+09:00

Commit Message:
SAGA2: Move global variables in beegee.cpp to Deejay class

Changed paths:
    engines/saga2/actor.cpp
    engines/saga2/actor.h
    engines/saga2/beegee.cpp
    engines/saga2/beegee.h
    engines/saga2/idtypes.h


diff --git a/engines/saga2/actor.cpp b/engines/saga2/actor.cpp
index bad9d40ce3..742ae603a4 100644
--- a/engines/saga2/actor.cpp
+++ b/engines/saga2/actor.cpp
@@ -3557,8 +3557,8 @@ void cleanupActors(void) {
 
 int16 AddFactionTally(int faction, enum factionTallyTypes act, int amt) {
 #if DEBUG
-	if (faction >= maxFactions)
-		error("Scripter: Tell Talin to increase maxFactions!\n");
+	if (faction >= kMaxFactions)
+		error("Scripter: Tell Talin to increase kMaxFactions!\n");
 	assert(faction >= 0);
 	assert(act >= 0);
 	assert(act < factionNumColumns);
@@ -3588,8 +3588,8 @@ int16 AddFactionTally(int faction, enum factionTallyTypes act, int amt) {
 //  Get the attitude a particular faction has for a char.
 int16 GetFactionTally(int faction, enum factionTallyTypes act) {
 #if DEBUG
-	if (faction >= maxFactions)
-		error("Scripter: Tell Talin to increase maxFactions!\n");
+	if (faction >= kMaxFactions)
+		error("Scripter: Tell Talin to increase kMaxFactions!\n");
 	assert(faction >= 0);
 	assert(act >= 0);
 	assert(act < factionNumColumns);
@@ -3610,7 +3610,7 @@ void saveFactionTallies(Common::OutSaveFile *outS) {
 
 	outS->write("FACT", 4);
 	CHUNK_BEGIN;
-	for (int i = 0; i < maxFactions; ++i) {
+	for (int i = 0; i < kMaxFactions; ++i) {
 		for (int j = 0; j < factionNumColumns; ++j)
 			out->writeSint16LE(g_vm->_act->_factionTable[i][j]);
 	}
@@ -3620,7 +3620,7 @@ void saveFactionTallies(Common::OutSaveFile *outS) {
 void loadFactionTallies(Common::InSaveFile *in) {
 	debugC(2, kDebugSaveload, "Loading Faction Tallies");
 
-	for (int i = 0; i < maxFactions; ++i) {
+	for (int i = 0; i < kMaxFactions; ++i) {
 		for (int j = 0; j < factionNumColumns; ++j)
 			g_vm->_act->_factionTable[i][j] = in->readSint16LE();
 	}
diff --git a/engines/saga2/actor.h b/engines/saga2/actor.h
index de641972e1..1803a625ca 100644
--- a/engines/saga2/actor.h
+++ b/engines/saga2/actor.h
@@ -1097,9 +1097,6 @@ void addEnchantment(Actor *a, uint16 enchantmentID);
    Actor factions table
  * ============================================================================ */
 
-//  Let's assume 64 factions maximum for now
-const int           maxFactions = 64;
-
 enum factionTallyTypes {
 	factionNumKills = 0,            // # of times faction member killed by PC
 	factionNumThefts,               // # of times PC steals from faction member
@@ -1142,7 +1139,7 @@ public:
 
 	int32 _updatesViaScript;
 	int32 _baseActorIndex;
-	int16 _factionTable[maxFactions][factionNumColumns];
+	int16 _factionTable[kMaxFactions][factionNumColumns];
 	bool _actorStatesPaused;
 	bool _combatBehaviorEnabled;
 
diff --git a/engines/saga2/beegee.cpp b/engines/saga2/beegee.cpp
index 9c9d706e12..42d34d8e3a 100644
--- a/engines/saga2/beegee.cpp
+++ b/engines/saga2/beegee.cpp
@@ -35,19 +35,6 @@ namespace Saga2 {
 #define AUXTHEMES 2
 #define USEAUXTHEME 0xe0
 
-struct auxAudioTheme {
-	bool active;
-	StaticLocation l;
-	uint32 loopID;
-};
-
-static const StaticTilePoint NullTile = {(int16)minint16, (int16)minint16, (int16)minint16};
-
-static auxAudioTheme aats[AUXTHEMES] = {
-	{false, {NullTile, 0}, 0},
-	{false, {NullTile, 0}, 0}
-};
-
 void addAuxTheme(Location loc, uint32 lid);
 void killAuxTheme(uint32 lid);
 void killAllAuxThemes(void);
@@ -138,45 +125,6 @@ extern GameObject *getViewCenterObject(void);
 extern bool debugAudioThemes;
 #endif
 
-/* ===================================================================== *
-   Locals
- * ===================================================================== */
-
-static uint32 currentTheme = 0;
-static uint32 auxTheme = 0;
-static StaticPoint32 themeAt = {0, 0};
-
-static int32 lastGameTime = 0;
-static int32 elapsedGameTime = 0;
-
-static bool playingExternalLoop = false;
-
-int activeFactions[maxFactions];
-
-
-static StaticTilePoint themeVectors[kMaxThemes] = {
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0},
-	{0, 0, 0}
-};
-
-
-
-int16 themeCount[kMaxThemes];
-
 /* ===================================================================== *
    Prototypes
  * ===================================================================== */
@@ -210,10 +158,10 @@ void initAudioEnvirons(void) {
 
 void addAuxTheme(Location loc, uint32 lid) {
 	for (int i = 0; i < AUXTHEMES; i++) {
-		if (!aats[i].active) {
-			aats[i].l.set(loc, loc.context);
-			aats[i].loopID = lid;
-			aats[i].active = true;
+		if (!g_vm->_grandMasterFTA->_aats[i].active) {
+			g_vm->_grandMasterFTA->_aats[i].l = loc;
+			g_vm->_grandMasterFTA->_aats[i].loopID = lid;
+			g_vm->_grandMasterFTA->_aats[i].active = true;
 			return;
 		}
 	}
@@ -221,15 +169,15 @@ void addAuxTheme(Location loc, uint32 lid) {
 
 void killAuxTheme(uint32 lid) {
 	for (int i = 0; i < AUXTHEMES; i++) {
-		if (aats[i].active &&   aats[i].loopID == lid) {
-			aats[i].active = false;
+		if (g_vm->_grandMasterFTA->_aats[i].active &&   g_vm->_grandMasterFTA->_aats[i].loopID == lid) {
+			g_vm->_grandMasterFTA->_aats[i].active = false;
 		}
 	}
 }
 
 void killAllAuxThemes(void) {
 	for (int i = 0; i < AUXTHEMES; i++) {
-		aats[i].active = false;
+		g_vm->_grandMasterFTA->_aats[i].active = false;
 	}
 }
 
@@ -237,24 +185,23 @@ void killAllAuxThemes(void) {
 // Hooks to allow other loops to play
 
 void disableBGLoop(bool s) {
-	playingExternalLoop = s;
+	g_vm->_grandMasterFTA->_playingExternalLoop = s;
 }
 
 void enableBGLoop(void) {
-	uint32 cr = currentTheme;
-	playingExternalLoop = false;
-	currentTheme = 0;
-	audioEnvironmentUseSet(cr, auxTheme, themeAt);
+	uint32 cr = g_vm->_grandMasterFTA->_currentTheme;
+	g_vm->_grandMasterFTA->_playingExternalLoop = false;
+	g_vm->_grandMasterFTA->_currentTheme = 0;
+	audioEnvironmentUseSet(cr, g_vm->_grandMasterFTA->_auxTheme, g_vm->_grandMasterFTA->_themeAt);
 }
 
 //-----------------------------------------------------------------------
 // Main loop selection routine - called from Tile.cpp
 
-static int32 pct = 0;
 void setAreaSound(const TilePoint &) {
-	pct = (pct + 1) % 8;
-	if (pct == 0) {
-		if (!playingExternalLoop) {
+	g_vm->_grandMasterFTA->_pct = (g_vm->_grandMasterFTA->_pct + 1) % 8;
+	if (g_vm->_grandMasterFTA->_pct == 0) {
+		if (!g_vm->_grandMasterFTA->_playingExternalLoop) {
 			TilePoint baseCoords = centerActorCoords() >> kTileUVShift;
 			TilePoint       mtPos;
 			metaTileNoise   loopID = 0;
@@ -274,16 +221,11 @@ void setAreaSound(const TilePoint &) {
 				themePos.x = dist.u;
 				themePos.y = dist.v;
 				MetaTilePtr     mt = mIter.first(&mtPos);
-				for (i = 0; i < 16; i++) {
-					themeVectors[i].set(0, 0, 0);
-				}
 				while (mt) {
 					i++;
 					if (getSound(mt)) {
 						j++;
 						TilePoint thisDist = mtPos - baseCoords;
-						int theme = getSound(mt);
-						themeCount[theme]++;
 						if (thisDist.magnitude() < dist.magnitude()) {
 							dist = thisDist;
 							loopID = getSound(mt);
@@ -294,14 +236,14 @@ void setAreaSound(const TilePoint &) {
 					mt = mIter.next(&mtPos);
 				}
 				for (i = 0; i < AUXTHEMES; i++) {
-					if (aats[i].active) {
+					if (g_vm->_grandMasterFTA->_aats[i].active) {
 						Location loc = getCenterActor()->notGetWorldLocation();
-						if (aats[i].l.context == Nothing || loc.context == aats[i].l.context) {
-							TilePoint tp = (aats[i].l.tile >> kTileUVShift) - baseCoords;
+						if (g_vm->_grandMasterFTA->_aats[i].l.context == Nothing || loc.context == g_vm->_grandMasterFTA->_aats[i].l.context) {
+							TilePoint tp = (g_vm->_grandMasterFTA->_aats[i].l >> kTileUVShift) - baseCoords;
 							if (tp.magnitude() < dist.magnitude()) {
 								dist = tp;
 								loopID = USEAUXTHEME;
-								ss = aats[i].loopID;
+								ss = g_vm->_grandMasterFTA->_aats[i].loopID;
 								themePos.x = tp.u;
 								themePos.y = tp.v;
 							}
@@ -313,8 +255,8 @@ void setAreaSound(const TilePoint &) {
 				loopID = 0;
 			}
 			audioEnvironmentUseSet(loopID, ss, themePos << kPlatShift);
-		} else if (playingExternalLoop) {
-			audioEnvironmentUseSet(playingExternalLoop, 0, Point16(0, 0)); //themePos << kPlatShift);
+		} else if (g_vm->_grandMasterFTA->_playingExternalLoop) {
+			audioEnvironmentUseSet(g_vm->_grandMasterFTA->_playingExternalLoop, 0, Point16(0, 0)); //themePos << kPlatShift);
 		}
 	}
 }
@@ -330,24 +272,24 @@ void audioEnvironmentUseSet(int16 audioSet, int32 auxID, Point32 relPos) {
 		res = metaNoiseID(audioSet);
 	else
 		res = 0;
-	if (currentTheme != (uint16)audioSet || auxTheme != (uint32)auxID) {
-		currentTheme = audioSet;
-		auxTheme = auxID;
-		themeAt.x = relPos.x;
-		themeAt.y = relPos.y;
+	if (g_vm->_grandMasterFTA->_currentTheme != (uint16)audioSet || g_vm->_grandMasterFTA->_auxTheme != (uint32)auxID) {
+		g_vm->_grandMasterFTA->_currentTheme = audioSet;
+		g_vm->_grandMasterFTA->_auxTheme = auxID;
+		g_vm->_grandMasterFTA->_themeAt.x = relPos.x;
+		g_vm->_grandMasterFTA->_themeAt.y = relPos.y;
 		_playLoop(0);
-		if (currentTheme)
-			playLoopAt(res, themeAt);
+		if (g_vm->_grandMasterFTA->_currentTheme)
+			playLoopAt(res, g_vm->_grandMasterFTA->_themeAt);
 
-	} else if (currentTheme && themeAt != relPos) {
+	} else if (g_vm->_grandMasterFTA->_currentTheme && g_vm->_grandMasterFTA->_themeAt != relPos) {
 #if DEBUG
 		if (debugAudioThemes) {
-			WriteStatusF(9, "Thm: %2.2d (%d,%d) was (%d,%d)   ", audioSet, relPos.x, relPos.y, themeAt.x, themeAt.y);
+			WriteStatusF(9, "Thm: %2.2d (%d,%d) was (%d,%d)   ", audioSet, relPos.x, relPos.y, g_vm->_grandMasterFTA->_themeAt.x, g_vm->_grandMasterFTA->_themeAt.y);
 		}
 #endif
-		themeAt.x = relPos.x;
-		themeAt.y = relPos.y;
-		moveLoop(themeAt);
+		g_vm->_grandMasterFTA->_themeAt.x = relPos.x;
+		g_vm->_grandMasterFTA->_themeAt.y = relPos.y;
+		moveLoop(g_vm->_grandMasterFTA->_themeAt);
 	}
 }
 
@@ -356,14 +298,14 @@ void audioEnvironmentUseSet(int16 audioSet, int32 auxID, Point32 relPos) {
 
 void audioEnvironmentCheck(void) {
 
-	uint32 delta = gameTime - lastGameTime;
-	lastGameTime = gameTime;
-	if (currentTheme > 0 && currentTheme <= kAudioTerrainLIMIT) {
-		elapsedGameTime += delta;
-		if (elapsedGameTime > kCheckGameTime) {
+	uint32 delta = gameTime - g_vm->_grandMasterFTA->_lastGameTime;
+	g_vm->_grandMasterFTA->_lastGameTime = gameTime;
+	if (g_vm->_grandMasterFTA->_currentTheme > 0 && g_vm->_grandMasterFTA->_currentTheme <= kAudioTerrainLIMIT) {
+		g_vm->_grandMasterFTA->_elapsedGameTime += delta;
+		if (g_vm->_grandMasterFTA->_elapsedGameTime > kCheckGameTime) {
 			int i;
-			elapsedGameTime = 0;
-			const IntermittentAudioRecord &iar = intermittentAudioRecords[currentTheme];
+			g_vm->_grandMasterFTA->_elapsedGameTime = 0;
+			const IntermittentAudioRecord &iar = intermittentAudioRecords[g_vm->_grandMasterFTA->_currentTheme];
 			int16 totalProb = iar.noSoundOdds;
 			for (i = 0; i < 4; i++)
 				totalProb += iar.soundOdds[i];
@@ -376,17 +318,17 @@ void audioEnvironmentCheck(void) {
 			for (i = 0; i < 4; i++) {
 				if (pval < iar.soundOdds[i]) {
 					//GameObject *go=getViewCenterObject();
-					//Location cal=Location(TilePoint(themeAt.x,themeAt.y,0),go->IDParent());
-					//playSound(metaNoiseID((currentTheme*10)+i));
-					playSoundAt(metaNoiseID((currentTheme * 10) + i), themeAt);
+					//Location cal=Location(TilePoint(g_vm->_grandMasterFTA->_themeAt.x,g_vm->_grandMasterFTA->_themeAt.y,0),go->IDParent());
+					//playSound(metaNoiseID((g_vm->_grandMasterFTA->_currentTheme*10)+i));
+					playSoundAt(metaNoiseID((g_vm->_grandMasterFTA->_currentTheme * 10) + i), g_vm->_grandMasterFTA->_themeAt);
 					return;
 				} else
 					pval -= iar.soundOdds[i];
 			}
 
 		}
-	} else if (currentTheme)
-		warning("currentTheme out of range: %d", currentTheme);
+	} else if (g_vm->_grandMasterFTA->_currentTheme)
+		warning("currentTheme out of range: %d", g_vm->_grandMasterFTA->_currentTheme);
 
 }
 
@@ -440,20 +382,20 @@ void Deejay::select(void) {
 // Faction enumeration routines
 
 void clearActiveFactions(void) {
-	for (int i = 0; i < maxFactions; i++)
-		activeFactions[i] = 0;
+	for (int i = 0; i < kMaxFactions; i++)
+		g_vm->_grandMasterFTA->_activeFactions[i] = 0;
 }
 
 void incrementActiveFaction(Actor *a) {
-	activeFactions[a->_faction]++;
+	g_vm->_grandMasterFTA->_activeFactions[a->_faction]++;
 }
 
 void useActiveFactions(void) {
 	int highCount = 0;
 	int highFaction = 0;
-	for (int i = 0; i < maxFactions; i++) {
-		if (activeFactions[i] > highCount) {
-			highCount = activeFactions[i];
+	for (int i = 0; i < kMaxFactions; i++) {
+		if (g_vm->_grandMasterFTA->_activeFactions[i] > highCount) {
+			highCount = g_vm->_grandMasterFTA->_activeFactions[i];
 			highFaction = i;
 		}
 	}
diff --git a/engines/saga2/beegee.h b/engines/saga2/beegee.h
index 038c314d42..beab6fc619 100644
--- a/engines/saga2/beegee.h
+++ b/engines/saga2/beegee.h
@@ -27,10 +27,13 @@
 #ifndef SAGA2_BEEGEE_H
 #define SAGA2_BEEGEE_H
 
+#include "saga2/objproto.h"
+
 namespace Saga2 {
 
 enum {
 	kNoEnemy = -1,
+	kAuxThemes = 2,
 	kMaxThemes = 16
 };
 
@@ -41,6 +44,18 @@ enum {
 //-----------------------------------------------------------------------
 // Music selection brain
 
+struct AuxAudioTheme {
+	bool active;
+	Location l;
+	uint32 loopID;
+
+	AuxAudioTheme() {
+		 active = false;
+		 loopID = 0;
+		 l = Nowhere;
+	}
+};
+
 class Deejay {
 private:
 	int     _enemy;
@@ -51,8 +66,23 @@ private:
 
 	int _current;
 	int _currentID;
-
 public:
+
+	uint32 _currentTheme;
+	uint32 _auxTheme;
+	Point32 _themeAt;
+
+	int32 _lastGameTime;
+	int32 _elapsedGameTime;
+
+	int32 _pct;
+
+	bool _playingExternalLoop;
+
+	int _activeFactions[kMaxFactions];
+
+	AuxAudioTheme _aats[kAuxThemes];
+
 	Deejay() {
 		_enemy = -1;
 		_aggr = false;
@@ -61,6 +91,14 @@ public:
 		_ugd = false;
 		_current = 0;
 		_currentID = 0;
+
+		_currentTheme = 0;
+		_auxTheme = 0;
+		_lastGameTime = 0;
+		_elapsedGameTime = 0;
+		_pct = 0;
+		_playingExternalLoop = false;
+		memset(_activeFactions, 0, sizeof(_activeFactions));
 	}
 	~Deejay() {}
 
diff --git a/engines/saga2/idtypes.h b/engines/saga2/idtypes.h
index 08b6d1dd27..1991a12d58 100644
--- a/engines/saga2/idtypes.h
+++ b/engines/saga2/idtypes.h
@@ -468,6 +468,11 @@ enum {
 	kDefaultReach = 24
 };
 
+// Actor Constants
+enum {
+	kMaxFactions = 64
+};
+
 } // end of namespace Saga2
 
 #endif


Commit: e6db9ded56a4dc30b2a3c5392b63285c6e69bb2e
    https://github.com/scummvm/scummvm/commit/e6db9ded56a4dc30b2a3c5392b63285c6e69bb2e
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-26T04:43:14+09:00

Commit Message:
SAGA2: Move calender to Saga2Engine

Changed paths:
    engines/saga2/assign.cpp
    engines/saga2/calender.cpp
    engines/saga2/calender.h
    engines/saga2/saga2.cpp
    engines/saga2/saga2.h
    engines/saga2/sagafunc.cpp
    engines/saga2/tilemode.cpp
    engines/saga2/tilemode.h
    engines/saga2/transit.cpp


diff --git a/engines/saga2/assign.cpp b/engines/saga2/assign.cpp
index e6d2040a7b..f824cc1216 100644
--- a/engines/saga2/assign.cpp
+++ b/engines/saga2/assign.cpp
@@ -41,7 +41,7 @@ const uint16 kIndefiniteTime = CalenderTime::kFramesPerDay;
 
 //  Constructor
 ActorAssignment::ActorAssignment(Actor *a, uint16 until) :
-	_startFrame(calender.frameInDay()),
+	_startFrame(g_vm->_calender->frameInDay()),
 	_endFrame(until) {
 	_actor = a;
 	debugC(2, kDebugActors, "New assignment for %p (%s) from %d until %d: %p",
@@ -96,7 +96,7 @@ void ActorAssignment::write(Common::MemoryWriteStreamDynamic *out) const {
 //	Determine if the time limit for this assignment has been exceeded
 
 bool ActorAssignment::isValid(void) {
-	uint16  frame = calender.frameInDay();
+	uint16  frame = g_vm->_calender->frameInDay();
 
 	return      frame < _endFrame
 	            || (_startFrame >= _endFrame && frame >= _startFrame);
diff --git a/engines/saga2/calender.cpp b/engines/saga2/calender.cpp
index abf2f805ef..e22d97889f 100644
--- a/engines/saga2/calender.cpp
+++ b/engines/saga2/calender.cpp
@@ -33,18 +33,6 @@
 
 namespace Saga2 {
 
-/* ===================================================================== *
-   Globals
- * ===================================================================== */
-
-static bool calenderPaused;
-
-/* ===================================================================== *
-   Constants
- * ===================================================================== */
-
-const uint16 GAME_START_HOUR = 5;
-
 /* ===================================================================== *
    FrameAlarm member functions
  * ===================================================================== */
@@ -181,12 +169,12 @@ void FrameAlarm::read(Common::InSaveFile *in) {
 }
 
 void FrameAlarm::set(uint16 dur) {
-	_baseFrame = calender.frameInDay();
+	_baseFrame = g_vm->_calender->frameInDay();
 	_duration = dur;
 }
 
 bool FrameAlarm::check(void) {
-	uint16      frameInDay = calender.frameInDay();
+	uint16      frameInDay = g_vm->_calender->frameInDay();
 
 	return  _baseFrame + _duration < CalenderTime::kFramesPerDay
 	        ?   frameInDay >= _baseFrame + _duration
@@ -199,7 +187,7 @@ bool FrameAlarm::check(void) {
 // time elapsed since alarm set
 
 uint16 FrameAlarm::elapsed(void) {
-	uint16      frameInDay = calender.frameInDay();
+	uint16      frameInDay = g_vm->_calender->frameInDay();
 
 	return  _baseFrame + _duration < CalenderTime::kFramesPerDay
 	        ?   frameInDay - _baseFrame
@@ -216,21 +204,21 @@ uint16 FrameAlarm::elapsed(void) {
 //	Pause the global calender
 
 void pauseCalender(void) {
-	calenderPaused = true;
+	g_vm->_calender->_calenderPaused = true;
 }
 
 //-----------------------------------------------------------------------
 //	Restart the paused global calender
 
 void resumeCalender(void) {
-	calenderPaused = false;
+	g_vm->_calender->_calenderPaused = false;
 }
 
 //-----------------------------------------------------------------------
 //	Update the global calender
 
 void updateCalender(void) {
-	if (!calenderPaused) calender.update();
+	if (!g_vm->_calender->_calenderPaused) g_vm->_calender->update();
 }
 
 //-----------------------------------------------------------------------
@@ -254,14 +242,14 @@ uint32 operator - (const CalenderTime &time1, const CalenderTime &time2) {
 //	Initialize the game calender
 
 void initCalender(void) {
-	calenderPaused          = false;
-	calender._years          = 0;
-	calender._weeks          = 0;
-	calender._days           = 0;
-	calender._dayInYear      = 0;
-	calender._dayInWeek      = 0;
-	calender._hour           = GAME_START_HOUR;
-	calender._frameInHour    = 0;
+	g_vm->_calender->_calenderPaused          = false;
+	g_vm->_calender->_years          = 0;
+	g_vm->_calender->_weeks          = 0;
+	g_vm->_calender->_days           = 0;
+	g_vm->_calender->_dayInYear      = 0;
+	g_vm->_calender->_dayInWeek      = 0;
+	g_vm->_calender->_hour           = CalenderTime::kGameStartHour;
+	g_vm->_calender->_frameInHour    = 0;
 }
 
 void saveCalender(Common::OutSaveFile *outS) {
@@ -269,26 +257,24 @@ void saveCalender(Common::OutSaveFile *outS) {
 
 	outS->write("CALE", 4);
 	CHUNK_BEGIN;
-	out->writeUint16LE(calenderPaused);
-	debugC(3, kDebugSaveload, "... calenderPaused = %d", calenderPaused);
-	calender.write(out);
+	out->writeUint16LE(g_vm->_calender->_calenderPaused);
+	debugC(3, kDebugSaveload, "... _calenderPaused = %d", g_vm->_calender->_calenderPaused);
+	g_vm->_calender->write(out);
 	CHUNK_END;
 }
 
 void loadCalender(Common::InSaveFile *in) {
 	debugC(2, kDebugSaveload, "Loading calender");
 
-	calenderPaused = in->readUint16LE();
+	g_vm->_calender->_calenderPaused = in->readUint16LE();
 
-	debugC(3, kDebugSaveload, "... calenderPaused = %d", calenderPaused);
+	debugC(3, kDebugSaveload, "... _calenderPaused = %d", g_vm->_calender->_calenderPaused);
 
-	calender.read(in);
+	g_vm->_calender->read(in);
 }
 
-CalenderTime    calender;
-
 bool isDayTime(void) {
-	return calender.lightLevel(MAX_LIGHT) >= (MAX_LIGHT / 2);
+	return g_vm->_calender->lightLevel(MAX_LIGHT) >= (MAX_LIGHT / 2);
 }
 
 }
diff --git a/engines/saga2/calender.h b/engines/saga2/calender.h
index 52128c4bc1..7a7a7e167e 100644
--- a/engines/saga2/calender.h
+++ b/engines/saga2/calender.h
@@ -49,7 +49,9 @@ public:
 		kFramesPerHour   = (kFramesPerDay / kHoursPerDay),
 		kFramesAtNoon    = (kFramesPerDay / 2),
 
-		kDayBias = kFramesAtNoon / 6
+		kDayBias = kFramesAtNoon / 6,
+
+		kGameStartHour = 5
 	};
 
 	uint16      _years,
@@ -60,6 +62,13 @@ public:
 	            _hour,
 	            _frameInHour;
 
+	bool _calenderPaused;
+
+	CalenderTime() {
+		_years = _weeks = _days = _dayInYear = _dayInWeek = _hour = _frameInHour = 0;
+		_calenderPaused = false;
+	}
+
 	void read(Common::InSaveFile *in);
 	void write(Common::MemoryWriteStreamDynamic *out);
 
@@ -104,12 +113,6 @@ void loadCalender(Common::InSaveFile *in);
 
 bool isDayTime(void);
 
-/* ===================================================================== *
-   Global calender
- * ===================================================================== */
-
-extern CalenderTime calender;
-
 const int MAX_LIGHT = 12;       // maximum light level
 
 }
diff --git a/engines/saga2/saga2.cpp b/engines/saga2/saga2.cpp
index 6150c5fa1f..0c9243a204 100644
--- a/engines/saga2/saga2.cpp
+++ b/engines/saga2/saga2.cpp
@@ -39,6 +39,7 @@
 #include "saga2/audio.h"
 #include "saga2/band.h"
 #include "saga2/beegee.h"
+#include "saga2/calender.h"
 #include "saga2/contain.h"
 #include "saga2/dispnode.h"
 #include "saga2/gdraw.h"
@@ -48,6 +49,7 @@
 #include "saga2/music.h"
 #include "saga2/panel.h"
 #include "saga2/spelshow.h"
+#include "saga2/tilemode.h"
 #include "saga2/vpal.h"
 
 namespace Saga2 {
@@ -70,6 +72,8 @@ Saga2Engine::Saga2Engine(OSystem *syst)
 	_audio = nullptr;
 	_pal = nullptr;
 	_act = nullptr;
+	_calender = nullptr;
+	_tmm = nullptr;
 
 	_bandList = nullptr;
 	_mouseInfo = nullptr;
@@ -132,6 +136,8 @@ Saga2Engine::~Saga2Engine() {
 	delete _renderer;
 	delete _pal;
 	delete _act;
+	delete _calender;
+	delete _tmm;
 
 	delete _imageCache;
 	delete _mTaskList;
@@ -160,6 +166,8 @@ Common::Error Saga2Engine::run() {
 
 	_pal = new PaletteManager;
 	_act = new ActorManager;
+	_calender = new CalenderTime;
+	_tmm = new TileModeManager;
 
 	readConfig();
 
diff --git a/engines/saga2/saga2.h b/engines/saga2/saga2.h
index 16c6d87b52..16662adec5 100644
--- a/engines/saga2/saga2.h
+++ b/engines/saga2/saga2.h
@@ -81,6 +81,8 @@ class CMapFeature;
 class AudioInterface;
 class PaletteManager;
 class ActorManager;
+class CalenderTime;
+class TileModeManager;
 
 enum {
 	kDebugResources = 1 << 0,
@@ -140,6 +142,8 @@ public:
 	AudioInterface *_audio;
 	PaletteManager *_pal;
 	ActorManager *_act;
+	CalenderTime *_calender;
+	TileModeManager *_tmm;
 
 	WeaponStuff _weaponRack[kMaxWeapons];
 	weaponID _loadedWeapons;
diff --git a/engines/saga2/sagafunc.cpp b/engines/saga2/sagafunc.cpp
index 970d671a80..0a7f196648 100644
--- a/engines/saga2/sagafunc.cpp
+++ b/engines/saga2/sagafunc.cpp
@@ -1874,7 +1874,7 @@ int16 scriptActorAssignAttend(int16 *args) {
 		if (a->getAssignment() != NULL) delete a->getAssignment();
 
 		if (new AttendAssignment(a,
-		            (calender.frameInDay()
+		            (g_vm->_calender->frameInDay()
 		             + (uint16)args[0])
 		            %   CalenderTime::kFramesPerDay,
 		            GameObject::objectAddress(args[1]))
@@ -3130,7 +3130,7 @@ int16 scriptPlayVoice(int16 *args) {
 
 int16 scriptGetHour(int16 *) {
 	MONOLOG(GetHour);
-	return calender._hour;
+	return g_vm->_calender->_hour;
 }
 
 //-----------------------------------------------------------------------
@@ -3138,7 +3138,7 @@ int16 scriptGetHour(int16 *) {
 
 int16 scriptGetFrameInHour(int16 *) {
 	MONOLOG(GetFrameInHour);
-	return calender._frameInHour;
+	return g_vm->_calender->_frameInHour;
 }
 
 //-----------------------------------------------------------------------
diff --git a/engines/saga2/tilemode.cpp b/engines/saga2/tilemode.cpp
index dc8a4c7e1f..ca7c13862d 100644
--- a/engines/saga2/tilemode.cpp
+++ b/engines/saga2/tilemode.cpp
@@ -208,11 +208,6 @@ extern hResContext          *imageRes;              // image resource handle
 
 //  Combat related data
 static bool         aggressiveActFlag = false;  //  Indicates wether or not
-//  there has been an
-//  aggressive act
-static CalenderTime timeOfLastAggressiveAct;    //  Used to determine the
-//  mode state
-
 static bool         inCombat,
        combatPaused;
 
@@ -343,7 +338,7 @@ void logAggressiveAct(ObjectID attackerID, ObjectID attackeeID) {
 			handlePlayerActorAttacked(playerID);
 
 		aggressiveActFlag = true;
-		timeOfLastAggressiveAct = calender;
+		*g_vm->_tmm->_timeOfLastAggressiveAct = *g_vm->_calender;
 	}
 }
 
@@ -352,7 +347,7 @@ void logAggressiveAct(ObjectID attackerID, ObjectID attackeeID) {
 //	involving a player actor
 
 uint16 timeSinceLastAggressiveAct(void) {
-	return aggressiveActFlag ? calender - timeOfLastAggressiveAct : maxuint16;
+	return aggressiveActFlag ? *g_vm->_calender - *g_vm->_tmm->_timeOfLastAggressiveAct : maxuint16;
 }
 
 //-----------------------------------------------------------------------
@@ -623,7 +618,7 @@ void saveTileModeState(Common::OutSaveFile *outS) {
 	debugC(3, kDebugSaveload, "... combatPaused = %d", combatPaused);
 
 	if (aggressiveActFlag)
-		timeOfLastAggressiveAct.write(out);
+		g_vm->_tmm->_timeOfLastAggressiveAct->write(out);
 	CHUNK_END;
 }
 
@@ -640,7 +635,7 @@ void loadTileModeState(Common::InSaveFile *in) {
 	debugC(3, kDebugSaveload, "... combatPaused = %d", combatPaused);
 
 	if (aggressiveActFlag)
-		timeOfLastAggressiveAct.read(in);
+		g_vm->_tmm->_timeOfLastAggressiveAct->read(in);
 
 	tileLockFlag = false;
 }
@@ -1474,4 +1469,12 @@ void noStickyMap(void) {
 	mousePressed = false;
 }
 
+TileModeManager::TileModeManager() {
+	_timeOfLastAggressiveAct = new CalenderTime;
+}
+
+TileModeManager::~TileModeManager() {
+	delete _timeOfLastAggressiveAct;
+}
+
 } // end of namespace Saga2
diff --git a/engines/saga2/tilemode.h b/engines/saga2/tilemode.h
index 2e0c379102..9fbbc353cd 100644
--- a/engines/saga2/tilemode.h
+++ b/engines/saga2/tilemode.h
@@ -56,6 +56,14 @@ void TileModeCleanup(void);                      // free tile resources
 
 void noStickyMap(void);
 
+class TileModeManager {
+public:
+	CalenderTime *_timeOfLastAggressiveAct;    //  Used to determine the
+
+	TileModeManager();
+	~TileModeManager();
+};
+
 } // end of namespace Saga2
 
 #endif
diff --git a/engines/saga2/transit.cpp b/engines/saga2/transit.cpp
index 24439f67b1..14867a676b 100644
--- a/engines/saga2/transit.cpp
+++ b/engines/saga2/transit.cpp
@@ -63,7 +63,7 @@ void dayNightUpdate(void) {
 
 	audioEnvironmentSetDaytime(isDayTime());
 
-	uint32 lightLevel = calender.lightLevel(MAX_LIGHT);
+	uint32 lightLevel = g_vm->_calender->lightLevel(MAX_LIGHT);
 
 	//  Code to avoid unneccessary fades.
 	if (lightLevel != g_vm->_pal->_prevLightLevel) {




More information about the Scummvm-git-logs mailing list