[Scummvm-cvs-logs] SF.net SVN: scummvm: [24725] scummvm/trunk/engines/touche

cyx at users.sourceforge.net cyx at users.sourceforge.net
Thu Nov 16 00:00:42 CET 2006


Revision: 24725
          http://svn.sourceforge.net/scummvm/?rev=24725&view=rev
Author:   cyx
Date:     2006-11-15 15:00:41 -0800 (Wed, 15 Nov 2006)

Log Message:
-----------
added dirty rects handling

Modified Paths:
--------------
    scummvm/trunk/engines/touche/saveload.cpp
    scummvm/trunk/engines/touche/touche.cpp
    scummvm/trunk/engines/touche/touche.h

Modified: scummvm/trunk/engines/touche/saveload.cpp
===================================================================
--- scummvm/trunk/engines/touche/saveload.cpp	2006-11-15 22:35:45 UTC (rev 24724)
+++ scummvm/trunk/engines/touche/saveload.cpp	2006-11-15 23:00:41 UTC (rev 24725)
@@ -271,7 +271,6 @@
 void ToucheEngine::loadGameStateData(Common::ReadStream *stream) {
 	setKeyCharMoney();
 	clearDirtyRects();
-	clearAreaTable();
 	_flagsTable[115] = 0;
 	clearRoomArea();
 	_currentEpisodeNum = stream->readUint16LE();

Modified: scummvm/trunk/engines/touche/touche.cpp
===================================================================
--- scummvm/trunk/engines/touche/touche.cpp	2006-11-15 22:35:45 UTC (rev 24724)
+++ scummvm/trunk/engines/touche/touche.cpp	2006-11-15 23:00:41 UTC (rev 24725)
@@ -59,7 +59,7 @@
 
 	_roomNeedRedraw	= false;
 	_fullRedrawCounter = 0;
-	_redrawScreenCounter1 = 0;
+	_menuRedrawCounter = 0;
 	memset(_paletteBuffer, 0, sizeof(_paletteBuffer));
 
 	setupOpcodes();
@@ -151,7 +151,6 @@
 	_giveItemToObjectNum = 0;
 	_giveItemToCounter = 0;
 
-	clearAreaTable();
 	clearAnimationTable();
 
 	setupInventoryAreas();
@@ -370,8 +369,6 @@
 	}
 	redrawRoom();
 	clearDirtyRects();
