[Scummvm-cvs-logs] SF.net SVN: scummvm: [29600] scummvm/trunk/engines/agi

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Nov 22 09:20:28 CET 2007


Revision: 29600
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29600&view=rev
Author:   fingolfin
Date:     2007-11-22 00:20:28 -0800 (Thu, 22 Nov 2007)

Log Message:
-----------
Refactore the AGI floodfill code

Modified Paths:
--------------
    scummvm/trunk/engines/agi/picture.cpp
    scummvm/trunk/engines/agi/picture.h

Modified: scummvm/trunk/engines/agi/picture.cpp
===================================================================
--- scummvm/trunk/engines/agi/picture.cpp	2007-11-21 21:51:21 UTC (rev 29599)
+++ scummvm/trunk/engines/agi/picture.cpp	2007-11-22 08:20:28 UTC (rev 29600)
@@ -25,6 +25,7 @@
 
 #include "agi/agi.h"
 #include "agi/graphics.h"
+#include "common/stack.h"
 
 namespace Agi {
 
@@ -230,9 +231,6 @@
 	if (x < 0 || x >= _width || y < 0 || y >= _height)
 		return false;
 
-	if (!_scrOn && !_priOn)
-		return false;
-
 	p = _vm->_game.sbuf16c[y * _width + x];
 
 	if (_flags & kPicFTrollMode)
@@ -250,59 +248,51 @@
 /**************************************************************************
 ** agi_fill
 **************************************************************************/
-void PictureMgr::fillScanline(int x, int y) {
-	unsigned int c;
-	int newspanUp, newspanDown;
-
-	if (!isOkFillHere(x, y))
+void PictureMgr::agiFill(unsigned int x, unsigned int y) {
+	if (!_scrOn && !_priOn)
 		return;
 
-	/* Scan for left border */
-	for (c = x - 1; isOkFillHere(c, y); c--);
+	// Push initial pixel on the stack
+	Common::Stack<Common::Point> stack;
+	stack.push(Common::Point(x,y));
 
-	newspanUp = newspanDown = 1;
-	for (c++; isOkFillHere(c, y); c++) {
-		putVirtPixel(c, y);
-		if (isOkFillHere(c, y - 1)) {
-			if (newspanUp) {
-				_stack.push(c + (_width * 2) * (y - 1));
-				newspanUp = 0;
+	// Exit if stack is empty
+	while (!stack.empty()) {
+		Common::Point p = stack.pop();
+		unsigned int c;
+		int newspanUp, newspanDown;
+
+		if (!isOkFillHere(p.x, p.y))
+			continue;
+
+		/* Scan for left border */
+		for (c = p.x - 1; isOkFillHere(c, p.y); c--)
+			;
+
+		newspanUp = newspanDown = 1;
+		for (c++; isOkFillHere(c, p.y); c++) {
+			putVirtPixel(c, p.y);
+			if (isOkFillHere(c, p.y - 1)) {
+				if (newspanUp) {
+					stack.push(Common::Point(c,p.y-1));
+					newspanUp = 0;
+				}
+			} else {
+				newspanUp = 1;
 			}
-		} else {
-			newspanUp = 1;
-		}
 
-		if (isOkFillHere(c, y + 1)) {
-			if (newspanDown) {
-				_stack.push(c + (_width * 2) * (y + 1));
-				newspanDown = 0;
+			if (isOkFillHere(c, p.y + 1)) {
+				if (newspanDown) {
+					stack.push(Common::Point(c,p.y+1));
+					newspanDown = 0;
+				}
+			} else {
+				newspanDown = 1;
 			}
-		} else {
-			newspanDown = 1;
 		}
 	}
 }
 
-void PictureMgr::agiFill(unsigned int x, unsigned int y) {
-	uint16 c;
-	_stack.push(x + (_width * 2) * y);
-
-	for (;;) {
-		// Exit if stack is empty
-		if (_stack.empty())
-			break;
-
-		c = _stack.pop();
-
-		x = c % (_width * 2);
-		y = c / (_width * 2);
-
-		fillScanline(x, y);
-	}
-
-	_stack.clear();
-}
-
 /**************************************************************************
 ** xCorner
 **

Modified: scummvm/trunk/engines/agi/picture.h
===================================================================
--- scummvm/trunk/engines/agi/picture.h	2007-11-21 21:51:21 UTC (rev 29599)
+++ scummvm/trunk/engines/agi/picture.h	2007-11-22 08:20:28 UTC (rev 29600)
@@ -27,7 +27,6 @@
 #define AGI_PICTURE_H
 
 #include "agi/agi.h"
-#include "common/stack.h"
 
 namespace Agi {
 
@@ -73,7 +72,6 @@
 	void dynamicDrawLine();
 	void absoluteDrawLine();
 	INLINE int isOkFillHere(int x, int y);
-	void fillScanline(int x, int y);
 	void agiFill(unsigned int x, unsigned int y);
 	void xCorner(bool skipOtherCoords = false);
 	void yCorner(bool skipOtherCoords = false);
@@ -141,7 +139,6 @@
 
 	int _flags;
 	int _currentStep;
-	Common::Stack<uint16> _stack;	// For the flood fill routines
 };
 
 } // End of namespace Agi


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