[Scummvm-cvs-logs] CVS: scummvm/bs2/driver d_draw.cpp,1.9,1.10 rdwin.cpp,1.16,1.17 rdwin.h,1.1,1.2 render.cpp,1.16,1.17 sprite.cpp,1.12,1.13

Torbj?rn Andersson eriktorbjorn at users.sourceforge.net
Thu Aug 28 23:43:04 CEST 2003


Update of /cvsroot/scummvm/scummvm/bs2/driver
In directory sc8-pr-cvs1:/tmp/cvs-serv10958/driver

Modified Files:
	d_draw.cpp rdwin.cpp rdwin.h render.cpp sprite.cpp 
Log Message:
Added some code to stop producing interpolation frames if the scene has
already reached its scroll target. This keeps BS2 from using all available
CPU time all of the time.

It may still be that we need a mechanism for throttling the frame rate when
the scene is moving towards a scroll target, but my computer isn't really
fast enough to test that.

Two other bugs fixed in the process:

* I think the last frame of the render cycle was rendered, but not
  displayed. If so, that should be fixed now.

* I discovered that there are cases where we do need to clear the screen
  (e.g. at the "Meanwhile..." message when George has found out about the
  Glease Gallery), so I've re-enabled the function and disabled it in the
  render cycle.


Index: d_draw.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/d_draw.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- d_draw.cpp	28 Aug 2003 06:36:15 -0000	1.9
+++ d_draw.cpp	29 Aug 2003 06:42:34 -0000	1.10
@@ -24,6 +24,7 @@
 #include "_mouse.h"
 #include "d_draw.h"
 #include "palette.h"
+#include "render.h"
 
 #define SCREENYOFFSET	40
 #define MILLISECSPERCYCLE 83
@@ -205,14 +206,7 @@
 }
 
 int32 EraseBackBuffer( void ) {
-	// Since the entire screen is redrawn each time, there probably isn't
-	// any need to actually clear the back buffer.
-	//
-	// At the very least, since the menu code now is solely responsible
-	// for its own parts of the screen, we'd only need to clear the
-	// picture area.
-
-	// memset(lpBackBuffer + MENUDEEP * screnWide, 0, screenWide * (screenDeep - 2 * MENUDEEP));
+	memset(lpBackBuffer + MENUDEEP * screenWide, 0, screenWide * RENDERDEEP);
 	return RD_OK;
 }
 

Index: rdwin.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/rdwin.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- rdwin.cpp	28 Aug 2003 06:36:15 -0000	1.16
+++ rdwin.cpp	29 Aug 2003 06:42:34 -0000	1.17
@@ -537,7 +537,11 @@
 
 }
 
+static bool _needRedraw = false;
 
+void SetNeedRedraw() {
+	_needRedraw = true;
+}
 
 int32 ServiceWindows(void)
 
@@ -548,8 +552,14 @@
 	// FIXME: We re-render the entire picture area of the screen for each
 	// frame, which is pretty horrible.
 
-	g_system->copy_rect(lpBackBuffer + MENUDEEP * screenWide, screenWide, 0, MENUDEEP, screenWide, screenDeep - 2 * MENUDEEP);
+	if (_needRedraw) {
+		g_system->copy_rect(lpBackBuffer + MENUDEEP * screenWide, screenWide, 0, MENUDEEP, screenWide, screenDeep - 2 * MENUDEEP);
+		_needRedraw = false;
+	}
+
+	// We still need to update because of fades, menu animations, etc.
 	g_system->update_screen();
+
 //	warning("stub ServiceWindows");  // too noisy
 /*
 	MSG msg;

Index: rdwin.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/rdwin.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- rdwin.h	28 Jul 2003 01:47:41 -0000	1.1
+++ rdwin.h	29 Aug 2003 06:42:34 -0000	1.2
@@ -52,5 +52,6 @@
 extern void Message(LPSTR fmt, ...);
 */
 
+extern void SetNeedRedraw(void);
 
 #endif

Index: render.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/render.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- render.cpp	28 Aug 2003 06:36:15 -0000	1.16
+++ render.cpp	29 Aug 2003 06:42:34 -0000	1.17
@@ -258,7 +258,6 @@
 int32 renderTimeLog[RENDERAVERAGETOTAL] = {60, 60, 60, 60};
 int32 initialTime;
 int32 startTime;
-int32 originTime;
 int32 totalTime;
 int32 renderAverageTime = 60;
 int32 framesPerGameCycle;
@@ -331,6 +330,7 @@
 	}
 
 	// UploadRect(r);
