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

📄 bstub.c

📁 小型游戏引擎
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman * Ken Silverman's official web site: "http://www.advsys.net/ken" * See the included license file "BUILDLIC.TXT" for license info. * This file has been modified from Ken Silverman's original release */#include <fcntl.h>#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <memory.h>#include <stdlib.h>#include "engine.h"#include "platform.h"#include "build.h"#include "pragmas.h"#include "names.h"#include "bstub.h"#include "cache1d.h"  /* rcg05232001 need groupfile support. */#include "display.h"  /* rcg05232001 need some "vesa" routines. *//* !!! temporary externs. */extern long total_rendered_frames, total_render_time;extern char keystatus[256];static char tempbuf[256];extern long qsetmode;extern short searchsector, searchwall, searchstat;extern long zmode, kensplayerheight;extern short defaultspritecstat;extern short temppicnum, tempcstat, templotag, temphitag, tempextra;extern char tempshade, temppal, tempxrepeat, tempyrepeat;extern char somethingintab;#define NUMOPTIONS 8#define NUMKEYS 19static long vesares[13][2] = {	{320,200},{360,200},{320,240},{360,240},{320,400},	{360,400},{640,350},{640,400},{640,480},{800,600},	{1024,768},{1280,1024},{1600,1200}};static char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0};static char keys[NUMKEYS] ={	0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39,	0x1e,0x2c,0xd1,0xc9,0x33,0x34,	0x9c,0x1c,0xd,0xc,0xf,};extern char buildkeys[NUMKEYS];extern long frameplace, xdimenscale, ydimen;extern long posx, posy, posz, horiz;extern short ang, cursectnum;static long hang = 0;extern long stretchhline(long,long,long,long,long,long);#ifdef PLATFORM_DOS#pragma aux stretchhline parm [eax][ebx][ecx][edx][esi][edi];#endif#ifdef PLATFORM_DOSextern void printext16(long xpos, long ypos, short col, short backcol,			char name[82], char fontsize);#define statusbar_printext16 printext16#define statusbar_printext16_noupdate printext16#elseextern void statusbar_printext16(long xpos, long ypos, short col, short backcol, char name[82], char fontsize);#endif/* * Detecting 2D / 3D mode: *    qsetmode is 200 in 3D mode *    qsetmode is 350/480 in 2D mode *  * You can read these variables when F5-F8 is pressed in 3D mode only: *  *    If (searchstat == 0)  WALL        searchsector=sector, searchwall=wall *    If (searchstat == 1)  CEILING     searchsector=sector *    If (searchstat == 2)  FLOOR       searchsector=sector *    If (searchstat == 3)  SPRITE      searchsector=sector, searchwall=sprite *    If (searchstat == 4)  MASKED WALL searchsector=sector, searchwall=wall *  *    searchsector is the sector of the selected item for all 5 searchstat's *  *    searchwall is undefined if searchstat is 1 or 2 *    searchwall is the wall if searchstat = 0 or 4 *    searchwall is the sprite if searchstat = 3 (Yeah, I know - it says wall, *                                       but trust me, it's the sprite number) */long ofinetotalclock, ototalclock, averagefps;#define AVERAGEFRAMES 32static long frameval[AVERAGEFRAMES], framecnt = 0;#ifdef PLATFORM_DOSvoid inittimer42(void);#pragma aux inittimer42 =\	"in al, 0x61",\	"or al, 1",\	"out 0x61, al",\	"mov al, 0xb4",\	"out 0x43, al",\	"xor al, al",\	"out 0x42, al",\	"out 0x42, al",\	modify exact [eax]\void uninittimer42(void);#pragma aux uninittimer42 =\	"in al, 0x61",\	"and al, 252",\	"out 0x61, al",\	modify exact [eax]\long gettimer42(void);#pragma aux gettimer42 =\	"mov al, 0x84",\	"out 0x43, al",\	"in al, 0x42",\	"shl eax, 24",\	"in al, 0x42",\	"rol eax, 8",\	modify [eax]#else  void inittimer42(void) {}  void uninittimer42(void) {}  int gettimer42(void) { return(0); }#endif/* rcg05232001 These are defined in build.c ... */void editinput(void);void clearmidstatbar16(void);short getnumber16(char namestart[80], short num, long maxnumber);void printmessage16(char name[82]);/* rcg05232001 much thanks to TerminX (Mapster) for the lookup.dat info! */static int use_palette_lookup_file(const char *lookup_file){    int retval = 0;    unsigned char *tempbuf = NULL;    unsigned char *ptr = NULL;    unsigned char num_palettes = 0;    int i = 0;    int bytes = 0;    long in = kopen4load(lookup_file, 0);    if (in != -1)    {        if (kread(in, &num_palettes, 1) == 1)        {            bytes = ( ((int) num_palettes) * 257 );            tempbuf = (unsigned char *) malloc((size_t) bytes);            if (tempbuf != NULL)            {                if (kread(in, tempbuf, bytes) == bytes)                {                    for (i = 0, ptr = tempbuf; i < num_palettes; i++)                    {                        makepalookup(*ptr, (char *) ptr + 1, 0, 0, 0, 1);                        ptr += 257;                    } /* for */                    retval = 1;  /* success. */                } /* if */                free(tempbuf);            } /* if */        } /* if */        kclose(in);    } /* if */    return(retval);} /* use_lookup_dat */void ExtInit(void){	long i, fil;    const char *grpname = getenv("BUILD_GROUPFILE");	/*    printf("------------------------------------------------------------------------------\n");	printf("   BUILD.EXE copyright(c) 1996 by Ken Silverman.  You are granted the\n");	printf("   right to use this software for your personal use only.  This is a\n");	printf("   special version to be used with \"Happy Fun KenBuild\" and may not work\n");	printf("   properly with other Build engine games.  Please refer to license.doc\n");	printf("   for distribution rights\n");	printf("------------------------------------------------------------------------------\n");	getch();	*/        /* Now we check for an envr variable first, for Duke/SW/etc groups. */    if (grpname == NULL)        grpname = "stuff.dat";        /* rcg08122000 panic if groupfile is missing. */	if (initgroupfile(grpname) < 0)    {        fprintf(stderr, "BUILDGRP: Cannot open \"%s\"! Aborting...\n", grpname);        exit(55);    } /* if */	if ((fil = open("setup.dat",O_BINARY|O_RDWR,S_IREAD)) != -1)	{		read(fil,&option[0],NUMOPTIONS);		read(fil,&keys[0],NUMKEYS);		memcpy((void *)buildkeys,(void *)keys,NUMKEYS);   /* Trick to make build use setup.dat keys */		close(fil);	}	if (option[4] > 0) option[4] = 0;	initmouse();	initengine();	vidoption = option[0]; xdim = vesares[option[6]&15][0]; ydim = vesares[option[6]&15][1];		/*         * You can load your own palette lookup tables here if you just		 * copy the right code! (sez Ken).         *         * We try to use a Duke3D lookup.dat first. If that fails, then         *  we revert to KenBuild's original method.  (sez Ryan).         */    if (!use_palette_lookup_file("lookup.dat"))    {    	for(i=0;i<256;i++)    		tempbuf[i] = ((i+32)&255);  /* remap colors for screwy palette sectors */    	makepalookup(16,tempbuf,0,0,0,1);    } /* if */	kensplayerheight = 32;	zmode = 0;	defaultspritecstat = 0;	pskyoff[0] = 0; pskyoff[1] = 0; pskybits = 1;}void ExtUnInit(void){	uninittimer42();	uninitgroupfile();}static long daviewingrange, daaspect, horizval1, horizval2;void ExtPreCheckKeys(void){	long cosang, sinang, dx, dy, mindx, i;	if (keystatus[0x3e])  /* F4 - screen re-size */	{		keystatus[0x3e] = 0;			/* cycle through all vesa modes, then screen-buffer mode */		getvalidvesamodes();		if (vidoption == 1)		{			for(i=0;i<validmodecnt;i++)				if ((validmodexdim[i] == xdim) && (validmodeydim[i] == ydim))				{					if (i == validmodecnt-1)						setgamemode(2,320L,200L);					else						setgamemode(1,validmodexdim[i+1],validmodeydim[i+1]);					break;				}		}		else if (validmodecnt > 0)			setgamemode(1,validmodexdim[0],validmodeydim[0]);		inittimer42();  /* Must init here because VESA 0x4F02 messes timer 2 */	}	if (keystatus[0x2a]|keystatus[0x36])	{		if (keystatus[0xcf]) hang = max(hang-1,-182);		if (keystatus[0xc7]) hang = min(hang+1,182);	}	else	{		if (keystatus[0xcf]) hang = max(hang-8,-182);		if (keystatus[0xc7]) hang = min(hang+8,182);	}	if (keystatus[0x4c]) { hang = 0; horiz = 100; }	if (hang != 0)	{		walock[4094] = 255;		if (waloff[4094] == 0) allocache(&waloff[4094],240L*384L,(unsigned char *) &walock[4094]);		setviewtotile(4094,240L,384L);		cosang = sintable[(hang+512)&2047];		sinang = sintable[hang&2047];		dx = dmulscale1(320,cosang,200,sinang); mindx = dx;		dy = dmulscale1(-200,cosang,320,sinang);		horizval1 = dy*(320>>1)/dx-1;		dx = dmulscale1(320,cosang,-200,sinang); mindx = min(dx,mindx);		dy = dmulscale1(200,cosang,320,sinang);		horizval2 = dy*(320>>1)/dx+1;		daviewingrange = scale(65536,16384*(xdim>>1),mindx-16);		daaspect = scale(daviewingrange,scale(320,tilesizx[4094],tilesizy[4094]),horizval2+6-horizval1);		setaspect(daviewingrange,scale(daaspect,ydim*320,xdim*200));		horiz = 100-divscale15(horizval1+horizval2,daviewingrange);	}}#define MAXVOXMIPS 5extern char *voxoff[][MAXVOXMIPS];void ExtAnalyzeSprites(void){	long i, *longptr;	spritetype *tspr;	for(i=0,tspr=&tsprite[0];i<spritesortcnt;i++,tspr++)	{		switch(tspr->picnum)		{			case PLAYER:				if (!voxoff[0][0]) qloadkvx(0L,"voxel000.kvx");				tspr->cstat |= 48;

⌨️ 快捷键说明

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