-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathACKFLOOR.C
1245 lines (1095 loc) · 40.3 KB
/
ACKFLOOR.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
// This source file contains the functions needed to process floors.
// (c) 1995 ACK Software (Lary Myers)
//#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
//#include <conio.h>
//#include <dos.h>
//#include <mem.h>
//#include <io.h>
//#include <fcntl.h>
#include <time.h>
#include <string.h>
//#include <sys\stat.h>
#include <limits.h>
#include "ACK3D.H"
#include "ACKENG.H"
#include "ACKEXT.H"
#define MAX_F_VIEWHALFHEIGHT 50
extern int32_t FloorCosTable[];
extern short gWinStartX;
extern short gWinStartY;
extern short gWinEndX;
extern short gWinHalfHeight;
extern UCHAR *gScrnBufferCenter;
extern UCHAR *gScrnBuffer;
extern int32_t WallDistTable[];
extern ACKENG* ae;//MEH
int32_t zdTable[VIEW_WIDTH][50];
int32_t mFactor;
int32_t dFactor;
//------------------------------------------------------------------------
// Internal function called during the initialize process to setup the
// floor and light shading arrays.
//------------------------------------------------------------------------
void SetupFloors(ACKENG *ae)
{
short i;//,a;
int ht,scanline;//,ht1;
int Scale_Fac;
int32_t scan2,f;
//int32_t x,y,dist;
//int32_t Lastx,Lasty;
for ( i=0; i<12;i++ ) scantables[i] = (char*)ae->PalTable + (7*256);
for ( i=12;i<24;i++ ) scantables[i] = (char*)ae->PalTable + (6*256);
for ( i=24;i<36;i++ ) scantables[i] = (char*)ae->PalTable + (5*256);
for ( i=36;i<48;i++ ) scantables[i] = (char*)ae->PalTable + (4*256);
for ( i=48;i<60;i++ ) scantables[i] = (char*)ae->PalTable + (3*256);
for ( i=60;i<72;i++ ) scantables[i] = (char*)ae->PalTable + (2*256);
for ( i=72;i<84;i++ ) scantables[i] = (char*)ae->PalTable + (1*256);
for ( i=84;i<96;i++ ) scantables[i] = (char*)ae->PalTable;
Scale_Fac = (ae->PlayerHeight - ViewHeight) * 5;
ht = ae->PlayerHeight - ViewHeight;
ht *= Scale_Fac;
for (i = 0; i < VIEW_WIDTH; i++)
{
f = FloorCosTable[i];
zdTable[i][0] = 0;
for (scanline = 1; scanline < MAX_F_VIEWHALFHEIGHT; scanline++)
{
scan2 = ht / scanline;
zdTable[i][scanline] = (f * scan2) >> 15;
if (zdTable[i][scanline-1] < zdTable[i][scanline])
zdTable[i][scanline-1] = zdTable[i][scanline];
}
}
// Some debugging values for internal use
mFactor = 10368;
dFactor = 160;
}
// Optimization attempts were made with drawing the rotating background
// as the ceiling was being drawn and drawing the entire background before
// drawing any ceiling tiles or walls. The former seemed to be faster
// in most cases, so the define below was used to toggle between the two
// methods.
#define DRAW_BACK 1
//------------------------------------------------------------------------
// Draws the floor and ceiling horizontally.
//------------------------------------------------------------------------
void AckDrawFloorHz(void)
{
int col,row,ht,Rcol,EndCol,BegCol;
int Scale_Fac,ScaleHt;
UCHAR *scr,*fscr,*bmp,*scrCeil,*cscr;
//UCHAR *Rscr,*Rfscr,*RscrCeil,*Rcscr;
UCHAR *ba,*ba1;//,*Rba1;
short va;//,va1;
int32_t LastDist,scan2;
int32_t cv,sv,dist,x,y,mPos,bPos,wdist,bcol;
//int32_t Rbcol,Rwdist,xp,yp;
int32_t *wPtr,*RwPtr;
int32_t fcv;
UCHAR ch;
USHORT bCode;
#if !(DRAW_BACK)
DrawBackDrop(); // Draw entire background
#endif
BegCol = gWinStartX;
EndCol = gWinEndX;
// Get the starting offset of the center row of the view
scr = gScrnBufferCenter + BegCol;
// Get the left side of the POV view
va = PlayerAngle - INT_ANGLE_32;
// Check for wrap-around
if (va < 0) va += INT_ANGLE_360;
// Adjust the viewing angle based on the starting view column
va += BegCol;
// and check for wrap-around
if (va >= INT_ANGLE_360)
va -= INT_ANGLE_360;
// Get the starting column for the background, there are 640
// columns possible, so the remainder when we divide is where
// we want to begin displaying
bcol = va % 640;
// Temporarily hold onto the view height / 2
ht = gWinHalfHeight;
// Since our horizon should always have some form of wall or object,
// no matter how far away it is, we can optimize a little here by not
// drawing the first few horizon rows (it does actually save time!).
// Start 5 video rows above the center row
scrCeil = scr;// - 320;//1600;
// Start 6 video rows below the center row
//scr += 1920;
// Initial right side of view
Rcol = 319;
wPtr = &WallDistTable[BegCol]; // Get pointers to avoid indexing
RwPtr = &WallDistTable[Rcol];
// The ScaleHt is used to determine the distance from the player for each
// row of the floor and ceiling. The value 89 was arrived at based on a
// reasonable height above the floor that the player is standing. By
// experimenting with this value, the effect of jumping up and down can
// be achieved, (as int32_t as the walls and objects are made to jump by the
// same amount).
Scale_Fac = (ae->PlayerHeight - ViewHeight) * 5;
ScaleHt = ae->PlayerHeight - ViewHeight;
ScaleHt *= Scale_Fac;
// Here we loop through each column of the viewing window
for (col = BegCol; col < EndCol; col ++)//= 2)
{
// printf("In AckDrawFloorHz() loop %d\n", col);
// Pick up the cosine and sine values for the current angle
cv = CosTable[va];
sv = SinTable[va];
// Point to the left side of the current floor and ceiling columns
fscr = scr;
cscr = scrCeil;
// Advance the columns for the next pass
scr ++;//= 2;
scrCeil ++;//= 2;
// Pick up the current distance to the wall that was found for the
// current column
wdist = *wPtr;
// Advance the wall distance pointer for the next pass
wPtr ++;//= 2;
#if DRAW_BACK
// Pick up the pointer to the background image for the current column
ba = BackArray[bcol++];
// Check for wrap-around in our 640 column image
if (bcol > 639) bcol = 0;
// Pick up the next column as well since the floor and ceiling are
// always done in low resolution
// ba1 = BackArray[bcol++];
if (bcol > 639) bcol = 0;
ba += ht;
//ba1 += ht;
#endif
// Initialize a last distance variable
LastDist = -1;
// Our floor cosine is used to counteract a fisheye effect
fcv = FloorCosTable[col];
for (row = 1; row <= ht; row++)
{
scan2 = ScaleHt / row;
// Get the distance for the current column and row position
dist = (fcv * scan2) >> 15;
// If we're still closer than any wall
if (dist < wdist)
{
// Do some extra calculations if it's a new distance from last time
// (Sometimes our distance works out to be the same so we can avoid
// the next few lines)
if (dist != LastDist)
{
x = xPglobal + ((cv * dist) >> 16);
y = yPglobal + ((sv * dist) >> 16);
LastDist = dist;
}
mPos = (y & 0xFC0) + (x >> 6); // Calc the Map Posn
if (mPos < 0L || mPos > 4095L)
continue;
bPos = (y & 63) + ((x & 63)<<6); // Calc the Bitmap Pixel
// Get the bitmap number for our floor
bCode = FloorMap[mPos];
// And use it to pull the actual bitmap from our array of wall bitmaps
bmp = WallbMaps[bCode];
// Make sure it's really a bitmap and then get the actual pixel to display
if (bmp != NULL)
ch = bmp[bPos];
// Place the pixel in this column as well as the next. Since we have a
// scattering effect we can display in low resolution without too much
// loss in detail. This really speeds up the drawing of the floor and
// ceiling.
// printf("screen buffer: %d\n", (int)(gScrnBuffer));
*fscr = ch; // Put it into two locations
//fscr[1] = ch; // for low resolution
// Only draw a ceiling pixel if there is a ceiling tile placed in the map
// This gives the effect of seeing the background through holes in the ceiling
if ((bCode = CeilMap[mPos]) != 0)
{
bmp = WallbMaps[bCode];
if (bmp != NULL)
ch = bmp[bPos];
*cscr = ch;
//cscr[1] = ch;
}
#if DRAW_BACK
// If no ceiling is drawn, then we need to draw the background image
else
{
*cscr = *ba;
//cscr[1] = *ba1;
}
#endif
}
fscr += 320; // Advance our screen position for the floor
cscr -= 320; // and the ceiling
#if DRAW_BACK
// Advance the pointers to the background image for the next pass
ba--;
ba1--;
#endif
}
// Advance our current viewing angle by 2 since we are in low resolution
va ++;//= 2;
// and check for wrap-around
if (va >= INT_ANGLE_360) va -= INT_ANGLE_360;
}
}
//------------------------------------------------------------------------
// Draws the floor and ceiling horizontally. MEH-deprecated
//------------------------------------------------------------------------
/*void AckDrawCeilingOnlyNS(void)
{
int col,row,ht,Rcol,EndCol,BegCol;
int Scale_Fac,ScaleHt;
UCHAR *scr,*bmp,*scrCeil,*cscr;
UCHAR *ba,*ba1;
short va;
int32_t LastDist,scan2;
int32_t cv,sv,dist,x,y,mPos,bPos,wdist,bcol;
int32_t *wPtr,*RwPtr;
int32_t fcv;
UCHAR ch;
USHORT bCode;
#if !(DRAW_BACK)
DrawBackDrop(); // Draw entire background
#endif
BegCol = gWinStartX;
EndCol = gWinEndX;
// Get the starting offset of the center row of the view
scr = gScrnBufferCenter + BegCol;
// Get the left side of the POV view
va = PlayerAngle - INT_ANGLE_32;
// Check for wrap-around
if (va < 0) va += INT_ANGLE_360;
// Adjust the viewing angle based on the starting view column
va += BegCol;
// and check for wrap-around
if (va >= INT_ANGLE_360)
va -= INT_ANGLE_360;
// Get the starting column for the background, there are 640
// columns possible, so the remainder when we divide is where
// we want to begin displaying
bcol = va % 640;
// Temporarily hold onto the view height / 2
ht = gWinHalfHeight;
// Since our horizon should always have some form of wall or object,
// no matter how far away it is, we can optimize alittle here by not
// drawing the first few horizon rows (it does actually save time!).
// Start 5 video rows above the center row
scrCeil = scr - 1600;
// Initial right side of view
Rcol = 319;
wPtr = &WallDistTable[BegCol]; // Get pointers to avoid indexing
RwPtr = &WallDistTable[Rcol];
// The ScaleHt is used to determine the distance from the player for each
// row of the floor and ceiling. The value 89 was arrived at based on a
// reasonable height above the floor that the player is standing. By
// experimenting with this value, the effect of jumping up and down can
// be achieved, (as int32_t as the walls and objects are made to jump by the
// same amount).
Scale_Fac = (ae->PlayerHeight - ViewHeight) * 5;
ScaleHt = ae->PlayerHeight - ViewHeight;
ScaleHt *= Scale_Fac;
// Here we loop through each column of the viewing window
for (col = BegCol; col < EndCol; col ++)//= 2)
{
// Pick up the cosine and sine values for the current angle
cv = CosTable[va];
sv = SinTable[va];
// Point to the left side of the current ceiling columns
cscr = scrCeil;
// Advance the columns for the next pass
scrCeil ++;//= 2;
// Pick up the current distance to the wall that was found for the
// current column
wdist = *wPtr;
// Advance the wall distance pointer for the next pass
wPtr ++;//= 2;
#if DRAW_BACK
// Pick up the pointer to the background image for the current column
ba = BackArray[bcol++];
// Check for wrap-around in our 640 column image
if (bcol > 639) bcol = 0;
// Pick up the next column as well since the floor and ceiling are
// always done in low resolution
//ba1 = BackArray[bcol++];
if (bcol > 639) bcol = 0;
ba += ht;
//ba1 += ht;
#endif
// Initialize a last distance variable
LastDist = -1;
// Our floor cosine is used to counteract a fisheye effect
fcv = FloorCosTable[col];
for (row = 6; row <= ht; row++)
{
scan2 = ScaleHt / row;
// Get the distance for the current column and row position
dist = (fcv * scan2) >> 15;
// If we're still closer than any wall
if (dist < wdist)
{
// Do some extra calculations if it's a new distance from last time
// (Sometimes our distance works out to be the same so we can avoid
// the next few lines)
if (dist != LastDist)
{
x = xPglobal + ((cv * dist) >> 16);
y = yPglobal + ((sv * dist) >> 16);
LastDist = dist;
}
mPos = (y & 0xFC0) + (x >> 6); // Calc the Map Posn
if (mPos < 0L || mPos > 4095L)
continue;
bPos = (y & 63) + ((x & 63)<<6); // Calc the Bitmap Pixel
// Only draw a ceiling pixel if there is a ceiling tile placed in the map
// This gives the effect of seeing the background through holes in the ceiling
if ((bCode = CeilMap[mPos]) != 0)
{
bmp = WallbMaps[bCode];
if (bmp != NULL)
ch = bmp[bPos];
*cscr = ch;
//cscr[1] = ch;
}
#if DRAW_BACK
// If no ceiling is drawn, then we need to draw the background image
else
{
*cscr = *ba;
//cscr[1] = *ba1;
}
#endif
}
cscr -= 320; // and the ceiling
#if DRAW_BACK
// Advance the pointers to the background image for the next pass
ba--;
ba1--;
#endif
}
// Advance our current viewing angle by 2 since we are in low resolution
va ++;//= 2;
// and check for wrap-around
if (va >= INT_ANGLE_360) va -= INT_ANGLE_360;
}
}
*/
//------------------------------------------------------------------------
// Draws the floor and ceiling horizontally.
//------------------------------------------------------------------------
//MEH Deprecated
/*void AckDrawFloorOnlyNS(void)
{
int col,row,ht,Rcol,EndCol,BegCol;
int Scale_Fac,ScaleHt;
UCHAR *scr,*fscr,*bmp;
//UCHAR *Rfscr,*RscrCeil,*Rcscr;
UCHAR *ba,*ba1;//,*Rba,*Rba1;
short va;//,va1;
int32_t LastDist,scan2;
int32_t cv,sv,dist,x,y,mPos,bPos,wdist,bcol;
//int32_t Rbcol,Rwdist,xp,yp;
int32_t *wPtr,*RwPtr;
int32_t fcv;
UCHAR ch;
USHORT bCode;
#if !(DRAW_BACK)
DrawBackDrop(); // Draw entire background
#endif
BegCol = gWinStartX;
EndCol = gWinEndX;
// Get the starting offset of the center row of the view
scr = gScrnBufferCenter + BegCol;
// Get the left side of the POV view
va = PlayerAngle - INT_ANGLE_32;
// Check for wrap-around
if (va < 0) va += INT_ANGLE_360;
// Adjust the viewing angle based on the starting view column
va += BegCol;
// and check for wrap-around
if (va >= INT_ANGLE_360)
va -= INT_ANGLE_360;
// Get the starting column for the background, there are 640
// columns possible, so the remainder when we divide is where
// we want to begin displaying
bcol = va % 640;
// Temporarily hold onto the view height / 2
ht = gWinHalfHeight;
// Since our horizon should always have some form of wall or object,
// no matter how far away it is, we can optimize alittle here by not
// drawing the first few horizon rows (it does actually save time!).
// Start 6 video rows below the center row
scr += 1920;
// Initial right side of view
Rcol = 319;
wPtr = &WallDistTable[BegCol]; // Get pointers to avoid indexing
RwPtr = &WallDistTable[Rcol];
// The ScaleHt is used to determine the distance from the player for each
// row of the floor and ceiling. The value 89 was arrived at based on a
// reasonable height above the floor that the player is standing. By
// experimenting with this value, the effect of jumping up and down can
// be achieved, (as int32_t as the walls and objects are made to jump by the
// same amount).
Scale_Fac = (ae->PlayerHeight - ViewHeight) * 5;
ScaleHt = ae->PlayerHeight - ViewHeight;
ScaleHt *= Scale_Fac;
// Here we loop through each column of the viewing window
for (col = BegCol; col < EndCol; col ++)//= 2)
{
// Pick up the cosine and sine values for the current angle
cv = CosTable[va];
sv = SinTable[va];
// Point to the left side of the current floor and ceiling columns
fscr = scr;
// Advance the columns for the next pass
scr ++;//= 2;
// Pick up the current distance to the wall that was found for the
// current column
wdist = *wPtr;
// Advance the wall distance pointer for the next pass
wPtr ++;//= 2;
#if DRAW_BACK
// Pick up the pointer to the background image for the current column
ba = BackArray[bcol++];
// Check for wrap-around in our 640 column image
if (bcol > 639) bcol = 0;
// Pick up the next column as well since the floor and ceiling are
// always done in low resolution
// ba1 = BackArray[bcol++];
if (bcol > 639) bcol = 0;
ba += ht;
// ba1 += ht;
#endif
// Initialize a last distance variable
LastDist = -1;
// Our floor cosine is used to counteract a fisheye effect
fcv = FloorCosTable[col];
for (row = 6; row <= ht; row++)
{
scan2 = ScaleHt / row;
// Get the distance for the current column and row position
dist = (fcv * scan2) >> 15;
// If we're still closer than any wall
if (dist < wdist)
{
// Do some extra calculations if it's a new distance from last time
// (Sometimes our distance works out to be the same so we can avoid
// the next few lines)
if (dist != LastDist)
{
x = xPglobal + ((cv * dist) >> 16);
y = yPglobal + ((sv * dist) >> 16);
LastDist = dist;
}
mPos = (y & 0xFC0) + (x >> 6); // Calc the Map Posn
if (mPos < 0L || mPos > 4095L)
continue;
bPos = (y & 63) + ((x & 63)<<6); // Calc the Bitmap Pixel
// Get the bitmap number for our floor
bCode = FloorMap[mPos];
// And use it to pull the actual bitmap from our array of wall bitmaps
bmp = WallbMaps[bCode];
// Make sure it's really a bitmap and then get the actual pixel to display
if (bmp != NULL)
ch = bmp[bPos];
// Place the pixel in this column as well as the next. Since we have a
// scattering effect we can display in low resolution without too much
// loss in detail. This really speeds up the drawing of the floor and
// ceiling.
*fscr = ch; // Put it into two locations
//fscr[1] = ch; // for low resolution
}
fscr += 320; // Advance our screen position for the floor
#if DRAW_BACK
// Advance the pointers to the background image for the next pass
ba--;
ba1--;
#endif
}
// Advance our current viewing angle by 2 since we are in low resolution
va ++;//= 2;
// and check for wrap-around
if (va >= INT_ANGLE_360) va -= INT_ANGLE_360;
}
}
*/
//------------------------------------------------------------------------
// The function performs the same process as AckDrawFloorHz except here
// we include light shading with distance.
//------------------------------------------------------------------------
void AckDrawFloor(void)
{
int col,row,ht,Rcol,EndCol,BegCol;
int Scale_Fac,ScaleHt;
UCHAR *scr,*fscr,*bmp,*scrCeil,*cscr;
// UCHAR *Rscr,*Rfscr,*RscrCeil,*Rcscr;
UCHAR *ba,*ba1;//,*Rba,*Rba1;
char *stPtr;
short va,LineNum;
int32_t LastDist,scan2;
int32_t cv,sv,dist,x,y,mPos,bPos,wdist,bcol;
// int32_t Rbcol,Rwdist,xp,yp;
int32_t *wPtr,*RwPtr;
int32_t fcv;
UCHAR ch;
USHORT bCode;
#if !(DRAW_BACK)
DrawBackDrop(); // Draw entire background
#endif
BegCol = gWinStartX;
EndCol = gWinEndX;
// Get the starting offset of the center row of the view
scr = gScrnBufferCenter + BegCol;
// Get the left side of the POV view
va = PlayerAngle - INT_ANGLE_32;
// Check for wrap-around
if (va < 0) va += INT_ANGLE_360;
// Adjust the viewing angle based on the starting view column
va += BegCol;
// and check for wrap-around
if (va >= INT_ANGLE_360)
va -= INT_ANGLE_360;
// Get the starting column for the background, there are 640
// columns possible, so the remainder when we divide is where
// we want to begin displaying
bcol = va % 640;
// Temporarily hold onto the view height / 2
ht = gWinHalfHeight;
// Since our horizon should always have some form of wall or object,
// no matter how far away it is, we can optimize a little here by not
// drawing the first few horizon rows (it does actually save time!).
// Start 5 video rows above the center row
scrCeil = scr;// - 1600;
// Start 6 video rows below the center row
//scr += 320;
// Initial right side of view
Rcol = 319;
wPtr = &WallDistTable[BegCol]; // Get pointers to avoid indexing
RwPtr = &WallDistTable[Rcol];
// The ScaleHt is used to determine the distance from the player for each
// row of the floor and ceiling. The value 89 was arrived at based on a
// reasonable height above the floor that the player is standing. By
// experimenting with this value, the effect of jumping up and down can
// be achieved, (as int32_t as the walls and objects are made to jump by the
// same amount).
Scale_Fac = (ae->PlayerHeight - ViewHeight) * 5;
ScaleHt = ae->PlayerHeight - ViewHeight;
ScaleHt *= Scale_Fac;
// Here we loop through each column of the viewing window
for (col = BegCol; col < EndCol; col ++)//= 2) //MEH For higher resolution, only increment by one instead of 2
{
// Pick up the cosine and sine values for the current angle
cv = CosTable[va];
sv = SinTable[va];
// Point to the left side of the current floor and ceiling columns
fscr = scr;
cscr = scrCeil;
// Advance the columns for the next pass
scr ++;//= 2;
scrCeil ++;//= 2;
// Pick up the current distance to the wall that was found for the
// current column
wdist = *wPtr;
// Advance the wall distance pointer for the next pass
wPtr ++;//= 2;
#if DRAW_BACK
// Pick up the pointer to the background image for the current column
ba = BackArray[bcol++];
// Check for wrap-around in our 640 column image
if (bcol > 639) bcol = 0;
// Pick up the next column as well since the floor and ceiling are
// always done in low resolution
// ba1 = BackArray[bcol++];
if (bcol > 639) bcol = 0;
ba += ht;
// ba1 += ht;
#endif
// Initialize a last distance variable
LastDist = -1;
// Our floor cosine is used to counteract a fisheye effect
fcv = FloorCosTable[col];
LineNum = 0;
for (row = 1; row <= ht; row++)
{
if(LineNum < 96)
stPtr = scantables[LineNum++];
scan2 = ScaleHt / row;
// Get the distance for the current column and row position
dist = (fcv * scan2) >> 15;
// If we're still closer than any wall
if (dist < wdist)
{
// Do some extra calculations if it's a new distance from last time
// (Sometimes our distance works out to be the same so we can avoid
// the next few lines)
if (dist != LastDist)
{
x = xPglobal + ((cv * dist) >> 16);
y = yPglobal + ((sv * dist) >> 16);
LastDist = dist;
}
mPos = (y & 0xFC0) + (x >> 6); // Calc the Map Posn
if (mPos < 0L || mPos > 4095L)
continue;
bPos = (y & 63) + ((x & 63)<<6); // Calc the Bitmap Pixel
// Get the bitmap number for our floor
bCode = FloorMap[mPos];
// And use it to pull the actual bitmap from our array of wall bitmaps
bmp = WallbMaps[bCode];
// Make sure it's really a bitmap and then get the actual pixel to display
if (bmp != NULL)
ch = bmp[bPos];
//printf("%d\n", row);// Crashes at row 97
ch = stPtr[ch]; // Get shaded value for pixel
// Place the pixel in this column as well as the next. Since we have a
// scattering effect we can display in low resolution without too much
// loss in detail. This really speeds up the drawing of the floor and
// ceiling.
*fscr = ch; // Put it into two locations
//fscr[1] = ch; // for low resolution
// Only draw a ceiling pixel if there is a ceiling tile placed in the map
// This gives the effect of seeing the background through holes in the ceiling
if ((bCode = CeilMap[mPos]) != 0)
{
bmp = WallbMaps[bCode];
if (bmp != NULL)
ch = bmp[bPos];
ch = stPtr[ch]; // Get shaded value for pixel
*cscr = ch;
//cscr[1] = ch;
}
#if DRAW_BACK
// If no ceiling is drawn, then we need to draw the background image
else
{
*cscr = *ba;
//cscr[1] = *ba1;
}
#endif
}
fscr += 320; // Advance our screen position for the floor
cscr -= 320; // and the ceiling
#if DRAW_BACK
// Advance the pointers to the background image for the next pass
ba--;
ba1--;
#endif
}
// Advance our current viewing angle by 2 since we are in low resolution
va ++;//= 2; //MEH NOT ANYMORES!
// and check for wrap-around
if (va >= INT_ANGLE_360) va -= INT_ANGLE_360;
}
}
//------------------------------------------------------------------------
// Draw ceiling texture bitmaps only. Floor is assumed to be a solid color.
//------------------------------------------------------------------------
//MEH Deprecated
/*void AckDrawCeilingOnly(void)
{
int col,row,ht,Rcol,EndCol,BegCol;
int Scale_Fac,ScaleHt;
UCHAR *scr,*bmp,*scrCeil,*cscr;
// UCHAR *Rscr,*Rfscr,*RscrCeil,*Rcscr;
UCHAR *ba,*ba1;//,*Rba,*Rba1;
short va,LineNum;
char *stPtr;
int32_t LastDist,scan2;
int32_t cv,sv,dist,x,y,mPos,bPos,wdist,bcol;
// int32_t Rbcol,Rwdist,xp,yp;
int32_t *wPtr,*RwPtr;//',*xyPtr;
int32_t fcv;
UCHAR ch;
USHORT bCode;
#if !(DRAW_BACK)
DrawBackDrop(); // Draw entire background
#endif
BegCol = gWinStartX;
EndCol = gWinEndX;
// Get the starting offset of the center row of the view
scr = gScrnBufferCenter + BegCol;
// Get the left side of the POV view
va = PlayerAngle - INT_ANGLE_32;
// Check for wrap-around
if (va < 0) va += INT_ANGLE_360;
// Adjust the viewing angle based on the starting view column
va += BegCol;
// and check for wrap-around
if (va >= INT_ANGLE_360)
va -= INT_ANGLE_360;
// Get the starting column for the background, there are 640
// columns possible, so the remainder when we divide is where
// we want to begin displaying
bcol = va % 640;
// Temporarily hold onto the view height / 2
ht = gWinHalfHeight;
// Since our horizon should always have some form of wall or object,
// no matter how far away it is, we can optimize alittle here by not
// drawing the first few horizon rows (it does actually save time!).
// Start 5 video rows above the center row
scrCeil = scr - 1600;
// Initial right side of view
Rcol = 319;
wPtr = &WallDistTable[BegCol]; // Get pointers to avoid indexing
RwPtr = &WallDistTable[Rcol];
// The ScaleHt is used to determine the distance from the player for each
// row of the floor and ceiling. The value 89 was arrived at based on a
// reasonable height above the floor that the player is standing. By
// experimenting with this value, the effect of jumping up and down can
// be achieved, (as int32_t as the walls and objects are made to jump by the
// same amount).
Scale_Fac = (ae->PlayerHeight - ViewHeight) * 5;
ScaleHt = ae->PlayerHeight - ViewHeight;
ScaleHt *= Scale_Fac;
// Here we loop through each column of the viewing window
for (col = BegCol; col < EndCol; col ++)//= 2)
{
// Pick up the cosine and sine values for the current angle
cv = CosTable[va];
sv = SinTable[va];
// Point to the left side of the current ceiling columns
cscr = scrCeil;
// Advance the columns for the next pass
scrCeil ++;//= 2;
// Pick up the current distance to the wall that was found for the
// current column
wdist = *wPtr;
// Advance the wall distance pointer for the next pass
wPtr ++;//= 2;
#if DRAW_BACK
// Pick up the pointer to the background image for the current column
ba = BackArray[bcol++];
// Check for wrap-around in our 640 column image
if (bcol > 639) bcol = 0;
// Pick up the next column as well since the floor and ceiling are
// always done in low resolution
// ba1 = BackArray[bcol++];
if (bcol > 639) bcol = 0;
ba += ht;
// ba1 += ht;
#endif
// Initialize a last distance variable
LastDist = -1;
// Our floor cosine is used to counteract a fisheye effect
fcv = FloorCosTable[col];
LineNum = 0;
for (row = 6; row <= ht; row++)
{
stPtr = scantables[LineNum++];
scan2 = ScaleHt / row;
// Get the distance for the current column and row position
dist = (fcv * scan2) >> 15;
// If we're still closer than any wall
if (dist < wdist)
{
// Do some extra calculations if it's a new distance from last time
// (Sometimes our distance works out to be the same so we can avoid
// the next few lines)
if (dist != LastDist)
{
x = xPglobal + ((cv * dist) >> 16);
y = yPglobal + ((sv * dist) >> 16);
LastDist = dist;
}
mPos = (y & 0xFC0) + (x >> 6); // Calc the Map Posn
if (mPos < 0L || mPos > 4095L)
continue;
bPos = (y & 63) + ((x & 63)<<6); // Calc the Bitmap Pixel
// Only draw a ceiling pixel if there is a ceiling tile placed in the map
// This gives the effect of seeing the background through holes in the ceiling
if ((bCode = CeilMap[mPos]) != 0)
{
bmp = WallbMaps[bCode];
if (bmp != NULL)
ch = bmp[bPos];
ch = stPtr[ch]; // Get shaded pixel
*cscr = ch;
//cscr[1] = ch;
}
#if DRAW_BACK
// If no ceiling is drawn, then we need to draw the background image
else
{
*cscr = *ba;
//cscr[1] = *ba1;
}
#endif
}
cscr -= 320; // and the ceiling
#if DRAW_BACK
// Advance the pointers to the background image for the next pass
ba--;
ba1--;
#endif
}
// Advance our current viewing angle by 2 since we are in low resolution
va ++;//= 2;
// and check for wrap-around
if (va >= INT_ANGLE_360) va -= INT_ANGLE_360;
}
}
*/
//------------------------------------------------------------------------
// Draw floor textured bitmaps only. Ceiling is a solid color.
//------------------------------------------------------------------------
//MEH Deprecated
/*void AckDrawFloorOnly(void)
{
int col,row,ht,Rcol,EndCol,BegCol;
int Scale_Fac,ScaleHt;
UCHAR *scr,*fscr,*bmp;//,*scrCeil,*cscr;
//UCHAR *Rscr,*Rfscr,*RscrCeil,*Rcscr;
UCHAR *ba,*ba1;//,*Rba,*Rba1;
short va,LineNum;
char *stPtr;
int32_t LastDist,scan2;
int32_t cv,sv,dist,x,y,mPos,bPos,wdist,bcol;
// int32_t Rbcol,Rwdist,xp,yp;
int32_t *wPtr,*RwPtr;
int32_t fcv;
UCHAR ch;
USHORT bCode;
#if !(DRAW_BACK)
DrawBackDrop(); // Draw entire background
#endif
BegCol = gWinStartX;
EndCol = gWinEndX;
// Get the starting offset of the center row of the view
scr = gScrnBufferCenter + BegCol;
// Get the left side of the POV view
va = PlayerAngle - INT_ANGLE_32;
// Check for wrap-around
if (va < 0) va += INT_ANGLE_360;
// Adjust the viewing angle based on the starting view column
va += BegCol;
// and check for wrap-around
if (va >= INT_ANGLE_360)
va -= INT_ANGLE_360;
// Get the starting column for the background, there are 640
// columns possible, so the remainder when we divide is where
// we want to begin displaying
bcol = va % 640;
// Temporarily hold onto the view height / 2
ht = gWinHalfHeight;
// Since our horizon should always have some form of wall or object,
// no matter how far away it is, we can optimize alittle here by not
// drawing the first few horizon rows (it does actually save time!).
// Start 6 video rows below the center row
scr += 1920;
// Initial right side of view
Rcol = 319;
wPtr = &WallDistTable[BegCol]; // Get pointers to avoid indexing
RwPtr = &WallDistTable[Rcol];