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

📄 r_data.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 3 页
字号:
// Emacs style mode select   -*- C++ -*-//-----------------------------------------------------------------------------//// $Id: r_data.c,v 1.25 2001/03/21 18:24:39 stroggonmeth 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: r_data.c,v $// Revision 1.25  2001/03/21 18:24:39  stroggonmeth// Misc changes and fixes. Code cleanup//// Revision 1.24  2001/03/19 18:52:01  hurdler// lil fix//// Revision 1.23  2001/03/13 22:14:20  stroggonmeth// Long time no commit. 3D floors, FraggleScript, portals, ect.//// Revision 1.22  2000/11/04 16:23:43  bpereira// no message//// Revision 1.21  2000/11/02 17:50:09  stroggonmeth// Big 3Dfloors & FraggleScript commit!!//// Revision 1.20  2000/10/04 16:19:23  hurdler// Change all those "3dfx names" to more appropriate names//// Revision 1.19  2000/09/28 20:57:17  bpereira// no message//// Revision 1.18  2000/08/11 12:25:23  hurdler// latest changes for v1.30//// Revision 1.17  2000/07/01 09:23:49  bpereira// no message//// Revision 1.16  2000/05/03 23:51:01  stroggonmeth// A few, quick, changes.//// Revision 1.15  2000/04/23 16:19:52  bpereira// no message//// Revision 1.14  2000/04/18 17:39:39  stroggonmeth// Bug fixes and performance tuning.//// Revision 1.13  2000/04/18 12:54:58  hurdler// software mode bug fixed//// Revision 1.12  2000/04/16 18:38:07  bpereira// no message//// Revision 1.11  2000/04/15 22:12:58  stroggonmeth// Minor bug fixes//// Revision 1.10  2000/04/13 23:47:47  stroggonmeth// See logs//// Revision 1.9  2000/04/08 17:45:11  hurdler// fix some boom stuffs//// Revision 1.8  2000/04/08 17:29:25  stroggonmeth// no message//// Revision 1.7  2000/04/08 11:27:29  hurdler// fix some boom stuffs//// Revision 1.6  2000/04/07 01:39:53  stroggonmeth// Fixed crashing bug in Linux.// Made W_ColormapNumForName search in the other direction to find newer colormaps.//// Revision 1.5  2000/04/06 21:06:19  stroggonmeth// Optimized extra_colormap code...// Added #ifdefs for older water code.//// Revision 1.4  2000/04/06 20:40:22  hurdler// Mostly remove warnings under windows//// Revision 1.3  2000/04/04 00:32:47  stroggonmeth// Initial Boom compatability plus few misc changes all around.//// Revision 1.2  2000/02/27 00:42:10  hurdler// fix CR+LF problem//// Revision 1.1.1.1  2000/02/22 20:32:32  hurdler// Initial import into CVS (v1.29 pr3)////// DESCRIPTION://      Preparation of data for rendering,//      generation of lookups, caching, retrieval by name.////-----------------------------------------------------------------------------#include "doomdef.h"#include "g_game.h"#include "i_video.h"#include "r_local.h"#include "r_sky.h"#include "p_local.h"#include "r_data.h"#include "w_wad.h"#include "z_zone.h"#include "p_setup.h" //levelflats#include "v_video.h" //pLoaclPalette#ifdef __WIN32__#include "malloc.h"#endif//// Graphics.// DOOM graphics for walls and sprites// is stored in vertical runs of opaque pixels (posts).// A column is composed of zero or more posts,// a patch or sprite is composed of zero or more columns.//#ifdef OLDWATERint             firstwaterflat; //added:18-02-98:WATER!#endifint             firstflat, lastflat, numflats;int             firstpatch, lastpatch, numpatches;int             firstspritelump, lastspritelump, numspritelumps;// texturesint             numtextures=0;      // total number of textures found,// size of following tablestexture_t**     textures=NULL;unsigned int**  texturecolumnofs;   // column offset lookup table for each texturebyte**          texturecache;       // graphics data for each generated full-size textureint*            texturewidthmask;   // texture width is a power of 2, so it                                    // can easily repeat along sidedefs using                                    // a simple maskfixed_t*        textureheight;      // needed for texture peggingint       *flattranslation;             // for global animationint       *texturetranslation;// needed for pre renderingfixed_t*        spritewidth;fixed_t*        spriteoffset;fixed_t*        spritetopoffset;fixed_t*        spriteheight; //SoMlighttable_t    *colormaps;//faB: for debugging/info purposeint             flatmemory;int             spritememory;int             texturememory;//faB: highcolor stuffshort    color8to16[256];       //remap color index to highcolor rgb valueshort*   hicolormaps;           // test a 32k colormap remaps high -> high//// MAPTEXTURE_T CACHING// When a texture is first needed,//  it counts the number of composite columns//  required in the texture and allocates space//  for a column directory and any new columns.// The directory will simply point inside other patches//  if there is only one patch in a given column,//  but any columns with multiple patches//  will have new column_ts generated.////// R_DrawColumnInCache// Clip and draw a column//  from a patch into a cached post.//void R_DrawColumnInCache ( column_t*     patch,                           byte*         cache,                           int           originy,                           int           cacheheight ){    int         count;    int         position;    byte*       source;    byte*       dest;    dest = (byte *)cache;// + 3;    while (patch->topdelta != 0xff)    {        source = (byte *)patch + 3;        count = patch->length;        position = originy + patch->topdelta;        if (position < 0)        {            count += position;            position = 0;        }        if (position + count > cacheheight)            count = cacheheight - position;        if (count > 0)            memcpy (cache + position, source, count);        patch = (column_t *)(  (byte *)patch + patch->length + 4);    }}//// R_GenerateTexture////   Allocate space for full size texture, either single patch or 'composite'//   Build the full textures from patches.//   The texture caching system is a little more hungry of memory, but has//   been simplified for the sake of highcolor, dynamic ligthing, & speed.////   This is not optimised, but it's supposed to be executed only once//   per level, when enough memory is available.//byte* R_GenerateTexture (int texnum){    byte*               block;    byte*               blocktex;    texture_t*          texture;    texpatch_t*         patch;    patch_t*            realpatch;    int                 x;    int                 x1;    int                 x2;    int                 i;    column_t*           patchcol;    unsigned int*       colofs;    int                 blocksize;    texture = textures[texnum];    // allocate texture column offset lookup    // single-patch textures can have holes in it and may be used on    // 2sided lines so they need to be kept in 'packed' format    if (texture->patchcount==1)    {        patch = texture->patches;        blocksize = W_LumpLength (patch->patch);#if 1        realpatch = W_CacheLumpNum (patch->patch, PU_CACHE);        block = Z_Malloc (blocksize,                          PU_STATIC,         // will change tag at end of this function                          &texturecache[texnum]);        memcpy (block, realpatch, blocksize);#else        // FIXME: this version don't put the user z_block        texturecache[texnum] = block = W_CacheLumpNum (patch->patch, PU_STATIC);#endif        //CONS_Printf ("R_GenTex SINGLE %.8s size: %d\n",texture->name,blocksize);        texturememory+=blocksize;        // use the patch's column lookup        colofs = (unsigned int*)(block + 8);        texturecolumnofs[texnum] = colofs;                blocktex = block;        for (i=0; i<texture->width; i++)             colofs[i] += 3;        goto done;    }    //    // multi-patch textures (or 'composite')    //    blocksize = (texture->width * 4) + (texture->width * texture->height);    //CONS_Printf ("R_GenTex MULTI  %.8s size: %d\n",texture->name,blocksize);    texturememory+=blocksize;    block = Z_Malloc (blocksize,                      PU_STATIC,                      &texturecache[texnum]);    // columns lookup table    colofs = (unsigned int*)block;    texturecolumnofs[texnum] = colofs;    // texture data before the lookup table    blocktex = block + (texture->width*4);    // Composite the columns together.    patch = texture->patches;    for (i=0 , patch = texture->patches;         i<texture->patchcount;         i++, patch++)    {        realpatch = W_CacheLumpNum (patch->patch, PU_CACHE);        x1 = patch->originx;        x2 = x1 + SHORT(realpatch->width);        if (x1<0)            x = 0;        else            x = x1;        if (x2 > texture->width)            x2 = texture->width;        for ( ; x<x2 ; x++)        {            patchcol = (column_t *)((byte *)realpatch                                    + LONG(realpatch->columnofs[x-x1]));            // generate column ofset lookup            colofs[x] = (x * texture->height) + (texture->width*4);            R_DrawColumnInCache (patchcol,                                 block + colofs[x],                                 patch->originy,                                 texture->height);        }    }done:    // Now that the texture has been built in column cache,    //  it is purgable from zone memory.    Z_ChangeTag (block, PU_CACHE);    return blocktex;}//// R_GetColumn////// new test version, short!//byte* R_GetColumn ( int           tex,                    int           col ){    byte*       data;    col &= texturewidthmask[tex];    data = texturecache[tex];    if (!data)        data = R_GenerateTexture (tex);    return data + texturecolumnofs[tex][col];}//  convert flat to hicolor as they are requested////byte**  flatcache;byte* R_GetFlat (int  flatlumpnum){    return W_CacheLumpNum (flatlumpnum, PU_CACHE);/*  // this code work but is useless    byte*    data;    short*   wput;    int      i,j;    //FIXME: work with run time pwads, flats may be added    // lumpnum to flatnum in flatcache    if ((data = flatcache[flatlumpnum-firstflat])!=0)                return data;    data = W_CacheLumpNum (flatlumpnum, PU_CACHE);    i=W_LumpLength(flatlumpnum);    Z_Malloc (i,PU_STATIC,&flatcache[flatlumpnum-firstflat]);    memcpy (flatcache[flatlumpnum-firstflat], data, i);    return flatcache[flatlumpnum-firstflat];*//*  // this code don't work because it don't put a proper user in the z_block    if ((data = flatcache[flatlumpnum-firstflat])!=0)       return data;    data = (byte *) W_CacheLumpNum(flatlumpnum,PU_LEVEL);    flatcache[flatlumpnum-firstflat] = data;    return data;    flatlumpnum -= firstflat;    if (scr_bpp==1)    {                flatcache[flatlumpnum] = data;                return data;    }    // allocate and convert to high color    wput = (short*) Z_Malloc (64*64*2,PU_STATIC,&flatcache[flatlumpnum]);    //flatcache[flatlumpnum] =(byte*) wput;    for (i=0; i<64; i++)       for (j=0; j<64; j++)                        wput[i*64+j] = ((color8to16[*data++]&0x7bde) + ((i<<9|j<<4)&0x7bde))>>1;                //Z_ChangeTag (data, PU_CACHE);                return (byte*) wput;*/}//// Empty the texture cache (used for load wad at runtime)//void R_FlushTextureCache (void){    int i;    if (numtextures>0)        for (i=0; i<numtextures; i++)        {            if (texturecache[i])                Z_Free (texturecache[i]);        }}//// R_InitTextures// Initializes the texture list with the textures from the world map.//void R_LoadTextures (void){    maptexture_t*       mtexture;

⌨️ 快捷键说明

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