Index: GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h
===================================================================
--- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h	(revision 1220)
+++ GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h	(revision 1250)
@@ -114,5 +114,6 @@
 		mBuildMethod(KdTree::KDBM_PRIORITYQUEUE),
 		mDemoMode(false),
-		mEnhancedVisibility(false)
+		mEnhancedVisibility(false),
+		mDemoInterval(1.0f)
 		{
 
@@ -134,5 +135,14 @@
 		bool mDemoMode;
 		bool mEnhancedVisibility;
-	};
+		Real mDemoInterval;
+	};
+
+	struct DemoStats
+	{
+		unsigned int mTotalNumFrames;
+		unsigned int mNumFrames;
+		Real mTotalEllapsedTime;
+		Real mEllapsedTime;
+	} mDemoStats;
 
     // Constructor takes a RenderWindow because it uses that to determine input context
Index: GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp	(revision 1220)
+++ GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp	(revision 1250)
@@ -37,5 +37,6 @@
 				.addOpt("s","scenemgr", ARGUMENT_REQUIRED)
 				.addOpt("","comment", ARGUMENT_REQUIRED)
-				.addOpt("e","enhancevis", ARGUMENT_NONE);
+				.addOpt("e","enhancevis", ARGUMENT_NONE)
+				.addOpt("","logint",ARGUMENT_REQUIRED);
 
 
@@ -87,4 +88,11 @@
 				s << tmp;
 				s >> options.mKI;
+				s.clear();
+			}
+
+			if (cmdparser.getOpt("logint", tmp))
+			{
+				s << tmp;
+				s >> options.mDemoInterval;
 				s.clear();
 			}
@@ -417,5 +425,5 @@
 		KdTreeAppListener::SCENEMANAGERNAME[mOptions.mSceneManager],
 		"MySceneManager");
-	// set params depending on scene manager
+	// set params for kdtree scene manager
 	if (mOptions.mSceneManager == KdTreeAppListener::SM_KDT)
 	{
@@ -426,7 +434,10 @@
 		mSceneMgr->setOption("RenderMethod", &mOptions.mRenderMethod);
 		mSceneMgr->setOption("EnhancedVisibility", &mOptions.mEnhancedVisibility);
+		// fix
+		bool depthpass = false;
+		mSceneMgr->setOption("UseDepthPass", &depthpass);
 	}
 	// set algorithm when scene manager is OCM - numbering is different though
-	if (mOptions.mSceneManager == KdTreeAppListener::SM_OCM)
+	else if (mOptions.mSceneManager == KdTreeAppListener::SM_OCM)
 	{
 		int alg = CONV_KDT_TO_OCM_ALG(mOptions.mRenderMethod);
Index: GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp	(revision 1220)
+++ GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp	(revision 1250)
@@ -131,5 +131,5 @@
 mTimeUntilNextToggle(0.0f),
 // stuff for walkthrough recording/playback
-mTimeUntilNextLogWrite(0.0f),
+mTimeUntilNextLogWrite(options.mDemoInterval),
 mTimeRemaining(0.0f),
 mWaitBeforeDemoStart(0.0f),
@@ -1063,4 +1063,10 @@
 		mTimeRemaining -= evt.timeSinceLastFrame;
 
+		// update stats
+		++ mDemoStats.mNumFrames;
+		++ mDemoStats.mTotalNumFrames;
+		mDemoStats.mEllapsedTime += evt.timeSinceLastFrame;
+		mDemoStats.mTotalEllapsedTime += evt.timeSinceLastFrame;
+
 		// store fps when in demo mode
 		if (mOptions.mDemoMode)
@@ -1070,7 +1076,10 @@
 			if (mTimeUntilNextLogWrite <= 0.0)
 			{
-				const RenderTarget::FrameStats& stats = mWindow->getStatistics();
-				mTimeUntilNextLogWrite += 1.0;
-				mDemoFPS.push_back(stats.lastFPS);
+				mTimeUntilNextLogWrite += mOptions.mDemoInterval;
+				//const RenderTarget::FrameStats& stats = mWindow->getStatistics();
+				//mDemoFPS.push_back(stats.lastFPS);
+				mDemoFPS.push_back(mDemoStats.mNumFrames / mDemoStats.mEllapsedTime);
+				mDemoStats.mNumFrames = 0;
+				mDemoStats.mEllapsedTime = 0.0f;
 			}
 		}
