/* ================ idDeclParticle::Parse ================ */ bool idDeclParticle::Parse( const char *text, const int textLength ) { idLexer src; idToken token; src.LoadMemory( text, textLength, GetFileName(), GetLineNum() ); src.SetFlags( DECL_LEXER_FLAGS ); src.SkipUntilString( "{" ); depthHack = 0.0f; while (1) { if ( !src.ReadToken( &token ) ) { break; } if ( !token.Icmp( "}" ) ) { break; } if ( !token.Icmp( "{" ) ) { idParticleStage *stage = ParseParticleStage( src ); if ( !stage ) { src.Warning( "Particle stage parse failed" ); MakeDefault(); return false; } stages.Append( stage ); continue; } if ( !token.Icmp( "depthHack" ) ) { depthHack = src.ParseFloat(); continue; } src.Warning( "bad token %s", token.c_str() ); MakeDefault(); return false; } // // calculate the bounds // bounds.Clear(); for( int i = 0; i < stages.Num(); i++ ) { GetStageBounds( stages[i] ); bounds.AddBounds( stages[i]->bounds ); } if ( bounds.GetVolume() <= 0.1f ) { bounds = idBounds( vec3_origin ).Expand( 8.0f ); } return true; }
/* ================ idDeclParticle::Parse ================ */ bool idDeclParticle::Parse( const char* text, const int textLength, bool allowBinaryVersion ) { if( cvarSystem->GetCVarBool( "fs_buildresources" ) ) { fileSystem->AddParticlePreload( GetName() ); } idLexer src; idToken token; unsigned int sourceChecksum = 0; idStrStatic< MAX_OSPATH > generatedFileName; if( allowBinaryVersion ) { // Try to load the generated version of it // If successful, // - Create an MD5 of the hash of the source // - Load the MD5 of the generated, if they differ, create a new generated generatedFileName = "generated/particles/"; generatedFileName.AppendPath( GetName() ); generatedFileName.SetFileExtension( ".bprt" ); idFileLocal file( fileSystem->OpenFileReadMemory( generatedFileName ) ); sourceChecksum = MD5_BlockChecksum( text, textLength ); if( binaryLoadParticles.GetBool() && LoadBinary( file, sourceChecksum ) ) { return true; } } src.LoadMemory( text, textLength, GetFileName(), GetLineNum() ); src.SetFlags( DECL_LEXER_FLAGS ); src.SkipUntilString( "{" ); depthHack = 0.0f; while( 1 ) { if( !src.ReadToken( &token ) ) { break; } if( !token.Icmp( "}" ) ) { break; } if( !token.Icmp( "{" ) ) { if( stages.Num() >= MAX_PARTICLE_STAGES ) { src.Error( "Too many particle stages" ); MakeDefault(); return false; } idParticleStage* stage = ParseParticleStage( src ); if( !stage ) { src.Warning( "Particle stage parse failed" ); MakeDefault(); return false; } stages.Append( stage ); continue; } if( !token.Icmp( "depthHack" ) ) { depthHack = src.ParseFloat(); continue; } src.Warning( "bad token %s", token.c_str() ); MakeDefault(); return false; } // don't calculate bounds or write binary files for defaulted ( non-existent ) particles in resource builds if( fileSystem->UsingResourceFiles() ) { bounds = idBounds( vec3_origin ).Expand( 8.0f ); return true; } // // calculate the bounds // bounds.Clear(); for( int i = 0; i < stages.Num(); i++ ) { GetStageBounds( stages[i] ); bounds.AddBounds( stages[i]->bounds ); } if( bounds.GetVolume() <= 0.1f ) { bounds = idBounds( vec3_origin ).Expand( 8.0f ); } if( allowBinaryVersion && binaryLoadParticles.GetBool() ) { idLib::Printf( "Writing %s\n", generatedFileName.c_str() ); idFileLocal outputFile( fileSystem->OpenFileWrite( generatedFileName, "fs_basepath" ) ); WriteBinary( outputFile, sourceChecksum ); } return true; }