Ejemplo n.º 1
0
void W_InitCache(void)
{
  int maxfd = 0;
  // set up caching
  cachelump = calloc(numlumps, sizeof *cachelump);
  if (!cachelump)
    I_Error ("W_Init: Couldn't allocate lumpcache");

#ifdef TIMEDIAG
  atexit(W_ReportLocks);
#endif

  {
    int i;
    for (i=0; i<numlumps; i++)
      if (lumpinfo[i].wadfile)
        if (lumpinfo[i].wadfile->handle > maxfd) maxfd = lumpinfo[i].wadfile->handle;
  }
  mapped_wad = calloc(maxfd+1,sizeof *mapped_wad);
  {
    int i;
    for (i=0; i<numlumps; i++) {
      cachelump[i].locks = -1;
      if (lumpinfo[i].wadfile) {
        int fd = lumpinfo[i].wadfile->handle;
        if (!mapped_wad[fd])
          if ((mapped_wad[fd] = mmap(NULL,I_Filelength(fd),PROT_READ,MAP_SHARED,fd,0)) == MAP_FAILED) 
            I_Error("W_InitCache: failed to mmap");
      }
    }
  }
}
Ejemplo n.º 2
0
void W_DoneCache(void)
{
  {
    int i;
    for (i=0; i<numlumps; i++)
      if (lumpinfo[i].wadfile) {
        int fd = lumpinfo[i].wadfile->handle;
        if (mapped_wad[fd]) {
          if (munmap(mapped_wad[fd],I_Filelength(fd))) 
            I_Error("W_DoneCache: failed to munmap");
          mapped_wad[fd] = NULL;
        }
      }
  }
  free(mapped_wad);
  mapped_wad = NULL;
}
Ejemplo n.º 3
0
//
// W_AddFile
// 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.
//
// Reload hack removed by Lee Killough
// CPhipps - source is an enum
//
// proff - changed using pointer to wadfile_info_t
static void W_AddFile(wadfile_info_t *wadfile) 
// killough 1/31/98: static, const
{
  wadinfo_t   header;
  lumpinfo_t* lump_p;
  unsigned    i;
  int         length;
  int         startlump;
  filelump_t  *fileinfo, *fileinfo2free=NULL; //killough
  filelump_t  singleinfo;

  // open the file and add to directory

  wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY);

#ifdef HAVE_NET
  if (wadfile->handle == -1 && D_NetGetWad(wadfile->name)) // CPhipps
    wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY);
#endif
    
  if (wadfile->handle == -1) 
    {
      if (  strlen(wadfile->name)<=4 ||      // add error check -- killough
	         (strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".lmp" ) &&
	          strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".gwa" ) )
         )
	I_Error("W_AddFile: couldn't open %s",wadfile->name);
      return;
    }

  //jff 8/3/98 use logical output routine
  lprintf (LO_INFO," adding %s\n",wadfile->name);
  startlump = numlumps;

  if (  strlen(wadfile->name)<=4 || 
	      (
          strcasecmp(wadfile->name+strlen(wadfile->name)-4,".wad") && 
	        strcasecmp(wadfile->name+strlen(wadfile->name)-4,".gwa")
        )
     )
    {
      // single lump file
      fileinfo = &singleinfo;
      singleinfo.filepos = 0;
      singleinfo.size = LONG(I_Filelength(wadfile->handle));
      ExtractFileBase(wadfile->name, singleinfo.name);
      numlumps++;
    }
  else
    {
      // WAD file
      I_Read(wadfile->handle, &header, sizeof(header));
      if (strncmp(header.identification,"IWAD",4) &&
          strncmp(header.identification,"PWAD",4))
        I_Error("W_AddFile: Wad file %s doesn't have IWAD or PWAD id", wadfile->name);
      header.numlumps = LONG(header.numlumps);
      header.infotableofs = LONG(header.infotableofs);
      length = header.numlumps*sizeof(filelump_t);
      fileinfo2free = fileinfo = malloc(length);    // killough
      lseek(wadfile->handle, header.infotableofs, SEEK_SET);
      I_Read(wadfile->handle, fileinfo, length);
      numlumps += header.numlumps;
    }

    // Fill in lumpinfo
    lumpinfo = realloc(lumpinfo, numlumps*sizeof(lumpinfo_t));

    lump_p = &lumpinfo[startlump];

    for (i=startlump ; (int)i<numlumps ; i++,lump_p++, fileinfo++)
      {
        lump_p->wadfile = wadfile;                    //  killough 4/25/98
        lump_p->position = LONG(fileinfo->filepos);
        lump_p->size = LONG(fileinfo->size);
        lump_p->li_namespace = ns_global;              // killough 4/17/98
        strncpy (lump_p->name, fileinfo->name, 8);
	lump_p->source = wadfile->src;                    // Ty 08/29/98
      }

    free(fileinfo2free);      // killough
}
Ejemplo n.º 4
0
//
// W_AddFile
// 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.
//
// Reload hack removed by Lee Killough
// CPhipps - source is an enum
//
// proff - changed using pointer to wadfile_info_t
static void W_AddFile(wadfile_info_t *wadfile) 
// killough 1/31/98: static, const
{
  wadinfo_t   header;
  lumpinfo_t* lump_p;
  unsigned    i;
  int         length;
  int         startlump;
  filelump_t  *fileinfo, *fileinfo2free=NULL; //killough
  filelump_t  singleinfo;
  int         flags = 0;

  // open the file and add to directory

  wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY);

