Browse Source

Fixed issues with new text data creation algorithm

Marko Pintera 12 years ago
parent
commit
89ead30f92
2 changed files with 27 additions and 15 deletions
  1. 20 11
      CamelotCore/Source/CmTextUtility.cpp
  2. 7 4
      TextOpts.txt

+ 20 - 11
CamelotCore/Source/CmTextUtility.cpp

@@ -146,6 +146,9 @@ namespace CamelotFramework
 	{
 	{
 		UINT32 numQuads = 0;
 		UINT32 numQuads = 0;
 
 
+		if(mIsEmpty)
+			return numQuads;
+
 		UINT32 penX = 0;
 		UINT32 penX = 0;
 		for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
 		for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
 		{
 		{
@@ -266,6 +269,9 @@ namespace CamelotFramework
 
 
 	UINT32 TextUtility::TextLine::getNumChars() const
 	UINT32 TextUtility::TextLine::getNumChars() const
 	{
 	{
+		if(mIsEmpty)
+			return 0;
+
 		UINT32 numChars = 0;
 		UINT32 numChars = 0;
 		for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
 		for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
 		{
 		{
@@ -285,6 +291,9 @@ namespace CamelotFramework
 		mWidth = 0;
 		mWidth = 0;
 		mHeight = 0;
 		mHeight = 0;
 
 
+		if(mIsEmpty)
+			return;
+
 		for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
 		for(UINT32 i = mWordsStart; i <= mWordsEnd; i++)
 		{
 		{
 			TextWord& word = TextUtility::WordBuffer[i];
 			TextWord& word = TextUtility::WordBuffer[i];
@@ -377,14 +386,14 @@ namespace CamelotFramework
 			UINT32 charId = text[charIdx];
 			UINT32 charId = text[charIdx];
 			const CHAR_DESC& charDesc = fontData->getCharDesc(charId);
 			const CHAR_DESC& charDesc = fontData->getCharDesc(charId);
 
 
-			TextLine& curLine = LineBuffer[curLineIdx];
+			TextLine* curLine = &LineBuffer[curLineIdx];
 
 
 			if(text[charIdx] == '\n')
 			if(text[charIdx] == '\n')
 			{
 			{
-				curLine.finalize(true);
+				curLine->finalize(true);
 
 
 				curLineIdx = allocLine(textData.get());
 				curLineIdx = allocLine(textData.get());
-				curLine = LineBuffer[curLineIdx];
+				curLine = &LineBuffer[curLineIdx];
 
 
 				curHeight += fontData->fontDesc.lineHeight;
 				curHeight += fontData->fontDesc.lineHeight;
 
 
@@ -394,35 +403,35 @@ namespace CamelotFramework
 
 
 			if(charId != SPACE_CHAR)
 			if(charId != SPACE_CHAR)
 			{
 			{
-				curLine.add(charIdx, charDesc);
+				curLine->add(charIdx, charDesc);
 				addCharToPage(charDesc.page, *fontData);
 				addCharToPage(charDesc.page, *fontData);
 			}
 			}
 			else
 			else
 			{
 			{
-				curLine.addSpace();
+				curLine->addSpace();
 				addCharToPage(0, *fontData);
 				addCharToPage(0, *fontData);
 			}
 			}
 
 
-			if(widthIsLimited && curLine.getWidth() > width)
+			if(widthIsLimited && curLine->getWidth() > width)
 			{
 			{
 				if(wordWrap)
 				if(wordWrap)
 				{
 				{
-					assert(!curLine.isEmpty());
+					assert(!curLine->isEmpty());
 
 
-					UINT32 lastWordIdx = curLine.removeLastWord();
+					UINT32 lastWordIdx = curLine->removeLastWord();
 					TextWord& lastWord = WordBuffer[lastWordIdx];
 					TextWord& lastWord = WordBuffer[lastWordIdx];
 
 
 					if(lastWord.getWidth() <= width) // If the word fits, attempt to add it to a new line
 					if(lastWord.getWidth() <= width) // If the word fits, attempt to add it to a new line
 					{
 					{
-						curLine.finalize(false);
+						curLine->finalize(false);
 
 
 						curLineIdx = allocLine(textData.get());
 						curLineIdx = allocLine(textData.get());
-						curLine = LineBuffer[curLineIdx];
+						curLine = &LineBuffer[curLineIdx];
 
 
 						curHeight += fontData->fontDesc.lineHeight;
 						curHeight += fontData->fontDesc.lineHeight;
 					}
 					}
 
 
-					curLine.addWord(lastWordIdx, lastWord);
+					curLine->addWord(lastWordIdx, lastWord);
 				}
 				}
 			}
 			}
 
 

+ 7 - 4
TextOpts.txt

@@ -1,7 +1,10 @@
 Make sure to also update TextSprite and ImageSprite and anything else in UpdateMesh, then don't forget to find the issue that causes elements to get marked as dirty every single frame
 Make sure to also update TextSprite and ImageSprite and anything else in UpdateMesh, then don't forget to find the issue that causes elements to get marked as dirty every single frame
 
 
-MultiLine text doesn't work and possibly input/selection
+TODO: Fix allocation counter as it doesn't work properly between multiple threads
+TODO: Get rid of TextUtility and make all text generation happen in TextData constructor. Get rid of TextData shared_ptr as it just causes an unnecessary allocation.
+TODO: MultiLine text doesn't work and possibly input/selection
+TODO: Ensure that buffers in TextData actually handle multiple threads properly (THREADLOCAL?)
 
 
-		// TODO: Ensure that buffers in TextData actually handle multiple threads properly (THREADLOCAL?)
-		// TODO: Merge buffer allocations for shared_ptr and data into a single alloc?
-		// TODO: Pre-opt stats: 1500 allocs, 600 frees, 0.5ms
+Performance stats:
+ Pre-opt: 1500 allocs, 600 frees, 0.5ms
+ Post-first-stage-opt: 408 alloc, 136 frees, 0.15ms