@@ -1256,4 +1265,10 @@
 		mCurrFrame = mFrameList.begin();
 		mTimeRemaining = mCurrFrame->mElapsedTime;
+
+		// reset stats
+		mDemoStats.mNumFrames = 0;
+		mDemoStats.mTotalNumFrames = 0;
+		mDemoStats.mEllapsedTime = 0.0f;
+		mDemoStats.mTotalEllapsedTime = 0.0f;
 	}
 	// stop playback
@@ -1452,5 +1467,7 @@
 	// stats
 	Real minFPS = Math::POS_INFINITY, maxFPS = 0.0, avgFPS = 0.0;
-	String demofile;
+	String line, storedname;
+	String demopath, demoname;
+	StringUtil::splitFilename(mOptions.mDemoInfileName, demoname, demopath);
 	
 	// check if logfile exists
@@ -1458,12 +1475,13 @@
 	if (logread.is_open())
 	{
-		// read first item, it's the name of the demo
+		// read first line, shuold start with the name of the demo
 		// if matches, OK, otherwise do something
-		logread >> demofile;
-		if (!StringUtil::startsWith(demofile, mOptions.mDemoInfileName))
+		logread >> line;
+		storedname = line.substr(0,line.find_first_of(','));
+		if (storedname != demoname)
 		{
 			LogManager::getSingleton().logMessage(
 				"##Error##: Saved demo stats do not match the current demo: " +
-				demofile + " != " + mOptions.mDemoInfileName);
+				storedname + " != " + demoname);
 			logread.close();
 			return;
@@ -1477,5 +1495,5 @@
 		{
 			// demo title
-			logheader << mOptions.mDemoInfileName << fs;
+			logheader << demoname << fs;
 			// seconds
 			for (size_t i = 0; i < mDemoFPS.size(); i ++)
@@ -1484,5 +1502,6 @@
 			}
 			// minFPS, avgFPS, maxFPS, comment, record separator
-			logheader << "min FPS" << fs << "avg FPS" << fs << "max FPS" << fs << "Comment" << rs;
+			logheader << "\"min FPS\"" << fs << "\"avg FPS\"" << fs << "\"max FPS\"" << fs 
+				<< "\"# Frames \"" << fs << "\"Total Time\"" << fs << "\"Comment\"" << rs;
 			logheader.close();
 		}
@@ -1502,5 +1521,5 @@
 	{
 		// demo settings
-		logwrite << SCENEMANAGER[mOptions.mSceneManager];
+		logwrite << "\"" << SCENEMANAGER[mOptions.mSceneManager];
 		if (mOptions.mSceneManager == SM_KDT)
 		{
@@ -1512,5 +1531,5 @@
 			logwrite << ds << RENDERMETHOD[(mOptions.mRenderMethod+3)%3];
 		}
-		logwrite << fs;
+		logwrite << "\"" << fs;
 		// per second stats
 		for (std::list<Real>::iterator it = mDemoFPS.begin(); it != mDemoFPS.end(); it ++)
@@ -1522,12 +1541,15 @@
 				maxFPS = *it;
 
-			avgFPS += *it;
+			//avgFPS += *it;
 
 			logwrite << (int)(*it) << fs;
 
 		}
-		avgFPS /= mDemoFPS.size();
+		//avgFPS /= mDemoFPS.size();
+		avgFPS = mDemoStats.mTotalNumFrames / mDemoStats.mTotalEllapsedTime;
 		// minFPS, avgFPS, maxFPS, comment, record separator
-		logwrite << (int)minFPS << fs << (int)avgFPS << fs << (int)maxFPS << fs << mOptions.mComment << rs;
+		logwrite << (int)minFPS << fs << (int)avgFPS << fs << (int)maxFPS << fs 
+			<< mDemoStats.mTotalNumFrames << fs << mDemoStats.mTotalEllapsedTime << fs 
+			<< "\"" << mOptions.mComment << "\"" << rs;
 		logwrite.close();
 	}
