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

Iskhodnyy_kod_Doom

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

drawseg_t*

ds;

short

clipbot[SCREENWIDTH];

short

cliptop[SCREENWIDTH];

int

x;

int

r1;

int

r2;

fixed_t

scale;

fixed_t

lowscale;

int

silhouette;

for (x = spr->x1 ; x<=spr->x2 ; x++) clipbot[x] = cliptop[x] = -2;

//Scan drawsegs from end to start for obscuring segs.

//The first drawseg that has a greater scale

//is the clip seg.

for (ds=ds_p-1 ; ds >= drawsegs ; ds--)

{

// determine if the drawseg obscures the sprite if (ds->x1 > spr->x2

||ds->x2 < spr->x1

||(!ds->silhouette

&&!ds->maskedtexturecol) )

{

// does not cover sprite continue;

}

r1 = ds->x1 < spr->x1 ? spr->x1 : ds->x1; r2 = ds->x2 > spr->x2 ? spr->x2 : ds->x2;

if (ds->scale1 > ds->scale2)

{

lowscale = ds->scale2; scale = ds->scale1;

}

else

{

lowscale = ds->scale1; scale = ds->scale2;

}

if (scale < spr->scale

||( lowscale < spr->scale

&&!R_PointOnSegSide (spr->gx, spr->gy, ds->curline) ) )

{

// masked mid texture?

if (ds->maskedtexturecol) R_RenderMaskedSegRange (ds, r1, r2);

// seg is behind sprite continue;

}

// clip this piece of the sprite silhouette = ds->silhouette;

if (spr->gz >= ds->bsilheight) silhouette &= ~SIL_BOTTOM;

if (spr->gzt <= ds->tsilheight) silhouette &= ~SIL_TOP;

if (silhouette == 1)

{

701

// bottom sil

for (x=r1 ; x<=r2 ; x++) if (clipbot[x] == -2)

clipbot[x] = ds->sprbottomclip[x];

}

else if (silhouette == 2)

{

// top sil

for (x=r1 ; x<=r2 ; x++) if (cliptop[x] == -2)

cliptop[x] = ds->sprtopclip[x];

}

else if (silhouette == 3)

{

// both

for (x=r1 ; x<=r2 ; x++)

{

if

(clipbot[x]

== -2)

 

clipbot[x]

=

ds->sprbottomclip[x];

if

(cliptop[x]

== -2)

 

cliptop[x]

=

ds->sprtopclip[x];

}

}

}

//all clipping has been performed, so draw the sprite

//check for unclipped columns

for (x = spr->x1 ; x<=spr->x2 ; x++)

{

if (clipbot[x] == -2) clipbot[x] = viewheight;

if (cliptop[x] == -2) cliptop[x] = -1;

}

mfloorclip = clipbot; mceilingclip = cliptop;

R_DrawVisSprite (spr, spr->x1, spr->x2);

}

//

// R_DrawMasked

//

void R_DrawMasked (void)

{

vissprite_t*

spr;

drawseg_t*

ds;

R_SortVisSprites ();

if (vissprite_p > vissprites)

{

// draw all vissprites back to front for (spr = vsprsortedhead.next ;

spr != &vsprsortedhead ; spr=spr->next)

{

R_DrawSprite (spr);

702

}

}

//render any remaining masked mid textures for (ds=ds_p-1 ; ds >= drawsegs ; ds--)

if (ds->maskedtexturecol)

R_RenderMaskedSegRange (ds, ds->x1, ds->x2);

//draw the psprites on top of everything

//but does not draw on side views

if (!viewangleoffset) R_DrawPlayerSprites ();

}

10.19r things.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:

//Rendering of moving objects, sprites.

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

#ifndef __R_THINGS__ #define __R_THINGS__

#ifdef __GNUG__ #pragma interface #endif

#define MAXVISSPRITES

128

extern vissprite_t

vissprites[MAXVISSPRITES];

extern

vissprite_t*

vissprite_p;

extern

vissprite_t

vsprsortedhead;

//Constant arrays used for psprite clipping

//and initializing clipping.

extern short

negonearray[SCREENWIDTH];

extern short

screenheightarray[SCREENWIDTH];

// vars for R_DrawMaskedColumn

extern short*

mfloorclip;

extern short*

mceilingclip;

extern fixed_t

spryscale;

703

extern fixed_t

sprtopscreen;

extern

fixed_t

pspritescale;

extern

fixed_t

pspriteiscale;

void R_DrawMaskedColumn (column_t* column);

void R_SortVisSprites (void);

void R_AddSprites (sector_t* sec); void R_AddPSprites (void);

void R_DrawSprites (void);

void R_InitSprites (char** namelist); void R_ClearSprites (void);

