Пример #1
0
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
	char	namebuffer[256];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	byte	stackbuf[1*1024];		// avoid dirtying the cache heap

// see if still in memory
	sc = (sfxcache_t *) Cache_Check (&s->cache);
	if (sc)
		return sc;

//	Con_Printf ("%s: %x\n", __thisfunc__, (int)stackbuf);

// load it in
	q_strlcpy(namebuffer, "sound/", sizeof(namebuffer));
	q_strlcat(namebuffer, s->name, sizeof(namebuffer));

//	Con_Printf ("loading %s\n",namebuffer);

	data = FS_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));

	if (!data)
	{
		Con_Printf ("Couldn't load %s\n", namebuffer);
		return NULL;
	}

	info = GetWavinfo (s->name, data, fs_filesize);
	if (info.channels != 1)
	{
		Con_Printf ("%s is a stereo sample\n",s->name);
		return NULL;
	}

	stepscale = (float)info.rate / shm->speed;
	len = info.samples / stepscale;

	len = len * info.width * info.channels;

	sc = (sfxcache_t *) Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
	if (!sc)
		return NULL;

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	return sc;
}
Пример #2
0
/* <42900> ../engine/l_studio.c:31 */
void Mod_LoadStudioModel_internal(model_t * mod, void * buffer)
{
	uint8_t *poutdata;
	uint8_t *pindata;
	mstudiotexture_t *ptexture;
	int size;
	int i;
	uint8_t *pout;

	studiohdr_t * phdr = (studiohdr_t *)buffer;
	i = LittleLong(phdr->version);
	if (i != STUDIO_VERSION)
	{
		Q_memset(phdr, 0, 244u);
		Q_strcpy(phdr->name, "bogus");
		phdr->length = 244;
		phdr->texturedataindex = 244;
	}

	mod->type = mod_studio;
	mod->flags = phdr->flags;
	Cache_Alloc(&mod->cache, phdr->length + 1280 * phdr->numtextures, mod->name);
	pout = (uint8_t *)mod->cache.data;
	if (pout)
	{
		if (phdr->textureindex)
		{
			Q_memcpy(pout, buffer, phdr->texturedataindex);
			poutdata = pout + phdr->texturedataindex;
			pindata = (uint8_t*)buffer + phdr->texturedataindex;
			ptexture = (mstudiotexture_t *)(pout + phdr->textureindex);
			for (i = 0; i < phdr->numtextures; i++, ptexture++)
			{
				size = ptexture->height * ptexture->width;
				ptexture->index = poutdata - pout;
				Q_memcpy(poutdata, pindata, size);
				poutdata += size;
				pindata += size;

				for (int j = 0; j < 256; j++, pindata += 3, poutdata += 8)
				{
					((uint16_t*)poutdata)[0] = texgammatable[pindata[0]];
					((uint16_t*)poutdata)[1] = texgammatable[pindata[1]];
					((uint16_t*)poutdata)[2] = texgammatable[pindata[2]];
					((uint16_t*)poutdata)[3] = 0;
				}
			}
		}
		else
		{
			Q_memcpy(pout, buffer, phdr->length);
		}
	}
}
Пример #3
0
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char		namebuffer[512];
	wavinfo_t	info;
	int			len;
	float		stepscale;
	sfxcache_t	*sc;

	// see if still in memory
	sc = (sfxcache_t*)Cache_Check(&s->cache);
	if(sc)
		return sc;

	// load it in
	strncpy(namebuffer, g_state.cSoundPath, sizeof(namebuffer));
	strcat(namebuffer, s->name);

	uint8_t *data = (uint8_t*)COM_LoadHeapFile(namebuffer);
	if (!data)
	{
		Con_Warning("Couldn't load %s\n", namebuffer);
		return NULL;
	}

	info = GetWavinfo (s->name, data, com_filesize);

	stepscale = (float)info.rate / shm->speed;
	len = info.samples / stepscale;

	len = len * info.width * info.channels;

	sc = (sfxcache_t*)Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
	if (!sc)
	{
		free(data);
		return NULL;
	}

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	free(data);

	return sc;
}
Пример #4
0
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char	namebuffer[256];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	fs_offset_t filesize;

// see if still in memory
	sc = Cache_Check (&s->cache);
	if (sc)
		return sc;

