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

📄 r_data.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 3 页
字号:
  }  #define NUMFROMCHAR(c)  (c >= '0' && c <= '9' ? c - '0' : 0)  if(p2[0] == '#')  {    // SoM: Get parameters like, fadestart, fadeend, and the fogflag...    fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10);    fadeend = NUMFROMCHAR(p2[5]) + (NUMFROMCHAR(p2[4]) * 10);    if(fadestart > 32 || fadestart < 0)      fadestart = 0;    if(fadeend > 33 || fadeend < 1)      fadeend = 33;    fadedist = fadeend - fadestart;    fog = NUMFROMCHAR(p2[1]) ? 1 : 0;  }  #undef getnum  if(p3[0] == '#')  {    cdestr = cr = ((HEX2INT(p3[1]) * 16) + HEX2INT(p3[2]));    cdestg = cg = ((HEX2INT(p3[3]) * 16) + HEX2INT(p3[4]));    cdestb = cb = ((HEX2INT(p3[5]) * 16) + HEX2INT(p3[6]));    fadecolor = (((cb) >> 3) + (((cg) >> 2) << 5) + (((cr) >> 3) << 11));  }  else  {    cdestr = 0;    cdestg = 0;    cdestb = 0;    fadecolor = 0;  }  #undef HEX2INT  for(i = 0; i < num_extra_colormaps; i++)  {    if(foundcolormaps[i] != -1)      continue;    if(maskcolor == extra_colormaps[i].maskcolor &&       fadecolor == extra_colormaps[i].fadecolor &&       maskamt == extra_colormaps[i].maskamt &&       fadestart == extra_colormaps[i].fadestart &&       fadeend == extra_colormaps[i].fadeend &&       fog == extra_colormaps[i].fog)      return i;  }  if(num_extra_colormaps == MAXCOLORMAPS)    I_Error("R_CreateColormap: Too many colormaps!\n");#ifdef HWRENDER  if(rendermode == render_soft)#endif  {    for(i = 0; i < 256; i++)    {      r = pLocalPalette[i].s.red;      g = pLocalPalette[i].s.green;      b = pLocalPalette[i].s.blue;      cbrightness = sqrt((r*r) + (g*g) + (b*b));      map[i][0] = (cbrightness * cmaskr) + (r * othermask);      if(map[i][0] > 255.0)        map[i][0] = 255.0;      deltas[i][0] = (map[i][0] - cdestr) / (double)fadedist;      map[i][1] = (cbrightness * cmaskg) + (g * othermask);      if(map[i][1] > 255.0)        map[i][1] = 255.0;      deltas[i][1] = (map[i][1] - cdestg) / (double)fadedist;      map[i][2] = (cbrightness * cmaskb) + (b * othermask);      if(map[i][2] > 255.0)        map[i][2] = 255.0;      deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist;    }  }  foundcolormaps[num_extra_colormaps] = -1;  // aligned on 8 bit for asm code  extra_colormaps[num_extra_colormaps].colormap = NULL;  extra_colormaps[num_extra_colormaps].maskcolor = maskcolor;  extra_colormaps[num_extra_colormaps].fadecolor = fadecolor;  extra_colormaps[num_extra_colormaps].maskamt = maskamt;  extra_colormaps[num_extra_colormaps].fadestart = fadestart;  extra_colormaps[num_extra_colormaps].fadeend = fadeend;  extra_colormaps[num_extra_colormaps].fog = fog;#define ABS2(x) (x) < 0 ? -(x) : (x)#ifdef HWRENDER  if(rendermode == render_soft)#endif  {    extra_colormaps[num_extra_colormaps].colormap = colormap_p = Z_MallocAlign (256 * 34, PU_LEVEL, 0, 8);    for(p = 0; p < 34; p++)    {      for(i = 0; i < 256; i++)      {        *colormap_p = NearestColor(RoundUp(map[i][0]), RoundUp(map[i][1]), RoundUp(map[i][2]));        colormap_p++;          if((unsigned int)p < fadestart)          continue;          if(ABS2(map[i][0] - cdestr) > ABS2(deltas[i][0]))          map[i][0] -= deltas[i][0];        else          map[i][0] = cdestr;        if(ABS2(map[i][1] - cdestg) > ABS2(deltas[i][1]))          map[i][1] -= deltas[i][1];        else          map[i][1] = cdestg;        if(ABS2(map[i][2] - cdestb) > ABS2(deltas[i][1]))          map[i][2] -= deltas[i][2];        else          map[i][2] = cdestb;      }    }  }#undef ABS2  return num_extra_colormaps++;}//Thanks to quake2 source!//utils3/qdata/images.cunsigned char NearestColor(unsigned char r, unsigned char g, unsigned char b) {  int dr, dg, db;  int distortion;  int bestdistortion = 256 * 256 * 4;  int bestcolor = 0;  int i;  for(i = 0; i < 256; i++) {    dr = r - pLocalPalette[i].s.red;    dg = g - pLocalPalette[i].s.green;    db = b - pLocalPalette[i].s.blue;    distortion = dr*dr + dg*dg + db*db;    if(distortion < bestdistortion) {      if(!distortion)        return i;      bestdistortion = distortion;      bestcolor = i;      }    }  return bestcolor;  }// Rounds off floating numbers and checks for 0 - 255 boundsint RoundUp(double number) {  if(number > 255.0)    return 255.0;  if(number < 0)    return 0;  if((int)number <= (number -0.5))    return (int)number + 1;  return (int)number;  }char *R_ColormapNameForNum(int num){  if(num == -1)    return "NONE";  if(num < 0 || num > MAXCOLORMAPS)    I_Error("R_ColormapNameForNum: num is invalid!\n");  if(foundcolormaps[num] == -1)    return "INLEVEL";  return wadfiles[foundcolormaps[num] >> 16]->lumpinfo[foundcolormaps[num] & 0xffff].name;}////  build a table for quick conversion from 8bpp to 15bpp//int makecol15(int r, int g, int b){   return (((r >> 3) << 10) | ((g >> 3) << 5) | ((b >> 3)));}void R_Init8to16 (void){    byte*       palette;    int         i;    palette = W_CacheLumpName ("PLAYPAL",PU_CACHE);    for (i=0;i<256;i++)    {                // doom PLAYPAL are 8 bit values        color8to16[i] = makecol15 (palette[0],palette[1],palette[2]);        palette += 3;    }    // test a big colormap    hicolormaps = Z_Malloc (32768 /**34*/, PU_STATIC, 0);    for (i=0;i<16384;i++)         hicolormaps[i] = i<<1;}//// R_InitData// Locates all the lumps//  that will be used by all views// Must be called after W_Init.//void R_InitData (void){    //fab highcolor    if (highcolor)    {        CONS_Printf ("\nInitHighColor...");        R_Init8to16 ();    }    CONS_Printf ("\nInitTextures...");    R_LoadTextures ();    CONS_Printf ("\nInitFlats...");    R_InitFlats ();    CONS_Printf ("\nInitSprites...\n");    R_InitSpriteLumps ();    R_InitSprites (sprnames);    CONS_Printf ("\nInitColormaps...\n");    R_InitColormaps ();}//SoM: REmoved R_FlatNumForName//// R_CheckTextureNumForName// Check whether texture is available.// Filter out NoTexture indicator.//int     R_CheckTextureNumForName (char *name){    int         i;    // "NoTexture" marker.    if (name[0] == '-')        return 0;    for (i=0 ; i<numtextures ; i++)        if (!strncasecmp (textures[i]->name, name, 8) )            return i;    return -1;}//// R_TextureNumForName// Calls R_CheckTextureNumForName,//  aborts with error message.//int     R_TextureNumForName (char* name){    int         i;    i = R_CheckTextureNumForName (name);    if (i==-1)    {        I_Error ("R_TextureNumForName: %.8s not found",                 name);    }    return i;}//// R_PrecacheLevel// Preloads all relevant graphics for the level.//// BP: rules : no extern in c !!!//     slution put a new function in p_setup.c or put this in global (not recommended)// SoM: Ok.. Here it goes. This function is in p_setup.c and caches the flats.int P_PrecacheLevelFlats();void R_PrecacheLevel (void){//  char*               flatpresent; //SoM: 4/18/2000: No longer used    char*               texturepresent;    char*               spritepresent;    int                 i;    int                 j;    int                 k;    int                 lump;    thinker_t*          th;    spriteframe_t*      sf;    //int numgenerated;  //faB:debug    if (demoplayback)        return;    // do not flush the memory, Z_Malloc twice with same user    // will cause error in Z_CheckHeap(), 19991022 by Kin    if (rendermode != render_soft)        return;    // Precache flats.    /*flatpresent = alloca(numflats);    memset (flatpresent,0,numflats);    // Check for used flats    for (i=0 ; i<numsectors ; i++)    {#ifdef PARANOIA        if( sectors[i].floorpic<0 || sectors[i].floorpic>numflats )            I_Error("sectors[%d].floorpic=%d out of range [0..%d]\n",i,sectors[i].floorpic,numflats);        if( sectors[i].ceilingpic<0 || sectors[i].ceilingpic>numflats )            I_Error("sectors[%d].ceilingpic=%d out of range [0..%d]\n",i,sectors[i].ceilingpic,numflats);#endif        flatpresent[sectors[i].floorpic] = 1;        flatpresent[sectors[i].ceilingpic] = 1;    }    flatmemory = 0;    for (i=0 ; i<numflats ; i++)    {        if (flatpresent[i])        {            lump = firstflat + i;            if(devparm)               flatmemory += W_LumpLength(lump);            R_GetFlat (lump);//            W_CacheLumpNum(lump, PU_CACHE);        }    }*/    flatmemory = P_PrecacheLevelFlats();    //    // Precache textures.    //    // no need to precache all software textures in 3D mode    // (note they are still used with the reference software view)    if (rendermode == render_soft)    {    texturepresent = alloca(numtextures);    memset (texturepresent,0, numtextures);    for (i=0 ; i<numsides ; i++)    {        texturepresent[sides[i].toptexture] = 1;        texturepresent[sides[i].midtexture] = 1;        texturepresent[sides[i].bottomtexture] = 1;    }    // Sky texture is always present.    // Note that F_SKY1 is the name used to    //  indicate a sky floor/ceiling as a flat,    //  while the sky texture is stored like    //  a wall texture, with an episode dependend    //  name.    texturepresent[skytexture] = 1;    //if (devparm)    //    CONS_Printf("Generating textures..\n");    texturememory = 0;    for (i=0 ; i<numtextures ; i++)    {        if (!texturepresent[i])            continue;        //texture = textures[i];        if( texturecache[i]==NULL )            R_GenerateTexture (i);        //numgenerated++;        // note: pre-caching individual patches that compose textures became        //       obsolete since we now cache entire composite textures        //for (j=0 ; j<texture->patchcount ; j++)        //{        //    lump = texture->patches[j].patch;        //    texturememory += W_LumpLength(lump);        //    W_CacheLumpNum(lump , PU_CACHE);        //}    }    //CONS_Printf ("total mem for %d textures: %d k\n",numgenerated,texturememory>>10);    }    //    // Precache sprites.    //    spritepresent = alloca(numsprites);    memset (spritepresent,0, numsprites);    for (th = thinkercap.next ; th != &thinkercap ; th=th->next)    {        if (th->function.acp1 == (actionf_p1)P_MobjThinker)            spritepresent[((mobj_t *)th)->sprite] = 1;    }    spritememory = 0;    for (i=0 ; i<numsprites ; i++)    {        if (!spritepresent[i])            continue;        for (j=0 ; j<sprites[i].numframes ; j++)        {            sf = &sprites[i].spriteframes[j];            for (k=0 ; k<8 ; k++)            {                //Fab: see R_InitSprites for more about lumppat,lumpid                lump = /*firstspritelump +*/ sf->lumppat[k];                if(devparm)                   spritememory += W_LumpLength(lump);                W_CachePatchNum(lump , PU_CACHE);            }        }    }    //FIXME: this is no more correct with glide render mode    if (devparm)    {        CONS_Printf("Precache level done:\n"                    "flatmemory:    %ld k\n"                    "texturememory: %ld k\n"                    "spritememory:  %ld k\n", flatmemory>>10, texturememory>>10, spritememory>>10 );    }}

⌨️ 快捷键说明

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