-	processAreaTable();
-	clearAreaTable();
 	updateRoomRegions();
 	if (_flagsTable[612] != 0) {
 		_flagsTable[613] = getRandomNumber(_flagsTable[612]);
@@ -450,7 +447,6 @@
 	_currentObjectNum = -1;
 	if (num != -1) {
 		_updatedRoomAreasTable[0] = 1;
-		clearAreaTable();
 		initKeyChars(-1);
 		for (int i = 200; i < 300; ++i) {
 			_flagsTable[i] = 0;
@@ -496,8 +492,7 @@
 	if (key->num != 0) {
 		Common::Rect r(key->prevBoundingRect);
 		r.extend(key->boundingRect);
-//		r.clip(_roomAreaRect);
-//		addToDirtyRect(r);
+		addToDirtyRect(r);
 	}
 }
 
@@ -613,12 +608,9 @@
 	for (int i = indexStart; i < indexEnd; ++i) {
 		KeyChar *key = &_keyCharsTable[i];
 		if (keyChar != -1 && key->num != 0) {
-			Area keyCharArea;
-			keyCharArea.r = key->prevBoundingRect;
-			keyCharArea.r.extend(key->boundingRect);
-			keyCharArea.srcX = _flagsTable[614] + keyCharArea.r.left;
-			keyCharArea.srcY = _flagsTable[615] + keyCharArea.r.top;
-			addToAreaTable(&keyCharArea);
+			Common::Rect r(key->prevBoundingRect);
+			r.extend(key->boundingRect);
+			addToDirtyRect(r);
 		}
 		key->num = 0;
 		key->strNum = 0;
@@ -1767,7 +1759,7 @@
 }
 
 int ToucheEngine::handleActionMenuUnderCursor(const int16 *actions, int offs, int y, int str) {
-	if (*actions == 0 || _redrawScreenCounter1 != 0) {
+	if (*actions == 0 || _menuRedrawCounter != 0) {
 		return -26;
 	}
 	int i;
@@ -1823,7 +1815,7 @@
 	}
 	updateScreenArea(cursorPosX, cursorPosY, cursorW, cursorH);
 
-	_redrawScreenCounter1 = 2;
+	_menuRedrawCounter = 2;
 	Common::Rect rect(0, y, 640, y + h);
 	i = -1;
 	while (_inp_rightMouseButtonPressed && _flagsTable[611] == 0) {
@@ -1877,36 +1869,13 @@
 	}
 }
 
-void ToucheEngine::processAreaTable() {
-	debugC(9, kDebugEngine, "ToucheEngine::processAreaTable()");
-//	for (int i = 0; i < _areaTableCount; ++i) {
-//		Rect r(_areaTable[i].r);
-//		if (rectClip(&_roomAreaRect, &r)) {
-//			addToDirtyRect(&r);
-//		}
-//	}
-}
-
-void ToucheEngine::clearAreaTable() {
-	debugC(9, kDebugEngine, "ToucheEngine::clearAreaTable()");
-	_areaTableCount = 0;
-}
-
-void ToucheEngine::addToAreaTable(const Area *area) {
-	debugC(9, kDebugEngine, "ToucheEngine::addToAreaTable()");
-	assert(_areaTableCount < NUM_AREAS);
-	_areaTable[_areaTableCount] = *area;
-	++_areaTableCount;
-}
-
 void ToucheEngine::addRoomArea(int num, int flag) {
 	debugC(9, kDebugEngine, "ToucheEngine::addRoomArea(%d, %d)", num, flag);
 	if (_flagsTable[flag] == 20000) {
 		Area area = _programBackgroundTable[num].area;
+		addToDirtyRect(area.r);
 		area.r.translate(-_flagsTable[614], -_flagsTable[615]);
-		if (area.clip(_roomAreaRect)) {
-			addToAreaTable(&area);
-		}
+		addToDirtyRect(area.r);
 	}
 	_programBackgroundTable[num].area.r.moveTo(_flagsTable[flag], _flagsTable[flag + 1]);
 }
@@ -1930,10 +1899,9 @@
 			  area.r.width(), area.r.height(),
 			  Graphics::kTransparent);
 			if (flags != 0) {
+				addToDirtyRect(area.r);
 				area.r.translate(-_flagsTable[614], -_flagsTable[615]);
-				if (area.clip(_roomAreaRect)) {
-					addToAreaTable(&area);
-				}
+				addToDirtyRect(area.r);
 			}
 		}
 	}
@@ -3179,9 +3147,7 @@
 		y += dy;
 	}
 	anim->displayRect = Common::Rect(displayRectX1, displayRectY1, displayRectX2 + 58, displayRectY2 + 42);
