-
Notifications
You must be signed in to change notification settings - Fork 13
/
r_local.h
633 lines (495 loc) · 14.6 KB
/
r_local.h
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
/* R_local.h */
#ifndef __R_LOCAL__
#define __R_LOCAL__
#include "doomdef.h"
extern int16_t viewportWidth, viewportHeight;
extern int16_t centerX, centerY;
extern boolean lowResMode;
extern fixed_t centerXFrac, centerYFrac;
extern fixed_t stretch;
extern fixed_t stretchX;
extern VINT weaponYpos;
extern fixed_t weaponXScale;
#define PROJECTION centerXFrac
#define PSPRITEXSCALE FRACUNIT
#define PSPRITEYSCALE FRACUNIT
#define PSPRITEXISCALE FRACUNIT
#define PSPRITEYISCALE FRACUNIT
#define ANGLETOSKYSHIFT 22 /* sky map is 256*128*4 maps */
#define BASEYCENTER 100
#define WINDOWHEIGHT (viewportHeight-SBARHEIGHT)
#define MINZ (FRACUNIT*4)
#define FIELDOFVIEW 2048 /* fineangles in the SCREENWIDTH wide window */
/* */
/* lighting constants */
/* */
#ifdef JAGUAR
#define LIGHTLEVELS 256 /* number of diminishing */
#define INVERSECOLORMAP 255
#else
#define INVERSECOLORMAP 32*256
#endif
#ifdef MARS
#define HWLIGHT(light) ((((255 - (light)) >> 3) & 31) * 256)
#else
#define HWLIGHT(light) -((255 - (light)) << 14) & 0xffffff
#endif
#define MINLIGHT 0
extern VINT viewportnum;
extern VINT anamorphicview;
/*
==============================================================================
INTERNAL MAP TYPES
==============================================================================
*/
/*================ used by play and refresh */
typedef struct
{
fixed_t x,y;
} vertex_t;
struct line_s;
typedef struct
{
fixed_t floorheight, ceilingheight;
VINT floorpic, ceilingpic; /* if ceilingpic == -1,draw sky */
uint8_t lightlevel, special;
VINT validcount; /* if == validcount, already checked */
VINT linecount;
VINT tag;
mobj_t *soundtarget; /* thing that made a sound (or null) */
VINT blockbox[4]; /* mapblock bounding box for height changes */
VINT soundorg[2]; /* for any sounds played by the sector */
mobj_t *thinglist; /* list of mobjs in sector */
void *specialdata; /* thinker_t for reversable actions */
VINT *lines; /* [linecount] size */
} sector_t;
typedef struct
{
VINT sector;
uint8_t toptexture, bottomtexture, midtexture;
uint8_t rowoffset; /* add this to the calculated texture top */
int16_t textureoffset; /* 8.4, add this to the calculated texture col */
} side_t;
typedef struct line_s
{
VINT flags;
VINT sidenum[2]; /* sidenum[1] will be -1 if one sided */
VINT v1, v2;
VINT special, tag;
VINT fineangle; /* to get sine / eosine for sliding */
} line_t;
#define LD_FRONTSECTOR(ld) (§ors[sides[(ld)->sidenum[0]].sector])
#define LD_BACKSECTOR(ld) ((ld)->sidenum[1] != -1 ? §ors[sides[ld->sidenum[1]].sector] : NULL)
typedef struct subsector_s
{
VINT numlines;
VINT firstline;
sector_t *sector;
} subsector_t;
typedef struct seg_s
{
VINT v1, v2;
VINT sideoffset;
VINT linedef;
} seg_t;
typedef struct
{
fixed_t x,y,dx,dy; /* partition line */
fixed_t bbox[2][4]; /* bounding box for each child */
int children[2]; /* if NF_SUBSECTOR its a subsector */
} node_t;
#define MIPLEVELS 4
typedef struct
{
VINT mincol, maxcol;
VINT minrow, maxrow;
VINT texturenum;
} texdecal_t;
typedef struct
{
char name[8]; /* for switch changing, etc */
VINT width;
VINT height;
VINT lumpnum;
uint16_t decals;
#if MIPLEVELS > 1
VINT mipcount;
#endif
#ifdef MARS
inpixel_t *data[MIPLEVELS];
#else
pixel_t *data[MIPLEVELS]; /* cached data to draw from */
#endif
#ifndef MARS
int usecount; /* for precaching */
int pad;
#endif
} texture_t;
typedef struct
{
#ifdef MARS
inpixel_t *data[MIPLEVELS];
#else
pixel_t *data[MIPLEVELS]; /* cached data to draw from */
#endif
} flattex_t;
/*
==============================================================================
OTHER TYPES
==============================================================================
*/
/* Sprites are patches with a special naming convention so they can be */
/* recognized by R_InitSprites. The sprite and frame specified by a */
/* thing_t is range checked at run time. */
/* a sprite is a patch_t that is assumed to represent a three dimensional */
/* object and may have multiple rotations pre drawn. Horizontal flipping */
/* is used to save space. Some sprites will only have one picture used */
/* for all views. */
typedef struct
{
VINT lump; /* lump to use for view angles 0-7 */
/* if lump[1] == -1, use 0 for any position */
} spriteframe_t;
typedef struct
{
short numframes;
short firstframe; /* index in the spriteframes array */
} spritedef_t;
extern spriteframe_t *spriteframes;
extern VINT *spritelumps;
extern spritedef_t sprites[NUMSPRITES];
/*
===============================================================================
MAP DATA
===============================================================================
*/
extern int numvertexes;
extern vertex_t *vertexes;
extern int numsegs;
extern seg_t *segs;
extern int numsectors;
extern sector_t *sectors;
extern int numsubsectors;
extern subsector_t *subsectors;
extern int numnodes;
extern node_t *nodes;
extern int numlines;
extern line_t *lines;
extern int numsides;
extern side_t *sides;
/*============================================================================= */
extern VINT viewportNum;
extern const VINT numViewports;
/*
===============================================================================
=
= R_PointOnSide
=
= Returns side 0 (front) or 1 (back)
===============================================================================
*/
ATTR_DATA_CACHE_ALIGN
static inline int R_PointOnSide (int x, int y, node_t *node)
{
fixed_t dx,dy;
fixed_t left, right;
dx = (x - node->x);
dy = (y - node->y);
#ifdef MARS
left = ((int64_t)node->dy*dx) >> 32;
right = ((int64_t)dy*node->dx) >> 32;
#else
left = (node->dy>>FRACBITS) * (dx>>FRACBITS);
right = (dy>>FRACBITS) * (node->dx>>FRACBITS);
#endif
return (left <= right);
}
//
// To get a global angle from Cartesian coordinates, the coordinates are
// flipped until they are in the first octant of the coordinate system,
// then the y (<= x) is scaled and divided by x to get a tangent (slope)
// value which is looked up in the tantoangle table.
//
#define R_PointToAngle(x,y) R_PointToAngle2(vd.viewx,vd.viewy,x,y)
void R_InitData (void);
void R_SetViewportSize(int num);
int R_DefaultViewportSize(void); // returns the viewport id for fullscreen, low detail mode
void R_SetDrawMode(void);
void R_SetupLevel(void);
void R_SetupTextureCaches(void);
typedef void (*drawcol_t)(int, int, int, int, fixed_t, fixed_t, inpixel_t*, int);
typedef void (*drawspan_t)(int, int, int, int, fixed_t, fixed_t, fixed_t, fixed_t, inpixel_t*, int);
extern drawcol_t drawcol;
extern drawcol_t drawfuzzcol;
extern drawcol_t drawcolnpo2;
extern drawcol_t drawcollow;
extern drawspan_t drawspan;
#define FUZZTABLE 64
#define FUZZMASK (FUZZTABLE-1)
extern short fuzzoffset[FUZZTABLE];
/* to get a global angle from cartesian coordinates, the coordinates are */
/* flipped until they are in the first octant of the coordinate system, then */
/* the y (<=x) is scaled and divided by x to get a tangent (slope) value */
/* which is looked up in the tantoangle[] table. The +1 size is to handle */
/* the case when x==y without additional checking. */
#define SLOPERANGE 2048
#define SLOPEBITS 11
#define DBITS (FRACBITS-SLOPEBITS)
#ifdef MARS
extern angle_t* const tantoangle;
#else
extern const angle_t tantoangle[SLOPERANGE + 1];
#endif
extern fixed_t *yslope/*[SCREENHEIGHT]*/;
extern fixed_t *distscale/*[SCREENWIDTH]*/;
#define OPENMARK 0xff00
#ifdef MARS
#define MARKEDOPEN(x) ((int8_t)((x)>>8) == -1)
#else
#define MARKEDOPEN(x) ((x) == OPENMARK)
#endif
extern VINT extralight;
#ifdef MARS
__attribute__((aligned(16)))
#endif
extern pixel_t* viewportbuffer;
/* The viewangletox[viewangle + FINEANGLES/4] lookup maps the visible view */
/* angles to screen X coordinates, flattening the arc to a flat projection */
/* plane. There will be many angles mapped to the same X. */
extern VINT *viewangletox/*[FINEANGLES/2]*/;
/* The xtoviewangleangle[] table maps a screen pixel to the lowest viewangle */
/* that maps back to x ranges from clipangle to -clipangle */
extern uint16_t *xtoviewangle/*[SCREENWIDTH+1]*/;
#ifdef MARS
extern const fixed_t finetangent_[FINEANGLES/4];
fixed_t finetangent(angle_t angle) ATTR_DATA_CACHE_ALIGN ATTR_OPTIMIZE_EXTREME;
#else
extern const fixed_t finetangent_[FINEANGLES/2];
#define finetangent(x) finetangent_[x]
#endif
extern VINT *validcount;
extern VINT framecount;
#ifndef MARS
extern int phasetime[9];
#endif
/* */
/* R_data.c */
/* */
extern texture_t *skytexturep;
extern VINT numtextures;
extern texture_t *textures;
extern boolean texmips;
extern VINT numdecals;
extern texdecal_t *decals;
extern uint8_t *flattranslation; /* for global animation */
extern uint8_t *texturetranslation; /* for global animation */
extern flattex_t *flatpixels;
extern VINT firstflat, numflats, col2flat;
extern VINT firstsprite, numsprites;
extern int8_t* dc_colormaps;
extern int8_t* dc_colormaps2;
extern uint8_t* dc_playpals;
#ifdef MARS
#define R_CheckPixels(lumpnum) (void *)(W_POINTLUMPNUM(lumpnum))
// auto-detect presence of jagobj_t header
void *R_SkipJagObjHeader(void *data, int size, int width, int height);
#endif
void R_InitTextures(void);
void R_InitFlats(void);
int R_FlatNumForName(const char* name);
int R_CheckTextureNumForName(const char* name);
void R_InitMathTables(void);
void R_InitSpriteDefs(const char** namelist);
void R_InitColormap(boolean doublepix);
boolean R_CompositeColumn(int colnum, int numdecals, texdecal_t *decals, inpixel_t *src, inpixel_t *dst, int height, int miplevel) ATTR_DATA_CACHE_ALIGN;
/*
==============================================================================
TEXTURE CACHING
==============================================================================
*/
typedef struct
{
int reqcount_le;
int reqfreed;
int zonesize;
void* zone;
} r_texcache_t;
typedef struct
{
uint16_t pixels;
VINT lifecount;
void** userp;
void *userpold;
} texcacheblock_t;
extern r_texcache_t r_texcache;
#define CACHE_FRAMES_DEFAULT 15
void R_InitTexCache(r_texcache_t* c);
void R_InitTexCacheZone(r_texcache_t* c, int zonesize);
void R_AddToTexCache(r_texcache_t* c, int id, int pixels, void **userp);
void R_ClearTexCache(r_texcache_t* c);
boolean R_InTexCache(r_texcache_t* c, void *p) ATTR_DATA_CACHE_ALIGN;
boolean R_TouchIfInTexCache(r_texcache_t* c, void *p);
void R_PostTexCacheFrame(r_texcache_t* c);
/*
==============================================================================
COMMAND QUE STRUCTURES
==============================================================================
*/
#define AC_ADDFLOOR 1
#define AC_ADDCEILING 2
#define AC_TOPTEXTURE 4
#define AC_BOTTOMTEXTURE 8
#define AC_NEWCEILING 16
#define AC_NEWFLOOR 32
#define AC_TOPSIL 64
#define AC_BOTTOMSIL 128
#define AC_SOLIDSIL 256
#define AC_ADDSKY 512
#define AC_DRAWN 1024
#define AC_MIDTEXTURE 2048
typedef struct
{
/* */
/* filled in by early prep */
/* */
/* !!! THE FOLLOWING SECTION MUST BE LARGE ENOUGH */
/* !!! TO ACCOMODATE VISSPRITE_T STRUCTURE, GETS */
/* !!! OVERWRITTEN AFTER PHASE 7 - BEGIN */
unsigned centerangle;
unsigned offset;
unsigned distance;
int t_topheight;
int t_bottomheight;
int t_texturemid;
int b_bottomheight;
int b_texturemid;
int b_topheight;
/* !!! THE SECTION ABOVE MUST BE LARGE ENOUGH */
/* !!! TO ACCOMODATE VISSPRITE_T STRUCTURE, GETS */
/* !!! OVERWRITTEN AFTER PHASE 7 - END */
int m_texturemid;
VINT m_texturenum;
VINT t_texturenum;
VINT b_texturenum;
VINT floorpicnum;
VINT ceilingpicnum;
int scalestep; /* polar angle to start at phase1, then scalestep after phase2 */
unsigned scalefrac;
unsigned scale2;
short actionbits;
short seglightlevel;
int16_t miplevels[2];
/* */
/* filled in by bsp */
/* */
VINT start, realstart;
VINT stop, realstop; /* inclusive x coordinates */
union
{
seg_t *seg;
mapvertex_t v1;
};
union
{
fixed_t ceilingheight;
mapvertex_t v2;
};
uint16_t *clipbounds;
} viswall_t;
typedef struct
{
fixed_t floorheight, floornewheight, ceilnewheight, pad;
} viswallextra_t;
#define MAXWALLCMDS 150
/* A vissprite_t is a thing that will be drawn during a refresh */
typedef struct vissprite_s
{
VINT x1, x2; /* clipped to screen edges column range */
fixed_t startfrac; /* horizontal position of x1 */
fixed_t xscale;
fixed_t xiscale; /* negative if flipped */
fixed_t yscale;
fixed_t texturemid;
VINT patchnum;
VINT colormap; /* < 0 = shadow draw */
short gx,gy; /* global coordinates */
void *colormaps;
#ifndef MARS
pixel_t *pixels; /* data patch header references */
#endif
} vissprite_t;
#define MAXVISSPRITES MAXWALLCMDS
#define MAXOPENINGS SCREENWIDTH*16
#define MAXVISSSEC 128
typedef struct visplane_s
{
fixed_t height;
VINT minx, maxx;
int flatandlight;
struct visplane_s *next;
unsigned short *open/*[SCREENWIDTH+2]*/; /* top<<8 | bottom */ /* leave pads for [minx-1]/[maxx+1] */
} visplane_t;
#define MAXVISPLANES 32
#define NUM_VISPLANES_BUCKETS 32
void R_MarkOpenPlane(visplane_t* pl)
ATTR_DATA_CACHE_ALIGN
;
visplane_t *R_FindPlane(fixed_t height, int flatandlight,
int start, int stop)
ATTR_DATA_CACHE_ALIGN
;
void R_InitClipBounds(uint32_t *clipbounds)
ATTR_DATA_CACHE_ALIGN
;
#define MAX_COLUMN_LENGTH 128
#if MIPLEVELS > 1
#define COLUMN_CACHE_SIZE MAX_COLUMN_LENGTH * 2
#else
#define COLUMN_CACHE_SIZE MAX_COLUMN_LENGTH
#endif
typedef struct
#ifdef MARS
__attribute__((aligned(16)))
#endif
{
fixed_t viewx, viewy, viewz;
angle_t viewangle;
fixed_t viewcos, viewsin;
player_t *viewplayer;
VINT lightlevel;
VINT extralight;
VINT displayplayer;
VINT fixedcolormap;
VINT fuzzcolormap;
angle_t clipangle, doubleclipangle;
VINT *viewangletox;
/* */
/* walls */
/* */
viswall_t * volatile viswalls/*[MAXWALLCMDS] __attribute__((aligned(16)))*/;
viswall_t * volatile lastwallcmd;
viswallextra_t * volatile viswallextras;
/* */
/* sprites */
/* */
viswall_t * volatile vissprites/*[MAXVISSPRITES]*/, * volatile lastsprite_p, * volatile vissprite_p;
/* */
/* subsectors */
/* */
sector_t **vissectors/*[MAXVISSSEC]*/, **lastvissector;
/* */
/* planes */
/* */
visplane_t * volatile visplanes/*[MAXVISPLANES]*/, * volatile lastvisplane;
int * volatile gsortedvisplanes;
visplane_t * volatile * visplanes_hash;
/* */
/* openings / misc refresh memory */
/* */
unsigned short * volatile segclip, * volatile lastsegclip;
int * volatile gsortedsprites;
uint8_t *columncache[2]; // composite column cache for both CPUs
} viewdef_t;
extern viewdef_t vd;
extern texture_t *testtex;
#endif /* __R_LOCAL__ */