From bcc54d496490c501bb212466ff1bc5a143b12a4f Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Fri, 11 Mar 2011 16:39:03 -0600
Subject: SH-477 Put estimated streaming cost back in the debug display -- use
 newfangled equation.

---
 indra/newview/app_settings/settings.xml |  2 +-
 indra/newview/llmeshrepository.cpp      | 39 +++++++++++++++++++++++---------
 indra/newview/llviewerwindow.cpp        | 40 +++++++++++++++++++++++++++++----
 indra/newview/llvovolume.cpp            |  2 +-
 indra/newview/llvovolume.h              |  2 +-
 5 files changed, 68 insertions(+), 17 deletions(-)

(limited to 'indra')

diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 01610f73ed..d0c62817e5 100755
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -8930,7 +8930,7 @@
     <key>Type</key>
     <string>F32</string>
     <key>Value</key>
-    <real>0.125</real>
+    <real>2.0</real>
   </map>
   <key>MeshThreadCount</key>
   <map>
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index b6e3626cba..e259ee9846 100755
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -3100,9 +3100,7 @@ F32 LLMeshRepository::getStreamingCost(const LLSD& header, F32 radius)
 	F32 dlowest = llmin(radius/0.06f, 256.f);
 	F32 dlow = llmin(radius/0.24f, 256.f);
 	F32 dmid = llmin(radius/1.0f, 256.f);
-	F32 dhigh = 0.f;
-
-
+	
 	F32 bytes_lowest = header["lowest_lod"]["size"].asReal()/1024.f;
 	F32 bytes_low = header["low_lod"]["size"].asReal()/1024.f;
 	F32 bytes_mid = header["medium_lod"]["size"].asReal()/1024.f;
@@ -3128,14 +3126,35 @@ F32 LLMeshRepository::getStreamingCost(const LLSD& header, F32 radius)
 		bytes_lowest = bytes_low;
 	}
 
-	F32 cost = 0.f;
-	cost += llmax(256.f-dlowest, 1.f)/32.f*bytes_lowest;
-	cost += llmax(dlowest-dlow, 1.f)/32.f*bytes_low;
-	cost += llmax(dlow-dmid, 1.f)/32.f*bytes_mid;
-	cost += llmax(dmid-dhigh, 1.f)/32.f*bytes_high;
+	F32 max_area = 65536.f;
+	F32 min_area = 1.f;
+
+	F32 high_area = llmin(F_PI*dmid*dmid, max_area);
+	F32 mid_area = llmin(F_PI*dlow*dlow, max_area);
+	F32 low_area = llmin(F_PI*dlowest*dlowest, max_area);
+	F32 lowest_area = max_area;
+
+	lowest_area -= low_area;
+	low_area -= mid_area;
+	mid_area -= high_area;
+
+	high_area = llclamp(high_area, min_area, max_area);
+	mid_area = llclamp(mid_area, min_area, max_area);
+	low_area = llclamp(low_area, min_area, max_area);
+	lowest_area = llclamp(lowest_area, min_area, max_area);
+
+	F32 total_area = high_area + mid_area + low_area + lowest_area;
+	high_area /= total_area;
+	mid_area /= total_area;
+	low_area /= total_area;
+	lowest_area /= total_area;
+
+	F32 weighted_avg = bytes_high*high_area +
+					   bytes_mid*mid_area +
+					   bytes_low*low_area +
+					  bytes_lowest*lowest_area;
 
-	cost *= gSavedSettings.getF32("MeshStreamingCostScaler");
-	return cost;
+	return weighted_avg * gSavedSettings.getF32("MeshStreamingCostScaler");
 }
 
 
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index f665f39e9c..5d91a0045a 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -489,6 +489,42 @@ public:
 				ypos += y_inc;
 			}
 
+			//show streaming cost/triangle count of known prims in current region OR selection
+			{
+				F32 cost = 0.f;
+				S32 count = 0;
+				const char* label = "Region";
+				if (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 0)
+				{ //region
+					LLViewerRegion* region = gAgent.getRegion();
+					if (region)
+					{
+						for (U32 i = 0; i < gObjectList.getNumObjects(); ++i)
+						{
+							LLViewerObject* object = gObjectList.getObject(i);
+							if (object && 
+								object->getRegion() == region &&
+								object->getVolume())
+							{
+								cost += object->getStreamingCost();
+								count += object->getTriangleCount();
+							}
+						}
+					}
+				}
+				else
+				{
+					label = "Selection";
+					cost = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectStreamingCost();
+					count = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectTriangleCount();
+				}
+					
+				addText(xpos,ypos, llformat("%s streaming cost: %.1f (%.1f KTris)",
+							label, cost, count/1000.f));
+				ypos += y_inc;
+			
+			}
+
 			addText(xpos, ypos, llformat("%d MB Vertex Data", LLVertexBuffer::sAllocatedBytes/(1024*1024)));
 			ypos += y_inc;
 
@@ -572,10 +608,6 @@ public:
 				ypos += y_inc;
 			}
 
-			addText(xpos, ypos, llformat("Selection Triangle Count: %.3f Ktris ", LLSelectMgr::getInstance()->getSelection()->getSelectedObjectTriangleCount()/1000.f));
-
-			ypos += y_inc;
-
 			LLVertexBuffer::sBindCount = LLImageGL::sBindCount = 
 				LLVertexBuffer::sSetCount = LLImageGL::sUniqueCount = 
 				gPipeline.mNumVisibleNodes = LLPipeline::sVisibleLightCount = 0;
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 1186d4d8d9..7f373736fa 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -3096,7 +3096,7 @@ F32 LLVOVolume::getStreamingCost()
 	return 0.f;
 }
 
-U32 LLVOVolume::getTriangleCount() const
+U32 LLVOVolume::getTriangleCount()
 {
 	U32 count = 0;
 	LLVolume* volume = getVolume();
diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h
index 0c12f14832..b09243055c 100644
--- a/indra/newview/llvovolume.h
+++ b/indra/newview/llvovolume.h
@@ -131,7 +131,7 @@ public:
 	/*virtual*/	const LLMatrix4	getRenderMatrix() const;
 				U32 	getRenderCost(std::set<LLUUID> &textures) const;
 	/*virtual*/	F32		getStreamingCost();
-	/*virtual*/ U32		getTriangleCount() const;
+	/*virtual*/ U32		getTriangleCount();
 	/*virtual*/ BOOL lineSegmentIntersect(const LLVector3& start, const LLVector3& end, 
 										  S32 face = -1,                        // which face to check, -1 = ALL_SIDES
 										  BOOL pick_transparent = FALSE,
-- 
cgit v1.2.3