home *** CD-ROM | disk | FTP | other *** search
/ Quake++ for Quake / Quake++.iso / quake / edquake / code / bsp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-13  |  3.9 KB  |  108 lines

  1. #include "bsp.h"
  2. #include "pak.h"
  3. #include "disk.h"
  4. #include "svgacc.h"
  5.  
  6. dheader_t bsp;
  7. miptex_t  texture[256];
  8. long numtex;
  9.  
  10. dentry_t fgetd(FILE *p)
  11. {
  12.    dentry_t t;
  13.    t.offset = fgetl(p);
  14.    t.size = fgetl(p);
  15.    return t;
  16. }
  17.  
  18. /*void reportbsp() //good for debugging (this routine needs debugged)  :)
  19. {
  20.    printf("BSP file data");
  21.    printf("bsp version: %i\n", bsp.version);
  22.    printf("entities  (%u) bytes @ %u\n", bsp.entities.size, bsp.entities.offset);
  23.    printf("planes    (%u) bytes @ %u\n", bsp.planes.size, bsp.planes.offset);
  24.    printf("miptex    (%u) bytes @ %u\n", bsp.miptex.size, bsp.miptex.offset);
  25.    printf("vertices  (%u) bytes @ %u\n", bsp.vertices.size, bsp.vertices.offset);
  26.    printf("visilist  (%u) bytes @ %u\n", bsp.visilist.size, bsp.visilist.offset);
  27.    printf("nodes     (%u) bytes @ %u\n", bsp.nodes.size, bsp.nodes.offset);
  28.    printf("surfaces  (%u) bytes @ %u\n", bsp.surfaces.size, bsp.surfaces.offset);
  29.    printf("lightmaps (%u) bytes @ %u\n", bsp.lightmaps.size, bsp.lightmaps.offset);
  30.    printf("boundnodes(%u) bytes @ %u\n", bsp.boundnodes.size, bsp.boundnodes.offset);
  31.    printf("leaves    (%u) bytes @ %u\n", bsp.leaves.size, bsp.leaves.offset);
  32.    printf("lstedges  (%u) bytes @ %u\n", bsp.lstedges.size, bsp.lstedges.offset);
  33.    printf("hulls     (%u) bytes @ %u\n", bsp.hulls.size, bsp.hulls.offset);
  34. } */
  35.  
  36. void loadbsp(int e)
  37. {
  38.   getentry(e);
  39.   fseek(pak.p,pakentry.loc,0);
  40.   bsp.startloc = pakentry.loc;
  41.   bsp.version = fgetl(pak.p);            // Model version, must be 0x17 (23).
  42.                      //NOTE:shareware is 0x1c
  43.   bsp.entities = fgetd(pak.p);           // List of Entities.
  44.   bsp.planes = fgetd(pak.p);             // Map Planes.
  45.                      // numplanes = size/sizeof(plane_t)
  46.   bsp.miptex = fgetd(pak.p);             // Wall Textures.
  47.  
  48.   bsp.vertices = fgetd(pak.p);           // Map Vertices.
  49.                    // numvertices = size/sizeof(vertex_t)
  50.   bsp.visilist = fgetd(pak.p);           // Leaves Visibility lists.
  51.   bsp.nodes = fgetd(pak.p);              // BSP Nodes.
  52.                            // numnodes = size/sizeof(node_t)
  53.   bsp.surfaces = fgetd(pak.p);           // Map Surfaces.
  54.                    // numsurfaces = size/sizeof(surface_t)
  55.   bsp.lightmaps = fgetd(pak.p);          // Wall Light Maps.
  56.   bsp.boundnodes = fgetd(pak.p);         // BSP bound nodes, for Hulls.
  57.                    // numbounds = size/sizeof(hullbound_t)
  58.   bsp.leaves = fgetd(pak.p);             // BSP Leaves.
  59.                    // numlaves = size/sizeof(leaf_t)
  60.   bsp.lstsurf = fgetd(pak.p);            // List of Surfaces.
  61.   bsp.edges = fgetd(pak.p);              // Original surface Edges.
  62.                    // numedges = Size/sizeof(edge_t)
  63.   bsp.lstedges = fgetd(pak.p);           // List of surfaces Edges.
  64.   bsp.hulls = fgetd(pak.p);              // List of Hulls.
  65.                    // numhulls = Size/sizeof(hull_t)
  66. }
  67.  
  68. int gettexture()
  69. {
  70.    long offset;
  71.    int t, x;
  72.    int cx, cy;
  73.    fseek(pak.p, bsp.miptex.offset + bsp.startloc, 0);
  74.    numtex = fgetl(pak.p);
  75.    for (x = 0; x < numtex; x++)
  76.    {
  77.    fseek(pak.p, bsp.miptex.offset + bsp.startloc + ((x+1) * 4), 0);
  78.    offset = fgetl(pak.p);
  79.    fseek(pak.p, bsp.miptex.offset + bsp.startloc + offset, 0);
  80.    for (t = 0; t < 16; t++) texture[x].name[t] = fgetc(pak.p);
  81.    texture[x].width = fgetl(pak.p);
  82.    texture[x].height = fgetl(pak.p);
  83.    texture[x].offset1 = fgetl(pak.p);
  84.    texture[x].offset2 = fgetl(pak.p);
  85.    texture[x].offset4 = fgetl(pak.p);
  86.    texture[x].offset8 = fgetl(pak.p);
  87.    fseek(pak.p, texture[x].offset1 - 40, 1);
  88.    texture[x].pakoffset = ftell(pak.p);
  89.    }
  90.    return numtex;
  91. }
  92.  
  93. void showtexture(int e)
  94. {
  95.   int x, y, maxx, maxy, t, skipx;
  96.   fseek(pak.p, texture[e].pakoffset, 0);
  97.   if ((maxx = texture[e].width)  > 128) maxx = 128;
  98.   if ((maxy = texture[e].height) > 128) maxy = 128;
  99.   skipx = maxx - 128;
  100.   for (y = 0; y < maxy; y++)
  101.   {
  102.     for (x = 0; x < texture[e].width; x++)
  103.       drwpoint(SET,fgetc(pak.p),672+x,y+120);
  104.     for (t = 0; t < skipx; t++) fgetc(pak.p);
  105.   }
  106. }
  107.  
  108.