// load it in
    strcpy (namebuffer, "sound/");
    strcat (namebuffer, s->name);

	data = FS_LoadFile (namebuffer, false, &filesize);
	if (!data)
		return NULL;

	info = GetWavinfo (s->name, data, filesize);
	if (info.channels != 1)
	{
		Com_Printf ("%s is a stereo sample\n",s->name);
		return NULL;
	}

	stepscale = (float)info.rate / dma.speed;
	len = info.samples / stepscale;

	len = len * info.width * info.channels;

	sc = (sfxcache_t *) Cache_Alloc (&s->cache, len + sizeof(sfxcache_t), s->name);
	if (!sc)
		return NULL;

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	return sc;
}
Пример #5
0
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char		namebuffer[512];
	byte		*data;
	wavinfo_t	info;
	int			len;
	float		stepscale;
	sfxcache_t	*sc;
	byte		stackbuf[1*1024];		// avoid dirtying the cache heap

	// see if still in memory
	sc = (sfxcache_t*)Cache_Check(&s->cache);
	if(sc)
		return sc;

	// load it in
	Q_strcpy(namebuffer,Global.cSoundPath);
    Q_strcat(namebuffer,s->name);

	data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));
	if (!data)
	{
		Con_Warning("Couldn't load %s\n", namebuffer);
		return NULL;
	}

	info = GetWavinfo (s->name, data, com_filesize);

	stepscale = (float)info.rate / shm->speed;
	len = info.samples / stepscale;

	len = len * info.width * info.channels;

	sc = (sfxcache_t*)Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
	if (!sc)
		return NULL;

	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	return sc;
}
void CAudioSourceMP3Cache::CacheLoad( void )
{
	if ( IsCached() )
		return;

	int file = g_pSndIO->open( m_pName );
	if ( !file )
		return;

	m_fileSize = g_pSndIO->size( file );
	// create a buffer for the samples
	char *pData = (char *)Cache_Alloc( &m_cache, m_fileSize, m_pName );
	// load them into memory
	g_pSndIO->read( pData, m_fileSize, file );

	g_pSndIO->close( file );
}
Пример #7
0
/*
==========
Skin_Cache

Returns a pointer to the skin bitmap, or NULL to use the default
==========
*/
byte *Skin_Cache (skin_t *skin)
{
	int		y;
	byte	*pic, *out, *pix;
	int		width, height;
	char	name[MAX_OSPATH];

	if (skin->failedload)
		return NULL;

	out = Cache_Check (&skin->cache);
	if (out)
		return out;

//
// load the pic from disk
//
	Q_snprintf (name, sizeof(name), "skins/%s", skin->name);
	pic = Image_LoadImage (name, &width, &height);
	if (!pic || width > 320 || height > 200)
	{
		if (pic)
			Q_free (pic);

		skin->failedload = true;
		Com_DPrintf ("Couldn't load skin %s\n", name);
		return NULL;
	}

	out = pix = Cache_Alloc (&skin->cache, 320*200, skin->name);
	if (!out)
		Sys_Error ("Skin_Cache: couldn't allocate");

	memset (out, 0, 320*200);
	for (y=0 ; y<height ; y++, pix += 320)
		memcpy (pix, pic + y*width, width);

	Q_free (pic);

	skin->failedload = false;

	return out;
}
Пример #8
0
// Returns a pointer to the skin bitmap, or NULL to use the default
byte *Skin_Cache (skin_t *skin, qbool no_baseskin) 
{
	int y, max_w, max_h, bpp, real_width = -1, real_height = -1;
	byte *pic = NULL, *out, *pix;
	char name[MAX_OSPATH];

	if (noskins.value == 1) // JACK: So NOSKINS > 1 will show skins, but
		return NULL;		// not download new ones.

	if (skin->failedload)
		return NULL;

	if ((out = (byte *) Cache_Check (&skin->cache)))
		return out;

	// not cached, load from HDD

	snprintf (name, sizeof(name), "skins/%s.pcx", skin->name);

	if (!(pic = Skin_PixelsLoad(name, &max_w, &max_h, &bpp, &real_width, &real_height)) || real_width > max_w || real_height > max_h) 
	{
		Q_free(pic);

		if (no_baseskin) 
		{
			skin->warned = true;
			return NULL; // well, we not set skin->failedload = true, that how I need it here
		}
		else if (!skin->warned)
		{
			Com_Printf ("&cf22Couldn't load skin:&r %s\n", name);
		}

		skin->warned = true;
	}

	if (!pic) 
	{ 
		// Attempt load at least default/base.
		snprintf (name, sizeof(name), "skins/%s.pcx", baseskin.string);

		if (!(pic = Skin_PixelsLoad(name, &max_w, &max_h, &bpp, &real_width, &real_height)) || real_width > max_w || real_height > max_h) 
		{
			Q_free(pic);
			skin->failedload = true;
			return NULL;
		}
	}

	if (!(out = pix = (byte *) Cache_Alloc (&skin->cache, max_w * max_h * bpp, skin->name)))
		Sys_Error ("Skin_Cache: couldn't allocate");

	memset (out, 0, max_w * max_h * bpp);
	for (y = 0; y < real_height; y++, pix += (max_w * bpp))
	{
		memcpy (pix, pic + y * real_width * bpp, real_width * bpp);
	}

	Q_free (pic);
	skin->bpp 	 = bpp;
	skin->width	 = real_width;
	skin->height = real_height;

	// load 32bit skin ASAP, so later we not affected by Cache changes, actually we don't need cache for 32bit skins at all
	//	skin->texnum = (bpp != 1) ? GL_LoadTexture (skin->name, skin->width, skin->height, pix, TEX_MIPMAP | TEX_NOSCALE, bpp) : 0;
	// FIXME: Above line does't work, texture loaded wrong, seems I need set some global gl states, but I dunno which,
	// so moved it to R_TranslatePlayerSkin() and here set texture to 0
	skin->texnum = 0;
	skin->failedload = false;

	return out;
}
Пример #9
0
/*
=================
Mod_LoadAliasModel
=================
*/
void Mod_LoadAliasModel (model_t *mod, void *buffer)
{
	int					i;
	mdl_t				*pmodel, *pinmodel;
	stvert_t			*pstverts, *pinstverts;
	aliashdr_t			*pheader;
	mtriangle_t			*ptri;
	dtriangle_t			*pintriangles;
	int					version, numframes, numskins;
	int					size;
	daliasframetype_t	*pframetype;
	daliasskintype_t	*pskintype;
	maliasskindesc_t	*pskindesc;
	int					skinsize;
	int					start, end, total;
	
	start = Hunk_LowMark ();

	pinmodel = (mdl_t *)buffer;

	version = LittleLong (pinmodel->version);
	if (version != ALIAS_VERSION)
		Sys_Error ("%s has wrong version number (%i should be %i)",
				 mod->name, version, ALIAS_VERSION);

//
// allocate space for a working header, plus all the data except the frames,
// skin and group info
//
	size = 	sizeof (aliashdr_t) + (LittleLong (pinmodel->numframes) - 1) *
			 sizeof (pheader->frames[0]) +
			sizeof (mdl_t) +
			LittleLong (pinmodel->numverts) * sizeof (stvert_t) +
			LittleLong (pinmodel->numtris) * sizeof (mtriangle_t);

	pheader = Hunk_AllocName (size, loadname);
	pmodel = (mdl_t *) ((byte *)&pheader[1] +
			(LittleLong (pinmodel->numframes) - 1) *
			 sizeof (pheader->frames[0]));
	
//	mod->cache.data = pheader;
	mod->flags = LittleLong (pinmodel->flags);

//
// endian-adjust and copy the data, starting with the alias model header
//
	pmodel->boundingradius = LittleFloat (pinmodel->boundingradius);
	pmodel->numskins = LittleLong (pinmodel->numskins);
	pmodel->skinwidth = LittleLong (pinmodel->skinwidth);
	pmodel->skinheight = LittleLong (pinmodel->skinheight);

	if (pmodel->skinheight > MAX_LBM_HEIGHT)
		Sys_Error ("model %s has a skin taller than %d", mod->name,
				   MAX_LBM_HEIGHT);

	pmodel->numverts = LittleLong (pinmodel->numverts);

	if (pmodel->numverts <= 0)
		Sys_Error ("model %s has no vertices", mod->name);

	if (pmodel->numverts > MAXALIASVERTS)
		Sys_Error ("model %s has too many vertices", mod->name);

	pmodel->numtris = LittleLong (pinmodel->numtris);

	if (pmodel->numtris <= 0)
		Sys_Error ("model %s has no triangles", mod->name);

	pmodel->numframes = LittleLong (pinmodel->numframes);
	pmodel->size = LittleFloat (pinmodel->size) * ALIAS_BASE_SIZE_RATIO;
	mod->synctype = LittleLong (pinmodel->synctype);
	mod->numframes = pmodel->numframes;

	for (i=0 ; i<3 ; i++)
	{
		pmodel->scale[i] = LittleFloat (pinmodel->scale[i]);
		pmodel->scale_origin[i] = LittleFloat (pinmodel->scale_origin[i]);
		pmodel->eyeposition[i] = LittleFloat (pinmodel->eyeposition[i]);
	}

	numskins = pmodel->numskins;
	numframes = pmodel->numframes;

	if (pmodel->skinwidth & 0x03)
		Sys_Error ("Mod_LoadAliasModel: skinwidth not multiple of 4");

	pheader->model = (byte *)pmodel - (byte *)pheader;

//
// load the skins
//
	skinsize = pmodel->skinheight * pmodel->skinwidth;

	if (numskins < 1)
		Sys_Error ("Mod_LoadAliasModel: Invalid # of skins: %d\n", numskins);

	pskintype = (daliasskintype_t *)&pinmodel[1];

	pskindesc = Hunk_AllocName (numskins * sizeof (maliasskindesc_t),
								loadname);

	pheader->skindesc = (byte *)pskindesc - (byte *)pheader;

	for (i=0 ; i<numskins ; i++)
	{
		aliasskintype_t	skintype;

		skintype = LittleLong (pskintype->type);
		pskindesc[i].type = skintype;

		if (skintype == ALIAS_SKIN_SINGLE)
		{
			pskintype = (daliasskintype_t *)
					Mod_LoadAliasSkin (pskintype + 1,
									   &pskindesc[i].skin,
									   skinsize, pheader);
		}
		else
		{
			pskintype = (daliasskintype_t *)
					Mod_LoadAliasSkinGroup (pskintype + 1,
											&pskindesc[i].skin,
											skinsize, pheader);
		}
	}

//
// set base s and t vertices
//
	pstverts = (stvert_t *)&pmodel[1];
	pinstverts = (stvert_t *)pskintype;

	pheader->stverts = (byte *)pstverts - (byte *)pheader;

	for (i=0 ; i<pmodel->numverts ; i++)
	{
		pstverts[i].onseam = LittleLong (pinstverts[i].onseam);
	// put s and t in 16.16 format
		pstverts[i].s = LittleLong (pinstverts[i].s) << 16;
		pstverts[i].t = LittleLong (pinstverts[i].t) << 16;
	}

//
// set up the triangles
//
	ptri = (mtriangle_t *)&pstverts[pmodel->numverts];
	pintriangles = (dtriangle_t *)&pinstverts[pmodel->numverts];

	pheader->triangles = (byte *)ptri - (byte *)pheader;

	for (i=0 ; i<pmodel->numtris ; i++)
	{
		int		j;

		ptri[i].facesfront = LittleLong (pintriangles[i].facesfront);

		for (j=0 ; j<3 ; j++)
		{
			ptri[i].vertindex[j] =
					LittleLong (pintriangles[i].vertindex[j]);
		}
	}

//
// load the frames
//
	if (numframes < 1)
		Sys_Error ("Mod_LoadAliasModel: Invalid # of frames: %d\n", numframes);

	pframetype = (daliasframetype_t *)&pintriangles[pmodel->numtris];

	for (i=0 ; i<numframes ; i++)
	{
		aliasframetype_t	frametype;

		frametype = LittleLong (pframetype->type);
		pheader->frames[i].type = frametype;

		if (frametype == ALIAS_SINGLE)
		{
			pframetype = (daliasframetype_t *)
					Mod_LoadAliasFrame (pframetype + 1,
										&pheader->frames[i].frame,
										pmodel->numverts,
										&pheader->frames[i].bboxmin,
										&pheader->frames[i].bboxmax,
										pheader, pheader->frames[i].name);
		}
		else
		{
			pframetype = (daliasframetype_t *)
					Mod_LoadAliasGroup (pframetype + 1,
										&pheader->frames[i].frame,
										pmodel->numverts,
										&pheader->frames[i].bboxmin,
										&pheader->frames[i].bboxmax,
										pheader, pheader->frames[i].name);
		}
	}

	mod->type = mod_alias;

// FIXME: do this right
	mod->mins[0] = mod->mins[1] = mod->mins[2] = -16;
	mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16;

//
// move the complete, relocatable alias model to the cache
//	
	end = Hunk_LowMark ();
	total = end - start;
	
	Cache_Alloc (&mod->cache, total, loadname);
	if (!mod->cache.data)
		return;
	memcpy (mod->cache.data, pheader, total);

	Hunk_FreeToLowMark (start);
}
Пример #10
0
sfxcache_t *S_LoadSound(sfx_t *s)
{
	char namebuffer[MAX_OSPATH];
	char extionless[MAX_OSPATH];
	sfxcache_t *sc = NULL;
	int eof = 0;
	int current_section;
	vfsfile_t *f;
	OggVorbis_File oggfile;
	vorbis_info *ogginfo;
	ov_callbacks ovc = {
		vorbis_callback_read,
		vorbis_callback_seek,
		vorbis_callback_close,
		vorbis_callback_tell
	};
	static char pcmbuff[4096];
	
	//unsigned char *data;
	wavinfo_t info;
	int len;
	//int filesize;

	// see if still in memory
	if ((sc = (sfxcache_t *) Cache_Check (&s->cache)))
		return sc;

	if (!vorbis_CheckActive())
		vorbis_LoadLibrary();

	// load it in
	COM_StripExtension(s->name, extionless);
	snprintf (namebuffer, sizeof (namebuffer), "sound/%s.ogg", extionless);

/*	if (!(data = FS_LoadTempFile (namebuffer, &filesize))) {
		Com_Printf ("Couldn't load %s\n", namebuffer);
		return NULL;
	}*/

	if (!(f = FS_OpenVFS(namebuffer, "rb", FS_ANY))) {
		Com_Printf("Couldn't load %s\n", namebuffer);
		return NULL;
	}

	if (qov_open_callbacks(f, &oggfile, NULL, 0, ovc)) {
		Com_Printf("Invalid sound file %s\n", namebuffer);
		VFS_CLOSE(f);
		return NULL;
	}
	if (!(ogginfo = qov_info(&oggfile,-1))) {
		Com_Printf("Unable to retrieve information for %s\n", namebuffer);
		goto fail;
	}

	/* Print some information */
	fprintf(stderr, "%s\n", namebuffer);
	{
		char **ptr = qov_comment(&oggfile,-1)->user_comments;
		while(*ptr){
			fprintf(stderr,"%s\n",*ptr);
			++ptr;
		}
		fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",
				ogginfo->channels, ogginfo->rate);
		fprintf(stderr,"\nDecoded length: %ld samples\n",
				(long) qov_pcm_total(&oggfile,-1));
		fprintf(stderr,"Encoded by: %s\n\n", qov_comment(&oggfile,-1)->vendor);
	}

	info.rate = ogginfo->rate;			// Frequency rate
	info.width = 1;						// 8 bit samples
	info.channels = ogginfo->channels;	// 1 == mono, 2 == stereo
	info.loopstart = -1;				// NOOO idea...
	info.samples = qov_pcm_total(&oggfile,-1);	// Total samples
	info.dataofs = 0;					// offset

	
	//FMod_CheckModel(namebuffer, data, filesize);

	//info = GetWavinfo (s->name, data, filesize);

	// Stereo sounds are allowed (intended for music)
	if (info.channels < 1 || info.channels > 2) {
		Com_Printf("%s has an unsupported number of channels (%i)\n",s->name, info.channels);
		return NULL;
	}

	len = (int) ((double) info.samples * (double) shm->format.speed / (double) info.rate);
	len = len * info.width * info.channels;

	if (!(sc = (sfxcache_t *) Cache_Alloc (&s->cache, len + sizeof(sfxcache_t), s->name)))
		return NULL;

	/* Read the whole Ogg Vorbis file in */
	byte *output = sc->data;
	while (!eof) {
		// 0 == little endian, 1 = big endian
		// 1 == 8 bit samples, 2 = 16 bit samples
		// 1 == signed samples
		long ret = qov_read(&oggfile, pcmbuff, sizeof(pcmbuff), 
				0, info.width, 1, &current_section);
		if (ret == 0) {
			eof = 1;
		} else if (ret < 0) {
			/* error in the stream. Not a problem, just reporting it in
			 * case we (the app) cares. In this case, we don't. */
		} else {
			/* we don't bother dealing with sample rate changes, etc, but
			 * you'll have to */
			memcpy(output, pcmbuff, ret);
			output += ret;
		}
	}
	qov_clear(&oggfile);

	sc->total_length = (unsigned int) info.samples;
	sc->format.speed = info.rate;
	sc->format.width = info.width;
	sc->format.channels = info.channels;
	if (info.loopstart < 0)
		sc->loopstart = -1;
	else
		sc->loopstart = (int)((double)info.loopstart * (double)shm->format.speed / (double)sc->format.speed);

