engine/EngineModel.c
/*	Loads a model into the cache
*/
Loads a model into the cache
Loads a model into the cache
model_t *Model_Load(model_t *model)
{
	char		exten[64];
	void		*d;
	int			i;
	if (!model->bNeedLoad)
	{
		if (model->type == MODEL_TYPE_MD2)
		{
			d = Cache_Check(&model->cache);
			if (d)
				return model;
		}
		else
			return model;
	}
	void *buf = COM_LoadHeapFile(model->name);
	if(!buf)
	{
		Con_Warning("Model was not found! (%s)\n", model->name);
		return NULL;
	}
	COM_FileBase(model->name, loadname);
	loadmodel = model;
	model->bNeedLoad = false;
	switch (LittleLong(*(unsigned*)buf))
	{
	case MD2E_HEADER:
	case MD2_HEADER:
		Model_LoadMD2(model, buf);
		break;
	case BSP_HEADER:
		Model_LoadBSP(model, buf);
		break;
	default:
		strncpy(exten, COM_FileExtension(model->name), sizeof(exten));
		if (exten[0] != ' ')
		{
			for (i = 0; i < pARRAYELEMENTS(model_formatlist); i++)
			{
				if (!strcmp(model_formatlist[i].extension, exten))
				{
					model->type = (ModelType_t)model_formatlist[i].type;
					model_formatlist[i].Function(model, buf);
					break;
				}
			}
		}
		Con_Warning("Unsupported model type! (%s)\n", model->name);
		model = NULL;
	}
	free(buf);
	return model;
}
model_t * Model_Load ( model_t * model ) { char exten [ 64 ] ; void * d ; int i ; if ( ! model -> bNeedLoad ) { if ( model -> type == MODEL_TYPE_MD2 ) { d = Cache_Check ( & model -> cache ) ; if ( d ) return model ; } else return model ; } void * buf = COM_LoadHeapFile ( model -> name ) ; if ( ! buf ) { Con_Warning ( " \n " , model -> name ) ; return NULL ; } COM_FileBase ( model -> name , loadname ) ; loadmodel = model ; model -> bNeedLoad = false ; switch ( LittleLong ( * ( unsigned * ) buf ) ) { case MD2E_HEADER : case MD2_HEADER : Model_LoadMD2 ( model , buf ) ; break ; case BSP_HEADER : Model_LoadBSP ( model , buf ) ; break ; default : strncpy ( exten , COM_FileExtension ( model -> name ) , sizeof ( exten ) ) ; if ( exten [ 0 ] != ' ' ) { for ( i = 0 ; i < pARRAYELEMENTS ( model_formatlist ) ; i ++ ) { if ( ! strcmp ( model_formatlist [ i ] . extension , exten ) ) { model -> type = ( ModelType_t ) model_formatlist [ i ] . type ; model_formatlist [ i ] . Function ( model , buf ) ; break ; } } } Con_Warning ( " \n " , model -> name ) ; model = NULL ; } free ( buf ) ; return model ; }
Loads a model into the cache
Loads a model into the cache
// Load the file // Allocate a new model // Call the apropriate loader // Grab the file extension, so we can check for formats that don't have idents. // Set the default type, we can change later. // If we reach this point, definately not supported.