home *** CD-ROM | disk | FTP | other *** search
- /***
- **** QuBE --- Graphical display of the level, if possible.
- ****
- **** It seriously needs work; better support of, well, everything.
- ***/
-
- #include "qube.h"
- #include "thing.h"
- #include "gfx.h"
-
- #ifdef QUBE_MSDOS
- #include "svgagrph.h"
- #include "svgamous.h"
- #include "f08nsans.h"
- #include "keyboard.h"
- #endif
- #ifdef QUBE_UNIX
- #include "xgfx.h"
- #endif
-
- void DoGraphics(void);
-
- static void DrawScrn(int blackify);
- static void DrawOneThing(int highlight, int thing);
- static void MouseMove(void);
-
- static long int orgx = 0, orgy = 0;
- static int scale = 1;
-
- static long int grid = 8;
-
- void DoGraphics(void)
- {
- thing *tt;
- long int i;
- char c;
- char *type;
- char *entry;
-
- maxlen = header.thingslen;
- if (header.id != 0x17)
- Error("Not a valid .BSP file");
-
- fseek(fi, header.things, SEEK_SET);
- do {
- tt = malloc(sizeof(thing));
-
- tt->classname = NULL;
- tt->origin = NULL;
- tt->model = NULL;
- tt->light = NULL;
- tt->angle = NULL;
- tt->wad = NULL;
- tt->style = NULL;
- tt->spawnflags = NULL;
-
- skipspace(fi);
- getopenbrace(fi);
- nextchar(fi);
-
- if (fileend()) break;
-
- do {
- putback = 1;
- skipspace(fi);
- type = getstring(fi);
- skipspace(fi);
- entry = getstring(fi);
- skipspace(fi);
- if (strcmp(type, "classname") == 0) tt->classname = entry;
- if (strcmp(type, "origin") == 0) tt->origin = entry;
- if (strcmp(type, "model") == 0) tt->model = entry;
- if (strcmp(type, "light") == 0) tt->light = entry;
- if (strcmp(type, "angle") == 0) tt->angle = entry;
- if (strcmp(type, "style") == 0) tt->style = entry;
- if (strcmp(type, "wad") == 0) tt->wad = entry;
- if (strcmp(type, "spawnflags") == 0) tt->spawnflags = entry;
-
- c = nextchar(fi);
- } while (c != '}' && c != EOF && c != '\0');
-
- if (tt->origin != NULL)
- sscanf(tt->origin, "%ld%ld%ld", &(tt->x), &(tt->y), &(tt->z));
-
- thingarray[nextthing++] = tt;
-
- skipspace(fi);
-
- } while (!fileend());
-
- InitScrn(M640x480x256);
- InitMouse(640, 480, 1, 1);
- StdCursor(CURarrow);
- MouseOn();
-
- DrawScrn(0);
-
- do {
- while (!KeyStatus()) MouseMove();
-
- switch (c = ReadKeyScan()) {
- case 0x7F:
- DrawScrn(0);
- break;
- case 0x48:
- DrawScrn(1);
- orgy -= (10 * 32) / scale;
- DrawScrn(0);
- break;
- case 0x4B:
- DrawScrn(1);
- orgx += (10 * 32) / scale;
- DrawScrn(0);
- break;
- case 0x4D:
- DrawScrn(1);
- orgx -= (10 * 32) / scale;
- DrawScrn(0);
- break;
- case 0x50:
- DrawScrn(1);
- orgy += (10 * 32) / scale;
- DrawScrn(0);
- break;
- case 0xC:
- if (scale > 1) {
- DrawScrn(1);
- scale--;
- DrawScrn(0);
- }
- break;
- case 0xD:
- if (scale < 32) {
- DrawScrn(1);
- scale++;
- DrawScrn(0);
- }
- break;
- case 0x31:
- DrawOneThing(0, curthing);
- do {
- if (++curthing >= nextthing) curthing = 0;
- } while (strcmp(thingarray[curthing]->classname, "light") == 0);
- DrawOneThing(1, curthing);
- break;
- case 0x19:
- DrawOneThing(0, curthing);
- do {
- if (--curthing < 0) curthing = nextthing - 1;
- } while (strcmp(thingarray[curthing]->classname, "light") == 0);
- DrawOneThing(1, curthing);
- break;
- case 0x22:
-
- /* The stuff below is for manipulating a grid which can overlay the level.
- The code sucks rocks, so it's commented out. */
- #if 0
- DrawScrn(1);
- grid >>= 1;
- if (grid == 4) grid = 2048;
- DrawScrn(0);
- #endif
- break;
-
- }
- } while (c != 0x1);
-
- MouseOff();
- KillMouse();
- InitScrn(M80x25x16);
- }
-
- static void DrawScrn(int blackify)
- {
- long int x, y, z, s, so;
- int i, color;
-
- blackify = 0;
-
- MouseOff();
- if (grid != 8) {
- so = s = (grid * scale) / 32;
- x = ((orgx % grid) * scale) / 32;
- y = ((orgy % grid) * scale) / 32;
-
- color = BLUE;
- if (s < 4) {
- color = GRAY;
- s = 4;
- }
- if (blackify) color = BLACK;
-
- for (i = 0; i < 320 + so; i += s) {
- LineXOR(320 + x + i, 0, 320 + x + i, 479, color);
- LineXOR(320 + x - i, 0, 320 + x - i, 479, color);
- }
-
- for (i = 0; i < 240 + so; i += s) {
- LineXOR(0, 240 - y + i, 639, 240 - y + i, color);
- LineXOR(0, 240 - y - i, 639, 240 - y - i, color);
- }
-
- if (color != BLACK) color = LBLUE;
- LineXOR(320 + (orgx * scale) / 32, 0, 320 + (orgx * scale) / 32, 479, color);
- LineXOR(0, 240 - (orgy * scale) / 32, 639, 240 - (orgy * scale) / 32, color);
- }
-
- if (blackify) DrawOneThing(0, curthing);
- MouseOff();
-
- for (i = 0; i < nextthing; i++) {
- if (thingarray[i]->origin != NULL) {
- x = ((thingarray[i]->x + orgx) * scale) / 32;
- y = ((thingarray[i]->y + orgy) * scale) / 32;
-
- color = LRED;
- if (strncmp(thingarray[i]->classname, "light", 5) == 0) color = LGRAY;
- if (strncmp(thingarray[i]->classname, "item_", 5) == 0) color = WHITE;
- if (strncmp(thingarray[i]->classname, "info_player_start", 17) == 0) color = GREEN;
- if (strncmp(thingarray[i]->classname, "info_player_deathmatch", 22) == 0) color = LGREEN;
- if (strncmp(thingarray[i]->classname, "weapon_", 7) == 0) color = YELLOW;
-
- if (blackify) color = BLACK;
-
- if (strcmp(thingarray[i]->classname, "light") == 0)
- BoxFillXOR(320+x, 240-y, 320+x, 240-y, color);
- else if (strcmp(thingarray[i]->classname, "item_health") == 0) {
- LineXOR(318+x, 240-y, 322+x, 240-y, color);
- LineXOR(320+x, 238-y, 320+x, 242-y, color);
- }
- else if (strncmp(thingarray[i]->classname, "weapon_", 7) == 0 ||
- strncmp(thingarray[i]->classname, "info_player_start", 17) == 0) {
- BoxOutlnXOR(318+x, 238-y, 322+x, 242-y, color);
- BoxOutlnXOR(320+x, 240-y, 320+x, 240-y, color);
- }
- else BoxFillXOR(319+x, 239-y, 321+x, 241-y, color);
- }
- }
-
- if (!blackify) DrawOneThing(1, curthing);
- MouseOn();
- }
-
- static void DrawOneThing(int highlight, int thing)
- {
- long int x, y, z;
- int i = thing, color;
-
- x = ((thingarray[i]->x + orgx) * scale) / 32;
- y = ((thingarray[i]->y + orgy) * scale) / 32;
-
- MouseOff();
- color = LRED;
- if (thingarray[thing]->origin != NULL)
- BoxOutlnXOR(317+x, 237-y, 323+x, 243-y, color);
-
- if (highlight) color = LRED;
- else color = BLACK;
-
- Gprintf(0, 440, Sans8N, color, "#%d. Class \"%s\"", i, thingarray[i]->classname);
- Gprintf(0, 450, Sans8N, color, "Origin \"%s\", Angle \"%s\"", thingarray[i]->origin, thingarray[i]->angle);
- Gprintf(0, 460, Sans8N, color, "SpawnFlags \"%s\"", thingarray[i]->spawnflags);
- Gprintf(0, 470, Sans8N, color, "Model \"%s\", Style \"%s\"", thingarray[i]->model, thingarray[i]->style);
- MouseOn();
- }
-
- static void MouseMove(void)
- {
- long int x, y;
- int i;
- static long int mx, my;
-
- do {
- ReadMouse();
- if (KeyStatus()) break;
- } while (mx == MouseX && my == MouseY);
-
- mx = MouseX;
- my = MouseY;
-
- if (KeyStatus()) return;
-
- for (i = 0; i < nextthing; i++) {
- if (KeyStatus()) break;
- if (i != curthing && thingarray[i]->origin != NULL) {
- x = 320 + ((thingarray[i]->x + orgx) * scale) / 32;
- y = 240 - ((thingarray[i]->y + orgy) * scale) / 32;
- if (MouseX > x-4 && MouseY > y-4 && MouseX < x+4 && MouseY < y+4) {
- DrawOneThing(0, curthing);
- DrawOneThing(1, curthing = i);
- break;
- }
- }
- }
- }
-
-