//	ResampleSfx (s, data + info.dataofs, info.samples, &sc->format, sc->data);
	return sc;

fail:
	qov_clear(&oggfile); // Only goto fail if ov_open* succeded
	if (f) {
		VFS_CLOSE(f);
	}
	return NULL;
}
Пример #11
0
/*
=================
Mod_LoadAliasModel
=================
*/
void Mod_LoadAliasModel (model_t *mod, void *buffer)
{
	int					i, j;
	mdl_t				*pinmodel;
	stvert_t			*pinstverts;
	dtriangle_t			*pintriangles;
	int					version, numframes, numskins;
	int					size;
	daliasframetype_t	*pframetype;
	daliasskintype_t	*pskintype;
	int					start, end, total;
	
	start = Hunk_LowMark ();

	pinmodel = (mdl_t *)buffer;

	version = LittleLong (pinmodel->version);
	if (version != ALIAS_VERSION)
		Sys_Error ("%s has wrong version number (%i should be %i)",
				 mod->name, version, ALIAS_VERSION);

//
// allocate space for a working header, plus all the data except the frames,
// skin and group info
//
	size = 	sizeof (aliashdr_t) 
			+ (LittleLong (pinmodel->numframes) - 1) *
			sizeof (pheader->frames[0]);
	pheader = Hunk_AllocName (size, loadname);
	
	mod->flags = LittleLong (pinmodel->flags);

//
// endian-adjust and copy the data, starting with the alias model header
//
	pheader->boundingradius = LittleFloat (pinmodel->boundingradius);
	pheader->numskins = LittleLong (pinmodel->numskins);
	pheader->skinwidth = LittleLong (pinmodel->skinwidth);
	pheader->skinheight = LittleLong (pinmodel->skinheight);

	if (pheader->skinheight > MAX_LBM_HEIGHT)
		Sys_Error ("model %s has a skin taller than %d", mod->name,
				   MAX_LBM_HEIGHT);

	pheader->numverts = LittleLong (pinmodel->numverts);

	if (pheader->numverts <= 0)
		Sys_Error ("model %s has no vertices", mod->name);

	if (pheader->numverts > MAXALIASVERTS)
		Sys_Error ("model %s has too many vertices", mod->name);

	pheader->numtris = LittleLong (pinmodel->numtris);

	if (pheader->numtris <= 0)
		Sys_Error ("model %s has no triangles", mod->name);

	pheader->numframes = LittleLong (pinmodel->numframes);
	numframes = pheader->numframes;
	if (numframes < 1)
		Sys_Error ("Mod_LoadAliasModel: Invalid # of frames: %d\n", numframes);

	pheader->size = LittleFloat (pinmodel->size) * ALIAS_BASE_SIZE_RATIO;
	mod->synctype = LittleLong (pinmodel->synctype);
	mod->numframes = pheader->numframes;

	for (i=0 ; i<3 ; i++)
	{
		pheader->scale[i] = LittleFloat (pinmodel->scale[i]);
		pheader->scale_origin[i] = LittleFloat (pinmodel->scale_origin[i]);
		pheader->eyeposition[i] = LittleFloat (pinmodel->eyeposition[i]);
	}


//
// load the skins
//
	pskintype = (daliasskintype_t *)&pinmodel[1];
	pskintype = Mod_LoadAllSkins (pheader->numskins, pskintype);

//
// load base s and t vertices
//
	pinstverts = (stvert_t *)pskintype;

	for (i=0 ; i<pheader->numverts ; i++)
	{
		stverts[i].onseam = LittleLong (pinstverts[i].onseam);
		stverts[i].s = LittleLong (pinstverts[i].s);
		stverts[i].t = LittleLong (pinstverts[i].t);
	}

//
// load triangle lists
//
	pintriangles = (dtriangle_t *)&pinstverts[pheader->numverts];

	for (i=0 ; i<pheader->numtris ; i++)
	{
		triangles[i].facesfront = LittleLong (pintriangles[i].facesfront);

		for (j=0 ; j<3 ; j++)
		{
			triangles[i].vertindex[j] =
					LittleLong (pintriangles[i].vertindex[j]);
		}
	}

//
// load the frames
//
	posenum = 0;
	pframetype = (daliasframetype_t *)&pintriangles[pheader->numtris];

	for (i=0 ; i<numframes ; i++)
	{
		aliasframetype_t	frametype;

		frametype = LittleLong (pframetype->type);

		if (frametype == ALIAS_SINGLE)
		{
			pframetype = (daliasframetype_t *)
					Mod_LoadAliasFrame (pframetype + 1, &pheader->frames[i]);
		}
		else
		{
			pframetype = (daliasframetype_t *)
					Mod_LoadAliasGroup (pframetype + 1, &pheader->frames[i]);
		}
	}


	pheader->numposes = posenum;

	mod->type = mod_alias;

// FIXME: do this right
	mod->mins[0] = mod->mins[1] = mod->mins[2] = -16;
	mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16;
#if ALIAS_VBO
	///////////////////////////////////////////////////////////
	//
	//create a gl VBO object so we don't have to send this data each frame
	//
	//FORMAT [TEXTURE DATA BLOCK]
	//		 [VERTEX BLOCK FRAME 0]
	//		 [VERTEX BLOCK FRAME 1]
	//		 [VERTEX BLOCK FRAME 2]
	//		 ...
	//		 [VERTEX BLOCK FRAME N]
	//int numfloats = pheader->numposes * pheader->numtris * /*floats per verts*/ 9 * /*verts per triangle*/ 3;
	int numGLVerts = pheader->numposes * pheader->numtris * 3;
	
	glAliasData* gpuBoundData = (glAliasData*)malloc(sizeof(glAliasData)*numGLVerts);

	int processedIndex = 0;
	int f, t, v;
	for (f=0 ; f<pheader->numposes ; f++)
	{
		for (t = 0; t < pheader->numtris; t++)
		{
			for(v=0; v<3; v++){
				//
				int vIdx = triangles[t].vertindex[v];
				const trivertx_t* pVtx = &poseverts[f][vIdx];

				//pintriangles[t].facesfront;
				byte x = pVtx->v[0]; //render code applies scale + translation
				byte y = pVtx->v[1];
				byte z = pVtx->v[2];

				/* Compute texture coordinates */
				float cs = stverts[vIdx].s;
				float ct = stverts[vIdx].t;
				if (!triangles[t].facesfront && stverts[vIdx].onseam)
				{
					cs += pheader->skinwidth * 0.5f;
				}

				cs = (cs + 0.5f) / pheader->skinwidth;
				ct = (ct + 0.5f) / pheader->skinheight;

				gpuBoundData[processedIndex].st[0] = (unsigned char)(255 * cs);
				gpuBoundData[processedIndex].st[1] = (unsigned char)(255 * ct);

				//gpuBoundData[processedIndex].st[0] = cs;
				//gpuBoundData[processedIndex].st[1] = ct;

				gpuBoundData[processedIndex].pos[0] = x;
				gpuBoundData[processedIndex].pos[1] = y;
				gpuBoundData[processedIndex].pos[2] = z;

				gpuBoundData[processedIndex].lightNormalIndex = pVtx->lightnormalindex;
				processedIndex++;
			}
		}
	}

		CreatAliasBuffers(&pheader->vbo_offset,numGLVerts,gpuBoundData);

	free(gpuBoundData);

	//JAMES
	//we can brobably safely ditch most of what is below, just a waste of memory now
#endif //ALIAS_VBO
	
	///////////////////////////////////////////////////////////

	//
	// build the draw lists
	//
	GL_MakeAliasModelDisplayLists (mod, pheader);

//
// move the complete, relocatable alias model to the cache
//	
	end = Hunk_LowMark ();
	total = end - start;
	
	Cache_Alloc (&mod->cache, total, loadname);
	if (!mod->cache.data)
		return;
	memcpy (mod->cache.data, pheader, total);

	Hunk_FreeToLowMark (start);
}
Пример #12
0
/* DESCRIPTION: COM_LoadFile
// LOCATION: SDK
// PATH: Theoretically anywhere, since it's in the SDK.
//
// The args are known, the function cannot be altered.
// LoadFileForMe is a wrapper for COM_LoadFile, which is ALSO
// in the SDK.
//
// pLength can be null, for some reason (backwards compat?).
// What 'usehunk' does is tell the function HOW to load the file;
// I think the functions below better illustrate the types.
*/
HLDS_DLLEXPORT byte * COM_LoadFile(const char *path, int usehunk, int *pLength) {

   //pLength is a variable passed by reference we are suppossed to put
   //the size of our loaded file in.  It is optional though.

   hl_file_t *file;

   byte *FileData = NULL; //what we end up returning
   const char *FileName;
   int len;

   file = FS_Open(path, "rb");

   if(file == NULL) {
      //No file.  How sad.
      if(pLength != NULL) {
         *pLength = 0;
      }
      return(NULL);
   }

   len = FS_Size(file);

   switch(usehunk) {
   case 0:
      //0 must be small text files, but I'm not sure it's used
      FileData = (byte *)Z_Malloc(len+1);
      break;
   case 1:
      //1 must be regular hunk
      FileName = strrchr(path, '/');

      if(FileName == NULL) { FileName = path; }
      else { FileName++; } //worst case oddities, an empty string, shouldn't hurt.

      FileData = (byte *)Hunk_AllocName(len+1, FileName);
      break;
   case 2:
      //2 must be temporary file allocation
      FileData = (byte *)Hunk_TempAlloc(len+1);
      break;
   case 3:
      //3 must be caching.  I still don't quite understand how that works.
      FileName = strrchr(path, '/');

      if(FileName == NULL) { FileName = path; }
      else { FileName++; }

      FileData = (byte *)Cache_Alloc(loadcache, len+1, FileName); //loadcache = global
      break;
   case 4:
      //Similar to case 2.  Temp allocation, or allocation to a temporary file pointer.
      if (len+1 > loadsize) { FileData = (byte *)Hunk_TempAlloc(len+1); }
      else { FileData = loadbuf; }

      break;
   case 5:
      //And 5 is mallocing the memory.  But how is it freed?
      FileData = (byte *)Q_Malloc(len+1); //Freeing relies on the user.
      CHECK_MEMORY_MALLOC(FileData);

      //printf("%s: Allocating file %s (%u)\n", __FUNCTION__, path, len+1);

      break;
   //tempallocmore--case 6--doesn't exist in HL
   default:
      Sys_Error ("COM_LoadFile: \"usehunk\" is suppossed to be between 0 and 5.  Fix it, modder.\n");
   }

   if(FileData == NULL)   {
      Sys_Error("COM_LoadFile: Couldn't load \"%s\" for some memory related reason.\n", path);
      FS_Close(file); //since sys_error kills us, why close?
   }

   //whoawhoawhoa, tacking on a null? I spy a pretty nasty off by one error...
   //And now len has been +1'd, fixing it.

   FS_Read(FileData, len, 1, file);
   FileData[len] = '\0';

   FS_Close(file);

   if(pLength != NULL) { *pLength = len; }

   return(FileData);
}
Пример #13
0
/*
=================
Mod_LoadQ3Model
=================
*/
void Mod_LoadQ3Model (model_t *mod, const void *buffer)
{
	md3header_t		*header;
	md3surface_t	*surf;
	int				 i, j, picmip_flag;
	md3shader_t		*shader;
	md3frame_t		*frame;
//	md3ver_t		*vert;
	byte			*modeldata;
	const char		**pathlist;
	const char		*namelist[2];
	char			path[MAX_OSPATH];

	header = (md3header_t *) buffer;
	if (header->version != 15)
	{
		Con_Printf ("\x02""ERROR: incorrect version of MD3 file %s\n", mod->name);
		return;
	}

	Con_DPrintf ("Loading md3 model...%s (%s)\n", header->filename, mod->name);

	frame = (md3frame_t *) ((byte *) header + header->frame_offs);
	for (i = 0; i < header->num_frames; i++, frame++)
	{
		VectorCopy (frame->pos, md3bboxmins);
		VectorCopy (frame->pos, md3bboxmaxs);

		for (j = 0; j < 3; j++)
		{
			if (frame->mins[j] < md3bboxmins[j])
				md3bboxmins[j] = frame->mins[j];
			if (frame->maxs[j] > md3bboxmaxs[j])
				md3bboxmaxs[j] = frame->maxs[j];
		}

	}

#ifndef RQM_SV_ONLY
	picmip_flag = gl_picmip_all.value ? TEX_MIPMAP : 0;
#else
	picmip_flag = 0;
#endif

	surf = (md3surface_t *) ((byte *)header + header->surface_offs);
	for (i=0; i < header->num_surfaces; i++)
	{
		if (*(long *)surf->id != MD3IDHEADER)
		{
			Con_Printf ("\x02""MD3 bad surface for: %s\n", header->filename);
			break;
		}

		/*vert = (md3vert_t *) ((byte *) surf + surf->vert_offs);
		for (j=0; j < surf->num_surf_verts * surf->num_surf_frames; j++, vert++)
		{
			float lat;
			float lng;

			//convert verts from shorts to floats
			md3vert_mem_t   *mem_vert = (md3vert_mem_t *)((byte *)mem_head + posn);
			md3vert_t      *disk_vert = (md3vert_t *)((byte *)surf + surf->vert_offs + j * sizeof(md3vert_t));

			mem_vert->vec[0] = (float)disk_vert->vec[0] / 64.0f;
			mem_vert->vec[1] = (float)disk_vert->vec[1] / 64.0f;
			mem_vert->vec[2] = (float)disk_vert->vec[2] / 64.0f;

			//work out normals
			lat = (disk_vert->normal + 255) * (2 * 3.141592654) / 255;
			lng = ((disk_vert->normal >> 8) & 255) * (2 * 3.141592654) / 255;

			mem_vert->normal[0] = cos (lat) * sin (lng);
			mem_vert->normal[1] = sin (lat) * sin (lng);
			mem_vert->normal[2] = cos (lng);
		} */

		// load all the external textures:
		shader = (md3shader_t *)((byte *)surf + surf->shader_offs);
		for (j=0; j < surf->num_surf_shaders; j++, shader++)
		{
		#ifndef RQM_SV_ONLY
			//shader->index = GL_LoadTextureImage ("", shader->name, NULL, picmip_flag | TEX_BLEND, mod_loadpath->dir_level);
			namelist[0] = COM_SkipPath (shader->name);
			namelist[1] = NULL;
			if (namelist[0] != shader->name)
			{
				Q_strncpy (path, sizeof(path), shader->name, namelist[0]-shader->name);
				md3_paths[0] = path;
				pathlist = &md3_paths[0];
			}
			else
			{
				pathlist = &md3_paths[1];		// no custom path
			}

			shader->index = GL_LoadTextureImage_MultiSource (pathlist, namelist, NULL, picmip_flag | TEX_BLEND, mod_loadpath->dir_level);
			if (!shader->index)
			{
				Con_Printf ("\x02""Model: %s  Texture missing: %s\n", mod->name, shader->name);
			}
		#else
			shader->index = 0;
		#endif
		}

		surf = (md3surface_t *)((byte *)surf + surf->end_offs);
	}

	modeldata = Cache_Alloc (&mod->cache, header->end_offs, mod->name);
	if (!modeldata)
	{
		Con_DPrintf ("\x02""cache alloc failed...%s (%s)\n", header->filename, mod->name);
		return;   //cache alloc failed
	}

	memcpy (modeldata, buffer, header->end_offs);

	mod->type = mod_md3;
//	mod->aliastype = MD3IDHEADER;
	mod->numframes = header->num_frames;

	mod->modhint = Mod_GetAliasHint (mod->name);
	mod->flags = header->flags;

	if (mod->modhint == MOD_HEAD)
		mod->flags |= EF_GIB;
	else
		mod->flags |= Mod_GetQ3ModelFlags (mod->name);

	VectorScale (md3bboxmaxs, 1.0/64.0, mod->maxs);
	VectorScale (md3bboxmins, 1.0/64.0, mod->mins);
}
Пример #14
0
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound(sfx_t *s)
{
    char	namebuffer[256];
    byte	*data;
    wavinfo_t	info;
    int		len;
    float	stepscale;
    sfxcache_t	*sc;
    byte	stackbuf[1*1024];		// avoid dirtying the cache heap
    loadedfile_t	*fileinfo;	// 2001-09-12 Returning information about loaded file by Maddes

// see if still in memory
    sc = Cache_Check(&s->cache);
    if (sc) {
        return sc;
    }

//Con_Printf ("S_LoadSound: %x\n", (int)stackbuf);
// load it in
    Q_strcpy(namebuffer, "sound/");
    Q_strcat(namebuffer, s->name);

    if (developer.value == 1) {
        Con_DPrintf("Loading %s\n",namebuffer);    // Edited
    }
//	Con_Printf ("loading %s\n",namebuffer);

// 2001-09-12 Returning information about loaded file by Maddes  start
    /*
    	data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));

    	if (!data)
    */
    fileinfo = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf));
    if (!fileinfo)