void R_DrawMasked (void);

void

 

 

 

 

R_ClipVisSprite

 

( vissprite_t*

vis,

int

 

 

 

xl,

int

 

 

 

xh );

#endif

 

 

 

 

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

 

 

 

 

//

 

 

 

 

// $Log:$

 

//

 

 

 

 

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

 

 

 

 

11

Sound code

 

11.1

s

 

sound.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

//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: none

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

static const char

rcsid[] = "$Id: s_sound.c,v 1.6 1997/02/03 22:45:12 b1 Exp $";

704

#include <stdio.h> #include <stdlib.h>

#include "i_system.h" #include "i_sound.h" #include "sounds.h"

#include "s_sound.h"

#include "z_zone.h" #include "m_random.h" #include "w_wad.h"

#include "doomdef.h" #include "p_local.h"

#include "doomstat.h"

// Purpose?

const char snd_prefixen[]

= { ’P’, ’P’, ’A’, ’S’, ’S’, ’S’, ’M’, ’M’, ’M’, ’S’, ’S’, ’S’ };

#define S_MAX_VOLUME

127

//when to clip out sounds

//Does not fit the large outdoor areas.

#define S_CLIPPING_DIST

(1200*0x10000)

//Distance tp origin when sounds should be maxed out.

//This should relate to movement clipping resolution

//(see BLOCKMAP handling).

//Originally: (200*0x10000).

#define S_CLOSE_DIST

(160*0x10000)

#define S_ATTENUATOR

((S_CLIPPING_DIST-S_CLOSE_DIST)>>FRACBITS)

// Adjustable by menu.

 

#define NORM_VOLUME

snd_MaxVolume

#define NORM_PITCH

128

#define NORM_PRIORITY

64

#define NORM_SEP

128

#define S_PITCH_PERTURB

1

#define S_STEREO_SWING

(96*0x10000)

// percent attenuation from front to back

#define S_IFRACVOL

30

#define NA

0

#define S_NUMCHANNELS

2

//Current music/sfx card - index useless

//w/o a reference LUT in a sound module. extern int snd_MusicDevice;

extern int snd_SfxDevice;

//Config file? Same disclaimer as above. extern int snd_DesiredMusicDevice;

extern int snd_DesiredSfxDevice;

typedef struct

705

{

 

 

//

sound information (if null, channel avail.)

sfxinfo_t*

sfxinfo;

//

origin of sound

void*

origin;

//

handle of the sound being played

int

 

handle;

} channel_t;

 

// the

set of channels available

static

channel_t*

channels;

//These are not used, but should be (menu).

//Maximum volume of a sound effect.

//Internal default is max out of 0-15.

int snd_SfxVolume = 15;

// Maximum volume of music. Useless so far.

int

snd_MusicVolume = 15;

//

whether songs are mus_paused

static boolean

mus_paused;

//

music currently being played

static musicinfo_t*

mus_playing=0;

//following is set

//by the defaults code in M_misc:

//number of channels available

int

numChannels;

static int

nextcleanup;

//

 

// Internals.

 

//

 

int

 

S_getChannel

 

( void*

origin,

sfxinfo_t*

sfxinfo );

int S_AdjustSoundParams

( mobj_t*

listener,

mobj_t*

source,

int*

vol,

int*

sep,

int*

pitch );

void S_StopChannel(int cnum);

//

//Initializes sound stuff, including volume

//Sets channels, SFX and music volume,

706

sfxVolume, musicVolume )
i;

// allocates channel buffer, sets S_sfx lookup.

//

