Esempio n. 1
0
void MapLoader::ParseMeshBlock(Mesh * mesh) {
	while (currentToken != endIter && currentToken->first != MapTokenBlockEnd) {
		if (currentToken->first == MapTokenVertices) {
			TGen::VertexStructure vertexStructure;
			
			StepToken();
			while (currentToken->first != MapTokenEndOfLine && currentToken->first != MapTokenBlockStart) {
				std::string format = getStringToken("mesh.vertices: expecting string value for format", false, false);
				StepToken();
				vertexStructure.AddElement(format);
			}
			
			while (currentToken->first == MapTokenEndOfLine) {
				StepToken();
			}	

			if (currentToken->first != MapTokenBlockStart) 
				throw TGen::RuntimeException("MapLoader::ParseMeshBlock", "mesh.vertices: expecting block start, not '" + currentToken->second + "'!");
			
			StepToken();
			
			MeshData * meshData = new MeshData(vertexStructure);
			StepToken();
			
			std::cout << "entering vertices..." << std::endl;
			ParseVertices(meshData);
			std::cout << "leaving vertices" << std::endl;
		}
		else if (currentToken->first == MapTokenIndices) {
			
		}
		else if (currentToken->second == "primitive") {
			StepToken();
			std::string primitiveType = getStringToken("mesh.primitive: expecting string value for type", false, false);
			
		}
		else if (currentToken->first != MapTokenEndOfLine) {
			throw TGen::RuntimeException("MapLoader::ParseMeshBlock", "not expecting '" + currentToken->second + "'!");						
		}
		
		StepToken();
	}
	
}
/*
================
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;
}
Esempio n. 3
0
/*
================
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;
}