[Scummvm-cvs-logs] CVS: scummvm/scumm charset.cpp,2.132,2.133 charset.h,2.38,2.39 gfx.cpp,2.416,2.417 gfx.h,1.107,1.108 scumm.cpp,1.383,1.384 scumm.h,1.546,1.547

Max Horn fingolfin at users.sourceforge.net
Thu Mar 24 17:28:36 CET 2005


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

Modified Files:
	charset.cpp charset.h gfx.cpp gfx.h scumm.cpp scumm.h 
Log Message:
Started some cleanup work on class Gdi (in particular, I try to limit that class to GFX decoding only, and moved the screen rendering code out of it)

Index: charset.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/charset.cpp,v
retrieving revision 2.132
retrieving revision 2.133
diff -u -d -r2.132 -r2.133
--- charset.cpp	24 Mar 2005 04:53:27 -0000	2.132
+++ charset.cpp	25 Mar 2005 01:27:02 -0000	2.133
@@ -202,6 +202,7 @@
 	_blitAlso = false;
 	_firstChar = false;
 	_disableOffsX = false;
+	_textSurface.pixels = 0;
 
 	_vm = vm;
 	_curId = 0;
@@ -1218,8 +1219,8 @@
 		dst = vs->getPixels(_left, drawTop);
 		drawBits1(*vs, dst, charPtr, drawTop, origWidth, origHeight);
 	} else {
-		dst = (byte *)_vm->gdi._textSurface.pixels + _top * _vm->gdi._textSurface.pitch + _left;
-		drawBits1(_vm->gdi._textSurface, dst, charPtr, drawTop, origWidth, origHeight);
+		dst = (byte *)_textSurface.pixels + _top * _textSurface.pitch + _left;
+		drawBits1(_textSurface, dst, charPtr, drawTop, origWidth, origHeight);
 	}
 
 	if (_str.left > _left)
@@ -1375,8 +1376,8 @@
 		dstSurface = *vs;
 		dstPtr = vs->getPixels(_left, drawTop);
 	} else {
-		dstSurface = _vm->gdi._textSurface;
-		dstPtr = (byte *)_vm->gdi._textSurface.pixels + (_top - _vm->_screenTop) * _vm->gdi._textSurface.pitch + _left;
+		dstSurface = _textSurface;
+		dstPtr = (byte *)_textSurface.pixels + (_top - _vm->_screenTop) * _textSurface.pitch + _left;
 	}
 
 	if (_blitAlso && vs->hasTwoBuffers) {
@@ -1650,7 +1651,7 @@
 		s = *vs;
 		s.pixels = vs->getPixels(0, 0);
 	} else {
-		s = _vm->gdi._textSurface;
+		s = _textSurface;
 		drawTop -= _vm->_screenTop;
 	}
 
@@ -1790,8 +1791,8 @@
 		dst = vs->getPixels(_left, drawTop);
 		drawBits1(*vs, dst, charPtr, drawTop, origWidth, origHeight);
 	} else {
-		dst = (byte *)_vm->gdi._textSurface.pixels + _top * _vm->gdi._textSurface.pitch + _left;
-		drawBits1(_vm->gdi._textSurface, dst, charPtr, drawTop, origWidth, origHeight);
+		dst = (byte *)_textSurface.pixels + _top * _textSurface.pitch + _left;
+		drawBits1(_textSurface, dst, charPtr, drawTop, origWidth, origHeight);
 	}
 
 	if (_str.left > _left)

Index: charset.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/charset.h,v
retrieving revision 2.38
retrieving revision 2.39
diff -u -d -r2.38 -r2.39
--- charset.h	16 Mar 2005 03:20:28 -0000	2.38
+++ charset.h	25 Mar 2005 01:27:03 -0000	2.39
@@ -76,6 +76,12 @@
 	bool _firstChar;
 	bool _disableOffsX;
 
