1 // SONIC ROBO BLAST 2
2 //-----------------------------------------------------------------------------
3 // Copyright (C) 1993-1996 by id Software, Inc.
4 // Copyright (C) 1998-2000 by DooM Legacy Team.
5 // Copyright (C) 1999-2020 by Sonic Team Junior.
6 //
7 // This program is free software distributed under the
8 // terms of the GNU General Public License, version 2.
9 // See the 'LICENSE' file for more details.
10 //-----------------------------------------------------------------------------
11 /// \file  r_main.h
12 /// \brief Rendering variables, consvars, defines
13 
14 #ifndef __R_MAIN__
15 #define __R_MAIN__
16 
17 #include "d_player.h"
18 #include "r_data.h"
19 #include "r_textures.h"
20 
21 //
22 // POV related.
23 //
24 extern fixed_t viewcos, viewsin;
25 extern INT32 viewheight;
26 extern INT32 centerx, centery;
27 
28 extern fixed_t centerxfrac, centeryfrac;
29 extern fixed_t projection, projectiony;
30 extern fixed_t fovtan;
31 
32 // WARNING: a should be unsigned but to add with 2048, it isn't!
33 #define AIMINGTODY(a) FixedDiv((FINETANGENT((2048+(((INT32)a)>>ANGLETOFINESHIFT)) & FINEMASK)*160), fovtan)
34 
35 extern size_t validcount, linecount, loopcount, framecount;
36 
37 //
38 // Lighting LUT.
39 // Used for z-depth cuing per column/row,
40 //  and other lighting effects (sector ambient, flash).
41 //
42 
43 // Lighting constants.
44 // Now with 32 levels.
45 #define LIGHTLEVELS 32
46 #define LIGHTSEGSHIFT 3
47 
48 #define MAXLIGHTSCALE 48
49 #define LIGHTSCALESHIFT 12
50 #define MAXLIGHTZ 128
51 #define LIGHTZSHIFT 20
52 
53 #define LIGHTRESOLUTIONFIX (640*fovtan/vid.width)
54 
55 extern lighttable_t *scalelight[LIGHTLEVELS][MAXLIGHTSCALE];
56 extern lighttable_t *scalelightfixed[MAXLIGHTSCALE];
57 extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ];
58 
59 // Number of diminishing brightness levels.
60 // There a 0-31, i.e. 32 LUT in the COLORMAP lump.
61 #define NUMCOLORMAPS 32
62 
63 // Utility functions.
64 INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node);
65 INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line);
66 angle_t R_PointToAngle(fixed_t x, fixed_t y);
67 angle_t R_PointToAngle64(INT64 x, INT64 y);
68 angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1);
69 angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1);
70 fixed_t R_PointToDist(fixed_t x, fixed_t y);
71 fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1);
72 
73 fixed_t R_ScaleFromGlobalAngle(angle_t visangle);
74 subsector_t *R_PointInSubsector(fixed_t x, fixed_t y);
75 subsector_t *R_PointInSubsectorOrNull(fixed_t x, fixed_t y);
76 
77 boolean R_DoCulling(line_t *cullheight, line_t *viewcullheight, fixed_t vz, fixed_t bottomh, fixed_t toph);
78 
79 // Render stats
80 
81 extern precise_t ps_prevframetime;// time when previous frame was rendered
82 extern precise_t ps_rendercalltime;
83 extern precise_t ps_uitime;
84 extern precise_t ps_swaptime;
85 
86 extern precise_t ps_bsptime;
87 
88 extern precise_t ps_sw_spritecliptime;
89 extern precise_t ps_sw_portaltime;
90 extern precise_t ps_sw_planetime;
91 extern precise_t ps_sw_maskedtime;
92 
93 extern int ps_numbspcalls;
94 extern int ps_numsprites;
95 extern int ps_numdrawnodes;
96 extern int ps_numpolyobjects;
97 
98 //
99 // REFRESH - the actual rendering functions.
100 //
101 
102 extern consvar_t cv_showhud, cv_translucenthud;
103 extern consvar_t cv_homremoval;
104 extern consvar_t cv_chasecam, cv_chasecam2;
105 extern consvar_t cv_flipcam, cv_flipcam2;
106 
107 extern consvar_t cv_shadow;
108 extern consvar_t cv_ffloorclip;
109 extern consvar_t cv_translucency;
110 extern consvar_t cv_drawdist, cv_drawdist_nights, cv_drawdist_precip;
111 extern consvar_t cv_fov;
112 extern consvar_t cv_skybox;
113 extern consvar_t cv_tailspickup;
114 
115 // Called by startup code.
116 void R_Init(void);
117 
118 void R_CheckViewMorph(void);
119 void R_ApplyViewMorph(void);
120 
121 // just sets setsizeneeded true
122 extern boolean setsizeneeded;
123 void R_SetViewSize(void);
124 
125 // do it (sometimes explicitly called)
126 void R_ExecuteSetViewSize(void);
127 
128 void R_SetupFrame(player_t *player);
129 void R_SkyboxFrame(player_t *player);
130 
131 boolean R_ViewpointHasChasecam(player_t *player);
132 boolean R_IsViewpointThirdPerson(player_t *player, boolean skybox);
133 
134 // Called by D_Display.
135 void R_RenderPlayerView(player_t *player);
136 
137 // add commands related to engine, at game startup
138 void R_RegisterEngineStuff(void);
139 #endif
140