diff options
| author | Max Horn | 2002-12-04 13:36:27 +0000 | 
|---|---|---|
| committer | Max Horn | 2002-12-04 13:36:27 +0000 | 
| commit | 89335008e9076bdfd0565514a7b22ecf4738b605 (patch) | |
| tree | f177dcbf676afc7e059e104519c701d79ad55b4a | |
| parent | be506653c9adcee20af99adf7248c0173fc246c5 (diff) | |
| download | scummvm-rg350-89335008e9076bdfd0565514a7b22ecf4738b605.tar.gz scummvm-rg350-89335008e9076bdfd0565514a7b22ecf4738b605.tar.bz2 scummvm-rg350-89335008e9076bdfd0565514a7b22ecf4738b605.zip | |
lots of cleanup to the graphics code; removed various global states (makes it easier to understand the code)
svn-id: r5831
| -rw-r--r-- | scumm/gfx.cpp | 91 | ||||
| -rw-r--r-- | scumm/gfx.h | 33 | ||||
| -rw-r--r-- | scumm/saveload.cpp | 4 | ||||
| -rw-r--r-- | scumm/scumm.h | 7 | ||||
| -rw-r--r-- | scumm/scummvm.cpp | 2 | ||||
| -rw-r--r-- | scumm/string.cpp | 18 | 
6 files changed, 81 insertions, 74 deletions
| diff --git a/scumm/gfx.cpp b/scumm/gfx.cpp index 21f9211855..b811bc1371 100644 --- a/scumm/gfx.cpp +++ b/scumm/gfx.cpp @@ -273,7 +273,7 @@ void Scumm::blit(byte *dst, byte *src, int w, int h)  void Scumm::setCursor(int cursor)  {  	if (cursor >= 0 && cursor <= 3) -		gdi._currentCursor = cursor; +		_currentCursor = cursor;  	else  		warning("setCursor(%d)", cursor);  } @@ -452,7 +452,7 @@ void Scumm::setPaletteFromPtr(byte *ptr)  		// check for that. And somebody before me added a check for V7 games, turning this  		// off there, too... I wonder if it hurts other games, too? What exactly is broken  		// if we remove this patch? -		if ((_gameId == GID_MONKEY_VGA) || (_features & GF_AFTER_V7) || (i <= 15 || r < 252 || g < 252 || b < 252)) { +		if ((_features & GF_AFTER_V7) || (i <= 15 || r < 252 || g < 252 || b < 252)) {  			*dest++ = r;  			*dest++ = g;  			*dest++ = b; @@ -728,8 +728,7 @@ void Scumm::fadeOut(int effect)  	// Fill screen 0 with black  	vs = &virtscr[0]; -	gdi._backbuff_ptr = vs->screenPtr + vs->xstart; -	memset(gdi._backbuff_ptr, 0, vs->size); +	memset(vs->screenPtr + vs->xstart, 0, vs->size);  	// Fade to black with the specified effect, if any.  	switch (effect) { @@ -921,14 +920,14 @@ void Gdi::drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h,  			if (_vm->hasCharsetMask(sx << 3, y, (sx + 1) << 3, bottom)) {  				if (flag & dbClear || !lightsOn) -					clear8ColWithMasking(); +					clear8ColWithMasking(_backbuff_ptr, h, _mask_ptr);  				else -					draw8ColWithMasking(); +					draw8ColWithMasking(_backbuff_ptr, _bgbak_ptr, h, _mask_ptr);  			} else {  				if (flag & dbClear || !lightsOn) -					clear8Col(); +					clear8Col(_backbuff_ptr, h);  				else -					_vm->blit(_backbuff_ptr, _bgbak_ptr, 8, h); +					draw8Col(_backbuff_ptr, _bgbak_ptr, h);  			}  		}  		CHECK_HEAP; @@ -950,13 +949,13 @@ void Gdi::drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h,  		// are still too unstable for me to investigate.  		if (flag & dbDrawMaskOnAll) { -			_z_plane_ptr = zplane_list[1] + READ_LE_UINT16(zplane_list[1] + stripnr * 2 + 8); +			byte *z_plane_ptr = zplane_list[1] + READ_LE_UINT16(zplane_list[1] + stripnr * 2 + 8);  			for (i = 0; i < numzbuf; i++) {  				_mask_ptr_dest = _vm->getResourceAddress(rtBuffer, 9) + y * _numStrips + x + _imgBufOffs[i];  				if (_useOrDecompress && flag & dbAllowMaskOr) -					decompressMaskImgOr(); +					decompressMaskImgOr(_mask_ptr_dest, z_plane_ptr, h);  				else -					decompressMaskImg(); +					decompressMaskImg(_mask_ptr_dest, z_plane_ptr, h);  			}  		} else {  			for (i = 1; i < numzbuf; i++) { @@ -976,15 +975,15 @@ void Gdi::drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h,  				_mask_ptr_dest = _vm->getResourceAddress(rtBuffer, 9) + y * _numStrips + x + _imgBufOffs[i];  				if (offs) { -					_z_plane_ptr = zplane_list[i] + offs; +					byte *z_plane_ptr = zplane_list[i] + offs;  					if (_useOrDecompress && flag & dbAllowMaskOr) -						decompressMaskImgOr(); +						decompressMaskImgOr(_mask_ptr_dest, z_plane_ptr, h);  					else -						decompressMaskImg(); +						decompressMaskImg(_mask_ptr_dest, z_plane_ptr, h);  				} else {  					if (!(_useOrDecompress && flag & dbAllowMaskOr)) -						for (int height = 0; height < _numLinesToProcess; height++) +						for (int height = 0; height < h; height++)  							_mask_ptr_dest[height * _numStrips] = 0;  					/* needs better abstraction, FIXME */  				} @@ -1135,12 +1134,8 @@ int Scumm::hasCharsetMask(int x, int y, int x2, int y2)  	return 1;  } -void Gdi::draw8ColWithMasking() +void Gdi::draw8ColWithMasking(byte *dst, byte *src, int height, byte *mask)  { -	int height = _numLinesToProcess; -	byte *mask = _mask_ptr; -	byte *dst = _backbuff_ptr; -	byte *src = _bgbak_ptr;  	byte maskbits;  	do { @@ -1164,7 +1159,7 @@ void Gdi::draw8ColWithMasking()  				dst[7] = src[7];  		} else {  #if defined(SCUMM_NEED_ALIGNMENT) -			memcpy(dst, src, 2 * sizeof(uint32)); +			memcpy(dst, src, 8);  #else  			((uint32 *)dst)[0] = ((uint32 *)src)[0];  			((uint32 *)dst)[1] = ((uint32 *)src)[1]; @@ -1176,11 +1171,8 @@ void Gdi::draw8ColWithMasking()  	} while (--height);  } -void Gdi::clear8ColWithMasking() +void Gdi::clear8ColWithMasking(byte *dst, int height, byte *mask)  { -	int height = _numLinesToProcess; -	byte *mask = _mask_ptr; -	byte *dst = _backbuff_ptr;  	byte maskbits;  	do { @@ -1204,7 +1196,7 @@ void Gdi::clear8ColWithMasking()  				dst[7] = 0;  		} else {  #if defined(SCUMM_NEED_ALIGNMENT) -			memset(dst, 0, 2 * sizeof(uint32)); +			memset(dst, 0, 8);  #else  			((uint32 *)dst)[0] = 0;  			((uint32 *)dst)[1] = 0; @@ -1215,14 +1207,11 @@ void Gdi::clear8ColWithMasking()  	} while (--height);  } -void Gdi::clear8Col() +void Gdi::clear8Col(byte *dst, int height)  { -	int height = _numLinesToProcess; -	byte *dst = _backbuff_ptr; -  	do {  #if defined(SCUMM_NEED_ALIGNMENT) -		memset(dst, 0, 2 * sizeof(uint32)); +		memset(dst, 0, 8);  #else  		((uint32 *)dst)[0] = 0;  		((uint32 *)dst)[1] = 0; @@ -1231,11 +1220,23 @@ void Gdi::clear8Col()  	} while (--height);  } -void Gdi::decompressMaskImg() +void Gdi::draw8Col(byte *dst, byte *src, int height) +{ +	do { +#if defined(SCUMM_NEED_ALIGNMENT) +		memcpy(dst, src, 8); +#else +		((uint32 *)dst)[0] = ((uint32 *)src)[0]; +		((uint32 *)dst)[1] = ((uint32 *)src)[1]; +#endif +		dst += _vm->_realWidth; +		src += _vm->_realWidth; +	} while (--height); +} + + +void Gdi::decompressMaskImg(byte *dst, byte *src, int height)  { -	byte *src = _z_plane_ptr; -	byte *dst = _mask_ptr_dest; -	int height = _numLinesToProcess;  	byte b, c;  	while (1) { @@ -1262,15 +1263,13 @@ void Gdi::decompressMaskImg()  	}  } -void Gdi::decompressMaskImgOr() +void Gdi::decompressMaskImgOr(byte *dst, byte *src, int height)  { -	byte *src = _z_plane_ptr; -	byte *dst = _mask_ptr_dest; -	int height = _numLinesToProcess;  	byte b, c;  	while (1) {  		b = *src++; +		  		if (b & 0x80) {  			b &= 0x7F;  			c = *src++; @@ -1600,7 +1599,7 @@ void Gdi::unkDecode7()  	do {  		/* Endian safe */  #if defined(SCUMM_NEED_ALIGNMENT) -		memcpy(dst, src, 2 * sizeof(uint32)); +		memcpy(dst, src, 8);  #else  		((uint32 *)dst)[0] = ((uint32 *)src)[0];  		((uint32 *)dst)[1] = ((uint32 *)src)[1]; @@ -2720,11 +2719,11 @@ void Gdi::resetBackground(int top, int bottom, int strip)  	if (_numLinesToProcess) {  		if ((_vm->_features & GF_AFTER_V6) || (_vm->_vars[_vm->VAR_CURRENT_LIGHTS] & LIGHTMODE_screen)) {  			if (_vm->hasCharsetMask(strip << 3, top, (strip + 1) << 3, bottom)) -				draw8ColWithMasking(); +				draw8ColWithMasking(_backbuff_ptr, _bgbak_ptr, _numLinesToProcess, _mask_ptr);  			else -				_vm->blit(_backbuff_ptr, _bgbak_ptr, 8, _numLinesToProcess); +				draw8Col(_backbuff_ptr, _bgbak_ptr, _numLinesToProcess);  		} else { -			clear8Col(); +			clear8Col(_backbuff_ptr, _numLinesToProcess);  		}  	}  } @@ -3028,12 +3027,12 @@ void Scumm::decompressDefaultCursor(int idx)  	} else {  		_cursorWidth = 16;  		_cursorHeight = 16; -		_cursorHotspotX = default_cursor_hotspots[2 * gdi._currentCursor]; -		_cursorHotspotY = default_cursor_hotspots[2 * gdi._currentCursor + 1]; +		_cursorHotspotX = default_cursor_hotspots[2 * _currentCursor]; +		_cursorHotspotY = default_cursor_hotspots[2 * _currentCursor + 1];  		for (i = 0; i < 16; i++) {  			for (j = 0; j < 16; j++) { -				if (default_cursor_images[gdi._currentCursor][i] & (1 << j)) +				if (default_cursor_images[_currentCursor][i] & (1 << j))  					_grabbedCursor[16 * i + 15 - j] = color;  			}  		} diff --git a/scumm/gfx.h b/scumm/gfx.h index eca0c543f4..c4230fbea2 100644 --- a/scumm/gfx.h +++ b/scumm/gfx.h @@ -109,17 +109,22 @@ struct BompDrawData {		/* Bomp graphics data */  	uint16 shadowMode;  }; -struct Gdi { +class Gdi { +	friend class Scumm;	// Mostly for the code in saveload.cpp ... +public:  	Scumm *_vm; +protected:  	byte *_readPtr;  	uint _readOffs; +public:  	int _numZBuffer;  	int _imgBufOffs[5];  	byte _disable_zbuffer;  	int32 _numStrips; +protected:  	bool _useOrDecompress;  	int _numLinesToProcess;  	int _tempNumLines; @@ -130,8 +135,9 @@ struct Gdi {  	int16 _drawMouseX;  	int16 _drawMouseY; +public:  	int16 _mask_top, _mask_bottom, _mask_right, _mask_left; -	byte _currentCursor; +protected:  	byte _mouseColors[4];  	byte _mouseColor;  	byte _mouseClipMask1, _mouseClipMask2, _mouseClipMask3; @@ -142,7 +148,6 @@ struct Gdi {  	byte *_bgbak_ptr;  	byte *_mask_ptr;  	byte *_mask_ptr_dest; -	byte *_z_plane_ptr;  	byte _palette_mod;  	byte _decomp_shr, _decomp_mask; @@ -164,27 +169,31 @@ struct Gdi {  	void unkDecode10();  	void unkDecode11(); +public:  	void drawBitmap(byte *ptr, VirtScreen *vs, int x, int y, int h, int stripnr, int numstrip, byte flag);  	void clearUpperMask();  	void disableZBuffer() { _disable_zbuffer++; }  	void enableZBuffer() { _disable_zbuffer--; } -	void draw8ColWithMasking(); -	void clear8ColWithMasking(); -	void clear8Col(); -	void decompressMaskImgOr(); -	void decompressMaskImg(); - -	void resetBackground(int top, int bottom, int strip); -	void drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b); -	void updateDirtyScreen(VirtScreen *vs); +protected: +	void draw8ColWithMasking(byte *dst, byte *src, int height, byte *mask); +	void draw8Col(byte *dst, byte *src, int height); +	void clear8ColWithMasking(byte *dst, int height, byte *mask); +	void clear8Col(byte *dst, int height); +	void decompressMaskImgOr(byte *dst, byte *src, int height); +	void decompressMaskImg(byte *dst, byte *src, int height); +public:  	enum DrawBitmapFlags {  		dbAllowMaskOr = 1,  		dbDrawMaskOnAll = 2,  		dbClear = 4  	}; + +	void resetBackground(int top, int bottom, int strip); +	void drawStripToScreen(VirtScreen *vs, int x, int w, int t, int b); +	void updateDirtyScreen(VirtScreen *vs);  };  #endif diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp index 33ecf348bf..8be9d988c1 100644 --- a/scumm/saveload.cpp +++ b/scumm/saveload.cpp @@ -398,7 +398,7 @@ void Scumm::saveOrLoad(Serializer *s)  		MKLINE(Scumm, _userPut, sleByte),  		MKLINE(Scumm, _cursorState, sleByte),  		MKLINE(Scumm, gdi._cursorActive, sleByte), -		MKLINE(Scumm, gdi._currentCursor, sleByte), +		MKLINE(Scumm, _currentCursor, sleByte),  		MKLINE(Scumm, _doEffect, sleByte),  		MKLINE(Scumm, _switchRoomEffect, sleByte), @@ -513,7 +513,7 @@ void Scumm::saveOrLoad(Serializer *s)  		MKLINE(Scumm, _userPut, sleByte),  		MKLINE(Scumm, _cursorState, sleByte),  		MKLINE(Scumm, gdi._cursorActive, sleByte), -		MKLINE(Scumm, gdi._currentCursor, sleByte), +		MKLINE(Scumm, _currentCursor, sleByte),  		MKLINE(Scumm, _doEffect, sleByte),  		MKLINE(Scumm, _switchRoomEffect, sleByte), diff --git a/scumm/scumm.h b/scumm/scumm.h index 61d92896a2..4a19cef967 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -200,14 +200,10 @@ struct CharsetRenderer {  	byte _ignoreCharsetMask; -	byte *_backbuff_ptr, *_bgbak_ptr; -	byte *_mask_ptr; -	byte *_dest_ptr; -		  	byte _colorMap[16];  	byte _buffer[512]; -	void drawBits(); +	void drawBits(byte *dst, byte *mask);  	void printChar(int chr);  	void printCharOld(int chr);  	int getSpacing(byte chr, byte *charset); @@ -696,6 +692,7 @@ public:  	int _cursorHotspotX, _cursorHotspotY, _cursorWidth, _cursorHeight;  	byte _cursorAnimate, _cursorAnimateIndex, _grabbedCursor[2048];  	int8 _cursorState; +	byte _currentCursor;  	byte _newEffect, _switchRoomEffect2, _switchRoomEffect;  	bool _doEffect; diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp index da5025081b..ab41c5131f 100644 --- a/scumm/scummvm.cpp +++ b/scumm/scummvm.cpp @@ -311,7 +311,7 @@ void Scumm::scummInit()  	_talkDelay = 0;  	_keepText = false; -	gdi._currentCursor = 0; +	_currentCursor = 0;  	_cursorState = 0;  	_userPut = 0; diff --git a/scumm/string.cpp b/scumm/string.cpp index e98b067717..cc4821e527 100644 --- a/scumm/string.cpp +++ b/scumm/string.cpp @@ -1023,10 +1023,14 @@ void CharsetRenderer::printChar(int chr)  	if (vs->number == 0 && _blitAlso == 0)  		_hasMask = true; +	byte *_backbuff_ptr; +	byte *_mask_ptr; +	byte *_dest_ptr; +  	_dest_ptr = _backbuff_ptr = vs->screenPtr + vs->xstart + _drawTop * _vm->_realWidth + _left;  	if (_blitAlso) { -		_dest_ptr = _bgbak_ptr = _vm->getResourceAddress(rtBuffer, vs->number + 5) +		_dest_ptr = _vm->getResourceAddress(rtBuffer, vs->number + 5)  			+ vs->xstart + _drawTop * _vm->_realWidth + _left;  	} @@ -1036,10 +1040,10 @@ void CharsetRenderer::printChar(int chr)  	_virtScreenHeight = vs->height;  	_charPtr += 4; -	drawBits(); +	drawBits(_dest_ptr, _mask_ptr);  	if (_blitAlso) -		_vm->blit(_backbuff_ptr, _bgbak_ptr, _width, _height); +		_vm->blit(_backbuff_ptr, _dest_ptr, _width, _height);  	_left += _width;  	if (_left > _strRight) @@ -1051,10 +1055,10 @@ void CharsetRenderer::printChar(int chr)  	_top -= _offsY;  } -void CharsetRenderer::drawBits() +void CharsetRenderer::drawBits(byte *dst, byte *mask)  {  	bool usemask; -	byte *dst, *mask, maskmask; +	byte maskmask;  	int y, x;  	int maskpos;  	int color; @@ -1065,8 +1069,6 @@ void CharsetRenderer::drawBits()  	bits = *_charPtr++;  	numbits = 8; -	dst = _dest_ptr; -	mask = _mask_ptr;  	y = 0;  	for (y = 0; y < _height && y + _drawTop < _virtScreenHeight;) { @@ -1092,7 +1094,7 @@ void CharsetRenderer::drawBits()  				maskpos++;  			}  		} -		dst = (_dest_ptr += _vm->_realWidth); +		dst += _vm->_realWidth - _width;  		mask += _vm->gdi._numStrips;  		y++;  	} | 
