[Scummvm-git-logs] scummvm master -> 357936b4142aae5b7a43b655142b436dd15d3b24

sev- sev at scummvm.org
Sat Aug 1 19:27:21 UTC 2020


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

Summary:
357936b414 FULLPIPE: Turned Palette into struct for more robust memory management


Commit: 357936b4142aae5b7a43b655142b436dd15d3b24
    https://github.com/scummvm/scummvm/commit/357936b4142aae5b7a43b655142b436dd15d3b24
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-08-01T21:26:58+02:00

Commit Message:
FULLPIPE: Turned Palette into struct for more robust memory management

Changed paths:
    engines/fullpipe/fullpipe.h
    engines/fullpipe/gfx.cpp
    engines/fullpipe/gfx.h
    engines/fullpipe/scene.cpp
    engines/fullpipe/statics.cpp


diff --git a/engines/fullpipe/fullpipe.h b/engines/fullpipe/fullpipe.h
index 5f5fda4648..4d1114e659 100644
--- a/engines/fullpipe/fullpipe.h
+++ b/engines/fullpipe/fullpipe.h
@@ -87,9 +87,23 @@ class SoundList;
 class StaticANIObject;
 class Vars;
 typedef Common::Array<int16> MovTable;
-typedef Common::Array<int32> Palette;
 typedef Common::Array<Common::Point> PointList;
 
+struct Palette {
+	uint32 pal[256];
+	uint size;
+
+	Palette() {
+		size = 0;
+		memset(pal, 0, 256 * 4);
+	}
+
+	void copy(const Palette &src) {
+		size = src.size;
+		memcpy(pal, src.pal, 256 * 4);
+	}
+};
+
 typedef Common::HashMap<uint16, Common::String> GameObjHMap;
 
 int global_messageHandler1(ExCommand *cmd);
diff --git a/engines/fullpipe/gfx.cpp b/engines/fullpipe/gfx.cpp
index 6da876400b..93524b3a5c 100644
--- a/engines/fullpipe/gfx.cpp
+++ b/engines/fullpipe/gfx.cpp
@@ -462,10 +462,10 @@ bool Picture::load(MfcArchive &file) {
 	int havePal = file.readUint32LE();
 
 	if (havePal > 0) {
-		_paletteData.reserve(256);
 		for (int i = 0; i < 256; ++i) {
-			_paletteData.push_back(file.readUint32LE());
+			_paletteData.pal[i] = file.readUint32LE();
 		}
+		_paletteData.size = 256;
 	}
 
 	getData();
@@ -529,7 +529,7 @@ void Picture::getDibInfo() {
 	_bitmap->load(s);
 	delete s;
 
-	_bitmap->decode(_data, _paletteData.size() ? _paletteData : *g_fp->_globalPalette);
+	_bitmap->decode(_data, _paletteData.size ? _paletteData : *g_fp->_globalPalette);
 }
 
 const Bitmap *Picture::getPixelData() {
@@ -562,7 +562,7 @@ void Picture::draw(int x, int y, int style, int angle) {
 	}
 
 	const Palette *pal;
-	if (_paletteData.size()) {
+	if (_paletteData.size) {
 		pal = &_paletteData;
 	} else {
 		//warning("Picture:draw: using global palette");
@@ -628,10 +628,10 @@ void Picture::displayPicture() {
 }
 
 void Picture::setPaletteData(const Palette &pal) {
-	if (pal.size()) {
-		_paletteData = pal;
+	if (pal.size) {
+		_paletteData.copy(pal);
 	} else {
-		_paletteData.clear();
+		_paletteData.size = 0;
 	}
 }
 
@@ -793,7 +793,7 @@ bool Bitmap::putDibRB(byte *pixels, const Palette &palette) {
 	uint16 *srcPtr2;
 	uint16 *srcPtr;
 
-	if (!palette.size()) {
+	if (!palette.size) {
 		debugC(2, kDebugDrawing, "Bitmap::putDibRB(): Both global and local palettes are empty");
 		return false;
 	}
@@ -847,7 +847,7 @@ bool Bitmap::putDibRB(byte *pixels, const Palette &palette) {
 				if (fillLen > 0 || start1 >= 0) {
 					if (x <= _width + 1 || (fillLen += _width - x + 1, fillLen > 0)) {
 						if (y <= endy) {
-							int bgcolor = palette[(pixel >> 8) & 0xff];
+							int bgcolor = palette.pal[(pixel >> 8) & 0xff];
 							curDestPtr = (uint32 *)_surface->getBasePtr(start1, y);
 							colorFill(curDestPtr, fillLen, bgcolor);
 						}
@@ -897,7 +897,7 @@ void Bitmap::putDibCB(byte *pixels, const Palette &palette) {
 
 	cb05_format = (_type == MKTAG('C', 'B', '\05', 'e'));
 
-	if (!palette.size() && !cb05_format)
+	if (!palette.size && !cb05_format)
 		error("Bitmap::putDibCB(): Both global and local palettes are empty");
 
 	bpp = cb05_format ? 2 : 1;
@@ -960,7 +960,7 @@ void Bitmap::paletteFill(uint32 *dest, byte *src, int len, const Palette &palett
 	byte r, g, b;
 
 	for (int i = 0; i < len; i++) {
-		g_fp->_origFormat.colorToRGB(palette[*src++] & 0xffff, r, g, b);
+		g_fp->_origFormat.colorToRGB(palette.pal[*src++] & 0xffff, r, g, b);
 
 		*dest++ = TS_ARGB(0xff, r, g, b);
 	}
@@ -989,7 +989,7 @@ void Bitmap::copierKeyColor(uint32 *dest, byte *src, int len, int keyColor, cons
 	if (!cb05_format) {
 		for (int i = 0; i < len; i++) {
 			if (*src != keyColor) {
-				g_fp->_origFormat.colorToRGB(palette[*src] & 0xffff, r, g, b);
+				g_fp->_origFormat.colorToRGB(palette.pal[*src] & 0xffff, r, g, b);
 				*dest = TS_ARGB(0xff, r, g, b);
 			}
 
@@ -1033,7 +1033,7 @@ void Bitmap::copier(uint32 *dest, byte *src, int len, const Palette &palette, bo
 
 	if (!cb05_format) {
 		for (int i = 0; i < len; i++) {
-			g_fp->_origFormat.colorToRGB(palette[*src++] & 0xffff, r, g, b);
+			g_fp->_origFormat.colorToRGB(palette.pal[*src++] & 0xffff, r, g, b);
 
 			*dest++ = TS_ARGB(0xff, r, g, b);
 		}
diff --git a/engines/fullpipe/gfx.h b/engines/fullpipe/gfx.h
index b498734c45..57a8d475d7 100644
--- a/engines/fullpipe/gfx.h
+++ b/engines/fullpipe/gfx.h
@@ -36,7 +36,6 @@ class DynamicPhase;
 class Movement;
 struct PicAniInfo;
 
-typedef Common::Array<int32> Palette;
 typedef Common::Point Dims;
 
 typedef Common::SharedPtr<Graphics::TransparentSurface> TransSurfacePtr;
diff --git a/engines/fullpipe/scene.cpp b/engines/fullpipe/scene.cpp
index 7018dd91b3..19ef3f3611 100644
--- a/engines/fullpipe/scene.cpp
+++ b/engines/fullpipe/scene.cpp
@@ -204,9 +204,10 @@ bool Scene::load(MfcArchive &file) {
 			assert(col->getDataSize() == 256 * sizeof(uint32));
 			const byte *data = col->getData();
 			for (int i = 0; i < 256; ++i) {
-				_palette.push_back(READ_LE_UINT32(data));
+				_palette.pal[i] = READ_LE_UINT32(data);
 				data += sizeof(uint32);
 			}
+			_palette.size = 256;
 		}
 	}
 
@@ -660,7 +661,7 @@ void Scene::drawContent(int minPri, int maxPri, bool drawBg) {
 	if (!_picObjList.size() && !_bigPictureXDim)
 		return;
 
-	if (_palette.size()) {
+	if (_palette.size) {
 		g_fp->_globalPalette = &_palette;
 	}
 
diff --git a/engines/fullpipe/statics.cpp b/engines/fullpipe/statics.cpp
index 7949847635..91b3df8e48 100644
--- a/engines/fullpipe/statics.cpp
+++ b/engines/fullpipe/statics.cpp
@@ -486,7 +486,7 @@ void Movement::draw(bool flipFlag, int angle) {
 	int x = _ox - point.x;
 	int y = _oy - point.y;
 
-	if (_currDynamicPhase->getPaletteData().size())
+	if (_currDynamicPhase->getPaletteData().size)
 		g_fp->_globalPalette = &_currDynamicPhase->getPaletteData();
 
 	Common::ScopedPtr<Bitmap> bmp;
@@ -2135,7 +2135,7 @@ DynamicPhase::DynamicPhase(DynamicPhase *src, bool reverse) {
 	_dynFlags = src->_dynFlags;
 
 	debug(8, "DynamicPhase::DynamicPhase(): pal: %p, pal size: %d",
-		(const void *)&src->getPaletteData(), src->getPaletteData().size());
+		(const void *)&src->getPaletteData(), src->getPaletteData().size);
 	setPaletteData(src->getPaletteData());
 
 	copyMemoryObject2(*src);




More information about the Scummvm-git-logs mailing list