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

📄 w_wad.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 2 页
字号:
{    union {        char  s[9];        int   x[2];    } name8;    int         i;    int         v1;    int         v2;    lumpinfo_t* lump_p;    strncpy (name8.s,name,8);    name8.s[8] = 0;    strupr (name8.s);    v1 = name8.x[0];    v2 = name8.x[1];    //    // scan forward    // start at 'startlump', useful parameter when there are multiple    //                       resources with the same name    //    if (startlump < wadfiles[wadid]->numlumps)    {        lump_p = wadfiles[wadid]->lumpinfo + startlump;        for (i = startlump; i<wadfiles[wadid]->numlumps; i++,lump_p++)        {            if ( *(int *)lump_p->name == v1              && *(int *)&lump_p->name[4] == v2)            {                return ((wadid<<16)+i);            }        }    }    // not found.    return -1;}//// W_GetNumForName//   Calls W_CheckNumForName, but bombs out if not found.//int W_GetNumForName (char* name){    int i;    i = W_CheckNumForName (name);    if (i == -1)        I_Error ("W_GetNumForName: %s not found!\n", name);    return i;}int W_CheckNumForNameFirst (char* name){    int i;    // 3am coding.. force a scan of resource name forward, for one call    scanforward = true;    i = W_CheckNumForName (name);    scanforward = false;    return i;}////  W_GetNumForNameFirst : like W_GetNumForName, but scans FORWARD//                         so it gets resources from the original wad first//  (this is used only to get S_START for now, in r_data.c)int W_GetNumForNameFirst (char* name){    int i;    i = W_CheckNumForNameFirst (name);    if (i == -1)        I_Error ("W_GetNumForNameFirst: %s not found!", name);    return i;}////  W_LumpLength//   Returns the buffer size needed to load the given lump.//int W_LumpLength (int lump){#ifdef PARANOIA    if (lump<0) I_Error("W_LumpLenght: lump not exist\n");    if ((lump&0xFFFF) >= wadfiles[lump>>16]->numlumps)        I_Error ("W_LumpLength: %i >= numlumps",lump);#endif    return wadfiles[lump>>16]->lumpinfo[lump&0xFFFF].size;}//// W_ReadLumpHeader : read 'size' bytes of lump//                    sometimes just the header is needed////Fab:02-08-98: now returns the number of bytes read (should == size)int  W_ReadLumpHeader ( int           lump,                        void*         dest,                        int           size ){    int         bytesread;    lumpinfo_t* l;    int         handle;#ifdef PARANOIA    if (lump<0) I_Error("W_ReadLumpHeader: lump not exist\n");    if ((lump&0xFFFF) >= wadfiles[lump>>16]->numlumps)        I_Error ("W_ReadLumpHeader: %i >= numlumps",lump);#endif    l = wadfiles[lump>>16]->lumpinfo + (lump&0xFFFF);    // the good ole 'loading' disc icon TODO: restore it :)    // ??? I_BeginRead ();    // empty resource (usually markers like S_START, F_END ..)    if (l->size==0)        return 0;/*    if (l->handle == -1)    {        // reloadable file, so use open / read / close        if ( (handle = open (reloadname,O_RDONLY|O_BINARY,0666)) == -1)            I_Error ("W_ReadLumpHeader: couldn't open %s",reloadname);    }    else*/        handle = wadfiles[lump>>16]->handle; //l->handle;    // 0 size means read all the lump    if (!size || size>l->size)        size = l->size;        lseek (handle, l->position, SEEK_SET);    bytesread = read (handle, dest, size);    /*if (l->handle == -1)        close (handle);*/    // ??? I_EndRead ();    return bytesread;}////  W_ReadLump//  Loads the lump into the given buffer,//   which must be >= W_LumpLength().////added:06-02-98: now calls W_ReadLumpHeader() with full lump size.//                0 size means the size of the lump, see W_ReadLumpHeadervoid W_ReadLump ( int           lump,                  void*         dest ){    W_ReadLumpHeader (lump, dest, 0);}// ==========================================================================// W_CacheLumpNum// ==========================================================================void* W_CacheLumpNum ( int lump, int tag ){    byte*         ptr;    lumpcache_t*  lumpcache;    //SoM: 4/8/2000: Don't keep doing oporations to the lump variable!    int           llump = lump & 0xffff;    int           lfile = lump >> 16;#ifdef PARANOIA    // check return value of a previous W_CheckNumForName()    //SoM: 4/8/2000: Do better checking. No more SIGSEGV's!    if (lfile >= numwadfiles)      I_Error("W_CacheLumpNum: %i >= numwadfiles(%i)\n", lfile, numwadfiles);    if (llump >= wadfiles[lfile]->numlumps)      I_Error ("W_CacheLumpNum: %i >= numlumps", llump);    if(lump == -1)      I_Error ("W_CacheLumpNum: -1 passed!\n");    if(llump < 0)      I_Error ("W_CacheLumpNum: %i < 0!\n", llump);#endif    lumpcache = wadfiles[lfile]->lumpcache;    if (!lumpcache[llump]) {        // read the lump in        //CONS_Printf ("cache miss on lump %i\n",lump);        ptr = Z_Malloc (W_LumpLength (lump), tag, &lumpcache[llump]);        W_ReadLumpHeader (lump, lumpcache[llump], 0);   // read full    }    else {        //CONS_Printf ("cache hit on lump %i\n",lump);        Z_ChangeTag (lumpcache[llump],tag);    }    return lumpcache[llump];}// ==========================================================================// W_CacheLumpName// ==========================================================================void* W_CacheLumpName ( char* name, int tag ){    return W_CacheLumpNum (W_GetNumForName(name), tag);}// ==========================================================================//                                         CACHING OF GRAPHIC PATCH RESOURCES// ==========================================================================// Graphic 'patches' are loaded, and if necessary, converted into the format// the most useful for the current rendermode. For software renderer, the// graphic patches are kept as is. For the hardware renderer, graphic patches// are 'unpacked', and are kept into the cache in that unpacked format, the// heap memory cache then act as a 'level 2' cache just after the graphics// card memory.//// Cache a patch into heap memory, convert the patch format as necessary//// Software-only compile cache the data without conversion#ifdef HWRENDER // not win32 only 19990829 by Kinvoid* W_CachePatchNum ( int lump,int tag ){    GlidePatch_t*   grPatch;    if( rendermode == render_soft )        return W_CacheLumpNum(lump,tag);// ------------------------------------------------------ accelereted RENDER#ifdef PARANOIA    // check the return value of a previous W_CheckNumForName()    if ( ( lump==-1 ) ||         ((lump&0xFFFF) >= wadfiles[lump>>16]->numlumps) )        I_Error ("W_CachePatchNum: %i >= numlumps", lump&0xffff);#endif    grPatch = &(wadfiles[lump>>16]->hwrcache[lump & 0xffff]);    if( grPatch->mipmap.grInfo.data )     {           if( tag == PU_CACHE )            tag = PU_HWRCACHE;        Z_ChangeTag (grPatch->mipmap.grInfo.data, tag);     }    else    {   // first time init grPatch fields        // we need patch w,h,offset,...        // well this code will be executed latter in GetPatch, anyway         // do it now ...        patch_t *ptr = W_CacheLumpNum(grPatch->patchlump, PU_STATIC);        HWR_MakePatch ( ptr, grPatch, &grPatch->mipmap);        Z_Free (ptr);         //Hurdler: why not do a Z_ChangeTag (grPatch->mipmap.grInfo.data, tag) here?        //BP: mmm, yes we can...    }    // return GlidePatch_t, which can be casted to (patch_t) with valid patch header info    return (void*)grPatch;}#endif // HWRENDER Glide version//////void* W_CachePatchName ( char*   name,                         int     tag ){    if( W_CheckNumForName( name )<0)        return W_CachePatchNum (W_GetNumForName("BRDR_MM"), tag);    return W_CachePatchNum (W_GetNumForName(name), tag);}// convert raw heretic picture to legacy pic_t formatvoid *W_CacheRawAsPic( int lump, int width, int height, int tag){    lumpcache_t*  lumpcache;    //SoM: 4/8/2000: Don't keep doing oporations to the lump variable!    int           llump = lump & 0xffff;    int           lfile = lump >> 16;    pic_t         *pic;#ifdef PARANOIA    // check return value of a previous W_CheckNumForName()    //SoM: 4/8/2000: Do better checking. No more SIGSEGV's!    if (lfile >= numwadfiles)      I_Error("W_CacheRawAsPic: %i >= numwadfiles(%i)\n", lfile, numwadfiles);    if (llump >= wadfiles[lfile]->numlumps)      I_Error ("W_CacheRawAsPic: %i >= numlumps", llump);    if(lump == -1)      I_Error ("W_CacheRawAsPic: -1 passed!\n");    if(llump < 0)      I_Error ("W_CacheRawAsPic: %i < 0!\n", llump);#endif    lumpcache = wadfiles[lfile]->lumpcache;    if (!lumpcache[llump])     {        // read the lump in        pic = Z_Malloc (W_LumpLength (lump)+sizeof(pic_t), tag, &lumpcache[llump]);        W_ReadLumpHeader (lump, pic->data, 0);   // read full        pic->width = SHORT(width);        pic->height = SHORT(height);        pic->mode = PALETTE;    }    else         Z_ChangeTag (lumpcache[llump],tag);    return lumpcache[llump];}// search for all DEHACKED lump in all wads and load itvoid W_LoadDehackedLumps( int wadnum ){    int clump = 0;        while (1)    {         clump = W_CheckNumForNamePwad("DEHACKED", wadnum, clump);        if(clump == -1)            break;        CONS_Printf("Loading dehacked from %s\n",wadfiles[wadnum]->filename);        DEH_LoadDehackedLump(clump);        clump++;    }}// --------------------------------------------------------------------------// W_Profile// --------------------------------------------------------------------------///*     --------------------- UNUSED ------------------------int             info[2500][10];int             profilecount;void W_Profile (void){    int         i;    memblock_t* block;    void*       ptr;    char        ch;    FILE*       f;    int         j;    char        name[9];    for (i=0 ; i<numlumps ; i++)    {        ptr = lumpcache[i];        if (!ptr)        {            ch = ' ';            continue;        }        else        {            block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));            if (block->tag < PU_PURGELEVEL)                ch = 'S';            else                ch = 'P';        }        info[i][profilecount] = ch;    }    profilecount++;    f = fopen ("waddump.txt","w");    name[8] = 0;    for (i=0 ; i<numlumps ; i++)    {        memcpy (name,lumpinfo[i].name,8);        for (j=0 ; j<8 ; j++)            if (!name[j])                break;        for ( ; j<8 ; j++)            name[j] = ' ';        fprintf (f,"%s ",name);        for (j=0 ; j<profilecount ; j++)            fprintf (f,"    %c",info[i][j]);        fprintf (f,"\n");    }    fclose (f);}// --------------------------------------------------------------------------// W_AddFile : the old code kept for reference// --------------------------------------------------------------------------// All files are optional, but at least one file must be//  found (PWAD, if all required lumps are present).// Files with a .wad extension are wadlink files//  with multiple lumps.// Other files are single lumps with the base filename//  for the lump name.//int filelen (int handle){    struct stat fileinfo;    if (fstat (handle,&fileinfo) == -1)        I_Error ("Error fstating");    return fileinfo.st_size;}int W_AddFile (char *filename){    wadinfo_t           header;    lumpinfo_t*         lump_p;    unsigned            i;    int                 handle;    int                 length;    int                 startlump;    filelump_t*         fileinfo;    filelump_t          singleinfo;    int                 storehandle;    // open the file and add to directory    // handle reload indicator.    if (filename[0] == '~')    {        filename++;        reloadname = filename;        reloadlump = numlumps;    }    if ( (handle = open (filename,O_RDONLY | O_BINARY)) == -1)    {        CONS_Printf (" couldn't open %s\n",filename);        return 0;    }    CONS_Printf (" adding %s\n",filename);    startlump = numlumps;    if (stricmp (filename+strlen(filename)-3, "wad") )    {        // single lump file        fileinfo = &singleinfo;        singleinfo.filepos = 0;        singleinfo.size = LONG(filelen(handle));        FIL_ExtractFileBase (filename, singleinfo.name);        numlumps++;    }    else    {        // WAD file        read (handle, &header, sizeof(header));        if (strncmp(header.identification,"IWAD",4))        {            // Homebrew levels?            if (strncmp(header.identification,"PWAD",4))            {                I_Error ("Wad file %s doesn't have IWAD "                         "or PWAD id\n", filename);            }            // ???modifiedgame = true;        }        header.numlumps = LONG(header.numlumps);        header.infotableofs = LONG(header.infotableofs);        length = header.numlumps*sizeof(filelump_t);        fileinfo = alloca (length);        lseek (handle, header.infotableofs, SEEK_SET);        read (handle, fileinfo, length);        numlumps += header.numlumps;    }    // Fill in lumpinfo    lumpinfo = realloc (lumpinfo, numlumps*sizeof(lumpinfo_t));    if (!lumpinfo)        I_Error ("Couldn't realloc lumpinfo");    lump_p = &lumpinfo[startlump];    storehandle = reloadname ? -1 : handle;    for (i=startlump ; i<numlumps ; i++,lump_p++, fileinfo++)    {        lump_p->handle = storehandle;        lump_p->position = LONG(fileinfo->filepos);        lump_p->size = LONG(fileinfo->size);        strncpy (lump_p->name, fileinfo->name, 8);    }    if (reloadname)        close (handle);    return 1;}*/

⌨️ 快捷键说明

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