Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Iskhodnyy_kod_Doom

.pdf
Скачиваний:
7
Добавлен:
13.02.2015
Размер:
1.01 Mб
Скачать

if (sfx_id == sfx_sawidl

||sfx_id == sfx_sawful

||sfx_id == sfx_sawhit)

{

for (i=first_saw;i!=next_saw;i=(i+1)%10) if (last_saw_origins[i] != origin)

fprintf(stderr, "old origin 0x%lx != " "origin 0x%lx for sfx %d\n", last_saw_origins[i],

origin, sfx_id);

last_saw_origins[next_saw] = origin; next_saw = (next_saw + 1) % 10;

if (next_saw == first_saw)

first_saw = (first_saw + 1) % 10;

for (n=i=0; i<numChannels ; i++)

{

if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]

||channels[i].sfxinfo == &S_sfx[sfx_sawful]

||channels[i].sfxinfo == &S_sfx[sfx_sawhit]) n++;

}

if (n>1)

{

for (i=0; i<numChannels ; i++)

{

if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]

||channels[i].sfxinfo == &S_sfx[sfx_sawful]

||channels[i].sfxinfo == &S_sfx[sfx_sawhit])

{

fprintf(stderr,

"chn: sfxinfo=0x%lx, origin=0x%lx, " "handle=%d\n",

channels[i].sfxinfo,

channels[i].origin,

channels[i].handle);

}

}

fprintf(stderr, "\n");

}

}

}

#endif

}

void S_StopSound(void *origin)

{

int cnum;

for (cnum=0 ; cnum<numChannels ; cnum++)

{

if (channels[cnum].sfxinfo && channels[cnum].origin == origin)

{

S_StopChannel(cnum); break;

}

}

711

}

//

// Stop and resume music, during game PAUSE.

//

void S_PauseSound(void)

{

if (mus_playing && !mus_paused)

{

I_PauseSong(mus_playing->handle); mus_paused = true;

}

}

void S_ResumeSound(void)

{

if (mus_playing && mus_paused)

{

I_ResumeSong(mus_playing->handle); mus_paused = false;

}

}

//

// Updates music & sounds

//

void S_UpdateSounds(void* listener_p)

{

int

audible;

int

cnum;

int

volume;

int

sep;

int

pitch;

sfxinfo_t*

sfx;

channel_t*

c;

mobj_t*

listener = (mobj_t*)listener_p;

//Clean up unused data.

//This is currently not done for 16bit (sounds cached static).

//DOS 8bit remains.

/*if (gametic > nextcleanup)

{

for (i=1 ; i<NUMSFX ; i++)

{

if (S_sfx[i].usefulness < 1

&& S_sfx[i].usefulness > -1)

{

if (--S_sfx[i].usefulness == -1)

{

Z_ChangeTag(S_sfx[i].data, PU_CACHE);

S_sfx[i].data = 0;

}

}

712

}

nextcleanup = gametic + 15;

}*/

for (cnum=0 ; cnum<numChannels ; cnum++)

{

c = &channels[cnum]; sfx = c->sfxinfo;

if (c->sfxinfo)

{

if (I_SoundIsPlaying(c->handle))

{

// initialize parameters volume = snd_SfxVolume; pitch = NORM_PITCH;

sep = NORM_SEP;

if (sfx->link)

{

pitch = sfx->pitch; volume += sfx->volume; if (volume < 1)

{

S_StopChannel(cnum); continue;

}

else if (volume > snd_SfxVolume)

{

volume = snd_SfxVolume;

}

}

//check non-local sounds for distance clipping

//or modify their params

if (c->origin && listener_p != c->origin)

{

audible = S_AdjustSoundParams(listener, c->origin, &volume, &sep, &pitch);

if (!audible)

{

S_StopChannel(cnum);

}

else

I_UpdateSoundParams(c->handle, volume, sep, pitch);

}

}

else

{

//if channel is allocated but sound has stopped,

//free it

S_StopChannel(cnum);

}

}

}

// kill music if it is a single-play && finished

// if ( mus_playing

//&& !I_QrySongPlaying(mus_playing->handle)

//&& !mus_paused )

//S_StopMusic();

}

713

void S_SetMusicVolume(int volume)

{

if (volume < 0 || volume > 127)

{

I_Error("Attempt to set music volume at %d", volume);

}

I_SetMusicVolume(127); I_SetMusicVolume(volume); snd_MusicVolume = volume;

}

void S_SetSfxVolume(int volume)

