/* ================ ParseEntities Parses the dentdata string into entities ================ */ void ParseEntities( void ) { num_entities = 0; ParseFromMemory( dentdata, entdatasize ); while ( ParseEntity () ) { } }
/** * @brief Parses the curTile->entdata string into entities * @sa UnparseEntities * @sa ParseEntity */ void ParseEntities (void) { num_entities = 0; ParseFromMemory(curTile->entdata, curTile->entdatasize); while (ParseEntity() != nullptr) { } }
void ParseEntities( void ){ numEntities = 0; ParseFromMemory( bspEntData, bspEntDataSize ); while ( ParseEntity() ) ; /* ydnar: set number of bsp entities in case a map is loaded on top */ numBSPEntities = numEntities; }
/*!*************************************************************************** @Function ParseFromFile @Input pszFileName PFX file name @Output pReturnError error string @Return EPVRTError PVR_SUCCESS for success parsing file PVR_FAIL if file doesn't exist or is invalid @Description Reads the PFX file and calls the parser. *****************************************************************************/ EPVRTError CPVRTPFXParser::ParseFromFile(const char * const pszFileName, CPVRTString * const pReturnError) { CPVRTResourceFile PfxFile(pszFileName); if (!PfxFile.IsOpen()) { *pReturnError = CPVRTString("Unable to open file ") + pszFileName; return PVR_FAIL; } return ParseFromMemory(PfxFile.StringPtr(), pReturnError); }
//----------------------------------------------------------------------------- // Create binary compiled version of VCD. Stores to a dictionary for later // post processing //----------------------------------------------------------------------------- bool CreateTargetFile_VCD( const char *pSourceName, const char *pTargetName, bool bWriteToZip, bool bLittleEndian ) { CUtlBuffer sourceBuf; if ( !scriptlib->ReadFileToBuffer( pSourceName, sourceBuf ) ) { return false; } CRC32_t crcSource; CRC32_Init( &crcSource ); CRC32_ProcessBuffer( &crcSource, sourceBuf.Base(), sourceBuf.TellMaxPut() ); CRC32_Final( &crcSource ); ParseFromMemory( (char *)sourceBuf.Base(), sourceBuf.TellMaxPut() ); CChoreoScene *pChoreoScene = ChoreoLoadScene( pSourceName, NULL, &g_SceneTokenProcessor, Msg ); if ( !pChoreoScene ) { return false; } int iScene = g_SceneFiles.AddToTail(); g_SceneFiles[iScene].fileName.Set( pSourceName ); // Walk all events looking for SPEAK events CChoreoEvent *pEvent; for ( int i = 0; i < pChoreoScene->GetNumEvents(); ++i ) { pEvent = pChoreoScene->GetEvent( i ); FindSoundsInEvent( pEvent, g_SceneFiles[iScene].soundList ); } // calc duration g_SceneFiles[iScene].msecs = (unsigned int)( pChoreoScene->FindStopTime() * 1000.0f + 0.5f ); // compile to binary buffer g_SceneFiles[iScene].compiledBuffer.SetBigEndian( !bLittleEndian ); pChoreoScene->SaveToBinaryBuffer( g_SceneFiles[iScene].compiledBuffer, crcSource, &g_ChoreoStringPool ); unsigned int compressedSize; unsigned char *pCompressedBuffer = LZMA_Compress( (unsigned char *)g_SceneFiles[iScene].compiledBuffer.Base(), g_SceneFiles[iScene].compiledBuffer.TellMaxPut(), &compressedSize ); if ( pCompressedBuffer ) { // replace the compiled buffer with the compressed version g_SceneFiles[iScene].compiledBuffer.Purge(); g_SceneFiles[iScene].compiledBuffer.EnsureCapacity( compressedSize ); g_SceneFiles[iScene].compiledBuffer.Put( pCompressedBuffer, compressedSize ); free( pCompressedBuffer ); } delete pChoreoScene; return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : wnd - // *params - // Output : static void //----------------------------------------------------------------------------- void CBaseEventPropertiesDialog::ParseTags( CEventParams *params ) { strcpy( params->m_szTagName, "" ); strcpy( params->m_szTagWav, "" ); if ( params->m_bUsesTag ) { // Parse out the two tokens char selectedText[ 512 ]; selectedText[ 0 ] = 0; HWND control = GetControl( IDC_TAGS ); if ( control ) { SendMessage( control, WM_GETTEXT, (WPARAM)sizeof( selectedText ), (LPARAM)selectedText ); } ParseFromMemory( selectedText, strlen( selectedText ) ); if ( TokenAvailable() ) { GetToken( false ); char tagname[ 256 ]; strcpy( tagname, token ); if ( TokenAvailable() ) { GetToken( false ); char wavename[ 256 ]; strcpy( wavename, token ); // Valid strcpy( params->m_szTagName, tagname ); strcpy( params->m_szTagWav, wavename ); } else { params->m_bUsesTag = false; } } else { params->m_bUsesTag = false; } } }
void LoadWadcfgfile (const char *filename) { int count = 0; int size; char *buffer; size = LoadFile (filename, &buffer); ParseFromMemory (buffer, size); while (GetToken (true)) { bool include = false; wadpath_t *current; if (!stricmp (g_token, "include")) { include = true; if (!GetToken (true)) { Error ("parsing '%s': unexpected end of file.", filename); } } Developer (DEVELOPER_LEVEL_MESSAGE, "LoadWadcfgfile: adding wad file '%s'.\n", g_token); if (g_iNumWadPaths >= MAX_WADPATHS) { Error ("parsing '%s': too many wad files.", filename); } count++; current = (wadpath_t *)malloc (sizeof (wadpath_t)); hlassume (current != NULL, assume_NoMemory); g_pWadPaths[g_iNumWadPaths] = current; g_iNumWadPaths++; safe_strncpy (current->path, g_token, _MAX_PATH); current->usedbymap = true; // what's this? current->usedtextures = 0; if (include) { Developer (DEVELOPER_LEVEL_MESSAGE, "LoadWadcfgfile: including '%s'.\n", current->path); g_WadInclude.push_back(current->path); } } free (buffer); // should not be freed because it is still being used as script buffer Log ("Using custom wadfile configuration: '%s' (with %i wad%s)\n", filename, count, count > 1 ? "s" : ""); }
void LoadSurfaceExtraFile( const char *path ) { char srfPath[ 1024 ]; surfaceExtra_t *se; int surfaceNum, size; byte *buffer; /* dummy check */ if( path == NULL || path[ 0 ] == '\0' ) return; /* load the file */ strcpy( srfPath, path ); StripExtension( srfPath ); strcat( srfPath, ".srf" ); Sys_Printf( "Loading %s\n", srfPath ); size = LoadFile( srfPath, (void**) &buffer ); if( size <= 0 ) { Sys_Printf( "WARNING: Unable to find surface file %s, using defaults.\n", srfPath ); return; } /* parse the file */ ParseFromMemory( (char *) buffer, size ); /* tokenize it */ while( 1 ) { /* test for end of file */ if( !GetToken( qtrue ) ) break; /* default? */ if( !Q_stricmp( token, "default" ) ) se = &seDefault; /* surface number */ else { surfaceNum = atoi( token ); if( surfaceNum < 0 || surfaceNum > MAX_MAP_DRAW_SURFS ) Error( "ReadSurfaceExtraFile(): %s, line %d: bogus surface num %d", srfPath, scriptline, surfaceNum ); while( surfaceNum >= numSurfaceExtras ) se = AllocSurfaceExtra(); se = &surfaceExtras[ surfaceNum ]; } /* handle { } section */ if( !GetToken( qtrue ) || strcmp( token, "{" ) ) Error( "ReadSurfaceExtraFile(): %s, line %d: { not found", srfPath, scriptline ); while( 1 ) { if( !GetToken( qtrue ) ) break; if( !strcmp( token, "}" ) ) break; /* shader */ if( !Q_stricmp( token, "shader" ) ) { GetToken( qfalse ); se->si = ShaderInfoForShader( token ); } /* parent surface number */ else if( !Q_stricmp( token, "parent" ) ) { GetToken( qfalse ); se->parentSurfaceNum = atoi( token ); } /* entity number */ else if( !Q_stricmp( token, "entity" ) ) { GetToken( qfalse ); se->entityNum = atoi( token ); } /* cast shadows */ else if( !Q_stricmp( token, "castShadows" ) ) { GetToken( qfalse ); se->castShadows = atoi( token ); } /* recv shadows */ else if( !Q_stricmp( token, "receiveShadows" ) ) { GetToken( qfalse ); se->recvShadows = atoi( token ); } /* lightmap sample size */ else if( !Q_stricmp( token, "sampleSize" ) ) { GetToken( qfalse ); se->sampleSize = atoi( token ); } /* longest curve */ else if( !Q_stricmp( token, "longestCurve" ) ) { GetToken( qfalse ); se->longestCurve = atof( token ); } /* lightmap axis vector */ else if( !Q_stricmp( token, "lightmapAxis" ) ) Parse1DMatrix( 3, se->lightmapAxis ); /* ignore all other tokens on the line */ while( TokenAvailable() ) GetToken( qfalse ); } } /* free the buffer */ free( buffer ); }
void CMapEntities::CheckUpdateMap( char const *mapname ) { if ( !mapname || !mapname[ 0 ] ) return; if ( !stricmp( mapname, m_szCurrentMap ) ) return; // Latch off the name of the map Q_strncpy( m_szCurrentMap, mapname, sizeof( m_szCurrentMap ) ); // Load names from map m_Entities.RemoveAll(); FileHandle_t hfile = filesystem->Open( mapname, "rb" ); if ( hfile == FILESYSTEM_INVALID_HANDLE ) return; dheader_t header; filesystem->Read( &header, sizeof( header ), hfile ); // Check the header if ( header.ident != IDBSPHEADER || header.version < MINBSPVERSION || header.version > BSPVERSION ) { Con_ErrorPrintf( "BSP file %s is wrong version (%i), expected (%i)\n", mapname, header.version, BSPVERSION ); filesystem->Close( hfile ); return; } // Find the LUMP_PAKFILE offset lump_t *entlump = &header.lumps[ LUMP_ENTITIES ]; if ( entlump->filelen <= 0 ) { Con_ErrorPrintf( "BSP file %s is missing entity lump\n", mapname ); // It's empty or only contains a file header ( so there are no entries ), so don't add to search paths filesystem->Close( hfile ); return; } // Seek to correct position filesystem->Seek( hfile, entlump->fileofs, FILESYSTEM_SEEK_HEAD ); char *buffer = new char[ entlump->filelen + 1 ]; Assert( buffer ); filesystem->Read( buffer, entlump->filelen, hfile ); filesystem->Close( hfile ); buffer[ entlump->filelen ] = 0; // Now we have entity buffer, now parse it ParseFromMemory( buffer, entlump->filelen ); while ( 1 ) { if (!GetToken (true)) break; if (Q_stricmp (token, "{") ) Error ("ParseEntity: { not found"); char name[ 256 ]; char origin[ 256 ]; char angles[ 256 ]; name[ 0 ] = 0; origin[ 0 ] = 0; angles[ 0 ] = 0; do { char key[ 256 ]; char value[ 256 ]; if (!GetToken (true)) { Error ("ParseEntity: EOF without closing brace"); } if (!Q_stricmp (token, "}") ) break; Q_strncpy( key, token, sizeof( key ) ); GetToken (false); Q_strncpy( value, token, sizeof( value ) ); // Con_Printf( "Parsed %s -- %s\n", key, value ); if ( !Q_stricmp( key, "name" ) ) { Q_strncpy( name, value, sizeof( name ) ); } if ( !Q_stricmp( key, "targetname" ) ) { Q_strncpy( name, value, sizeof( name ) ); } if ( !Q_stricmp( key, "origin" ) ) { Q_strncpy( origin, value, sizeof( origin ) ); } if ( !Q_stricmp( key, "angles" ) ) { Q_strncpy( angles, value, sizeof( angles ) ); } } while (1); if ( name[ 0 ] ) { if ( FindNamedEntity( name ) == - 1 ) { CMapEntityData ent; float org[3]; if ( origin[ 0 ] ) { if ( 3 == sscanf( origin, "%f %f %f", &org[ 0 ], &org[ 1 ], &org[ 2 ] ) ) { ent.origin = Vector( org[ 0 ], org[ 1 ], org[ 2 ] ); // Con_Printf( "read %f %f %f for entity %s\n", org[0], org[1], org[2], name ); } } if ( angles[ 0 ] ) { if ( 3 == sscanf( angles, "%f %f %f", &org[ 0 ], &org[ 1 ], &org[ 2 ] ) ) { ent.angles = QAngle( org[ 0 ], org[ 1 ], org[ 2 ] ); // Con_Printf( "read %f %f %f for entity %s\n", org[0], org[1], org[2], name ); } } m_Entities.Insert( name, ent ); } } } delete[] buffer; }