Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/CoherentHierarchicalCullingPlusPlusManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/CoherentHierarchicalCullingPlusPlusManager.h	(revision 2555)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/include/CoherentHierarchicalCullingPlusPlusManager.h	(revision 2557)
@@ -66,4 +66,6 @@
 	inline void IssueQuery(HierarchyNode *node, const bool testGeometry);
 
+	//void IssueOptimalBatches(QueryHeap &nodes);
+
 
 	//////////////////////
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingPlusPlusManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingPlusPlusManager.cpp	(revision 2556)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingPlusPlusManager.cpp	(revision 2557)
@@ -52,11 +52,4 @@
 		//////////
 		//-- only wait for result if there are no nodes to process
-#if 0
-		bool resultAvailable = true;
-		while (!mQueryQueue.empty() && 
-			   (NodeInvalid(mQueryQueue.front().first) ||
-			    mQueryQueue.front().second->GetQueryResult(
-				             visiblePixels, mHierarchyInterface->GetQueue()->empty())))
-#else
 		bool resultAvailable = false;
 
@@ -67,5 +60,4 @@
 			   (resultAvailable = mQueryQueue.front().second->GetQueryResult(visiblePixels, false)))
 			   )
-#endif
 		{
 			HierarchyNode *node = mQueryQueue.front().first;
@@ -75,5 +67,5 @@
 			if (NodeInvalid(node)) {mQueryQueue.pop(); continue;}
 
-			// during the wait time issue nodes from visible queue
+			// during the wait time we issue nodes from visible queue
 			while (1 && !mVisibleNodes.empty() && !resultAvailable)
 			{
@@ -114,5 +106,5 @@
 				if (mVisualizeCulledNodes)
 					mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED);
-				}
+			}
 			
 			// update node's visited flag
@@ -221,5 +213,6 @@
 
         // issue rest of nodes from nodes from visible queue
-		if (0 && mHierarchyInterface->GetQueue()->empty() && mQueryQueue.empty() && !mVisibleNodes.empty())
+		if (0 && 
+			mHierarchyInterface->GetQueue()->empty() && mQueryQueue.empty() && !mVisibleNodes.empty())
 		{
 			while (!mVisibleNodes.empty())
@@ -230,14 +223,6 @@
 		}
 	}
-
-
-	if (0 && !mVisibleNodes.empty())
-	{
-		std::stringstream d;
-		d << "queries: " << (int)mQueryQueue.size() << " vis: " << (int)mVisibleNodes.size() << " inv: " << (int)mInvisibleNodes.size();
-		CullingLogManager::GetSingleton()->LogMessage(d.str());
-	}
 	
-    // render rest
+    // render what is left in the render queue
 	mHierarchyInterface->RenderQueue();
 
@@ -279,11 +264,4 @@
 		mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());	
 	}
-
-	if (0)
-	{
-		std::stringstream d;
-		d << "tested: " << i << " nodes";
-		CullingLogManager::GetSingleton()->LogMessage(d.str());
-	}
 }
 //-----------------------------------------------------------------------
@@ -357,4 +335,50 @@
 	nodes.clear();
 }
+//-----------------------------------------------------------------------
+#if 0
+void CoherentHierarchicalCullingPlusPlusManager::IssueOptimalBatches(QueryHeap &nodes)
+{
+	while (!nodes.Empty())
+	{	
+		QueryQueueEntry *entry = GetNextQueryQueueEntry();
+		entry->mIsVisibleQuery = false;
+	
+		float pFail = 1.0f; 
+		float maxBatchVal = 0.0f;
+		float newPBatch = 1.0f;
+		float newBatchVal;
 		
-}
+		// issue next query
+		while (!nodes.Empty())
+		{
+			HierarchyNode *node = nodes.Top();
+	
+			newPBatch *= mNodePredictor.GetProbability(node);
+
+			if (entry->mNodes.empty())
+				newBatchVal = 1.0f;
+			else
+			{
+				const float newSize = float(entry->mNodes.size() + 1);
+				newBatchVal = newSize / (1.0f + (1.0f - newPBatch) * newSize);
+			}
+
+			if (newBatchVal <= maxBatchVal)
+				break;
+
+			pFail = entry->mNodes.empty() ? 0.0f : (1.0f - newPBatch);
+
+			nodes.Pop();
+			entry->AddNode(node);
+
+			maxBatchVal = newBatchVal;
+		}
+
+		entry->mPFail = pFail;
+
+		IssueQuery(*entry, false);
+		mQueries.push(entry);
+	}
+}
+#endif
+}
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityPredictor.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityPredictor.h	(revision 2557)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityPredictor.h	(revision 2557)
@@ -0,0 +1,31 @@
+#ifndef _OGREVISIBILITYPREDICTOR_H__
+#define _OGREVISIBILITYPREDICTOR_H__
+
+#include <Ogre.h>
+#include "ViewCellsManager.h"
+#include "HierarchyInterface.h"
+
+
+namespace Ogre {
+ 
+/** Visibility predictor
+*/
+
+class __declspec(dllexport) VisibilityPredictor
+{
+public:
+    
+	void HandleProbablyVisibleObjects(GtpVisibilityPreprocessor::ViewCell *vc);
+	void UpdateVisibility(GtpVisibilityPreprocessor::ViewCell *vc);
+
+	VisibilityPredictor();
+
+protected:
+
+	GtpVisibility::HierarchyNodeContainer mNodeBuffer;
+};
+
+
+} // namespace Ogre
+
+#endif // VisibilityPredictor
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 2532)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 2557)
@@ -525,4 +525,7 @@
 			</File>
 			<File