{

if (volume < 0 || volume > 127)

I_Error("Attempt to set sfx volume at %d", volume);

snd_SfxVolume = volume;

}

//

// Starts some music with the music id found in sounds.h.

//

void S_StartMusic(int m_id)

{

S_ChangeMusic(m_id, false);

}

void

 

S_ChangeMusic

 

( int

musicnum,

int

looping )

{

 

musicinfo_t*

music;

char

namebuf[9];

if ( (musicnum <= mus_None)

|| (musicnum >= NUMMUSIC) )

{

I_Error("Bad music number %d", musicnum);

}

else

music = &S_music[musicnum];

if (mus_playing == music) return;

//shutdown old music S_StopMusic();

//get lumpnum if neccessary if (!music->lumpnum)

{

sprintf(namebuf, "d_%s", music->name); music->lumpnum = W_GetNumForName(namebuf);

}

//load & register it

714

music->data = (void *) W_CacheLumpNum(music->lumpnum, PU_MUSIC); music->handle = I_RegisterSong(music->data);

// play it I_PlaySong(music->handle, looping);

mus_playing = music;

}

void S_StopMusic(void)

{

if (mus_playing)

{

if (mus_paused) I_ResumeSong(mus_playing->handle);

I_StopSong(mus_playing->handle);

I_UnRegisterSong(mus_playing->handle);

Z_ChangeTag(mus_playing->data, PU_CACHE);

mus_playing->data = 0; mus_playing = 0;

}

}

void S_StopChannel(int cnum)

{

int

i;

 

channel_t*

c =

&channels[cnum];

if (c->sfxinfo)

{

// stop the sound playing

if (I_SoundIsPlaying(c->handle))

{

#ifdef SAWDEBUG

if (c->sfxinfo == &S_sfx[sfx_sawful]) fprintf(stderr, "stopped\n");

#endif

I_StopSound(c->handle);

}

//check to see

//if other channels are playing the sound for (i=0 ; i<numChannels ; i++)

{

if (cnum != i

&&c->sfxinfo == channels[i].sfxinfo)

{

break;

}

}

// degrade usefulness of sound data c->sfxinfo->usefulness--;

c->sfxinfo = 0;

}

}

715

//

//Changes volume, stereo-separation, and pitch variables

//from the norm of a sound effect to be played.

//If the sound is not audible, returns a 0.

//Otherwise, modifies parameters and returns 1.

//

int S_AdjustSoundParams

( mobj_t*

listener,

mobj_t*

source,

int*

vol,

int*

sep,

int*

pitch )

{

 

fixed_t

approx_dist;

fixed_t

adx;

fixed_t

ady;

angle_t

angle;

//calculate the distance to sound origin

//and clip it if necessary

adx = abs(listener->x - source->x); ady = abs(listener->y - source->y);

// From _GG1_ p.428. Appox. eucledian distance fast. approx_dist = adx + ady - ((adx < ady ? adx : ady)>>1);

if (gamemap != 8

&& approx_dist > S_CLIPPING_DIST)

{

return 0;

}

// angle of source to listener angle = R_PointToAngle2(listener->x,

listener->y, source->x, source->y);

if (angle > listener->angle)

angle = angle - listener->angle;

else

angle = angle + (0xffffffff - listener->angle);

angle >>= ANGLETOFINESHIFT;

// stereo separation

*sep = 128 - (FixedMul(S_STEREO_SWING,finesine[angle])>>FRACBITS);

// volume calculation

if (approx_dist < S_CLOSE_DIST)

{

*vol = snd_SfxVolume;

}

else if (gamemap == 8)

{

if (approx_dist > S_CLIPPING_DIST) approx_dist = S_CLIPPING_DIST;

*vol = 15+ ((snd_SfxVolume-15)

*((S_CLIPPING_DIST - approx_dist)>>FRACBITS)) / S_ATTENUATOR;

}

716

else

{

// distance effect *vol = (snd_SfxVolume

*((S_CLIPPING_DIST - approx_dist)>>FRACBITS))

/S_ATTENUATOR;

}

return (*vol > 0);

}

//

//S_getChannel :

//If none available, return -1. Otherwise channel #.

int S_getChannel

( void*

origin,

sfxinfo_t*

sfxinfo )

