[Scummvm-cvs-logs] SF.net SVN: scummvm: [25287] scummvm/trunk/engines/scumm/smush

cyx at users.sourceforge.net cyx at users.sourceforge.net
Tue Jan 30 21:36:05 CET 2007


Revision: 25287
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25287&view=rev
Author:   cyx
Date:     2007-01-30 12:36:03 -0800 (Tue, 30 Jan 2007)

Log Message:
-----------
added deinitialisation of codecs at the end of smush playback. This allows to save a bit of memory (about 1Mb for CMI) during gameplay.

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/smush/codec47.cpp
    scummvm/trunk/engines/scumm/smush/smush_player.cpp
    scummvm/trunk/engines/scumm/smush/smush_player.h

Modified: scummvm/trunk/engines/scumm/smush/codec47.cpp
===================================================================
--- scummvm/trunk/engines/scumm/smush/codec47.cpp	2007-01-30 20:31:48 UTC (rev 25286)
+++ scummvm/trunk/engines/scumm/smush/codec47.cpp	2007-01-30 20:36:03 UTC (rev 25287)
@@ -513,6 +513,8 @@
 	deinit();
 	_width = width;
 	_height = height;
+	_tableBig = (byte *)malloc(256 * 388);
+	_tableSmall = (byte *)malloc(256 * 128);
 	makeTablesInterpolation(4);
 	makeTablesInterpolation(8);
 
