[Scummvm-cvs-logs] CVS: scummvm/sword2/driver animation.cpp,1.1,1.2 animation.h,1.3,1.4 d_draw.cpp,1.57,1.58 d_draw.h,1.22,1.23

Max Horn fingolfin at users.sourceforge.net
Mon Jan 12 17:27:02 CET 2004


Update of /cvsroot/scummvm/scummvm/sword2/driver
In directory sc8-pr-cvs1:/tmp/cvs-serv13659

Modified Files:
	animation.cpp animation.h d_draw.cpp d_draw.h 
Log Message:
added legal header; fixed incorrect fscanf use; C++ification (the code still is quite Cish, though :-)

Index: animation.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/animation.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- animation.cpp	12 Jan 2004 11:11:19 -0000	1.1
+++ animation.cpp	13 Jan 2004 01:26:18 -0000	1.2
@@ -1,3 +1,24 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2004 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
 #include "common/stdafx.h"
 #include "sword2/sword2.h"
 #include "sword2/driver/menu.h"
@@ -8,48 +29,48 @@
 namespace Sword2 {
 
 // Build 'Best-Match' RGB lookup table
-void MoviePlayer::buildlookup(AnimationState * st, int p, int lines) {
+void AnimationState::buildLookup(int p, int lines) {
 	int y, cb;
 	int r, g, b, ii;
 
   
-	if (p != st->curpal) {
-		st->curpal = p;
-		st->cr = 0;
-		st->pos = 0;
+	if (p != curpal) {
+		curpal = p;
+		cr = 0;
+		pos = 0;
 	}
 
-	if (st->cr >= BITDEPTH)
+	if (cr >= BITDEPTH)
 		return;
 
 	for (ii = 0; ii < lines; ii++) {
-		r = (-16*256 + (int)(256*1.596) * ((st->cr<<SHIFT)-128)) / 256;
+		r = (-16*256 + (int)(256*1.596) * ((cr<<SHIFT)-128)) / 256;
 		for (cb = 0; cb < BITDEPTH; cb++) {
-			g = (-16*256 - (int)(0.813*256) * ((st->cr<<SHIFT)-128) - (int)(0.391*256) * ((cb<<SHIFT)-128)) / 256;
+			g = (-16*256 - (int)(0.813*256) * ((cr<<SHIFT)-128) - (int)(0.391*256) * ((cb<<SHIFT)-128)) / 256;
 			b = (-16*256 + (int)(2.018*256) * ((cb<<SHIFT)-128)) / 256;
 
 			for (y = 0; y < BITDEPTH; y++) {
 				int idx, bst = 0;
-				int dis = 2*SQR(r-st->palettes[p].pal[0])+4*SQR(g-st->palettes[p].pal[1])+SQR(b-st->palettes[p].pal[2]);
+				int dis = 2*SQR(r-palettes[p].pal[0])+4*SQR(g-palettes[p].pal[1])+SQR(b-palettes[p].pal[2]);
 
 				for (idx = 1; idx < 256; idx++) {
-					long d2 = 2*SQR(r-st->palettes[p].pal[4*idx])+4*SQR(g-st->palettes[p].pal[4*idx+1])+SQR(b-st->palettes[p].pal[4*idx+2]);
+					long d2 = 2*SQR(r-palettes[p].pal[4*idx])+4*SQR(g-palettes[p].pal[4*idx+1])+SQR(b-palettes[p].pal[4*idx+2]);
 					if (d2 < dis) {
 						bst = idx;
 						dis = d2;
+					}
 				}
+				lut2[pos++] = bst;
+	
+				r += (1 << SHIFT);
+				g += (1 << SHIFT);
+				b += (1 << SHIFT);
 			}
-			st->lut2[st->pos++] = bst;
-
-			r += (1 << SHIFT);
-			g += (1 << SHIFT);
-			b += (1 << SHIFT);
+			r -= 256;
 		}
-		r -= 256;
-	}
-    	st->cr++;
-    	if (st->cr >= BITDEPTH)
-      		return;
+		cr++;
+		if (cr >= BITDEPTH)
+			return;
 	}
 }
 
@@ -66,12 +87,12 @@
 }
 
 #ifndef USE_MPEG2
-bool MoviePlayer::pic(AnimationState * st) {
+bool MoviePlayer::decodeFrame(AnimationState * st) {
 	// Dummy for MPEG2-less builds
 	return false;
 }
 #else
-bool MoviePlayer::pic(AnimationState * st) {
+bool MoviePlayer::decodeFrame(AnimationState * st) {
 	mpeg2_state_t state;
 	const mpeg2_sequence_t *sequence_i;
 	size_t size = (size_t)-1;
@@ -92,13 +113,13 @@
 					checkPaletteSwitch(st);
 					_vm->_graphics->plotYUV(st->lut, sequence_i->width, sequence_i->height, st->info->display_fbuf->buf);
 					st->framenum++;
-					buildlookup(st, st->palnum+1, st->lutcalcnum);
+					st->buildLookup(st->palnum+1, st->lutcalcnum);
 					return true;
 				}
 			break;
 
 			default:
-      			break;
+				break;
 		}
 	} while (size);
 
@@ -107,11 +128,11 @@
 #endif
 
 #ifndef USE_MPEG2
-AnimationState *MoviePlayer::initanimation(char *name) {
+AnimationState *MoviePlayer::initAnimation(const char *name) {
 	return 0;
 }
 #else
-AnimationState *MoviePlayer::initanimation(char *name) {
+AnimationState *MoviePlayer::initAnimation(const char *name) {
 	char basename[512], tempFile[512];
 	AnimationState *st = new AnimationState;
   	int i, p;
@@ -127,15 +148,19 @@
 	if (!f) {
 		warning("Cutscene: %s.pal palette missing", basename);
 		return 0;
-    	}
+	}
 
 	p = 0;
 	while (!feof(f)) {
 		fscanf(f, "%i %i", &st->palettes[p].end, &st->palettes[p].cnt);
   		for (i = 0; i < st->palettes[p].cnt; i++) {
-			fscanf(f, "%i", &st->palettes[p].pal[4*i]);
-			fscanf(f, "%i", &st->palettes[p].pal[4*i+1]);
-			fscanf(f, "%i", &st->palettes[p].pal[4*i+2]);
+  			int r, g, b;
+  			fscanf(f, "%i", &r);
+  			fscanf(f, "%i", &g);
+  			fscanf(f, "%i", &b);
+			st->palettes[p].pal[4*i] = r;
+			st->palettes[p].pal[4*i+1] = g;
+			st->palettes[p].pal[4*i+2] = b;
 		}
 		p++;
 	}
@@ -146,7 +171,7 @@
 	st->lut = st->lut2 = st->lookup[0];
 	st->curpal = -1;
 	st->cr = 0;
-	buildlookup(st, st->palnum, 256);
+	st->buildLookup(st->palnum, 256);
 	st->lut2 = st->lookup[1];
 
 	// Open MPEG2 stream
@@ -174,20 +199,24 @@
 
 
 	/* Play audio - TODO: Sync with video?*/
+	// Another TODO: There is no reason that this only allows OGG, and not MP3, or any other format
+	// the mixer might support one day... is there?
 	File *sndFile = new File;
 	sprintf(tempFile, "%s.ogg", basename);
 	if (sndFile->open(tempFile))
 		_vm->_mixer->playVorbis(&st->bgSound, sndFile, 100000000);
 
+	// FIXME: This leaks (sndFile will never be deleted)
+
 	return st;
 }
 #endif
 
 #ifndef USE_MPEG2
-void MoviePlayer::doneanimation(AnimationState *st) {
+void MoviePlayer::doneAnimation(AnimationState *st) {
 }
 #else
-void MoviePlayer::doneanimation(AnimationState *st) {
+void MoviePlayer::doneAnimation(AnimationState *st) {
 	_vm->_mixer->stopHandle(st->bgSound);
 
 	mpeg2_close (st->decoder);

Index: animation.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/animation.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- animation.h	12 Jan 2004 23:41:05 -0000	1.3
+++ animation.h	13 Jan 2004 01:26:18 -0000	1.4
@@ -1,3 +1,24 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2004 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
 #ifndef ANIMATION_H
 #define ANIMATION_H
 
@@ -21,7 +42,8 @@
 #define BUFFER_SIZE 4096
 
 
-typedef struct {
+class AnimationState {
+public:
   int palnum;
 
   byte lookup[2][BITDEPTH * BITDEPTH * BITDEPTH];
@@ -51,7 +73,10 @@
 
   PlayingSoundHandle bgSound;
 
-} AnimationState;
+public:
+	void buildLookup(int p, int lines);
+
+};
 
 } // End of namespace Sword2
 

Index: d_draw.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_draw.cpp,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- d_draw.cpp	12 Jan 2004 16:36:01 -0000	1.57
+++ d_draw.cpp	13 Jan 2004 01:26:18 -0000	1.58
@@ -140,7 +140,7 @@
  * @param musicOut lead-out music
  */
 
-int32 MoviePlayer::play(char *filename, MovieTextObject *text[], uint8 *musicOut) {
+int32 MoviePlayer::play(const char *filename, MovieTextObject *text[], uint8 *musicOut) {
 #ifdef USE_MPEG2
 	int frameCounter = 0, textCounter = 0;
 	PlayingSoundHandle handle;
@@ -150,7 +150,7 @@
 	uint8 oldPal[1024];
 	memcpy(oldPal, _vm->_graphics->_palCopy, 1024);
 
-	AnimationState * anim = initanimation(filename);
+	AnimationState * anim = initAnimation(filename);
 	if (!anim) {
 		// Missing Files? Use the old 'Narration Only' hack
 		playDummy(filename, text, musicOut);
@@ -166,7 +166,7 @@
 #endif
 
 	while (1) {
-		if (!pic(anim)) break;
+		if (!decodeFrame(anim)) break;
 		_vm->_graphics->setNeedFullRedraw();
 
 		if (text && text[textCounter]) {                      
@@ -240,7 +240,7 @@
 
 	_vm->_graphics->setPalette(0, 256, oldPal, RDPAL_INSTANT);
 
-	doneanimation(anim);
+	doneAnimation(anim);
 
 	// Lead-in and lead-out music are, as far as I can tell, only used for
 	// the animated cut-scenes, so this seems like a good place to close
@@ -258,7 +258,7 @@
 }
 
 // This just plays the cutscene with voiceovers / subtitles, in case the files are missing
-int32 MoviePlayer::playDummy(char *filename, MovieTextObject *text[], uint8 *musicOut) {
+int32 MoviePlayer::playDummy(const char *filename, MovieTextObject *text[], uint8 *musicOut) {
 	int frameCounter = 0, textCounter = 0;
 	if (text) {
 		uint8 oldPal[1024];
@@ -310,7 +310,7 @@
 		tmpPal[255 * 4 + 2] = 255;
 		_vm->_graphics->setPalette(0, 256, tmpPal, RDPAL_INSTANT);
 
-PlayingSoundHandle handle;
+		PlayingSoundHandle handle;
 
 		bool skipCutscene = false;
 

Index: d_draw.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_draw.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- d_draw.h	12 Jan 2004 19:08:04 -0000	1.22
+++ d_draw.h	13 Jan 2004 01:26:18 -0000	1.23
@@ -68,23 +68,22 @@
 class MoviePlayer {
 private:
 	Sword2Engine *_vm;
-
 	uint8 *_textSurface;
+
 	void openTextObject(MovieTextObject *obj);
 	void closeTextObject(MovieTextObject *obj);
 	void drawTextObject(MovieTextObject *obj);
 
-	void buildlookup(AnimationState * st, int p, int lines);
 	void checkPaletteSwitch(AnimationState * st);
 
-	AnimationState * initanimation(char *name);
-	void doneanimation(AnimationState * st);
-	bool pic(AnimationState * st);
+	AnimationState * initAnimation(const char *name);
+	void doneAnimation(AnimationState * st);
+	bool decodeFrame(AnimationState * st);
 
 public:
 	MoviePlayer(Sword2Engine *vm) : _vm(vm), _textSurface(NULL) {}
-	int32 play(char *filename, MovieTextObject *text[], uint8 *musicOut);
-	int32 playDummy(char *filename, MovieTextObject *text[], uint8 *musicOut);
+	int32 play(const char *filename, MovieTextObject *text[], uint8 *musicOut);
+	int32 playDummy(const char *filename, MovieTextObject *text[], uint8 *musicOut);
 };
 
 struct BlockSurface {





More information about the Scummvm-git-logs mailing list