home *** CD-ROM | disk | FTP | other *** search
/ Quake++ for Quake / Quake++.iso / quake / qube / gfx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-29  |  7.4 KB  |  297 lines

  1. /***
  2. ****  QuBE --- Graphical display of the level, if possible.
  3. ****
  4. ****  It seriously needs work; better support of, well, everything.
  5. ***/
  6.  
  7. #include "qube.h"
  8. #include "thing.h"
  9. #include "gfx.h"
  10.  
  11. #ifdef QUBE_MSDOS
  12. #include "svgagrph.h"
  13. #include "svgamous.h"
  14. #include "f08nsans.h"
  15. #include "keyboard.h"
  16. #endif
  17. #ifdef QUBE_UNIX
  18. #include "xgfx.h"
  19. #endif
  20.  
  21. void DoGraphics(void);
  22.  
  23. static void DrawScrn(int blackify);
  24. static void DrawOneThing(int highlight, int thing);
  25. static void MouseMove(void);
  26.  
  27. static long int orgx = 0, orgy = 0;
  28. static int scale = 1;
  29.  
  30. static long int grid = 8;
  31.  
  32. void DoGraphics(void)
  33. {
  34.     thing *tt;
  35.     long int i;
  36.         char c;
  37.         char *type;
  38.     char *entry;
  39.  
  40.     maxlen = header.thingslen;
  41.         if (header.id != 0x17)
  42.         Error("Not a valid .BSP file");
  43.  
  44.         fseek(fi, header.things, SEEK_SET);
  45.     do {
  46.         tt = malloc(sizeof(thing));
  47.  
  48.         tt->classname = NULL;
  49.         tt->origin = NULL;
  50.         tt->model = NULL;
  51.         tt->light = NULL;
  52.         tt->angle = NULL;
  53.         tt->wad = NULL;
  54.         tt->style = NULL;
  55.         tt->spawnflags = NULL;
  56.  
  57.         skipspace(fi);
  58.         getopenbrace(fi);
  59.         nextchar(fi);
  60.  
  61.         if (fileend()) break;
  62.  
  63.         do {
  64.             putback = 1;
  65.             skipspace(fi);
  66.             type = getstring(fi);
  67.             skipspace(fi);
  68.             entry = getstring(fi);
  69.             skipspace(fi);
  70.             if (strcmp(type, "classname") == 0) tt->classname = entry;
  71.             if (strcmp(type, "origin") == 0) tt->origin = entry;
  72.             if (strcmp(type, "model") == 0) tt->model = entry;
  73.             if (strcmp(type, "light") == 0) tt->light = entry;
  74.             if (strcmp(type, "angle") == 0) tt->angle = entry;
  75.             if (strcmp(type, "style") == 0) tt->style = entry;
  76.             if (strcmp(type, "wad") == 0) tt->wad = entry;
  77.             if (strcmp(type, "spawnflags") == 0) tt->spawnflags = entry;
  78.  
  79.             c = nextchar(fi);
  80.         } while (c != '}' && c != EOF && c != '\0');
  81.  
  82.         if (tt->origin != NULL)
  83.             sscanf(tt->origin, "%ld%ld%ld", &(tt->x), &(tt->y), &(tt->z));
  84.  
  85.         thingarray[nextthing++] = tt;
  86.  
  87.         skipspace(fi);
  88.  
  89.     } while (!fileend());
  90.  
  91.     InitScrn(M640x480x256);
  92.     InitMouse(640, 480, 1, 1);
  93.     StdCursor(CURarrow);
  94.     MouseOn();
  95.  
  96.     DrawScrn(0);
  97.  
  98.     do {
  99.         while (!KeyStatus()) MouseMove();
  100.  
  101.                 switch (c = ReadKeyScan()) {
  102.         case 0x7F:
  103.             DrawScrn(0);
  104.             break;
  105.         case 0x48:
  106.             DrawScrn(1);
  107.             orgy -= (10 * 32) / scale;
  108.             DrawScrn(0);
  109.             break;
  110.         case 0x4B:
  111.             DrawScrn(1);
  112.             orgx += (10 * 32) / scale;
  113.             DrawScrn(0);
  114.             break;
  115.         case 0x4D:
  116.             DrawScrn(1);
  117.             orgx -= (10 * 32) / scale;
  118.             DrawScrn(0);
  119.             break;
  120.         case 0x50:
  121.             DrawScrn(1);
  122.             orgy += (10 * 32) / scale;
  123.             DrawScrn(0);
  124.             break;
  125.         case 0xC:
  126.             if (scale > 1) {
  127.                 DrawScrn(1);
  128.                 scale--;
  129.                 DrawScrn(0);
  130.             }
  131.             break;
  132.         case 0xD:
  133.             if (scale < 32) {
  134.                 DrawScrn(1);
  135.                 scale++;
  136.                 DrawScrn(0);
  137.             }
  138.             break;
  139.         case 0x31:
  140.             DrawOneThing(0, curthing);
  141.             do {
  142.                 if (++curthing >= nextthing) curthing = 0;
  143.             } while (strcmp(thingarray[curthing]->classname, "light") == 0);
  144.                         DrawOneThing(1, curthing);
  145.                         break;
  146.                 case 0x19:
  147.             DrawOneThing(0, curthing);
  148.             do {
  149.                 if (--curthing < 0) curthing = nextthing - 1;
  150.             } while (strcmp(thingarray[curthing]->classname, "light") == 0);
  151.                         DrawOneThing(1, curthing);
  152.                         break;
  153.         case 0x22:
  154.  
  155. /* The stuff below is for manipulating a grid which can overlay the level.
  156.    The code sucks rocks, so it's commented out. */
  157. #if 0
  158.                         DrawScrn(1);
  159.             grid >>= 1;
  160.             if (grid == 4) grid = 2048;
  161.             DrawScrn(0);
  162. #endif
  163.                         break;
  164.  
  165.                 }
  166.     } while (c != 0x1);
  167.  
  168.     MouseOff();
  169.         KillMouse();
  170.         InitScrn(M80x25x16);
  171. }
  172.  
  173. static void DrawScrn(int blackify)
  174. {
  175.     long int x, y, z, s, so;
  176.     int i, color;
  177.  
  178.     blackify = 0;
  179.  
  180.     MouseOff();
  181.     if (grid != 8) {
  182.         so = s = (grid * scale) / 32;
  183.         x = ((orgx % grid) * scale) / 32;
  184.         y = ((orgy % grid) * scale) / 32;
  185.  
  186.                color = BLUE;
  187.         if (s < 4) {
  188.             color = GRAY;
  189.             s = 4;
  190.         }
  191.         if (blackify) color = BLACK;
  192.  
  193.         for (i = 0; i < 320 + so; i += s) {
  194.             LineXOR(320 + x + i, 0, 320 + x + i, 479, color);
  195.             LineXOR(320 + x - i, 0, 320 + x - i, 479, color);
  196.         }
  197.  
  198.         for (i = 0; i < 240 + so; i += s) {
  199.             LineXOR(0, 240 - y + i, 639, 240 - y + i, color);
  200.             LineXOR(0, 240 - y - i, 639, 240 - y - i, color);
  201.         }
  202.  
  203.         if (color != BLACK) color = LBLUE;
  204.         LineXOR(320 + (orgx * scale) / 32, 0, 320 + (orgx * scale) / 32, 479, color);
  205.         LineXOR(0, 240 - (orgy * scale) / 32, 639, 240 - (orgy * scale) / 32, color);
  206.     }
  207.  
  208.     if (blackify) DrawOneThing(0, curthing);
  209.     MouseOff();
  210.  
  211.     for (i = 0; i < nextthing; i++) {
  212.         if (thingarray[i]->origin != NULL) {
  213.             x = ((thingarray[i]->x + orgx) * scale) / 32;
  214.             y = ((thingarray[i]->y + orgy) * scale) / 32;
  215.  
  216.             color = LRED;
  217.             if (strncmp(thingarray[i]->classname, "light", 5) == 0) color = LGRAY;
  218.             if (strncmp(thingarray[i]->classname, "item_", 5) == 0) color = WHITE;
  219.             if (strncmp(thingarray[i]->classname, "info_player_start", 17) == 0) color = GREEN;
  220.             if (strncmp(thingarray[i]->classname, "info_player_deathmatch", 22) == 0) color = LGREEN;
  221.                         if (strncmp(thingarray[i]->classname, "weapon_", 7) == 0) color = YELLOW;
  222.  
  223.             if (blackify) color = BLACK;
  224.  
  225.                         if (strcmp(thingarray[i]->classname, "light") == 0)
  226.                 BoxFillXOR(320+x, 240-y, 320+x, 240-y, color);
  227.             else if (strcmp(thingarray[i]->classname, "item_health") == 0) {
  228.                 LineXOR(318+x, 240-y, 322+x, 240-y, color);
  229.                 LineXOR(320+x, 238-y, 320+x, 242-y, color);
  230.                         }
  231.             else if (strncmp(thingarray[i]->classname, "weapon_", 7) == 0 ||
  232.                  strncmp(thingarray[i]->classname, "info_player_start", 17) == 0) {
  233.                 BoxOutlnXOR(318+x, 238-y, 322+x, 242-y, color);
  234.                 BoxOutlnXOR(320+x, 240-y, 320+x, 240-y, color);
  235.                         }
  236.             else BoxFillXOR(319+x, 239-y, 321+x, 241-y, color);
  237.         }
  238.     }
  239.  
  240.     if (!blackify) DrawOneThing(1, curthing);
  241.     MouseOn();
  242. }
  243.  
  244. static void DrawOneThing(int highlight, int thing)
  245. {
  246.     long int x, y, z;
  247.     int i = thing, color;
  248.  
  249.     x = ((thingarray[i]->x + orgx) * scale) / 32;
  250.     y = ((thingarray[i]->y + orgy) * scale) / 32;
  251.  
  252.     MouseOff();
  253.     color = LRED;
  254.     if (thingarray[thing]->origin != NULL)
  255.         BoxOutlnXOR(317+x, 237-y, 323+x, 243-y, color);
  256.  
  257.     if (highlight) color = LRED;
  258.     else color = BLACK;
  259.  
  260.         Gprintf(0, 440, Sans8N, color, "#%d. Class \"%s\"", i, thingarray[i]->classname);
  261.     Gprintf(0, 450, Sans8N, color, "Origin \"%s\", Angle \"%s\"", thingarray[i]->origin, thingarray[i]->angle);
  262.     Gprintf(0, 460, Sans8N, color, "SpawnFlags \"%s\"", thingarray[i]->spawnflags);
  263.     Gprintf(0, 470, Sans8N, color, "Model \"%s\", Style \"%s\"", thingarray[i]->model, thingarray[i]->style);
  264.     MouseOn();
  265. }
  266.  
  267. static void MouseMove(void)
  268. {
  269.     long int x, y;
  270.     int i;
  271.     static long int mx, my;
  272.  
  273.         do {
  274.         ReadMouse();
  275.         if (KeyStatus()) break;
  276.         } while (mx == MouseX && my == MouseY);
  277.  
  278.         mx = MouseX;
  279.     my = MouseY;
  280.  
  281.     if (KeyStatus()) return;
  282.  
  283.         for (i = 0; i < nextthing; i++) {
  284.         if (KeyStatus()) break;
  285.         if (i != curthing && thingarray[i]->origin != NULL) {
  286.             x = 320 + ((thingarray[i]->x + orgx) * scale) / 32;
  287.             y = 240 - ((thingarray[i]->y + orgy) * scale) / 32;
  288.             if (MouseX > x-4 && MouseY > y-4 && MouseX < x+4 && MouseY < y+4) {
  289.                 DrawOneThing(0, curthing);
  290.                 DrawOneThing(1, curthing = i);
  291.                 break;
  292.                         }
  293.                 }
  294.         }
  295. }
  296.  
  297.