@@ -525,12 +527,20 @@
 }
 
 Codec47Decoder::Codec47Decoder() {
-	_tableBig = (byte *)malloc(99328);
-	_tableSmall = (byte *)malloc(32768);
+	_tableBig = NULL;
+	_tableSmall = NULL;
 	_deltaBuf = NULL;
 }
 
 void Codec47Decoder::deinit() {
+	if (_tableBig) {
+		free(_tableBig);
+		_tableBig = NULL;
+	}
+	if (_tableSmall) {
+		free(_tableSmall);
+		_tableSmall = NULL;
+	}
 	_lastTableWidth = -1;
 	if (_deltaBuf) {
 		free(_deltaBuf);
@@ -542,14 +552,6 @@
 }
 
 Codec47Decoder::~Codec47Decoder() {
-	if (_tableBig) {
-		free(_tableBig);
-		_tableBig = NULL;
-	}
-	if (_tableSmall) {
-		free(_tableSmall);
-		_tableSmall = NULL;
-	}
 	deinit();
 }
 

Modified: scummvm/trunk/engines/scumm/smush/smush_player.cpp
===================================================================
--- scummvm/trunk/engines/scumm/smush/smush_player.cpp	2007-01-30 20:31:48 UTC (rev 25286)
+++ scummvm/trunk/engines/scumm/smush/smush_player.cpp	2007-01-30 20:36:03 UTC (rev 25287)
@@ -284,7 +284,8 @@
 void SmushPlayer::init(int32 speed) {
 	_frame = 0;
 	_speed = speed;
-	_alreadyInit = false;
+	_codec37AlreadyInit = false;
+	_codec47AlreadyInit = false;
 	_endOfFile = false;
 
 	_vm->_smushVideoShouldFinish = false;
@@ -318,7 +319,7 @@
 	_closeOnTextTick = true;
 	// Wait for _closeOnTextTick to be set to false to indicate file closure
 	while (_closeOnTextTick) {
-		User::After(15624); 
+		User::After(15624);
 	}
 #endif
 
@@ -352,6 +353,15 @@
 	_vm->_gdi->_numStrips = _origNumStrips;
 
 	_initDone = false;
+
+	if (_codec37AlreadyInit) {
+		_codec37.deinit();
+		_codec37AlreadyInit = false;
+	}
+	if (_codec47AlreadyInit) {
+		_codec47.deinit();
+		_codec47AlreadyInit = false;
+	}
 }
 
 void SmushPlayer::checkBlock(const Chunk &b, Chunk::type type_expected, uint32 min_size) {
@@ -781,6 +791,31 @@
 
 void smush_decode_codec1(byte *dst, const byte *src, int left, int top, int width, int height, int pitch);
 
+void SmushPlayer::decodeFrameObject(int codec, const uint8 *src, int left, int top, int width, int height) {
+	switch (codec) {
+	case 1:
+	case 3:
+		smush_decode_codec1(_dst, src, left, top, width, height, _vm->_screenWidth);
+		break;
+	case 37:
+		if (!_codec37AlreadyInit) {
+			_codec37.init(width, height);
+			_codec37AlreadyInit = true;
+		}
+		_codec37.decode(_dst, src);
+		break;
+	case 47:
+		if (!_codec47AlreadyInit) {
+			_codec47.init(width, height);
+			_codec47AlreadyInit = true;
+		}
+		_codec47.decode(_dst, src);
+		break;
+	default:
+		error("Invalid codec for frame object : %d", codec);
+	}
+}
+
 #ifdef USE_ZLIB
 void SmushPlayer::handleZlibFrameObject(Chunk &b) {
 	if (_skipNext) {
@@ -813,18 +848,13 @@
 		_dst = _specialBuffer;
 	} else if ((height > _vm->_screenHeight) || (width > _vm->_screenWidth))
 		return;
+
 	// FT Insane uses smaller frames to draw overlays with moving objects
 	// Other .san files do have them as well but their purpose in unknown
 	// and often it causes memory overdraw. So just skip those frames
 	else if (!_insanity && ((height != _vm->_screenHeight) || (width != _vm->_screenWidth)))
 		return;
 
-	if (!_alreadyInit) {
-		_codec37.init(width, height);
-		_codec47.init(width, height);
-		_alreadyInit = true;
-	}
-
 	if ((height == 242) && (width == 384)) {
 		_width = width;
 		_height = height;
@@ -833,20 +863,7 @@
 		_height = _vm->_screenHeight;
 	}
 
-	switch (codec) {
-	case 1:
-	case 3:
-		smush_decode_codec1(_dst, fobjBuffer + 14, left, top, width, height, _vm->_screenWidth);
-		break;
-	case 37:
-		_codec37.decode(_dst, fobjBuffer + 14);
-		break;
-	case 47:
-		_codec47.decode(_dst, fobjBuffer + 14);
-		break;
-	default:
-		error("Invalid codec for frame object : %d", (int)codec);
-	}
+	decodeFrameObject(codec, fobjBuffer + 14, left, top, width, height);
 
 	if (_storeFrame) {
 		if (_frameBuffer == NULL) {
@@ -885,12 +902,6 @@
 	else if (!_insanity && ((height != _vm->_screenHeight) || (width != _vm->_screenWidth)))
 		return;
 
-	if (!_alreadyInit) {
-		_codec37.init(width, height);
-		_codec47.init(width, height);
-		_alreadyInit = true;
-	}
-
 	if ((height == 242) && (width == 384)) {
 		_width = width;
 		_height = height;
@@ -907,20 +918,7 @@
 	assert(chunk_buffer);
 	b.read(chunk_buffer, chunk_size);
 
-	switch (codec) {
-	case 1:
-	case 3:
-		smush_decode_codec1(_dst, chunk_buffer, left, top, width, height, _vm->_screenWidth);
-		break;
-	case 37:
-		_codec37.decode(_dst, chunk_buffer);
-		break;
-	case 47:
-		_codec47.decode(_dst, chunk_buffer);
-		break;
-	default:
-		error("Invalid codec for frame object : %d", (int)codec);
-	}
+	decodeFrameObject(codec, chunk_buffer, left, top, width, height);
 
 	if (_storeFrame) {
 		if (_frameBuffer == NULL) {
@@ -1390,7 +1388,7 @@
 			if (!skipFrame) {
 				int w = _width, h = _height;
 
-				// Workaround for bug #1386333: "FT DEMO: assertion triggered 
+				// Workaround for bug #1386333: "FT DEMO: assertion triggered
 				// when playing movie". Some frames there are 384 x 224
 				if (w > _vm->_screenWidth)
 					w = _vm->_screenWidth;

Modified: scummvm/trunk/engines/scumm/smush/smush_player.h
===================================================================
--- scummvm/trunk/engines/scumm/smush/smush_player.h	2007-01-30 20:31:48 UTC (rev 25286)
+++ scummvm/trunk/engines/scumm/smush/smush_player.h	2007-01-30 20:36:03 UTC (rev 25287)
@@ -47,7 +47,9 @@
 	byte _pal[0x300];
 	StringResource *_strings;
 	Codec37Decoder _codec37;
+	bool _codec37AlreadyInit;
 	Codec47Decoder _codec47;
+	bool _codec47AlreadyInit;
 	FileChunk *_base;
 	byte *_frameBuffer;
 	byte *_specialBuffer;
@@ -70,7 +72,6 @@
 	byte _IACToutput[4096];
 	int32 _IACTpos;
 	bool _storeFrame;
-	bool _alreadyInit;
 	bool _initDone;
 	int _speed;
 	bool _outputSound;
@@ -130,6 +131,7 @@
 	void tryCmpFile(const char *filename);
 
 	bool readString(const char *file);
+	void decodeFrameObject(int codec, const uint8 *src, int left, int top, int width, int height);
 	void checkBlock(const Chunk &, Chunk::type, uint32 = 0);
 	void handleAnimHeader(Chunk &);
 	void handleFrame(Chunk &);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list