changeset 21:f2287962b4b7

- use portable timing method - enable vsync by default
author Extrawurst
date Thu, 09 Dec 2010 22:23:20 +0100
parents f897d96cc7c9
children ed2c81f3d1df
files trunk/tests/ChipmunkDemos/gameApp.d
diffstat 1 files changed, 29 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/tests/ChipmunkDemos/gameApp.d	Thu Dec 09 22:20:50 2010 +0100
+++ b/trunk/tests/ChipmunkDemos/gameApp.d	Thu Dec 09 22:23:20 2010 +0100
@@ -1,3 +1,6 @@
+
+// written in the D programming language
+
 /++
  +	Authors: Stephan Dilly, www.extrawurst.org
  +/
@@ -31,20 +34,25 @@
 import samples.TheoJansen;
 import samples.UnsafeOps;
 
+// using derelict bindings for sdl/opengl
 import derelict.opengl.gl;
 import derelict.opengl.glu;
 import derelict.sdl.sdl;
 
 import std.stdio;
-import core.thread:Sleep;
+import core.thread;
 
-extern(System) ulong GetTickCount();
-
-version = TIME_TRIAL;
+//version = TIME_TRIAL;
 
 cpVect			mousePos;
 cpVect			arrowDirection;
 
+bool key_up = false;
+bool key_down = false;
+bool key_left = false;
+bool key_right = false;
+bool key_space = false;
+
 ///
 final class GameApp {
 
@@ -58,11 +66,6 @@
 	cpConstraint*	mouseJoint;
 	cpVect			mousePos_last;
 	
-	bool key_up = false;
-	bool key_down = false;
-	bool key_left = false;
-	bool key_right = false;
-	
 	bool 	m_running = true;
 	
 	drawSpaceOptions options = {
@@ -79,23 +82,25 @@
 	
 version(TIME_TRIAL)
 {
-	void time_trial(int index, int count)
+	ulong time_trial(int index, int count)
 	{
 		currentDemo = demos[index];
 		space = currentDemo.initFunc();
 		
-		auto start = .GetTickCount();
+		auto start = .tickCount();
 		
 		foreach(i; 0..count)
 			currentDemo.updateFunc(i);
 		
-		auto end = .GetTickCount();
+		auto end = .tickCount();
 		auto duration = (end - start);
 		
 		currentDemo.destroyFunc();
 		currentDemo = null;
 		
 		writefln("Time(%s) = %s", cast(char)(index + 'a'), duration);
+		
+		return duration;
 	}
 }
 
@@ -130,26 +135,29 @@
 		
 version(TIME_TRIAL)
 {
-		Sleep(1);
+		Thread.sleep(1_000_000); //1s
+		ulong duration;
 		foreach(i; 0..demos.length)
 		{
-			//if(i == 'l' - 'a') continue;
-			time_trial(i, 1000);
+			if(i == 'l'-'a') continue;
+			duration+=time_trial(i, 1000);
 		}
 	
+		writefln("Time accum = %s", duration);
+	
 		m_running = false;
 		
 		return;
 }//TIME_TRIAL
 		
 		//setup framework
-		framework.startup("chipmunk'd by Stephan Dilly",width,height);
+		framework.startup("chipmunk'd by Stephan Dilly",width,height,false);
 
 		reshape(width,height);
 				
 		glEnableClientState(GL_VERTEX_ARRAY);
 		
-		runDemo(demos[0]);
+		runDemo(&LogoSmash);
 		
 		mouseBody = cpBodyNew(INFINITY, INFINITY);
 	}
@@ -297,6 +305,8 @@
 				options.drawHash = !options.drawHash;
 			} else if(key == 92){
 				options.drawBBs = !options.drawBBs;
+			} else if(key == 27){
+				m_running = false;
 			} else if(key == 93){
 				glEnable(GL_LINE_SMOOTH);
 				glEnable(GL_POINT_SMOOTH);
@@ -311,6 +321,7 @@
 				else if(key == SDLK_DOWN) key_down = true;
 				else if(key == SDLK_LEFT) key_left = true;
 				else if(key == SDLK_RIGHT) key_right = true;
+				else if(key == SDLK_SPACE) key_space = true;
 	
 				set_arrowDirection();
 			}
@@ -321,6 +332,7 @@
 			else if(key == SDLK_DOWN) key_down = false;
 			else if(key == SDLK_LEFT) key_left = false;
 			else if(key == SDLK_RIGHT) key_right = false;
+			else if(key == SDLK_SPACE) key_space = false;
 			
 			set_arrowDirection();
 		}