+	/**
+	 * All text is normally rendered into this overlay surface. Then later
+	 * drawStripToScreen() composits it over the game graphics.
+	 */
+	Graphics::Surface _textSurface;
+
 protected:
 	ScummEngine *_vm;
 	byte _curId;

Index: gfx.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/gfx.cpp,v
retrieving revision 2.416
retrieving revision 2.417
diff -u -d -r2.416 -r2.417
--- gfx.cpp	25 Mar 2005 00:55:49 -0000	2.416
+++ gfx.cpp	25 Mar 2005 01:27:03 -0000	2.417
@@ -202,10 +202,6 @@
 	_roomPalette = vm->_roomPalette;
 	if ((vm->_features & GF_AMIGA) && (vm->_version >= 4))
 		_roomPalette += 16;
-	
-	_compositeBuf = 0;
-	_textSurface.pixels = 0;
-	_herculesBuf = 0;
 }
 
 void ScummEngine::initScreens(int b, int h) {
@@ -243,28 +239,29 @@
 	_screenH = h;
 	
 	gdi.init();
-}
 
-void Gdi::init() {
-	const int size = _vm->_screenWidth * _vm->_screenHeight;
+	const int size = _screenWidth * _screenHeight;
 	free(_compositeBuf);
-	free(_textSurface.pixels);
+	free(_charset->_textSurface.pixels);
 	free(_herculesBuf);
 	_compositeBuf = (byte *)malloc(size);
-	_textSurface.pixels = malloc(size);
+	_charset->_textSurface.pixels = malloc(size);
 	memset(_compositeBuf, CHARSET_MASK_TRANSPARENCY, size);
-	memset(_textSurface.pixels, CHARSET_MASK_TRANSPARENCY, size);
+	memset(_charset->_textSurface.pixels, CHARSET_MASK_TRANSPARENCY, size);
 
-	if (_vm->_renderMode == Common::kRenderHercA || _vm->_renderMode == Common::kRenderHercG) {
+	if (_renderMode == Common::kRenderHercA || _renderMode == Common::kRenderHercG) {
 		_herculesBuf = (byte *)malloc(Common::kHercW * Common::kHercH);
 		memset(_herculesBuf, CHARSET_MASK_TRANSPARENCY, Common::kHercW * Common::kHercH);
 	}
 
-	_textSurface.w = _vm->_screenWidth;
-	_textSurface.h = _vm->_screenHeight;
-	_textSurface.pitch = _vm->_screenWidth;
-	_textSurface.bytesPerPixel = 1;
+	_charset->_textSurface.w = _screenWidth;
+	_charset->_textSurface.h = _screenHeight;
+	_charset->_textSurface.pitch = _screenWidth;
+	_charset->_textSurface.bytesPerPixel = 1;
 
+}
+
+void Gdi::init() {
 	_numStrips = _vm->_screenWidth / 8;
 
 	// Increase the number of screen strips by one; needed for smooth scrolling
@@ -422,7 +419,7 @@
 	if (camera._last.x != camera._cur.x || (_features & GF_NEW_CAMERA && (camera._cur.y != camera._last.y))) {
 		// Camera moved: redraw everything
 		VirtScreen *vs = &virtscr[kMainVirtScreen];
-		gdi.drawStripToScreen(vs, 0, vs->w, 0, vs->h);
+		drawStripToScreen(vs, 0, vs->w, 0, vs->h);
 		vs->setDirtyRange(vs->h, 0);
 	} else {
 		updateDirtyScreen(kMainVirtScreen);
@@ -438,15 +435,13 @@
 	}
 }
 
-void ScummEngine::updateDirtyScreen(VirtScreenNumber slot) {
-	gdi.updateDirtyScreen(&virtscr[slot]);
-}
-
 /**
  * Blit the dirty data from the given VirtScreen to the display. If the camera moved,
  * a full blit is done, otherwise only the visible dirty areas are updated.
  */
-void Gdi::updateDirtyScreen(VirtScreen *vs) {
+void ScummEngine::updateDirtyScreen(VirtScreenNumber slot) {
+	VirtScreen *vs = &virtscr[slot];
+
 	// Do nothing for unused virtual screens
 	if (vs->h == 0)
 		return;
@@ -455,13 +450,13 @@
 	int w = 8;
 	int start = 0;
 
-	for (i = 0; i < _numStrips; i++) {
+	for (i = 0; i < gdi._numStrips; i++) {
 		if (vs->bdirty[i]) {
 			const int top = vs->tdirty[i];
 			const int bottom = vs->bdirty[i];
 			vs->tdirty[i] = vs->h;
 			vs->bdirty[i] = 0;
-			if (i != (_numStrips - 1) && vs->bdirty[i + 1] == bottom && vs->tdirty[i + 1] == top) {
+			if (i != (gdi._numStrips - 1) && vs->bdirty[i + 1] == bottom && vs->tdirty[i + 1] == top) {
 				// Simple optimizations: if two or more neighbouring strips
 				// form one bigger rectangle, coalesce them.
 				w += 8;
@@ -481,7 +476,7 @@
  * arrays which map 'strips' (sections of the real screen) to dirty areas as
  * specified by top/bottom coordinate in the virtual screen.
  */
-void Gdi::drawStripToScreen(VirtScreen *vs, int x, int width, int top, int bottom) {
+void ScummEngine::drawStripToScreen(VirtScreen *vs, int x, int width, int top, int bottom) {
 
 	if (bottom <= top)
 		return;
@@ -491,26 +486,26 @@
 
 	assert(top >= 0 && bottom <= vs->h);	// Paranoia checks
 	assert(x >= 0 && width <= vs->pitch);
-	assert(_textSurface.pixels);
+	assert(_charset->_textSurface.pixels);
 	assert(_compositeBuf);
 	
 	if (width > vs->w - x)
 		width = vs->w - x;
 
 	// Clip to the visible part of the scene
-	if (top < _vm->_screenTop)
-		top = _vm->_screenTop;
-	if (bottom > _vm->_screenTop + _vm->_screenHeight)
-		bottom = _vm->_screenTop + _vm->_screenHeight;
+	if (top < _screenTop)
+		top = _screenTop;
+	if (bottom > _screenTop + _screenHeight)
+		bottom = _screenTop + _screenHeight;
 
 	// Convert the vertical coordinates to real screen coords
-	int y = vs->topline + top - _vm->_screenTop;
+	int y = vs->topline + top - _screenTop;
 	int height = bottom - top;
 	
 	// Compute screen etc. buffer pointers
 	const byte *src = vs->getPixels(x, top);
-	byte *dst = _compositeBuf + x + y * _vm->_screenWidth;
-	const byte *text = (byte *)_textSurface.pixels + x + y * _textSurface.pitch;
+	byte *dst = _compositeBuf + x + y * _screenWidth;
+	const byte *text = (byte *)_charset->_textSurface.pixels + x + y * _charset->_textSurface.pitch;
 
 #ifdef __PALM_OS__
 	ARM_START(DrawStripType)
@@ -520,9 +515,9 @@
 		ARM_ADDM(src)
 		ARM_ADDM(dst)
 		ARM_ADDM(text)
-		ARM_ADDV(_vm_screenWidth, _vm->_screenWidth)
+		ARM_ADDV(_vm_screenWidth, _screenWidth)
 		ARM_ADDV(vs_pitch, vs->pitch)
-		ARM_ADDV(_textSurface_pitch, _textSurface.pitch)
+		ARM_ADDV(_charset->_textSurface_pitch, _charset->_textSurface.pitch)
 		ARM_CALL(ARM_ENGINE, PNO_DATA())
 	ARM_CONTINUE()
 #endif
@@ -535,18 +530,18 @@
 				dst[w] = text[w];
 		}
 		src += vs->pitch;
-		dst += _vm->_screenWidth;
-		text += _textSurface.pitch;
+		dst += _screenWidth;
+		text += _charset->_textSurface.pitch;
 	}
 
-	if (_vm->_renderMode == Common::kRenderCGA)
-		ditherCGA(_compositeBuf + x + y * _vm->_screenWidth, _vm->_screenWidth, x, y, width, height);
+	if (_renderMode == Common::kRenderCGA)
+		gdi.ditherCGA(_compositeBuf + x + y * _screenWidth, _screenWidth, x, y, width, height);
 
-	if (_vm->_renderMode == Common::kRenderHercA || _vm->_renderMode == Common::kRenderHercG) {
-		ditherHerc(_compositeBuf + x + y * _vm->_screenWidth, _herculesBuf, _vm->_screenWidth, &x, &y, &width, &height);
+	if (_renderMode == Common::kRenderHercA || _renderMode == Common::kRenderHercG) {
+		gdi.ditherHerc(_compositeBuf + x + y * _screenWidth, _herculesBuf, _screenWidth, &x, &y, &width, &height);
 		// center image on the screen
-		_vm->_system->copyRectToScreen(_herculesBuf + x + y * Common::kHercW, 
-			Common::kHercW, x + (Common::kHercW - _vm->_screenWidth * 2) / 2, y, width, height);
+		_system->copyRectToScreen(_herculesBuf + x + y * Common::kHercW, 
+			Common::kHercW, x + (Common::kHercW - _screenWidth * 2) / 2, y, width, height);
 	} else {
 		// Finally blit the whole thing to the screen
 		int x1 = x;
@@ -555,11 +550,11 @@
 		// NES can address negative number sprites and that poses problem for
 		// our code. So instead adding zillions of fixes and potentially break
 		// other games we shift it right on rendering stage
-		if (_vm->_features & GF_NES && ((_vm->_NESStartStrip > 0) || (vs->number != kMainVirtScreen))) {
+		if (_features & GF_NES && ((_NESStartStrip > 0) || (vs->number != kMainVirtScreen))) {
 			x += 16;
 		}
 
-		_vm->_system->copyRectToScreen(_compositeBuf + x1 + y * _vm->_screenWidth, _vm->_screenWidth, x, y, width, height);
+		_system->copyRectToScreen(_compositeBuf + x1 + y * _screenWidth, _screenWidth, x, y, width, height);
 	}
 }
 
@@ -810,14 +805,12 @@
 	for (int i = 0; i < num; i++)
 		setGfxUsageBit(s + i, USAGE_BIT_DIRTY);
 
-	if (_version == 1) {
-		gdi._objectMode = false;
-	}
 	if (_heversion >= 70)
 		room = getResourceAddress(rtRoomImage, _roomResource);
 	else
 		room = getResourceAddress(rtRoom, _roomResource);
 
+	gdi._objectMode = false;
 	gdi.drawBitmap(room + _IM00_offs,
 					&virtscr[0], s, 0, _roomWidth, virtscr[0].h, s, num, 0, _roomStrips);
 }
@@ -856,8 +849,8 @@
 	if (vs->hasTwoBuffers && _currentRoom != 0 && isLightOn()) {
 		blit(screenBuf, vs->pitch, vs->getBackPixels(rect.left, rect.top), vs->pitch, width, height);
 		if (vs->number == kMainVirtScreen && _charset->_hasMask) {
-			byte *mask = (byte *)gdi._textSurface.pixels + gdi._textSurface.pitch * (rect.top - _screenTop) + rect.left;
-			fill(mask, gdi._textSurface.pitch, CHARSET_MASK_TRANSPARENCY, width, height);
+			byte *mask = (byte *)_charset->_textSurface.pixels + _charset->_textSurface.pitch * (rect.top - _screenTop) + rect.left;
+			fill(mask, _charset->_textSurface.pitch, CHARSET_MASK_TRANSPARENCY, width, height);
 		}
 	} else {
 		fill(screenBuf, vs->pitch, backColor, width, height);
@@ -898,7 +891,7 @@
 
 		if (vs->hasTwoBuffers) {
 			// Clean out the charset mask
-			memset(_vm->gdi._textSurface.pixels, CHARSET_MASK_TRANSPARENCY, _vm->gdi._textSurface.pitch * _vm->gdi._textSurface.h);
+			memset(_textSurface.pixels, CHARSET_MASK_TRANSPARENCY, _textSurface.pitch * _textSurface.h);
 		}
 	}
 }
@@ -1038,8 +1031,8 @@
 		bgbuff = vs->getBackPixels(x, y);
 		blit(backbuff, vs->pitch, bgbuff, vs->pitch, width, height);
 		if (_charset->_hasMask) {
-			byte *mask = (byte *)gdi._textSurface.pixels + gdi._textSurface.pitch * (y - _screenTop) + x;
-			fill(mask, gdi._textSurface.pitch, CHARSET_MASK_TRANSPARENCY, width, height);
+			byte *mask = (byte *)_charset->_textSurface.pixels + _charset->_textSurface.pitch * (y - _screenTop) + x;
+			fill(mask, _charset->_textSurface.pitch, CHARSET_MASK_TRANSPARENCY, width, height);
 		}
 	} else {
 		fill(backbuff, vs->pitch, color, width, height);

Index: gfx.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/gfx.h,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- gfx.h	25 Mar 2005 00:55:55 -0000	1.107
+++ gfx.h	25 Mar 2005 01:27:04 -0000	1.108
@@ -211,12 +211,7 @@
 	
 	Gdi(ScummEngine *vm);
 
-	Graphics::Surface _textSurface;
-
 protected:
-	byte *_compositeBuf;
-	byte *_herculesBuf;
-
 	byte *_roomPalette;
 	byte _decomp_shr, _decomp_mask;
 	byte _transparentColor;
@@ -269,8 +264,6 @@
 	void decompressMaskImg(byte *dst, const byte *src, int height) const;
 
 	/* Misc */
-	void drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b);
-	void updateDirtyScreen(VirtScreen *vs);
 	void ditherCGA(byte *dst, int dstPitch, int x, int y, int width, int height) const;
 	void ditherHerc(byte *src, byte *hercbuf, int srcPitch, int *x, int *y, int *width, int *height) const;
 

Index: scumm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.cpp,v
retrieving revision 1.383
retrieving revision 1.384
diff -u -d -r1.383 -r1.384
--- scumm.cpp	25 Mar 2005 00:56:02 -0000	1.383
+++ scumm.cpp	25 Mar 2005 01:27:04 -0000	1.384
@@ -807,8 +807,10 @@
 	_doEffect = false;
 	memset(&_flashlight, 0, sizeof(_flashlight));
 	_roomStrips = 0;
+	_compositeBuf = 0;
+	_herculesBuf = 0;
 	_bompActorPalettePtr = NULL;
-	_shakeEnabled= false;
+	_shakeEnabled = false;
 	_shakeFrame = 0;
 	_screenStartStrip = 0;
 	_screenEndStrip = 0;

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.546
retrieving revision 1.547
diff -u -d -r1.546 -r1.547
--- scumm.h	25 Mar 2005 00:37:14 -0000	1.546
+++ scumm.h	25 Mar 2005 01:27:05 -0000	1.547
@@ -984,8 +984,12 @@
 		markRectAsDirty(virt, rect.left, rect.right, rect.top, rect.bottom, dirtybit);
 	}
 protected:
+	// Screen rendering
+	byte *_compositeBuf;
+	byte *_herculesBuf;
 	void drawDirtyScreenParts();
 	void updateDirtyScreen(VirtScreenNumber slot);
+	void drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b);
 
 public:
 	VirtScreen *findVirtScreen(int y);





More information about the Scummvm-git-logs mailing list