Debian Codegraph @

code/client/cl_scrn.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 // cl_scrn.c -- master for refresh, status bar, console, chat, notify, etc
23
24 #include "client.h"
25
26 qboolean scr_initialized; // ready to draw
27
28 cvar_t *cl_timegraph;
29 cvar_t *cl_debuggraph;
30 cvar_t *cl_graphheight;
31 cvar_t *cl_graphscale;
32 cvar_t *cl_graphshift;
33
34 /*
35 ================
36 SCR_DrawNamedPic
37
38 Coordinates are 640*480 virtual values
39 =================
40 */
41 void SCR_DrawNamedPic( float x, float y, float width, float height, const char *picname ) {
42 qhandle_t hShader;
43
44 assert( width != 0 );
45
46 hShader = re.RegisterShader( picname );
47 SCR_AdjustFrom640( &x, &y, &width, &height );
48 re.DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
49 }
50
51
52 /*
53 ================
54 SCR_AdjustFrom640
55
56 Adjusted for resolution and screen aspect ratio
57 ================
58 */
59 void SCR_AdjustFrom640( float *x, float *y, float *w, float *h ) {
60 float xscale;
61 float yscale;
62
63 #if 0
64 // adjust for wide screens
65 if ( cls.glconfig.vidWidth * 480 > cls.glconfig.vidHeight * 640 ) {
66 *x += 0.5 * ( cls.glconfig.vidWidth - ( cls.glconfig.vidHeight * 640 / 480 ) );
67 }
68 #endif
69
70 // scale for screen sizes
71 xscale = cls.glconfig.vidWidth / 640.0;
72 yscale = cls.glconfig.vidHeight / 480.0;
73 if ( x ) {
74 *x *= xscale;
75 }
76 if ( y ) {
77 *y *= yscale;
78 }
79 if ( w ) {
80 *w *= xscale;
81 }
82 if ( h ) {
83 *h *= yscale;
84 }
85 }
86
87 /*
88 ================
89 SCR_FillRect
90
91 Coordinates are 640*480 virtual values
92 =================
93 */
94 void SCR_FillRect( float x, float y, float width, float height, const float *color ) {
95 re.SetColor( color );
96
97 SCR_AdjustFrom640( &x, &y, &width, &height );
98 re.DrawStretchPic( x, y, width, height, 0, 0, 0, 0, cls.whiteShader );
99
100 re.SetColor( NULL );
101 }
102
103
104 /*
105 ================
106 SCR_DrawPic
107
108 Coordinates are 640*480 virtual values
109 =================
110 */
111 void SCR_DrawPic( float x, float y, float width, float height, qhandle_t hShader ) {
112 SCR_AdjustFrom640( &x, &y, &width, &height );
113 re.DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
114 }
115
116
117
118 /*
119 ** SCR_DrawChar
120 ** chars are drawn at 640*480 virtual screen size
121 */
122 static void SCR_DrawChar( int x, int y, float size, int ch ) {
123 int row, col;
124 float frow, fcol;
125 float ax, ay, aw, ah;
126
127 ch &= 255;
128
129 if ( ch == ' ' ) {
130 return;
131 }
132
133 if ( y < -size ) {
134 return;
135 }
136
137 ax = x;
138 ay = y;
139 aw = size;
140 ah = size;
141 SCR_AdjustFrom640( &ax, &ay, &aw, &ah );
142
143 row = ch>>4;
144 col = ch&15;
145
146 frow = row*0.0625;
147 fcol = col*0.0625;
148 size = 0.0625;
149
150 re.DrawStretchPic( ax, ay, aw, ah,
151 fcol, frow,
152 fcol + size, frow + size,
153 cls.charSetShader );
154 }
155
156 /*
157 ** SCR_DrawSmallChar
158 ** small chars are drawn at native screen resolution
159 */
160 void SCR_DrawSmallChar( int x, int y, int ch ) {
161 int row, col;
162 float frow, fcol;
163 float size;
164
165 ch &= 255;
166
167 if ( ch == ' ' ) {
168 return;
169 }
170
171 if ( y < -g_smallchar_height ) {
172 return;
173 }
174
175 row = ch>>4;
176 col = ch&15;
177
178 frow = row*0.0625;
179 fcol = col*0.0625;
180 size = 0.0625;
181
182 re.DrawStretchPic( x, y, g_smallchar_width, g_smallchar_height,
183 fcol, frow,
184 fcol + size, frow + size,
185 cls.charSetShader );
186 }
187
188
189 /*
190 ==================
191 SCR_DrawBigString[Color]
192
193 Draws a multi-colored string with a drop shadow, optionally forcing
194 to a fixed color.
195
196 Coordinates are at 640 by 480 virtual resolution
197 ==================
198 */
199 void SCR_DrawStringExt( int x, int y, float size, const char *string, float *setColor, qboolean forceColor,
200 qboolean noColorEscape ) {
201 vec4_t color;
202 const char *s;
203 int xx;
204
205 // draw the drop shadow
206 color[0] = color[1] = color[2] = 0;
207 color[3] = setColor[3];
208 re.SetColor( color );
209 s = string;
210 xx = x;
211 while ( *s ) {
212 if ( !noColorEscape && Q_IsColorString( s ) ) {
213 s += 2;
214 continue;
215 }
216 SCR_DrawChar( xx+2, y+2, size, *s );
217 xx += size;
218 s++;
219 }
220
221
222 // draw the colored text
223 s = string;
224 xx = x;
225 re.SetColor( setColor );
226 while ( *s ) {
227 if ( Q_IsColorString( s ) ) {
228 if ( !forceColor ) {
229 Com_Memcpy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ) );
230 color[3] = setColor[3];
231 re.SetColor( color );
232 }
233 if ( !noColorEscape ) {
234 s += 2;
235 continue;
236 }
237 }
238 SCR_DrawChar( xx, y, size, *s );
239 xx += size;
240 s++;
241 }
242 re.SetColor( NULL );
243 }
244
245
246 void SCR_DrawBigString( int x, int y, const char *s, float alpha, qboolean noColorEscape ) {
247 float color[4];
248
249 color[0] = color[1] = color[2] = 1.0;
250 color[3] = alpha;
251 SCR_DrawStringExt( x, y, BIGCHAR_WIDTH, s, color, qfalse, noColorEscape );
252 }
253
254 void SCR_DrawBigStringColor( int x, int y, const char *s, vec4_t color, qboolean noColorEscape ) {
255 SCR_DrawStringExt( x, y, BIGCHAR_WIDTH, s, color, qtrue, noColorEscape );
256 }
257
258
259 /*
260 ==================
261 SCR_DrawSmallString[Color]
262
263 Draws a multi-colored string with a drop shadow, optionally forcing
264 to a fixed color.
265 ==================
266 */
267 void SCR_DrawSmallStringExt( int x, int y, const char *string, float *setColor, qboolean forceColor,
268 qboolean noColorEscape ) {
269 vec4_t color;
270 const char *s;
271 int xx;
272
273 // draw the colored text
274 s = string;
275 xx = x;
276 re.SetColor( setColor );
277 while ( *s ) {
278 if ( Q_IsColorString( s ) ) {
279 if ( !forceColor ) {
280 Com_Memcpy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ) );
281 color[3] = setColor[3];
282 re.SetColor( color );
283 }
284 if ( !noColorEscape ) {
285 s += 2;
286 continue;
287 }
288 }
289 SCR_DrawSmallChar( xx, y, *s );
290 xx += g_smallchar_width;
291 s++;
292 }
293 re.SetColor( NULL );
294 }
295
296
297
298 /*
299 ** SCR_Strlen -- skips color escape codes
300 */
301 static int SCR_Strlen( const char *str ) {
302 const char *s = str;
303 int count = 0;
304
305 while ( *s ) {
306 if ( Q_IsColorString( s ) ) {
307 s += 2;
308 } else {
309 count++;
310 s++;
311 }
312 }
313
314 return count;
315 }
316
317 /*
318 ** SCR_GetBigStringWidth
319 */
320 int SCR_GetBigStringWidth( const char *str ) {
321 return SCR_Strlen( str ) * BIGCHAR_WIDTH;
322 }
323
324
325 //===============================================================================
326
327 /*
328 =================
329 SCR_DrawDemoRecording
330 =================
331 */
332 void SCR_DrawDemoRecording( void ) {
333 char string[1024];
334 int pos;
335
336 if ( !clc.demorecording ) {
337 return;
338 }
339 if ( clc.spDemoRecording ) {
340 return;
341 }
342
343 pos = FS_FTell( clc.demofile );
344 sprintf( string, "RECORDING %s: %ik", clc.demoName, pos / 1024 );
345
346 SCR_DrawStringExt( 320 - strlen( string ) * 4, 20, 8, string, g_color_table[7], qtrue, qfalse );
347 }
348
349
350 #ifdef USE_VOIP
351 /*
352 =================
353 SCR_DrawVoipMeter
354 =================
355 */
356 void SCR_DrawVoipMeter( void ) {
357 char buffer[16];
358 char string[256];
359 int limit, i;
360
361 if (!cl_voipShowMeter->integer)
362 return; // player doesn't want to show meter at all.
363 else if (!cl_voipSend->integer)
364 return; // not recording at the moment.
365 else if (clc.state != CA_ACTIVE)
366 return; // not connected to a server.
367 else if (!clc.voipEnabled)
368 return; // server doesn't support VoIP.
369 else if (clc.demoplaying)
370 return; // playing back a demo.
371 else if (!cl_voip->integer)
372 return; // client has VoIP support disabled.
373
374 limit = (int) (clc.voipPower * 10.0f);
375 if (limit > 10)
376 limit = 10;
377
378 for (i = 0; i < limit; i++)
379 buffer[i] = '*';
380 while (i < 10)
381 buffer[i++] = ' ';
382 buffer[i] = '\0';
383
384 sprintf( string, "VoIP: [%s]", buffer );
385 SCR_DrawStringExt( 320 - strlen( string ) * 4, 10, 8, string, g_color_table[7], qtrue, qfalse );
386 }
387 #endif
388
389
390
391
392 /*
393 ===============================================================================
394
395 DEBUG GRAPH
396
397 ===============================================================================
398 */
399
400 static int current;
401 static float values[1024];
402
403 /*
404 ==============
405 SCR_DebugGraph
406 ==============
407 */
408 void SCR_DebugGraph (float value)
409 {
410 values[current] = value;
411 current = (current + 1) % ARRAY_LEN(values);
412 }
413
414 /*
415 ==============
416 SCR_DrawDebugGraph
417 ==============
418 */
419 void SCR_DrawDebugGraph (void)
420 {
421 int a, x, y, w, i, h;
422 float v;
423
424 //
425 // draw the graph
426 //
427 w = cls.glconfig.vidWidth;
428 x = 0;
429 y = cls.glconfig.vidHeight;
430 re.SetColor( g_color_table[0] );
431 re.DrawStretchPic(x, y - cl_graphheight->integer,
432 w, cl_graphheight->integer, 0, 0, 0, 0, cls.whiteShader );
433 re.SetColor( NULL );
434
435 for (a=0 ; a<w ; a++)
436 {
437 i = (ARRAY_LEN(values)+current-1-(a % ARRAY_LEN(values))) % ARRAY_LEN(values);
438 v = values[i];
439 v = v * cl_graphscale->integer + cl_graphshift->integer;
440
441 if (v < 0)
442 v += cl_graphheight->integer * (1+(int)(-v / cl_graphheight->integer));
443 h = (int)v % cl_graphheight->integer;
444 re.DrawStretchPic( x+w-1-a, y - h, 1, h, 0, 0, 0, 0, cls.whiteShader );
445 }
446 }
447
448 //=============================================================================
449
450 /*
451 ==================
452 SCR_Init
453 ==================
454 */
455 void SCR_Init( void ) {
456 cl_timegraph = Cvar_Get ("timegraph", "0", CVAR_CHEAT);
457 cl_debuggraph = Cvar_Get ("debuggraph", "0", CVAR_CHEAT);
458 cl_graphheight = Cvar_Get ("graphheight", "32", CVAR_CHEAT);
459 cl_graphscale = Cvar_Get ("graphscale", "1", CVAR_CHEAT);
460 cl_graphshift = Cvar_Get ("graphshift", "0", CVAR_CHEAT);
461
462 scr_initialized = qtrue;
463 }
464
465
466 //=======================================================
467
468 /*
469 ==================
470 SCR_DrawScreenField
471
472 This will be called twice if rendering in stereo mode
473 ==================
474 */
475 void SCR_DrawScreenField( stereoFrame_t stereoFrame ) {
476 qboolean uiFullscreen;
477
478 re.BeginFrame( stereoFrame );
479
480 uiFullscreen = (uivm && VM_Call( uivm, UI_IS_FULLSCREEN ));
481
482 // wide aspect ratio screens need to have the sides cleared
483 // unless they are displaying game renderings
484 if ( uiFullscreen || clc.state < CA_LOADING ) {
485 if ( cls.glconfig.vidWidth * 480 > cls.glconfig.vidHeight * 640 ) {
486 re.SetColor( g_color_table[0] );
487 re.DrawStretchPic( 0, 0, cls.glconfig.vidWidth, cls.glconfig.vidHeight, 0, 0, 0, 0, cls.whiteShader );
488 re.SetColor( NULL );
489 }
490 }
491
492 // if the menu is going to cover the entire screen, we
493 // don't need to render anything under it
494 if ( uivm && !uiFullscreen ) {
495 switch( clc.state ) {
496 default:
497 Com_Error( ERR_FATAL, "SCR_DrawScreenField: bad clc.state" );
498 break;
499 case CA_CINEMATIC:
500 SCR_DrawCinematic();
501 break;
502 case CA_DISCONNECTED:
503 // force menu up
504 S_StopAllSounds();
505 VM_Call( uivm, UI_SET_ACTIVE_MENU, UIMENU_MAIN );
506 break;
507 case CA_CONNECTING:
508 case CA_CHALLENGING:
509 case CA_CONNECTED:
510 // connecting clients will only show the connection dialog
511 // refresh to update the time
512 VM_Call( uivm, UI_REFRESH, cls.realtime );
513 VM_Call( uivm, UI_DRAW_CONNECT_SCREEN, qfalse );
514 break;
515 case CA_LOADING:
516 case CA_PRIMED:
517 // draw the game information screen and loading progress
518 CL_CGameRendering(stereoFrame);
519
520 // also draw the connection information, so it doesn't
521 // flash away too briefly on local or lan games
522 // refresh to update the time
523 VM_Call( uivm, UI_REFRESH, cls.realtime );
524 VM_Call( uivm, UI_DRAW_CONNECT_SCREEN, qtrue );
525 break;
526 case CA_ACTIVE:
527 // always supply STEREO_CENTER as vieworg offset is now done by the engine.
528 CL_CGameRendering(stereoFrame);
529 SCR_DrawDemoRecording();
530 #ifdef USE_VOIP
531 SCR_DrawVoipMeter();
532 #endif
533 break;
534 }
535 }
536
537 // the menu draws next
538 if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) {
539 VM_Call( uivm, UI_REFRESH, cls.realtime );
540 }
541
542 // console draws next
543 Con_DrawConsole ();
544
545 // debug graph can be drawn on top of anything
546 if ( cl_debuggraph->integer || cl_timegraph->integer || cl_debugMove->integer ) {
547 SCR_DrawDebugGraph ();
548 }
549 }
550
551 /*
552 ==================
553 SCR_UpdateScreen
554
555 This is called every frame, and can also be called explicitly to flush
556 text to the screen.
557 ==================
558 */
559 void SCR_UpdateScreen( void ) {
560 static int recursive;
561
562 if ( !scr_initialized ) {
563 return; // not initialized yet
564 }
565
566 if ( ++recursive > 2 ) {
567 Com_Error( ERR_FATAL, "SCR_UpdateScreen: recursively called" );
568 }
569 recursive = 1;
570
571 // If there is no VM, there are also no rendering commands issued. Stop the renderer in
572 // that case.
573 if( uivm || com_dedicated->integer )
574 {
575 // XXX
576 int in_anaglyphMode = Cvar_VariableIntegerValue("r_anaglyphMode");
577 // if running in stereo, we need to draw the frame twice
578 if ( cls.glconfig.stereoEnabled || in_anaglyphMode) {
579 SCR_DrawScreenField( STEREO_LEFT );
580 SCR_DrawScreenField( STEREO_RIGHT );
581 } else {
582 SCR_DrawScreenField( STEREO_CENTER );
583 }
584
585 if ( com_speeds->integer ) {
586 re.EndFrame( &time_frontend, &time_backend );
587 } else {
588 re.EndFrame( NULL, NULL );
589 }
590 }
591
592 recursive = 0;
593 }
594