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

📄 engine.c

📁 小型游戏引擎
💻 C
📖 第 1 页 / 共 5 页
字号:
#if (defined USE_I386_ASM)  #if (defined __WATCOMC__)	/* 0x007ff000 is (11<<13), 0x3f800000 is (127<<23) */    long krecipasm(long param);    #pragma aux krecipasm =\	"mov fpuasm, eax",\	"fild dword ptr fpuasm",\	"add eax, eax",\	"fstp dword ptr fpuasm",\	"sbb ebx, ebx",\	"mov eax, fpuasm",\	"mov ecx, eax",\	"and eax, 0x007ff000",\	"shr eax, 10",\	"sub ecx, 0x3f800000",\	"shr ecx, 23",\	"mov eax, dword ptr reciptable[eax]",\	"sar eax, cl",\	"xor eax, ebx",\	parm [eax]\	modify exact [eax ebx ecx]\  #elif (defined __GNUC__)        static long krecipasm(long i1)        {            long retval;            __asm__ __volatile__ (                "\n\t"                "call _asm_krecipasm\n\t"            : "=a" (retval) : "a" (i1)        	: "cc", "ebx", "ecx", "memory");            return(retval);        } /* krecipasm */        #else        #error Please write Assembly for your platform!  #endif#else  /* USE_I386_ASM */        static long krecipasm(long x)        {            float xf;            int z;            int not;                if (x & 0x80000000) /* If the highest bit is set... */                not = 0x0FFFFFFFF;            else                not = 0;              xf = (float)x;/* convert the int to a float */                /* Pretend the float is an int so we can extract bits */            x = *((int*)(&xf));            z = x;                  x = x & 0x007FF000;/* Mask out: 11 << 13 */            x = x >> 10;       /* Divide x by 1024 */                /* X now contains: 13 high order bits of the mantissa,               followed by two 0 bits */                /* Now we perform an elaborate extraction               of the exponent from the floating point               number? WTF is the subtraction for? */            z = z - 0x03F800000;/* Subtract (127<<23) */            z = z >> 23;                /* z now contains the exponent divided by two?  */            x = shift_algebraic_right(reciptable[(x>>2)], z) ^ not;            return x;        }    #endif /* defined USE_I386_ASM */#if (defined USE_I386_ASM)  #if (defined __WATCOMC__)        int setgotpic(long param);    #pragma aux setgotpic =\	"mov ebx, eax",\	"cmp byte ptr walock[eax], 200",\	"jae skipit",\	"mov byte ptr walock[eax], 199",\	"skipit: shr eax, 3",\	"and ebx, 7",\	"mov dl, byte ptr gotpic[eax]",\	"mov bl, byte ptr pow2char[ebx]",\	"or dl, bl",\	"mov byte ptr gotpic[eax], dl",\	parm [eax]\	modify exact [eax ebx ecx edx]\  #elif (defined __GNUC__)        int setgotpic(long i1)        {            int retval = 0;            __asm__ __volatile__ (                "\n\t"                "movl %%eax, %%ebx\n\t"            	"cmpb $200, " SYM_walock "(%%eax)\n\t"            	"jae setgotpic_skipit\n\t"            	"movb $199, " SYM_walock "(%%eax)\n\t"            	"setgotpic_skipit: shrl $3, %%eax\n\t"            	"andl $7, %%ebx\n\t"            	"movb " SYM_gotpic "(%%eax), %%dl\n\t"            	"movb " SYM_pow2char "(%%ebx), %%bl\n\t"            	"orb %%bl, %%dl\n\t"            	"movb %%dl, (" SYM_gotpic ")(%%eax)\n\t"            : "=a" (retval) : "a" (i1) : "ebx", "ecx", "edx", "cc", "memory");            return(retval);        } /* setgotpic */    #else        #error Please write Assembly for your platform!    #endif#else   /* !defined USE_I386_ASM */    #error Implement me in C!#endif /* defined USE_I386_ASM */#if (defined USE_I386_ASM)  #if (defined __WATCOMC__)        long getclipmask(int i1, int i2, int i3, int i4);    #pragma aux getclipmask =\	"sar eax, 31",\	"add ebx, ebx",\	"adc eax, eax",\	"add ecx, ecx",\	"adc eax, eax",\	"add edx, edx",\	"adc eax, eax",\	"mov ebx, eax",\	"shl ebx, 4",\	"or al, 0xf0",\	"xor eax, ebx",\	parm [eax][ebx][ecx][edx]\	modify exact [eax ebx ecx edx]\  #elif (defined __GNUC__)        long getclipmask(int i1, int i2, int i3, int i4)        {            int retval;            __asm__ __volatile__ (        		"\n\t"                "sarl $31, %%eax\n\t"        		"addl %%ebx, %%ebx\n\t"        		"adcl %%eax, %%eax\n\t"        		"addl %%ecx, %%ecx\n\t"        		"adcl %%eax, %%eax\n\t"        		"addl %%edx, %%edx\n\t"        		"adcl %%eax, %%eax\n\t"        		"movl %%eax, %%ebx\n\t"        		"shll $4, %%ebx\n\t"        		"orb $0xf0, %%al\n\t"        		"xorl %%ebx, %%eax\n\t"        	: "=a" (retval) : "a" (i1), "b" (i2), "c" (i3), "d" (i4)        	: "cc", "memory");            return(retval);        } /* getclipmask */    #else        #error Please write Assembly for your platform!    #endif#else  /* !defined USE_I386_ASM */    #error Implement me in C!#endif /* defined USE_I386_ASM */static void scansector (short sectnum){	walltype *wal, *wal2;	spritetype *spr;	long xs, ys, x1, y1, x2, y2, xp1, yp1, xp2=0, yp2=0, templong;	short z, zz, startwall, endwall, numscansbefore, scanfirst, bunchfrst;	short nextsectnum;	if (sectnum < 0) return;	if (automapping) show2dsector[sectnum>>3] |= pow2char[sectnum&7];	sectorborder[0] = sectnum, sectorbordercnt = 1;	do	{		sectnum = sectorborder[--sectorbordercnt];		for(z=headspritesect[sectnum];z>=0;z=nextspritesect[z])		{			spr = &sprite[z];			if ((((spr->cstat&0x8000) == 0) || (showinvisibility)) &&				  (spr->xrepeat > 0) && (spr->yrepeat > 0) &&				  (spritesortcnt < MAXSPRITESONSCREEN))			{				xs = spr->x-globalposx; ys = spr->y-globalposy;				if ((spr->cstat&48) || (xs*cosglobalang+ys*singlobalang > 0))				{					copybufbyte(spr,&tsprite[spritesortcnt],sizeof(spritetype));					tsprite[spritesortcnt++].owner = z;				}			}		}		gotsector[sectnum>>3] |= pow2char[sectnum&7];		bunchfrst = numbunches;		numscansbefore = numscans;		startwall = sector[sectnum].wallptr;		endwall = startwall + sector[sectnum].wallnum;		scanfirst = numscans;		for(z=startwall,wal=&wall[z];z<endwall;z++,wal++)		{			nextsectnum = wal->nextsector;			wal2 = &wall[wal->point2];			x1 = wal->x-globalposx; y1 = wal->y-globalposy;			x2 = wal2->x-globalposx; y2 = wal2->y-globalposy;			if ((nextsectnum >= 0) && ((wal->cstat&32) == 0))				if ((gotsector[nextsectnum>>3]&pow2char[nextsectnum&7]) == 0)				{					templong = x1*y2-x2*y1;					if (((unsigned)templong+262144) < 524288)						if (mulscale5(templong,templong) <= (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))							sectorborder[sectorbordercnt++] = nextsectnum;				}			if ((z == startwall) || (wall[z-1].point2 != z))			{				xp1 = dmulscale6(y1,cosglobalang,-x1,singlobalang);				yp1 = dmulscale6(x1,cosviewingrangeglobalang,y1,sinviewingrangeglobalang);			}			else			{				xp1 = xp2;				yp1 = yp2;			}			xp2 = dmulscale6(y2,cosglobalang,-x2,singlobalang);			yp2 = dmulscale6(x2,cosviewingrangeglobalang,y2,sinviewingrangeglobalang);			if ((yp1 < 256) && (yp2 < 256)) goto skipitaddwall;				/* If wall's NOT facing you */			if (dmulscale32(xp1,yp2,-xp2,yp1) >= 0) goto skipitaddwall;			if (xp1 >= -yp1)			{				if ((xp1 > yp1) || (yp1 == 0)) goto skipitaddwall;				xb1[numscans] = halfxdimen + scale(xp1,halfxdimen,yp1);				if (xp1 >= 0) xb1[numscans]++;   /* Fix for SIGNED divide */				if (xb1[numscans] >= xdimen) xb1[numscans] = xdimen-1;				yb1[numscans] = yp1;			}			else			{				if (xp2 < -yp2) goto skipitaddwall;				xb1[numscans] = 0;				templong = yp1-yp2+xp1-xp2;				if (templong == 0) goto skipitaddwall;				yb1[numscans] = yp1 + scale(yp2-yp1,xp1+yp1,templong);			}			if (yb1[numscans] < 256) goto skipitaddwall;			if (xp2 <= yp2)			{				if ((xp2 < -yp2) || (yp2 == 0)) goto skipitaddwall;				xb2[numscans] = halfxdimen + scale(xp2,halfxdimen,yp2) - 1;				if (xp2 >= 0) xb2[numscans]++;   /* Fix for SIGNED divide */				if (xb2[numscans] >= xdimen) xb2[numscans] = xdimen-1;				yb2[numscans] = yp2;			}			else			{				if (xp1 > yp1) goto skipitaddwall;				xb2[numscans] = xdimen-1;				templong = xp2-xp1+yp1-yp2;				if (templong == 0) goto skipitaddwall;				yb2[numscans] = yp1 + scale(yp2-yp1,yp1-xp1,templong);			}			if ((yb2[numscans] < 256) || (xb1[numscans] > xb2[numscans])) goto skipitaddwall;				/* Made it all the way! */			thesector[numscans] = sectnum; thewall[numscans] = z;			rx1[numscans] = xp1; ry1[numscans] = yp1;			rx2[numscans] = xp2; ry2[numscans] = yp2;			p2[numscans] = numscans+1;			numscans++;skipitaddwall:			if ((wall[z].point2 < z) && (scanfirst < numscans))				p2[numscans-1] = scanfirst, scanfirst = numscans;		}		for(z=numscansbefore;z<numscans;z++)			if ((wall[thewall[z]].point2 != thewall[p2[z]]) || (xb2[z] >= xb1[p2[z]]))				bunchfirst[numbunches++] = p2[z], p2[z] = -1;		for(z=bunchfrst;z<numbunches;z++)		{			for(zz=bunchfirst[z];p2[zz]>=0;zz=p2[zz]);			bunchlast[z] = zz;		}	} while (sectorbordercnt > 0);}static void prepwall(long z, walltype *wal){	long i, l=0, ol=0, splc, sinc, x, topinc, top, botinc, bot, walxrepeat;	walxrepeat = (wal->xrepeat<<3);		/* lwall calculation */	i = xb1[z]-halfxdimen;	topinc = -(ry1[z]>>2);	botinc = ((ry2[z]-ry1[z])>>8);	top = mulscale5(rx1[z],xdimen)+mulscale2(topinc,i);	bot = mulscale11(rx1[z]-rx2[z],xdimen)+mulscale2(botinc,i);	splc = mulscale19(ry1[z],xdimscale);	sinc = mulscale16(ry2[z]-ry1[z],xdimscale);	x = xb1[z];	if (bot != 0)	{		l = divscale12(top,bot);		swall[x] = mulscale21(l,sinc)+splc;		l *= walxrepeat;		lwall[x] = (l>>18);	}	while (x+4 <= xb2[z])	{		top += topinc; bot += botinc;		if (bot != 0)		{			ol = l; l = divscale12(top,bot);			swall[x+4] = mulscale21(l,sinc)+splc;			l *= walxrepeat;			lwall[x+4] = (l>>18);		}		i = ((ol+l)>>1);		lwall[x+2] = (i>>18);		lwall[x+1] = ((ol+i)>>19);		lwall[x+3] = ((l+i)>>19);		swall[x+2] = ((swall[x]+swall[x+4])>>1);		swall[x+1] = ((swall[x]+swall[x+2])>>1);		swall[x+3] = ((swall[x+4]+swall[x+2])>>1);		x += 4;	}	if (x+2 <= xb2[z])	{		top += (topinc>>1); bot += (botinc>>1);		if (bot != 0)		{			ol = l; l = divscale12(top,bot);			swall[x+2] = mulscale21(l,sinc)+splc;			l *= walxrepeat;			lwall[x+2] = (l>>18);		}		lwall[x+1] = ((l+ol)>>19);		swall[x+1] = ((swall[x]+swall[x+2])>>1);		x += 2;	}	if (x+1 <= xb2[z])	{		bot += (botinc>>2);		if (bot != 0)		{			l = divscale12(top+(topinc>>2),bot);			swall[x+1] = mulscale21(l,sinc)+splc;			lwall[x+1] = mulscale18(l,walxrepeat);		}	}	if (lwall[xb1[z]] < 0) lwall[xb1[z]] = 0;	if ((lwall[xb2[z]] >= walxrepeat) && (walxrepeat)) lwall[xb2[z]] = walxrepeat-1;	if (wal->cstat&8)	{		walxrepeat--;		for(x=xb1[z];x<=xb2[z];x++) lwall[x] = walxrepeat-lwall[x];	}}static int getpalookup(long davis, long dashade){	return(min(max(dashade+(davis>>8),0),numpalookups-1));}static void hline (long xr, long yp){	long xl, r, s;	xl = lastx[yp]; if (xl > xr) return;	r = horizlookup2[yp-globalhoriz+horizycent];	asm1 = globalx1*r;	asm2 = globaly2*r;	s = ((long)getpalookup((long)mulscale16(r,globvis),globalshade)<<8);	hlineasm4(xr-xl,0L,s,globalx2*r+globalypanning,globaly1*r+globalxpanning,		ylookup[yp]+xr+frameoffset);}static void slowhline (long xr, long yp){	long xl, r;	xl = lastx[yp]; if (xl > xr) return;	r = horizlookup2[yp-globalhoriz+horizycent];	asm1 = globalx1*r;	asm2 = globaly2*r;

⌨️ 快捷键说明

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