Index: /GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp	(revision 724)
+++ /GTP/trunk/App/Demos/Vis/Teapots/RenderTraverser.cpp	(revision 937)
@@ -141,8 +141,8 @@
 
 	//-- PART 1: process finished occlusion queries
-	while(!mDistanceQueue.empty() || !queryQueue.empty())
-	{
-		while(!queryQueue.empty() && 
-			  (ResultAvailable(queryQueue.front()) || mDistanceQueue.empty()))
+	while (!mDistanceQueue.empty() || !queryQueue.empty())
+	{
+		while (!queryQueue.empty() && 
+			   (ResultAvailable(queryQueue.front()) || mDistanceQueue.empty()))
 		{
 			HierarchyNode *node = queryQueue.front();
@@ -164,5 +164,5 @@
 
 		//-- PART 2: hierarchical traversal
-		if(! mDistanceQueue.empty())
+		if (!mDistanceQueue.empty())
 		{
 			HierarchyNode *node = mDistanceQueue.top();
@@ -174,5 +174,5 @@
 			bool intersects;
 			
-			if(InsideViewFrustum(node, intersects))
+			if (InsideViewFrustum(node, intersects))
 			{
 				// for near plane intersecting bounding box possible 
Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrain.vcproj
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrain.vcproj	(revision 866)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrain.vcproj	(revision 937)
@@ -85,5 +85,5 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="OGREMain.LIB CEGUIBase.lib OgreGUIRenderer.lib Plugin_OctreeSceneManager.lib Plugin_VisibilitySceneManager.lib IVReader.lib"
+				AdditionalDependencies="OGREMain.LIB CEGUIBase.lib OgreGUIRenderer.lib Plugin_OctreeSceneManager.lib Plugin_VisibilitySceneManager.lib IVReader.lib zdll.lib zziplib.lib"
 				OutputFile="$(OGRE_PATH)/Samples/Common/bin/Release/TestCullingTerrain.exe"
 				LinkIncremental="1"
Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp	(revision 932)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp	(revision 937)
@@ -7,5 +7,4 @@
 #include "TerrainFrameListener.h"
 #include "OgrePlatformQueryManager.h"
-#include "OgreVisibilityTerrainSceneManager.h"
 #include "VisibilityInfo.h"
 #include "OgreOcclusionQueriesQueryManager.h"
@@ -68,5 +67,5 @@
 	"robot",
 	"athene",
-	//"natFX_Tree1_LOD2",
+	"natFX_Tree1_LOD2",
 	//"tree2",
 	//"HongKong_Tower",
@@ -161,4 +160,5 @@
 mVizScale(25),
 mUseViewCells(false),
+mViewCellsLoaded(false),
 mUseVisibilityFilter(false)
 {
@@ -1164,5 +1164,16 @@
 void TerrainFrameListener::toggleUseViewCells()
 {
+	// HACK: no view cells for hilly terrain
+	if (mApplication->msShowHillyTerrain)
+		return;
+
 	mUseViewCells = !mUseViewCells;
+
+	// load on demand
+	if (mUseViewCells && !mViewCellsLoaded)
+	{
+		mViewCellsLoaded = mApplication->LoadViewCells(mApplication->mViewCellsFilename);
+	}
+
 	mSceneMgr->setOption("UseViewCells", &mUseViewCells);
 }
@@ -1372,8 +1383,10 @@
 		break;
 	case KC_8:
-		changeAssumedVisibility(-1);
+	//	changeAssumedVisibility(-5);
+		changeAssumedVisibility(-500);
 		break;
 	case KC_9:
-		changeAssumedVisibility(1);
+		changeAssumedVisibility(500);
+		//changeAssumedVisibility(5);
 		break;
 	case KC_LSHIFT:
Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp	(revision 932)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp	(revision 937)
@@ -7,10 +7,6 @@
 #include <OgreIteratorWrappers.h>
 #include <Ogre.h>
-#include <direct.h> // for getcwd
-//#include "OgreReferenceAppLayer.h"
-//#include "OgreRefAppWorld.h"
 #include "TestCullingTerrainApplication.h"
 #include "TerrainFrameListener.h"
-//#include "OgreOcclusionCullingSceneManager.h"
 
 #include "IVReader.h"
@@ -161,5 +157,7 @@
 mTerrainContentGenerator(NULL), 
 mRayQueryExecutor(NULL),
-mIVReader(NULL)
+mIVReader(NULL),
+mFilename("terrain"),
+mEnvironmentFilename("simple.env")
 {
 }
@@ -174,5 +172,5 @@
 	config.load(filename);
 
-	std::stringstream d; d << "reading config from: " << filename;
+	std::stringstream d; d << "reading the config file from: " << filename;
 	LogManager::getSingleton().logMessage(d.str());
 
@@ -182,15 +180,26 @@
 	{
 		 mFilename = val.c_str();
-
-		 std::stringstream d; d << "filename: " << mFilename;
+		 d << "\nloading scene from file: " << mFilename;
 		 LogManager::getSingleton().logMessage(d.str());
 	}
 
-/*	val = config.getSetting("ViewCells");
+	
+#if 0
+	val = config.getSetting("ViewCells");
 
 	if (!val.empty())
 	{
 		 mViewCellsFilename = val.c_str();
-	}*/
+	}
+#endif
+
+	val = config.getSetting("VisibilityEnvironment");
+
+	if (!val.empty())
+	{
+		 mEnvironmentFilename = val.c_str();
+		 std::stringstream d; d << "loading environment from from file: " << mEnvironmentFilename;
+		 LogManager::getSingleton().logMessage(d.str());
+	}
 
 	Vector3 v = Vector3::UNIT_SCALE;
@@ -211,4 +220,38 @@
 		v.z = atof( val.c_str());
 
+
+	/////////////////////////
+	// setup scene
+
+	//-- load the scene from specified file
+	if (!LoadScene(mFilename))
+		LogManager::getSingleton().logMessage("error loading scene");
+
+
+	GtpVisibility::VisibilityManager *mVisManager = NULL;
+
+	//-- load the environment from file
+	if (mSceneMgr->getOption("VisibilityManager", &mVisManager))
+	{
+		GtpVisibility::VisibilityEnvironment *visEnv = mVisManager->GetVisibilityEnvironment();
+		
+		if (!visEnv->LoadEnvironment(mEnvironmentFilename))
+		{
+			std::stringstream d; d << "failed loading environment from " << mEnvironmentFilename;
+			LogManager::getSingleton().logMessage(d.str());
+		}
+		else //-- load environment options
+		{
+			//-- get view cells name. load only on demand
+			mViewCellsFilename = visEnv->getViewCellsFileName();
+
+			std::stringstream d; d << "view cells file name: " << mViewCellsFilename;
+			LogManager::getSingleton().logMessage(d.str());
+		}
+	}
+	else
+	{
+		LogManager::getSingleton().logMessage("error! no visibility scenemanager available");
+	}
 	// set camera position accordingly
 	mCamNode->setPosition(v);
@@ -358,13 +401,6 @@
 {
 	//-- load scene
-
-	//GtpVisibility::VisibilityManager *mVisManager;
-	//if (!mSceneMgr->getOption("VisibilityManager", mVisManager))	return;
-	//const std::string filename = visEnv->getSceneFilename();
-	loadConfig("test.cfg");
-	LoadScene(mFilename);
-
-
-
+	loadConfig("terrainCulling.cfg");
+	
 	/////////////////////////////////////
 
@@ -455,19 +491,8 @@
 	{
 		// the objects are generated randomly distributed over the terrain
-		if (1) generateScene(500, 0); // create robots
+		if (1) generateScene(1500, 0); // create robots
 		if (0) generateScene(100, 1); // create trees
 		if (0) generateScene(100, 2); // create ninjas
 	}
-
-
-
-	//-- HACK: load the view cells from the disc
-	
-	//std::string filename = "vienna_simple-21-04-avs2-viewCells.xml";
-	//std::string filename = "vienna_simple-21-04-kdcasm-viewCells.xml";
-	std::string filename = "vienna_simple-21-04-avs-viewCells.xml";
-
-	//-- the actual loading happens here
-	if (0) mSceneMgr->setOption("LoadViewCells", filename.c_str());
 }
 //-----------------------------------------------------------------------
@@ -658,5 +683,5 @@
 
 //-----------------------------------------------------------------------
-bool TestCullingTerrainApplication::LoadScene(const std::string filename)
+bool TestCullingTerrainApplication::LoadScene(const String &filename)
 {
 	using namespace std;
@@ -716,8 +741,15 @@
 }
 //-----------------------------------------------------------------------
-bool TestCullingTerrainApplication::LoadViewCells(const std::string filename)
-{
-
-	return true;
+bool TestCullingTerrainApplication::LoadViewCells(const String &filename)
+{
+	LogManager::getSingleton().logMessage("loading view cells");
+
+	//-- the actual loading happens here
+	if (mSceneMgr->setOption("LoadViewCells", filename.c_str()))
+    	return true;
+
+	LogManager::getSingleton().logMessage("error loading view cells!!");
+
+	return false;
 }
 
Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.h	(revision 915)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.h	(revision 937)
@@ -430,5 +430,5 @@
 	
 	bool mUseViewCells;
-
+	bool mViewCellsLoaded;
 	bool mUseVisibilityFilter;
 };
Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h	(revision 932)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h	(revision 937)
@@ -128,7 +128,7 @@
 	bool LoadSceneIV(const String &filename, SceneNode *root, const int index);
 
-	bool LoadScene(const std::string filename);
+	bool LoadScene(const String &filename);
 
-	bool LoadViewCells(const std::string filename);
+	bool LoadViewCells(const String &filename);
 
 	/** Loads configuration from disc.
@@ -138,4 +138,10 @@
 	/// if hilly terrain should be loaded
 	static bool msShowHillyTerrain;
+
+
+	String mFilename;
+	String mViewCellsFilename;
+	// name of the visibility environment file
+	String mEnvironmentFilename;
 
 protected:
@@ -185,6 +191,5 @@
 	StaticGeometry *mStaticGeometry;
 
-	String mFilename;
-	//String mViewCellsFilename;
+	
 
 private:
