bool ParseTxt(TxtParser& parser) { ParseNodes(parser); if (parser.failed) return false; return true; }
/* ================ idCollisionModelManagerLocal::ParseNodes ================ */ cm_node_t *idCollisionModelManagerLocal::ParseNodes( idLexer *src, cm_model_t *model, cm_node_t *parent ) { cm_node_t *node; model->numNodes++; node = AllocNode( model, model->numNodes < NODE_BLOCK_SIZE_SMALL ? NODE_BLOCK_SIZE_SMALL : NODE_BLOCK_SIZE_LARGE ); node->brushes = NULL; node->polygons = NULL; node->parent = parent; src->ExpectTokenString( "(" ); node->planeType = src->ParseInt(); node->planeDist = src->ParseFloat(); src->ExpectTokenString( ")" ); if ( node->planeType != -1 ) { node->children[0] = ParseNodes( src, model, node ); node->children[1] = ParseNodes( src, model, node ); } return node; }
bool GenerateGeoObjectsData(string const & featuresFile, string const & nodesFile, string const & dataFile) { set<uint64_t> nodeIds; if (!ParseNodes(nodesFile, nodeIds)) return false; auto const needSerialize = [&nodeIds](FeatureBuilder1 & fb) { auto & fb2 = static_cast<FeatureBuilder2 &>(fb); return fb2.IsPoint() || fb2.IsArea() || (!fb.GetOsmIds().empty() && nodeIds.count(fb.GetMostGenericOsmId().GetEncodedId()) != 0); }; DataHeader header; header.SetGeometryCodingParams(serial::GeometryCodingParams()); header.SetScales({scales::GetUpperScale()}); LocalityCollector localityCollector(dataFile, header, static_cast<uint32_t>(base::SecondsSinceEpoch())); return GenerateLocalityDataImpl(localityCollector, needSerialize, featuresFile, dataFile); }
/* ================= idRenderWorldLocal::InitFromMap A NULL or empty name will make a world without a map model, which is still useful for displaying a bare model ================= */ bool idRenderWorldLocal::InitFromMap( const char* name ) { idLexer* src; idToken token; idRenderModel* lastModel; // if this is an empty world, initialize manually if( !name || !name[0] ) { FreeWorld(); mapName.Clear(); ClearWorld(); return true; } // load it idStrStatic< MAX_OSPATH > filename = name; filename.SetFileExtension( PROC_FILE_EXT ); // check for generated file idStrStatic< MAX_OSPATH > generatedFileName = filename; generatedFileName.Insert( "generated/", 0 ); generatedFileName.SetFileExtension( "bproc" ); // if we are reloading the same map, check the timestamp // and try to skip all the work ID_TIME_T currentTimeStamp = fileSystem->GetTimestamp( filename ); if( name == mapName ) { if( fileSystem->InProductionMode() || ( currentTimeStamp != FILE_NOT_FOUND_TIMESTAMP && currentTimeStamp == mapTimeStamp ) ) { common->Printf( "idRenderWorldLocal::InitFromMap: retaining existing map\n" ); FreeDefs(); TouchWorldModels(); AddWorldModelEntities(); ClearPortalStates(); return true; } common->Printf( "idRenderWorldLocal::InitFromMap: timestamp has changed, reloading.\n" ); } FreeWorld(); // see if we have a generated version of this static const byte BPROC_VERSION = 1; static const unsigned int BPROC_MAGIC = ( 'P' << 24 ) | ( 'R' << 16 ) | ( 'O' << 8 ) | BPROC_VERSION; bool loaded = false; idFileLocal file( fileSystem->OpenFileReadMemory( generatedFileName ) ); if( file != NULL ) { int numEntries = 0; int magic = 0; file->ReadBig( magic ); if( magic == BPROC_MAGIC ) { file->ReadBig( numEntries ); file->ReadString( mapName ); file->ReadBig( mapTimeStamp ); loaded = true; for( int i = 0; i < numEntries; i++ ) { idStrStatic< MAX_OSPATH > type; file->ReadString( type ); type.ToLower(); if( type == "model" ) { idRenderModel* lastModel = ReadBinaryModel( file ); if( lastModel == NULL ) { loaded = false; break; } renderModelManager->AddModel( lastModel ); localModels.Append( lastModel ); } else if( type == "shadowmodel" ) { idRenderModel* lastModel = ReadBinaryModel( file ); if( lastModel == NULL ) { loaded = false; break; } renderModelManager->AddModel( lastModel ); localModels.Append( lastModel ); } else if( type == "interareaportals" ) { ReadBinaryAreaPortals( file ); } else if( type == "nodes" ) { ReadBinaryNodes( file ); } else { idLib::Error( "Binary proc file failed, unexpected type %s\n", type.c_str() ); } } } } if( !loaded ) { src = new( TAG_RENDER ) idLexer( filename, LEXFL_NOSTRINGCONCAT | LEXFL_NODOLLARPRECOMPILE ); if( !src->IsLoaded() ) { common->Printf( "idRenderWorldLocal::InitFromMap: %s not found\n", filename.c_str() ); ClearWorld(); return false; } mapName = name; mapTimeStamp = currentTimeStamp; // if we are writing a demo, archive the load command if( common->WriteDemo() ) { WriteLoadMap(); } if( !src->ReadToken( &token ) || token.Icmp( PROC_FILE_ID ) ) { common->Printf( "idRenderWorldLocal::InitFromMap: bad id '%s' instead of '%s'\n", token.c_str(), PROC_FILE_ID ); delete src; return false; } int numEntries = 0; idFileLocal outputFile( fileSystem->OpenFileWrite( generatedFileName, "fs_basepath" ) ); if( outputFile != NULL ) { int magic = BPROC_MAGIC; outputFile->WriteBig( magic ); outputFile->WriteBig( numEntries ); outputFile->WriteString( mapName ); outputFile->WriteBig( mapTimeStamp ); } // parse the file while( 1 ) { if( !src->ReadToken( &token ) ) { break; } common->UpdateLevelLoadPacifier(); if( token == "model" ) { lastModel = ParseModel( src, name, currentTimeStamp, outputFile ); // add it to the model manager list renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map localModels.Append( lastModel ); numEntries++; continue; } if( token == "shadowModel" ) { lastModel = ParseShadowModel( src, outputFile ); // add it to the model manager list renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map localModels.Append( lastModel ); numEntries++; continue; } if( token == "interAreaPortals" ) { ParseInterAreaPortals( src, outputFile ); numEntries++; continue; } if( token == "nodes" ) { ParseNodes( src, outputFile ); numEntries++; continue; } src->Error( "idRenderWorldLocal::InitFromMap: bad token \"%s\"", token.c_str() ); } delete src; if( outputFile != NULL ) { outputFile->Seek( 0, FS_SEEK_SET ); int magic = BPROC_MAGIC; outputFile->WriteBig( magic ); outputFile->WriteBig( numEntries ); } } // if it was a trivial map without any areas, create a single area if( !numPortalAreas ) { ClearWorld(); } // find the points where we can early-our of reference pushing into the BSP tree CommonChildrenArea_r( &areaNodes[0] ); AddWorldModelEntities(); ClearPortalStates(); // done! return true; }
/* ================ idCollisionModelManagerLocal::ParseCollisionModel ================ */ cm_model_t* idCollisionModelManagerLocal::ParseCollisionModel( idLexer* src ) { cm_model_t* model; idToken token; if( numModels >= MAX_SUBMODELS ) { common->Error( "LoadModel: no free slots" ); return NULL; } model = AllocModel(); models[numModels ] = model; numModels++; // parse the file src->ExpectTokenType( TT_STRING, 0, &token ); model->name = token; src->ExpectTokenString( "{" ); while( !src->CheckTokenString( "}" ) ) { src->ReadToken( &token ); if( token == "vertices" ) { ParseVertices( src, model ); continue; } if( token == "edges" ) { ParseEdges( src, model ); continue; } if( token == "nodes" ) { src->ExpectTokenString( "{" ); model->node = ParseNodes( src, model, NULL ); src->ExpectTokenString( "}" ); continue; } if( token == "polygons" ) { ParsePolygons( src, model ); continue; } if( token == "brushes" ) { ParseBrushes( src, model ); continue; } src->Error( "ParseCollisionModel: bad token \"%s\"", token.c_str() ); } // calculate edge normals checkCount++; CalculateEdgeNormals( model, model->node ); // get model bounds from brush and polygon bounds CM_GetNodeBounds( &model->bounds, model->node ); // get model contents model->contents = CM_GetNodeContents( model->node ); // total memory used by this model model->usedMemory = model->numVertices * sizeof( cm_vertex_t ) + model->numEdges * sizeof( cm_edge_t ) + model->polygonMemory + model->brushMemory + model->numNodes * sizeof( cm_node_t ) + model->numPolygonRefs * sizeof( cm_polygonRef_t ) + model->numBrushRefs * sizeof( cm_brushRef_t ); return model; }
/* ================= idRenderWorldLocal::InitFromMap A NULL or empty name will make a world without a map model, which is still useful for displaying a bare model ================= */ bool idRenderWorldLocal::InitFromMap( const char *name ) { idLexer * src; idToken token; idStr filename; idRenderModel * lastModel; // if this is an empty world, initialize manually if ( !name || !name[0] ) { FreeWorld(); mapName.Clear(); ClearWorld(); return true; } // load it filename = name; filename.SetFileExtension( PROC_FILE_EXT ); // if we are reloading the same map, check the timestamp // and try to skip all the work ID_TIME_T currentTimeStamp; fileSystem->ReadFile( filename, NULL, ¤tTimeStamp ); if ( name == mapName ) { if ( currentTimeStamp != FILE_NOT_FOUND_TIMESTAMP && currentTimeStamp == mapTimeStamp ) { common->Printf( "idRenderWorldLocal::InitFromMap: retaining existing map\n" ); FreeDefs(); TouchWorldModels(); AddWorldModelEntities(); ClearPortalStates(); return true; } common->Printf( "idRenderWorldLocal::InitFromMap: timestamp has changed, reloading.\n" ); } FreeWorld(); src = new idLexer( filename, LEXFL_NOSTRINGCONCAT | LEXFL_NODOLLARPRECOMPILE ); if ( !src->IsLoaded() ) { common->Printf( "idRenderWorldLocal::InitFromMap: %s not found\n", filename.c_str() ); ClearWorld(); return false; } mapName = name; mapTimeStamp = currentTimeStamp; // if we are writing a demo, archive the load command if ( session->writeDemo ) { WriteLoadMap(); } if ( !src->ReadToken( &token ) || token.Icmp( PROC_FILE_ID ) ) { common->Printf( "idRenderWorldLocal::InitFromMap: bad id '%s' instead of '%s'\n", token.c_str(), PROC_FILE_ID ); delete src; return false; } // parse the file while ( 1 ) { if ( !src->ReadToken( &token ) ) { break; } if ( token == "model" ) { lastModel = ParseModel( src ); // add it to the model manager list renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map localModels.Append( lastModel ); continue; } if ( token == "shadowModel" ) { lastModel = ParseShadowModel( src ); // add it to the model manager list renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map localModels.Append( lastModel ); continue; } if ( token == "interAreaPortals" ) { ParseInterAreaPortals( src ); continue; } if ( token == "nodes" ) { ParseNodes( src ); continue; } src->Error( "idRenderWorldLocal::InitFromMap: bad token \"%s\"", token.c_str() ); } delete src; // if it was a trivial map without any areas, create a single area if ( !numPortalAreas ) { ClearWorld(); } // find the points where we can early-our of reference pushing into the BSP tree CommonChildrenArea_r( &areaNodes[0] ); AddWorldModelEntities(); ClearPortalStates(); // done! return true; }
/* ================ idAASFileLocal::Load ================ */ bool idAASFileLocal::Load( const idStr &fileName, unsigned int mapFileCRC ) { idLexer src( LEXFL_NOFATALERRORS | LEXFL_NOSTRINGESCAPECHARS | LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES ); idToken token; int depth; unsigned int c; name = fileName; crc = mapFileCRC; common->Printf( "[Load AAS]\n" ); common->Printf( "loading %s\n", name.c_str() ); if ( !src.LoadFile( name ) ) { return false; } if ( !src.ExpectTokenString( AAS_FILEID ) ) { common->Warning( "Not an AAS file: '%s'", name.c_str() ); return false; } if ( !src.ReadToken( &token ) || token != AAS_FILEVERSION ) { common->Warning( "AAS file '%s' has version %s instead of %s", name.c_str(), token.c_str(), AAS_FILEVERSION ); return false; } if ( !src.ExpectTokenType( TT_NUMBER, TT_INTEGER, &token ) ) { common->Warning( "AAS file '%s' has no map file CRC", name.c_str() ); return false; } c = token.GetUnsignedIntValue(); if ( mapFileCRC && c != mapFileCRC ) { common->Warning( "AAS file '%s' is out of date", name.c_str() ); return false; } // clear the file in memory Clear(); // parse the file while ( 1 ) { if ( !src.ReadToken( &token ) ) { break; } if ( token == "settings" ) { if ( !settings.FromParser( src ) ) { return false; } } else if ( token == "planes" ) { if ( !ParsePlanes( src ) ) { return false; } } else if ( token == "vertices" ) { if ( !ParseVertices( src ) ) { return false; } } else if ( token == "edges" ) { if ( !ParseEdges( src ) ) { return false; } } else if ( token == "edgeIndex" ) { if ( !ParseIndex( src, edgeIndex ) ) { return false; } } else if ( token == "faces" ) { if ( !ParseFaces( src ) ) { return false; } } else if ( token == "faceIndex" ) { if ( !ParseIndex( src, faceIndex ) ) { return false; } } else if ( token == "areas" ) { if ( !ParseAreas( src ) ) { return false; } } else if ( token == "nodes" ) { if ( !ParseNodes( src ) ) { return false; } } else if ( token == "portals" ) { if ( !ParsePortals( src ) ) { return false; } } else if ( token == "portalIndex" ) { if ( !ParseIndex( src, portalIndex ) ) { return false; } } else if ( token == "clusters" ) { if ( !ParseClusters( src ) ) { return false; } } else { src.Error( "idAASFileLocal::Load: bad token \"%s\"", token.c_str() ); return false; } } FinishAreas(); depth = MaxTreeDepth(); if ( depth > MAX_AAS_TREE_DEPTH ) { src.Error( "idAASFileLocal::Load: tree depth = %d", depth ); } common->Printf( "done.\n" ); return true; }
bool MD5Renderer::InitFromMap( const char *name ) { idLexer * src; idToken token; idStr filename; idRenderModel * lastModel; // if this is an empty world, initialize manually if ( !name || !name[0] ) { FreeWorld(); mapName.Clear(); ClearWorld(); return true; } // load it filename = name; filename.SetFileExtension( PROC_FILE_EXT ); FreeWorld(); src = new idLexer( filename, LEXFL_NOSTRINGCONCAT | LEXFL_NODOLLARPRECOMPILE ); if ( !src->IsLoaded() ) { //common->Printf( "idRenderWorldLocal::InitFromMap: %s not found\n", filename.c_str() ); ClearWorld(); return false; } mapName = name; if ( !src->ReadToken( &token ) || token.Icmp( PROC_FILE_ID ) ) { //common->Printf( "idRenderWorldLocal::InitFromMap: bad id '%s' instead of '%s'\n", token.c_str(), PROC_FILE_ID ); delete src; return false; } int num = 0; // parse the file while ( 1 ) { if ( !src->ReadToken( &token ) ) { break; } if ( token == "model" ) { //lastModel = ParseModel( src ); ParseModel( src ); num++; // add it to the model manager list //renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map //localModels.Append( lastModel ); continue; } if ( token == "shadowModel" ) { //lastModel = ParseShadowModel( src ); // add it to the model manager list //renderModelManager->AddModel( lastModel ); // save it in the list to free when clearing this map //localModels.Append( lastModel ); continue; } if ( token == "interAreaPortals" ) { ParseInterAreaPortals( src ); continue; } if ( token == "nodes" ) { ParseNodes( src ); continue; } src->Error( "idRenderWorldLocal::InitFromMap: bad token \"%s\"", token.c_str() ); } delete src; // if it was a trivial map without any areas, create a single area if ( !numPortalAreas ) { ClearWorld(); } for (size_t i = 0; i < gameLocal.mCurrScene->Areas_.size(); ++i) { gameLocal.mCurrScene->Areas_.at(i)->CreateBuffers(); } // find the points where we can early-our of reference pushing into the BSP tree //CommonChildrenArea_r( &areaNodes[0] ); //AddWorldModelEntities(); //ClearPortalStates(); // done! return true; }