-
Notifications
You must be signed in to change notification settings - Fork 3
/
r_main.c
488 lines (384 loc) · 8.52 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
/* r_main.c */
#include "doomdef.h"
#include "r_local.h"
/*===================================== */
/* */
/* subsectors */
/* */
subsector_t *vissubsectors[MAXVISSSEC], **lastvissubsector;
/* */
/* walls */
/* */
viswall_t viswalls[MAXWALLCMDS], *lastwallcmd;
/* */
/* planes */
/* */
visplane_t visplanes[MAXVISPLANES], *lastvisplane;
/* */
/* sprites */
/* */
vissprite_t vissprites[MAXVISSPRITES], *lastsprite_p, *vissprite_p;
/* */
/* openings / misc refresh memory */
/* */
unsigned short openings[MAXOPENINGS], *lastopening;
/*===================================== */
boolean phase1completed;
pixel_t *workingscreen;
fixed_t viewx, viewy, viewz;
angle_t viewangle;
fixed_t viewcos, viewsin;
player_t *viewplayer;
int validcount = 1; /* increment every time a check is made */
int framecount; /* incremented every frame */
boolean fixedcolormap;
int lightlevel; /* fixed light level */
int extralight; /* bumped light from gun blasts */
/* */
/* sky mapping */
/* */
int skytexture;
/* */
/* precalculated math */
/* */
angle_t clipangle,doubleclipangle;
fixed_t *finecosine = &finesine[FINEANGLES/4];
/*
===============================================================================
=
= R_PointToAngle
=
===============================================================================
*/
extern int tantoangle[SLOPERANGE+1];
int SlopeDiv (unsigned num, unsigned den)
{
unsigned ans;
if (den < 512)
return SLOPERANGE;
ans = (num<<3)/(den>>8);
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;
x = x2 - x1;
y = y2 - y1;
if ( (!x) && (!y) )
return 0;
if (x>= 0)
{ /* x >=0 */
if (y>= 0)
{ /* y>= 0 */
if (x>y)
return tantoangle[ SlopeDiv(y,x)]; /* octant 0 */
else
return ANG90-1-tantoangle[ SlopeDiv(x,y)]; /* octant 1 */
}
else
{ /* y<0 */
y = -y;
if (x>y)
return -tantoangle[SlopeDiv(y,x)]; /* octant 8 */
else
return ANG270+tantoangle[ SlopeDiv(x,y)]; /* octant 7 */
}
}
else
{ /* x<0 */
x = -x;
if (y>= 0)
{ /* y>= 0 */
if (x>y)
return ANG180-1-tantoangle[ SlopeDiv(y,x)]; /* octant 3 */
else
return ANG90+ tantoangle[ SlopeDiv(x,y)]; /* octant 2 */
}
else
{ /* y<0 */
y = -y;
if (x>y)
return ANG180+tantoangle[ SlopeDiv(y,x)]; /* octant 4 */
else
return ANG270-1-tantoangle[ SlopeDiv(x,y)]; /* octant 5 */
}
}
#ifndef LCC
return 0;
#endif
}
/*
===============================================================================
=
= R_PointOnSide
=
= Returns side 0 (front) or 1 (back)
===============================================================================
*/
static int R_PointOnSide (int x, int y, node_t *node)
{
fixed_t dx,dy;
fixed_t left, right;
if (!node->dx)
{
if (x <= node->x)
return node->dy > 0;
return node->dy < 0;
}
if (!node->dy)
{
if (y <= node->y)
return node->dx < 0;
return node->dx > 0;
}
dx = (x - node->x);
dy = (y - node->y);
left = (node->dy>>16) * (dx>>16);
right = (dy>>16) * (node->dx>>16);
if (right < left)
return 0; /* front side */
return 1; /* back side */
}
/*
==============
=
= 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;
while (! (nodenum & NF_SUBSECTOR) )
{
node = &nodes[nodenum];
side = R_PointOnSide (x, y, node);
nodenum = node->children[side];
}
return &subsectors[nodenum & ~NF_SUBSECTOR];
}
/*============================================================================= */
/*
==============
=
= R_Init
=
==============
*/
void R_Init (void)
{
D_printf ("R_InitData\n");
R_InitData ();
D_printf ("Done\n");
clipangle = xtoviewangle[0];
doubleclipangle = clipangle*2;
framecount = 0;
viewplayer = &players[0];
}
/*============================================================================= */
extern int ticsinframe;
extern int checkpostics, shoottics;
extern int lasttics;
extern int playertics, thinkertics, sighttics, basetics, latetics;
extern int tictics;
extern int soundtics;
/*
===================
=
= R_DebugScreen
=
===================
*/
void R_DebugScreen (void)
{
#ifdef JAGUAR
#if 1
PrintNumber (15,1, vblsinframe);
PrintNumber (15,2, phasetime[8] - phasetime[0]);
PrintNumber (15,3, tictics);
PrintNumber (15,4, soundtics);
#endif
#if 1
PrintNumber (15,6, playertics);
PrintNumber (15,7, thinkertics);
PrintNumber (15,8, sighttics);
PrintNumber (15,9, basetics);
PrintNumber (15,10, latetics);
#endif
#if 0
int i;
PrintNumber (15,1, phasetime[8] - phasetime[0]);
for (i=0 ; i < 8 ; i++)
PrintNumber (15,3+i,phasetime[i+1]-phasetime[i]);
#endif
#endif
}
/*============================================================================= */
int shadepixel;
extern int workpage;
extern pixel_t *screens[2]; /* [SCREENWIDTH*SCREENHEIGHT]; */
/*
==================
=
= R_Setup
=
==================
*/
void R_Setup (void)
{
int damagecount, bonuscount;
player_t *player;
int shadex, shadey, shadei;
/* */
/* set up globals for new frame */
/* */
workingscreen = screens[workpage];
#ifdef JAGUAR
*(pixel_t **)0xf02224 = workingscreen; /* a2 base pointer */
*(int *)0xf02234 = 0x10000; /* a2 outer loop add (+1 y) */
*(int *)0xf0226c = *(int *)0xf02268 = 0; /* pattern compare */
#endif
framecount++;
validcount++;
viewplayer = player = &players[displayplayer];
viewx = player->mo->x;
viewy = player->mo->y;
viewz = player->viewz;
viewangle = player->mo->angle;
viewsin = finesine[viewangle>>ANGLETOFINESHIFT];
viewcos = finecosine[viewangle>>ANGLETOFINESHIFT];
extralight = player->extralight << 6;
fixedcolormap = player->fixedcolormap;
/* */
/* calc shadepixel */
/* */
player = &players[consoleplayer];
damagecount = player->damagecount;
bonuscount = player->bonuscount;
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);
/* */
/* plane filling */
/* */
lastvisplane = visplanes+1; /* visplanes[0] is left empty */
lastwallcmd = viswalls; /* no walls added yet */
lastvissubsector = vissubsectors; /* no subsectors visible yet */
/* */
/* clear sprites */
/* */
vissprite_p = vissprites;
lastopening = openings;
phasetime[0] = samplecount;
}
void R_BSP (void);
void R_WallPrep (void);
void R_SpritePrep (void);
boolean R_LatePrep (void);
void R_Cache (void);
void R_SegCommands (void);
void R_DrawPlanes (void);
void R_Sprites (void);
void R_Update (void);
/*
==============
=
= R_RenderView
=
==============
*/
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;
extern boolean debugscreenactive;
void R_RenderPlayerView (void)
{
/* make sure its done now */
#ifdef JAGUAR
while (!I_RefreshCompleted ())
;
#endif
/* */
/* initial setup */
/* */
if (debugscreenactive)
R_DebugScreen ();
R_Setup ();
#ifndef JAGUAR
R_BSP ();
R_WallPrep ();
R_SpritePrep ();
/* 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_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;
#if 0
while (!I_RefreshCompleted () )
; /* wait for refresh to latch all needed data before */
/* running the next tick */
#endif
#endif
}