-
Notifications
You must be signed in to change notification settings - Fork 12
/
r_main.c
963 lines (778 loc) · 19.2 KB
/
r_main.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
/* r_main.c */
#include "doomdef.h"
#include "r_local.h"
#ifdef MARS
#include "mars.h"
#include "marshw.h"
#endif
int16_t viewportWidth, viewportHeight;
int16_t centerX, centerY;
fixed_t centerXFrac, centerYFrac;
fixed_t stretch;
fixed_t stretchX;
VINT weaponYpos;
fixed_t weaponXScale;
VINT anamorphicview = 0;
VINT initmathtables = 2;
drawcol_t drawcol;
drawcol_t drawfuzzcol;
drawcol_t drawcolnpo2;
drawcol_t drawcollow;
drawspan_t drawspan;
short fuzzoffset[FUZZTABLE] =
{
1,-1,1,-1,1,1,-1,
1,1,-1,1,1,1,-1,
1,1,1,-1,-1,-1,-1,
1,-1,-1,1,1,1,1,-1,
1,-1,1,1,-1,-1,1,
1,-1,-1,-1,-1,1,1,
1,1,-1,1,1,-1,1,
-1,-1,1,-1,1,1,1,
1,-1,1,-1,-1,1,1
};
/*===================================== */
const uint16_t visplane0open[SCREENWIDTH+2] = { 0 };
/*===================================== */
#ifndef MARS
boolean phase1completed;
pixel_t *workingscreen;
#endif
#ifdef MARS
static int16_t curpalette = -1;
__attribute__((aligned(16)))
pixel_t* viewportbuffer;
__attribute__((aligned(16)))
#endif
viewdef_t vd;
player_t *viewplayer;
VINT framecount; /* incremented every frame */
VINT extralight; /* bumped light from gun blasts */
/* */
/* precalculated math */
/* */
#ifndef MARS
fixed_t *finecosine_ = &finesine_[FINEANGLES/4];
#endif
fixed_t *yslope/*[SCREENHEIGHT]*/;
fixed_t *distscale/*[SCREENWIDTH]*/;
VINT *viewangletox/*[FINEANGLES/2]*/;
uint16_t *xtoviewangle/*[SCREENWIDTH+1]*/;
/* */
/* performance counters */
/* */
VINT t_ref_cnt = 0;
int t_ref_bsp[4], t_ref_prep[4], t_ref_segs[4], t_ref_planes[4], t_ref_sprites[4], t_ref_total[4];
r_texcache_t r_texcache;
texture_t *testtex;
/*
===============================================================================
=
= R_PointToAngle
=
===============================================================================
*/
static int SlopeDiv(unsigned int num, unsigned int den) ATTR_DATA_CACHE_ALIGN;
static int SlopeDiv (unsigned num, unsigned den)
{
unsigned ans;
den >>= 8;
if (den < 2)
return SLOPERANGE;
ans = (num<<3)/den;
return ans <= SLOPERANGE ? ans : SLOPERANGE;
}
angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2)
{
int x;
int y;
int base = 0;
int num = 0, den = 0, n = 1;
x = x2 - x1;
y = y2 - y1;
if ( (!x) && (!y) )
return 0;
if (x>= 0)
{ /* x >=0 */
if (y>= 0)
{ /* y>= 0 */
if (x>y)
{
/* octant 0 */
num = y, den = x;
}
else
{
/* octant 1 */
base = ANG90-1, n = -1, num = x, den = y;
}
}
else
{ /* y<0 */
y = -y;
if (x>y)
{
n = -1, num = y, den = x; /* octant 8 */
}
else
{
base = ANG270, n = 1, num = x, den = y; /* octant 7 */
}
}
}
else
{ /* x<0 */
x = -x;
if (y>= 0)
{ /* y>= 0 */
if (x>y)
{
base = ANG180-1, n = -1, num = y, den = x; /* octant 3 */
}
else
{
base = ANG90, num = x, den = y; /* octant 2 */
}
}
else
{ /* y<0 */
y = -y;
if (x>y)
{
base = ANG180, num = y, den = x; /* octant 4 */
}
else
{
base = ANG270-1, n = -1, num = x, den = y; /* octant 5 */
}
}
}
return base + n * tantoangle[SlopeDiv(num, den)];
}
/*
==============
=
= R_PointInSubsector
=
==============
*/
struct subsector_s *R_PointInSubsector (fixed_t x, fixed_t y)
{
node_t *node;
int side, nodenum;
if (!numnodes) /* single subsector is a special case */
return subsectors;
nodenum = numnodes-1;
#ifdef MARS
while ( (int16_t)nodenum >= 0 )
#else
while (! (nodenum & NF_SUBSECTOR) )
#endif
{
node = &nodes[nodenum];
side = R_PointOnSide(x, y, node);
nodenum = node->children[side];
}
return &subsectors[nodenum & ~NF_SUBSECTOR];
}
/*============================================================================= */
const VINT viewports[][2][3] = {
{ { 128, 144, true }, { 80, 100, true } },
{ { 160, 180, true }, { 80, 144, true } },
{ { 256, 144, false }, { 160, 128, false } },
{ { 320, 180, false }, { 160, 144, false } },
};
VINT viewportNum;
boolean lowResMode;
const VINT numViewports = sizeof(viewports) / sizeof(viewports[0]);
/*
================
=
= R_SetViewportSize
=
================
*/
void R_SetViewportSize(int num)
{
int width, height;
while (!I_RefreshCompleted())
;
num %= numViewports;
width = viewports[num][splitscreen][0];
height = viewports[num][splitscreen][1];
lowResMode = viewports[num][splitscreen][2];
viewportNum = num;
viewportWidth = width;
viewportHeight = height;
centerX = viewportWidth / 2;
centerY = viewportHeight / 2;
centerXFrac = centerX * FRACUNIT;
centerYFrac = centerY * FRACUNIT;
if (anamorphicview)
{
stretch = ((FRACUNIT * 16 * height) / 180 * 28) / width;
//weaponXScale = 1050 * (lowResMode ? 1 : 2) * FRACUNIT / 1100;
weaponXScale = FRACUNIT * (lowResMode ? 1 : 2);
}
else
{
/* proper screen size would be 160*100, stretched to 224 is 2.2 scale */
//stretch = (fixed_t)((160.0f / width) * ((float)height / 180.0f) * 2.2f * FRACUNIT);
stretch = ((FRACUNIT * 16 * height) / 180 * 22) / width;
weaponXScale = FRACUNIT * (lowResMode ? 1 : 2);
}
stretchX = stretch * centerX;
weaponYpos = 180;
if (viewportHeight <= 128) {
weaponYpos = 144;
}
weaponYpos = (viewportHeight - weaponYpos) / 2;
initmathtables = 2;
clearscreen = 2;
// refresh func pointers
R_SetDrawMode();
R_InitColormap(lowResMode);
#ifdef MARS
Mars_CommSlaveClearCache();
#endif
}
void R_SetDrawMode(void)
{
if (debugmode == DEBUGMODE_NODRAW)
{
drawcol = I_DrawColumnNoDraw;
drawcolnpo2 = I_DrawColumnNoDraw;
drawfuzzcol = I_DrawColumnNoDraw;
drawcollow = I_DrawColumnNoDraw;
drawspan = I_DrawSpanNoDraw;
return;
}
if (lowResMode)
{
drawcol = I_DrawColumnLow;
drawcolnpo2 = I_DrawColumnNPo2Low;
drawfuzzcol = I_DrawFuzzColumnLow;
drawcollow = I_DrawColumnLow;
drawspan = I_DrawSpanLow;
}
else
{
drawcol = I_DrawColumn;
drawcolnpo2 = I_DrawColumnNPo2;
drawfuzzcol = I_DrawFuzzColumn;
drawspan = I_DrawSpan;
drawcollow = I_DrawColumnLow;
drawspan = I_DrawSpan;
}
#ifdef MARS
Mars_CommSlaveClearCache();
#endif
}
int R_DefaultViewportSize(void)
{
int i;
for (i = 0; i < numViewports; i++)
{
const VINT* vp = viewports[i][0];
if (vp[0] == 160 && vp[2] == true)
return i;
}
return 0;
}
/*
==============
=
= R_Init
=
==============
*/
void R_Init (void)
{
D_printf ("R_InitData\n");
R_InitData ();
D_printf ("Done\n");
R_SetViewportSize(viewportNum);
framecount = 0;
viewplayer = &players[0];
R_SetDrawMode();
R_InitTexCache(&r_texcache);
testtex = &textures[R_TextureNumForName("SLADWALL")];
}
/*
==============
=
= R_SetupTextureCaches
=
==============
*/
void R_SetupTextureCaches(void)
{
int i, j;
int zonefree;
int cachezonesize;
void *margin;
const int zonemargin = 8*1024;
const int flatblocksize = sizeof(memblock_t) + ((sizeof(texcacheblock_t) + 15) & ~15) + 64*64 + 32;
// reset pointers from previous level
for (i = 0; i < numtextures; i++)
{
int w = textures[i].width, h = textures[i].height;
int mipcount = 1;
int lump = textures[i].lumpnum;
uint8_t *start = R_CheckPixels(lump);
uint8_t *data = R_SkipJagObjHeader(start, W_LumpLength(lump), w, h);
#if MIPLEVELS > 1
mipcount = textures[i].mipcount;
#endif
for (j = 0; j < mipcount; j++)
{
int size = w * h;
textures[i].data[j] = data;
data += size;
w >>= 1;
if (w < 1)
w = 1;
h >>= 1;
if (h < 1)
h = 1;
}
}
for (i=0 ; i<numflats ; i++)
{
int size = 64;
uint8_t *data = R_CheckPixels(firstflat + i);
for (j = 0; j < MIPLEVELS; j++)
{
flatpixels[i].data[j] = data;
if (texmips) {
data += size * size;
size >>= 1;
}
}
}
// functioning texture cache requires at least 8kb of ram
zonefree = Z_LargestFreeBlock(mainzone);
if (zonefree < zonemargin+flatblocksize)
goto nocache;
cachezonesize = zonefree - zonemargin - 128; // give the main zone some slack
if (cachezonesize < flatblocksize)
goto nocache;
margin = Z_Malloc(zonemargin, PU_LEVEL);
R_InitTexCacheZone(&r_texcache, cachezonesize);
Z_Free(margin);
return;
nocache:
R_InitTexCacheZone(&r_texcache, 0);
}
void R_SetupLevel(void)
{
R_SetupTextureCaches();
R_SetViewportSize(viewportNum);
#ifdef MARS
curpalette = -1;
#endif
}
/*============================================================================= */
#ifndef MARS
int shadepixel;
extern int workpage;
extern pixel_t *screens[2]; /* [viewportWidth*viewportHeight]; */
#endif
/*
==================
=
= R_Setup
=
==================
*/
static void R_Setup (int displayplayer, visplane_t *visplanes_,
visplane_t **visplanes_hash_, sector_t **vissectors_, viswallextra_t *viswallex_)
{
int i;
int damagecount, bonuscount;
player_t *player;
#ifdef JAGUAR
int shadex, shadey, shadei;
#endif
unsigned short *tempbuf;
#ifdef MARS
int palette = 0;
#endif
/* */
/* set up globals for new frame */
/* */
#ifndef MARS
workingscreen = screens[workpage];
*(pixel_t **)0xf02224 = workingscreen; /* a2 base pointer */
*(int *)0xf02234 = 0x10000; /* a2 outer loop add (+1 y) */
*(int *)0xf0226c = *(int *)0xf02268 = 0; /* pattern compare */
#else
if (debugmode == DEBUGMODE_NODRAW)
I_ClearFrameBuffer();
#endif
framecount++;
validcount[0]++;
player = &players[displayplayer];
vd.viewplayer = player;
vd.viewx = player->mo->x;
vd.viewy = player->mo->y;
vd.viewz = player->viewz;
vd.viewangle = player->mo->angle;
vd.viewsin = finesine(vd.viewangle>>ANGLETOFINESHIFT);
vd.viewcos = finecosine(vd.viewangle>>ANGLETOFINESHIFT);
vd.displayplayer = displayplayer;
vd.lightlevel = player->mo->subsector->sector->lightlevel;
vd.fixedcolormap = 0;
vd.clipangle = xtoviewangle[0]<<FRACBITS;
vd.doubleclipangle = vd.clipangle * 2;
vd.viewangletox = viewangletox;
damagecount = player->damagecount;
bonuscount = player->bonuscount;
#ifdef JAGUAR
vd.extralight = player->extralight << 6;
/* */
/* calc shadepixel */
/* */
if (damagecount)
damagecount += 10;
if (bonuscount)
bonuscount += 2;
damagecount >>= 2;
shadex = (bonuscount>>1) + damagecount;
shadey = (bonuscount>>1) - damagecount;
shadei = (bonuscount + damagecount)<<2;
shadei += player->extralight<<3;
/* */
/* pwerups */
/* */
if (player->powers[pw_invulnerability] > 60
|| (player->powers[pw_invulnerability]&4) )
{
shadex -= 8;
shadei += 32;
}
if (player->powers[pw_ironfeet] > 60
|| (player->powers[pw_ironfeet]&4) )
shadey += 7;
if (player->powers[pw_strength]
&& (player->powers[pw_strength]< 64) )
shadex += (8 - (player->powers[pw_strength]>>3) );
/* */
/* bound and store shades */
/* */
if (shadex > 7)
shadex = 7;
else if (shadex < -8)
shadex = -8;
if (shadey > 7)
shadey = 7;
else if (shadey < -8)
shadey = -8;
if (shadei > 127)
shadei = 127;
else if (shadei < -128)
shadei = -128;
shadepixel = ((shadex<<12)&0xf000) + ((shadey<<8)&0xf00) + (shadei&0xff);
#endif
#ifdef MARS
vd.extralight = player->extralight << 4;
if (player->powers[pw_invulnerability] > 0)
{
if (player->powers[pw_invulnerability] > 60
|| (player->powers[pw_invulnerability] & 4))
vd.fixedcolormap = INVERSECOLORMAP;
}
else if (player->powers[pw_infrared] > 0)
{
if (player->powers[pw_infrared] > 4*32
|| (player->powers[pw_infrared]&8) )
{
// almost full bright
vd.fixedcolormap = 1*256;
}
}
viewportbuffer = (pixel_t*)I_ViewportBuffer();
palette = 0;
i = 0;
if (player->powers[pw_strength] > 0)
i = 12 - player->powers[pw_strength] / 64;
if (i < damagecount)
i = damagecount;
if (gamepaused)
palette = 14;
else if (!splitscreen)
{
if (i)
{
palette = (i + 7) / 8;
if (palette > 7)
palette = 7;
palette += 1;
}
else if (bonuscount)
{
palette = (bonuscount + 7) / 8;
if (palette > 3)
palette = 3;
palette += 9;
}
else if (player->powers[pw_ironfeet] > 60
|| (player->powers[pw_ironfeet] & 4))
palette = 13;
}
if (palette != curpalette) {
curpalette = palette;
I_SetPalette(dc_playpals+palette*768);
}
if (vd.fixedcolormap == INVERSECOLORMAP)
vd.fuzzcolormap = INVERSECOLORMAP;
else
vd.fuzzcolormap = 12 * 256;
#endif
vd.visplanes = visplanes_;
vd.visplanes[0].flatandlight = 0;
tempbuf = (unsigned short *)I_WorkBuffer();
/* */
/* plane filling */
/* */
vd.visplanes[0].open = (uint16_t *)visplane0open + 1;
tempbuf = (unsigned short*)(((intptr_t)tempbuf + 3) & ~3);
tempbuf += 2; // padding
for (i = 1; i < MAXVISPLANES; i++) {
vd.visplanes[i].open = tempbuf;
tempbuf += SCREENWIDTH+2;
}
vd.segclip = tempbuf;
tempbuf += MAXOPENINGS;
tempbuf = (unsigned short*)(((intptr_t)tempbuf + 3) & ~3);
vd.viswalls = (void*)tempbuf;
tempbuf += sizeof(*vd.viswalls) * MAXWALLCMDS / sizeof(*tempbuf);
vd.viswallextras = viswallex_ + 1;
// re-use the openings array in VRAM
vd.gsortedsprites = (void *)(((intptr_t)vd.visplanes[1].open + 3) & ~3);
vd.vissprites = (void *)vd.viswalls;
vd.lastwallcmd = vd.viswalls; /* no walls added yet */
vd.lastsegclip = vd.segclip;
vd.lastvisplane = vd.visplanes + 1; /* visplanes[0] is left empty */
vd.visplanes_hash = visplanes_hash_;
vd.gsortedvisplanes = NULL;
vd.columncache[0] = (uint8_t*)(((intptr_t)tempbuf + 3) & ~3);
tempbuf += sizeof(uint8_t) * COLUMN_CACHE_SIZE * 2 / sizeof(*tempbuf);
vd.columncache[1] = (uint8_t*)(((intptr_t)tempbuf + 3) & ~3);
tempbuf += sizeof(uint8_t) * COLUMN_CACHE_SIZE * 2 / sizeof(*tempbuf);
//I_Error("%d", ((uint16_t *)I_FrameBuffer() + 64*1024-0x100 - tempbuf) * 2);
I_SetThreadLocalVar(DOOMTLS_COLUMNCACHE, vd.columncache[0]);
/* */
/* clear sprites */
/* */
vd.vissprite_p = vd.vissprites;
vd.lastsprite_p = vd.vissprite_p;
vd.vissectors = vissectors_;
vd.lastvissector = vd.vissectors; /* no subsectors visible yet */
for (i = 0; i < NUM_VISPLANES_BUCKETS; i++)
vd.visplanes_hash[i] = NULL;
#ifndef MARS
phasetime[0] = samplecount;
#endif
}
#ifdef MARS
void Mars_Sec_R_Setup(void)
{
int i;
Mars_ClearCacheLines(&vd, (sizeof(vd) + 31) / 16);
Mars_ClearCacheLine(&viewportbuffer);
Mars_ClearCacheLines(vd.visplanes, (sizeof(visplane_t)*MAXVISPLANES+31)/16);
for (i = 0; i < NUM_VISPLANES_BUCKETS; i++)
vd.visplanes_hash[i] = NULL;
I_SetThreadLocalVar(DOOMTLS_COLUMNCACHE, vd.columncache[1]);
}
#endif
//
// Check for a matching visplane in the visplanes array, or set up a new one
// if no compatible match can be found.
//
#define R_PlaneHash(height, lightlevel) \
((((unsigned)(height) >> 8) + (flatandlight>>16)) ^ (flatandlight&0xffff)) & (NUM_VISPLANES_BUCKETS - 1)
void R_MarkOpenPlane(visplane_t* pl)
{
int i;
int longs = (viewportWidth + 1) / 2;
uint32_t * open = (uint32_t *)pl->open;
const uint32_t v = ((uint32_t)OPENMARK << 16) | OPENMARK;
for (i = 0; i < longs/2; i++)
{
*open++ = v;
*open++ = v;
}
}
void R_InitClipBounds(uint32_t *clipbounds)
{
// initialize the clipbounds array
int i;
int longs = (viewportWidth + 1) / 2;
uint32_t* clip = clipbounds;
const uint32_t v = ((uint32_t)viewportHeight << 16) | viewportHeight;
for (i = 0; i < longs/2; i++)
{
*clip++ = v;
*clip++ = v;
}
}
visplane_t* R_FindPlane(fixed_t height,
int flatandlight, int start, int stop)
{
visplane_t *check, *tail, *next;
int hash = R_PlaneHash(height, flatandlight);
tail = vd.visplanes_hash[hash];
for (check = tail; check; check = next)
{
next = check->next;
if (height == check->height && // same plane as before?
flatandlight == check->flatandlight)
{
if (MARKEDOPEN(check->open[start]))
{
// found a plane, so adjust bounds and return it
if (start < check->minx)
check->minx = start; // mark the new edge
if (stop > check->maxx)
check->maxx = stop; // mark the new edge
return check; // use the same one as before
}
}
}
if (vd.lastvisplane == vd.visplanes + MAXVISPLANES)
return vd.visplanes;
// make a new plane
check = vd.lastvisplane;
++vd.lastvisplane;
check->height = height;
check->flatandlight = flatandlight;
check->minx = start;
check->maxx = stop;
R_MarkOpenPlane(check);
check->next = tail;
vd.visplanes_hash[hash] = check;
return check;
}
void R_BSP (void) __attribute__((noinline));
void R_WallPrep (void) __attribute__((noinline));
void R_SpritePrep (void) __attribute__((noinline));
boolean R_LatePrep (void) __attribute__((noinline));
void R_Cache (void) __attribute__((noinline));
void R_SegCommands (void) __attribute__((noinline));
void R_DrawPlanes (void) __attribute__((noinline));
void R_Sprites (void) __attribute__((noinline));
void R_Update (void) __attribute__((noinline));
/*
==============
=
= R_RenderView
=
==============
*/
extern boolean debugscreenactive;
#ifndef MARS
int phasetime[9] = {1,2,3,4,5,6,7,8,9};
extern ref1_start;
extern ref2_start;
extern ref3_start;
extern ref4_start;
extern ref5_start;
extern ref6_start;
extern ref7_start;
extern ref8_start;
void R_RenderPlayerView(int displayplayer)
{
visplane_t visplanes_[MAXVISPLANES];
visplane_t *visplanes_hash_[NUM_VISPLANES_BUCKETS];
sector_t *vissectors_[MAXVISSSEC];
viswallextra_t viswallex_[MAXWALLCMDS + 1] __attribute__((aligned(16)));
/* make sure its done now */
#if defined(JAGUAR)
while (!I_RefreshCompleted())
;
#endif
/* */
/* initial setup */
/* */
if (debugscreenactive)
I_DebugScreen();
R_Setup(displayplayer, visplanes_, visplanes_hash_, vissectors_, viswallex_);
#ifndef JAGUAR
R_BSP();
R_WallPrep();
/* the rest of the refresh can be run in parallel with the next game tic */
if (R_LatePrep())
R_Cache();
R_SegCommands();
R_DrawPlanes();
R_SpritePrep();
R_Sprites();
R_Update();
#else
/* start the gpu running the refresh */
phasetime[1] = 0;
phasetime[2] = 0;
phasetime[3] = 0;
phasetime[4] = 0;
phasetime[5] = 0;
phasetime[6] = 0;
phasetime[7] = 0;
phasetime[8] = 0;
gpufinished = zero;
gpucodestart = (int)&ref1_start;
#endif
}
#else
void R_RenderPlayerView(int displayplayer)
{
int t_bsp, t_prep, t_segs, t_planes, t_sprites, t_total;
boolean drawworld = !(players[consoleplayer].automapflags & AF_ACTIVE);
__attribute__((aligned(16)))
visplane_t visplanes_[MAXVISPLANES];
__attribute__((aligned(16)))
visplane_t *visplanes_hash_[NUM_VISPLANES_BUCKETS];
sector_t *vissectors_[(MAXVISSSEC > MAXVISSPRITES ? MAXVISSSEC : MAXVISSPRITES) + 1];
viswallextra_t viswallex_[MAXWALLCMDS + 1] __attribute__((aligned(16)));
t_total = I_GetFRTCounter();
R_Setup(displayplayer, visplanes_, visplanes_hash_, vissectors_, viswallex_);
Mars_R_BeginWallPrep(drawworld);
t_bsp = I_GetFRTCounter();
R_BSP();
t_bsp = I_GetFRTCounter() - t_bsp;
Mars_R_EndWallPrep();
if (!drawworld)
{
Mars_R_SecWait();
return;
}
t_prep = I_GetFRTCounter();
R_Cache();
t_prep = I_GetFRTCounter() - t_prep;
t_segs = I_GetFRTCounter();
R_SegCommands();
t_segs = I_GetFRTCounter() - t_segs;
Mars_ClearCacheLine(&vd.lastsegclip);
if (vd.lastsegclip - vd.segclip > MAXOPENINGS)
I_Error("lastsegclip > MAXOPENINGS: %d", vd.lastsegclip - vd.segclip);
if (vd.lastvissector - vd.vissectors > MAXVISSSEC)
I_Error("lastvissector > MAXVISSSEC: %d", vd.lastvissector - vd.vissectors);
t_planes = I_GetFRTCounter();
R_DrawPlanes();
t_planes = I_GetFRTCounter() - t_planes;
t_sprites = I_GetFRTCounter();
R_SpritePrep();
R_Sprites();
t_sprites = I_GetFRTCounter() - t_sprites;
R_Update();
t_total = I_GetFRTCounter() - t_total;
t_ref_cnt = (t_ref_cnt + 1) & 3;
t_ref_bsp[t_ref_cnt] = t_bsp;
t_ref_prep[t_ref_cnt] = t_prep;
t_ref_segs[t_ref_cnt] = t_segs;
t_ref_planes[t_ref_cnt] = t_planes;
t_ref_sprites[t_ref_cnt] = t_sprites;
t_ref_total[t_ref_cnt] = t_total;
}
#endif