[Scummvm-cvs-logs] CVS: scummvm/scumm/smush chunk_type.h,1.8,1.8.2.1 smush_font.cpp,1.16,1.16.2.1 smush_font.h,1.10,1.10.2.1 smush_mixer.cpp,1.31,1.31.2.1 smush_player.cpp,1.111.2.3,1.111.2.4 smush_player.h,1.26.2.1,1.26.2.2

Pawel Kolodziejski aquadran at users.sourceforge.net
Sat Jun 26 02:19:13 CEST 2004


Update of /cvsroot/scummvm/scummvm/scumm/smush
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12615/scummvm/scumm/smush

Modified Files:
      Tag: branch-0-6-0
	chunk_type.h smush_font.cpp smush_font.h smush_mixer.cpp 
	smush_player.cpp smush_player.h 
Log Message:
backported imuse digital and smush changes

Index: chunk_type.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk_type.h,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -u -d -r1.8 -r1.8.2.1
--- chunk_type.h	6 Jan 2004 12:45:31 -0000	1.8
+++ chunk_type.h	26 Jun 2004 09:18:30 -0000	1.8.2.1
@@ -32,6 +32,7 @@
 static const Chunk::type TYPE_FRME = 'FRME';
 static const Chunk::type TYPE_NPAL = 'NPAL';
 static const Chunk::type TYPE_FOBJ = 'FOBJ';
+static const Chunk::type TYPE_ZFOB = 'ZFOB';
 static const Chunk::type TYPE_PSAD = 'PSAD';
 static const Chunk::type TYPE_TRES = 'TRES';
 static const Chunk::type TYPE_XPAL = 'XPAL';

