Example #1
0
/*
* CM_LoadMap
* Loads in the map and all submodels
* 
*  for spawning a server with no map at all, call like this:
*  CM_LoadMap( "", qfalse, &checksum );	// no real map
*/
cmodel_t *CM_LoadMap( cmodel_state_t *cms, const char *name, qboolean clientload, unsigned *checksum )
{
	int length;
	unsigned *buf;
	char *header;
	const modelFormatDescr_t *descr;
	bspFormatDesc_t *bspFormat = NULL;

	assert( cms );
	assert( name && strlen( name ) < MAX_CONFIGSTRING_CHARS );
	assert( checksum );

	cms->map_clientload = clientload;

	if( !strcmp( cms->map_name, name ) && ( clientload || !Cvar_Value( "flushmap" ) ) )
	{
		*checksum = cms->checksum;

		if( !clientload )
		{
			memset( cms->map_areaportals, 0, cms->numareas * cms->numareas * sizeof( *cms->map_areaportals ) );
			CM_FloodAreaConnections( cms );
		}

		return cms->map_cmodels; // still have the right version
	}

	CM_Clear( cms );

	if( !name || !name[0] )
	{
		cms->numleafs = 1;
		cms->numcmodels = 2;
		*checksum = 0;
		return cms->map_cmodels;    // cinematic servers won't have anything at all
	}

	//
	// load the file
	//
	length = FS_LoadFile( name, ( void ** )&buf, NULL, 0 );
	if( !buf )
		Com_Error( ERR_DROP, "Couldn't load %s", name );

	cms->checksum = Com_MD5Digest32( ( const qbyte * )buf, length );
	*checksum = cms->checksum;

	// call the apropriate loader
	descr = Q_FindFormatDescriptor( cm_supportedformats, ( const qbyte * )buf, (const bspFormatDesc_t **)&bspFormat );
	if( !descr )
		Com_Error( ERR_DROP, "CM_LoadMap: unknown fileid for %s", name );

	if( !bspFormat )
		Com_Error( ERR_DROP, "CM_LoadMap: %s: unknown bsp format" );

	// copy header into temp variable to be saveed in a cvar
	header = Mem_TempMalloc( descr->headerLen + 1 );
	memcpy( header, buf, descr->headerLen );
	header[descr->headerLen] = '\0';

	// store map format description in cvars
	Cvar_ForceSet( "cm_mapHeader", header );
	Cvar_ForceSet( "cm_mapVersion", va( "%i", LittleLong( *((int *)((qbyte *)buf + descr->headerLen)) ) ) );

	Mem_TempFree( header );

	descr->loader( cms, NULL, buf, bspFormat );

	CM_InitBoxHull( cms );
	CM_InitOctagonHull( cms );

	if( cms->numareas )
	{
		cms->map_areas = Mem_Alloc( cms->mempool, cms->numareas * sizeof( *cms->map_areas ) );
		cms->map_areaportals = Mem_Alloc( cms->mempool, cms->numareas * cms->numareas * sizeof( *cms->map_areaportals ) );

		memset( cms->map_areaportals, 0, cms->numareas * cms->numareas * sizeof( *cms->map_areaportals ) );
		CM_FloodAreaConnections( cms );
	}

	memset( cms->nullrow, 255, MAX_CM_LEAFS / 8 );

	Q_strncpyz( cms->map_name, name, sizeof( cms->map_name ) );

	return cms->map_cmodels;
}
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];
}