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

📄 hw_main.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 5 页
字号:
seg_t*      gr_curline;side_t*     gr_sidedef;line_t*     gr_linedef;sector_t*   gr_frontsector;sector_t*   gr_backsector;//FRGBAFloat  gr_cursectorlight;      // colour & intensity of current sector's lighting// --------------------------------------------------------------------------//                                              STUFF FOR THE PROJECTION CODE// --------------------------------------------------------------------------#ifdef TANDLFTransform      transform;#endif// duplicates of the main code, set after R_SetupFrame() passed them into sharedstruct,// copied here for local usestatic  fixed_t dup_viewx;static  fixed_t dup_viewy;static  fixed_t dup_viewz;static  angle_t dup_viewangle;static  float   gr_viewx;static  float   gr_viewy;float   gr_viewz;static  float   gr_viewsin;static  float   gr_viewcos;//04/01/00: Maybe not necessary with the new T&L code (need to be checked!)static float   gr_viewludsin;  //look up down kik teststatic float   gr_viewludcos;// ==========================================================================//                                    LIGHT stuffs// ==========================================================================static byte lightleveltonumlut[256];// added to Doom's sector lightlevel to make things a bit brighter (sprites/walls/planes)byte LightLevelToLum(int l){    if( fixedcolormap )        return 255;    l = lightleveltonumlut[l];    l += (extralight<<4 );    if(l>255)        l= 255;    return l;}static void InitLumLut(){    int i,k;    for( i=0; i<256; i++ )    {        // this polygone is the solution of equ : f(0)=0, f(1)=1 f(.5)=.5, f'(0)=0, f'(1)=0), f'(.5)=K#define K   2#define A  (-24+16*K)#define B  ( 60-40*K)#define C  (32*K-50)#define D  (-8*K+15)        float x=(float)i/255;        float xx,xxx;        xx = x*x;        xxx = x*xx;        k = 255*(A*xx*xxx + B*xx*xx + C*xxx + D*xx);        lightleveltonumlut[i] = min(255,k);    }}// ==========================================================================//                                   FLOOR/CEILING GENERATION FROM SUBSECTORS// ==========================================================================#ifdef  DOPLANES//what is the maximum number of verts around a convex floor/ceiling polygon? FIXME: gothic2 map02 has a 304 vertex poly!!!!#define MAXPLANEVERTICES 256static  FOutVector  planeVerts[MAXPLANEVERTICES];//Hurdler: added for correct dynamic ligting with mlookstatic  FVector     plVerts[MAXPLANEVERTICES];// -----------------+// HWR_RenderPlane  : Render a floor or ceiling convex polygon// -----------------+void HWR_RenderPlane( extrasubsector_t *xsub,                      fixed_t           fixedheight,                      FBITFIELD         PolyFlags ){    polyvertex_t*   pv;    float           height; //constant y for all points on the convex flat polygon    FOutVector      *v3d;    int             nrPlaneVerts;   //verts original define of convex flat polygon    int             i;#ifndef TANDL    float           tr_x,tr_y,tr_z;#endif    float           flatxref,flatyref;    FSurfaceInfo    Surf;    // no convex poly were generated for this subsector    if (!xsub->planepoly)        return;    height = ((float)fixedheight) * crapmul;    pv  = xsub->planepoly->pts;    nrPlaneVerts = xsub->planepoly->numpts;    if (nrPlaneVerts < 3)   //not even a triangle ?        return;    if(nrPlaneVerts > MAXPLANEVERTICES) // FIXME: exceeds plVerts size    {        CONS_Printf("polygon size of %d exceeds max value of %d vertices\n", nrPlaneVerts, MAXPLANEVERTICES);        return;    }    //reference point for flat texture coord for each vertex around the polygon    flatxref = ((fixed_t)pv->x & (~63)) / 64.0f;    flatyref = ((fixed_t)pv->y & (~63)) / 64.0f;    // transform    v3d = planeVerts;#ifndef TANDL    for (i=0; i<nrPlaneVerts; i++,v3d++,pv++)    {        // translation        tr_x     = pv->x - gr_viewx;        v3d->sow = (pv->x / 64.0f) - flatxref;        tr_y     = pv->y - gr_viewy;    //distance close/away        v3d->tow = flatyref - (pv->y / 64.0f );        tr_z   = height - gr_viewz;        // rotation around vertical y axis        v3d->x = (tr_x * gr_viewsin) - (tr_y * gr_viewcos );        tr_x   = (tr_x * gr_viewcos) + (tr_y * gr_viewsin );        //Hurdler: added for correct dynamic ligting with mlook        plVerts[i].x = v3d->x;        plVerts[i].y = tr_z;        plVerts[i].z = tr_x;        // look up/down ----TOTAL SUCKS!!!--- do the 2 rotation in one!!!!!!!!!!!!!!!!!!!!!        tr_y     = (tr_x * gr_viewludcos) + (tr_z * gr_viewludsin );        v3d->oow = (tr_x * gr_viewludsin) - (tr_z * gr_viewludcos );        //scale to enter the frustum clipping, so that 90deg frustum fit to screen height        v3d->y = tr_y  * ORIGINAL_ASPECT;    }#else    for (i=0; i<nrPlaneVerts; i++,v3d++,pv++)    {        v3d->sow = (pv->x / 64.0f) - flatxref;        v3d->tow = flatyref - (pv->y / 64.0f );        v3d->x = pv->x;        v3d->y = height;        v3d->oow = pv->y;        plVerts[i].x = v3d->x;        plVerts[i].y = v3d->y;        plVerts[i].z = v3d->oow;    }#endif    // only useful for flat coloured triangles    //Surf.FlatColor = 0xff804020;    //  use different light tables    //  for horizontal / vertical / diagonal    //  note: try to get the same visual feel as the original    Surf.FlatColor.s.alpha = 0xff;    Surf.FlatColor.s.red = Surf.FlatColor.s.green =          Surf.FlatColor.s.blue = LightLevelToLum(gr_frontsector->lightlevel);    HWD.pfnDrawPolygon( &Surf, planeVerts, nrPlaneVerts, PolyFlags|PF_Masked|PF_Modulated|PF_Clip );    //12/11/99: Hurdler: add here code for dynamic lighting on planes#ifndef TANDL    HWR_PlaneLighting(planeVerts, nrPlaneVerts, plVerts);#endif    //experimental code: shadow of the player: should be done only on floor    //HWR_DynamicShadowing(planeVerts, nrPlaneVerts, plVerts, plyr);}#ifdef POLYSKY// this don't draw anything it only update the z-buffer so there isn't problem with// wall/things upper that sky (map12)static void HWR_RenderSkyPlane (extrasubsector_t *xsub, fixed_t fixedheight)//                              FBITFIELD         PolyFlags ){    polyvertex_t*   pv;    float           height; //constant y for all points on the convex flat polygon    FOutVector      *v3d;    int             nrPlaneVerts;   //verts original define of convex flat polygon    int             i;#ifndef TANDL    float           tr_x,tr_y,tr_z;#endif    float           flatxref,flatyref;    // no convex poly were generated for this subsector    if (!xsub->planepoly)        return;    height = ((float)fixedheight) * crapmul;    pv  = xsub->planepoly->pts;    nrPlaneVerts = xsub->planepoly->numpts;    if (nrPlaneVerts < 3)   //not even a triangle ?        return;    //HWR_GetTexture (skytexture);    //reference point for flat texture coord for each vertex around the polygon    flatxref = ((fixed_t)pv->x & (~63)) / 64.0f;    flatyref = ((fixed_t)pv->y & (~63)) / 64.0f;    // transform    v3d = planeVerts;#ifndef TANDL    for (i=0; i<nrPlaneVerts; i++,v3d++,pv++)    {        // translation        tr_x     = pv->x - gr_viewx;        v3d->sow = (pv->x / 64.0f) - flatxref;        tr_y     = pv->y - gr_viewy;    //distance close/away        v3d->tow = flatyref - (pv->y / 64.0f );        tr_z   = height - gr_viewz;        // rotation around vertical y axis        v3d->x = (tr_x * gr_viewsin) - (tr_y * gr_viewcos );        tr_x   = (tr_x * gr_viewcos) + (tr_y * gr_viewsin );        // look up/down ----TOTAL SUCKS!!!--- do the 2 rotation in one!!!!!!!!!!!!!!!!!!!!!        tr_y     = (tr_x * gr_viewludcos) + (tr_z * gr_viewludsin );        v3d->oow = (tr_x * gr_viewludsin) - (tr_z * gr_viewludcos );        //scale to enter the frustum clipping, so that 90deg frustum fit to screen height        v3d->y = tr_y  * ORIGINAL_ASPECT;//        v3d->sow = -1; //gr_windowcenterx + v3d->x*gr_centerx/v3d->oow;//        v3d->tow =  1; //gr_windowcentery + v3d->y*gr_centery/v3d->oow;    }#else    for (i=0; i<nrPlaneVerts; i++,v3d++,pv++)    {        v3d->sow = must be transformed and projected !;        v3d->tow = must be transformed and projected !;        v3d->x = pv->x;        v3d->y = height;        v3d->oow = pv->y;        plVerts[i].x = v3d->x;        plVerts[i].y = v3d->y;        plVerts[i].z = v3d->oow;    }#endif    HWD.pfnDrawPolygon( NULL, planeVerts, nrPlaneVerts, PF_Invisible|PF_Occlude|PF_Masked|PF_Clip );}#endif //polysky#endif //doplanes/*   wallVerts order is :          3--2          | /|          |/ |          0--1*/#ifdef WALLSPLATSvoid HWR_DrawSegsSplats( FSurfaceInfo * pSurf ){    FOutVector    trVerts[4],*wv;    wallVert3D    wallVerts[4];    wallVert3D    *pwallVerts;    wallsplat_t*  splat;#ifndef TANDL    float         tr_x,tr_y;#endif    GlidePatch_t* gpatch;    int           i;    FSurfaceInfo  pSurf2;    // seg bbox    fixed_t       segbbox[4];    M_ClearBox(segbbox);    M_AddToBox(segbbox,((polyvertex_t *)gr_curline->v1)->x/crapmul,((polyvertex_t *)gr_curline->v1)->y/crapmul);    M_AddToBox(segbbox,((polyvertex_t *)gr_curline->v2)->x/crapmul,((polyvertex_t *)gr_curline->v2)->y/crapmul);    // splat are drawn by line but this func is called for eatch segs of a line    /* BP: DONT WORK BECAUSE Z-buffer !!!!           FIXME : the splat must be stored by segs !    if( gr_curline->linedef->splatdrawn == validcount )        return;    gr_curline->linedef->splatdrawn = validcount;    */    splat = (wallsplat_t*) gr_curline->linedef->splats;    for ( ; splat ; splat=splat->next)    {        //BP: don't draw splat extern to this seg        //    this is quick fix best is explain in logboris.txt at 12-4-2000        if( !M_PointInBox(segbbox,splat->v1.x,splat->v1.y) && !M_PointInBox(segbbox,splat->v2.x,splat->v2.y))            continue;        gpatch = W_CachePatchNum (splat->patch, PU_CACHE);        HWR_GetPatch(gpatch);        wallVerts[0].x = wallVerts[3].x = splat->v1.x*crapmul;        wallVerts[0].z = wallVerts[3].z = splat->v1.y*crapmul;        wallVerts[2].x = wallVerts[1].x = splat->v2.x*crapmul;        wallVerts[2].z = wallVerts[1].z = splat->v2.y*crapmul;        i = splat->top;        if( splat->yoffset )            i += *splat->yoffset;        wallVerts[2].y = wallVerts[3].y = i*crapmul+(gpatch->height>>1);        wallVerts[0].y = wallVerts[1].y = i*crapmul-(gpatch->height>>1);        wallVerts[3].s = wallVerts[3].t = wallVerts[2].s = wallVerts[0].t = 0.0f;        wallVerts[1].s = wallVerts[1].t = wallVerts[2].t = wallVerts[0].s = 1.0f;        // transform        wv = trVerts;        pwallVerts = wallVerts;#ifndef TANDL        for (i=0; i<4; i++,wv++,pwallVerts++)        {            // translation            tr_x = pwallVerts->x - gr_viewx;            tr_y = pwallVerts->z - gr_viewy;            wv->y = pwallVerts->y - gr_viewz;            // rotation around vertical y axis            wv->oow = (tr_x * gr_viewcos) + (tr_y * gr_viewsin );            wv->x   = (tr_x * gr_viewsin) - (tr_y * gr_viewcos );            //look up/down ----TOTAL SUCKS!!!--- do the 2 in one!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!            tr_y = wv->y;            tr_x = wv->oow;            wv->y   = (tr_x * gr_viewludcos) + (tr_y * gr_viewludsin );            wv->oow = (tr_x * gr_viewludsin) - (tr_y * gr_viewludcos );            //scale y before frustum so that frustum can be scaled to screen height            wv->y = wv->y * ORIGINAL_ASPECT;            wv->sow = pwallVerts->s;            wv->tow = pwallVerts->t;        }#else        for (i=0; i<4; i++,wv++,pwallVerts++)        {            wv->x   = pwallVerts->x;            wv->oow = pwallVerts->z;            wv->y   = pwallVerts->y;            wv->sow = pwallVerts->s;            wv->tow = pwallVerts->t;        }#endif        memcpy(&pSurf2,pSurf,sizeof(FSurfaceInfo));        switch (splat->flags & SPLATDRAWMODE_MASK) {            case SPLATDRAWMODE_OPAQUE :                pSurf2.FlatColor.s.alpha = 0xff;                i = PF_Translucent;                break;            case SPLATDRAWMODE_TRANS :                pSurf2.FlatColor.s.alpha = 128;                i = PF_Translucent;                break;            case SPLATDRAWMODE_SHADE :                pSurf2.FlatColor.s.alpha = 0xff;                i = PF_Substractive;                break;        }        HWD.pfnDrawPolygon( &pSurf2, trVerts, 4, i|PF_Modulated|PF_Clip|PF_Decal);    }}#endif// ==========================================================================//                                        WALL GENERATION FROM SUBSECTOR SEGS// ==========================================================================void transform(float *cx, float *cy, float *cz){#ifndef TANDL    float tr_x,tr_y;    // translation    tr_x = *cx - gr_viewx;

⌨️ 快捷键说明

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