+				RelativePath="..\include\OgreVisibilityPredictor.h">
+			</File>
+			<File
 				RelativePath="..\include\VisibilityMesh.h">
 			</File>
@@ -563,4 +566,7 @@
 			<File
 				RelativePath="..\src\OgreVisibilityOptionsManager.cpp">
+			</File>
+			<File
+				RelativePath=".\OgreVisibilityPredictor.cpp">
 			</File>
 			<File
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityPredictor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityPredictor.cpp	(revision 2557)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityPredictor.cpp	(revision 2557)
@@ -0,0 +1,91 @@
+#include "OgreVisibilityPredictor.h"
+#include "OgreBoundingBoxConverter.h"
+#include "DistanceQueue.h"
+
+
+const static int maxInvisibleNodesSize = 50;
+
+
+namespace Ogre
+{
+	VisibilityPredictor::VisibilityPredictor()
+	{
+	}
+
+	void VisibilityPredictor::HandleProbablyVisibleObjects(GtpVisibilityPreprocessor::ViewCell *vc)
+	{
+		GtpVisibility::QueryQueue queryQueue;
+		GtpVisibility::HierarchyNodeContainer invisibleNodes;
+
+		// use multiqueries for the objects that are probably invisible
+        GtpVisibilityPreprocessor::ObjectPvsIterator pit = vc->GetPvs().GetIterator();
+
+		while (pit.HasMoreEntries())
+		{		
+			GtpVisibilityPreprocessor::Intersectable *obj = pit.Next();
+            
+			if (obj->Type() != GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE)
+				continue;
+		
+			EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
+
+			EntityContainer *entries = oi->GetItem();
+			
+			EntityContainer::const_iterator eit, eit_end = entries->end();
+
+			for (eit = entries->begin(); eit != eit_end; ++ eit)
+			{
+				// collect entities for multiqueries
+				//invisibleNodes.push_back(node);
+
+				if ((int)invisibleNodes.size() >= maxInvisibleNodesSize)
+				{
+					// issue the batched queries
+					//IssueBatchedQuery(invisibleNodes);
+				}
+			}
+		}
+	
+		while(!queryQueue.empty())
+		{
+			unsigned int visiblePixels;
+
+			// fetch multiquery result
+			queryQueue.front().second->GetQueryResult(visiblePixels, false);
+
+			// collect nodes assoziated with current multiquery
+			GtpVisibility::HierarchyNode *node = queryQueue.front().first;
+
+			// tested visible
+			if (visiblePixels > 0)
+			{
+				// render nodes
+				
+				// we have to store and test individual nodes later
+				mNodeBuffer.push_back(node);
+			}
+
+			queryQueue.pop();
+		}	
+	}
+
+
+	void VisibilityPredictor::UpdateVisibility(GtpVisibilityPreprocessor::ViewCell *vc)
+	{
+		GtpVisibility::HierarchyNodeContainer::const_iterator nit, nit_end = mNodeBuffer.end();
+
+		// test individual nodes
+		for (nit = mNodeBuffer.begin(); nit != nit_end; ++ nit)
+		{
+
+		}
+
+		// fetch query results, update PVS of view cell
+		for (nit = mNodeBuffer.begin(); nit != nit_end; ++ nit)
+		{
+
+		}
+
+		mNodeBuffer.clear();
+	}
+}
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 2532)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 2557)
@@ -5,5 +5,4 @@
 
 #include "OgreOcclusionQueriesQueryManager.h"
-//#include "OgrePlatformHierarchyInterface.h"
 #include "OgreOcclusionCullingSceneManager.h"
 #include "VisibilityEnvironment.h"