{

 

// channel number to use

int

cnum;

channel_t*

c;

// Find an open channel

for (cnum=0 ; cnum<numChannels ; cnum++)

{

if (!channels[cnum].sfxinfo) break;

else if (origin && channels[cnum].origin == origin)

{

S_StopChannel(cnum); break;

}

}

// None available

if (cnum == numChannels)

{

// Look for lower priority

for (cnum=0 ; cnum<numChannels ; cnum++)

if (channels[cnum].sfxinfo->priority >= sfxinfo->priority) break;

if (cnum == numChannels)

{

// FUCK! No lower priority. Sorry, Charlie. return -1;

}

else

{

// Otherwise, kick out lower priority. S_StopChannel(cnum);

}

}

c = &channels[cnum];

// channel is decided to be cnum. c->sfxinfo = sfxinfo;

c->origin = origin;

717

sfxVolume, musicVolume );

return cnum;

}

11.2 s sound.h

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//This program is free software; you can redistribute it and/or

//modify it under the terms of the GNU General Public License

//as published by the Free Software Foundation; either version 2

//of the License, or (at your option) any later version.

//

//This program is distributed in the hope that it will be useful,

//but WITHOUT ANY WARRANTY; without even the implied warranty of

//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

//GNU General Public License for more details.

//

//DESCRIPTION:

//The not so system specific sound interface.

//-----------------------------------------------------------------------------

#ifndef __S_SOUND__ #define __S_SOUND__

#ifdef __GNUG__ #pragma interface #endif

//

//Initializes sound stuff, including volume

//Sets channels, SFX and music volume,

//allocates channel buffer, sets S_sfx lookup.

void S_Init

( int int

//

//Per level startup code.

//Kills playing sounds at start of level,

//determines music if any, changes music.

void S_Start(void);

//

// Start sound for thing at <origin>

718

origin, sound_id, volume );

// using <sound_id> from sounds.h

//

 

void

 

S_StartSound

 

( void*

origin,

int

sound_id );

// Will start a sound at a given volume. void

S_StartSoundAtVolume ( void*

int int

//Stop sound for thing at <origin> void S_StopSound(void* origin);

//Start music using <music_id> from sounds.h void S_StartMusic(int music_id);

//Start music using <music_id> from sounds.h,

//and set whether looping

void S_ChangeMusic

( int

music_id,

int

looping );

// Stops the music fer sure. void S_StopMusic(void);

// Stop and resume music, during game PAUSE. void S_PauseSound(void);

void S_ResumeSound(void);

//

// Updates music & sounds

//

void S_UpdateSounds(void* listener);

void S_SetMusicVolume(int volume); void S_SetSfxVolume(int volume);

#endif //-----------------------------------------------------------------------------

//

// $Log:$

//

//-----------------------------------------------------------------------------

11.3 sounds.c

// Emacs style mode select -*- C++ -*- //-----------------------------------------------------------------------------

//

//$Id:$

//Copyright (C) 1993-1996 by id Software, Inc.

//This program is free software; you can redistribute it and/or

719

//modify it under the terms of the GNU General Public License

//as published by the Free Software Foundation; either version 2

//of the License, or (at your option) any later version.

//

//This program is distributed in the hope that it will be useful,

//but WITHOUT ANY WARRANTY; without even the implied warranty of

//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

//GNU General Public License for more details.

//

//$Log:$

//DESCRIPTION:

//Created by a sound utility.

//Kept as a sample, DOOM2 sounds.

//-----------------------------------------------------------------------------

static const char

rcsid[] = "$Id: sounds.c,v 1.3 1997/01/29 22:40:44 b1 Exp $";

#include "doomtype.h" #include "sounds.h"

//

// Information about all the music

//

musicinfo_t S_music[] =

{

{0 },

{"e1m1", 0 },

{"e1m2", 0 },

{"e1m3", 0 },

{"e1m4", 0 },

{"e1m5", 0 },

{"e1m6", 0 },

{"e1m7", 0 },

{"e1m8", 0 },

{"e1m9", 0 },

{"e2m1", 0 },

{"e2m2", 0 },

{"e2m3", 0 },

{"e2m4", 0 },

{"e2m5", 0 },

{"e2m6", 0 },

{"e2m7", 0 },

{"e2m8", 0 },

{"e2m9", 0 },

{"e3m1", 0 },

{"e3m2", 0 },

{"e3m3", 0 },

{"e3m4", 0 },

{"e3m5", 0 },

{"e3m6", 0 },

{"e3m7", 0 },

{"e3m8", 0 },

{"e3m9", 0 },

{"inter", 0 },

{"intro", 0 },

{"bunny", 0 },

{"victor", 0 },

{"introa", 0 },

{"runnin", 0 },

720

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]