1 /*
2 	r_cvar.c
3 
4 	renderer cvar definitions
5 
6 	Copyright (C) 2000       Bill Currie
7 	                         Ragnvald Maartmann-Moe IV
8 
9 	Author: Bill Currie
10 	        Ragnvald Maartmann-Moe IV
11 	Date: 2001/5/17
12 
13 	This program is free software; you can redistribute it and/or
14 	modify it under the terms of the GNU General Public License
15 	as published by the Free Software Foundation; either version 2
16 	of the License, or (at your option) any later version.
17 
18 	This program is distributed in the hope that it will be useful,
19 	but WITHOUT ANY WARRANTY; without even the implied warranty of
20 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 
22 	See the GNU General Public License for more details.
23 
24 	You should have received a copy of the GNU General Public License
25 	along with this program; if not, write to:
26 
27 		Free Software Foundation, Inc.
28 		59 Temple Place - Suite 330
29 		Boston, MA  02111-1307, USA
30 
31 */
32 #ifdef HAVE_CONFIG_H
33 # include "config.h"
34 #endif
35 
36 #include "QF/cvar.h"
37 #include "QF/model.h"
38 #include "QF/qendian.h"
39 #include "QF/render.h"
40 
41 #include "compat.h"
42 #include "r_internal.h"
43 
44 cvar_t	   *easter_eggs;
45 
46 cvar_t     *cl_crossx;
47 cvar_t     *cl_crossy;
48 cvar_t     *cl_verstring;
49 cvar_t     *crosshair;
50 cvar_t     *crosshaircolor;
51 
52 cvar_t     *d_mipcap;
53 cvar_t     *d_mipscale;
54 
55 cvar_t     *r_aliasstats;
56 cvar_t     *r_aliastransadj;
57 cvar_t     *r_aliastransbase;
58 cvar_t     *r_ambient;
59 cvar_t     *r_clearcolor;
60 cvar_t     *r_dlight_lightmap;
61 cvar_t	   *r_dlight_max;
62 cvar_t     *r_drawentities;
63 cvar_t     *r_drawexplosions;
64 cvar_t     *r_drawflat;
65 cvar_t     *r_drawviewmodel;
66 cvar_t     *r_dspeeds;
67 cvar_t     *r_dynamic;
68 cvar_t     *r_explosionclip;
69 cvar_t     *r_farclip;
70 cvar_t     *r_firecolor;
71 cvar_t     *r_flatlightstyles;
72 cvar_t     *r_graphheight;
73 cvar_t     *r_lightmap_components;
74 cvar_t     *r_maxedges;
75 cvar_t     *r_maxsurfs;
76 cvar_t     *r_mirroralpha;
77 cvar_t	   *r_nearclip;
78 cvar_t     *r_norefresh;
79 cvar_t     *r_novis;
80 cvar_t     *r_numedges;
81 cvar_t     *r_numsurfs;
82 cvar_t     *r_particles;
83 cvar_t	   *r_particles_style;
84 cvar_t	   *r_particles_max;
85 cvar_t	   *r_particles_nearclip;
86 cvar_t     *r_reportedgeout;
87 cvar_t     *r_reportsurfout;
88 cvar_t     *r_shadows;
89 cvar_t     *r_skyname;
90 cvar_t     *r_speeds;
91 cvar_t     *r_timegraph;
92 cvar_t     *r_wateralpha;
93 cvar_t     *r_waterripple;
94 cvar_t     *r_waterwarp;
95 cvar_t     *r_zgraph;
96 
97 cvar_t     *scr_fov;
98 cvar_t     *scr_fisheye;
99 cvar_t     *scr_fviews;
100 cvar_t     *scr_ffov;
101 cvar_t     *scr_showpause;
102 cvar_t     *scr_showram;
103 cvar_t     *scr_showturtle;
104 cvar_t     *scr_viewsize;
105 
106 int         r_viewsize;
107 
108 quat_t      crosshair_color;
109 
110 static void
crosshaircolor_f(cvar_t * var)111 crosshaircolor_f (cvar_t *var)
112 {
113 	byte       *color;
114 	color = (byte *) &d_8to24table[bound (0, var->int_val, 255)];
115 	QuatScale (color, 1.0 / 255, crosshair_color);
116 }
117 
118 static void
r_lightmap_components_f(cvar_t * var)119 r_lightmap_components_f (cvar_t *var)
120 {
121 	switch (var->int_val) {
122 		case 1:
123 			mod_lightmap_bytes = 1;
124 			break;
125 		case 3:
126 		case 4:
127 		default:
128 			mod_lightmap_bytes = 3;
129 			break;
130 	}
131 }
132 
133 static void
r_farclip_f(cvar_t * var)134 r_farclip_f (cvar_t *var)
135 {
136 	Cvar_SetValue (r_farclip, bound (8.0, var->value, Q_MAXFLOAT));
137 	if (r_particles_nearclip && r_nearclip)
138 		Cvar_SetValue (r_particles_nearclip,
139 					   bound (r_nearclip->value, r_particles_nearclip->value,
140 							  r_farclip->value));
141 	vid.recalc_refdef = true;
142 }
143 
144 static void
r_nearclip_f(cvar_t * var)145 r_nearclip_f (cvar_t *var)
146 {
147 	Cvar_SetValue (r_nearclip, bound (0.01, var->value, 4.0));
148 	if (r_particles_nearclip && r_farclip)
149 		Cvar_SetValue (r_particles_nearclip,
150 					   bound (r_nearclip->value, r_particles_nearclip->value,
151 							  r_farclip->value));
152 	vid.recalc_refdef = true;
153 }
154 
155 static void
scr_fisheye_f(cvar_t * var)156 scr_fisheye_f (cvar_t *var)
157 {
158 	if (var->int_val)
159 		Cvar_Set (scr_fov, "90");
160 }
161 
162 static void
scr_ffov_f(cvar_t * var)163 scr_ffov_f (cvar_t *var)
164 {
165 	if (var->value < 130)
166 		Cvar_Set (scr_fviews, "3");
167 	else if (var->value < 220)
168 		Cvar_Set (scr_fviews, "5");
169 	else
170 		Cvar_Set (scr_fviews, "6");
171 }
172 
173 static void
viewsize_f(cvar_t * var)174 viewsize_f (cvar_t *var)
175 {
176 	if (var->int_val < 30 || var->int_val > 120) {
177 		Cvar_SetValue (var, bound (30, var->int_val, 120));
178 	} else {
179 		vid.recalc_refdef = true;
180 		r_viewsize = bound (0, var->int_val, 100);
181 		if (vr_data.viewsize_callback)
182 			vr_data.viewsize_callback (var);
183 	}
184 }
185 
186 void
R_Init_Cvars(void)187 R_Init_Cvars (void)
188 {
189 	cl_crossx = Cvar_Get ("cl_crossx", "0", CVAR_ARCHIVE, NULL,
190 						  "Sets the position of the crosshair on the X-axis.");
191 	cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ARCHIVE, NULL,
192 						  "Sets the position of the crosshair on the Y-axis.");
193 	cl_verstring = Cvar_Get ("cl_verstring", PACKAGE_VERSION, CVAR_NONE,
194 							 NULL, "Client version string");
195 	crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL, "Crosshair "
196 						  "type. 0 off, 1 old white, 2 new with colors");
197 	crosshaircolor = Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE,
198 							   crosshaircolor_f, "Color of the new crosshair");
199 	d_mipcap = Cvar_Get ("d_mipcap", "0", CVAR_NONE, NULL,
200 						 "Detail level. 0 is highest, 3 is lowest.");
201 	d_mipscale = Cvar_Get ("d_mipscale", "1", CVAR_NONE, NULL, "Detail level "
202 						   "of objects. 0 is highest, 3 is lowest.");
203 	r_aliasstats = Cvar_Get ("r_polymodelstats", "0", CVAR_NONE, NULL,
204 							 "Toggles the displays of number of polygon "
205 							 "models current being viewed");
206 	r_aliastransadj = Cvar_Get ("r_aliastransadj", "100", CVAR_NONE, NULL,
207 								"Determines how much of an alias model is "
208 								"clipped away and how much is viewable.");
209 	r_aliastransbase = Cvar_Get ("r_aliastransbase", "200", CVAR_NONE, NULL,
210 								 "Determines how much of an alias model is "
211 								 "clipped away and how much is viewable");
212 	r_ambient = Cvar_Get ("r_ambient", "0", CVAR_NONE, NULL,
213 						  "Determines the ambient lighting for a level");
214 	r_clearcolor = Cvar_Get ("r_clearcolor", "2", CVAR_NONE, NULL,
215 							 "This sets the color for areas outside of the "
216 							 "current map");
217 	r_dlight_lightmap = Cvar_Get ("r_dlight_lightmap", "1", CVAR_ARCHIVE,
218 								  NULL, "Set to 1 for high quality dynamic "
219 								  "lighting.");
220 	r_dlight_max = Cvar_Get ("r_dlight_max", "32", CVAR_ARCHIVE,
221 							 R_MaxDlightsCheck, "Number of dynamic lights.");
222 	r_drawentities = Cvar_Get ("r_drawentities", "1", CVAR_NONE, NULL,
223 							   "Toggles drawing of entities (almost "
224 							   "everything but the world)");
225 	r_drawexplosions = Cvar_Get ("r_drawexplosions", "1", CVAR_ARCHIVE, NULL,
226 								 "Draw explosions.");
227 	r_drawflat = Cvar_Get ("r_drawflat", "0", CVAR_NONE, NULL,
228 						   "Toggles the drawing of textures");
229 	r_drawviewmodel = Cvar_Get ("r_drawviewmodel", "1", CVAR_ARCHIVE, NULL,
230 								"Toggles view model drawing (your weapons)");
231 	r_dspeeds = Cvar_Get ("r_dspeeds", "0", CVAR_NONE, NULL,
232 						  "Toggles the display of drawing speed information");
233 	r_dynamic = Cvar_Get ("r_dynamic", "1", CVAR_NONE, NULL,
234 						  "Set to 0 to disable lightmap changes");
235 	r_explosionclip = Cvar_Get ("r_explosionclip", "0", CVAR_ARCHIVE, NULL,
236 								"Clip explosions.");
237 	r_farclip = Cvar_Get ("r_farclip", "4096", CVAR_ARCHIVE, r_farclip_f,
238 						  "Distance of the far clipping plane from the "
239 						  "player.");
240 	r_firecolor = Cvar_Get ("r_firecolor", "0.9 0.7 0.0", CVAR_ARCHIVE, NULL,
241 							"color of rocket and lava ball fires");
242 	r_flatlightstyles = Cvar_Get ("r_flatlightstyles", "0", CVAR_NONE, NULL,
243 								  "Disable animated lightmaps. 2 = use peak, "
244 								  "1 = use average, anything else = normal");
245 	r_graphheight = Cvar_Get ("r_graphheight", "32", CVAR_NONE, NULL,
246 							  "Set the number of lines displayed in the "
247 							  "various graphs");
248 	r_lightmap_components = Cvar_Get ("r_lightmap_components", "3", CVAR_ROM,
249 									  r_lightmap_components_f,
250 									  "Lightmap texture components. 1 "
251 									  "is greyscale, 3 is RGB, 4 is RGBA.");
252 	r_maxedges = Cvar_Get ("r_maxedges", "0", CVAR_NONE, NULL,
253 						   "Sets the maximum number of edges");
254 	r_maxsurfs = Cvar_Get ("r_maxsurfs", "0", CVAR_NONE, NULL,
255 						   "Sets the maximum number of surfaces");
256 	r_mirroralpha = Cvar_Get ("r_mirroralpha", "1", CVAR_NONE, NULL, "None");
257 	r_nearclip = Cvar_Get ("r_nearclip", "4", CVAR_ARCHIVE, r_nearclip_f,
258 						   "Distance of the near clipping plane from the "
259 						   "player.");
260 	r_norefresh = Cvar_Get ("r_norefresh_", "0", CVAR_NONE, NULL,
261 							"Set to 1 to disable display refresh");
262 	r_novis = Cvar_Get ("r_novis", "0", CVAR_NONE, NULL, "Set to 1 to enable "
263 						"runtime visibility checking (SLOW)");
264 	r_numedges = Cvar_Get ("r_numedges", "0", CVAR_NONE, NULL,
265 						   "Toggles the displaying of number of edges "
266 						   "currently being viewed");
267 	r_numsurfs = Cvar_Get ("r_numsurfs", "0", CVAR_NONE, NULL,
268 						   "Toggles the displaying of number of surfaces "
269 						   "currently being viewed");
270 	r_reportedgeout = Cvar_Get ("r_reportedgeout", "0", CVAR_NONE, NULL,
271 								"Toggle the display of how many edges were "
272 								"not displayed");
273 	r_reportsurfout = Cvar_Get ("r_reportsurfout", "0", CVAR_NONE, NULL,
274 								"Toggle the display of how many surfaces "
275 								"were not displayed");
276 	r_shadows = Cvar_Get ("r_shadows", "0", CVAR_ARCHIVE, NULL,
277 						  "Set to 1 to enable shadows for entities");
278 	r_skyname = Cvar_Get ("r_skyname", "none", CVAR_NONE, NULL,
279 						  "name of the current skybox");
280 	r_speeds = Cvar_Get ("r_speeds", "0", CVAR_NONE, NULL, "Display drawing "
281 						 "time and statistics of what is being viewed");
282 	r_timegraph = Cvar_Get ("r_timegraph", "0", CVAR_NONE, NULL,
283 							"Toggle the display of a performance graph");
284 	r_wateralpha = Cvar_Get ("r_wateralpha", "1", CVAR_ARCHIVE, NULL,
285 							 "Determine the opacity of liquids. 1 = opaque, "
286 							 "0 = transparent, otherwise translucent.");
287 	r_waterripple = Cvar_Get ("r_waterripple", "0", CVAR_NONE, NULL,
288 							  "Set to make liquids ripple, try setting to 5");
289 	r_waterwarp = Cvar_Get ("r_waterwarp", "1", CVAR_NONE, NULL,
290 							"Toggles whether surfaces are warped in liquid.");
291 	r_zgraph = Cvar_Get ("r_zgraph", "0", CVAR_NONE, NULL,
292 						 "Toggle the graph that reports the changes of "
293 						 "z-axis position");
294 	scr_fov = Cvar_Get ("fov", "90", CVAR_NONE, NULL, "Your field of view in "
295 						"degrees. Smaller than 90 zooms in. Don't touch in "
296 						"fisheye mode, use ffov instead.");
297 	scr_fisheye = Cvar_Get ("fisheye", "0", CVAR_NONE, scr_fisheye_f,
298 							"Toggles fisheye mode.");
299 	scr_fviews = Cvar_Get ("fviews", "6", CVAR_NONE, NULL, "The number of "
300 						   "fisheye views.");
301 	scr_ffov = Cvar_Get ("ffov", "180", CVAR_NONE, scr_ffov_f, "Your field of "
302 						 "view in degrees in fisheye mode.");
303 	scr_showpause = Cvar_Get ("showpause", "1", CVAR_NONE, NULL,
304 							  "Toggles display of pause graphic");
305 	scr_showram = Cvar_Get ("showram", "1", CVAR_NONE, NULL,
306 							"Show RAM icon if game is running low on memory");
307 	scr_showturtle = Cvar_Get ("showturtle", "0", CVAR_NONE, NULL,
308 							   "Show a turtle icon if your fps is below 10");
309 	scr_viewsize = Cvar_Get ("viewsize", "100", CVAR_ARCHIVE, viewsize_f,
310 							 "Set the screen size 30 minimum, 120 maximum");
311 
312 	vr_data.graphheight = r_graphheight;
313 	vr_data.scr_viewsize = scr_viewsize;
314 }
315