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

📄 r_things.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (spritedef->spriteframes == NULL)        spritedef->spriteframes =            Z_Malloc (maxframe * sizeof(spriteframe_t), PU_STATIC, NULL);    spritedef->numframes = maxframe;    memcpy (spritedef->spriteframes, sprtemp, maxframe*sizeof(spriteframe_t));    return true;}//// Search for sprite replacements, whose names are in namelist//void R_AddSpriteDefs (char** namelist, int wadnum){    int         i;    int         start;    int         end;    int         addsprites;    // find the sprites section in this pwad    // we need at least the S_END    // (not really, but for speedup)    start = W_CheckNumForNamePwad ("S_START",wadnum,0);    if (start==-1)        start = W_CheckNumForNamePwad ("SS_START",wadnum,0); //deutex compatib.    if (start==-1)        start=0;      // search frames from start of wad                              // (lumpnum low word is 0)    else        start++;   // just after S_START    start &= 0xFFFF;    // 0 based in lumpinfo    end = W_CheckNumForNamePwad ("S_END",wadnum,0);    if (end==-1)        end = W_CheckNumForNamePwad ("SS_END",wadnum,0);     //deutex compatib.    if (end==-1)    {        if (devparm)            CONS_Printf ("no sprites in pwad %d\n", wadnum);        return;        //I_Error ("R_AddSpriteDefs: S_END, or SS_END missing for sprites "        //         "in pwad %d\n",wadnum);    }    end &= 0xFFFF;    //    // scan through lumps, for each sprite, find all the sprite frames    //    addsprites = 0;    for (i=0 ; i<numsprites ; i++)    {        spritename = namelist[i];        if (R_AddSingleSpriteDef (spritename, &sprites[i], wadnum, start, end) )        {            // if a new sprite was added (not just replaced)            addsprites++;            if (devparm)                CONS_Printf ("sprite %s set in pwad %d\n", namelist[i], wadnum);//Fab        }    }    CONS_Printf ("%d sprites added from file %s\n", addsprites, wadfiles[wadnum]->filename);//Fab    //CONS_Error ("press enter\n");}//// GAME FUNCTIONS//static vissprite_t     vissprites[MAXVISSPRITES];static vissprite_t*    vissprite_p;//// R_InitSprites// Called at program start.//void R_InitSprites (char** namelist){    int         i;    char**      check;    for (i=0 ; i<MAXVIDWIDTH ; i++)    {        negonearray[i] = -1;    }    //    // count the number of sprite names, and allocate sprites table    //    check = namelist;    while (*check != NULL)        check++;    numsprites = check - namelist;    if (!numsprites)        I_Error ("R_AddSpriteDefs: no sprites in namelist\n");    sprites = Z_Malloc(numsprites * sizeof(*sprites), PU_STATIC, NULL);    memset (sprites, 0, numsprites * sizeof(*sprites));    // find sprites in each -file added pwad    for (i=0; i<numwadfiles; i++)        R_AddSpriteDefs (namelist, i);    //    // now check for skins    //    // it can be is do before loading config for skin cvar possible value    R_InitSkins ();    for (i=0; i<numwadfiles; i++)        R_AddSkins (i);    //    // check if all sprites have frames    //    /*    for (i=0; i<numsprites; i++)         if (sprites[i].numframes<1)             CONS_Printf ("R_InitSprites: sprite %s has no frames at all\n", sprnames[i]);    */}//// R_ClearSprites// Called at frame start.//void R_ClearSprites (void){    vissprite_p = vissprites;}//// R_NewVisSprite//static vissprite_t     overflowsprite;static vissprite_t* R_NewVisSprite (void){    if (vissprite_p == &vissprites[MAXVISSPRITES])        return &overflowsprite;    vissprite_p++;    return vissprite_p-1;}//// R_DrawMaskedColumn// Used for sprites and masked mid textures.// Masked means: partly transparent, i.e. stored//  in posts/runs of opaque pixels.//short*          mfloorclip;short*          mceilingclip;fixed_t         spryscale;fixed_t         sprtopscreen;fixed_t         sprbotscreen;fixed_t         windowtop;fixed_t         windowbottom;void R_DrawMaskedColumn (column_t* column){    int         topscreen;    int         bottomscreen;    fixed_t     basetexturemid;    basetexturemid = dc_texturemid;    for ( ; column->topdelta != 0xff ; )    {        // calculate unclipped screen coordinates        //  for post        topscreen = sprtopscreen + spryscale*column->topdelta;        bottomscreen = sprbotscreen == MAXINT ? topscreen + spryscale*column->length : sprbotscreen + spryscale*column->length;        dc_yl = (topscreen+FRACUNIT-1)>>FRACBITS;        dc_yh = (bottomscreen-1)>>FRACBITS;        if(windowtop != MAXINT && windowbottom != MAXINT)        {          if(windowtop > topscreen)            dc_yl = (windowtop + FRACUNIT - 1) >> FRACBITS;          if(windowbottom < bottomscreen)            dc_yh = (windowbottom - 1) >> FRACBITS;        }        if (dc_yh >= mfloorclip[dc_x])            dc_yh = mfloorclip[dc_x]-1;        if (dc_yl <= mceilingclip[dc_x])            dc_yl = mceilingclip[dc_x]+1;        if (dc_yl <= dc_yh && dc_yl < vid.height && dc_yh > 0)        {            dc_source = (byte *)column + 3;            dc_texturemid = basetexturemid - (column->topdelta<<FRACBITS);            // dc_source = (byte *)column + 3 - column->topdelta;            // Drawn by either R_DrawColumn            //  or (SHADOW) R_DrawFuzzColumn.            colfunc ();        }        column = (column_t *)(  (byte *)column + column->length + 4);    }    dc_texturemid = basetexturemid;}//// R_DrawVisSprite//  mfloorclip and mceilingclip should also be set.//static void R_DrawVisSprite ( vissprite_t*          vis,                              int                   x1,                              int                   x2 ){    column_t*           column;    int                 texturecolumn;    fixed_t             frac;    patch_t*            patch;    //Fab:R_InitSprites now sets a wad lump number    patch = W_CacheLumpNum (vis->patch, PU_CACHE);    dc_colormap = vis->colormap;    if (vis->transmap==VIS_SMOKESHADE)        // shadecolfunc uses 'colormaps'        colfunc = shadecolfunc;    else if (vis->transmap)    {        colfunc = fuzzcolfunc;        dc_transmap = vis->transmap;    //Fab:29-04-98: translucency table    }    else if (vis->mobjflags & MF_TRANSLATION)    {        // translate green skin to another color        colfunc = transcolfunc;        dc_translation = translationtables - 256 +            ( (vis->mobjflags & MF_TRANSLATION) >> (MF_TRANSSHIFT-8) );    }    if(vis->extra_colormap && !fixedcolormap)    {      if(!dc_colormap)        dc_colormap = vis->extra_colormap->colormap;      else        dc_colormap = &vis->extra_colormap->colormap[dc_colormap - colormaps];    }    if(!dc_colormap)      dc_colormap = colormaps;    //dc_iscale = abs(vis->xiscale)>>detailshift;  ???    dc_iscale = FixedDiv (FRACUNIT, vis->scale);    dc_texturemid = vis->texturemid;    dc_texheight = 0;    frac = vis->startfrac;    spryscale = vis->scale;    sprtopscreen = centeryfrac - FixedMul(dc_texturemid,spryscale);    windowtop = windowbottom = sprbotscreen = MAXINT;    for (dc_x=vis->x1 ; dc_x<=vis->x2 ; dc_x++, frac += vis->xiscale)    {        texturecolumn = frac>>FRACBITS;#ifdef RANGECHECK        if (texturecolumn < 0 || texturecolumn >= SHORT(patch->width))            I_Error ("R_DrawSpriteRange: bad texturecolumn");#endif        column = (column_t *) ((byte *)patch +                               LONG(patch->columnofs[texturecolumn]));        R_DrawMaskedColumn (column);    }    colfunc = basecolfunc;}//// R_SplitSprite// runs through a sector's lightlist andstatic void R_SplitSprite (vissprite_t* sprite, mobj_t* thing){  int           i, lightnum, index;  sector_t*     sector;  vissprite_t*  newsprite;  sector = sprite->sector;  for(i = 1; i < sector->numlights; i++)  {    if(sector->lightlist[i].height >= sprite->gzt || !(sector->lightlist[i].caster->flags & FF_CUTSPRITES))      continue;    if(sector->lightlist[i].height <= sprite->gz)      return;    // Found a split! Make a new sprite, copy the old sprite to it, and    // adjust the heights.    newsprite = R_NewVisSprite ();    memcpy(newsprite, sprite, sizeof(vissprite_t));    sprite->cut |= SC_BOTTOM;    sprite->gz = sector->lightlist[i].height;    newsprite->gzt = sprite->gz;    sprite->sz = (centeryfrac - FixedMul(sector->lightlist[i].height - viewz, sprite->scale)) >> FRACBITS;    newsprite->szt = sprite->sz - 1;    newsprite->cut |= SC_TOP;    if(!(sector->lightlist[i].caster->flags & FF_NOSHADE))    {      if(sector->lightlist[i].caster->flags & FF_FOG)        lightnum = (sector->lightlist[i].lightlevel >> LIGHTSEGSHIFT);      else        lightnum = (sector->lightlist[i].lightlevel >> LIGHTSEGSHIFT) + extralight;      if (lightnum < 0)          spritelights = scalelight[0];      else if (lightnum >= LIGHTLEVELS)          spritelights = scalelight[LIGHTLEVELS-1];      else          spritelights = scalelight[lightnum];      newsprite->extra_colormap = sector->lightlist[i].extra_colormap;      if (thing->frame & FF_SMOKESHADE)        ;      else      {/*        if (thing->frame & FF_TRANSMASK)          ;        else if (thing->flags & MF_SHADOW)          ;*/        if (fixedcolormap )          ;        else if ((thing->frame & (FF_FULLBRIGHT|FF_TRANSMASK) || thing->flags & MF_SHADOW) && (!newsprite->extra_colormap || !newsprite->extra_colormap->fog))          ;        else        {          index = sprite->xscale>>(LIGHTSCALESHIFT-detailshift);          if (index >= MAXLIGHTSCALE)            index = MAXLIGHTSCALE-1;          newsprite->colormap = spritelights[index];        }      }    }    sprite = newsprite;  }}//// R_ProjectSprite// Generates a vissprite for a thing//  if it might be visible.//static void R_ProjectSprite (mobj_t* thing){    fixed_t             tr_x;    fixed_t             tr_y;    fixed_t             gxt;    fixed_t             gyt;    fixed_t             tx;    fixed_t             tz;    fixed_t             xscale;    fixed_t             yscale; //added:02-02-98:aaargll..if I were a math-guy!!!    int                 x1;    int                 x2;    spritedef_t*        sprdef;    spriteframe_t*      sprframe;    int                 lump;    unsigned            rot;    boolean             flip;    int                 index;    vissprite_t*        vis;    angle_t             ang;    fixed_t             iscale;    //SoM: 3/17/2000    fixed_t             gzt;    int                 heightsec;    int                 light = 0;    // transform the origin point    tr_x = thing->x - viewx;    tr_y = thing->y - viewy;    gxt = FixedMul(tr_x,viewcos);    gyt = -FixedMul(tr_y,viewsin);    tz = gxt-gyt;    // thing is behind view plane?    if (tz < MINZ)        return;    // aspect ratio stuff :    xscale = FixedDiv(projection, tz);    yscale = FixedDiv(projectiony, tz);    gxt = -FixedMul(tr_x,viewsin);    gyt = FixedMul(tr_y,viewcos);    tx = -(gyt+gxt);    // too far off the side?    if (abs(tx)>(tz<<2))        return;    if(viewx != bspx || viewy != bspy)    {      angle_t  ang1;      ang1 = R_PointToAngle2(bspx, bspy, thing->x, thing->y) - viewangle;      if(ang1 > ANG90 && ang1 < ANG270)        return;    }    // decide which patch to use for sprite relative to player#ifdef RANGECHECK    if ((unsigned)thing->sprite >= numsprites)        I_Error ("R_ProjectSprite: invalid sprite number %i ",                 thing->sprite);#endif

⌨️ 快捷键说明

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