summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/wolf3d/wl_debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/progs/wolf3d/wl_debug.c')
-rw-r--r--apps/plugins/sdl/progs/wolf3d/wl_debug.c863
1 files changed, 863 insertions, 0 deletions
diff --git a/apps/plugins/sdl/progs/wolf3d/wl_debug.c b/apps/plugins/sdl/progs/wolf3d/wl_debug.c
new file mode 100644
index 0000000000..bfa651e87c
--- /dev/null
+++ b/apps/plugins/sdl/progs/wolf3d/wl_debug.c
@@ -0,0 +1,863 @@
1// WL_DEBUG.C
2
3#include "wl_def.h"
4#pragma hdrstop
5
6#ifdef USE_CLOUDSKY
7#include "wl_cloudsky.h"
8#endif
9
10/*
11=============================================================================
12
13 LOCAL CONSTANTS
14
15=============================================================================
16*/
17
18#define VIEWTILEX (viewwidth/16)
19#define VIEWTILEY (viewheight/16)
20
21/*
22=============================================================================
23
24 GLOBAL VARIABLES
25
26=============================================================================
27*/
28
29#ifdef DEBUGKEYS
30
31int DebugKeys (void);
32
33
34// from WL_DRAW.C
35
36void ScalePost();
37void SimpleScaleShape (int xcenter, int shapenum, unsigned height);
38
39/*
40=============================================================================
41
42 LOCAL VARIABLES
43
44=============================================================================
45*/
46
47int maporgx;
48int maporgy;
49enum {mapview,tilemapview,actoratview,visview} viewtype;
50
51void ViewMap (void);
52
53//===========================================================================
54
55/*
56==================
57=
58= CountObjects
59=
60==================
61*/
62
63void CountObjects (void)
64{
65 int i,total,count,active,inactive,doors;
66 objtype *obj;
67
68 CenterWindow (17,7);
69 active = inactive = count = doors = 0;
70
71 US_Print ("Total statics :");
72 total = (int)(laststatobj-&statobjlist[0]);
73 US_PrintUnsigned (total);
74
75 char str[60];
76 sprintf(str,"\nlaststatobj=%.8X",(int32_t)(uintptr_t)laststatobj);
77 US_Print(str);
78
79 US_Print ("\nIn use statics:");
80 for (i=0;i<total;i++)
81 {
82 if (statobjlist[i].shapenum != -1)
83 count++;
84 else
85 doors++; //debug
86 }
87 US_PrintUnsigned (count);
88
89 US_Print ("\nDoors :");
90 US_PrintUnsigned (doornum);
91
92 for (obj=player->next;obj;obj=obj->next)
93 {
94 if (obj->active)
95 active++;
96 else
97 inactive++;
98 }
99
100 US_Print ("\nTotal actors :");
101 US_PrintUnsigned (active+inactive);
102
103 US_Print ("\nActive actors :");
104 US_PrintUnsigned (active);
105
106 VW_UpdateScreen();
107 IN_Ack ();
108}
109
110
111//===========================================================================
112
113/*
114===================
115=
116= PictureGrabber
117=
118===================
119*/
120void PictureGrabber (void)
121{
122 static char fname[] = "WSHOT000.BMP";
123
124 for(int i = 0; i < 1000; i++)
125 {
126 fname[7] = i % 10 + '0';
127 fname[6] = (i / 10) % 10 + '0';
128 fname[5] = i / 100 + '0';
129 int file = open(fname, O_RDONLY | O_BINARY);
130 if(file == -1) break; // file does not exist, so use that filename
131 close(file);
132 }
133
134 // overwrites WSHOT999.BMP if all wshot files exist
135
136 SDL_SaveBMP(curSurface, fname);
137
138 CenterWindow (18,2);
139 US_PrintCentered ("Screenshot taken");
140 VW_UpdateScreen();
141 IN_Ack();
142}
143
144
145//===========================================================================
146
147/*
148===================
149=
150= BasicOverhead
151=
152===================
153*/
154
155void BasicOverhead (void)
156{
157 int x, y, z, offx, offy;
158
159 z = 128/MAPSIZE; // zoom scale
160 offx = 320/2;
161 offy = (160-MAPSIZE*z)/2;
162
163#ifdef MAPBORDER
164 int temp = viewsize;
165 NewViewSize(16);
166 DrawPlayBorder();
167#endif
168
169 // right side (raw)
170
171 for(x=0;x<MAPSIZE;x++)
172 for(y=0;y<MAPSIZE;y++)
173 VWB_Bar(x*z+offx, y*z+offy,z,z,(unsigned)(uintptr_t)actorat[x][y]);
174
175 // left side (filtered)
176
177 uintptr_t tile;
178 int color;
179 offx -= 128;
180
181 for(x=0;x<MAPSIZE;x++)
182 {
183 for(y=0;y<MAPSIZE;y++)
184 {
185 tile = (uintptr_t)actorat[x][y];
186 if (ISPOINTER(tile) && ((objtype *)tile)->flags&FL_SHOOTABLE) color = 72; // enemy
187 else if (!tile || ISPOINTER(tile))
188 {
189 if (spotvis[x][y]) color = 111; // visable
190 else color = 0; // nothing
191 }
192 else if (MAPSPOT(x,y,1) == PUSHABLETILE) color = 171; // pushwall
193 else if (tile == 64) color = 158; // solid obj
194 else if (tile < 128) color = 154; // walls
195 else if (tile < 256) color = 146; // doors
196
197 VWB_Bar(x*z+offx, y*z+offy,z,z,color);
198 }
199 }
200
201 VWB_Bar(player->tilex*z+offx,player->tiley*z+offy,z,z,15); // player
202
203 // resize the border to match
204
205 VW_UpdateScreen();
206 IN_Ack();
207
208#ifdef MAPBORDER
209 NewViewSize(temp);
210 DrawPlayBorder();
211#endif
212}
213
214
215//===========================================================================
216
217/*
218================
219=
220= ShapeTest
221=
222================
223*/
224
225void ShapeTest (void)
226{
227 //TODO
228#if NOTYET
229 extern word NumDigi;
230 extern word *DigiList;
231 extern int postx;
232 extern int postwidth;
233 extern byte *postsource;
234 static char buf[10];
235
236 boolean done;
237 ScanCode scan;
238 int i,j,k,x;
239 longword l;
240 byte *addr;
241 soundnames sound;
242 // PageListStruct far *page;
243
244 CenterWindow(20,16);
245 VW_UpdateScreen();
246 for (i = 0,done = false; !done;)
247 {
248 US_ClearWindow();
249 sound = (soundnames) -1;
250
251 // page = &PMPages[i];
252 US_Print(" Page #");
253 US_PrintUnsigned(i);
254 if (i < PMSpriteStart)
255 US_Print(" (Wall)");
256 else if (i < PMSoundStart)
257 US_Print(" (Sprite)");
258 else if (i == ChunksInFile - 1)
259 US_Print(" (Sound Info)");
260 else
261 US_Print(" (Sound)");
262
263 /* US_Print("\n XMS: ");
264 if (page->xmsPage != -1)
265 US_PrintUnsigned(page->xmsPage);
266 else
267 US_Print("No");
268
269 US_Print("\n Main: ");
270 if (page->mainPage != -1)
271 US_PrintUnsigned(page->mainPage);
272 else if (page->emsPage != -1)
273 {
274 US_Print("EMS ");
275 US_PrintUnsigned(page->emsPage);
276 }
277 else
278 US_Print("No");
279
280 US_Print("\n Last hit: ");
281 US_PrintUnsigned(page->lastHit);*/
282
283 US_Print("\n Address: ");
284 addr = (byte *) PM_GetPage(i);
285 sprintf(buf,"0x%08X",(int32_t) addr);
286 US_Print(buf);
287
288 if (addr)
289 {
290 if (i < PMSpriteStart)
291 {
292 //
293 // draw the wall
294 //
295 vbuf += 32*SCREENWIDTH;
296 postx = 128;
297 postwidth = 1;
298 postsource = addr;
299 for (x=0;x<64;x++,postx++,postsource+=64)
300 {
301 wallheight[postx] = 256;
302 ScalePost ();
303 }
304 vbuf -= 32*SCREENWIDTH;
305 }
306 else if (i < PMSoundStart)
307 {
308 //
309 // draw the sprite
310 //
311 vbuf += 32*SCREENWIDTH;
312 SimpleScaleShape (160, i-PMSpriteStart, 64);
313 vbuf -= 32*SCREENWIDTH;
314 }
315 else if (i == ChunksInFile - 1)
316 {
317 US_Print("\n\n Number of sounds: ");
318 US_PrintUnsigned(NumDigi);
319 for (l = j = k = 0;j < NumDigi;j++)
320 {
321 l += DigiList[(j * 2) + 1];
322 k += (DigiList[(j * 2) + 1] + (PMPageSize - 1)) / PMPageSize;
323 }
324 US_Print("\n Total bytes: ");
325 US_PrintUnsigned(l);
326 US_Print("\n Total pages: ");
327 US_PrintUnsigned(k);
328 }
329 else
330 {
331 byte *dp = addr;
332 for (j = 0;j < NumDigi;j++)
333 {
334 k = (DigiList[(j * 2) + 1] + (PMPageSize - 1)) / PMPageSize;
335 if ((i >= PMSoundStart + DigiList[j * 2])
336 && (i < PMSoundStart + DigiList[j * 2] + k))
337 break;
338 }
339 if (j < NumDigi)
340 {
341 sound = (soundnames) j;
342 US_Print("\n Sound #");
343 US_PrintUnsigned(j);
344 US_Print("\n Segment #");
345 US_PrintUnsigned(i - PMSoundStart - DigiList[j * 2]);
346 }
347 for (j = 0;j < PageLengths[i];j += 32)
348 {
349 byte v = dp[j];
350 int v2 = (unsigned)v;
351 v2 -= 128;
352 v2 /= 4;
353 if (v2 < 0)
354 VWB_Vlin(WindowY + WindowH - 32 + v2,
355 WindowY + WindowH - 32,
356 WindowX + 8 + (j / 32),BLACK);
357 else
358 VWB_Vlin(WindowY + WindowH - 32,
359 WindowY + WindowH - 32 + v2,
360 WindowX + 8 + (j / 32),BLACK);
361 }
362 }
363 }
364
365 VW_UpdateScreen();
366
367 IN_Ack();
368 scan = LastScan;
369
370 IN_ClearKey(scan);
371 switch (scan)
372 {
373 case sc_LeftArrow:
374 if (i)
375 i--;
376 break;
377 case sc_RightArrow:
378 if (++i >= ChunksInFile)
379 i--;
380 break;
381 case sc_W: // Walls
382 i = 0;
383 break;
384 case sc_S: // Sprites
385 i = PMSpriteStart;
386 break;
387 case sc_D: // Digitized
388 i = PMSoundStart;
389 break;
390 case sc_I: // Digitized info
391 i = ChunksInFile - 1;
392 break;
393/* case sc_L: // Load all pages
394 for (j = 0;j < ChunksInFile;j++)
395 PM_GetPage(j);
396 break;*/
397 case sc_P:
398 if (sound != -1)
399 SD_PlayDigitized(sound,8,8);
400 break;
401 case sc_Escape:
402 done = true;
403 break;
404/* case sc_Enter:
405 PM_GetPage(i);
406 break;*/
407 }
408 }
409 SD_StopDigitized();
410#endif
411}
412
413
414//===========================================================================
415
416
417/*
418================
419=
420= DebugKeys
421=
422================
423*/
424
425int DebugKeys (void)
426{
427 boolean esc;
428 int level;
429
430 if (Keyboard[sc_B]) // B = border color
431 {
432 CenterWindow(20,3);
433 PrintY+=6;
434 US_Print(" Border color (0-56): ");
435 VW_UpdateScreen();
436 esc = !US_LineInput (px,py,str,NULL,true,2,0);
437 if (!esc)
438 {
439 level = atoi (str);
440 if (level>=0 && level<=99)
441 {
442 if (level<30) level += 31;
443 else
444 {
445 if (level > 56) level=31;
446 else level -= 26;
447 }
448
449 bordercol=level*4+3;
450
451 if (bordercol == VIEWCOLOR)
452 DrawStatusBorder(bordercol);
453
454 DrawPlayBorder();
455
456 return 0;
457 }
458 }
459 return 1;
460 }
461 if (Keyboard[sc_C]) // C = count objects
462 {
463 CountObjects();
464 return 1;
465 }
466 if (Keyboard[sc_D]) // D = Darkone's FPS counter
467 {
468 CenterWindow (22,2);
469 if (fpscounter)
470 US_PrintCentered ("Darkone's FPS Counter OFF");
471 else
472 US_PrintCentered ("Darkone's FPS Counter ON");
473 VW_UpdateScreen();
474 IN_Ack();
475 fpscounter ^= 1;
476 return 1;
477 }
478 if (Keyboard[sc_E]) // E = quit level
479 playstate = ex_completed;
480
481 if (Keyboard[sc_F]) // F = facing spot
482 {
483 char str[60];
484 CenterWindow (14,6);
485 US_Print ("x:"); US_PrintUnsigned (player->x);
486 US_Print (" ("); US_PrintUnsigned (player->x%65536);
487 US_Print (")\ny:"); US_PrintUnsigned (player->y);
488 US_Print (" ("); US_PrintUnsigned (player->y%65536);
489 US_Print (")\nA:"); US_PrintUnsigned (player->angle);
490 US_Print (" X:"); US_PrintUnsigned (player->tilex);
491 US_Print (" Y:"); US_PrintUnsigned (player->tiley);
492 US_Print ("\n1:"); US_PrintUnsigned (tilemap[player->tilex][player->tiley]);
493 sprintf(str," 2:%.8X",(unsigned)(uintptr_t)actorat[player->tilex][player->tiley]); US_Print(str);
494 US_Print ("\nf 1:"); US_PrintUnsigned (player->areanumber);
495 US_Print (" 2:"); US_PrintUnsigned (MAPSPOT(player->tilex,player->tiley,1));
496 US_Print (" 3:");
497 if ((unsigned)(uintptr_t)actorat[player->tilex][player->tiley] < 256)
498 US_PrintUnsigned (spotvis[player->tilex][player->tiley]);
499 else
500 US_PrintUnsigned (actorat[player->tilex][player->tiley]->flags);
501 VW_UpdateScreen();
502 IN_Ack();
503 return 1;
504 }
505
506 if (Keyboard[sc_G]) // G = god mode
507 {
508 CenterWindow (12,2);
509 if (godmode == 0)
510 US_PrintCentered ("God mode ON");
511 else if (godmode == 1)
512 US_PrintCentered ("God (no flash)");
513 else if (godmode == 2)
514 US_PrintCentered ("God mode OFF");
515
516 VW_UpdateScreen();
517 IN_Ack();
518 if (godmode != 2)
519 godmode++;
520 else
521 godmode = 0;
522 return 1;
523 }
524 if (Keyboard[sc_H]) // H = hurt self
525 {
526 IN_ClearKeysDown ();
527 TakeDamage (16,NULL);
528 }
529 else if (Keyboard[sc_I]) // I = item cheat
530 {
531 CenterWindow (12,3);
532 US_PrintCentered ("Free items!");
533 VW_UpdateScreen();
534 GivePoints (100000);
535 HealSelf (99);
536 if (gamestate.bestweapon<wp_chaingun)
537 GiveWeapon (gamestate.bestweapon+1);
538 gamestate.ammo += 50;
539 if (gamestate.ammo > 99)
540 gamestate.ammo = 99;
541 DrawAmmo ();
542 IN_Ack ();
543 return 1;
544 }
545 else if (Keyboard[sc_K]) // K = give keys
546 {
547 CenterWindow(16,3);
548 PrintY+=6;
549 US_Print(" Give Key (1-4): ");
550 VW_UpdateScreen();
551 esc = !US_LineInput (px,py,str,NULL,true,1,0);
552 if (!esc)
553 {
554 level = atoi (str);
555 if (level>0 && level<5)
556 GiveKey(level-1);
557 }
558 return 1;
559 }
560 else if (Keyboard[sc_L]) // L = level ratios
561 {
562 byte x,start,end=LRpack;
563
564 if (end == 8) // wolf3d
565 {
566 CenterWindow(17,10);
567 start = 0;
568 }
569 else // sod
570 {
571 CenterWindow(17,12);
572 start = 0; end = 10;
573 }
574again:
575 for(x=start;x<end;x++)
576 {
577 US_PrintUnsigned(x+1);
578 US_Print(" ");
579 US_PrintUnsigned(LevelRatios[x].time/60);
580 US_Print(":");
581 if (LevelRatios[x].time%60 < 10)
582 US_Print("0");
583 US_PrintUnsigned(LevelRatios[x].time%60);
584 US_Print(" ");
585 US_PrintUnsigned(LevelRatios[x].kill);
586 US_Print("% ");
587 US_PrintUnsigned(LevelRatios[x].secret);
588 US_Print("% ");
589 US_PrintUnsigned(LevelRatios[x].treasure);
590 US_Print("%\n");
591 }
592 VW_UpdateScreen();
593 IN_Ack();
594 if (end == 10 && gamestate.mapon > 9)
595 {
596 start = 10; end = 20;
597 CenterWindow(17,12);
598 goto again;
599 }
600
601 return 1;
602 }
603 else if (Keyboard[sc_N]) // N = no clip
604 {
605 noclip^=1;
606 CenterWindow (18,3);
607 if (noclip)
608 US_PrintCentered ("No clipping ON");
609 else
610 US_PrintCentered ("No clipping OFF");
611 VW_UpdateScreen();
612 IN_Ack ();
613 return 1;
614 }
615 else if (Keyboard[sc_O]) // O = basic overhead
616 {
617 BasicOverhead();
618 return 1;
619 }
620 else if(Keyboard[sc_P]) // P = Ripper's picture grabber
621 {
622 PictureGrabber();
623 return 1;
624 }
625 else if (Keyboard[sc_Q]) // Q = fast quit
626 Quit (NULL);
627 else if (Keyboard[sc_S]) // S = slow motion
628 {
629 CenterWindow(30,3);
630 PrintY+=6;
631 US_Print(" Slow Motion steps (default 14): ");
632 VW_UpdateScreen();
633 esc = !US_LineInput (px,py,str,NULL,true,2,0);
634 if (!esc)
635 {
636 level = atoi (str);
637 if (level>=0 && level<=50)
638 singlestep = level;
639 }
640 return 1;
641 }
642 else if (Keyboard[sc_T]) // T = shape test
643 {
644 ShapeTest ();
645 return 1;
646 }
647 else if (Keyboard[sc_V]) // V = extra VBLs
648 {
649 CenterWindow(30,3);
650 PrintY+=6;
651 US_Print(" Add how many extra VBLs(0-8): ");
652 VW_UpdateScreen();
653 esc = !US_LineInput (px,py,str,NULL,true,1,0);
654 if (!esc)
655 {
656 level = atoi (str);
657 if (level>=0 && level<=8)
658 extravbls = level;
659 }
660 return 1;
661 }
662 else if (Keyboard[sc_W]) // W = warp to level
663 {
664 CenterWindow(26,3);
665 PrintY+=6;
666#ifndef SPEAR
667 US_Print(" Warp to which level(1-10): ");
668#else
669 US_Print(" Warp to which level(1-21): ");
670#endif
671 VW_UpdateScreen();
672 esc = !US_LineInput (px,py,str,NULL,true,2,0);
673 if (!esc)
674 {
675 level = atoi (str);
676#ifndef SPEAR
677 if (level>0 && level<11)
678#else
679 if (level>0 && level<22)
680#endif
681 {
682 gamestate.mapon = level-1;
683 playstate = ex_warped;
684 }
685 }
686 return 1;
687 }
688 else if (Keyboard[sc_X]) // X = item cheat
689 {
690 CenterWindow (12,3);
691 US_PrintCentered ("Extra stuff!");
692 VW_UpdateScreen();
693 // DEBUG: put stuff here
694 IN_Ack ();
695 return 1;
696 }
697#ifdef USE_CLOUDSKY
698 else if(Keyboard[sc_Z])
699 {
700 char defstr[15];
701
702 CenterWindow(34,4);
703 PrintY+=6;
704 US_Print(" Recalculate sky with seek: ");
705 int seekpx = px, seekpy = py;
706 US_PrintUnsigned(curSky->seed);
707 US_Print("\n Use color map (0-");
708 US_PrintUnsigned(numColorMaps - 1);
709 US_Print("): ");
710 int mappx = px, mappy = py;
711 US_PrintUnsigned(curSky->colorMapIndex);
712 VW_UpdateScreen();
713
714 sprintf(defstr, "%u", curSky->seed);
715 esc = !US_LineInput(seekpx, seekpy, str, defstr, true, 10, 0);
716 if(esc) return 0;
717 curSky->seed = (uint32_t) atoi(str);
718
719 sprintf(defstr, "%u", curSky->colorMapIndex);
720 esc = !US_LineInput(mappx, mappy, str, defstr, true, 10, 0);
721 if(esc) return 0;
722 uint32_t newInd = (uint32_t) atoi(str);
723 if(newInd < (uint32_t) numColorMaps)
724 {
725 curSky->colorMapIndex = newInd;
726 InitSky();
727 }
728 else
729 {
730 CenterWindow (18,3);
731 US_PrintCentered ("Illegal color map!");
732 VW_UpdateScreen();
733 IN_Ack ();
734 }
735 }
736#endif
737
738 return 0;
739}
740
741
742#if 0
743/*
744===================
745=
746= OverheadRefresh
747=
748===================
749*/
750
751void OverheadRefresh (void)
752{
753 unsigned x,y,endx,endy,sx,sy;
754 unsigned tile;
755
756
757 endx = maporgx+VIEWTILEX;
758 endy = maporgy+VIEWTILEY;
759
760 for (y=maporgy;y<endy;y++)
761 {
762 for (x=maporgx;x<endx;x++)
763 {
764 sx = (x-maporgx)*16;
765 sy = (y-maporgy)*16;
766
767 switch (viewtype)
768 {
769#if 0
770 case mapview:
771 tile = *(mapsegs[0]+farmapylookup[y]+x);
772 break;
773
774 case tilemapview:
775 tile = tilemap[x][y];
776 break;
777
778 case visview:
779 tile = spotvis[x][y];
780 break;
781#endif
782 case actoratview:
783 tile = (unsigned)actorat[x][y];
784 break;
785 }
786
787 if (tile<MAXWALLTILES)
788 LatchDrawTile(sx,sy,tile);
789 else
790 {
791 LatchDrawChar(sx,sy,NUMBERCHARS+((tile&0xf000)>>12));
792 LatchDrawChar(sx+8,sy,NUMBERCHARS+((tile&0x0f00)>>8));
793 LatchDrawChar(sx,sy+8,NUMBERCHARS+((tile&0x00f0)>>4));
794 LatchDrawChar(sx+8,sy+8,NUMBERCHARS+(tile&0x000f));
795 }
796 }
797 }
798}
799#endif
800
801#if 0
802/*
803===================
804=
805= ViewMap
806=
807===================
808*/
809
810void ViewMap (void)
811{
812 boolean button0held;
813
814 viewtype = actoratview;
815 // button0held = false;
816
817
818 maporgx = player->tilex - VIEWTILEX/2;
819 if (maporgx<0)
820 maporgx = 0;
821 if (maporgx>MAPSIZE-VIEWTILEX)
822 maporgx=MAPSIZE-VIEWTILEX;
823 maporgy = player->tiley - VIEWTILEY/2;
824 if (maporgy<0)
825 maporgy = 0;
826 if (maporgy>MAPSIZE-VIEWTILEY)
827 maporgy=MAPSIZE-VIEWTILEY;
828
829 do
830 {
831 //
832 // let user pan around
833 //
834 PollControls ();
835 if (controlx < 0 && maporgx>0)
836 maporgx--;
837 if (controlx > 0 && maporgx<mapwidth-VIEWTILEX)
838 maporgx++;
839 if (controly < 0 && maporgy>0)
840 maporgy--;
841 if (controly > 0 && maporgy<mapheight-VIEWTILEY)
842 maporgy++;
843
844#if 0
845 if (c.button0 && !button0held)
846 {
847 button0held = true;
848 viewtype++;
849 if (viewtype>visview)
850 viewtype = mapview;
851 }
852 if (!c.button0)
853 button0held = false;
854#endif
855
856 OverheadRefresh ();
857
858 } while (!Keyboard[sc_Escape]);
859
860 IN_ClearKeysDown ();
861}
862#endif
863#endif