Beispiel #1
0
/*
 * DibOpenFileSimple:  Read basic bitmap information from the given file into
 *   b, shrink, width, and height.  This does not load the actual bits of any bitmap.
 *   Return True on success.
 */
Bool DibOpenFileSimple(const char *szFile, Bitmaps *b, BYTE *shrink, int *width, int *height)
{
   file_node f;

   if (!MappedFileOpenRead(szFile, &f))
      return False;
   
   if (!DibReadHeader(&f, b, shrink))
      return MappedFileClose(&f);
   
   // Switch width and height since walls are rotated 90 degrees
   if (MappedFileRead(&f, height, 4) != 4)
      return MappedFileClose(&f);
   
   if (MappedFileRead(&f, width, 4) != 4)
      return MappedFileClose(&f);
   
   MappedFileClose(&f);
   return True;
}
Beispiel #2
0
/*
 * DibOpenFile: Load the bitmaps in the file given by filename into the
 *   given bitmap structure.  Return TRUE on success.
 */
Bool DibOpenFile(const char *szFile, Bitmaps *b)
{
   file_node f;
   DWORD   dwLen, dwBits;
   DWORD   width, height, xoffset, yoffset;
	BYTE    num_hotspots, shrink;
   int     i, j, size, offset, num_indices;

   if (!MappedFileOpenRead(szFile, &f))
      return False;

   if (!DibReadHeader(&f, b, &shrink))
      return MappedFileClose(&f);
   
   // Allocate memory for bitmap pointers and indices
   size  = b->num_bitmaps * sizeof(PDIB) + b->num_groups * b->max_indices * sizeof(int);
   b->pdibs = (PDIB *) SafeMalloc(size);
   b->indices = (int *) ((BYTE *) b->pdibs + b->num_bitmaps * sizeof(PDIB));
   memset(b->pdibs, 0, size);
   
   // Read in bitmaps
   for (i=0; i < b->num_bitmaps; i++)
   {
      // Switch width and height since walls are rotated 90 degrees
      if (MappedFileRead(&f, &height, 4) != 4)
	 return MappedFileClose(&f);
      
      if (MappedFileRead(&f, &width, 4) != 4)
	 return MappedFileClose(&f);
      
      if (MappedFileRead(&f, &xoffset, 4) != 4)
	 return MappedFileClose(&f);
      
      if (MappedFileRead(&f, &yoffset, 4) != 4)
	 return MappedFileClose(&f);
      
      if (MappedFileRead(&f, &num_hotspots, 1) != 1)
	 return MappedFileClose(&f);
      
      /* How much memory do we need to hold the PDIB? */
      dwBits = width * height;
      dwLen  = dwBits + sizeof(DIBHEADER) + num_hotspots * (sizeof(POINT) + sizeof(BYTE));
      
      // Arrangement of PDIB in memory:
      // Header
      // bytes of bitmap
      // array of hotspot numbers
      // array of hotspot positions
      
      b->pdibs[i] = (PDIB) SafeMalloc(dwLen);
      
      b->pdibs[i]->width        = width;
      b->pdibs[i]->height       = height;
      b->pdibs[i]->xoffset      = xoffset;
      b->pdibs[i]->yoffset      = yoffset;
      b->pdibs[i]->num_hotspots = num_hotspots;
      b->pdibs[i]->numbers      = (char *) (DibPtr(b->pdibs[i]) + dwBits);
      b->pdibs[i]->hotspots     = (POINT *) (b->pdibs[i]->numbers + num_hotspots * sizeof(BYTE));
      b->pdibs[i]->shrink       = shrink;
      
      // read in the hotspots
      for (j=0; j < num_hotspots; j++)
      {
	 if ((MappedFileRead(&f, &b->pdibs[i]->numbers[j], 1) != 1) ||
	     (MappedFileRead(&f, &b->pdibs[i]->hotspots[j].x, 4) != 4) ||
	     (MappedFileRead(&f, &b->pdibs[i]->hotspots[j].y, 4) != 4))
	 {
	    BitmapsFree(b);
	    return MappedFileClose(&f);
	 }
      }
      
      /* read in the bits */
      if (!DibReadBits(&f, b->pdibs[i], version))
      {
	 BitmapsFree(b);
	 return MappedFileClose(&f);
      }
      RotateBits(DibPtr(b->pdibs[i]), height, width);
   }
   
   // Read in indices
   for (i=0; i < b->num_groups; i++)
   {
      // offset stores where we are in indices array
      offset = b->max_indices * i;
      if (MappedFileRead(&f, &num_indices, 4) != 4)
      {
	 BitmapsFree(b);
	 return MappedFileClose(&f);
      }
      b->indices[offset] = num_indices;
      for (j=0; j < num_indices; j++)
      {
	 offset++;
	 if (MappedFileRead(&f, &b->indices[offset], 4) != 4)
	 {
	    BitmapsFree(b);
	    return MappedFileClose(&f);
	 }
      }
   }
   
   MappedFileClose(&f);
   return True;
}
Beispiel #3
0
Bool BSPRooFileLoad(char *fname, room_type *room)
{
   int i, temp;
   BYTE byte;
   WORD num_nodes, num_walls, num_sectors, num_sidedefs;
   int node_pos, wall_pos, sidedef_pos, sector_pos, offset_adjust;
   file_node f;

   if (!MappedFileOpenCopy(fname, &f))
      return False;

   // Check magic number and version
   for (i = 0; i < 4; i++)
      if (CliMappedFileRead(&f, &byte, 1) != 1 || byte != room_magic[i])
      { MappedFileClose(&f); debug(("%s is not a roo file\n", fname)); return False; }

   security = 0;

   if (CliMappedFileRead(&f, &room_version, 4) != 4 || room_version < ROO_VERSION)
   { 
      MappedFileClose(&f); 
      debug(("Bad roo version %d; expecting %d\n", room_version, ROO_VERSION)); 
      return False; 
   }
   
   security += room_version;

   if (CliMappedFileRead(&f, &room->security, 4) != 4)
   { MappedFileClose(&f); return False; }   

   // Read pointer to main info in file, and go there
   if (CliMappedFileRead(&f, &temp, 4) != 4)
   { MappedFileClose(&f); return False; }
   MappedFileGoto(&f, temp);

   // Read size of room
   if (CliMappedFileRead(&f, &room->width, 4) != 4)
   { MappedFileClose(&f); return False; }

   offset_adjust = 0;
   room->cols = room->width >> LOG_FINENESS;

   if (CliMappedFileRead(&f, &room->height, 4) != 4)
   { MappedFileClose(&f); return False; }
   room->rows = room->height >> LOG_FINENESS;

   // Read pointers to file sections
   if (CliMappedFileRead(&f, &node_pos, 4) != 4) { MappedFileClose(&f); return False; }
   if (CliMappedFileRead(&f, &wall_pos, 4) != 4) { MappedFileClose(&f); return False; }
   if (CliMappedFileRead(&f, &temp, 4) != 4) { MappedFileClose(&f); return False; }
   if (CliMappedFileRead(&f, &sidedef_pos, 4) != 4) { MappedFileClose(&f); return False; }
   if (CliMappedFileRead(&f, &sector_pos, 4) != 4) { MappedFileClose(&f); return False; }
   node_pos += offset_adjust;
   wall_pos += offset_adjust;
   sidedef_pos += offset_adjust;
   sector_pos += offset_adjust;

   // Read nodes
   MappedFileGoto(&f, node_pos);
   if (CliMappedFileRead(&f, &num_nodes, 2) != 2) { MappedFileClose(&f); return False; }
   if (LoadNodes(&f, room, num_nodes) == False) 
   { 
      debug(("Failure loading %d nodes\n", num_nodes));
      MappedFileClose(&f); 
      return False; 
   }

   // Read walls
   MappedFileGoto(&f, wall_pos);
   if (CliMappedFileRead(&f, &num_walls, 2) != 2) { MappedFileClose(&f); return False; }
   if (LoadWalls(&f, room, num_walls) == False) 
   { 
      debug(("Failure loading %d walls\n", num_walls));
      MappedFileClose(&f); 
      return False; 
   }

   // Read sidedefs
   MappedFileGoto(&f, sidedef_pos);
   if (CliMappedFileRead(&f, &num_sidedefs, 2) != 2) { MappedFileClose(&f); return False; }
   if (LoadSidedefs(&f, room, num_sidedefs) == False) 
   { 
      debug(("Failure loading %d sidedefs\n", num_sidedefs));
      MappedFileClose(&f); 
      return False; 
   }

   // Read sectors
   MappedFileGoto(&f, sector_pos);
   if (CliMappedFileRead(&f, &num_sectors, 2) != 2) { MappedFileClose(&f); return False; }
   if (LoadSectors(&f, room, num_sectors) == False)
   { 
      debug(("Failure loading %d sectors\n", num_sectors));
      MappedFileClose(&f); 
      return False; 
   }
   
   MappedFileClose(&f);

   if (num_nodes == 0)
   {
      debug(("LoadRoom found room with no nodes!\n"));
      room->tree = NULL;
   }
   else room->tree = &room->nodes[0];

   if (RoomSwizzle(room, room->tree, num_nodes, num_walls, num_sidedefs, num_sectors) ==  False)
   {
      debug(("RoomSwizzle failed\n")); 
      BSPRoomFree(room);
      return False; 
   }

   security ^= 0x89ab786c;
   if (security != room->security)
   {
      debug(("Room security mismatch (got %d, expecting %d)!\n", security, room->security));
      BSPRoomFree(room);
      return False;
   }

   room->num_nodes    = num_nodes;
   room->num_walls    = num_walls;
   room->num_sectors  = num_sectors;
   room->num_sidedefs = num_sidedefs;

//   BSPDumpTree(room->tree, 0);
//   D3DGeometryBuild(room);
   gD3DRedrawAll |= D3DRENDER_REDRAW_ALL;
   SandstormInit();
	playerOldPos.x = 0;
	playerOldPos.y = 0;
	playerOldPos.z = 0;

   CacheReport();

   return True;
}