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

📄 v_video.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 3 页
字号:
// Emacs style mode select   -*- C++ -*- //-----------------------------------------------------------------------------//// $Id: v_video.c,v 1.26 2001/04/28 14:33:41 metzgermeister Exp $//// Copyright (C) 1993-1996 by id Software, Inc.// Portions Copyright (C) 1998-2000 by DooM Legacy Team.//// 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: v_video.c,v $// Revision 1.26  2001/04/28 14:33:41  metzgermeister// *** empty log message ***//// Revision 1.25  2001/04/17 22:30:40  hurdler// fix some (strange!) problems//// Revision 1.24  2001/04/09 20:20:46  metzgermeister// fixed crash bug//// Revision 1.23  2001/04/01 17:35:07  bpereira// no message//// Revision 1.22  2001/03/30 17:12:51  bpereira// no message//// Revision 1.21  2001/03/13 22:14:20  stroggonmeth// Long time no commit. 3D floors, FraggleScript, portals, ect.//// Revision 1.20  2001/02/28 17:50:55  bpereira// no message//// Revision 1.19  2001/02/24 13:35:21  bpereira// no message//// Revision 1.18  2001/02/19 17:40:34  hurdler// Fix a bug with "chat on" in hw mode//// Revision 1.17  2001/02/10 13:05:45  hurdler// no message//// Revision 1.16  2001/01/31 17:14:08  hurdler// Add cv_scalestatusbar in hardware mode//// Revision 1.15  2001/01/25 22:15:44  bpereira// added heretic support//// Revision 1.14  2000/11/06 20:52:16  bpereira// no message//// Revision 1.13  2000/11/04 16:23:44  bpereira// no message//// Revision 1.12  2000/11/02 19:49:37  bpereira// no message//// Revision 1.11  2000/10/04 16:19:24  hurdler// Change all those "3dfx names" to more appropriate names//// Revision 1.10  2000/08/31 14:30:56  bpereira// no message//// Revision 1.9  2000/04/27 17:43:19  hurdler// colormap code in hardware mode is now the default//// Revision 1.8  2000/04/24 20:24:38  bpereira// no message//// Revision 1.7  2000/04/24 15:10:57  hurdler// Support colormap for text//// Revision 1.6  2000/04/22 21:12:15  hurdler// I like it better like that//// Revision 1.5  2000/04/06 20:47:08  hurdler// add Boris' changes for coronas in doom3.wad//// Revision 1.4  2000/03/29 20:10:50  hurdler// your fix didn't work under windows, find another solution//// Revision 1.3  2000/03/12 23:16:41  linuxcub// Fixed definition of VID_BlitLinearScreen (Well, it now compiles under RH61)//// Revision 1.2  2000/02/27 00:42:11  hurdler// fix CR+LF problem//// Revision 1.1.1.1  2000/02/22 20:32:33  hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION://      Gamma correction LUT stuff.//      Functions to draw patches (by post) directly to screen.//      Functions to blit a block to the screen.////-----------------------------------------------------------------------------#include "doomdef.h"#include "r_local.h"#include "v_video.h"#include "hu_stuff.h"#include "r_draw.h"#include "console.h"#include "i_video.h"            //rendermode#include "z_zone.h"#ifdef HWRENDER#include "hardware/hw_glob.h"#endif// Each screen is [vid.width*vid.height];byte*      screens[5];CV_PossibleValue_t gamma_cons_t[]={{0,"MIN"},{4,"MAX"},{0,NULL}};void CV_usegamma_OnChange(void);consvar_t  cv_ticrate={"vid_ticrate","0",0,CV_OnOff,NULL};consvar_t  cv_usegamma = {"gamma","0",CV_SAVE|CV_CALL,gamma_cons_t,CV_usegamma_OnChange};// Now where did these came from?byte gammatable[5][256] ={    {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,     17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,     33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,     49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,     65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,     81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,     97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,     113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,     128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,     144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,     160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,     176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,     192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,     208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,     224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,     240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255},    {2,4,5,7,8,10,11,12,14,15,16,18,19,20,21,23,24,25,26,27,29,30,31,     32,33,34,36,37,38,39,40,41,42,44,45,46,47,48,49,50,51,52,54,55,     56,57,58,59,60,61,62,63,64,65,66,67,69,70,71,72,73,74,75,76,77,     78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,     99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,     115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,129,     130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,     146,147,148,148,149,150,151,152,153,154,155,156,157,158,159,160,     161,162,163,163,164,165,166,167,168,169,170,171,172,173,174,175,     175,176,177,178,179,180,181,182,183,184,185,186,186,187,188,189,     190,191,192,193,194,195,196,196,197,198,199,200,201,202,203,204,     205,205,206,207,208,209,210,211,212,213,214,214,215,216,217,218,     219,220,221,222,222,223,224,225,226,227,228,229,230,230,231,232,     233,234,235,236,237,237,238,239,240,241,242,243,244,245,245,246,     247,248,249,250,251,252,252,253,254,255},    {4,7,9,11,13,15,17,19,21,22,24,26,27,29,30,32,33,35,36,38,39,40,42,     43,45,46,47,48,50,51,52,54,55,56,57,59,60,61,62,63,65,66,67,68,69,     70,72,73,74,75,76,77,78,79,80,82,83,84,85,86,87,88,89,90,91,92,93,     94,95,96,97,98,100,101,102,103,104,105,106,107,108,109,110,111,112,     113,114,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,     129,130,131,132,133,133,134,135,136,137,138,139,140,141,142,143,144,     144,145,146,147,148,149,150,151,152,153,153,154,155,156,157,158,159,     160,160,161,162,163,164,165,166,166,167,168,169,170,171,172,172,173,     174,175,176,177,178,178,179,180,181,182,183,183,184,185,186,187,188,     188,189,190,191,192,193,193,194,195,196,197,197,198,199,200,201,201,     202,203,204,205,206,206,207,208,209,210,210,211,212,213,213,214,215,     216,217,217,218,219,220,221,221,222,223,224,224,225,226,227,228,228,     229,230,231,231,232,233,234,235,235,236,237,238,238,239,240,241,241,     242,243,244,244,245,246,247,247,248,249,250,251,251,252,253,254,254,     255},    {8,12,16,19,22,24,27,29,31,34,36,38,40,41,43,45,47,49,50,52,53,55,     57,58,60,61,63,64,65,67,68,70,71,72,74,75,76,77,79,80,81,82,84,85,     86,87,88,90,91,92,93,94,95,96,98,99,100,101,102,103,104,105,106,107,     108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,     125,126,127,128,129,130,131,132,133,134,135,135,136,137,138,139,140,     141,142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,     155,156,157,158,159,160,160,161,162,163,164,165,165,166,167,168,169,     169,170,171,172,173,173,174,175,176,176,177,178,179,180,180,181,182,     183,183,184,185,186,186,187,188,189,189,190,191,192,192,193,194,195,     195,196,197,197,198,199,200,200,201,202,202,203,204,205,205,206,207,     207,208,209,210,210,211,212,212,213,214,214,215,216,216,217,218,219,     219,220,221,221,222,223,223,224,225,225,226,227,227,228,229,229,230,     231,231,232,233,233,234,235,235,236,237,237,238,238,239,240,240,241,     242,242,243,244,244,245,246,246,247,247,248,249,249,250,251,251,252,     253,253,254,254,255},    {16,23,28,32,36,39,42,45,48,50,53,55,57,60,62,64,66,68,69,71,73,75,76,     78,80,81,83,84,86,87,89,90,92,93,94,96,97,98,100,101,102,103,105,106,     107,108,109,110,112,113,114,115,116,117,118,119,120,121,122,123,124,     125,126,128,128,129,130,131,132,133,134,135,136,137,138,139,140,141,     142,143,143,144,145,146,147,148,149,150,150,151,152,153,154,155,155,     156,157,158,159,159,160,161,162,163,163,164,165,166,166,167,168,169,     169,170,171,172,172,173,174,175,175,176,177,177,178,179,180,180,181,     182,182,183,184,184,185,186,187,187,188,189,189,190,191,191,192,193,     193,194,195,195,196,196,197,198,198,199,200,200,201,202,202,203,203,     204,205,205,206,207,207,208,208,209,210,210,211,211,212,213,213,214,     214,215,216,216,217,217,218,219,219,220,220,221,221,222,223,223,224,     224,225,225,226,227,227,228,228,229,229,230,230,231,232,232,233,233,     234,234,235,235,236,236,237,237,238,239,239,240,240,241,241,242,242,     243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,     251,252,252,253,254,254,255,255}};// local copy of the palette for V_GetColor()RGBA_t  *pLocalPalette=NULL;     // keep a copy of the palette so that we can get the RGB// value for a color index at any time.static void LoadPalette( void ){    int     i,palsize;    byte*   usegamma = gammatable[cv_usegamma.value];    byte*   pal;    i = W_GetNumForName( "PLAYPAL" );    palsize = W_LumpLength(i)/3;    if( pLocalPalette )        Z_Free(pLocalPalette);    pLocalPalette = Z_Malloc(sizeof(RGBA_t)*palsize, PU_STATIC, NULL);        pal = W_CacheLumpNum(i, PU_CACHE);    for( i=0; i<palsize; i++ )    {        pLocalPalette[i].s.red   = usegamma[*pal++];        pLocalPalette[i].s.green = usegamma[*pal++];        pLocalPalette[i].s.blue  = usegamma[*pal++];//        if( (i&0xff) == HWR_PATCHES_CHROMAKEY_COLORINDEX )//            pLocalPalette[i].s.alpha = 0;//        else            pLocalPalette[i].s.alpha = 0xff;    }}// -------------+// V_SetPalette : Set the current palette to use for palettized graphics//              : (that is, most if not all of Doom's original graphics)// -------------+void V_SetPalette( int palettenum ){    if( !pLocalPalette )        LoadPalette();#ifdef HWRENDER    if( rendermode != render_soft )        HWR_SetPalette( &pLocalPalette[palettenum*256] );#ifdef LINUX    else // Hurdler: is it only necessary under win32 for startup ?#endif#endif    I_SetPalette( &pLocalPalette[palettenum*256] );}void CV_usegamma_OnChange(void){    // reload palette    LoadPalette();    V_SetPalette(0);}//added:18-02-98: this is an offset added to the destination address,//                for all SCALED graphics. When the menu is displayed,//                it is TEMPORARILY set to vid.centerofs, the rest of//                the time it should be zero.//                The menu is scaled, a round multiple of the original//                pixels to keep the graphics clean, then it is centered//                a little, but excepeted the menu, scaled graphics don't//                have to be centered. Set by m_menu.c, and SCR_Recalc()int     scaledofs;// V_MarkRect : this used to refresh only the parts of the screen//              that were modified since the last screen update//              it is useless today//int        dirtybox[4];void V_MarkRect ( int           x,                  int           y,                  int           width,                  int           height ){    M_AddToBox (dirtybox, x, y);    M_AddToBox (dirtybox, x+width-1, y+height-1);}//// V_CopyRect//void V_CopyRect( int           srcx,  int           srcy,  int           srcscrn,  int           width,  int           height,  int           destx,  int           desty,  int           destscrn ){    byte*       src;    byte*       dest;    // WARNING don't mix    if( (srcscrn & V_SCALESTART) || (destscrn & V_SCALESTART))    {        srcx*=vid.dupx;        srcy*=vid.dupy;        width*=vid.dupx;        height*=vid.dupy;        destx*=vid.dupx;        desty*=vid.dupy;    }    srcscrn&=0xffff;    destscrn&=0xffff;#ifdef RANGECHECK    if (srcx<0        ||srcx+width >vid.width        || srcy<0        || srcy+height>vid.height        ||destx<0||destx+width >vid.width        || desty<0        || desty+height>vid.height        || (unsigned)srcscrn>4        || (unsigned)destscrn>4)    {        I_Error ("Bad V_CopyRect %d %d %d %d %d %d %d %d", srcx, srcy,                   srcscrn, width, height, destx, desty, destscrn);    }#endif    V_MarkRect (destx, desty, width, height);#ifdef DEBUG    CONS_Printf("V_CopyRect: vidwidth %d screen[%d]=%x to screen[%d]=%x\n",             vid.width,srcscrn,screens[srcscrn],destscrn,screens[destscrn]);    CONS_Printf("..........: srcx %d srcy %d width %d height %d destx %d desty %d\n",            srcx,srcy,width,height,destx,desty);#endif    src = screens[srcscrn]+vid.width*srcy+srcx;    dest = screens[destscrn]+vid.width*desty+destx;    for ( ; height>0 ; height--)    {        memcpy (dest, src, width);        src += vid.width;        dest += vid.width;    }}#if !defined(USEASM) || defined(WIN32)// --------------------------------------------------------------------------// Copy a rectangular area from one bitmap to another (8bpp)// srcPitch, destPitch : width of source and destination bitmaps// --------------------------------------------------------------------------void VID_BlitLinearScreen (byte* srcptr, byte* destptr,                           int width, int height,                           int srcrowbytes, int destrowbytes){    if (srcrowbytes==destrowbytes)      memcpy (destptr, srcptr, srcrowbytes * height);    else    {        while (height--)        {            memcpy (destptr, srcptr, width);            destptr += destrowbytes;            srcptr += srcrowbytes;        }    }}#endif////  V_DrawMappedPatch : like V_DrawScaledPatch, but with a colormap.//////added:05-02-98:void V_DrawMappedPatch ( int           x,                         int           y,                         int           scrn,                         patch_t*      patch,                         byte*         colormap ){    int         count;    int         col;    column_t*   column;    byte*       desttop;    byte*       dest;    byte*       source;    int         w;    int         dupx,dupy;    int         ofs;    int         colfrac,rowfrac;    // draw an hardware converted patch#ifdef HWRENDER    if ( rendermode != render_soft)     {        HWR_ScalePatch(!(scrn & V_NOSCALEPATCH));        HWR_DrawMappedPatch ((GlidePatch_t*)patch, x, y, colormap);        return;    }#endif    if( (scrn & V_NOSCALEPATCH) )        dupx = dupy = 1;    else    {        dupx = vid.dupx;        dupy = vid.dupy;    }    y -= SHORT(patch->topoffset);    x -= SHORT(patch->leftoffset);    if( scrn & V_NOSCALESTART)        desttop = screens[scrn&0xffff] + (y*vid.width) + x;    else        desttop = screens[scrn&0xffff] + (y*vid.dupy*vid.width) + (x*vid.dupx) + scaledofs;    scrn &= 0xffff;    if (!scrn)        V_MarkRect (x, y, SHORT(patch->width)*dupx, SHORT(patch->height)*dupy);    col = 0;    colfrac  = FixedDiv (FRACUNIT, dupx<<FRACBITS);    rowfrac  = FixedDiv (FRACUNIT, dupy<<FRACBITS);    w = SHORT(patch->width)<<FRACBITS;    for ( ; col<w ; col+=colfrac, desttop++)    {        column = (column_t *)((byte *)patch + LONG(patch->columnofs[col>>FRACBITS]));        while (column->topdelta != 0xff )        {            source = (byte *)column + 3;            dest   = desttop + column->topdelta*dupy*vid.width;            count  = column->length*dupy;            ofs = 0;            while (count--)            {                *dest = *(colormap + source[ofs>>FRACBITS] );                dest += vid.width;                ofs += rowfrac;            }            column = (column_t *)( (byte *)column + column->length + 4 );        }    }}//// V_DrawScaledPatch//   like V_DrawPatch, but scaled 2,3,4 times the original size and position//   this is used for menu and title screens, with high resolutions////added:05-02-98:// default params : scale patch and scale startvoid V_DrawScaledPatch ( int           x,                         int           y,                         int           scrn,    // hacked flags in it...                         patch_t*      patch ){    int         count;    int         col;    column_t*   column;    byte*       desttop;    byte*       dest;    byte*       source;    int         w;    int         dupx,dupy;    int         ofs;    int         colfrac,rowfrac;    // draw an hardware converted patch#ifdef HWRENDER    if ( rendermode != render_soft)     {        HWR_ScalePatch(!(scrn & V_NOSCALEPATCH));        HWR_DrawPatch ((GlidePatch_t*)patch, x, y);        return;    }#endif    if( (scrn & V_NOSCALEPATCH) )        dupx = dupy = 1;    else    {        dupx = vid.dupx;        dupy = vid.dupy;    }            y -= SHORT(patch->topoffset);    x -= SHORT(patch->leftoffset);    col = 0;    colfrac  = FixedDiv (FRACUNIT, dupx<<FRACBITS);    rowfrac  = FixedDiv (FRACUNIT, dupy<<FRACBITS);    desttop = screens[scrn&0xFF];    if (scrn&V_NOSCALESTART)        desttop += (y*vid.width) + x;    else        desttop += (y*dupy*vid.width) + (x*dupx) + scaledofs;    w = SHORT(patch->width)<<FRACBITS;    for ( ; col<w ; col+=colfrac, desttop++)    {        column = (column_t *)((byte *)patch + LONG(patch->columnofs[col>>FRACBITS]));        while (column->topdelta != 0xff )        {

⌨️ 快捷键说明

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