-//	if (rectClip(&_roomAreaRect, &anim->displayRect)) {
-//		addToDirtyRect(&anim->displayRect);
-//	}
+	addToDirtyRect(anim->displayRect);
 }
 
 void ToucheEngine::processAnimationTable() {
@@ -3212,11 +3178,41 @@
 }
 
 void ToucheEngine::addToDirtyRect(const Common::Rect &r) {
-	// XXX
+	if (_fullRedrawCounter == 0 && r.width() > 0 && r.height() > 0 && r.intersects(_roomAreaRect)) {
+		Common::Rect dirtyRect(r);
+		dirtyRect.clip(_roomAreaRect);
+		if (_dirtyRectsTableCount == 0) {
+			_dirtyRectsTable[_dirtyRectsTableCount] = dirtyRect;
+			++_dirtyRectsTableCount;
+		} else {
+			int index = -1;
+			int minRectSurface = 640 * 400;
+			for (int i = 0; i < _dirtyRectsTableCount; ++i) {
+				if (r.intersects(_dirtyRectsTable[i])) {
+					Common::Rect tmpRect(r);
+					tmpRect.extend(_dirtyRectsTable[i]);
+					int rectSurface = tmpRect.width() * tmpRect.height();
+					if (rectSurface < minRectSurface) {
+						minRectSurface = rectSurface;
+						index = i;
+					}
+				}
+			}
+			if (index != -1) {
+				_dirtyRectsTable[index].extend(dirtyRect);
+			} else if (_dirtyRectsTableCount == NUM_DIRTY_RECTS) {
+				// trigger full screen redraw
+				_fullRedrawCounter = 1;
+			} else {
+				_dirtyRectsTable[_dirtyRectsTableCount] = dirtyRect;
+				++_dirtyRectsTableCount;
+			}
+		}
+	}
 }
 
 void ToucheEngine::clearDirtyRects() {
-	// XXX
+	_dirtyRectsTableCount = 0;
 }
 
 void ToucheEngine::setPalette(int firstColor, int colorCount, int rScale, int gScale, int bScale) {
@@ -3251,20 +3247,29 @@
 }
 
 void ToucheEngine::updateDirtyScreenAreas() {
-	// XXX
-	updateScreenArea(0, 0, 640, 400);
-	if (_fullRedrawCounter) {
-//		updateEntireScreen();
+//	_fullRedrawCounter = 1;
+	if (_fullRedrawCounter != 0) {
+		updateEntireScreen();
 		--_fullRedrawCounter;
 	} else {
-//		for (int i = 0; i < _dirtyRectsCount; ++i) {
-//			Common::Rect *r = &_dirtyRects[i];
-//			updateScreenArea(r->x, r->y, r->w, r->h);
-//		}
-		if (_redrawScreenCounter1) {
-			--_redrawScreenCounter1;
-//			updateScreenArea(_cursorObjectRect.x, _cursorObjectRect.y, _cursorObjectRect.w, _cursorObjectRect.h);
+		debug(1, "dirtyRectsCount=%d", _dirtyRectsTableCount);
+		for (int i = 0; i < _dirtyRectsTableCount; ++i) {
+			const Common::Rect &r = _dirtyRectsTable[i];
+#if 0
+			const int pts[4] = { r.left, r.top, r.right - 1, r.bottom - 1 };
+			Graphics::drawLine(_offscreenBuffer, 640, pts[0], pts[1], pts[2], pts[1], 0xFF);
+			Graphics::drawLine(_offscreenBuffer, 640, pts[2], pts[1], pts[2], pts[3], 0xFF);
+			Graphics::drawLine(_offscreenBuffer, 640, pts[0], pts[3], pts[2], pts[3], 0xFF);
+			Graphics::drawLine(_offscreenBuffer, 640, pts[0], pts[1], pts[0], pts[3], 0xFF);
+#endif
+			_system->copyRectToScreen(_offscreenBuffer + r.top * 640 + r.left, 640, r.left, r.top, r.width(), r.height());
 		}
+		if (_menuRedrawCounter) {
+			const Common::Rect &r = _cursorObjectRect;
+			_system->copyRectToScreen(_offscreenBuffer + r.top * 640 + r.left, 640, r.left, r.top, r.width(), r.height());
+			--_menuRedrawCounter;
+		}
+		_system->updateScreen();
 	}
 }
 

Modified: scummvm/trunk/engines/touche/touche.h
===================================================================
--- scummvm/trunk/engines/touche/touche.h	2006-11-15 22:35:45 UTC (rev 24724)
+++ scummvm/trunk/engines/touche/touche.h	2006-11-15 23:00:41 UTC (rev 24725)
@@ -328,7 +328,7 @@
 		NUM_TALK_ENTRIES = 16,
 		NUM_ANIMATION_ENTRIES = 4,
 		NUM_INVENTORY_ITEMS = 100,
-		NUM_DIRTY_RECTS = 50,
+		NUM_DIRTY_RECTS = 30,
 		NUM_DIRECTIONS = 135
 	};
 
@@ -405,9 +405,6 @@
 	int handleActionMenuUnderCursor(const int16 *actions, int offs, int y, int str);
 
 	void redrawBackground();
-	void processAreaTable();
-	void clearAreaTable();
-	void addToAreaTable(const Area *area);
 	void addRoomArea(int num, int flag);
 	void updateRoomAreas(int num, int flags);
 	void setRoomAreaState(int num, uint16 state);
@@ -666,9 +663,6 @@
 	int _newEpisodeNum;
 	int _currentEpisodeNum;
 
-	Area _areaTable[NUM_AREAS];
-	int _areaTableCount;
-
 	int _currentAmountOfMoney;
 	int _giveItemToKeyCharNum;
 	int _giveItemToObjectNum;
@@ -733,9 +727,11 @@
 
 	bool _roomNeedRedraw;
 	int _fullRedrawCounter;
-	int _redrawScreenCounter1;
+	int _menuRedrawCounter;
 	uint8 *_offscreenBuffer;
 	uint8 _paletteBuffer[256 * 4];
+	Common::Rect _dirtyRectsTable[NUM_DIRTY_RECTS];
+	int _dirtyRectsTableCount;
 
 	static SpriteData _spritesTable[NUM_SPRITES];
 	static const uint8 _directionsTable[NUM_DIRECTIONS];


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