home *** CD-ROM | disk | FTP | other *** search
/ Toolkit for DOOM / DOOMTOOL.ISO / editors / dme301.zip / SOURCE.ZIP / DEBUG.C < prev    next >
C/C++ Source or Header  |  1994-07-16  |  9KB  |  378 lines

  1. /*
  2.     This is a DMapEdit source code module.  Though it is copyrighted, you
  3.     may modify it and use it for your own personal use, meaning that new
  4.     modified code and anything derived from it (such as exe files) doesn't
  5.     get distributed to anyone, unless you get my permission first.  Code
  6.     from this file, or code based on ideas from this file may be used with
  7.     other programs, provided that you give credit for it in the source code,
  8.     documentation, and 'about' windows or screens, if one exists, for the
  9.     programs using it.  Giving credit means something like this:
  10.  
  11.     Code from DMapEdit was used in this program
  12.  
  13.                               or
  14.  
  15.     Some code for this program was based on ideas presented in DMapEdit
  16.  
  17.     Whatever.  Just be sure to mention "DMapEdit" in such a way that it's
  18.     self-evident how it was useful to the new program, and be sure to have
  19.     "DMapEdit is a trademark of Jason Hoffoss" in the docs.  That's all..
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <graphics.h>
  24. #include <string.h>
  25. #include <conio.h>
  26. #include <dos.h>
  27. #include "dme.h"
  28. #include "dme2.h"
  29.  
  30. int test_ssec=0;
  31.  
  32. void block_test(void)
  33. {
  34.     int offset, line1, num, x, y;
  35.     int x1, y1, v2, v3, v4;
  36.  
  37.     x = (re_x() - blockmap->xorigin) / 128;
  38.     y = (re_y() - blockmap->yorigin) / 128;
  39.     if (x < 0 || x >= blockmap->xsize || y < 0 || y >= blockmap->ysize)
  40.         return;
  41.     num = y * blockmap->xsize + x;
  42.     offset = blockmap->offsets[num] - 4;
  43.     if (blockmap->offsets[offset++])
  44.     {
  45.         error("non-zero error");
  46.         return;
  47.     }
  48.     while ((line1 = blockmap->offsets[offset++]) != -1)
  49.     {
  50.         setcolor(255);
  51.         draw_line(line1, SOLID_LINE);
  52.         setcolor(0);
  53.         draw_line(line1, DOTTED_LINE);
  54.     }
  55.     return;
  56. }
  57.  
  58. int seg_test(void)
  59. {
  60.     char msg[1024], msg2[256];
  61.     int i, start, end, key, n_count, v1, v2, x1, x2, y1, y2;
  62.  
  63.     if (test_ssec >= ss_size)
  64.         test_ssec = 0;
  65.     while (1)
  66.     {
  67.         draw_ssec(test_ssec);
  68.         sprintf(msg, "SSec #%d: (%d segs)", test_ssec,
  69.             ssectors[test_ssec].size);
  70.         start = ssectors[test_ssec].segptr;
  71.         end = start + ssectors[test_ssec].size;
  72.         for (i=start; i<end; i++)
  73.         {
  74.             sprintf(msg2, " {%u, %d}", segs[i].angle, segs[i].dist);
  75.             strcat(msg, msg2);
  76.         }
  77.  
  78.         toptext(msg);
  79.         key = getkey();
  80.         if (key == ',') {
  81.             if (test_ssec-- == 0)
  82.                 test_ssec = ss_size-1;
  83.         } else if (key == '.') {
  84.             if (++test_ssec == ss_size)
  85.                 test_ssec = 0;
  86.         } else if (key == 't') {
  87.             i = start;
  88.             while (!kbhit())
  89.             {
  90.                 v1 = segs[i].v1;
  91.                 v2 = segs[i].v2;
  92.                 x1 = adjustx(vertexes[v1].x);
  93.                 x2 = adjustx(vertexes[v2].x);
  94.                 y1 = adjusty(vertexes[v1].y);
  95.                 y2 = adjusty(vertexes[v2].y);
  96.  
  97.                 setcolor(96);
  98.                 if (line_in_rect(x1, y1, x2, y2, 0, 0, maxx, maxy))
  99.                     line(win.left, win.top, win.right, win.bottom);
  100.  
  101.                 delay(500);
  102.                 draw_ssec(test_ssec);
  103.                 if (i++ == end - 1)
  104.                     i = start;
  105.             }
  106.             getch();
  107.         } else return key;
  108.         draw_map();
  109.     }
  110. }
  111.  
  112. int node_test(void)
  113. {
  114.     char msg[1024];
  115.     int i, key, x1, y1, x2, y2, left_nodes, right_nodes, left_ss, right_ss;
  116.  
  117.     if (test_node >= n_size)
  118.         test_node = 0;
  119.     while (1)
  120.     {
  121.         left_ss = right_ss = left_nodes = right_nodes = 0;
  122.         draw_node(test_node, &left_nodes, &right_nodes, &left_ss, &right_ss, 1);
  123.         setlinestyle(SOLID_LINE, 0, 3);
  124.         setcolor(60);
  125.         x1 = nodes[test_node].x;
  126.         y1 = nodes[test_node].y;
  127.         x2 = x1 + nodes[test_node].dx;
  128.         y2 = y1 + nodes[test_node].dy;
  129.         draw_side(x1, y1, x2, y2);
  130.         setlinestyle(SOLID_LINE, 0, 1);
  131.  
  132.         sprintf(msg, "Node #%d Contains: %d Sub Sectors, %d Recursed Nodes",
  133.             test_node, left_ss + right_ss, left_nodes + right_nodes);
  134.         toptext(msg);
  135.         key = getkey();
  136.         if (key == ',')
  137.         {
  138.             if (test_node-- == 0)
  139.                 test_node = n_size-1;
  140.         } else if (key == '.')
  141.         {
  142.             if (++test_node == n_size)
  143.                 test_node = 0;
  144.         } else return key;
  145.         draw_map();
  146.     }
  147. }
  148.  
  149. int node_test2(void)
  150. {
  151.     char msg[1024], msg2[80];
  152.     int i, key, x1, y1, x2, y2, left_nodes, right_nodes, left_ss, right_ss;
  153.     uint link;
  154.     struct n_struct node;
  155.  
  156.     while (1)
  157.     {
  158.         left_ss = right_ss = 0;
  159.         left_nodes = right_nodes = -1;
  160.         draw_node(test_node, &left_nodes, &right_nodes, &left_ss, &right_ss, 0);
  161.         setlinestyle(SOLID_LINE, 0, 3);
  162.         setcolor(60);
  163.         x1 = nodes[test_node].x;
  164.         y1 = nodes[test_node].y;
  165.         x2 = x1 + nodes[test_node].dx;
  166.         y2 = y1 + nodes[test_node].dy;
  167.         draw_side(x1, y1, x2, y2);
  168.         setlinestyle(SOLID_LINE, 0, 1);
  169.  
  170.         if ((link = nodes[test_node].link1) < 32768)
  171.             sprintf(msg, "Node #%d Contains: Right: Node #%u (%d more), "
  172.                 "%d Sub Sectors", test_node, link, right_nodes, right_ss);
  173.         else
  174.             sprintf(msg, "Node #%d Contains: Right: Sub Sector #%u",
  175.                 test_node, link - 32768);
  176.         if ((link = nodes[test_node].link2) < 32768)
  177.             sprintf(msg2, "Left: Node #%u (%d more), %d Sub Sectors",
  178.                 link, left_nodes, left_ss);
  179.         else
  180.             sprintf(msg2, "Left: Sub Sector #%u", link - 32768);
  181.         toptext2(msg, msg2);
  182.         key = getkey();
  183.         if (key == ',')
  184.             link = nodes[test_node].link2;
  185.         else if (key == '.')
  186.             link = nodes[test_node].link1;
  187.         else if (key == '[')
  188.         {
  189.             if (test_node-- == 0)
  190.                 test_node = n_size-1;
  191.         } else if (key == ']')
  192.         {
  193.             if (++test_node == n_size)
  194.                 test_node = 0;
  195.         } else if (key == '=')
  196.         {
  197.             node = nodes[test_node];
  198.             nodes[test_node].node1.x1 = node.node2.x1;
  199.             nodes[test_node].node1.y1 = node.node2.y1;
  200.             nodes[test_node].node1.x2 = node.node2.x2;
  201.             nodes[test_node].node1.y2 = node.node2.y2;
  202.             nodes[test_node].node2.x1 = node.node1.x1;
  203.             nodes[test_node].node2.y1 = node.node1.y1;
  204.             nodes[test_node].node2.x2 = node.node1.x2;
  205.             nodes[test_node].node2.y2 = node.node1.y2;
  206.             nodes[test_node].link1 = node.link2;
  207.             nodes[test_node].link2 = node.link1;
  208.             nodes[test_node].x = node.x + node.dx;
  209.             nodes[test_node].y = node.y + node.dy;
  210.             nodes[test_node].dx = -node.dx;
  211.             nodes[test_node].dy = -node.dy;
  212.             continue;
  213.         }
  214.         else return key;
  215.  
  216.         draw_map();
  217.  
  218.         if (link < 32768)
  219.             test_node = link;
  220.         else {
  221.             test_ssec = link - 32768;
  222.             edit_mode = 100; /* display ssector now */
  223.             return 0;
  224.         }
  225.     }
  226. }
  227.  
  228. void draw_node(int node, int *ln, int *rn, int *lss, int *rss, int recurse)
  229. {
  230.     int x1, y1, x2, y2, rr, ln1, rn1, lss1, rss1;
  231.     uint link;
  232.  
  233.     if (recurse >= 0)
  234.     {
  235.         setlinestyle(DOTTED_LINE, 0, 3);
  236.         setcolor(96);
  237.         x1 = nodes[node].node1.x1;
  238.         y1 = nodes[node].node1.y1;
  239.         x2 = nodes[node].node1.x2;
  240.         y2 = nodes[node].node1.y2;
  241.         rectangle(adjustx(x1), adjusty(y1), adjustx(x2), adjusty(y2));
  242.         setcolor(32);
  243.         x1 = nodes[node].node2.x1;
  244.         y1 = nodes[node].node2.y1;
  245.         x2 = nodes[node].node2.x2;
  246.         y2 = nodes[node].node2.y2;
  247.         rectangle(adjustx(x1), adjusty(y1), adjustx(x2), adjusty(y2));
  248.     }
  249.     rr = 1;
  250.     if (recurse < 1)
  251.         rr = -1;
  252.  
  253.     if ((link = nodes[node].link1) > 32767)
  254.     {
  255.         if (recurse > 0)
  256.             draw_ssec(link - 32768);
  257.         (*rss)++;
  258.     } else {
  259.         ln1 = rn1 = lss1 = rss1 = 0;
  260.         draw_node(link, &ln1, &rn1, &lss1, &rss1, rr);
  261.         (*rn) += ln1 + rn1 + 1;
  262.         (*rss) += lss1 + rss1;
  263.     }
  264.     if ((link = nodes[node].link2) > 32767)
  265.     {
  266.         if (recurse > 0)
  267.             draw_ssec(link - 32768);
  268.         (*lss)++;
  269.     } else {
  270.         ln1 = rn1 = lss1 = rss1 = 0;
  271.         draw_node(link, &ln1, &rn1, &lss1, &rss1, rr);
  272.         (*ln) += ln1 + rn1 + 1;
  273.         (*lss) += lss1 + rss1;
  274.     }
  275.     return;
  276. }
  277.  
  278. void draw_ssec(int ssec)
  279. {
  280.     int i, start, end, x1, y1, x2, y2, point1, point2;
  281.  
  282.     setlinestyle(DOTTED_LINE, 0, 3);
  283.     setcolor(253);
  284.     for (i=0; i<n_size; i++)
  285.     {
  286.         if (nodes[i].link1 == ssec + 32768)
  287.         {
  288.             x1 = nodes[i].node1.x1;
  289.             y1 = nodes[i].node1.y1;
  290.             x2 = nodes[i].node1.x2;
  291.             y2 = nodes[i].node1.y2;
  292.             break;
  293.         }
  294.         if (nodes[i].link2 == ssec + 32768)
  295.         {
  296.             x1 = nodes[i].node2.x1;
  297.             y1 = nodes[i].node2.y1;
  298.             x2 = nodes[i].node2.x2;
  299.             y2 = nodes[i].node2.y2;
  300.             break;
  301.         }
  302.     }
  303.     rectangle(adjustx(x1), adjusty(y1), adjustx(x2), adjusty(y2));
  304.  
  305.     setlinestyle(SOLID_LINE, 0, 3);
  306.     start = ssectors[ssec].segptr;
  307.     end = start + ssectors[ssec].size;
  308.     for (i=start; i<end; i++)
  309.     {
  310.         point1 = segs[i].v1;
  311.         point2 = segs[i].v2;
  312.         x1 = adjustx(vertexes[point1].x);
  313.         x2 = adjustx(vertexes[point2].x);
  314.         y1 = adjusty(vertexes[point1].y);
  315.         y2 = adjusty(vertexes[point2].y);
  316.  
  317.         if (segs[i].dir)
  318.             setcolor(254);
  319.         else
  320.             setcolor(255);
  321.  
  322.         if (line_in_rect(x1, y1, x2, y2, 0, 0, maxx, maxy))
  323.         {
  324.             line(win.left, win.top, win.right, win.bottom);
  325.             if (points)
  326.             {
  327.                 draw_seg_vertex(point1, 96);
  328.                 draw_seg_vertex(point2, 32);
  329.             }
  330.         }
  331.     }
  332.     setlinestyle(SOLID_LINE, 0, 1);
  333.     return;
  334. }
  335.  
  336. void draw_seg_vertex(int num, int color)
  337. {
  338.     char image[125];
  339.     int i, x, y;
  340.  
  341.     x = adjustx(vertexes[num].x);
  342.     y = adjusty(vertexes[num].y);
  343.  
  344.     if (x < points ||
  345.          y < points ||
  346.          x > maxx - (points * 2) ||
  347.          y > maxy - (points * 2)) return;
  348.  
  349.     getimage(x-points, y-points, x+points, y+points, image);
  350.     for (i=4; i<125; i++)
  351.         if (point_ptr[points-1][i])
  352.             image[i] = color;
  353.     putimage(x-points, y-points, image, 0);
  354.     return;
  355. }
  356.  
  357. void color2wall(int line, int col1, int col2)
  358. {
  359.     setcolor(col1);
  360.     draw_line(line, SOLID_LINE);
  361.     setcolor(col2);
  362.     draw_line(line, DOTTED_LINE);
  363.     return;
  364. }
  365.  
  366. void test_draw_sector(int line, int sector)
  367. {
  368.     int sec1, sec2;
  369.  
  370.     if ((sec1 = linedefs[line].sd1) != -1)
  371.         sec1 = sidedefs[sec1].sector;
  372.     if ((sec2 = linedefs[line].sd2) != -1)
  373.         sec2 = sidedefs[sec2].sector;
  374.     if (sec1 == sector || sec2 == sector)
  375.         draw_line(line, SOLID_LINE);
  376.     return;
  377. }
  378.