forked from FlatRockSoft/Hovertank3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHOVDRAW.C
1156 lines (936 loc) · 23.8 KB
/
HOVDRAW.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Hovertank 3-D Source Code
* Copyright (C) 1993-2014 Flat Rock Software
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "HOVERDEF.H"
#pragma hdrstop
long bytecount,endcount; // for profiling
/*
============================================================================
3 - D DEFINITIONS
============================================================================
*/
fixed tileglobal = TILEGLOBAL;
fixed focallength = FOCALLENGTH;
fixed mindist = MINDIST;
int viewheight = VIEWHEIGHT;
fixed scale;
tilept tile,lasttile, // tile of wall being followed
focal, // focal point in tiles
left,mid,right; // rightmost tile in view
globpt edge,view;
int segstart[VIEWHEIGHT], // addline tracks line segment and draws
segend[VIEWHEIGHT],
segcolor[VIEWHEIGHT]; // only when the color changes
#define ADDLINE(a,b,y,c) \
{ \
if (a>segend[y]+1) \
{ \
if (y>CENTERY) \
DrawLine(segend[y]+1,a-1,y,8); \
else \
DrawLine(segend[y]+1,a-1,y,0); \
} \
DrawLine(a,a,y,0); \
if (a+1<=b) \
DrawLine(a+1,b,y,c); \
segend[y]=b; \
}
#define MAXWALLS 100
#define MIDWALL (MAXWALLS/2)
walltype walls[MAXWALLS],*leftwall,*rightwall;
//==========================================================================
//
// refresh stuff
//
//
// calculate location of screens in video memory so they have the
// maximum possible distance seperating them (for scaling overflow)
//
#define EXTRALINES (0x10000l/SCREENWIDTH-STATUSLINES-VIEWHEIGHT*3)
unsigned screenloc[3]=
{
((STATUSLINES+EXTRALINES/4)*SCREENWIDTH)&0xff00,
((STATUSLINES+EXTRALINES/2+VIEWHEIGHT)*SCREENWIDTH)&0xff00,
((STATUSLINES+3*EXTRALINES/4+2*VIEWHEIGHT)*SCREENWIDTH)&0xff00
};
int screenpage,tics;
long lasttimecount;
#define SHIFTFRAMES 256
int yshift[SHIFTFRAMES]; // screen sliding variables
unsigned slideofs;
//
// rendering stuff
//
int firstangle,lastangle;
fixed prestep;
fixed sintable[ANGLES+ANGLES/4],*costable = sintable+(ANGLES/4);
fixed viewx,viewy; // the focal point
int viewangle;
fixed viewsin,viewcos;
int zbuffer[VIEWXH+1]; // holds the height of the wall at that point
//==========================================================================
void DrawLine (int xl, int xh, int y,int color);
void DrawWall (walltype *wallptr);
void TraceRay (unsigned angle);
fixed FixedByFrac (fixed a, fixed b);
fixed FixedAdd (fixed a, fixed b);
fixed TransformX (fixed gx, fixed gy);
int FollowTrace (fixed tracex, fixed tracey, long deltax, long deltay, int max);
int BackTrace (int finish);
void ForwardTrace (void);
int TurnClockwise (void);
int TurnCounterClockwise (void);
void FollowWall (void);
void NewScene (void);
void BuildTables (void);
//==========================================================================
/*
==================
=
= DrawLine
=
= Must be in write mode 2 with all planes enabled
= The bit mask is left set to the end value, so clear it after all lines are
= drawn
=
==================
*/
unsigned char leftmask[8] = {0xff,0x7f,0x3f,0x1f,0xf,7,3,1};
unsigned char rightmask[8] = {0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
void DrawLine (int xl, int xh, int y,int color)
{
unsigned dest,xlb,xhb,maskleft,maskright,mid;
xlb=xl/8;
xhb=xh/8;
if (xh<xl)
Quit("DrawLine: xh<xl");
if (y<VIEWY)
Quit("DrawLine: y<VIEWY");
if (y>VIEWYH)
Quit("DrawLine: y>VIEWYH");
maskleft = leftmask[xl&7];
maskright = rightmask[xh&7];
mid = xhb-xlb-1;
dest = screenofs+ylookup[y]+xlb;
if (xlb==xhb)
{
//
// entire line is in one byte
//
maskleft&=maskright;
asm mov es,[screenseg]
asm mov di,[dest]
asm mov dx,GC_INDEX
asm mov al,GC_BITMASK
asm mov ah,[BYTE PTR maskleft]
asm out dx,ax // mask off pixels
asm mov al,[BYTE PTR color]
asm xchg al,[es:di] // load latches and write pixels
return;
}
asm mov es,[screenseg]
asm mov di,[dest]
asm mov dx,GC_INDEX
asm mov bh,[BYTE PTR color]
//
// draw left side
//
asm mov al,GC_BITMASK
asm mov ah,[BYTE PTR maskleft]
asm out dx,ax // mask off pixels
asm mov al,bh
asm mov bl,[es:di] // load latches
asm stosb
//
// draw middle
//
asm mov ax,GC_BITMASK + 255*256
asm out dx,ax // no masking
asm mov al,bh
asm mov cx,[mid]
asm rep stosb
//
// draw right side
//
asm mov al,GC_BITMASK
asm mov ah,[BYTE PTR maskright]
asm out dx,ax // mask off pixels
asm xchg bh,[es:di] // load latches and write pixels
}
//==========================================================================
/*
===================
=
= DrawWall
=
= Special polygon with vertical edges and symetrical top / bottom
= Clips horizontally to clipleft/clipright
= Clips vertically to VIEWY/VIEWYH
= Should only be called if the wall is at least partially visable
=
==================
*/
void DrawWall (walltype *wallptr)
{
walltype static wall;
int static y1l,y1h,y2l,y2h;
int i;
unsigned leftheight,rightheight;
long height,heightstep;
int temp,insight,x,y,slope,endfrac,end;
int start,ysteps,left,right;
wall = *wallptr;
i = wall.height1/2;
y1l = CENTERY-i;
y1h = CENTERY+i;
i = wall.height2/2;
y2l = CENTERY-i;
y2h = CENTERY+i;
if (wall.x1>wall.leftclip)
wall.leftclip = wall.x1;
if (wall.x2<wall.rightclip)
wall.rightclip = wall.x2;
//
// fill in the zbuffer
//
height = (long)wall.height1<<16;
if (wall.x2 != wall.x1)
heightstep = ((long)(wall.height2-wall.height1)<<16)/(int)(wall.x2-wall.x1);
else
heightstep = 0;
i = wall.leftclip-wall.x1;
if (i)
height += heightstep*i; // adjust for clipped area
for (x=wall.leftclip;x<=wall.rightclip;x++)
{
zbuffer[x] = height>>16;
height+=heightstep;
}
//
// draw the wall to the line buffer
//
if (y1l==y2l)
{
//
// rectangle, no slope
//
if (y1l<VIEWY)
y1l=VIEWY;
if (y1h>VIEWYH)
y1h=VIEWYH;
for (y=y1l;y<=y1h;y++)
ADDLINE(wall.leftclip,wall.rightclip,y,wall.color);
return;
}
if (y1l<y2l)
{
//
// slopes down to the right
//
slope = ((long)(wall.x2-wall.x1)<<6)/(y2l-y1l); // in 128ths
ysteps = y2l-y1l;
if (y1l<VIEWY)
ysteps -= VIEWY-y1l;
endfrac = wall.x2<<6;
for (y=1;y<ysteps;y++) // top and bottom slopes
{
endfrac-=slope;
end=endfrac>>6;
if (end>wall.rightclip)
end=wall.rightclip;
else
if (end<wall.leftclip) // the rest is hidden
break;
ADDLINE(wall.leftclip,end,y2l-y,wall.color);
ADDLINE(wall.leftclip,end,y2h+y,wall.color);
}
if (y2l<VIEWY)
y2l=VIEWY;
if (y2h>VIEWYH)
y2h=VIEWYH;
for (y=y2l;y<=y2h;y++) // middle
ADDLINE(wall.leftclip,wall.rightclip,y,wall.color);
}
else
{
//
// slopes down to the left
//
slope = ((long)(wall.x2-wall.x1)<<6)/(y1l-y2l); // in 128ths
ysteps = y1l-y2l;
if (y2l<VIEWY)
ysteps -= VIEWY-y2l;
endfrac = wall.x1<<6;
for (y=1;y<ysteps;y++) // top and bottom slopes
{
endfrac+=slope;
end=endfrac>>6;
if (end<wall.leftclip)
end=wall.leftclip;
else
if (end>wall.rightclip) // the rest is hidden
break;
ADDLINE(end,wall.rightclip,y1l-y,wall.color);
ADDLINE(end,wall.rightclip,y1h+y,wall.color);
}
if (y1l<VIEWY)
y1l=VIEWY;
if (y1h>VIEWYH)
y1h=VIEWYH;
for (y=y1l;y<=y1h;y++) // middle
ADDLINE(wall.leftclip,wall.rightclip,y,wall.color);
}
}
//==========================================================================
/*
=================
=
= TraceRay
=
= Used to find the left and rightmost tile in the view area to be traced from
= Follows a ray of the given angle from viewx,viewy in the global map until
= it hits a solid tile
= sets:
= tile.x,tile.y : tile coordinates of contacted tile
= tilecolor : solid tile's color
=
==================
*/
int tilecolor;
void TraceRay (unsigned angle)
{
long tracex,tracey,tracexstep,traceystep,searchx,searchy;
fixed fixtemp;
int otx,oty,searchsteps;
tracexstep = costable[angle];
traceystep = sintable[angle];
//
// advance point so it is even with the view plane before we start checking
//
fixtemp = FixedByFrac(prestep,tracexstep);
tracex = FixedAdd (viewx,fixtemp);
fixtemp = FixedByFrac(prestep,traceystep);
tracey = FixedAdd (viewy,fixtemp^SIGNBIT);
if (tracexstep&SIGNBIT) // use 2's complement, not signed magnitude
tracexstep = -(tracexstep&~SIGNBIT);
if (traceystep&SIGNBIT) // use 2's complement, not signed magnitude
traceystep = -(traceystep&~SIGNBIT);
tile.x = tracex>>TILESHIFT; // starting point in tiles
tile.y = tracey>>TILESHIFT;
//
// we assume viewx,viewy is not inside a solid tile, so go ahead one step
//
do // until a solid tile is hit
{
otx = tile.x;
oty = tile.y;
tracex += tracexstep;
tracey -= traceystep;
tile.x = tracex>>TILESHIFT;
tile.y = tracey>>TILESHIFT;
if (tile.x!=otx && tile.y!=oty && (tilemap[otx][tile.y] || tilemap[tile.x][oty]) )
{
//
// trace crossed two solid tiles, so do a binary search along the line
// to find a spot where only one tile edge is crossed
//
searchsteps = 0;
searchx = tracexstep;
searchy = traceystep;
do
{
searchx/=2;
searchy/=2;
if (tile.x!=otx && tile.y!=oty)
{
// still too far
tracex -= searchx;
tracey += searchy;
}
else
{
// not far enough, no tiles crossed
tracex += searchx;
tracey -= searchy;
}
//
// if it is REAL close, go for the most clockwise intersection
//
if (++searchsteps == 16)
{
tracex = (long)otx<<TILESHIFT;
tracey = (long)oty<<TILESHIFT;
if (tracexstep>0)
{
if (traceystep<0)
{
tracex += TILEGLOBAL-1;
tracey += TILEGLOBAL;
}
else
{
tracex += TILEGLOBAL;
}
}
else
{
if (traceystep<0)
{
tracex --;
tracey += TILEGLOBAL-1;
}
else
{
tracey --;
}
}
}
tile.x = tracex>>TILESHIFT;
tile.y = tracey>>TILESHIFT;
} while (( tile.x!=otx && tile.y!=oty) || (tile.x==otx && tile.y==oty) );
}
} while (!(tilecolor = tilemap[tile.x][tile.y]) );
}
//==========================================================================
/*
========================
=
= FixedByFrac
=
= multiply a 16/16 bit fixed point number by a 16 bit fractional number
= both unsigned (handle signs seperately)
=
========================
*/
fixed FixedByFrac (fixed a, fixed b)
{
fixed value;
asm mov si,[WORD PTR a+2]
asm xor si,[WORD PTR b+2]
asm and si,0x8000 // si is high word of result (sign bit)
asm mov bx,[WORD PTR b]
asm mov ax,[WORD PTR a]
asm mul bx // fraction*fraction
asm mov di,dx // di is low word of result
asm mov ax,[WORD PTR a+2]
asm and ax,0x7fff // strip sign bit
asm mul bx // units*fraction
asm add ax,di
asm adc dx,0
asm or dx,si
asm mov [WORD PTR value],ax
asm mov [WORD PTR value+2],dx
return value;
}
/*
=========================
=
= FixedAdd
=
= add two 16 bit fixed point numbers
= to subtract, invert the sign of B before invoking
=
=========================
*/
fixed FixedAdd (fixed a, fixed b)
{
fixed value;
asm mov ax,[WORD PTR a]
asm mov dx,[WORD PTR a+2]
asm mov bx,[WORD PTR b]
asm mov cx,[WORD PTR b+2]
asm or dx,dx
asm jns aok: // negative?
asm and dx,0x7fff
asm not ax // convert a from signed magnitude to 2's compl
asm not dx
asm add ax,1
asm adc dx,0
aok:
asm or cx,cx
asm jns bok: // negative?
asm and cx,0x7fff
asm not bx // convert b from signed magnitude to 2's compl
asm not cx
asm add bx,1
asm adc cx,0
bok:
asm add ax,bx // perform the addition
asm adc dx,cx
asm jns done
asm and dx,0x7fff // value was negative
asm not ax // back to signed magnitude
asm not dx
asm add ax,1
asm adc dx,0
done:
asm mov [WORD PTR value],ax
asm mov [WORD PTR value+2],dx
return value;
}
//==========================================================================
/*
========================
=
= TransformPoint
=
= Takes paramaters:
= gx,gy : globalx/globaly of point
=
= globals:
= viewx,viewy : point of view
= viewcos,viewsin : sin/cos of viewangle
=
=
= defines:
= CENTERX : pixel location of center of view window
= TILEGLOBAL : size of one
= FOCALLENGTH : distance behind viewx/y for center of projection
= scale : conversion from global value to screen value
=
= returns:
= screenx,screenheight: projected edge location and size
=
========================
*/
#define MINRATIO 16
void TransformPoint (fixed gx, fixed gy, int *screenx, unsigned *screenheight)
{
int ratio;
fixed gxt,gyt,nx,ny;
//
// translate point to view centered coordinates
//
gx = FixedAdd(gx,viewx|SIGNBIT);
gy = FixedAdd(gy,viewy|SIGNBIT);
//
// calculate newx
//
gxt = FixedByFrac(gx,viewcos);
gyt = FixedByFrac(gy,viewsin);
nx = FixedAdd(gxt,gyt^SIGNBIT);
//
// calculate newy
//
gxt = FixedByFrac(gx,viewsin);
gyt = FixedByFrac(gy,viewcos);
ny = FixedAdd(gyt,gxt);
//
// calculate perspective ratio
//
if (nx<0)
nx = 0;
ratio = nx*scale/FOCALLENGTH;
if (ratio<=MINRATIO)
ratio = MINRATIO;
if (ny & SIGNBIT)
*screenx = CENTERX - (ny&~SIGNBIT)/ratio;
else
*screenx = CENTERX + ny/ratio;
*screenheight = TILEGLOBAL/ratio;
}
//==========================================================================
fixed TransformX (fixed gx, fixed gy)
{
int ratio;
fixed gxt,gyt,nx,ny;
//
// translate point to view centered coordinates
//
gx = FixedAdd(gx,viewx|SIGNBIT);
gy = FixedAdd(gy,viewy|SIGNBIT);
//
// calculate newx
//
gxt = FixedByFrac(gx,viewcos);
gyt = FixedByFrac(gy,viewsin);
return FixedAdd(gxt,gyt^SIGNBIT);
}
//==========================================================================
/*
==================
=
= BuildTables
=
= Calculates:
=
= scale projection constant
= sintable/costable overlapping fractional tables
= firstangle/lastangle angles from focalpoint to left/right view edges
= prestep distance from focal point before checking for tiles
= yshift[] screen bouncing patters
=
==================
*/
#define PI 3.141592657
#define ANGLEQUAD (ANGLES/4)
void BuildTables (void)
{
int i,intang;
float angle,anglestep;
fixed value;
//
// calculate scale value so one tile at mindist allmost fills the view vertical
//
scale = GLOBAL1/VIEWWIDTH; // GLOBALVIEWHEIGHT/viewheight;
scale *= focallength;
scale /= (focallength+mindist);
//
// costable overlays sintable with a quarter phase shift
// ANGLES is assumed to be divisable by four
//
angle = 0;
anglestep = PI/2/ANGLEQUAD;
for (i=0;i<=ANGLEQUAD;i++)
{
value=GLOBAL1*sin(angle);
sintable[i]=
sintable[i+ANGLES]=
sintable[ANGLES/2-i] = value;
sintable[ANGLES-i]=
sintable[ANGLES/2+i] = value | SIGNBIT;
angle += anglestep;
}
//
// figure trace angles for first and last pixel on screen
//
angle = atan((float)VIEWWIDTH/2*scale/FOCALLENGTH);
angle *= ANGLES/(PI*2);
intang = (int)angle+1;
firstangle = intang;
lastangle = -intang;
prestep = GLOBAL1*((float)FOCALLENGTH/costable[firstangle]);
//
// hover screen shifting
//
for (i=0;i<SHIFTFRAMES;i++)
{
angle = (long)ANGLES*i/SHIFTFRAMES;
value = FixedByFrac(7*GLOBAL1,sintable[angle]);
yshift[i] = SCREENWIDTH*(FixedAdd(value,8*GLOBAL1)>>16);
}
//
// misc stuff
//
walls[0].x2 = VIEWX-1;
walls[0].height2 = 32000;
}
//==========================================================================
/*
=================
=
= StartView
=
= Called by player think
=
=================
*/
void StartView (void)
{
int tracedir;
//
// set up variables for this view
//
viewangle = objlist[0].angle;
viewsin = sintable[viewangle];
viewcos = costable[viewangle];
viewx = FixedAdd( objlist[0].x,FixedByFrac(FOCALLENGTH,viewcos)^SIGNBIT );
viewy = FixedAdd( objlist[0].y,FixedByFrac(FOCALLENGTH,viewsin) );
focal.x = viewx>>TILESHIFT;
focal.y = viewy>>TILESHIFT;
//
// find the rightmost visable tile in view
//
tracedir = viewangle + lastangle;
if (tracedir<0)
tracedir+=ANGLES;
else if (tracedir>=ANGLES)
tracedir-=ANGLES;
TraceRay( tracedir );
right.x = tile.x;
right.y = tile.y;
//
// find the leftmost visable tile in view
//
tracedir = viewangle + firstangle;
if (tracedir<0)
tracedir+=ANGLES;
else if (tracedir>=ANGLES)
tracedir-=ANGLES;
TraceRay( tracedir );
//
// follow the walls from there to the right
//
rightwall = &walls[1];
FollowWalls ();
}
//==========================================================================
/*
=====================
=
= DrawWallList
=
= Clips and draws all the walls traced this refresh
=
=====================
*/
void DrawWallList (void)
{
int i,leftx,newleft,rightclip;
walltype *wall, *check;
memset(segstart,0,sizeof(segstart)); // start lines at 0
memset(segend,0xff,sizeof(segend)); // end lines at -1
memset(segcolor,0xff,sizeof(segcolor)); // with color -1
rightwall->x1 = VIEWXH+1;
rightwall->height1 = 32000;
(rightwall+1)->x1 = 32000;
leftx = -1;
for (wall=&walls[1];wall<rightwall && leftx<=VIEWXH ;wall++)
{
if (leftx >= wall->x2)
continue;
rightclip = wall->x2;
check = wall+1;
while (check->x1 <= rightclip && check->height1 >= wall->height2)
{
rightclip = check->x1-1;
check++;
}
if (rightclip>VIEWXH)
rightclip=VIEWXH;
if (leftx < wall->x1 - 1)
newleft = wall->x1-1; // there was black space between walls
else
newleft = leftx;
if (rightclip > newleft)
{
wall->leftclip = newleft+1;
wall->rightclip = rightclip;
DrawWall (wall);
leftx = rightclip;
}
}
//
// finish all lines to the right edge
//
for (i=0;i<CENTERY;i++)
if (segend[i]<VIEWXH)
DrawLine(segend[i]+1,VIEWXH,i,0);
for (;i<VIEWHEIGHT;i++)
if (segend[i]<VIEWXH)
DrawLine(segend[i]+1,VIEWXH,i,8);
}
//==========================================================================
/*
=====================
=
= DrawScaleds
=
= Draws all objects that are visable
=
=====================
*/
int depthsort[MAXOBJECTS],
sortheight[MAXOBJECTS],
obscreenx[MAXOBJECTS],
obscreenheight[MAXOBJECTS],
obshapenum[MAXOBJECTS];
void DrawScaleds (void)
{
int i,j,least,leastnum,screenx,numvisable;
unsigned ratio,screenratio,scaleratio,screenheight;
fixed viewx;
objtype *obj;
numvisable = 0;
//
// calculate base positions of all objects
//
for (obj = &objlist[1];obj<=lastobj;obj++)
if (obj->class)
{
viewx = obj->viewx - obj->size; // now value of nearest edge
if (viewx >= FOCALLENGTH+MINDIST)
{
ratio = viewx*scale/FOCALLENGTH;
screenx = CENTERX + obj->viewy/ratio;
screenheight = TILEGLOBAL/ratio;
if (screenx > -128 && screenx < 320+128)
{
obscreenx[numvisable] = screenx;
obscreenheight[numvisable] = screenheight;
obshapenum[numvisable] = obj->shapenum;
numvisable++;
}
}
}
if (!numvisable)
return;
//
// sort in order of increasing height
//
for (i=0;i<numvisable;i++)
{
least = 32000;
for (j=0;j<numvisable;j++)
if (obscreenheight[j] < least)
{
leastnum = j;
least = obscreenheight[j];
}
depthsort[i] = leastnum;
sortheight[i] = least;
obscreenheight[leastnum] = 32000;
}
//
// draw in order
//
for (i=0;i<numvisable;i++)
{
j = depthsort[i];
SC_ScaleShape(obscreenx[j],CENTERY+5,sortheight[i]
,scalesegs[obshapenum[j]]);
}
}
//==========================================================================
/*
====================
=
= DrawCrossHairs
=
= Should still be in write mode 2
=