Index: smush_font.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_font.cpp,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -u -d -r1.16 -r1.16.2.1
--- smush_font.cpp	6 Jan 2004 12:45:31 -0000	1.16
+++ smush_font.cpp	26 Jun 2004 09:18:30 -0000	1.16.2.1
@@ -85,7 +85,7 @@
 		if (_new_colors) {
 			for (int j = 0; j < h; j++) {
 				for (int i = 0; i < w; i++) {
-					char value = *src++;
+					int8 value = *src++;
 					if (value == -color) {
 						dst[i] = 0xFF;
 					} else if (value == -31) {
@@ -157,27 +157,8 @@
 #define MAX_WORDS	60
 
 
-void SmushFont::drawStringAbsolute(const char *str, byte *buffer, int dst_width, int x, int y) {
-	debug(9, "SmushFont::drawStringAbsolute(%s, %d, %d)", str, x, y);
-
-	while (str) {
-		char line[256];
-		char *pos = strchr(str, '\n');
-		if (pos) {
-			memcpy(line, str, pos - str - 1);
-			line[pos - str - 1] = 0;
-			str = pos + 1;
-		} else {
-			strcpy(line, str);
-			str = 0;
-		}
-		drawSubstring(line, buffer, dst_width, x, y);
-		y += getStringHeight(line);
-	}
-}
-
-void SmushFont::drawStringCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y) {
-	debug(9, "SmushFont::drawStringCentered(%s, %d, %d)", str, x, y);
+void SmushFont::drawString(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center) {
+	debug(9, "SmushFont::drawString(%s, %d, %d, %d)", str, x, y, center);
 
 	while (str) {
 		char line[256];
@@ -190,13 +171,13 @@
 			strcpy(line, str);
 			str = 0;
 		}
-		drawSubstring(line, buffer, dst_width, x - getStringWidth(line) / 2, y);
+		drawSubstring(line, buffer, dst_width, center ? (x - getStringWidth(line) / 2) : x, y);
 		y += getStringHeight(line);
 	}
 }
 
-void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) {
-	debug(9, "SmushFont::drawStringWrap(%s, %d, %d, %d, %d)", str, x, y, left, right);
+void SmushFont::drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right, bool center) {
+	debug(9, "SmushFont::drawStringWrap(%s, %d, %d, %d, %d, %d)", str, x, y, left, right, center);
 
 	const int width = right - left;
 	char *s = strdup(str);
@@ -243,78 +224,28 @@
 	if (y > dst_height - height) {
 		y = dst_height - height;
 	}
-
-	if (x > dst_width - max_width)
-		x = dst_width - max_width;
-
-	for (i = 0; i < line_count; i++) {
-		drawSubstring(substrings[i], buffer, dst_width, x, y);
-		y += getStringHeight(substrings[i]);
-	}
 	
-	free(s);
-}
-
-void SmushFont::drawStringWrapCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right) {
-	debug(9, "SmushFont::drawStringWrapCentered(%s, %d, %d, %d, %d)", str, x, y, left, right);
+	if (center) {
+		max_width = (max_width + 1) / 2;
+		x = left + width / 2;
 	
-	const int width = right - left;
-	char *s = strdup(str);
-	char *words[MAX_WORDS];
-	int word_count = 0;
-
-	char *tmp = s;
-	while (tmp) {
-		assert(word_count < MAX_WORDS);
-		words[word_count++] = tmp;
-		tmp = strpbrk(tmp, " \t\r\n");
-		if (tmp == 0)
-			break;
-		*tmp++ = 0;
-	}
-
-	int i = 0, max_width = 0, height = 0, line_count = 0;
-
-	char *substrings[MAX_WORDS];
-	int substr_widths[MAX_WORDS];
-	const int space_width = getCharWidth(' ');
-
-	i = 0;
-	while (i < word_count) {
-		char *substr = words[i++];
-		int substr_width = getStringWidth(substr);
-
-		while (i < word_count) {
-			int word_width = getStringWidth(words[i]);
-			if ((substr_width + space_width + word_width) >= width)
-				break;
-			substr_width += word_width + space_width;
-			*(words[i]-1) = ' ';	// Convert 0 byte back to space
-			i++;
+		if (x < left + max_width)
+			x = left + max_width;
+		if (x > right - max_width)
+			x = right - max_width;
+	
+		for (i = 0; i < line_count; i++) {
+			drawSubstring(substrings[i], buffer, dst_width, x - substr_widths[i] / 2, y);
+			y += getStringHeight(substrings[i]);
+		}
+	} else {
+		if (x > dst_width - max_width)
+			x = dst_width - max_width;
+	
+		for (i = 0; i < line_count; i++) {
+			drawSubstring(substrings[i], buffer, dst_width, x, y);
+			y += getStringHeight(substrings[i]);
 		}
-
-		substrings[line_count] = substr;
-		substr_widths[line_count++] = substr_width;
-		if (max_width < substr_width)
-			max_width = substr_width;
-		height += getStringHeight(substr);
-	}
-
-	if (y > dst_height - height) {
-		y = dst_height - height;
-	}
-
-	max_width = (max_width + 1) / 2;
-	x = left + width / 2;
-
-	if (x < left + max_width)
-		x = left + max_width;
-	if (x > right - max_width)
-		x = right - max_width;
-
-	for (i = 0; i < line_count; i++) {
-		drawSubstring(substrings[i], buffer, dst_width, x - substr_widths[i] / 2, y);
-		y += getStringHeight(substrings[i]);
 	}
 	
 	free(s);

Index: smush_font.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_font.h,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -d -r1.10 -r1.10.2.1
--- smush_font.h	6 Jan 2004 12:45:31 -0000	1.10
+++ smush_font.h	26 Jun 2004 09:18:30 -0000	1.10.2.1
@@ -45,10 +45,8 @@
 	SmushFont(bool use_original_colors, bool new_colors);
 
 	void setColor(byte c) { _color = c; }
-	void drawStringAbsolute    (const char *str, byte *buffer, int dst_width, int x, int y);
-	void drawStringCentered    (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y);
-	void drawStringWrap        (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
-	void drawStringWrapCentered(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right);
+	void drawString    (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center);
+	void drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int left, int right, bool center);
 };
 
 } // End of namespace Scumm

Index: smush_mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_mixer.cpp,v
retrieving revision 1.31
retrieving revision 1.31.2.1
diff -u -d -r1.31 -r1.31.2.1
--- smush_mixer.cpp	2 Feb 2004 22:40:20 -0000	1.31
+++ smush_mixer.cpp	26 Jun 2004 09:18:30 -0000	1.31.2.1
@@ -77,7 +77,7 @@
 	}
 
 	for (i = 0; i < NUM_CHANNELS; i++) {
-		warning("channel %d : %p(%d, %d) %d", i, (void *)_channels[i].chan, 
+		warning("channel %d : %p(%d, %d)", i, (void *)_channels[i].chan, 
 			_channels[i].chan ? _channels[i].chan->getTrackIdentifier() : -1, 
 			_channels[i].chan ? _channels[i].chan->isTerminated() : 1);
 	}
@@ -120,7 +120,7 @@
 
 				if (_mixer->isReady()) {
 					if (!_channels[i].handle.isActive())
-						_mixer->newStream(&_channels[i].handle, rate, flags, 400000);
+						_mixer->newStream(&_channels[i].handle, rate, flags, 500000);
 					_mixer->setChannelVolume(_channels[i].handle, vol);
 					_mixer->setChannelBalance(_channels[i].handle, pan);
 					_mixer->appendStream(_channels[i].handle, data, size);

Index: smush_player.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_player.cpp,v
retrieving revision 1.111.2.3
retrieving revision 1.111.2.4
diff -u -d -r1.111.2.3 -r1.111.2.4
--- smush_player.cpp	4 May 2004 14:59:36 -0000	1.111.2.3
+++ smush_player.cpp	26 Jun 2004 09:18:30 -0000	1.111.2.4
@@ -48,6 +48,10 @@
 #include <png.h>
 #endif
 
+#ifdef USE_ZLIB
+#include <zlib.h>
+#endif
+
 namespace Scumm {
 
 const int MAX_STRINGS = 200;
@@ -241,27 +245,24 @@
 }
 
 SmushPlayer::~SmushPlayer() {
-	deinit();
+	release();
 }
 
 void SmushPlayer::init() {
-
 	_frame = 0;
-
+	_alreadyInit = false;
 	_vm->_videoFinished = false;
-
-	_smixer = new SmushMixer(_vm->_mixer);
-
 	_vm->setDirtyColors(0, 255);
 	_dst = _vm->virtscr[0].screenPtr + _vm->virtscr[0].xstart;
+	_smixer = new SmushMixer(_vm->_mixer);
 	g_timer->installTimerProc(&timerCallback, _speed, this);
-
-	_alreadyInit = false;
 }
 
-void SmushPlayer::deinit() {
+void SmushPlayer::release() {
 	_vm->_timer->removeTimerProc(&timerCallback);
 
+	_vm->_videoFinished = true;
+
 	for (int i = 0; i < 5; i++) {
 		if (_sf[i]) {
 			delete _sf[i];
@@ -284,12 +285,11 @@
 		delete _base;
 		_base = NULL;
 	}
-	
 	if (_specialBuffer) {
 		free(_specialBuffer);
 		_specialBuffer = NULL;
 	}
-
+	
 	_vm->_mixer->stopHandle(_IACTchannel);
 
 	_vm->_fullRedraw = true;
@@ -518,11 +518,12 @@
 		str++; // For Full Throttle text resources
 	}
 
+	byte transBuf[512];
 	if (_vm->_gameId == GID_CMI) {
-		_vm->translateText((const byte *)str - 1, _vm->_transText);
+		_vm->translateText((const byte *)str - 1, transBuf);
 		while (*str++ != '/')
 			;
-		string2 = (char *)_vm->_transText;
+		string2 = (char *)transBuf;
 
 		// If string2 contains formatting information there probably
 		// wasn't any translation for it in the language.tab file. In
@@ -565,10 +566,10 @@
 	// bit 3 - wrap around  8
 	switch (flags & 9) {
 	case 0: 
-		sf->drawStringAbsolute(str, _dst, _width, pos_x, pos_y);
+		sf->drawString(str, _dst, _width, _height, pos_x, pos_y, false);
 		break;
 	case 1:
-		sf->drawStringCentered(str, _dst, _width, _height, pos_x, MAX(pos_y, top));
+		sf->drawString(str, _dst, _width, _height, pos_x, MAX(pos_y, top), true);
 		break;
 	case 8:
 		// FIXME: Is 'right' the maximum line width here, just
@@ -576,7 +577,7 @@
 		// in The Dig's intro, where 'left' and 'right' are
 		// always 0 and 321 respectively, and apparently we
 		// handle that correctly.
-		sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, right);
+		sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, right, false);
 		break;
 	case 9:
 		// In this case, the 'right' parameter is actually the
@@ -585,7 +586,7 @@
 		//
 		// Note that in The Dig's "Spacetime Six" movie it's
 		// 621. I have no idea what that means.
-		sf->drawStringWrapCentered(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width));
+		sf->drawStringWrap(str, _dst, _width, _height, pos_x, MAX(pos_y, top), left, MIN(left + right, _width), true);
 		break;
 	default:
 		warning("SmushPlayer::handleTextResource. Not handled flags: %d", flags);
@@ -673,6 +674,83 @@
 
 void smush_decode_codec1(byte *dst, byte *src, int left, int top, int height, int width, int dstWidth);
 
+#ifdef USE_ZLIB
+void SmushPlayer::handleZlibFrameObject(Chunk &b) {
+	if (_skipNext) {
+		_skipNext = false;
+		return;
+	}
+
+	int32 chunkSize = b.getSize();
+	byte *chunkBuffer = (byte *)malloc(chunkSize);
+	assert(chunkBuffer);
+	b.read(chunkBuffer, chunkSize);
+
+	unsigned long decompressedSize = READ_BE_UINT32(chunkBuffer);
+	byte *fobjBuffer = (byte *)malloc(decompressedSize);
+	int result = uncompress(fobjBuffer, &decompressedSize, chunkBuffer + 4, chunkSize - 4);
+	if (result != Z_OK)
+		error("SmushPlayer::handleZlibFrameObject() Zlib uncompress error");
+	free(chunkBuffer);
+
+	byte *ptr = fobjBuffer;
+	int codec = READ_LE_UINT16(ptr); ptr += 2;
+	int left = READ_LE_UINT16(ptr); ptr += 2;
+	int top = READ_LE_UINT16(ptr); ptr += 2;
+	int width = READ_LE_UINT16(ptr); ptr += 2;
+	int height = READ_LE_UINT16(ptr); ptr += 2;
+
+	if ((height == 242) && (width == 384)) {
+		_dst = _specialBuffer = (byte *)malloc(242 * 384);
+	} 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;
+	} else {
+		_width = _vm->_screenWidth;
+		_height = _vm->_screenHeight;
+	}
+
+	switch (codec) {
+	case 1:
+	case 3:
+		smush_decode_codec1(_dst, fobjBuffer + 14, left, top, height, width, _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);
+	}
+
+	if (_storeFrame) {
+		if (_frameBuffer == NULL) {
+			_frameBuffer = (byte *)malloc(_width * _height);
+		}
+		memcpy(_frameBuffer, _dst, _width * _height);
+		_storeFrame = false;
+	}
+
+	free(fobjBuffer);
+}
+#endif
+
 void SmushPlayer::handleFrameObject(Chunk &b) {
 	checkBlock(b, TYPE_FOBJ, 14);
 	if (_skipNext) {
@@ -681,8 +759,8 @@
 	}
 
 	int codec = b.getWord();
-	int left = b.getWord(); // left
-	int top = b.getWord(); // top
+	int left = b.getWord();
+	int top = b.getWord();
 	int width = b.getWord();
 	int height = b.getWord();
 
@@ -766,6 +844,11 @@
 		case TYPE_FOBJ:
 			handleFrameObject(*sub);
 			break;
+#ifdef USE_ZLIB
+		case TYPE_ZFOB:
+			handleZlibFrameObject(*sub);
+			break;
+#endif
 		case TYPE_PSAD:
 			handleSoundFrame(*sub);
 			break;
@@ -902,6 +985,11 @@
 		error("Unknown Chunk found at %x: %x, %d", _base->tell(), sub->getType(), sub->getSize());
 	}
 	delete sub;
+
+	if (_insanity)
+		_vm->_sound->processSoundQues();
+
+	_vm->_imuseDigital->flushTracks();
 }
 
 void SmushPlayer::setPalette(const byte *palette) {
@@ -1051,7 +1139,7 @@
 		_middleAudio = true;
 	}
 
-	while (true) {
+	for (;;) {
 		_vm->parseEvents();
 		_vm->processKbd(true);
 		if (_updateNeeded) {
@@ -1062,9 +1150,6 @@
 			_vm->_system->update_screen();
 			_updateNeeded = false;
 
-			if (_insanity)
-				_vm->_sound->processSoundQues();
-
 			end_time = _vm->_system->get_msecs();
 
 			debug(4, "Smush stats: BackendUpdateScreen( %03d )", end_time - start_time);
@@ -1075,8 +1160,8 @@
 		_vm->_system->delay_msecs(10);
 	};
 
-	deinit();
-	
+	release();
+
 	// Reset mouse state
 	_vm->_system->show_mouse(oldMouseState);
 }

Index: smush_player.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_player.h,v
retrieving revision 1.26.2.1
retrieving revision 1.26.2.2
diff -u -d -r1.26.2.1 -r1.26.2.2
--- smush_player.h	22 Apr 2004 12:27:22 -0000	1.26.2.1
+++ smush_player.h	26 Jun 2004 09:18:30 -0000	1.26.2.2
@@ -91,7 +91,7 @@
 	void updatePalette(void);
 	void parseNextFrame();
 	void init();
-	void deinit();
+	void release();
 	void setupAnim(const char *file, const char *directory);
 	void updateScreen();
 
@@ -100,6 +100,9 @@
 	void handleAnimHeader(Chunk &);
 	void handleFrame(Chunk &);
 	void handleNewPalette(Chunk &);
+#ifdef USE_ZLIB
+	void handleZlibFrameObject(Chunk &b);
+#endif
 	void handleFrameObject(Chunk &);
 	void handleSoundBuffer(int32, int32, int32, int32, int32, int32, Chunk &, int32);
 	void handleSoundFrame(Chunk &);





More information about the Scummvm-git-logs mailing list