#ifdef HAVE_NET
  if (wadfile->handle == -1 && D_NetGetWad(wadfile->name)) // CPhipps
    wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY);
#endif

  if (wadfile->handle == -1 &&
    strlen(wadfile->name) > 4 &&
    wadfile->src == source_pwad && 
    !strcasecmp(wadfile->name + strlen(wadfile->name) - 4 , ".wad") &&
    D_TryGetWad(wadfile->name))
  {
    wadfile->handle = open(wadfile->name, O_RDONLY | O_BINARY);
  }

  if (wadfile->handle == -1) 
    {
      if (  strlen(wadfile->name)<=4 ||      // add error check -- killough
	         (strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".lmp" ) &&
	          strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".gwa" ) )
         )
	I_Error("W_AddFile: couldn't open %s",wadfile->name);
      return;
    }

  //jff 8/3/98 use logical output routine
  lprintf (LO_INFO," adding %s\n",wadfile->name);
  startlump = numlumps;

  // mark lumps from internal resource
  if (wadfile->src == source_auto_load)
  {
    int len = strlen(PACKAGE_TARNAME ".wad");
    int len_file = strlen(wadfile->name);
    if (len_file >= len)
    {
      if (!strcasecmp(wadfile->name + len_file - len, PACKAGE_TARNAME ".wad"))
      {
        flags = LUMP_PRBOOM;
      }
    }
  }

  if (  strlen(wadfile->name)<=4 || 
	      (
          strcasecmp(wadfile->name+strlen(wadfile->name)-4,".wad") && 
	        strcasecmp(wadfile->name+strlen(wadfile->name)-4,".gwa")
        )
     )
    {
      // single lump file
      fileinfo = &singleinfo;
      singleinfo.filepos = 0;
      singleinfo.size = LittleLong(I_Filelength(wadfile->handle));
      ExtractFileBase(wadfile->name, singleinfo.name);
      numlumps++;
    }
  else
    {
      // WAD file
      I_Read(wadfile->handle, &header, sizeof(header));
      if (strncmp(header.identification,"IWAD",4) &&
          strncmp(header.identification,"PWAD",4))
        I_Error("W_AddFile: Wad file %s doesn't have IWAD or PWAD id", wadfile->name);
      header.numlumps = LittleLong(header.numlumps);
      header.infotableofs = LittleLong(header.infotableofs);
      length = header.numlumps*sizeof(filelump_t);
      fileinfo2free = fileinfo = malloc(length);    // killough
      lseek(wadfile->handle, header.infotableofs, SEEK_SET),
      I_Read(wadfile->handle, fileinfo, length);
      numlumps += header.numlumps;
    }

    // Fill in lumpinfo
    lumpinfo = realloc(lumpinfo, numlumps*sizeof(lumpinfo_t));

    lump_p = &lumpinfo[startlump];

    for (i=startlump ; (int)i<numlumps ; i++,lump_p++, fileinfo++)
      {
        lump_p->flags = flags;
        lump_p->wadfile = wadfile;                    //  killough 4/25/98
        lump_p->position = LittleLong(fileinfo->filepos);
        lump_p->size = LittleLong(fileinfo->size);
        if (wadfile->src == source_lmp)
        {
          // Modifications to place command-line-added demo lumps
          // into a separate "ns_demos" namespace so that they cannot
          // conflict with other lump names
          lump_p->li_namespace = ns_demos;
        }
        else
        {
          lump_p->li_namespace = ns_global;              // killough 4/17/98
        }
        strncpy (lump_p->name, fileinfo->name, 8);
	lump_p->source = wadfile->src;                    // Ty 08/29/98
    // IWAD file used as recource PWAD must not override TEXTURE1 or PNAMES
    if (wadfile->src != source_iwad && !strncmp(header.identification,"IWAD",4) &&
      (!strnicmp(fileinfo->name,"TEXTURE1",8) || !strnicmp(fileinfo->name,"PNAMES",6)))
    {
      strncpy (lump_p->name, "-IGNORE-", 8);
    }
      }

    free(fileinfo2free);      // killough
}