From e069ce6129bf5b9b338fe96d9d78471f39b9a09a Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 21 Nov 2007 00:34:32 +0000 Subject: Common::FixedStack is used now for AGI flood fill routines svn-id: r29589 --- engines/agi/picture.cpp | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/picture.cpp b/engines/agi/picture.cpp index b6f4b87fcf..1f1015666e 100644 --- a/engines/agi/picture.cpp +++ b/engines/agi/picture.cpp @@ -23,11 +23,9 @@ * */ - - #include "agi/agi.h" #include "agi/graphics.h" - +#include "common/stack.h" namespace Agi { @@ -64,28 +62,10 @@ void PictureMgr::putVirtPixel(int x, int y) { *p = _scrColor | (*p & 0xf0); } -/* For the flood fill routines */ +// For the flood fill routines -/* MH2 needs stack size > 300 */ -// FIXME: Consider using FixedStack<> or Stack<> from common/stack.h here -#define STACK_SIZE 512 -static unsigned int stackPtr; -static uint16 stack[STACK_SIZE]; - -static INLINE void lpush(uint16 c) { - assert(stackPtr < STACK_SIZE); - - stack[stackPtr] = c; - stackPtr++; -} - -static INLINE uint16 lpop() { - if (stackPtr == 0) - return 0xffff; - - stackPtr--; - return stack[stackPtr]; -} +// MH2 needs stack size > 300 +Common::FixedStack _stack[512]; /** * Draw an AGI line. @@ -291,7 +271,7 @@ void PictureMgr::fillScanline(int x, int y) { putVirtPixel(c, y); if (isOkFillHere(c, y - 1)) { if (newspanUp) { - lpush(c + (_width * 2) * (y - 1)); + _stack->push(c + (_width * 2) * (y - 1)); newspanUp = 0; } } else { @@ -300,7 +280,7 @@ void PictureMgr::fillScanline(int x, int y) { if (isOkFillHere(c, y + 1)) { if (newspanDown) { - lpush(c + (_width * 2) * (y + 1)); + _stack->push(c + (_width * 2) * (y + 1)); newspanDown = 0; } } else { @@ -310,22 +290,23 @@ void PictureMgr::fillScanline(int x, int y) { } void PictureMgr::agiFill(unsigned int x, unsigned int y) { - lpush(x + (_width * 2) * y); + uint16 c; + _stack->push(x + (_width * 2) * y); for (;;) { - uint16 c = lpop(); - - /* Exit if stack is empty */ - if (c == 0xffff) + // Exit if stack is empty + if (_stack->empty()) break; + c = _stack->pop(); + x = c % (_width * 2); y = c / (_width * 2); fillScanline(x, y); } - stackPtr = 0; + _stack->clear(); } /************************************************************************** -- cgit v1.2.3