ccdemos/realtime_bunny.cc
branchpyrit
changeset 37 5f954c0d34fc
parent 36 b490093b0ac3
child 38 5d043eeb09d9
--- a/ccdemos/realtime_bunny.cc	Thu Dec 13 00:08:11 2007 +0100
+++ b/ccdemos/realtime_bunny.cc	Fri Dec 14 00:05:54 2007 +0100
@@ -13,6 +13,9 @@
 Raytracer rt;
 Camera cam;
 
+Uint32 fp10s_acc = 0;
+Uint32 fp10s_acc_samples = 0;
+
 void load_ply(const char *filename, Material *mat, Float scale)
 {
 	vector<NormalVertex*> vertices;
@@ -81,7 +84,7 @@
 		f.ignore(1000,'\n');
 	}
 
-	for (int i; i < vertex_num; i++)
+	for (int i = 0; i < vertex_num; i++)
 	{
 		normals.at(i) /= vertex_face_num.at(i);
 		normals.at(i).normalize();
@@ -93,6 +96,18 @@
 
 void update(SDL_Surface *screen)
 {
+	static Uint32 t = 0;
+	Uint32 tnow = SDL_GetTicks();
+	int fp10s = 10000/(int)(tnow - t);
+	if (t != 0)
+	{
+		fp10s_acc += fp10s;
+		++fp10s_acc_samples;
+	}
+	t = tnow;
+	printf("\b\b\b\b\b\b\b\b\b%3d.%1d fps", fp10s/10, fp10s%10);
+	fflush(stdout);
+
 	rt.render(w, h, render_buffer);
 
 	if (SDL_MUSTLOCK(screen))
@@ -123,6 +138,13 @@
 		SDL_UpdateRect(screen, 0, 0, w, h);
 }
 
+void quit()
+{
+	Uint32 fp100s_aver = fp10s_acc*10/fp10s_acc_samples;
+	printf("\naverlage fps: %3d.%2d\n", fp100s_aver/100, fp100s_aver%100);
+	SDL_Quit();
+}
+
 int main()
 {
 	/* initialize SDL */
@@ -133,7 +155,7 @@
 		exit(1);
 	}
 
-	atexit(SDL_Quit);
+	atexit(quit);
 
 	screen = SDL_SetVideoMode(w, h, 32, SDL_SWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE);
 	if ( screen == NULL ) {
@@ -142,6 +164,7 @@
 	}
 
 	/* initialize raytracer and prepare scene */
+	pyrit_verbosity = 0;
 	render_buffer = (Float *) malloc(w*h*3*sizeof(Float));
 
 	rt.setThreads(2);