[Scummvm-cvs-logs] SF.net SVN: scummvm: [28471] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Mon Aug 6 21:13:51 CEST 2007


Revision: 28471
          http://scummvm.svn.sourceforge.net/scummvm/?rev=28471&view=rev
Author:   peres001
Date:     2007-08-06 12:13:51 -0700 (Mon, 06 Aug 2007)

Log Message:
-----------
Changed graphics mask to a more generic BitBuffer object.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/callables_ns.cpp
    scummvm/trunk/engines/parallaction/graphics.cpp
    scummvm/trunk/engines/parallaction/graphics.h

Modified: scummvm/trunk/engines/parallaction/callables_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/callables_ns.cpp	2007-08-06 15:40:12 UTC (rev 28470)
+++ scummvm/trunk/engines/parallaction/callables_ns.cpp	2007-08-06 19:13:51 UTC (rev 28471)
@@ -600,8 +600,8 @@
 	return;
 }
 
-void plotPixel(int x, int y, int color, void *data) {
-	_vm->_gfx->plotMaskPixel(x, y, color);
+void zeroMask(int x, int y, int color, void *data) {
+	_vm->_gfx->zeroMaskValue(x, y, color);
 }
 
 void Parallaction_ns::_c_sketch(void *parm) {
@@ -614,7 +614,7 @@
 	uint16 oldy = _rightHandPositions[2*(index-1)+1];
 	uint16 oldx = _rightHandPositions[2*(index-1)];
 
-	Graphics::drawLine(oldx, oldy, newx, newy, 0, plotPixel, NULL);
+	Graphics::drawLine(oldx, oldy, newx, newy, 0, zeroMask, NULL);
 
 	_rightHandAnim->_left = newx;
 	_rightHandAnim->_top = newy - 20;

Modified: scummvm/trunk/engines/parallaction/graphics.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.cpp	2007-08-06 15:40:12 UTC (rev 28470)
+++ scummvm/trunk/engines/parallaction/graphics.cpp	2007-08-06 19:13:51 UTC (rev 28471)
@@ -357,21 +357,14 @@
 	byte *s = data + q.left + q.top * r.width();
 	byte *d = (byte*)_buffers[buffer]->getBasePtr(dp.x, dp.y);
 
-	for (uint16 i = q.top; i < q.bottom; i++) {
+	for (uint16 i = 0; i < q.height(); i++) {
 
-		uint16 n = dp.x % 4;
-		byte *m = _depthMask + dp.x/4 + (dp.y + i - q.top)*_vm->_screenMaskWidth;
-
-		for (uint16 j = q.left; j < q.right; j++) {
+		for (uint16 j = 0; j < q.width(); j++) {
 			if (*s != 0) {
-				uint16 v = ((3 << (n << 1)) & *m) >> (n << 1);
+				byte v = _depthMask->getValue(dp.x + j, dp.y + i);
 				if (z >= v) *d = *s;
 			}
 
-			n++;
-			if (n==4) m++;
-			n &= 0x3;
-
 			s++;
 			d++;
 		}
@@ -768,7 +761,7 @@
 }
 
 void Gfx::setMask(byte *mask) {
-	memcpy(_depthMask, mask, _vm->_screenMaskSize);
+	memcpy(_depthMask->data, mask, _vm->_screenMaskSize);
 }
 
 
@@ -808,10 +801,10 @@
 	so they shouldn't be modified when adding support for other games
 */
 
-void Gfx::plotMaskPixel(uint16 x, uint16 y, byte color) {
+void Gfx::zeroMaskValue(uint16 x, uint16 y, byte color) {
 
 	uint16 _ax = x + y * _vm->_screenWidth;
-	_depthMask[_ax >> 2] &= ~(3 << ((_ax & 3) << 1));
+	_depthMask->data[_ax >> 2] &= ~(3 << ((_ax & 3) << 1));
 
 	return;
 }
@@ -820,7 +813,7 @@
 	uint16 _di = r.left/4 + r.top * _vm->_screenMaskWidth;
 
 	for (uint16 _si = r.top; _si < r.bottom; _si++) {
-		memset(&_depthMask[_di], color, r.width()/4+1);
+		memset(_depthMask->data + _di, color, r.width()/4+1);
 		_di += _vm->_screenMaskWidth;
 	}
 
@@ -828,7 +821,7 @@
 
 }
 void Gfx::intGrottaHackMask() {
-	memset(_depthMask + 3600, 0, 3600);
+	memset(_depthMask->data + 3600, 0, 3600);
 	_bgLayers[1] = 500;
 	return;
 }
@@ -857,7 +850,8 @@
 	_buffers[kBit2] = new Graphics::Surface;
 	_buffers[kBit2]->create(_vm->_screenWidth, _vm->_screenHeight, 1);
 
-	_depthMask = (byte*)malloc(_vm->_screenMaskWidth * _vm->_screenHeight);
+	_depthMask = new BitBuffer;
+	_depthMask->create(_vm->_screenWidth, _vm->_screenHeight);
 
 	setBlackPalette();
 
@@ -878,7 +872,8 @@
 
 Gfx::~Gfx() {
 
-	free(_depthMask);
+	_depthMask->free();
+	delete _depthMask;
 
 	_buffers[kBitFront]->free();
 	delete _buffers[kBitFront];

Modified: scummvm/trunk/engines/parallaction/graphics.h
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.h	2007-08-06 15:40:12 UTC (rev 28470)
+++ scummvm/trunk/engines/parallaction/graphics.h	2007-08-06 19:13:51 UTC (rev 28471)
@@ -146,6 +146,47 @@
 	kFontMenu = 2
 };
 
+struct BitBuffer {
+	// handles a 2-bit depth buffer used for z-buffering
+
+	// TODO: generalize to handle 1-bit buffers, so that
+	// path buffers can be handled as well (use templates?)
+
+	uint16	w;
+	uint16  internalWidth;
+	uint16	h;
+	uint	size;
+	byte	*data;
+
+public:
+	BitBuffer() : w(0), internalWidth(0), h(0), data(0) {
+	}
+
+	~BitBuffer() {
+		free();
+	}
+
+	void create(uint16 width, uint16 height) {
+		w = width;
+		internalWidth = w >> 2;
+		h = height;
+		size = (internalWidth * h);
+		data = (byte*)malloc(size);
+	}
+
+	void free() {
+		if (data)
+			::free(data);
+	}
+
+	inline byte getValue(uint16 x, uint16 y) {
+		byte m = data[(x >> 2) + y * internalWidth];
+		uint n = (x & 3) << 1;
+		return ((3 << n) & m) >> n;
+	}
+
+};
+
 class Gfx {
 
 public:
@@ -184,9 +225,9 @@
 	void intGrottaHackMask();
 	void restoreBackground(const Common::Rect& r);
 
-	// intro
+	// intro hacks for Nippon Safes
 	void fillMaskRect(const Common::Rect& r, byte color);
-	void plotMaskPixel(uint16 x, uint16 y, byte color);
+	void zeroMaskValue(uint16 x, uint16 y, byte color);
 
 	// low level
 	void swapBuffers();
@@ -233,7 +274,7 @@
 protected:
 	Parallaction*		_vm;
 	Graphics::Surface	*_buffers[NUM_BUFFERS];
-	byte				*_depthMask;
+	BitBuffer			*_depthMask;
 	static byte			_mouseArrow[256];
 	StaticCnv			*_mouseComposedArrow;
 	Font				*_font;


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