Exemplo n.º 1
0
/*
* S_StartSound
*/
static void S_StartSound( sfx_t *sfx, const vec3_t origin, int entnum, int entchannel, float fvol, float attenuation )
{
	sfxcache_t *sc;
	int vol;
	playsound_t *ps, *sort;

	if( !sfx )
		return;

	// make sure the sound is loaded
	sc = S_LoadSound( sfx );
	if( !sc )
		return; // couldn't load the sound's data

	vol = fvol*255;

	// make the playsound_t
	ps = S_AllocPlaysound();
	if( !ps )
		return;

	if( origin )
	{
		VectorCopy( origin, ps->origin );
		ps->fixed_origin = true;
	}
	else
		ps->fixed_origin = false;

	ps->entnum = entnum;
	ps->entchannel = entchannel;
	ps->attenuation = attenuation;
	ps->volume = vol;
	ps->sfx = sfx;

	ps->begin = paintedtime;

	// sort into the pending sound list
	for( sort = s_pendingplays.next;
		sort != &s_pendingplays && sort->begin <= ps->begin;
		sort = sort->next )
		;

	ps->next = sort;
	ps->prev = sort->prev;

	ps->next->prev = ps;
	ps->prev->next = ps;
}
Exemplo n.º 2
0
/*
====================
S_StartSound

Validates the parms and ques the sound up
if pos is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
void S_StartSound(const vec3_t origin, int entnum, int entchannel, sfx_t *sfx, float fvol, float attenuation, float timeofs)
{
	sfxcache_t	*sc;
	playsound_t	*ps, *sort;
	int			start;

	if (!sound_started)
		return;

	if (!sfx)
		return;

	if (sfx->name[0] == '*') {
		if(entnum < 1 || entnum >= MAX_EDICTS ) {
			Com_Error( ERR_DROP, "S_StartSound: bad entnum: %d", entnum );
		}
		sfx = S_RegisterSexedSound(cl_entities[entnum].current.number, sfx->name);
	}

	// make sure the sound is loaded
	sc = S_LoadSound (sfx);
	if (!sc || sc->length <= 0)
		return;		// couldn't load the sound's data

	// make the playsound_t
	ps = S_AllocPlaysound ();
	if (!ps)
		return;

	if (origin) {
		VectorCopy (origin, ps->origin);
		ps->fixed_origin = true;
	}
	else
		ps->fixed_origin = false;

	ps->entnum = entnum;
	ps->entchannel = entchannel;
	ps->attenuation = attenuation;
	ps->sfx = sfx;

#ifdef USE_OPENAL
	if(alSound) {
		ps->volume = fvol*fvol;
		ps->begin = cl.time + (int)(timeofs * 1000);
	}
	else
#endif
	{
		ps->volume = fvol*255;
		// drift s_beginofs
		start = cl.serverTime * 0.001f * dma.speed + s_beginofs;
		if (start < paintedtime)
		{
			start = paintedtime;
			s_beginofs = start - (cl.serverTime * 0.001f * dma.speed);
		}
		else if (start > paintedtime + 0.3f * dma.speed)
		{
			start = paintedtime + 0.1f * dma.speed;
			s_beginofs = start - (cl.serverTime * 0.001f * dma.speed);
		}
		else
		{
			s_beginofs -= 10;
		}

		if (!timeofs)
			ps->begin = paintedtime;
		else
			ps->begin = start + timeofs * dma.speed;
	}

	// sort into the pending sound list
	for (sort = s_pendingplays.next;
		sort != &s_pendingplays && sort->begin < ps->begin ;
		sort = sort->next)
			;

	ps->next = sort;
	ps->prev = sort->prev;

	ps->next->prev = ps;
	ps->prev->next = ps;
}
Exemplo n.º 3
0
/*
====================
S_StartSound

Validates the parms and ques the sound up
if pos is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
void S_StartSound(const CVec3 *origin, int entnum, int entchannel, sfx_t *sfx, float fvol, float attenuation, float timeofs)
{
	if (!sound_started) return;
	if (!sfx) return;

	if (sfx->Name[0] == '*')
		sfx = GetPlayerSound(&cl_entities[entnum].current, sfx->Name);

	// make sure the sound is loaded
	sfxcache_t *sc = S_LoadSound(sfx);
	if (!sc)
		return;		// couldn't load the sound's data

	int vol = appRound(fvol*255);

	// make the playsound_t
	playsound_t *ps = S_AllocPlaysound();
	if (!ps) return;

	if (origin)
	{
		ps->origin = *origin;
		ps->fixed_origin = true;
	}
	else
		ps->fixed_origin = false;

	ps->entnum      = entnum;
	ps->entchannel  = entchannel;
	ps->attenuation = attenuation;
	ps->volume      = vol;
	ps->sfx         = sfx;

	// drift s_beginofs
	int start = appRound(cl.frame.servertime / 1000.0f * dma.speed + s_beginofs);
	if (start < paintedtime)
	{
		start = paintedtime;
		s_beginofs = start - appRound(cl.frame.servertime / 1000.0f * dma.speed);
	}
	else if (start > paintedtime + 0.3 * dma.speed)
	{
		start = appRound(paintedtime + 0.1 * dma.speed);
		s_beginofs = start - appRound(cl.frame.servertime / 1000.0f * dma.speed);
	}
	else
	{
		s_beginofs-=10;
	}

	if (!timeofs)
		ps->begin = paintedtime;
	else
		ps->begin = appRound(start + timeofs * dma.speed);

	// sort into the pending sound list
	playsound_t *sort;
	for (sort = s_pendingplays.next; sort != &s_pendingplays && sort->begin < ps->begin; sort = sort->next)
		; // empty

	ps->next = sort;
	ps->prev = sort->prev;

	ps->next->prev = ps;
	ps->prev->next = ps;
}
Exemplo n.º 4
0
/*
====================
S_StartSound

Validates the parms and ques the sound up
if pos is NULL, the sound will be dynamically sourced from the entity
Entchannel 0 will never override a playing sound
====================
*/
void S_StartSound(vec3_t origin, int entnum, int entchannel, sfx_t *sfx, float fvol, float attenuation, float timeofs)
{
	sfxcache_t	*sc;
	int			vol;
	playsound_t	*ps, *sort;
	int			start;

	if (!sound_started)
		return;

	if (!sfx)
		return;

	if (sfx->name[0] == '*')
		sfx = S_RegisterSexedSound(&cl_entities[entnum].current, sfx->name);

	// make sure the sound is loaded
	sc = S_LoadSound (sfx);
	if (!sc)
		return;		// couldn't load the sound's data

	vol = fvol*255;

	// make the playsound_t
	ps = S_AllocPlaysound ();
	if (!ps)
		return;

	if (origin)
	{
		VectorCopy (origin, ps->origin);
		ps->fixed_origin = true;
	}
	else
		ps->fixed_origin = false;

	ps->entnum = entnum;
	ps->entchannel = entchannel;
	ps->attenuation = attenuation;
	ps->volume = vol;
	ps->sfx = sfx;

	// drift s_beginofs
	start = cl.frame.servertime * 0.001 * dma.speed + s_beginofs;
	if (start < paintedtime)
	{
		start = paintedtime;
		s_beginofs = start - (cl.frame.servertime * 0.001 * dma.speed);
	}
	else if (start > paintedtime + 0.3 * dma.speed)
	{
		start = paintedtime + 0.1 * dma.speed;
		s_beginofs = start - (cl.frame.servertime * 0.001 * dma.speed);
	}
	else
	{
		s_beginofs-=10;
	}

	if (!timeofs)
		ps->begin = paintedtime;
	else
		ps->begin = start + timeofs * dma.speed;

	// sort into the pending sound list
	for (sort = s_pendingplays.next ; 
		sort != &s_pendingplays && sort->begin < ps->begin ;
		sort = sort->next)
			;

	ps->next = sort;
	ps->prev = sort->prev;

	ps->next->prev = ps;
	ps->prev->next = ps;
}