Maelstrom: Fixed the speed test (don't sync to vertical refresh during speed tests) :)

From 798c2c6be6a3eb0cc5843f51ad2ce4aa1b5a11a9 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 22 Oct 2011 03:21:28 -0400
Subject: [PATCH] Fixed the speed test (don't sync to vertical refresh during
 speed tests) :)

---
 init.cpp                   |  4 ++--
 main.cpp                   | 27 ++++++++++++---------------
 screenlib/SDL_FrameBuf.cpp |  6 +++---
 screenlib/SDL_FrameBuf.h   |  2 +-
 4 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/init.cpp b/init.cpp
index d3557b5c..c7a67c23 100644
--- a/init.cpp
+++ b/init.cpp
@@ -713,7 +713,7 @@ void CleanUp(void)
 
 /* ----------------------------------------------------------------- */
 /* -- Perform some initializations and report failure if we choke */
-int DoInitializations(Uint32 video_flags)
+int DoInitializations(Uint32 window_flags, Uint32 render_flags)
 {
 	int i;
 	SDL_Surface *icon;
@@ -755,7 +755,7 @@ int DoInitializations(Uint32 video_flags)
 
 	/* Initialize the screen */
 	screen = new FrameBuf;
-	if (screen->Init(SCREEN_WIDTH, SCREEN_HEIGHT, video_flags,
+	if (screen->Init(SCREEN_WIDTH, SCREEN_HEIGHT, window_flags, render_flags,
 					colors[gGammaCorrect], icon) < 0){
 		error("Fatal: %s\n", screen->Error());
 		return(-1);
diff --git a/main.cpp b/main.cpp
index 10465ef7..14851f28 100644
--- a/main.cpp
+++ b/main.cpp
@@ -17,7 +17,7 @@
 #include "checksum.h"
 
 /* External functions used in this file */
-extern int DoInitializations(Uint32 video_flags);		/* init.cpp */
+extern int DoInitializations(Uint32 window_flags, Uint32 render_flags);	/* init.cpp */
 extern void CleanUp(void);
 
 static const char *Version =
@@ -125,21 +125,16 @@ static void RunSpeedTest(void)
 	Uint32 then, now;
 	int i, frame, x=((640/2)-16), y=((480/2)-16), onscreen=0;
 
-	screen->Clear();
 	then = SDL_GetTicks();
 	for ( i=0; i<test_reps; ++i ) {
 		for ( frame=0; frame<SHIP_FRAMES; ++frame ) {
-			if ( onscreen ) {
-				screen->Clear(x, y, 32, 32);
-			} else {
-				onscreen = 1;
-			}
+			screen->Clear();
 			screen->QueueBlit(x, y, gPlayerShip->sprite[frame]);
 			screen->Update();
 		}
 	}
 	now = SDL_GetTicks();
-	mesg("Graphics speed test took %d microseconds per cycle.\r\n",
+	mesg("Graphics speed test took %d milliseconds per cycle.\r\n",
 						((now-then)/test_reps));
 }
 
@@ -172,7 +167,8 @@ int main(int argc, char *argv[])
 	/* Command line flags */
 	int doprinthigh = 0;
 	int speedtest = 0;
-	Uint32 video_flags = 0;
+	Uint32 window_flags = 0;
+	Uint32 render_flags = SDL_RENDERER_PRESENTVSYNC;
 
 	/* Normal variables */
 	SDL_Event event;
@@ -208,14 +204,14 @@ int main(int argc, char *argv[])
 
 	/* Parse command line arguments */
 #ifdef __MACOSX__
-	//video_flags |= SDL_WINDOW_FULLSCREEN;
+	//window_flags |= SDL_WINDOW_FULLSCREEN;
 #endif
 	for ( progname=argv[0]; --argc; ++argv ) {
 		if ( strcmp(argv[1], "-fullscreen") == 0 ) {
-			video_flags |= SDL_WINDOW_FULLSCREEN;
+			window_flags |= SDL_WINDOW_FULLSCREEN;
 		} else
 		if ( strcmp(argv[1], "-windowed") == 0 ) {
-			video_flags &= ~SDL_WINDOW_FULLSCREEN;
+			window_flags &= ~SDL_WINDOW_FULLSCREEN;
 		} else
 		if ( strcmp(argv[1], "-gamma") == 0 ) {
 			int gammacorrect;
@@ -269,9 +265,10 @@ int main(int argc, char *argv[])
 			doprinthigh = 1;
 		else if ( strcmp(argv[1], "-netscores") == 0 )
 			gNetScores = 1;
-		else if ( strcmp(argv[1], "-speedtest") == 0 )
+		else if ( strcmp(argv[1], "-speedtest") == 0 ) {
 			speedtest = 1;
-		else if ( LogicParseArgs(&argv, &argc) == 0 ) {
+			render_flags &= ~SDL_RENDERER_PRESENTVSYNC;
+		} else if ( LogicParseArgs(&argv, &argc) == 0 ) {
 			/* LogicParseArgs() took care of everything */;
 		} else if ( strcmp(argv[1], "-version") == 0 ) {
 			error("%s", Version);
@@ -292,7 +289,7 @@ int main(int argc, char *argv[])
 		exit(1);
 
 	/* Initialize everything. :) */
-	if ( DoInitializations(video_flags) < 0 ) {
+	if ( DoInitializations(window_flags, render_flags) < 0 ) {
 		/* An error message was already printed */
 		exit(1);
 	}
diff --git a/screenlib/SDL_FrameBuf.cpp b/screenlib/SDL_FrameBuf.cpp
index e10b2443..b45d1206 100644
--- a/screenlib/SDL_FrameBuf.cpp
+++ b/screenlib/SDL_FrameBuf.cpp
@@ -45,17 +45,17 @@ FrameBuf:: FrameBuf()
 }
 
 int
-FrameBuf:: Init(int width, int height, Uint32 flags,
+FrameBuf:: Init(int width, int height, Uint32 window_flags, Uint32 render_flags,
 		SDL_Color *colors, SDL_Surface *icon)
 {
-	window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
+	window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags);
 	if (!window) {
 		SetError("Couldn't create %dx%d window: %s", 
 					width, height, SDL_GetError());
 		return(-1);
 	}
 
-	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
+	renderer = SDL_CreateRenderer(window, -1, render_flags);
 	if (!renderer) {
 		SetError("Couldn't create renderer: %s", SDL_GetError());
 		return(-1);
diff --git a/screenlib/SDL_FrameBuf.h b/screenlib/SDL_FrameBuf.h
index 77a7e158..b2432435 100644
--- a/screenlib/SDL_FrameBuf.h
+++ b/screenlib/SDL_FrameBuf.h
@@ -46,7 +46,7 @@ class FrameBuf {
 
 public:
 	FrameBuf();
-	int Init(int width, int height, Uint32 flags,
+	int Init(int width, int height, Uint32 window_flags, Uint32 render_flags,
 			SDL_Color *colors = NULL, SDL_Surface *icon = NULL);
 	~FrameBuf();