+	SetNeedRedraw();
 }
 
 #define SCALE_MAXWIDTH 512
@@ -987,10 +987,11 @@
 }
 */
 
+// Uncomment this when benchmarking the drawing routines.
+#define LIMIT_FRAME_RATE
 
 int32 InitialiseRenderCycle(void) {
 	initialTime = SVM_timeGetTime();
-	originTime = initialTime;
 	totalTime = initialTime + MILLISECSPERCYCLE;
 	return RD_OK;
 }
@@ -1018,13 +1019,27 @@
 }
 
 
+// FIXME: Move this to some better place?
+
+void sleepUntil(int32 time) {
+	while ((int32) SVM_timeGetTime() < time) {
+		g_sword2->parseEvents();
+
+		// Make sure menu animations and fades don't suffer
+		ProcessMenu();
+		if (ServiceWindows() == RDERR_APPCLOSED)
+			break;
+
+		g_system->delay_msecs(10);
+	}
+}
 
 int32 EndRenderCycle(BOOL *end) {
 	int32 time;
 
 	time = SVM_timeGetTime();
 	renderTimeLog[renderCountIndex] = time - startTime;
-	startTime += renderTimeLog[renderCountIndex];
+	startTime = time;
 	renderAverageTime = (renderTimeLog[0] + renderTimeLog[1] + renderTimeLog[2] + renderTimeLog[3]) >> 2;
 
 	framesPerGameCycle += 1;
@@ -1037,13 +1052,31 @@
 		InitialiseRenderCycle();
 	} else if (startTime + renderAverageTime >= totalTime) {
 		*end = TRUE;
-		originTime = totalTime;
 		totalTime += MILLISECSPERCYCLE;
 		initialTime = time;
+#ifdef LIMIT_FRAME_RATE
+	} else if (scrollxTarget == scrollx && scrollyTarget == scrolly) {
+		// If we have already reached the scroll target sleep for the
+		// rest of the render cycle.
+		*end = TRUE;
+		sleepUntil(totalTime);
+		initialTime = SVM_timeGetTime();
+		totalTime += MILLISECSPERCYCLE;
+#endif
 	} else {
 		*end = FALSE;
-		scrollx = (int16) (scrollxOld + ((scrollxTarget - scrollxOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime));
-		scrolly = (int16) (scrollyOld + ((scrollyTarget - scrollyOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime));
+
+		// This is an attempt to ensure that we always reach the scroll
+		// target. Otherwise the game frequently tries to pump out new
+		// interpolation frames without ever getting anywhere.
+
+		if (ABS(scrollx - scrollxTarget) <= 1 && ABS(scrolly - scrollyTarget) <= 1) {
+			scrollx = scrollxTarget;
+			scrolly = scrollyTarget;
+		} else {
+			scrollx = (int16) (scrollxOld + ((scrollxTarget - scrollxOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime));
+			scrolly = (int16) (scrollyOld + ((scrollyTarget - scrollyOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime));
+		}
 	}
 
 	return RD_OK;
@@ -1057,9 +1090,8 @@
 }
 
 int32 CopyScreenBuffer(void) {
-	// FIXME: This function no longer seems needed. Calling copy_rect()
-	// for the whole screen is slower than the current approach. Not by
-	// much, but still...
+	// FIXME: This function no longer seems to be needed. We copy the
+	// back buffer to the screen in ServiceWindows() instead.
 	return RD_OK;
 }
 
@@ -1207,6 +1239,6 @@
 
 int32 EraseSoftwareScreenBuffer(void)
 {
-	memset(myScreenBuffer, 0, RENDERWIDE * RENDERDEEP);
+	// memset(myScreenBuffer, 0, RENDERWIDE * RENDERDEEP);
 	return(RD_OK);
 }

Index: sprite.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/bs2/driver/sprite.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- sprite.cpp	28 Aug 2003 06:36:15 -0000	1.12
+++ sprite.cpp	29 Aug 2003 06:42:34 -0000	1.13
@@ -265,6 +265,7 @@
 #include "render.h"
 #include "menu.h"
 #include "palette.h"
+#include "rdwin.h"
 
 
 #if PROFILING == 1
@@ -1330,6 +1331,8 @@
 		free(sprite);
 
 	// UploadRect(&rd);
+	SetNeedRedraw();
+
 	return 0;
 }
 
@@ -1621,6 +1624,7 @@
 		free(sprite);
 
 	// UploadRect(&rd);
+	SetNeedRedraw();
 
 /*
 





More information about the Scummvm-git-logs mailing list