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

a-yyg 76591232+a-yyg at users.noreply.github.com
Sun Jul 4 06:45:11 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:
c6c0475e41 SAGA2: Clean some global constructor warnings
f7556980d0 SAGA2: Clean more global constructors in tile.cpp


Commit: c6c0475e41363f0c15988e0accf5537ab40c5dd8
    https://github.com/scummvm/scummvm/commit/c6c0475e41363f0c15988e0accf5537ab40c5dd8
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-04T15:44:10+09:00

Commit Message:
SAGA2: Clean some global constructor warnings

Changed paths:
    engines/saga2/idtypes.h
    engines/saga2/tile.cpp
    engines/saga2/tile.h


diff --git a/engines/saga2/idtypes.h b/engines/saga2/idtypes.h
index cf465eb968..b3a2f893b6 100644
--- a/engines/saga2/idtypes.h
+++ b/engines/saga2/idtypes.h
@@ -67,6 +67,10 @@ typedef int16   PlayerActorID;
    MetaTileID struct
  * ===================================================================== */
 
+struct StaticMetaTileID {
+	int16 map, index;
+};
+
 struct MetaTileID {
 	int16           map;            //  map number
 	int16           index;          //  index into metatile array
@@ -80,6 +84,11 @@ struct MetaTileID {
 	//  Constructor
 	MetaTileID(int16 m, int16 i) : map(m), index(i) {}
 
+	MetaTileID(StaticMetaTileID mt) {
+		map = mt.map;
+		index = mt.index;
+	}
+
 	MetaTileID operator = (const MetaTileID &id) {
 		map = id.map;
 		index = id.index;
@@ -96,7 +105,7 @@ struct MetaTileID {
 };
 
 //  ID of NULL meta tile
-extern const MetaTileID     NoMetaTile;
+extern const StaticMetaTileID NoMetaTile;
 
 /* ===================================================================== *
    ActiveItemID struct
@@ -108,6 +117,10 @@ const int   activeItemMapShift = 13;
 
 const int16 activeItemIndexNullID = 0x1FFF;
 
+struct StaticActiveItemID {
+	int16 val;
+};
+
 #include "common/pack-start.h"
 struct ActiveItemID {
 	int16           val;            //  ID value --
@@ -125,13 +138,13 @@ struct ActiveItemID {
 	ActiveItemID(int16 idVal) : val(idVal) {}
 
 	//  Constructor
-#if DEBUG
-	ActiveItemID(int16 m, int16 i);
-#else
 	ActiveItemID(int16 m, int16 i) :
 		val((m << activeItemMapShift) | (i & activeItemIndexMask)) {
 	}
-#endif
+
+	ActiveItemID(StaticActiveItemID a) {
+		val = a.val;
+	}
 
 	ActiveItemID operator = (const ActiveItemID &id) {
 		val = id.val;
@@ -143,6 +156,10 @@ struct ActiveItemID {
 		return *this;
 	}
 
+	static int16 getVal(int16 m, int16 i) {
+		return (m << activeItemMapShift) | (i & activeItemIndexMask);
+	}
+
 	bool operator == (const ActiveItemID &id) const {
 		return val == id.val;
 	}
@@ -155,27 +172,19 @@ struct ActiveItemID {
 		return val;
 	}
 
-#if DEBUG
-	void setMapNum(int16 m);
-#else
 	void setMapNum(int16 m) {
 		val &= ~activeItemMapMask;
 		val |= (m << activeItemMapShift);
 	}
-#endif
 
 	int16 getMapNum(void) {
 		return (uint16)val >> activeItemMapShift;
 	}
 
-#if DEBUG
-	void setIndexNum(int16 i);
-#else
 	void setIndexNum(int16 i) {
 		val &= ~activeItemIndexMask;
 		val |= i & activeItemIndexMask;
 	}
-#endif
 
 	int16 getIndexNum(void) {
 		return val & activeItemIndexMask;
@@ -184,7 +193,7 @@ struct ActiveItemID {
 #include "common/pack-end.h"
 
 //  ID of NULL active item
-extern const ActiveItemID   NoActiveItem;
+extern const StaticActiveItemID NoActiveItem;
 
 /* ===================================================================== *
    Task's and TaskStacks
diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp
index 4833a64ee6..8f0344fc15 100644
--- a/engines/saga2/tile.cpp
+++ b/engines/saga2/tile.cpp
@@ -81,8 +81,8 @@ const int           slowScrollSpeed = 6,
 
 const StaticTilePoint Nowhere = {(int16)minint16, (int16)minint16, (int16)minint16};
 
-const MetaTileID    NoMetaTile(nullID, nullID);
-const ActiveItemID  NoActiveItem(0, activeItemIndexNullID);
+const StaticMetaTileID NoMetaTile = {nullID, nullID};
+const StaticActiveItemID  NoActiveItem = {ActiveItemID::getVal(0, activeItemIndexNullID)};
 
 enum SurfaceType {
 	surfaceHoriz,               //  Level surface
@@ -184,7 +184,7 @@ uint16                  rippedRoofID;
 
 static StaticTilePoint  ripTableCoords = Nowhere;
 
-static RipTable         ripTableList[25];
+static RipTable         *ripTableList;
 
 WorldMapData            *mapList;           //  master map data array
 
@@ -235,30 +235,6 @@ BankBits LoadedBanks;                // what banks are loaded?
    ActiveItemID member functions
  * ===================================================================== */
 
-#if DEBUG
-ActiveItemID::ActiveItemID(int16 m, int16 i) :
-	val((m << activeItemMapShift) | (i & activeItemIndexMask)) {
-	assert(m < 0x8);
-	assert((uint16)i <= activeItemIndexNullID);
-}
-
-void ActiveItemID::setMapNum(int16 m) {
-	assert(m < 0x8);
-	val &= ~activeItemMapMask;
-	val |= (m << activeItemMapShift);
-}
-
-void ActiveItemID::setIndexNum(int16 i) {
-	assert((uint16)i <= activeItemIndexNullID);
-	val &= ~activeItemIndexMask;
-	val |= i & activeItemIndexMask;
-}
-#endif
-
-/* ===================================================================== *
-   Finds the address of a tile associated with a TileID
- * ===================================================================== */
-
 //-----------------------------------------------------------------------
 //	Return the address of a tile's TileInfo structure given that tile's ID
 
@@ -1591,6 +1567,13 @@ void initMaps(void) {
 		mapData->buildInstanceHash();
 	}
 
+	ripTableList = new RipTable[RipTable::kRipTableSize];
+	for (int k = 0; k < RipTable::kRipTableSize; ++k) {
+		ripTableList[k].metaID = NoMetaTile;
+		ripTableList[k].ripID = 0;
+		memset(ripTableList[k].zTable, 0, sizeof(ripTableList[k].zTable));
+	}
+
 	initPlatformCache();
 	initMapFeatures();
 }
@@ -1602,6 +1585,9 @@ void cleanupMaps(void) {
 	int16       i;
 
 	termMapFeatures();
+
+	delete[] ripTableList;
+
 	//  Iterate through each map, dumping the data
 	for (i = 0; i < worldCount; i++) {
 		WorldMapData    *mapData = &mapList[i];
@@ -2818,7 +2804,7 @@ void buildRipTables(void) {
 	int16       tableIndex;
 
 	//  bit array of available rip tables
-	uint8       tableAvail[(ARRAYSIZE(ripTableList) + 7) >> 3];
+	uint8       tableAvail[(RipTable::kRipTableSize + 7) >> 3];
 
 	memset(tableAvail, 0xFF, sizeof(tableAvail));
 
@@ -2852,7 +2838,7 @@ void buildRipTables(void) {
 
 		uint j;
 		//  Find available table
-		for (j = 0; j < ARRAYSIZE(ripTableList); j++) {
+		for (j = 0; j < RipTable::kRipTableSize; j++) {
 			if (tableAvail[j >> 3] & (1 << (j & 0x7)))
 				break;
 		}
diff --git a/engines/saga2/tile.h b/engines/saga2/tile.h
index d17b3d46a1..3c524bb54e 100644
--- a/engines/saga2/tile.h
+++ b/engines/saga2/tile.h
@@ -766,6 +766,10 @@ struct RipTable {
 	uint16      ripID;
 	int16       zTable[kPlatformWidth][kPlatformWidth];
 
+	enum {
+		kRipTableSize = 25
+	};
+
 	//  Constructor
 	RipTable(void) : metaID(NoMetaTile) {}
 


Commit: f7556980d0d07bc613ba7d229a16d5f6aaa6d8d2
    https://github.com/scummvm/scummvm/commit/f7556980d0d07bc613ba7d229a16d5f6aaa6d8d2
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-04T15:44:10+09:00

Commit Message:
SAGA2: Clean more global constructors in tile.cpp

Changed paths:
    engines/saga2/dispnode.cpp
    engines/saga2/floating.cpp
    engines/saga2/modal.cpp
    engines/saga2/objects.cpp
    engines/saga2/rect.h
    engines/saga2/speech.cpp
    engines/saga2/sprite.cpp
    engines/saga2/tile.cpp
    engines/saga2/tile.h


diff --git a/engines/saga2/dispnode.cpp b/engines/saga2/dispnode.cpp
index 64140383a6..dd0b7f4e37 100644
--- a/engines/saga2/dispnode.cpp
+++ b/engines/saga2/dispnode.cpp
@@ -55,7 +55,7 @@ bool                            centerActorIndicatorEnabled;
 extern int16        currentMapNum;
 extern WorldMapData *mapList;
 
-extern Point16      fineScroll;
+extern StaticPoint16 fineScroll;
 extern gPort        backPort;
 
 extern SpriteSet    *objectSprites,        // object sprites
diff --git a/engines/saga2/floating.cpp b/engines/saga2/floating.cpp
index 70a31861ae..01230550ed 100644
--- a/engines/saga2/floating.cpp
+++ b/engines/saga2/floating.cpp
@@ -58,7 +58,7 @@ extern gToolBase    G_BASE;
 //  need to know about the scrolling tile area.
 
 extern gPixelMap    tileDrawMap;
-extern Point16      fineScroll;
+extern StaticPoint16 fineScroll;
 extern gFont        *mainFont;
 extern bool         allPlayerActorsDead;
 
diff --git a/engines/saga2/modal.cpp b/engines/saga2/modal.cpp
index 3a41cb8fd2..b23153b3ba 100644
--- a/engines/saga2/modal.cpp
+++ b/engines/saga2/modal.cpp
@@ -34,7 +34,6 @@ namespace Saga2 {
 ModalWindow *mWinPtr;
 
 extern gPixelMap    tileDrawMap;
-extern Point16      fineScroll;
 extern gToolBase    G_BASE;
 
 APPFUNC(cmdModalWindow);
diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index 0e55d3c827..68d7b15ebb 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -136,7 +136,7 @@ bool                massAndBulkCount;
  * ===================================================================== */
 
 extern BackWindow   *mainWindow;
-extern Point16      fineScroll;             // current scroll pos
+extern StaticPoint16 fineScroll;             // current scroll pos
 extern hResContext  *imageRes;              // image resource handle
 extern PlayerActor  playerList[];   //  Master list of all PlayerActors
 extern SpellStuff   spellBook[];
diff --git a/engines/saga2/rect.h b/engines/saga2/rect.h
index 694018d913..4d1191d22e 100644
--- a/engines/saga2/rect.h
+++ b/engines/saga2/rect.h
@@ -137,6 +137,41 @@ typedef Point16         Extent16;               // contains width and height
 
 struct StaticPoint32 {
 	int32 x, y;
+
+	friend StaticPoint32 operator+ (StaticPoint32 a, StaticPoint32 b) {
+		StaticPoint32 p;
+		p.x = a.x + b.x;
+		p.y = a.y + b.y;
+		return p;
+	}
+
+	friend StaticPoint32 operator- (StaticPoint32 a, StaticPoint32 b) {
+		StaticPoint32 p;
+		p.x = a.x - b.x;
+		p.y = a.y - b.y;
+		return p;
+	}
+
+	friend StaticPoint32 operator*(StaticPoint32 a, int b) {
+		StaticPoint32 p;
+		p.x = a.x * b;
+		p.y = a.y * b;
+
+		return p;
+	}
+
+	friend StaticPoint32 operator/(StaticPoint32 a, int b) {
+		StaticPoint32 p;
+		p.x = a.x / b;
+		p.y = a.y / b;
+
+		return p;
+	}
+
+	void operator+= (StaticPoint32 a) {
+		x += a.x;
+		y += a.y;
+	}
 };
 
 class Point32 {
diff --git a/engines/saga2/speech.cpp b/engines/saga2/speech.cpp
index 98738238b8..92e23323c4 100644
--- a/engines/saga2/speech.cpp
+++ b/engines/saga2/speech.cpp
@@ -50,9 +50,9 @@ struct TextSpan {
 //-----------------------------------------------------------------------
 //	externs
 
-extern  Point16     fineScroll;
+extern  StaticPoint16 fineScroll;
 int                 kludgeHeight = 15;
-extern  TilePoint   viewCenter;             // coordinates of view on map
+extern  StaticTilePoint viewCenter;         // coordinates of view on map
 
 //-----------------------------------------------------------------------
 //	constants
diff --git a/engines/saga2/sprite.cpp b/engines/saga2/sprite.cpp
index aa5daf529a..b04662b726 100644
--- a/engines/saga2/sprite.cpp
+++ b/engines/saga2/sprite.cpp
@@ -56,7 +56,6 @@ extern void drawTileMask(
  * ===================================================================== */
 
 extern gPixelMap    tileDrawMap;
-extern Point16      fineScroll;             // current scroll pos
 
 //  Color map ranges
 extern uint8        *ColorMapRanges;
diff --git a/engines/saga2/tile.cpp b/engines/saga2/tile.cpp
index 8f0344fc15..e13becc3ae 100644
--- a/engines/saga2/tile.cpp
+++ b/engines/saga2/tile.cpp
@@ -194,9 +194,7 @@ byte                   **stateArray;        //  Array of active item instance
 CyclePtr                cycleList;          // list of tile cycling info
 
 //  Platform caching management
-const int           platformCacheSize = 256;
-
-PlatformCacheEntry  platformCache[platformCacheSize];
+PlatformCacheEntry  *platformCache;
 
 /* ===================================================================== *
    View state
@@ -204,12 +202,11 @@ PlatformCacheEntry  platformCache[platformCacheSize];
 
 int16               defaultScrollSpeed = slowScrollSpeed;
 
-Point32             tileScroll,             // current tile scroll pos
-//					backScroll,              // quantized scroll pos
-                    targetScroll;           // where scroll going to
-Point16             fineScroll;
+static StaticPoint32 tileScroll = {0, 0},             // current tile scroll pos
+                     targetScroll = {0, 0};           // where scroll going to
+StaticPoint16 fineScroll = {0, 0};
 
-TilePoint           viewCenter;             // coordinates of view on map
+StaticTilePoint viewCenter = {0, 0, 0};             // coordinates of view on map
 
 //  These two variables define which sectors overlap the view rect.
 
@@ -1588,6 +1585,8 @@ void cleanupMaps(void) {
 
 	delete[] ripTableList;
 
+	delete[] platformCache;
+
 	//  Iterate through each map, dumping the data
 	for (i = 0; i < worldCount; i++) {
 		WorldMapData    *mapData = &mapList[i];
@@ -1789,7 +1788,9 @@ void loadAutoMap(SaveFileReader &saveGame) {
 //	Initialize the platform cache
 
 void initPlatformCache(void) {
-	for (int i = 0; i < platformCacheSize; i++) {
+	platformCache = new PlatformCacheEntry[PlatformCacheEntry::kPlatformCacheSize];
+
+	for (int i = 0; i < PlatformCacheEntry::kPlatformCacheSize; i++) {
 		PlatformCacheEntry  *pce = &platformCache[i];
 
 		//  Fill up the LRU with empty platforms
@@ -2254,7 +2255,7 @@ Platform *MetaTile::fetchPlatform(int16 mapNum, int16 layer) {
 	} else if (plIndex & cacheFlag) {
 		plIndex &= ~cacheFlag;
 
-		assert(plIndex < platformCacheSize);
+		assert(plIndex < PlatformCacheEntry::kPlatformCacheSize);
 
 			//	Get the address of the pce from the cache
 		pce = &platformCache[plIndex];
@@ -2282,7 +2283,7 @@ Platform *MetaTile::fetchPlatform(int16 mapNum, int16 layer) {
 		pce = &platformCache[cacheIndex];
 
 		//  Compute the layer of this entry in the cache
-		assert(cacheIndex < platformCacheSize);
+		assert(cacheIndex < PlatformCacheEntry::kPlatformCacheSize);
 		assert(cacheIndex >= 0);
 
 		if (pce->metaID != NoMetaTile) {
@@ -4504,7 +4505,7 @@ void updateMainDisplay(void) {
 
 	WorldMapData    *curMap = &mapList[currentMapNum];
 
-	Point32         scrollCenter,
+	StaticPoint32   scrollCenter,
 	                scrollDelta;
 	int32           scrollSpeed = defaultScrollSpeed,
 	                scrollDistance;
@@ -4567,7 +4568,9 @@ void updateMainDisplay(void) {
 	//  Compute the center of the screen in (u,v) coords.
 	scrollCenter.x = tileScroll.x + kTileRectWidth  / 2;
 	scrollCenter.y = tileScroll.y + kTileRectHeight / 2;
-	viewCenter = XYToUV(scrollCenter);
+	viewCenter.set(XYToUV(scrollCenter).u,
+	               XYToUV(scrollCenter).v,
+	               0);
 
 	//  Compute the largest U/V rectangle which completely
 	//  encloses the view area, and convert to sector coords.
diff --git a/engines/saga2/tile.h b/engines/saga2/tile.h
index 3c524bb54e..090b42f020 100644
--- a/engines/saga2/tile.h
+++ b/engines/saga2/tile.h
@@ -751,6 +751,10 @@ struct PlatformCacheEntry {
 	                layerNum;               // index of this plat in mt.
 	MetaTileID      metaID;                 // pointer to parent metatile
 	Platform        pl;                     // actual platform data
+
+	enum {
+		kPlatformCacheSize = 256
+	};
 };
 
 /* ======================================================================= *
@@ -962,7 +966,7 @@ public:
    Exports
  * ===================================================================== */
 
-extern TilePoint    viewCenter;             // coordinates of view on map
+extern StaticTilePoint viewCenter;             // coordinates of view on map
 
 //  These two variables define which sectors overlap the view rect.
 




More information about the Scummvm-git-logs mailing list