void S_Init ( int

int

{

int

fprintf( stderr, "S_Init: default sfx volume %d\n", sfxVolume);

// Whatever these did with DMX, these are rather dummies now. I_SetChannels();

S_SetSfxVolume(sfxVolume);

//No music with Linux - another dummy. S_SetMusicVolume(musicVolume);

//Allocating the internal channels for mixing

//(the maximum numer of sounds rendered

//simultaneously) within zone memory. channels =

(channel_t *) Z_Malloc(numChannels*sizeof(channel_t), PU_STATIC, 0);

//Free all channels for use

for (i=0 ; i<numChannels ; i++) channels[i].sfxinfo = 0;

//no sounds are playing, and they are not mus_paused mus_paused = 0;

//Note that sounds have not been cached (yet).

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

S_sfx[i].lumpnum = S_sfx[i].usefulness = -1;

}

//

//Per level startup code.

//Kills playing sounds at start of level,

//determines music if any, changes music.

void S_Start(void)

{

int cnum; int mnum;

//kill all playing sounds at start of level

//(trust me - a good idea)

for (cnum=0 ; cnum<numChannels ; cnum++) if (channels[cnum].sfxinfo)

S_StopChannel(cnum);

// start new music for the level mus_paused = 0;

if (gamemode == commercial)

mnum = mus_runnin + gamemap - 1; else

{

int spmus[]=

{

// Song - Who? - Where?

707

mus_e3m4,

// American

e4m1

mus_e3m2,

// Romero

e4m2

mus_e3m3,

// Shawn

e4m3

mus_e1m5,

// American

e4m4

mus_e2m7,

// Tim

e4m5

mus_e2m4,

// Romero

e4m6

mus_e2m6,

// J.Anderson

e4m7 CHIRON.WAD

mus_e2m5,

// Shawn

e4m8

mus_e1m9

// Tim

e4m9

};

if (gameepisode < 4)

mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1; else

mnum = spmus[gamemap-1];

}

//HACK FOR COMMERCIAL

//if (commercial && mnum > mus_e3m9)

//mnum -= mus_e3m9;

S_ChangeMusic(mnum, true);

nextcleanup = 15;

}

void S_StartSoundAtVolume

( void*

origin_p,

int

sfx_id,

int

volume )

{

 

int

rc;

int

sep;

int

pitch;

int

priority;

sfxinfo_t*

sfx;

int

cnum;

mobj_t*

origin = (mobj_t *) origin_p;

//Debug. /*fprintf( stderr,

"S_StartSoundAtVolume: playing sound %d (%s)\n", sfx_id, S_sfx[sfx_id].name );*/

//check for bogus sound #

if (sfx_id < 1 || sfx_id > NUMSFX) I_Error("Bad sfx #: %d", sfx_id);

sfx = &S_sfx[sfx_id];

// Initialize sound parameters if (sfx->link)

{

pitch = sfx->pitch; priority = sfx->priority; volume += sfx->volume;

708

if (volume < 1) return;

if (volume > snd_SfxVolume) volume = snd_SfxVolume;

}

else

{

pitch = NORM_PITCH; priority = NORM_PRIORITY;

}

//Check to see if it is audible,

//and if not, modify the params

if (origin && origin != players[consoleplayer].mo)

{

rc = S_AdjustSoundParams(players[consoleplayer].mo, origin,

&volume,

&sep,

&pitch);

if ( origin->x == players[consoleplayer].mo->x

 

&& origin->y == players[consoleplayer].mo->y)

{

 

sep

= NORM_SEP;

}

if (!rc) return;

}

else

{

sep = NORM_SEP;

}

// hacks to vary the sfx pitches if (sfx_id >= sfx_sawup

&& sfx_id <= sfx_sawhit)

{

pitch += 8 - (M_Random()&15);

if (pitch<0) pitch = 0;

else if (pitch>255) pitch = 255;

}

else if (sfx_id != sfx_itemup && sfx_id != sfx_tink)

{

pitch += 16 - (M_Random()&31);

if (pitch<0) pitch = 0;

else if (pitch>255) pitch = 255;

}

// kill old sound S_StopSound(origin);

// try to find a channel

cnum = S_getChannel(origin, sfx);

709

if (cnum<0) return;

//

//This is supposed to handle the loading/caching.

//For some odd reason, the caching is done nearly

//each time the sound is needed?

//

// get lumpnum if necessary if (sfx->lumpnum < 0)

sfx->lumpnum = I_GetSfxLumpNum(sfx);

#ifndef SNDSRV

// cache data if necessary if (!sfx->data)

{

fprintf( stderr,

"S_StartSoundAtVolume: 16bit and not pre-cached - wtf?\n");

// DOS remains, 8bit handling

//sfx->data = (void *) W_CacheLumpNum(sfx->lumpnum, PU_MUSIC);

//fprintf( stderr,

//"S_StartSoundAtVolume: loading %d (lump %d) : 0x%x\n",

//sfx_id, sfx->lumpnum, (int)sfx->data );

}

#endif

//increase the usefulness if (sfx->usefulness++ < 0)

sfx->usefulness = 1;

//Assigns the handle to one of the channels in the

//mix/output buffer.

channels[cnum].handle = I_StartSound(sfx_id, /*sfx->data,*/ volume,

sep,

pitch,

priority);

}

void

 

S_StartSound

 

( void*

origin,

int

sfx_id )

{

 

#ifdef SAWDEBUG

 

//if (sfx_id == sfx_sawful)

//sfx_id = sfx_itemup;

#endif

S_StartSoundAtVolume(origin, sfx_id, snd_SfxVolume);

// UNUSED. We had problems, had we not? #ifdef SAWDEBUG

{

int i; int n;

static mobj_t*

last_saw_origins[10] = {1,1,1,1,1,1,1,1,1,1};

static

int

first_saw=0;

static

int

next_saw=0;

710

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