Example #1
0
/*
* CM_LoadQ2BrushModel
*/
void CM_LoadQ2BrushModel( cmodel_state_t *cms, void *parent, void *buf, bspFormatDesc_t *format ) {
	int i;
	q2dheader_t header;

	cms->cmap_bspFormat = format;

	header = *( q2dheader_t * )buf;
	for( i = 0; i < sizeof( header ) / 4; i++ )
		( (int *)&header )[i] = LittleLong( ( (int *)&header )[i] );
	cms->cmod_base = ( uint8_t * )buf;

	// load into heap
	CMod_LoadTexinfo( cms, &header.lumps[Q2_LUMP_TEXINFO] );
	CMod_LoadPlanes( cms, &header.lumps[Q2_LUMP_PLANES] );
	CMod_LoadBrushSides( cms, &header.lumps[Q2_LUMP_BRUSHSIDES] );
	CMod_LoadBrushes( cms, &header.lumps[Q2_LUMP_BRUSHES] );
	CMod_LoadMarkBrushes( cms, &header.lumps[Q2_LUMP_LEAFBRUSHES] );
	CMod_LoadLeafs( cms, &header.lumps[Q2_LUMP_LEAFS] );
	CMod_LoadNodes( cms, &header.lumps[Q2_LUMP_NODES] );
	CMod_LoadSubmodels( cms, &header.lumps[Q2_LUMP_MODELS] );
	CMod_LoadVisibility( cms, &header.lumps[Q2_LUMP_VISIBILITY] );
	CMod_LoadEntityString( cms, &header.lumps[Q2_LUMP_ENTITIES] );

	FS_FreeFile( buf );
}
Example #2
0
/*
 * Loads in the map and all submodels
 */
cmodel_t *CM_LoadMap (char *name, qboolean clientload, unsigned *checksum)
{
    unsigned		*buf;
    int				i;
    dheader_t		header;
    int				length;
    static unsigned	last_checksum;

    map_noareas = Cvar_Get ("map_noareas", "0", 0);

    if (  !strcmp (map_name, name) && (clientload || !Cvar_VariableValue ("flushmap")) )
    {
        *checksum = last_checksum;

        if (!clientload)
        {
            memset (portalopen, 0, sizeof(portalopen));
            FloodAreaConnections ();
        }

        return &map_cmodels[0]; /* still have the right version */
    }

    /* free old stuff */
    numplanes = 0;
    numnodes = 0;
    numleafs = 0;
    numcmodels = 0;
    numvisibility = 0;
    numentitychars = 0;
    map_entitystring[0] = 0;
    map_name[0] = 0;

    if (!name || !name[0])
    {
        numleafs = 1;
        numclusters = 1;
        numareas = 1;
        *checksum = 0;
        return &map_cmodels[0]; /* cinematic servers won't have anything at all */
    }

    length = FS_LoadFile (name, (void **)&buf);

    if (!buf)
        Com_Error (ERR_DROP, "Couldn't load %s", name);

    last_checksum = LittleLong (Com_BlockChecksum (buf, length));
    *checksum = last_checksum;

    header = *(dheader_t *)buf;

    for (i=0 ; i<sizeof(dheader_t)/4 ; i++)
        ((int *)&header)[i] = LittleLong ( ((int *)&header)[i]);

    if (header.version != BSPVERSION)
        Com_Error (ERR_DROP, "CMod_LoadBrushModel: %s has wrong version number (%i should be %i)"
                   , name, header.version, BSPVERSION);

    cmod_base = (byte *)buf;

    /* load into heap */
    CMod_LoadSurfaces (&header.lumps[LUMP_TEXINFO]);
    CMod_LoadLeafs (&header.lumps[LUMP_LEAFS]);
    CMod_LoadLeafBrushes (&header.lumps[LUMP_LEAFBRUSHES]);
    CMod_LoadPlanes (&header.lumps[LUMP_PLANES]);
    CMod_LoadBrushes (&header.lumps[LUMP_BRUSHES]);
    CMod_LoadBrushSides (&header.lumps[LUMP_BRUSHSIDES]);
    CMod_LoadSubmodels (&header.lumps[LUMP_MODELS]);
    CMod_LoadNodes (&header.lumps[LUMP_NODES]);
    CMod_LoadAreas (&header.lumps[LUMP_AREAS]);
    CMod_LoadAreaPortals (&header.lumps[LUMP_AREAPORTALS]);
    CMod_LoadVisibility (&header.lumps[LUMP_VISIBILITY]);
    CMod_LoadEntityString (&header.lumps[LUMP_ENTITIES]);

    FS_FreeFile (buf);

    CM_InitBoxHull ();

    memset (portalopen, 0, sizeof(portalopen));
    FloodAreaConnections ();

    strcpy (map_name, name);

    return &map_cmodels[0];
}