2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 void R_CheckVariables (void)
33 static float oldbright
;
35 if (r_fullbright
.value
!= oldbright
)
37 oldbright
= r_fullbright
.value
;
38 D_FlushCaches (); // so all lighting changes
56 vr
.height
= vid
.height
;
66 For program optimization
69 void R_TimeRefresh_f (void)
72 float start
, stop
, time
;
76 startangle
= r_refdef
.viewangles
[1];
78 start
= Sys_FloatTime ();
79 for (i
=0 ; i
<128 ; i
++)
81 r_refdef
.viewangles
[1] = i
/128.0*360.0;
89 vr
.x
= r_refdef
.vrect
.x
;
90 vr
.y
= r_refdef
.vrect
.y
;
91 vr
.width
= r_refdef
.vrect
.width
;
92 vr
.height
= r_refdef
.vrect
.height
;
96 stop
= Sys_FloatTime ();
98 Con_Printf ("%f seconds (%f fps)\n", time
, 128/time
);
100 r_refdef
.viewangles
[1] = startangle
;
108 Only called by R_DisplayTime
111 void R_LineGraph (int x
, int y
, int h
)
117 // FIXME: should be disabled on no-buffer adapters, or should be in the driver
119 x
+= r_refdef
.vrect
.x
;
120 y
+= r_refdef
.vrect
.y
;
122 dest
= vid
.buffer
+ vid
.rowbytes
*y
+ x
;
124 s
= r_graphheight
.value
;
129 for (i
=0 ; i
<h
; i
++, dest
-= vid
.rowbytes
*2)
132 *(dest
-vid
.rowbytes
) = 0x30;
134 for ( ; i
<s
; i
++, dest
-= vid
.rowbytes
*2)
137 *(dest
-vid
.rowbytes
) = 0x30;
145 Performance monitoring tool
148 #define MAX_TIMINGS 100
149 extern float mouse_x
, mouse_y
;
150 void R_TimeGraph (void)
155 static byte r_timings
[MAX_TIMINGS
];
158 r_time2
= Sys_FloatTime ();
160 a
= (r_time2
-r_time1
)/0.01;
161 //a = fabs(mouse_y * 0.05);
162 //a = (int)((r_refdef.vieworg[2] + 1024)/1)%(int)r_graphheight.value;
163 //a = fabs(velocity[0])/20;
164 //a = ((int)fabs(origin[0])/8)%20;
165 //a = (cl.idealpitch + 30)/5;
166 r_timings
[timex
] = a
;
169 if (r_refdef
.vrect
.width
<= MAX_TIMINGS
)
170 x
= r_refdef
.vrect
.width
-1;
172 x
= r_refdef
.vrect
.width
-
173 (r_refdef
.vrect
.width
- MAX_TIMINGS
)/2;
176 R_LineGraph (x
, r_refdef
.vrect
.height
-2, r_timings
[a
]);
178 break; // screen too small to hold entire thing
183 } while (a
!= timex
);
185 timex
= (timex
+1)%MAX_TIMINGS
;
194 void R_PrintTimes (void)
199 r_time2
= Sys_FloatTime ();
201 ms
= 1000* (r_time2
- r_time1
);
203 Con_Printf ("%5.1f ms %3i/%3i/%3i poly %3i surf\n",
204 ms
, c_faceclip
, r_polycount
, r_drawnpolycount
, c_surf
);
214 void R_PrintDSpeeds (void)
216 float ms
, dp_time
, r_time2
, rw_time
, db_time
, se_time
, de_time
, dv_time
;
218 r_time2
= Sys_FloatTime ();
220 dp_time
= (dp_time2
- dp_time1
) * 1000;
221 rw_time
= (rw_time2
- rw_time1
) * 1000;
222 db_time
= (db_time2
- db_time1
) * 1000;
223 se_time
= (se_time2
- se_time1
) * 1000;
224 de_time
= (de_time2
- de_time1
) * 1000;
225 dv_time
= (dv_time2
- dv_time1
) * 1000;
226 ms
= (r_time2
- r_time1
) * 1000;
228 Con_Printf ("%3i %4.1fp %3iw %4.1fb %3is %4.1fe %4.1fv\n",
229 (int)ms
, dp_time
, (int)rw_time
, db_time
, (int)se_time
, de_time
,
239 void R_PrintAliasStats (void)
241 Con_Printf ("%3i polygon model drawn\n", r_amodels_drawn
);
245 void WarpPalette (void)
248 byte newpalette
[768];
255 // pull the colors halfway to bright brown
256 for (i
=0 ; i
<256 ; i
++)
258 for (j
=0 ; j
<3 ; j
++)
260 newpalette
[i
*3+j
] = (host_basepal
[i
*3+j
] + basecolor
[j
])/2;
264 VID_ShiftPalette (newpalette
);
273 void R_TransformFrustum (void)
278 for (i
=0 ; i
<4 ; i
++)
280 v
[0] = screenedge
[i
].normal
[2];
281 v
[1] = -screenedge
[i
].normal
[0];
282 v
[2] = screenedge
[i
].normal
[1];
284 v2
[0] = v
[1]*vright
[0] + v
[2]*vup
[0] + v
[0]*vpn
[0];
285 v2
[1] = v
[1]*vright
[1] + v
[2]*vup
[1] + v
[0]*vpn
[1];
286 v2
[2] = v
[1]*vright
[2] + v
[2]*vup
[2] + v
[0]*vpn
[2];
288 VectorCopy (v2
, view_clipplanes
[i
].normal
);
290 view_clipplanes
[i
].dist
= DotProduct (modelorg
, v2
);
302 void TransformVector (vec3_t in
, vec3_t out
)
304 out
[0] = DotProduct(in
,vright
);
305 out
[1] = DotProduct(in
,vup
);
306 out
[2] = DotProduct(in
,vpn
);
317 void R_TransformPlane (mplane_t
*p
, float *normal
, float *dist
)
321 d
= DotProduct (r_origin
, p
->normal
);
323 // TODO: when we have rotating entities, this will need to use the view matrix
324 TransformVector (p
->normal
, normal
);
330 R_SetUpFrustumIndexes
333 void R_SetUpFrustumIndexes (void)
337 pindex
= r_frustum_indexes
;
339 for (i
=0 ; i
<4 ; i
++)
341 for (j
=0 ; j
<3 ; j
++)
343 if (view_clipplanes
[i
].normal
[j
] < 0)
355 // FIXME: do just once at start
356 pfrustum_indexes
[i
] = pindex
;
367 void R_SetupFrame (void)
373 // don't allow cheats in multiplayer
374 if (cl
.maxclients
> 1)
376 Cvar_Set ("r_draworder", "0");
377 Cvar_Set ("r_fullbright", "0");
378 Cvar_Set ("r_ambient", "0");
379 Cvar_Set ("r_drawflat", "0");
382 if (r_numsurfs
.value
)
384 if ((surface_p
- surfaces
) > r_maxsurfsseen
)
385 r_maxsurfsseen
= surface_p
- surfaces
;
387 Con_Printf ("Used %d of %d surfs; %d max\n", surface_p
- surfaces
,
388 surf_max
- surfaces
, r_maxsurfsseen
);
391 if (r_numedges
.value
)
393 edgecount
= edge_p
- r_edges
;
395 if (edgecount
> r_maxedgesseen
)
396 r_maxedgesseen
= edgecount
;
398 Con_Printf ("Used %d of %d edges; %d max\n", edgecount
,
399 r_numallocatededges
, r_maxedgesseen
);
402 r_refdef
.ambientlight
= r_ambient
.value
;
404 if (r_refdef
.ambientlight
< 0)
405 r_refdef
.ambientlight
= 0;
408 r_draworder
.value
= 0; // don't let cheaters look behind walls
420 r_refdef
.vieworg
[0]= 80;
421 r_refdef
.vieworg
[1]= 64;
422 r_refdef
.vieworg
[2]= 40;
423 r_refdef
.viewangles
[0]= 0;
424 r_refdef
.viewangles
[1]= 46.763641357;
425 r_refdef
.viewangles
[2]= 0;
428 // build the transformation matrix for the given view angles
429 VectorCopy (r_refdef
.vieworg
, modelorg
);
430 VectorCopy (r_refdef
.vieworg
, r_origin
);
432 AngleVectors (r_refdef
.viewangles
, vpn
, vright
, vup
);
435 r_oldviewleaf
= r_viewleaf
;
436 r_viewleaf
= Mod_PointInLeaf (r_origin
, cl
.worldmodel
);
438 r_dowarpold
= r_dowarp
;
439 r_dowarp
= r_waterwarp
.value
&& (r_viewleaf
->contents
<= CONTENTS_WATER
);
441 if ((r_dowarp
!= r_dowarpold
) || r_viewchanged
|| lcd_x
.value
)
445 if ((vid
.width
<= vid
.maxwarpwidth
) &&
446 (vid
.height
<= vid
.maxwarpheight
))
450 vrect
.width
= vid
.width
;
451 vrect
.height
= vid
.height
;
453 R_ViewChanged (&vrect
, sb_lines
, vid
.aspect
);
460 if (w
> vid
.maxwarpwidth
)
462 h
*= (float)vid
.maxwarpwidth
/ w
;
463 w
= vid
.maxwarpwidth
;
466 if (h
> vid
.maxwarpheight
)
468 h
= vid
.maxwarpheight
;
469 w
*= (float)vid
.maxwarpheight
/ h
;
474 vrect
.width
= (int)w
;
475 vrect
.height
= (int)h
;
477 R_ViewChanged (&vrect
,
478 (int)((float)sb_lines
* (h
/(float)vid
.height
)),
479 vid
.aspect
* (h
/ w
) *
480 ((float)vid
.width
/ (float)vid
.height
));
487 vrect
.width
= vid
.width
;
488 vrect
.height
= vid
.height
;
490 R_ViewChanged (&vrect
, sb_lines
, vid
.aspect
);
493 r_viewchanged
= false;
496 // start off with just the four screen edge clip planes
497 R_TransformFrustum ();
500 VectorCopy (vpn
, base_vpn
);
501 VectorCopy (vright
, base_vright
);
502 VectorCopy (vup
, base_vup
);
503 VectorCopy (modelorg
, base_modelorg
);
507 R_SetUpFrustumIndexes ();
509 r_cache_thrash
= false;
511 // clear frame counts
515 r_drawnpolycount
= 0;
516 r_wholepolycount
= 0;