| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "client.h" |
| 25 |
|
| 26 |
qboolean scr_initialized; |
| 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 |
|
| 37 |
|
| 38 |
|
| 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 |
|
| 55 |
|
| 56 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 90 |
|
| 91 |
|
| 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 |
|
| 107 |
|
| 108 |
|
| 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 |
|
| 120 |
|
| 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 |
|
| 158 |
|
| 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 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 319 |
|
| 320 |
int SCR_GetBigStringWidth( const char *str ) { |
| 321 |
return SCR_Strlen( str ) * BIGCHAR_WIDTH; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 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 |
|
| 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; |
| 363 |
else if (!cl_voipSend->integer) |
| 364 |
return; |
| 365 |
else if (clc.state != CA_ACTIVE) |
| 366 |
return; |
| 367 |
else if (!clc.voipEnabled) |
| 368 |
return; |
| 369 |
else if (clc.demoplaying) |
| 370 |
return; |
| 371 |
else if (!cl_voip->integer) |
| 372 |
return; |
| 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 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
static int current; |
| 401 |
static float values[1024]; |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 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 |
|
| 417 |
|
| 418 |
|
| 419 |
void SCR_DrawDebugGraph (void) |
| 420 |
{ |
| 421 |
int a, x, y, w, i, h; |
| 422 |
float v; |
| 423 |
|
| 424 |
|
| 425 |
|
| 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 |
|
| 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 |
|
| 471 |
|
| 472 |
|
| 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 |
|
| 483 |
|
| 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 |
|
| 493 |
|
| 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 |
|
| 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 |
|
| 511 |
|
| 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 |
|
| 518 |
CL_CGameRendering(stereoFrame); |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
VM_Call( uivm, UI_REFRESH, cls.realtime ); |
| 524 |
VM_Call( uivm, UI_DRAW_CONNECT_SCREEN, qtrue ); |
| 525 |
break; |
| 526 |
case CA_ACTIVE: |
| 527 |
|
| 528 |
CL_CGameRendering(stereoFrame); |
| 529 |
SCR_DrawDemoRecording(); |
| 530 |
#ifdef USE_VOIP |
| 531 |
SCR_DrawVoipMeter(); |
| 532 |
#endif |
| 533 |
break; |
| 534 |
} |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
if ( Key_GetCatcher( ) & KEYCATCH_UI && uivm ) { |
| 539 |
VM_Call( uivm, UI_REFRESH, cls.realtime ); |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
Con_DrawConsole (); |
| 544 |
|
| 545 |
|
| 546 |
if ( cl_debuggraph->integer || cl_timegraph->integer || cl_debugMove->integer ) { |
| 547 |
SCR_DrawDebugGraph (); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
void SCR_UpdateScreen( void ) { |
| 560 |
static int recursive; |
| 561 |
|
| 562 |
if ( !scr_initialized ) { |
| 563 |
return; |
| 564 |
} |
| 565 |
|
| 566 |
if ( ++recursive > 2 ) { |
| 567 |
Com_Error( ERR_FATAL, "SCR_UpdateScreen: recursively called" ); |
| 568 |
} |
| 569 |
recursive = 1; |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
if( uivm || com_dedicated->integer ) |
| 574 |
{ |
| 575 |
|
| 576 |
int in_anaglyphMode = Cvar_VariableIntegerValue("r_anaglyphMode"); |
| 577 |
|
| 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 |
|