Example #1
0
//=====================================================================================
//	CreateAreas
//=====================================================================================
geBoolean CreateAreas(GBSP_Node *RootNode)
{
	GBSP_Model	*pModel;
	int32		m;

	GHook.Printf(" --- Create Area Leafs --- \n");

	// Clear all model area info
	for (pModel = BSPModels+1, m=1; m < NumBSPModels; m++, pModel++)	// Skip world model
	{
		pModel->Areas[0] = pModel->Areas[1] = 0;
		pModel->IsAreaPortal = GE_FALSE;
	}

	if (GFXAreas)
		geRam_Free(GFXAreas);
	if (GFXAreaPortals)
		geRam_Free(GFXAreaPortals);

	GFXAreas = GE_RAM_ALLOCATE_ARRAY(GFX_Area, MAX_AREAS);

	if (!GFXAreas)
		return GE_FALSE;

	GFXAreaPortals = GE_RAM_ALLOCATE_ARRAY(GFX_AreaPortal, MAX_AREA_PORTALS);

	if (!GFXAreaPortals)
		return GE_FALSE;
	
	NumGFXAreas = 1;			// 0 is invalid 
	NumGFXAreaPortals = 0;

	if (!CreateAreas_r(RootNode))
	{
		GHook.Error("Could not create model areas.\n");
		return GE_FALSE;
	}

	if (!FinishAreaPortals_r(RootNode))
	{
		GHook.Error("CreateAreas: FinishAreaPortals_r failed.\n");
		return GE_FALSE;
	}

	if (!FinishAreas())
	{
		GHook.Error("Could not finalize model areas.\n");
		return GE_FALSE;
	}

	//GHook.Printf("Num Areas            : %5i\n", NumGFXAreas-1);

	return GE_TRUE;
}
Example #2
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;
}