home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qube / tree.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-07  |  2.5 KB  |  99 lines

  1. /***
  2. ****  QuBE --- BSP tree manipulation routine.
  3. ***/
  4.  
  5. #include "qube.h"
  6. #include "tree.h"
  7.  
  8. static char HeaderInfo[][128] = {
  9.        "List of entities (type, placement, info, etc.)",
  10.        "The map planes (split planes, 28 bytes each)",
  11.        "Pointers to pictures",
  12.        "Map vertices (12 bytes each, floating point)",
  13.        "PVS lists (bit masks)",
  14.        "Hull BSP nodes (32 bytes each)",
  15.        "Map surfaces (24 bytes each)",
  16.        "Wall lighting maps (mip arrays)",
  17.        "Hull-bounding BSP tree (8 bytes each)",
  18.        "Hull BSP leaves (56 bytes each)",
  19.        "List of surfaces (2 bytes each)",
  20.        "Original surface edges (4 bytes each)",
  21.        "List of surface edges (2 bytes each)",
  22.        "List of hulls (56 bytes each)",
  23. };
  24.  
  25. /*
  26. **  ShowHeader.  Display file header and relevant information.
  27. */
  28.  
  29. void ShowHeader(void)
  30. {
  31.     long int *hdptr;
  32.     int i;
  33.  
  34.     printf("\nNo. Offset   Size       Description\n");
  35.     printf(  "--- -------- ---------- -----------\n");
  36.     printf(" 0. %08lX            Identifier tag - should be 17\n", header.id);
  37.  
  38.     for (hdptr = (long int *)(&header) + 1, i = 0; i < 14; i++, hdptr += 2)
  39.         printf("%2d. %08lX (%08lX) %s\n", i+1, *hdptr, *(hdptr+1), HeaderInfo[i]);
  40. }
  41.  
  42. /*
  43. **  XtractAll.    Extract everything to separate files.  Messy.
  44. */
  45.  
  46. void XtractAll(int argnum, char **argv)
  47. {
  48.     long int *hdptr;
  49.     long int i, j, k, readsize;
  50.     FILE *fo;
  51.     char tempname[1024];
  52.     char *temp;
  53.  
  54.     temp = Qmalloc(32768);
  55.  
  56.     for (hdptr = (long int *)(&header) + 1, i = 0; i < 14; i++, hdptr += 2) {
  57.         fseek(fi, *hdptr, SEEK_SET);
  58.                 sprintf(tempname, "%s.%d", argv[argnum+1], i+1);
  59.                 fo = fopen(tempname, "wb");
  60.                 for (j = 0L; j < *(hdptr+1); j += 32768L) {
  61.             if (*(hdptr+1) - j >= 32768) k = 32768;
  62.             else k = *(hdptr+1) - j;
  63.             readsize = fread(temp, sizeof(char), k, fi);
  64.             fwrite(temp, sizeof(char), readsize, fo);
  65.         }
  66.         fclose(fo);
  67.         }
  68.  
  69.     Qfree(temp);
  70. }
  71.  
  72. /*
  73. **  TreeList.  Not a lot, but it does the job.
  74. */
  75.  
  76. void TreeList(void)
  77. {
  78.     short int i, j, k;
  79.     unsigned long readcount;
  80.  
  81.     struct {
  82.         unsigned long int line;       /* What is this?    A polygon pointer? */
  83.         short int left;
  84.         short int right;
  85.     } tree;
  86.  
  87.     if (header.id != 0x17)
  88.         Error("Not a valid .BSP file");
  89.  
  90.         fseek(fi, header.tree, SEEK_SET);
  91.  
  92.     for (i = 0, readcount = 0L; readcount < header.treelen; readcount += 8, i++) {
  93.                 fread(&tree, 8, 1, fi);
  94.         printf("%4d:  %4d  %4d   (%ld)", i, tree.left, tree.right, tree.line);
  95.         printf("\n");
  96.         }
  97. }
  98.  
  99.