// 2001-09-12 Returning information about loaded file by Maddes  end
    {
        Con_Printf("Couldn't load %s\n", namebuffer);
        return NULL;
    }
    data = fileinfo->data;	// 2001-09-12 Returning information about loaded file by Maddes

    info = GetWavinfo(s->name, data, com_filesize);
    if (info.channels != 1) {
        Con_Printf("%s is a stereo sample\n",s->name);
        return NULL;
    }

    stepscale = (float)info.rate / shm->speed;
    len = info.samples / stepscale;

    len = len * info.width * info.channels;

    sc = Cache_Alloc(&s->cache, len + sizeof(sfxcache_t), s->name);
    if (!sc) {
        return NULL;
    }

    sc->length = info.samples;
    sc->loopstart = info.loopstart;
    sc->speed = info.rate;
    sc->width = info.width;
    sc->stereo = info.channels;

    ResampleSfx(s, sc->speed, sc->width, data + info.dataofs);

    return sc;
}
Пример #15
0
/*
==========
Skin_Cache

Returns a pointer to the skin bitmap, or NULL to use the default
==========
*/
byte	*Skin_Cache (skin_t *skin)
{
	char	name[1024];
	byte	*raw;
	byte	*out, *pix;
	pcx_t	*pcx;
	int		x, y;
	int		dataByte;
	int		runLength;

	if (cls.downloadtype == dl_skin)
		return NULL;		// use base until downloaded

	if (noskins.value==1) // JACK: So NOSKINS > 1 will show skins, but
		return NULL;	  // not download new ones.

	if (skin->failedload)
		return NULL;

	out = Cache_Check (&skin->cache);
	if (out)
		return out;

//
// load the pic from disk
//
	sprintf (name, "skins/%s.pcx", skin->name);
	raw = COM_LoadTempFile (name);
	if (!raw)
	{
		Con_Printf ("Couldn't load skin %s\n", name);
		sprintf (name, "skins/%s.pcx", baseskin.string);
		raw = COM_LoadTempFile (name);
		if (!raw)
		{
			skin->failedload = true;
			return NULL;
		}
	}

//
// parse the PCX file
//
	pcx = (pcx_t *)raw;
	raw = &pcx->data;

	if (pcx->manufacturer != 0x0a
		|| pcx->version != 5
		|| pcx->encoding != 1
		|| pcx->bits_per_pixel != 8
		|| pcx->xmax >= 320
		|| pcx->ymax >= 200)
	{
		skin->failedload = true;
		Con_Printf ("Bad skin %s\n", name);
		return NULL;
	}
	
	out = Cache_Alloc (&skin->cache, 320*200, skin->name);
	if (!out)
		Sys_Error ("Skin_Cache: couldn't allocate");

	pix = out;
	memset (out, 0, 320*200);

	for (y=0 ; y<pcx->ymax ; y++, pix += 320)
	{
		for (x=0 ; x<=pcx->xmax ; )
		{
			if (raw - (byte*)pcx > com_filesize) 
			{
				Cache_Free (&skin->cache);
				skin->failedload = true;
				Con_Printf ("Skin %s was malformed.  You should delete it.\n", name);
				return NULL;
			}
			dataByte = *raw++;

			if((dataByte & 0xC0) == 0xC0)
			{
				runLength = dataByte & 0x3F;
				if (raw - (byte*)pcx > com_filesize) 
				{
					Cache_Free (&skin->cache);
					skin->failedload = true;
					Con_Printf ("Skin %s was malformed.  You should delete it.\n", name);
					return NULL;
				}
				dataByte = *raw++;
			}
			else
				runLength = 1;

			// skin sanity check
			if (runLength + x > pcx->xmax + 2) {
				Cache_Free (&skin->cache);
				skin->failedload = true;
				Con_Printf ("Skin %s was malformed.  You should delete it.\n", name);
				return NULL;
			}
			while(runLength-- > 0)
				pix[x++] = dataByte;
		}

	}

	if ( raw - (byte *)pcx > com_filesize)
	{
		Cache_Free (&skin->cache);
		skin->failedload = true;
		Con_Printf ("Skin %s was malformed.  You should delete it.\n", name);
		return NULL;
	}

	skin->failedload = false;

	return out;
}
Пример #16
0
/*
=================
Mod_LoadAliasModel
=================
*/
void Mod_LoadAliasModel (model_t *mod, void *buffer)
{
	int					i, j;
	mdl_t				*pinmodel;
	stvert_t			*pinstverts;
	dtriangle_t			*pintriangles;
	int					version, numframes;
	int					size;
	daliasframetype_t	*pframetype;
	daliasskintype_t	*pskintype;
	int					start, end, total;

	if (!strcmp(loadmodel->name, "progs/player.mdl") ||
		!strcmp(loadmodel->name, "progs/eyes.mdl")) {
		unsigned short crc;
		byte *p;
		int len;
		char st[40];

		CRC_Init(&crc);
		for (len = com_filesize, p = buffer; len; len--, p++)
			CRC_ProcessByte(&crc, *p);
	
		sprintf(st, "%d", (int) crc);
		Info_SetValueForKey (cls.userinfo, 
			!strcmp(loadmodel->name, "progs/player.mdl") ? pmodel_name : emodel_name,
			st, MAX_INFO_STRING);

		if (cls.state >= ca_connected) {
			MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
			sprintf(st, "setinfo %s %d", 
				!strcmp(loadmodel->name, "progs/player.mdl") ? pmodel_name : emodel_name,
				(int)crc);
			SZ_Print (&cls.netchan.message, st);
		}
	}
	
	start = Hunk_LowMark ();

	pinmodel = (mdl_t *)buffer;

	version = LittleLong (pinmodel->version);
	if (version != ALIAS_VERSION)
		Sys_Error ("%s has wrong version number (%i should be %i)",
				 mod->name, version, ALIAS_VERSION);

//
// allocate space for a working header, plus all the data except the frames,
// skin and group info
//
	size = 	sizeof (aliashdr_t) 
			+ (LittleLong (pinmodel->numframes) - 1) *
			sizeof (pheader->frames[0]);
	pheader = Hunk_AllocName (size, loadname);
	
	mod->flags = LittleLong (pinmodel->flags);

//
// endian-adjust and copy the data, starting with the alias model header
//
	pheader->boundingradius = LittleFloat (pinmodel->boundingradius);
	pheader->numskins = LittleLong (pinmodel->numskins);
	pheader->skinwidth = LittleLong (pinmodel->skinwidth);
	pheader->skinheight = LittleLong (pinmodel->skinheight);

	if (pheader->skinheight > MAX_LBM_HEIGHT)
		Sys_Error ("model %s has a skin taller than %d", mod->name,
				   MAX_LBM_HEIGHT);

	pheader->numverts = LittleLong (pinmodel->numverts);

	if (pheader->numverts <= 0)
		Sys_Error ("model %s has no vertices", mod->name);

	if (pheader->numverts > MAXALIASVERTS)
		Sys_Error ("model %s has too many vertices", mod->name);

	pheader->numtris = LittleLong (pinmodel->numtris);

	if (pheader->numtris <= 0)
		Sys_Error ("model %s has no triangles", mod->name);

	pheader->numframes = LittleLong (pinmodel->numframes);
	numframes = pheader->numframes;
	if (numframes < 1)
		Sys_Error ("Mod_LoadAliasModel: Invalid # of frames: %d\n", numframes);

	pheader->size = LittleFloat (pinmodel->size) * ALIAS_BASE_SIZE_RATIO;
	mod->synctype = LittleLong (pinmodel->synctype);
	mod->numframes = pheader->numframes;

	for (i=0 ; i<3 ; i++)
	{
		pheader->scale[i] = LittleFloat (pinmodel->scale[i]);
		pheader->scale_origin[i] = LittleFloat (pinmodel->scale_origin[i]);
		pheader->eyeposition[i] = LittleFloat (pinmodel->eyeposition[i]);
	}


//
// load the skins
//
	pskintype = (daliasskintype_t *)&pinmodel[1];
	pskintype = Mod_LoadAllSkins (pheader->numskins, pskintype);

//
// load base s and t vertices
//
	pinstverts = (stvert_t *)pskintype;

	for (i=0 ; i<pheader->numverts ; i++)
	{
		stverts[i].onseam = LittleLong (pinstverts[i].onseam);
		stverts[i].s = LittleLong (pinstverts[i].s);
		stverts[i].t = LittleLong (pinstverts[i].t);
	}

//
// load triangle lists
//
	pintriangles = (dtriangle_t *)&pinstverts[pheader->numverts];

	for (i=0 ; i<pheader->numtris ; i++)
	{
		triangles[i].facesfront = LittleLong (pintriangles[i].facesfront);

		for (j=0 ; j<3 ; j++)
		{
			triangles[i].vertindex[j] =
					LittleLong (pintriangles[i].vertindex[j]);
		}
	}

//
// load the frames
//
	posenum = 0;
	pframetype = (daliasframetype_t *)&pintriangles[pheader->numtris];

	for (i=0 ; i<numframes ; i++)
	{
		aliasframetype_t	frametype;

		frametype = LittleLong (pframetype->type);

		if (frametype == ALIAS_SINGLE)
		{
			pframetype = (daliasframetype_t *)
					Mod_LoadAliasFrame (pframetype + 1, &pheader->frames[i]);
		}
		else
		{
			pframetype = (daliasframetype_t *)
					Mod_LoadAliasGroup (pframetype + 1, &pheader->frames[i]);
		}
	}

	pheader->numposes = posenum;

	mod->type = mod_alias;

// FIXME: do this right
	mod->mins[0] = mod->mins[1] = mod->mins[2] = -16;
	mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16;

	//
	// build the draw lists
	//
	GL_MakeAliasModelDisplayLists (mod, pheader);

//
// move the complete, relocatable alias model to the cache
//	
	end = Hunk_LowMark ();
	total = end - start;
	
	Cache_Alloc (&mod->cache, total, loadname);
	if (!mod->cache.data)
		return;
	memcpy (mod->cache.data, pheader, total);

	Hunk_FreeToLowMark (start);
}
Пример #17
0
/*
=================
Mod_LoadAliasModel
=================
*/
void Mod_LoadAliasModel (model_t *mod, void *buffer)
{
    int					i, j;
    mdl_t				*pinmodel;
    stvert_t			*pinstverts;
    dtriangle_t			*pintriangles;
    int					version, numframes, numskins;
    int					size;
    daliasframetype_t	*pframetype;
    daliasskintype_t	*pskintype;
    int					start, end, total;

    start = Hunk_LowMark ();

    pinmodel = (mdl_t *)buffer;

    version = LittleLong (pinmodel->version);
    if (version != ALIAS_VERSION)
        Sys_Error ("%s has wrong version number (%i should be %i)",
                   mod->name, version, ALIAS_VERSION);

//
// allocate space for a working header, plus all the data except the frames,
// skin and group info
//
    size = 	sizeof (aliashdr_t)
            + (LittleLong (pinmodel->numframes) - 1) *
            sizeof (pheader->frames[0]);
    pheader = Hunk_AllocName (size, loadname);

    mod->flags = LittleLong (pinmodel->flags);

//
// endian-adjust and copy the data, starting with the alias model header
//
    pheader->boundingradius = LittleFloat (pinmodel->boundingradius);
    pheader->numskins = LittleLong (pinmodel->numskins);
    pheader->skinwidth = LittleLong (pinmodel->skinwidth);
    pheader->skinheight = LittleLong (pinmodel->skinheight);

    if (pheader->skinheight > MAX_LBM_HEIGHT)
        Sys_Error ("model %s has a skin taller than %d", mod->name,
                   MAX_LBM_HEIGHT);

    pheader->numverts = LittleLong (pinmodel->numverts);

    if (pheader->numverts <= 0)
        Sys_Error ("model %s has no vertices", mod->name);

    if (pheader->numverts > MAXALIASVERTS)
        Sys_Error ("model %s has too many vertices", mod->name);

    pheader->numtris = LittleLong (pinmodel->numtris);

    if (pheader->numtris <= 0)
        Sys_Error ("model %s has no triangles", mod->name);

    pheader->numframes = LittleLong (pinmodel->numframes);
    numframes = pheader->numframes;
    if (numframes < 1)
        Sys_Error ("Mod_LoadAliasModel: Invalid # of frames: %d\n", numframes);

    pheader->size = LittleFloat (pinmodel->size) * ALIAS_BASE_SIZE_RATIO;
    mod->synctype = LittleLong (pinmodel->synctype);
    mod->numframes = pheader->numframes;

    for (i=0 ; i<3 ; i++)
    {
        pheader->scale[i] = LittleFloat (pinmodel->scale[i]);
        pheader->scale_origin[i] = LittleFloat (pinmodel->scale_origin[i]);
        pheader->eyeposition[i] = LittleFloat (pinmodel->eyeposition[i]);
    }


//
// load the skins
//
    pskintype = (daliasskintype_t *)&pinmodel[1];
    pskintype = Mod_LoadAllSkins (pheader->numskins, pskintype);

//
// load base s and t vertices
//
    pinstverts = (stvert_t *)pskintype;

    for (i=0 ; i<pheader->numverts ; i++)
    {
        stverts[i].onseam = LittleLong (pinstverts[i].onseam);
        stverts[i].s = LittleLong (pinstverts[i].s);
        stverts[i].t = LittleLong (pinstverts[i].t);
    }

//
// load triangle lists
//
    pintriangles = (dtriangle_t *)&pinstverts[pheader->numverts];

    for (i=0 ; i<pheader->numtris ; i++)
    {
        triangles[i].facesfront = LittleLong (pintriangles[i].facesfront);

        for (j=0 ; j<3 ; j++)
        {
            triangles[i].vertindex[j] =
                LittleLong (pintriangles[i].vertindex[j]);
        }
    }

//
// load the frames
//
    posenum = 0;
    pframetype = (daliasframetype_t *)&pintriangles[pheader->numtris];

    for (i=0 ; i<numframes ; i++)
    {
        aliasframetype_t	frametype;

        frametype = LittleLong (pframetype->type);

        if (frametype == ALIAS_SINGLE)
        {
            pframetype = (daliasframetype_t *)
                         Mod_LoadAliasFrame (pframetype + 1, &pheader->frames[i]);
        }
        else
        {
            pframetype = (daliasframetype_t *)
                         Mod_LoadAliasGroup (pframetype + 1, &pheader->frames[i]);
        }
    }

    pheader->numposes = posenum;

    mod->type = mod_alias;

// FIXME: do this right
    mod->mins[0] = mod->mins[1] = mod->mins[2] = -16;
    mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16;

    //
    // build the draw lists
    //
    GL_MakeAliasModelDisplayLists (mod, pheader);

//
// move the complete, relocatable alias model to the cache
//
    end = Hunk_LowMark ();
    total = end - start;

    Cache_Alloc (&mod->cache, total, loadname);
    if (!mod->cache.data)
        return;
    memcpy (mod->cache.data, pheader, total);

    Hunk_FreeToLowMark (start);
}
Пример #18
0
/*
==============
S_LoadSound
==============
*/
sfxcache_t *S_LoadSound (sfx_t *s)
{
    char	namebuffer[MAX_QPATH];
	byte	*data;
	wavinfo_t	info;
	int		len;
	float	stepscale;
	sfxcache_t	*sc;
	int		size;
	char	*name;
	int		close_file = 0;
	extern int s_in_precache;

	if(r_rache_is_empty) {
		return NULL;
	}

	if (s->name[0] == '*')
		return NULL;

	sc = (sfxcache_t *)Cache_Check (&ds_snd_cache,&(s->extradata));
	if (sc)
		return sc;

	if(s_in_precache == 0) {
		s_in_precache = 0;
	}

//Com_Printf ("S_LoadSound: %x\n", (int)stackbuf);
// load it in
	if (s->truename)
		name = s->truename;
	else
		name = s->name;

	if (name[0] == '#')
		strcpy(namebuffer, &name[1]);
	else
		Com_sprintf (namebuffer, sizeof(namebuffer), "sound/%s", name);

	//printf ("%s\n",namebuffer);

	FILE *h = (FILE *)s->handle;
	size = s->len;
	if(h == 0) {
		close_file = 1;
		//size = FS_LoadFile (namebuffer, (void **)&data);
		size = FS_FOpenFile (namebuffer, &h);
	} else {
		ds_fseek (h, s->pos, SEEK_SET);
	}
	if (!h) {
		Com_DPrintf ("Couldn't load %s\n", namebuffer);
		return NULL;
	}
	r_cache_set_fail(0);
	data = (byte *)Z_Malloc(size);
	if (!data)
	{
		r_cache_set_fail(1);
		if(close_file) {
			ds_fclose (h);
		}
		Com_DPrintf ("Couldn't load %s\n", namebuffer);
		return NULL;
	}
	FS_Read (data, size, h);
	if(close_file) {
		ds_fclose (h);
		s->handle = g_pack_file;
		s->pos = g_pack_file_pos;
		s->len = g_pack_file_len;
	}

	info = GetWavinfo (s->name, data, size);
	if (info.channels != 1)
	{
		r_cache_set_fail(1);
		Com_DPrintf ("%s is a stereo sample\n",s->name);
		//FS_FreeFile (data);
		Z_Free(data);
		return NULL;
	}

	stepscale = (float)info.rate / dma.speed;	
	len = info.samples / stepscale;
	/*if (info.width != 1)
	{
		r_cache_set_fail(1);
		printf ("%s is a 16 bit sample\n",s->name);
		//FS_FreeFile (data);
		Z_Free(data);
		return NULL;
	}*/

	//we are forcing 8 bit sound
	//len = len * info.width * info.channels;

	Cache_Alloc(&ds_snd_cache,(cache_user_t *)&(s->extradata),len + sizeof(sfxcache_t) + 4,s->name);

	/*cached_t *ds = DS_CacheAlloc(&ds_snd_cache,len + sizeof(sfxcache_t) + 4);
	if(!ds) {
		r_cache_set_fail(1);
		//FS_FreeFile (data);
		Z_Free(data);
		return NULL;
	}
	ds->owner = (cached_t **)&s->cache;
	ds->visframe = r_framecount;
	sc = s->cache = (sfxcache_t *)(ds+1);
	*/
	//sc = s->cache = (sfxcache_t *)Hunk_Alloc (len + sizeof(sfxcache_t) + 4);//pad by 4 just to be certain - too lazy to check
	sc = (sfxcache_t *)s->extradata;
	if (!sc)
	{
		r_cache_set_fail(1);
		//FS_FreeFile (data);
		Z_Free(data);
		return NULL;
	}
	r_cache_set_fail(1);
	
	sc->length = info.samples;
	sc->loopstart = info.loopstart;
	sc->speed = info.rate;
	sc->width = info.width;
	sc->stereo = info.channels;

	ResampleSfx (s, sc->speed, sc->width, data + info.dataofs);

	//FS_FreeFile (data);
	Z_Free(data);

	return sc;
}