Browse Source

Added profiler overlay captions and made sure they render in proper columns
Fixed a bug with inserting elements into layout (wasn't able to insert after last element)

Marko Pintera 12 years ago
parent
commit
bd49987b79

+ 5 - 5
BansheeEngine/Include/BsProfilerOverlay.h

@@ -92,11 +92,11 @@ namespace BansheeEngine
 		GUIElement* mTitlePreciseName;
 		GUIElement* mTitlePrecisePctOfParent;
 		GUIElement* mTitlePreciseNumCalls;
-		GUIElement* mTitlePreciseAvgTime;
-		GUIElement* mTitlePreciseTotalTime;
-		GUIElement* mTitlePreciseMaxTime;
-		GUIElement* mTitlePreciseAvgTitleSelf;
-		GUIElement* mTitlePreciseTotalTimeSelf;
+		GUIElement* mTitlePreciseAvgCycles;
+		GUIElement* mTitlePreciseTotalCycles;
+		GUIElement* mTitlePreciseMaxCycles;
+		GUIElement* mTitlePreciseAvgCyclesSelf;
+		GUIElement* mTitlePreciseTotalCyclesSelf;
 		GUIElement* mTitlePreciseEstOverhead;
 		GUIElement* mTitlePreciseEstOverheadSelf;
 

+ 2 - 2
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -156,7 +156,7 @@ namespace BansheeEngine
 
 	GUILayout& GUIElementBase::insertLayoutXInternal(GUIElementBase* parent, UINT32 idx)
 	{
-		if(idx < 0 || idx >= (UINT32)mChildren.size())
+		if(idx < 0 || idx > (UINT32)mChildren.size())
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUILayoutX* entry = cm_new<GUILayoutX, PoolAlloc>();
@@ -170,7 +170,7 @@ namespace BansheeEngine
 
 	GUILayout& GUIElementBase::insertLayoutYInternal(GUIElementBase* parent, UINT32 idx)
 	{
-		if(idx < 0 || idx >= (UINT32)mChildren.size())
+		if(idx < 0 || idx > (UINT32)mChildren.size())
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUILayoutY* entry = cm_new<GUILayoutY, PoolAlloc>();

+ 3 - 3
BansheeEngine/Source/BsGUILayout.cpp

@@ -59,7 +59,7 @@ namespace BansheeEngine
 
 	void GUILayout::insertElement(UINT32 idx, GUIElement* element)
 	{
-		if(idx < 0 || idx >= (UINT32)mChildren.size())
+		if(idx < 0 || idx > (UINT32)mChildren.size())
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUIElementBase* parentElement = element->_getParent();
@@ -125,7 +125,7 @@ namespace BansheeEngine
 
 	GUIFixedSpace& GUILayout::insertSpace(UINT32 idx, UINT32 size)
 	{
-		if(idx < 0 || idx >= (UINT32)mChildren.size())
+		if(idx < 0 || idx > (UINT32)mChildren.size())
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUIFixedSpace* entry = cm_new<GUIFixedSpace, PoolAlloc>(size);
@@ -170,7 +170,7 @@ namespace BansheeEngine
 
 	GUIFlexibleSpace& GUILayout::insertFlexibleSpace(UINT32 idx)
 	{
-		if(idx < 0 || idx >= (UINT32)mChildren.size())
+		if(idx < 0 || idx > (UINT32)mChildren.size())
 			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
 
 		GUIFlexibleSpace* entry = cm_new<GUIFlexibleSpace, PoolAlloc>();

+ 89 - 55
BansheeEngine/Source/BsProfilerOverlay.cpp

@@ -29,12 +29,13 @@ namespace BansheeEngine
 
 		~BasicRowFiller()
 		{
-			for(INT32 i = (INT32)rows.size() - 1; i >= (INT32)curIdx; i--)
+			UINT32 excessEntries = (UINT32)rows.size() - curIdx;
+			for(UINT32 i = 0; i < excessEntries; i++)
 			{
-				labelLayout.removeChildAt(i);
-				contentLayout.removeChildAt(i);
+				labelLayout.removeChildAt(labelLayout.getNumChildren() - i - 1); // -1 because last element is flexible space and we want to skip it
+				contentLayout.removeChildAt(contentLayout.getNumChildren() - i - 1); // -1 because last element is flexible space and we want to skip it
 
-				ProfilerOverlay::BasicRow& row = rows[i];
+				ProfilerOverlay::BasicRow& row = rows[curIdx + i];
 
 				for(auto& element : row.elements)
 					GUIElement::destroy(element);
@@ -63,19 +64,19 @@ namespace BansheeEngine
 				newRow.estOverhead = HString(L"{0}");
 				newRow.estOverheadSelf = HString(L"{0}");
 
-				newRow.labelLayout = &labelLayout.addLayoutX();
-				newRow.contentLayout = &contentLayout.addLayoutX();
+				newRow.labelLayout = &labelLayout.insertLayoutX(labelLayout.getNumChildren() - 1); // Insert before flexible space
+				newRow.contentLayout = &contentLayout.insertLayoutX(contentLayout.getNumChildren() - 1); // Insert before flexible space
 
-				GUILabel* name = GUILabel::create(widget, newRow.name);
-				GUILabel* pctOfParent = GUILabel::create(widget, newRow.pctOfParent);
-				GUILabel* numCalls = GUILabel::create(widget, newRow.numCalls);
-				GUILabel* avgTime = GUILabel::create(widget, newRow.avgTime);
-				GUILabel* totalTime = GUILabel::create(widget, newRow.totalTime);
-				GUILabel* maxTime = GUILabel::create(widget, newRow.maxTime);
-				GUILabel* avgTimeSelf = GUILabel::create(widget, newRow.avgTimeSelf);
-				GUILabel* totalTimeSelf = GUILabel::create(widget, newRow.totalTimeSelf);
-				GUILabel* estOverhead = GUILabel::create(widget, newRow.estOverhead);
-				GUILabel* estOverheadSelf = GUILabel::create(widget, newRow.estOverheadSelf);
+				GUILabel* name = GUILabel::create(widget, newRow.name, GUIOptions(GUIOption::fixedWidth(200)));
+				GUILabel* pctOfParent = GUILabel::create(widget, newRow.pctOfParent, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* numCalls = GUILabel::create(widget, newRow.numCalls, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* avgTime = GUILabel::create(widget, newRow.avgTime, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* totalTime = GUILabel::create(widget, newRow.totalTime, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* maxTime = GUILabel::create(widget, newRow.maxTime, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* avgTimeSelf = GUILabel::create(widget, newRow.avgTimeSelf, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* totalTimeSelf = GUILabel::create(widget, newRow.totalTimeSelf, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* estOverhead = GUILabel::create(widget, newRow.estOverhead, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* estOverheadSelf = GUILabel::create(widget, newRow.estOverheadSelf, GUIOptions(GUIOption::fixedWidth(100)));
 
 				newRow.labelLayout->addSpace(0);
 				newRow.labelLayout->addElement(name);
@@ -137,12 +138,13 @@ namespace BansheeEngine
 
 		~PreciseRowFiller()
 		{
-			for(INT32 i = (INT32)rows.size() - 1; i >= (INT32)curIdx; i--)
+			UINT32 excessEntries = (UINT32)rows.size() - curIdx;
+			for(UINT32 i = 0; i < excessEntries; i++)
 			{
-				labelLayout.removeChildAt(i);
-				contentLayout.removeChildAt(i);
+				labelLayout.removeChildAt(labelLayout.getNumChildren() - i - 1); // -1 because last element is flexible space and we want to skip it
+				contentLayout.removeChildAt(contentLayout.getNumChildren() - i - 1); // -1 because last element is flexible space and we want to skip it
 
-				ProfilerOverlay::PreciseRow& row = rows[i];
+				ProfilerOverlay::PreciseRow& row = rows[curIdx + i];
 
 				for(auto& element : row.elements)
 					GUIElement::destroy(element);
@@ -171,19 +173,19 @@ namespace BansheeEngine
 				newRow.estOverhead = HString(L"{0}");
 				newRow.estOverheadSelf = HString(L"{0}");
 
-				newRow.labelLayout = &labelLayout.addLayoutX();
-				newRow.contentLayout = &contentLayout.addLayoutX();
+				newRow.labelLayout = &labelLayout.insertLayoutX(labelLayout.getNumChildren() - 1); // Insert before flexible space
+				newRow.contentLayout = &contentLayout.insertLayoutX(contentLayout.getNumChildren() - 1); // Insert before flexible space
 
-				GUILabel* name = GUILabel::create(widget, newRow.name);
-				GUILabel* pctOfParent = GUILabel::create(widget, newRow.pctOfParent);
-				GUILabel* numCalls = GUILabel::create(widget, newRow.numCalls);
-				GUILabel* avgCycles = GUILabel::create(widget, newRow.avgCycles);
-				GUILabel* totalCycles = GUILabel::create(widget, newRow.totalCycles);
-				GUILabel* maxCycles = GUILabel::create(widget, newRow.maxCycles);
-				GUILabel* avgCyclesSelf = GUILabel::create(widget, newRow.avgCyclesSelf);
-				GUILabel* totalCyclesSelf = GUILabel::create(widget, newRow.totalCyclesSelf);
-				GUILabel* estOverhead = GUILabel::create(widget, newRow.estOverhead);
-				GUILabel* estOverheadSelf = GUILabel::create(widget, newRow.estOverheadSelf);
+				GUILabel* name = GUILabel::create(widget, newRow.name, GUIOptions(GUIOption::fixedWidth(200)));
+				GUILabel* pctOfParent = GUILabel::create(widget, newRow.pctOfParent, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* numCalls = GUILabel::create(widget, newRow.numCalls, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* avgCycles = GUILabel::create(widget, newRow.avgCycles,GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* totalCycles = GUILabel::create(widget, newRow.totalCycles, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* maxCycles = GUILabel::create(widget, newRow.maxCycles, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* avgCyclesSelf = GUILabel::create(widget, newRow.avgCyclesSelf, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* totalCyclesSelf = GUILabel::create(widget, newRow.totalCyclesSelf, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* estOverhead = GUILabel::create(widget, newRow.estOverhead, GUIOptions(GUIOption::fixedWidth(100)));
+				GUILabel* estOverheadSelf = GUILabel::create(widget, newRow.estOverheadSelf, GUIOptions(GUIOption::fixedWidth(100)));
 
 				newRow.labelLayout->addSpace(0);
 				newRow.labelLayout->addElement(name);
@@ -238,8 +240,8 @@ namespace BansheeEngine
 		mTitleBasicName(nullptr), mTitleBasicPctOfParent(nullptr), mTitleBasicNumCalls(nullptr), mTitleBasicAvgTime(nullptr), 
 		mTitleBasicTotalTime(nullptr), mTitleBasicMaxTime(nullptr), mTitleBasicAvgTitleSelf(nullptr), mTitleBasicTotalTimeSelf(nullptr), 
 		mTitleBasicEstOverhead(nullptr), mTitleBasicEstOverheadSelf(nullptr), mTitlePreciseName(nullptr), mTitlePrecisePctOfParent(nullptr), 
-		mTitlePreciseNumCalls(nullptr), mTitlePreciseAvgTime(nullptr), mTitlePreciseTotalTime(nullptr), mTitlePreciseMaxTime(nullptr), 
-		mTitlePreciseAvgTitleSelf(nullptr), mTitlePreciseTotalTimeSelf(nullptr), mTitlePreciseEstOverhead(nullptr), mTitlePreciseEstOverheadSelf(nullptr)
+		mTitlePreciseNumCalls(nullptr), mTitlePreciseAvgCycles(nullptr), mTitlePreciseTotalCycles(nullptr), mTitlePreciseMaxCycles(nullptr), 
+		mTitlePreciseAvgCyclesSelf(nullptr), mTitlePreciseTotalCyclesSelf(nullptr), mTitlePreciseEstOverhead(nullptr), mTitlePreciseEstOverheadSelf(nullptr)
 	{
 		setTarget(target, ownerWindow);
 
@@ -285,27 +287,59 @@ namespace BansheeEngine
 		mPreciseLayoutContents = &mPreciseAreaContents->getLayout().addLayoutY();
 
 		// Set up title bars
-		//mTitleBasicName = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::fixed(200, 20));
-		//mTitleBasicPctOfParent = GUILabel::create(*mWidget, HString(L"% parent"), GUILayoutOptions::expandableY(100));
-		//mTitleBasicNumCalls = GUILabel::create(*mWidget, HString(L"Num. calls"), GUILayoutOptions::expandableY(100));
-		//mTitleBasicAvgTime = GUILabel::create(*mWidget, HString(L"Avg. time"), GUILayoutOptions::expandableY(100));
-		//mTitleBasicTotalTime = GUILabel::create(*mWidget, HString(L"Total time"), GUILayoutOptions::expandableY(100));
-		//mTitleBasicMaxTime = GUILabel::create(*mWidget, HString(L"Max time"), GUILayoutOptions::expandableY(100));
-		//mTitleBasicAvgTitleSelf = GUILabel::create(*mWidget, HString(L"Avg. self time"), GUILayoutOptions::expandableY(100));
-		//mTitleBasicTotalTimeSelf = GUILabel::create(*mWidget, HString(L"Total self time"), GUILayoutOptions::expandableY(100));
-		//mTitleBasicEstOverhead = GUILabel::create(*mWidget, HString(L"Est. overhead"), GUILayoutOptions::expandableY(100));
-		//mTitleBasicEstOverheadSelf = GUILabel::create(*mWidget, HString(L"Est. self overhead"), GUILayoutOptions::expandableY(100));
-
-		//mTitlePreciseName = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePrecisePctOfParent = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePreciseNumCalls = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePreciseAvgTime = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePreciseTotalTime = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePreciseMaxTime = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePreciseAvgTitleSelf = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePreciseTotalTimeSelf = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePreciseEstOverhead = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
-		//mTitlePreciseEstOverheadSelf = GUILabel::create(*mWidget, HString(L"Name"), GUILayoutOptions::expandableY(200));
+		mTitleBasicName = GUILabel::create(*mWidget, HString(L"Name"), GUIOptions(GUIOption::fixedWidth(200)));
+		mTitleBasicPctOfParent = GUILabel::create(*mWidget, HString(L"% parent"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitleBasicNumCalls = GUILabel::create(*mWidget, HString(L"Num. calls"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitleBasicAvgTime = GUILabel::create(*mWidget, HString(L"Avg. time"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitleBasicTotalTime = GUILabel::create(*mWidget, HString(L"Total time"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitleBasicMaxTime = GUILabel::create(*mWidget, HString(L"Max time"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitleBasicAvgTitleSelf = GUILabel::create(*mWidget, HString(L"Avg. self time"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitleBasicTotalTimeSelf = GUILabel::create(*mWidget, HString(L"Total self time"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitleBasicEstOverhead = GUILabel::create(*mWidget, HString(L"Est. overhead"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitleBasicEstOverheadSelf = GUILabel::create(*mWidget, HString(L"Est. self overhead"), GUIOptions(GUIOption::fixedWidth(100)));
+
+		mTitlePreciseName = GUILabel::create(*mWidget, HString(L"Name"), GUIOptions(GUIOption::fixedWidth(200)));
+		mTitlePrecisePctOfParent = GUILabel::create(*mWidget, HString(L"% parent"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitlePreciseNumCalls = GUILabel::create(*mWidget, HString(L"Num. calls"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitlePreciseAvgCycles = GUILabel::create(*mWidget, HString(L"Avg. cycles"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitlePreciseTotalCycles = GUILabel::create(*mWidget, HString(L"Total cycles"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitlePreciseMaxCycles = GUILabel::create(*mWidget, HString(L"Max cycles"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitlePreciseAvgCyclesSelf = GUILabel::create(*mWidget, HString(L"Avg. self cycles"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitlePreciseTotalCyclesSelf = GUILabel::create(*mWidget, HString(L"Total self cycles"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitlePreciseEstOverhead = GUILabel::create(*mWidget, HString(L"Est. overhead"), GUIOptions(GUIOption::fixedWidth(100)));
+		mTitlePreciseEstOverheadSelf = GUILabel::create(*mWidget, HString(L"Est. self overhead"), GUIOptions(GUIOption::fixedWidth(100)));
+
+		GUILayout& basicTitleLabelLayout = mBasicLayoutLabels->addLayoutX();
+		GUILayout& preciseTitleLabelLayout = mPreciseLayoutLabels->addLayoutX();
+		GUILayout& basicTitleContentLayout = mBasicLayoutContents->addLayoutX();
+		GUILayout& preciseTitleContentLayout = mPreciseLayoutContents->addLayoutX();
+
+		basicTitleLabelLayout.addElement(mTitleBasicName);
+		basicTitleContentLayout.addElement(mTitleBasicPctOfParent);
+		basicTitleContentLayout.addElement(mTitleBasicNumCalls);
+		basicTitleContentLayout.addElement(mTitleBasicAvgTime);
+		basicTitleContentLayout.addElement(mTitleBasicTotalTime);
+		basicTitleContentLayout.addElement(mTitleBasicMaxTime);
+		basicTitleContentLayout.addElement(mTitleBasicAvgTitleSelf);
+		basicTitleContentLayout.addElement(mTitleBasicTotalTimeSelf);
+		basicTitleContentLayout.addElement(mTitleBasicEstOverhead);
+		basicTitleContentLayout.addElement(mTitleBasicEstOverheadSelf);
+
+		preciseTitleLabelLayout.addElement(mTitlePreciseName);
+		preciseTitleContentLayout.addElement(mTitlePrecisePctOfParent);
+		preciseTitleContentLayout.addElement(mTitlePreciseNumCalls);
+		preciseTitleContentLayout.addElement(mTitlePreciseAvgCycles);
+		preciseTitleContentLayout.addElement(mTitlePreciseTotalCycles);
+		preciseTitleContentLayout.addElement(mTitlePreciseMaxCycles);
+		preciseTitleContentLayout.addElement(mTitlePreciseAvgCyclesSelf);
+		preciseTitleContentLayout.addElement(mTitlePreciseTotalCyclesSelf);
+		preciseTitleContentLayout.addElement(mTitlePreciseEstOverhead);
+		preciseTitleContentLayout.addElement(mTitlePreciseEstOverheadSelf);
+
+		mBasicLayoutLabels->addFlexibleSpace();
+		mPreciseLayoutLabels->addFlexibleSpace();
+		mBasicLayoutContents->addFlexibleSpace();
+		mPreciseLayoutContents->addFlexibleSpace();
 
 		updateAreaSizes();
 	}

+ 4 - 1
CamelotCore/Source/CmProfiler.cpp

@@ -39,7 +39,10 @@ namespace CamelotFramework
 	{
 		idx = Math::Clamp(idx, 0U, (UINT32)(NUM_SAVED_FRAMES - 1));
 
-		return mSavedReports[idx];
+		UINT32 reportIdx = mNextReportIdx + (UINT32)((INT32)NUM_SAVED_FRAMES - ((INT32)idx + 1));
+		reportIdx = (reportIdx) % NUM_SAVED_FRAMES;
+
+		return mSavedReports[reportIdx];
 	}
 
 	Profiler& gProfiler()