⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r_things.c

📁 使用Doom引擎开发的著名游戏《毁灭巫师》的源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
		rot = (ang-thing->angle+(unsigned)(ANG45/2)*9)>>29;		lump = sprframe->lump[rot];		flip = (boolean)sprframe->flip[rot];	}	else	{	// use single rotation for all views		lump = sprframe->lump[0];		flip = (boolean)sprframe->flip[0];	}//// calculate edges of the shape//	tx -= spriteoffset[lump];	x1 = (centerxfrac + FixedMul (tx,xscale) ) >>FRACBITS;	if (x1 > viewwidth)		return;		// off the right side	tx +=  spritewidth[lump];	x2 = ((centerxfrac + FixedMul (tx,xscale) ) >>FRACBITS) - 1;	if (x2 < 0)		return;		// off the left side//// store information in a vissprite//	vis = R_NewVisSprite ();	vis->mobjflags = thing->flags;	vis->psprite = false;	vis->scale = xscale<<detailshift;	vis->gx = thing->x;	vis->gy = thing->y;	vis->gz = thing->z;	vis->gzt = thing->z + spritetopoffset[lump];	if(thing->flags&MF_TRANSLATION)	{		if(thing->player)		{			vis->class = thing->player->class;		}		else		{			vis->class = thing->special1;		}		if(vis->class > 2)		{			vis->class = 0;		}	}	// foot clipping	vis->floorclip = thing->floorclip;	vis->texturemid = vis->gzt-viewz-vis->floorclip;	vis->x1 = x1 < 0 ? 0 : x1;	vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2;	iscale = FixedDiv (FRACUNIT, xscale);	if (flip)	{		vis->startfrac = spritewidth[lump]-1;		vis->xiscale = -iscale;	}	else	{		vis->startfrac = 0;		vis->xiscale = iscale;	}	if (vis->x1 > x1)		vis->startfrac += vis->xiscale*(vis->x1-x1);	vis->patch = lump;//// get light level////	if (thing->flags & MF_SHADOW)//		vis->colormap = NULL;			// shadow draw//	else ...	if (fixedcolormap)		vis->colormap = fixedcolormap;	// fixed map	else if(LevelUseFullBright && thing->frame&FF_FULLBRIGHT)		vis->colormap = colormaps;		// full bright	else	{									// diminished light		index = xscale>>(LIGHTSCALESHIFT-detailshift);		if (index >= MAXLIGHTSCALE)			index = MAXLIGHTSCALE-1;		vis->colormap = spritelights[index];	}}/*========================== R_AddSprites=========================*/void R_AddSprites (sector_t *sec){	mobj_t		*thing;	int			lightnum;	if (sec->validcount == validcount)		return;		// already added	sec->validcount = validcount;	lightnum = (sec->lightlevel >> LIGHTSEGSHIFT)+extralight;	if (lightnum < 0)		spritelights = scalelight[0];	else if (lightnum >= LIGHTLEVELS)		spritelights = scalelight[LIGHTLEVELS-1];	else		spritelights = scalelight[lightnum];	for (thing = sec->thinglist ; thing ; thing = thing->snext)		R_ProjectSprite (thing);}/*========================== R_DrawPSprite=========================*/// Y-adjustment values for full screen (4 weapons)int PSpriteSY[NUMCLASSES][NUMWEAPONS] ={	{ 0, -12*FRACUNIT, -10*FRACUNIT, 10*FRACUNIT }, // Fighter	{ -8*FRACUNIT, 10*FRACUNIT, 10*FRACUNIT, 0 }, // Cleric	{ 9*FRACUNIT, 20*FRACUNIT, 20*FRACUNIT, 20*FRACUNIT }, // Mage 	{ 10*FRACUNIT, 10*FRACUNIT, 10*FRACUNIT, 10*FRACUNIT } // Pig};void R_DrawPSprite (pspdef_t *psp){	fixed_t		tx;	int			x1, x2;	spritedef_t	*sprdef;	spriteframe_t	*sprframe;	int			lump;	boolean		flip;	vissprite_t	*vis, avis;	int tempangle;//// decide which patch to use//#ifdef RANGECHECK	if ( (unsigned)psp->state->sprite >= numsprites)		I_Error ("R_ProjectSprite: invalid sprite number %i "		, psp->state->sprite);#endif	sprdef = &sprites[psp->state->sprite];#ifdef RANGECHECK	if ( (psp->state->frame & FF_FRAMEMASK)  >= sprdef->numframes)		I_Error ("R_ProjectSprite: invalid sprite frame %i : %i "		, psp->state->sprite, psp->state->frame);#endif	sprframe = &sprdef->spriteframes[ psp->state->frame & FF_FRAMEMASK ];	lump = sprframe->lump[0];	flip = (boolean)sprframe->flip[0];//// calculate edges of the shape//	tx = psp->sx-160*FRACUNIT;	tx -= spriteoffset[lump];	if(viewangleoffset)
	{
		tempangle = ((centerxfrac/1024)*(viewangleoffset>>ANGLETOFINESHIFT));
	}
	else
	{
		tempangle = 0;
	}
	x1 = (centerxfrac + FixedMul (tx,pspritescale)+tempangle ) >>FRACBITS;
	if (x1 > viewwidth)
		return;		// off the right side
	tx +=  spritewidth[lump];
	x2 = ((centerxfrac + FixedMul (tx, pspritescale)+tempangle ) >>FRACBITS) - 1;
	if (x2 < 0)
		return;		// off the left side
//// store information in a vissprite//	vis = &avis;	vis->mobjflags = 0;	vis->class = 0;	vis->psprite = true;	vis->texturemid = (BASEYCENTER<<FRACBITS)+FRACUNIT/2		-(psp->sy-spritetopoffset[lump]);	if(viewheight == SCREENHEIGHT)	{		vis->texturemid -= PSpriteSY[viewplayer->class]			[players[consoleplayer].readyweapon];	}	vis->x1 = x1 < 0 ? 0 : x1;	vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2;	vis->scale = pspritescale<<detailshift;	if (flip)	{		vis->xiscale = -pspriteiscale;		vis->startfrac = spritewidth[lump]-1;	}	else	{		vis->xiscale = pspriteiscale;		vis->startfrac = 0;	}	if (vis->x1 > x1)		vis->startfrac += vis->xiscale*(vis->x1-x1);	vis->patch = lump;	if(viewplayer->powers[pw_invulnerability] && viewplayer->class		== PCLASS_CLERIC)	{		vis->colormap = spritelights[MAXLIGHTSCALE-1];		if(viewplayer->powers[pw_invulnerability] > 4*32)		{			if(viewplayer->mo->flags2&MF2_DONTDRAW)			{ // don't draw the psprite				vis->mobjflags |= MF_SHADOW;			}			else if(viewplayer->mo->flags&MF_SHADOW)			{				vis->mobjflags |= MF_ALTSHADOW;			}		}		else if(viewplayer->powers[pw_invulnerability]&8)		{			vis->mobjflags |= MF_SHADOW;		}	}		else if(fixedcolormap)	{		// Fixed color		vis->colormap = fixedcolormap;	}	else if(psp->state->frame & FF_FULLBRIGHT)	{		// Full bright		vis->colormap = colormaps;	}	else	{		// local light		vis->colormap = spritelights[MAXLIGHTSCALE-1];	}	R_DrawVisSprite(vis, vis->x1, vis->x2);}/*========================== R_DrawPlayerSprites=========================*/void R_DrawPlayerSprites (void){	int			i, lightnum;	pspdef_t	*psp;//// get light level//	lightnum = (viewplayer->mo->subsector->sector->lightlevel >> LIGHTSEGSHIFT)		+extralight;	if (lightnum < 0)		spritelights = scalelight[0];	else if (lightnum >= LIGHTLEVELS)		spritelights = scalelight[LIGHTLEVELS-1];	else		spritelights = scalelight[lightnum];//// clip to screen bounds//	mfloorclip = screenheightarray;	mceilingclip = negonearray;//// add all active psprites//	for (i=0, psp=viewplayer->psprites ; i<NUMPSPRITES ; i++,psp++)		if (psp->state)			R_DrawPSprite (psp);}/*========================== R_SortVisSprites=========================*/vissprite_t	vsprsortedhead;void R_SortVisSprites (void){	int			i, count;	vissprite_t	*ds, *best;	vissprite_t	unsorted;	fixed_t		bestscale;	count = vissprite_p - vissprites;	unsorted.next = unsorted.prev = &unsorted;	if (!count)		return;	for (ds=vissprites ; ds<vissprite_p ; ds++)	{		ds->next = ds+1;		ds->prev = ds-1;	}	vissprites[0].prev = &unsorted;	unsorted.next = &vissprites[0];	(vissprite_p-1)->next = &unsorted;	unsorted.prev = vissprite_p-1;//// pull the vissprites out by scale//	best = 0;		// shut up the compiler warning	vsprsortedhead.next = vsprsortedhead.prev = &vsprsortedhead;	for (i=0 ; i<count ; i++)	{		bestscale = MAXINT;		for (ds=unsorted.next ; ds!= &unsorted ; ds=ds->next)		{			if (ds->scale < bestscale)			{				bestscale = ds->scale;				best = ds;			}		}		best->next->prev = best->prev;		best->prev->next = best->next;		best->next = &vsprsortedhead;		best->prev = vsprsortedhead.prev;		vsprsortedhead.prev->next = best;		vsprsortedhead.prev = best;	}}/*========================== R_DrawSprite=========================*/void R_DrawSprite (vissprite_t *spr){	drawseg_t		*ds;	short			clipbot[SCREENWIDTH], cliptop[SCREENWIDTH];	int				x, r1, r2;	fixed_t			scale, 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) )			continue;			// doesn't cover sprite		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) ) )		{			if (ds->maskedtexturecol)	// masked mid texture				R_RenderMaskedSegRange (ds, r1, r2);			continue;			// seg is behind sprite		}//// 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)		{	// 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);	}//// 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//// Added for the sideviewing with an external device	if (viewangleoffset <= 1024<<ANGLETOFINESHIFT || viewangleoffset >=
			-1024<<ANGLETOFINESHIFT)
  	{	// don't draw on side views
		R_DrawPlayerSprites ();
	}
//	if (!viewangleoffset)		// don't draw on side views//		R_DrawPlayerSprites ();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -