示例#1
0
bool CPrsBDF::RemoveNextWord( CStr &roStr )
{
	if( !roStr.GetSize() )
		return false;
	static const char *acSpace_ = " \t";
	RemoveLeadingSpace( roStr );
	int iPos = roStr.FindVec( 0, acSpace_ );
	if( iPos < 0 )
		iPos = roStr.GetSize();
	roStr.Del( 0, iPos );
	RemoveLeadingSpace( roStr );
	return true;
}
示例#2
0
void CPrsBDF::ReadValue( CStr &roStr, CArray<unsigned char> *poArrByte )
{
	poArrByte->Clear();
	CStr oStrHex( roStr );
	const int iSize = roStr.GetSize();
	int iPos = 0;
	char acHex[3] = { 0, 0, 0 };
	const char *pcS = oStrHex.GetData();
	while( iPos < iSize )
	{
		acHex[0] = *( pcS + iPos );
		++iPos;
		acHex[1] = *( pcS + iPos );
		++iPos;
		const unsigned char ucByte = (unsigned char)strtol( acHex, 0, 16 ); // TODO: ersetzen durch eigene Funktion.
		poArrByte->Append( ucByte );
	}
}
示例#3
0
bool CPrsBDF::Parse( const char *pcFont )
{
#define TOK(T) TPairTokenNameID( #T, PBDF_TOKEN_##T )
	static const TPairTokenNameID m_aoToken_[] = 
	{
		TOK( STARTFONT ),
		TOK( COMMENT ),
		TOK( CONTENTVERSION ),
		TOK( FONT ),
		TOK( SIZE ),
		TOK( FONTBOUNDINGBOX ),
		TOK( METRICSSET ),
		TOK( SWIDTH ),
		TOK( DWIDTH ),
		TOK( SWIDTH1 ),
		TOK( DWIDTH1 ),
		TOK( VVECTOR ),
		TOK( STARTPROPERTIES ),
		TOK( ENDPROPERTIES ),
		TOK( CHARS ),
		TOK( STARTCHAR ),
		TOK( ENCODING ),
		TOK( BBX ),
		TOK( BITMAP ),
		TOK( ENDCHAR ),
		TOK( ENDFONT )
	};
	static const unsigned int uiTokenNum = sizeof( m_aoToken_ ) / sizeof( TPairTokenNameID );
	CStr oStrFontFile( pcFont );
	const int iFontSize = oStrFontFile.GetSize();
	int iPropertiesStartPos = -1;
	CGlyph oGylphNew;
	CGlyph *poGlyph = &m_oGlyphDefault;
	bool bIsReadingChar = false;
	
	Reset();
	
	PBDF_LOG( "parse: start\n" );
	
	int iPos = 0;
	while( iPos < iFontSize )
	{
		int iEndOfLine = oStrFontFile.Find( iPos, PBDF_NEWLINE );
		if( iEndOfLine < 0 )
			iEndOfLine = iFontSize;
		
		CStr oStrLine = oStrFontFile.GetSub( iPos, iEndOfLine - iPos );
		RemoveLeadingSpace( oStrLine );
		
		//PBDF_LOG( "line: %s", oStrLine.GetData() );
		//PBDF_LOG( "line_size: %s", oStrLine.GetSize() );
		
		unsigned int uiTokenNext = PBDF_TOKEN_NONE;
		
		for( unsigned int t=0; t<uiTokenNum; ++t )
		{
			CStr oStrToken = m_aoToken_[t].GetFirst() ;
			const unsigned int uiTokenSize = oStrToken.GetSize();
			
			//PBDF_LOG( "token: %s", oStrToken.GetData() );
			
			int iPosToken = oStrLine.Find( 0, oStrToken );
			if( iPosToken != 0 ) 
				continue;
			
			// Danach müssen Leerzeichen oder das Ende folgen!
			const unsigned int uiPosNext = iPosToken + uiTokenSize;
			if( uiPosNext < oStrLine.GetSize() )
			{
				const char cNext = oStrLine[ uiPosNext ];
				if( !( cNext == ' ' || cNext == '\t' ) )
					continue;
			}
			
			if( iPosToken >= 0 )
			{
				oStrLine.Del( 0, uiTokenSize );
				RemoveLeadingSpace( oStrLine );
				uiTokenNext = m_aoToken_[t].GetSecond();
				PBDF_LOG( "token: %s\n", oStrToken.GetData() );
				break;
			}
		}
		
		if( uiTokenNext != PBDF_TOKEN_NONE )
		{
			switch( uiTokenNext )
			{
			case PBDF_TOKEN_STARTFONT:
				ReadValue( oStrLine, &m_dVersion );
				PBDF_LOG( "version: %g\n", m_dVersion );
			break;
			case PBDF_TOKEN_COMMENT:
			break;
			case PBDF_TOKEN_CONTENTVERSION: // optional
				ReadValue( oStrLine, &m_iContentVersion );
				PBDF_LOG( "content_version: %d\n", m_iContentVersion );
			break;
			case PBDF_TOKEN_FONT:
				ReadValue( oStrLine, &m_oStrFont );
				PBDF_LOG( "font: %s\n", m_oStrFont.GetData() );
			break;
			case PBDF_TOKEN_SIZE:
				ReadValue( oStrLine, &m_iPointSize );
				PBDF_LOG( "point_size: %d\n", m_iPointSize );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &m_iResX );
				PBDF_LOG( "res_x: %d\n", m_iResX );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &m_iResY );
				PBDF_LOG( "res_y: %d\n", m_iResY );
			break;
			case PBDF_TOKEN_FONTBOUNDINGBOX:
				ReadValue( oStrLine, &m_iBBX );
				PBDF_LOG( "bounding_box_x: %d\n", m_iBBX );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &m_iBBY );
				PBDF_LOG( "bounding_box_y: %d\n", m_iBBY );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &m_iOffX );
				PBDF_LOG( "offset_y: %d\n", m_iOffX );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &m_iOffY );
				PBDF_LOG( "offset_x: %d\n", m_iOffY );
				RemoveNextWord( oStrLine );
			break;
			case PBDF_TOKEN_METRICSSET: // optional
				ReadValue( oStrLine, &m_iMetricsSet );
				PBDF_LOG( "metrics_set: %d\n", m_iMetricsSet );
			break;
			case PBDF_TOKEN_SWIDTH:
				ReadValue( oStrLine, &poGlyph->m_dSX );
				PBDF_LOG( "sx: %g\n", poGlyph->m_dSX );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &poGlyph->m_dSY );
				PBDF_LOG( "sy: %g\n", poGlyph->m_dSY );
			break;
			case PBDF_TOKEN_DWIDTH:
				ReadValue( oStrLine, &poGlyph->m_iDX );
				PBDF_LOG( "dx: %d\n", poGlyph->m_iDX );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &poGlyph->m_iDY );
				PBDF_LOG( "dy: %d\n", poGlyph->m_iDY );
			break;
			case PBDF_TOKEN_SWIDTH1:
				ReadValue( oStrLine, &poGlyph->m_dSX1 );
				PBDF_LOG( "sx1: %g\n", poGlyph->m_dSX1 );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &poGlyph->m_dSY1 );
				PBDF_LOG( "sy1: %g\n", poGlyph->m_dSY1 );
			break;
			case PBDF_TOKEN_DWIDTH1:
				ReadValue( oStrLine, &poGlyph->m_iDX1 );
				PBDF_LOG( "dx1: %d\n", poGlyph->m_iDX1 );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &poGlyph->m_iDY1 );
				PBDF_LOG( "dy1: %d\n", poGlyph->m_iDY1 );
			break;
			case PBDF_TOKEN_VVECTOR: // optional
				ReadValue( oStrLine, &poGlyph->m_dVVX );
				PBDF_LOG( "vvx: %g\n", poGlyph->m_dVVX );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &poGlyph->m_dVVY );
				PBDF_LOG( "vvy: %g\n", poGlyph->m_dVVY );
			break;
			case PBDF_TOKEN_STARTPROPERTIES: // optional
				ReadValue( oStrLine, &m_iProperties );
				PBDF_LOG( "properties: %d\n", m_iProperties );
				iPropertiesStartPos = iEndOfLine + 1;
			break;
			case PBDF_TOKEN_ENDPROPERTIES: // optional
				if( iPropertiesStartPos < 0 )
					break;
				m_oStrProperties = oStrFontFile.GetSub( 
					iPropertiesStartPos, iPos - iPropertiesStartPos );
				PBDF_LOG( "properties:\n%s\n", m_oStrProperties.GetData() );
			break;
			case PBDF_TOKEN_CHARS:
				ReadValue( oStrLine, &m_iChars );
				PBDF_LOG( "chars: %d\n", m_iChars );
				
				poGlyph = &oGylphNew;
			break;
			case PBDF_TOKEN_STARTCHAR:
				if( bIsReadingChar )
				{
					PBDF_ERROR( "glyph %s\n", oStrLine.GetData() );
					return false;
				}
				bIsReadingChar = true;
				
				oGylphNew = m_oGlyphDefault;
				ReadValue( oStrLine, &poGlyph->m_oStrName );
				PBDF_LOG( "char_name: %s\n", poGlyph->m_oStrName.GetData() );
				PBDF_LOG( "char_num: %d\n", m_oArrGlyph.GetSize() );
			break;
			case PBDF_TOKEN_ENCODING:
				ReadValue( oStrLine, &poGlyph->m_iEncoding0  );
				PBDF_LOG( "encoding0: %d\n", poGlyph->m_iEncoding0 );
				RemoveNextWord( oStrLine );
				if( !oStrLine.GetSize() )
					break;
				ReadValue( oStrLine, &poGlyph->m_iEncoding1 );
				PBDF_LOG( "encoding1: %d\n", poGlyph->m_iEncoding1 );
			break;
			case PBDF_TOKEN_BBX:
				ReadValue( oStrLine, &poGlyph->m_iBBX );
				PBDF_LOG( "bbx: %d\n", poGlyph->m_iBBX );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &poGlyph->m_iBBY );
				PBDF_LOG( "bby: %d\n", poGlyph->m_iBBY );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &poGlyph->m_iBBOffX );
				PBDF_LOG( "bb_off_x: %d\n", poGlyph->m_iBBOffX );
				RemoveNextWord( oStrLine );
				ReadValue( oStrLine, &poGlyph->m_iBBOffY );
				PBDF_LOG( "bb_off_y: %d\n", poGlyph->m_iBBOffY );
			break;
			case PBDF_TOKEN_BITMAP:
			{
				CArray<unsigned char> oArrBitmap;
				const int iHeight = poGlyph->m_iBBY;
				
				// Da hier sowieso kein Token folgt, kann ohne weiteres
				// auch über das Zeilenende hinaus gearbeitet werden.
				int iPosBegin = iEndOfLine + 1;
				int l = 0;
				
				poGlyph->m_oArrBitmap.Clear();
				
				while( l < iHeight )
				{
					const int iEOL = oStrFontFile.Find( iPosBegin, PBDF_NEWLINE ); 
					if( iEOL < 0 )
						break;
					CStr oCodeLine = oStrFontFile.GetSub( iPosBegin, iEOL - iPosBegin );
					ReadValue( oCodeLine, &oArrBitmap );
					poGlyph->m_oArrBitmap.Append( oArrBitmap );
					iPosBegin = iEOL + 1;
					++l;
				}		
			}
			break;
			case PBDF_TOKEN_ENDCHAR:
				m_oArrGlyph.Append( oGylphNew );
				bIsReadingChar = false;
			break;
			case PBDF_TOKEN_ENDFONT:
				PBDF_LOG( "glyph_count: %d\n", m_oArrGlyph.GetSize() );
				if( m_oArrGlyph.GetSize() != (unsigned int)m_iChars )
				{
					PBDF_ERROR( "glyph_cout: %d != %d", m_oArrGlyph.GetSize(), m_iChars );
					return false;
				}
			break;
			};
		}
		iPos = iEndOfLine + 1; // falls "\r\n"??
	}
	
	PBDF_LOG( "parse: end\n" );
	return true;
}
示例#4
0
void CPrsBDF::ReadValue( CStr &roStr, CStr *poString )
{
	if( roStr.GetSize() )
		*poString = roStr; // TODO...
}
示例#5
0
void CPrsBDF::ReadValue( CStr &roStr, int *piInteger )
{
	if( roStr.GetSize() )
		*piInteger = atoi( roStr.GetData() ); // TODO: ersetzen durch eigene Funktion.
}
示例#6
0
void CPrsBDF::ReadValue( CStr &roStr, double *pdNumber )
{
	if( roStr.GetSize() )
		*pdNumber = atof( roStr.GetData() ); // TODO: ersetzen durch eigene Funktion.
}
示例#7
0
void CGmResMan::NewMeshObj( const char *pcSubDir, const char *pcFileName, CArray<CGMeshObj *> &roArr, bool bTexSmooth, bool bRawPoly )
{
	roArr.Clear();
	
	CStr oPre( DATA_DIR + "model/" + pcSubDir );
	if( oPre[oPre.GetSize()-1] != '/' )
		oPre += '/';
	CFileBlockTxt oFile;
	if( oFile.Load( ( oPre + pcFileName ).GetData() ) )
	{
		LOG( "Loading %s.\n", ( oPre + pcFileName ).GetData() );
		CStr oMaterialLibName;
		if( CGMeshObj::LoadModel_( oFile.GetString(), &roArr, bRawPoly, &oMaterialLibName ) )
		{
			LOG( "%d OBJ-Meshes loaded.\n", roArr.GetSize() );
			
			bool bMtllibOk = false;
			CFileBlockTxt oFileMaterialLib;
			if( oMaterialLibName.GetSize() )
			{
				if( oFileMaterialLib.Load( ( oPre + oMaterialLibName ).GetData() ) )
				{
					//LOG( "\nmtllib:\n%s\n", (const char *)oFileMaterialLib.m_pucData );
					LOG( "%s loaded.\n", oMaterialLibName.GetData() );
					bMtllibOk = true;
				}
			}
			
			for( unsigned int i=0; i<roArr.GetSize(); ++i )
			{
				CGMeshObj *poMesh = roArr[i];
				//poMesh->RotateX( M_PI );
				//poMesh->ScaleX( 1.1f );
				//poMesh->ScaleY( 1.1f );
				//poMesh->ScaleZ( 1.1f );
				LOG( "\t%s\n", poMesh->m_oName.GetData() );
				LOG( "\t%d vertices\n", poMesh->m_oArrVertex.GetSize() );
				LOG( "\t%d indices\n", poMesh->m_oArrIndex.GetSize() );
				LOG( "\tmaterial: %s\n", poMesh->m_oMaterialName.GetData() );
				
				if( bMtllibOk )
				{
					CStr oTexNameDiffuse, oTexNameNormal;
					
					poMesh->LoadMaterial(
						oFileMaterialLib.GetString(),
						poMesh->m_oMaterialName,
						&oTexNameDiffuse, 0, &oTexNameNormal );
					
					if( !bRawPoly )
					{
						if( oTexNameDiffuse.GetSize() )
						{
							poMesh->SetTex( NewTexture( oTexNameDiffuse, bTexSmooth, false ), 0 );
						}
						if( oTexNameNormal.GetSize() )
						{
							poMesh->SetTex( NewTexture( oTexNameNormal, false, false ), 1 );
						}
					}
				}
				else if( !bRawPoly && poMesh->m_oMaterialName.GetSize() )
				{
					poMesh->SetTex( NewTexture( poMesh->m_oMaterialName, bTexSmooth, false ), 0 );
				}
				
				poMesh->m_bEnableColor = false; // Hat keine Funktion bei beim Wavefront Object Meshes.
				poMesh->Init();
				
				m_oArrMesh.Append( poMesh ); // new
			}
		}
	}
	else
	{
		ERR( "OBJ Mesh %s.\n", pcFileName );
	}
}
示例#8
0
bool CGmObjAnim3::ReadXML( TiXmlNode* poParent, unsigned int uiCounter )
{
	if( !poParent )
		return false;
	
	static char acTxt_[256];
	if( uiCounter == 0 )
	{
	}
	
	switch ( poParent->Type() )
	{
	case TiXmlNode::DOCUMENT:
		LOG( "XML: Document" );
	break;
	case TiXmlNode::ELEMENT:
	{
		const char *pcName = poParent->Value();
		//LOG( "name: %s\n", pcName );
		if( !strcmp( pcName, "animation" ) )
		{
			LOG( "animation:\n" );
			
			TiXmlElement * poElement = poParent->ToElement();
			if( poElement )
			{
				int iIdx;
				CStr oMeshFileName;
				CArray<CStr> oArrAnimFileName;
				
				TiXmlAttribute* poAttrib = poElement->FirstAttribute();
				while( poAttrib )
				{
					const char *pcName = poAttrib->Name();
					if( !strcmp( pcName, "mesh" ) )
					{
						STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() );
						LOG( "%s: %s\n", poAttrib->Name(), acTxt_ );
						oMeshFileName = acTxt_;
					}
					else if( SSCANF( pcName, "anim_%d", &iIdx ) == 1 )
					{
						LOG( "%s: %d\n", poAttrib->Name(), iIdx );
						STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() );
						LOG( "%s: %s\n", poAttrib->Name(), acTxt_ );
						if( iIdx >= int( oArrAnimFileName.GetSize() ) )
							oArrAnimFileName.Resize( iIdx + 1 );
						oArrAnimFileName[iIdx] = acTxt_;
						
					}
					poAttrib = poAttrib->Next();
				}
				
				if( oMeshFileName.GetSize() )
				{
					// Model.
					m_poModel = m_poResMan_->NewModelMD5( oMeshFileName, oArrAnimFileName, false );
					
					const unsigned int uiFrameCountTotal = m_poModel->GetFrameCountTotal();
					const unsigned int uiMeshCount = m_poModel->GetMeshCount();
					const unsigned int uiAnimCount = m_poModel->GetAnimCount();
					
					m_oArrAnim.Resize( uiAnimCount );
					m_oArrAnim.Fill( 0 );
					
					m_poData->SetFrameCount( uiFrameCountTotal );
					unsigned int uiFrameIdx = 0;
					
					for( unsigned int uiAnim=0; uiAnim<uiAnimCount; ++uiAnim )
					{
						//m_poModel->SetAnim( uiAnim );	
						const unsigned int uiFrameCount = m_poModel->GetFrameCount( uiAnim );
						
						CAnim * poAnim = new CAnim;
						m_oArrAnim[uiAnim] = poAnim;
						
						poAnim->SetFrameRate( m_poModel->GetFrameRate( uiAnim ) );
						poAnim->SetFrameCount( uiFrameCount );
						
						for( unsigned int uiFrame=0; uiFrame<uiFrameCount; ++uiFrame )
						{
							CFrame * poFrame = new CFrame;
							m_poData->SetFrame( uiFrameIdx, poFrame );
							poAnim->SetFrameIndex( uiFrame, uiFrameIdx );
							++uiFrameIdx;
							
							poFrame->SetMeshCount( uiMeshCount );

							for( unsigned int uiMesh=0; uiMesh<uiMeshCount; ++uiMesh )
							{
								CGMeshMD5 * poMesh = m_poModel->GetPrecalcMesh( uiMesh, uiFrame, uiAnim );
								ASSERT( poMesh );
								poFrame->SetMesh( uiMesh, poMesh );
							}
						}

						poAnim->Init();
					}
					ASSERT( uiFrameIdx == uiFrameCountTotal );
				}
			}
		}
		else if( m_poModel )
		{
			if( !strcmp( pcName, "action" ) )
			{
				LOG( "action:\n" );
				
				TiXmlElement * poElement = poParent->ToElement();
				if( poElement )
				{
					CAction *poAction = 0;
					
					TiXmlAttribute* poAttrib = poElement->FirstAttribute();
					while( poAttrib )
					{
						const char *pcName = poAttrib->Name();
						if( !strcmp( pcName, "name" ) )
						{
							STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() );
							LOG( "%s: %s\n", poAttrib->Name(), acTxt_ );
							
							poAction = new CAction;
							poAction->m_oName = acTxt_;
							poAction->m_uiIndex = m_oArrAction.GetSize();
							m_oArrAction.Append( poAction );
						}
						else if( !strcmp( pcName, "anim" ) )
						{
							STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() );
							LOG( "%s: %s\n", poAttrib->Name(), acTxt_ );
							
							CStr oIdxSeq( acTxt_ );
							if( oIdxSeq.GetSize() && poAction )
							{
								static const char cDelim_ = ',';
								
								unsigned int i = 0;
								while( true )
								{
									int iIdx;
									if( SSCANF( oIdxSeq.GetData() + i, "%d", &iIdx ) == 1 )
									{
										LOG( "index: %d\n", iIdx );
										poAction->AppendAnimIndex( iIdx );
									}
									const int c = oIdxSeq.Find( i, cDelim_ );
									if( c < 0 )
										break;
									i = c + 1;
								}
								
							}
						}
						else if( !strcmp( pcName, "sound" ) )
						{
							STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() );
							LOG( "%s: %s\n", poAttrib->Name(), acTxt_ );
							
							TWav * poWav = m_poResMan_->NewWav( acTxt_ );
							if( poWav )
							{
								poAction->SetSoundStart( poWav );
							}
						}
						poAttrib = poAttrib->Next();
					}

					poAction->Init();
				}
			}
			/*
			else if( !strcmp( pcName, "joint_tracker" ) )
			{
				LOG( "joint_tracker:\n" );
				
				TiXmlElement * poElement = poParent->ToElement();
				if( poElement )
				{
					CJointTracker *poJointTracker = 0;
					
					TiXmlAttribute* poAttrib = poElement->FirstAttribute();
					while( poAttrib )
					{
						const char *pcName = poAttrib->Name();
						if( !strcmp( pcName, "name" ) )
						{
							STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() );
							LOG( "%s: %s\n", poAttrib->Name(), acTxt_ );
							
							poJointTracker = GetJointTracker( acTxt_ );
							if( !poJointTracker )
							{
								poJointTracker = new CJointTracker;
								poJointTracker->m_oName = acTxt_;
								m_oLstJointTracker.Append( poJointTracker );
							}
						}
						else if( !strcmp( pcName, "joint" ) && poJointTracker )
						{
							STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() );
							LOG( "%s: %s\n", poAttrib->Name(), acTxt_ );
							
							const int iJoint = m_poModel->GetJointIndex( acTxt_ );
							if( iJoint >= 0 )
								poJointTracker->New( iJoint );
						}
						poAttrib = poAttrib->Next();
					}
				}
			}
			*/
		}
	}
	break;
	case TiXmlNode::COMMENT:
		//LOG( "XML: Comment: [%s]", poParent->Value());
	break;
	case TiXmlNode::UNKNOWN:
		//LOG( "XML: Unknown" );
	break;
	case TiXmlNode::TEXT:
		//LOG( "XML: Text: [%s]", poParent->ToText()->Value() );
	break;
	case TiXmlNode::DECLARATION:
		//LOG( "XML: Declaration" );
	break;
	default:
	break;
	}
	LOG( "\n" );
	
	++uiCounter;
	
	for( TiXmlNode* poChild = poParent->FirstChild(); poChild != 0; poChild = poChild->NextSibling() ) 
	{
		ReadXML( poChild, uiCounter );
	}
	
	// Ganz am Schluss...
	if( uiCounter == 1 )
	{
	}
	return true;
}
示例#9
0
文件: OrgOp.cpp 项目: eriser/es
bool COrgOp::Load( CStr &roSrc, unsigned int uiIDOffset )
{
	CStr oStrLine;
	CStr oStrToken;
	CList<COp *> oLstPatch;
	unsigned int uiIDIn = 0;
	unsigned int uiIdxIn = 0;
	unsigned int uiCountIn = 0;
	unsigned int uiPortIn = 0;
	unsigned int uiIndexIn = 0;
	unsigned int uiCountOut = 0;
	unsigned int uiPortOut = 0;
	unsigned int uiInteralInt = 0;
	unsigned int uiInteralUInt = 0;
	unsigned int uiInteralFlt = 0;
	unsigned int i = 0;
	unsigned int uiMaxIPortIn = 0;
	unsigned int uiMaxIPortOut = 0;
	unsigned int uiMaxIInternalInt = 0;
	unsigned int uiMaxIInternalUInt = 0;
	unsigned int uiMaxIInternalFlt = 0;
	COp *poOp = 0;
	
	// <mod date="2010-12-07">
	CList<CArray<unsigned int> *> oLstArrID;
	CArray<unsigned int> * poArrID = 0;
	// </mod>
	
	// Alle Operatoren einlesen, erstellen und pseudo-patchen.
	while( 1 )
	{
		if( !Decode_GetNextLine( oStrLine, roSrc ) )
			break;
		i = 0;
		while( 1 )
		{
			if( !Decode_GetNextToken( oStrToken, oStrLine ) )
				break;

			if( !oStrToken.GetSize() )
			{
				if( i > 1 ) // Komprimierung :: -> :0:
					oStrToken = '0';
				else if( i == 0 )
					ORG_OP_LOG( "Fehler: Klassen-Name nicht vorhanden." );
			}

			// class
			if( i == 0 )
			{
				poOp = Create( oStrToken );
				if( poOp == 0 )
				{
					ORG_OP_LOG( "Fehler: Unbekannte Klasse: %s\n", oStrToken.GetData() );
					return false;
				}
				oLstPatch.Append( poOp );
			}
			// instance
			else if( i == 1 )
			{
#ifdef OP_USE_RUNTIME_INFO
				poOp->SetNameInstance( oStrToken );
#endif // OP_USE_RUNTIME_INFO
			}
			// id
			else if( i == 2 )
			{
				unsigned int uiID;
				ORG_OP_SSCANF( oStrToken, "%x", &uiID );
				poOp->SetID( uiID + uiIDOffset ); // Um keinen Konflikt zu erzeugen.
			}
			// flags
			else if( i == 3 )
			{
				unsigned int uiFlags;
				ORG_OP_SSCANF( oStrToken, "%x", &uiFlags );
				poOp->SetFlags( uiFlags );
			}
			// count_input
			else if ( i == 4 )
			{
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountIn );
				if( poOp->GetFlags() & OP_FLAG_DYNAMIC_INPUTS )
				{
					poOp->SetCountIn( uiCountIn );
				}
				else if( poOp->GetCountIn() != uiCountIn )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d Inputs unterstuetzt! "
						     "Keine dynamischen Inputs!\n", poOp->GetNameClass(), uiCountIn );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiPortIn = 0;
				uiIndexIn = 0;
				uiMaxIPortIn = 3 * uiCountIn + 4 + 1;
				
				// <mod date="2010-12-07">
				poArrID = new CArray<unsigned int>( uiCountIn );
				oLstArrID.Append( poArrID );
				// </mod>
			}
			// inputs
			else if( i < uiMaxIPortIn )
			{
				unsigned int uiVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%x", &uiVal );
				switch( uiIndexIn )
				{
				case 0: // id
					uiIDIn = uiVal;
				break;
				case 1: // port
					uiIdxIn = uiVal;
				break;
				case 2: // flags
					if( uiIDIn )
						uiIDIn += uiIDOffset; // Um keinen Konflikt zu erzeugen.
					
					// <mod date="2010-12-07">
					poArrID->At( uiPortIn ) = uiIDIn;
					poOp->In( uiPortIn ) = COp::CLink( 0, uiIdxIn, uiVal );
					//poOp->In( uiPortIn ) = COp::CLink( reinterpret_cast<COp *>( uiIDIn ), uiIdxIn, uiVal );
					// </mod>
					
					++uiPortIn;
				break;
				}
				++uiIndexIn;
				if( uiIndexIn == 3 )
					uiIndexIn = 0;
			}

			// count_output
			else if( i == uiMaxIPortIn )
			{
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountOut );
				if( poOp->GetFlags() & OP_FLAG_DYNAMIC_OUTPUTS )
				{
					poOp->SetCountOut( uiCountOut );
				}
				else if( poOp->GetCountOut() != uiCountOut )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d Outputs unterstuetzt! "
						     "Keine dynamischen Outputs!\n", poOp->GetNameClass(), uiCountOut );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiPortOut = 0;
				uiMaxIPortOut = uiCountOut + uiMaxIPortIn + 1;
			}
			// outputs
			else if( i < uiMaxIPortOut )
			{
				double dVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%lf", &dVal );
				poOp->Out( uiPortOut ) = dVal;
				++uiPortOut;
			}

			// int internal count
			else if( i == uiMaxIPortOut )
			{
				unsigned int uiCountInternalInt;
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountInternalInt );
				if( poOp->GetCountInternalInt() != uiCountInternalInt )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d Int-Interals unterstuetzt!\n", poOp->GetNameClass(), uiCountIn );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiInteralInt = 0;
				uiMaxIInternalInt = uiMaxIPortOut + uiCountInternalInt + 1;
			}
			// int internals
			else if( i < uiMaxIInternalInt )
			{
				int iVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%d", &iVal );
				poOp->SetValueInternalInt( uiInteralInt, iVal );
				++uiInteralInt;
			}
			// uint internal count
			else if( i == uiMaxIInternalInt )
			{
				unsigned int uiCountInternalUInt;
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountInternalUInt );
				if( poOp->GetCountInternalUInt() != uiCountInternalUInt )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d UInt-Interals unterstuetzt!\n", poOp->GetNameClass(), uiCountIn );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiInteralUInt = 0;
				uiMaxIInternalUInt = uiMaxIInternalInt + uiCountInternalUInt + 1;
			}
			// uint internals
			else if( i < uiMaxIInternalUInt )
			{
				unsigned int uiVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%u", &uiVal );
				poOp->SetValueInternalUInt( uiInteralUInt, uiVal );
				++uiInteralUInt;
			}
			// flt internal count
			else if( i == uiMaxIInternalUInt )
			{
				unsigned int uiCountInternalFlt;
				ORG_OP_SSCANF( oStrToken, "%x", &uiCountInternalFlt );
				if( poOp->GetCountInternalFlt() != uiCountInternalFlt )
				{
#ifdef OP_USE_RUNTIME_INFO
					ORG_OP_LOG( "Fehler: Von Klasse %s werden nicht %d Float-Interals unterstuetzt!\n", poOp->GetNameClass(), uiCountIn );
#endif // OP_USE_RUNTIME_INFO
					return false;
				}
				uiInteralFlt = 0;
				uiMaxIInternalFlt = uiMaxIInternalUInt + uiCountInternalFlt + 1;
			}
			// flt internals
			else if( i < uiMaxIInternalFlt )
			{
				double dVal;
				ORG_OP_SSCANF( oStrToken.GetData(), "%lf", &dVal );
				poOp->SetValueInternalFlt( uiInteralFlt, dVal );
				++uiInteralFlt;
			}
			else
				break;
			++i;
		}
	}

	// Pseudo-Patch nun mit echten Verbindungen versehen.
	i = oLstPatch.GetSize();
	/*
	if( i < 2 )
	{
		ORG_OP_LOG( "Fehler: Weniger als 2 Operatoren eingelesen!\n" );
		return false;
	}
	*/

	// Altes Patch löschen.
	//Clear();
	//m_poOpRootL_ = 0;
	//m_poOpRootR_ = 0;
	
	
	// <mod date="2010-12-07">
	oLstArrID.MoveToBack();
	// </mod>
	
	while( i )
	{
		--i;
		poOp = oLstPatch[i];
		
		// <mod date="2010-12-07">
		oLstArrID.GetPrev( &poArrID );
		// </mod>
		
		if( poOp )
		{
			unsigned int uiIn = poOp->GetCountIn();
			while( uiIn )
			{
				--uiIn;
				
				// <mod date="2010-12-07">
				const unsigned int uiTmpIDNext = poArrID->At( uiIn );
				//unsigned int uiTmpIDNext =
				//	reinterpret_cast<unsigned int>( poOp->In( uiIn ).GetOp() );
				// </mod>
				
				if( !uiTmpIDNext ) // ID 0 ist ungültig.
					continue;

				// Ganze Liste durchiterieren, und nach der ID aus dem aktuellen
				// Input-Array Ausschau halten!
				COp *poOpNext;
				oLstPatch.MoveToFront();
				while( oLstPatch.GetNext( &poOpNext ) )
				{
					if( poOpNext->GetID() == uiTmpIDNext )
					{
						poOp->In( uiIn ).SetOp( poOpNext );
					}
				}
			}
		}

		//if( i == 0 )
		//	m_poOpRootL_ = poOp;
		//else if ( i == 1 )
		//	m_poOpRootR_ = poOp;
	}
	
	// <mod date="2010-12-07">
	LIST_DELETE( oLstArrID, CArray<unsigned int> );
	// </mod>
	
	// Alle aufglösten Operatoren in die echte Liste einfügen...
	oLstPatch.MoveToFront();
	while( oLstPatch.GetNext( &poOp ) )
	{
#ifdef OP_USE_USER_DATA
		poOp->m_pvData = 0;
#endif // OP_USE_USER_DATA
		m_oLstOp.Append( poOp );
	}

	//UpdateAll();
	ValidateAll();
	return true;
}
示例#10
0
uint ParseConstants( CXMLElement * pBranch, TUniform ** ppUniforms )
{
	const size_t nUniformCount = pBranch->GetNumAttrs();
	//pShader->m_nUniformCount = pBranch->GetNumAttrs();

	if ( 0 == nUniformCount )
		return 0;

	(*ppUniforms) = NEW TUniform [ nUniformCount ];

	if ( NULL == (*ppUniforms) )
		return 0;

	for ( size_t n = 0; n < nUniformCount; ++n )
	{
		const CXMLAttr * pAttr = pBranch->GetAttr( n );

		CStr sType( pAttr->GetValue() );
		const char * szArray = strstr( sType.GetString(), " [" );

		TUniform * pUnfm = (*ppUniforms) + n;

		if ( szArray )
		{
			CStr sCount = szArray + 2;			// skip " [" substring
			sCount.Cut( sCount.GetSize() - 1 );	// cutoff ending ']' symbol

			pointer nOffset = szArray - sType.GetString() + 1;
			sType.Cut( nOffset );				// cutoff [##] string

			pUnfm->nCount= atoi( sCount );
		}
		else
		{
			pUnfm->nCount = 1;
			/*
			switch ( pShader->m_pUniforms[ n ].eType )
			{
				case TYPE_VEC4:
					pShader->m_pUniforms[ n ].nCount = 1;
				break;

				case TYPE_MAT4:
					pShader->m_pUniforms[ n ].nCount = 4;
				break;

				default:
					DEBUG_ASSERT( !"unexpected type" );
					pShader->m_pUniforms[ n ].nCount = 0;
			}
			*/
		}

		pUnfm->sName	= pAttr->GetName();
		pUnfm->eType	= g_pSystem->GetType( sType.GetString() );

		//pUnfm->nLoc	= pShader->GetUniformLoc( pUnfm->sName );
	}

	return nUniformCount;
}