1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
|
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
Copyright (C) 2007-2008 Kristian Duske
Copyright (C) 2010-2014 QuakeSpasm developers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// screen.c -- master for refresh, status bar, console, chat, notify, etc
#include "quakedef.h"
/*
background clear
rendering
turtle/net/ram icons
sbar
centerprint / slow centerprint
notify lines
intermission / finale overlay
loading plaque
console
menu
required background clears
required update regions
syncronous draw mode or async
One off screen buffer, with updates either copied or xblited
Need to double buffer?
async draw will require the refresh area to be cleared, because it will be
xblited, but sync draw can just ignore it.
sync
draw
CenterPrint ()
SlowPrint ()
Screen_Update ();
Con_Printf ();
net
turn off messages option
the refresh is allways rendered, unless the console is full screen
console is:
notify lines
half
full
*/
int glx, gly, glwidth, glheight;
float scr_con_current;
float scr_conlines; // lines of console to display
//johnfitz -- new cvars
cvar_t scr_menuscale = {"scr_menuscale", "1", CVAR_ARCHIVE};
cvar_t scr_sbarscale = {"scr_sbarscale", "1", CVAR_ARCHIVE};
cvar_t scr_sbaralpha = {"scr_sbaralpha", "0.75", CVAR_ARCHIVE};
cvar_t scr_conwidth = {"scr_conwidth", "0", CVAR_ARCHIVE};
cvar_t scr_conscale = {"scr_conscale", "1", CVAR_ARCHIVE};
cvar_t scr_crosshairscale = {"scr_crosshairscale", "1", CVAR_ARCHIVE};
cvar_t scr_showfps = {"scr_showfps", "0", CVAR_NONE};
cvar_t scr_clock = {"scr_clock", "0", CVAR_NONE};
//johnfitz
cvar_t scr_viewsize = {"viewsize","100", CVAR_ARCHIVE};
cvar_t scr_fov = {"fov","90",CVAR_NONE}; // 10 - 170
cvar_t scr_fov_adapt = {"fov_adapt","1",CVAR_ARCHIVE};
cvar_t scr_conspeed = {"scr_conspeed","500",CVAR_ARCHIVE};
cvar_t scr_centertime = {"scr_centertime","2",CVAR_NONE};
cvar_t scr_showram = {"showram","1",CVAR_NONE};
cvar_t scr_showturtle = {"showturtle","0",CVAR_NONE};
cvar_t scr_showpause = {"showpause","1",CVAR_NONE};
cvar_t scr_printspeed = {"scr_printspeed","8",CVAR_NONE};
cvar_t gl_triplebuffer = {"gl_triplebuffer", "1", CVAR_ARCHIVE};
extern cvar_t crosshair;
qboolean scr_initialized; // ready to draw
qpic_t *scr_ram;
qpic_t *scr_net;
qpic_t *scr_turtle;
int clearconsole;
int clearnotify;
vrect_t scr_vrect;
qboolean scr_disabled_for_loading;
qboolean scr_drawloading;
float scr_disabled_time;
int scr_tileclear_updates = 0; //johnfitz
void SCR_ScreenShot_f (void);
/*
===============================================================================
CENTER PRINTING
===============================================================================
*/
char scr_centerstring[1024];
float scr_centertime_start; // for slow victory printing
float scr_centertime_off;
int scr_center_lines;
int scr_erase_lines;
int scr_erase_center;
/*
==============
SCR_CenterPrint
Called for important messages that should stay in the center of the screen
for a few moments
==============
*/
void SCR_CenterPrint (const char *str) //update centerprint data
{
strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1);
scr_centertime_off = scr_centertime.value;
scr_centertime_start = cl.time;
// count the number of lines for centering
scr_center_lines = 1;
str = scr_centerstring;
while (*str)
{
if (*str == '\n')
scr_center_lines++;
str++;
}
}
void SCR_DrawCenterString (void) //actually do the drawing
{
char *start;
int l;
int j;
int x, y;
int remaining;
GL_SetCanvas (CANVAS_MENU); //johnfitz
// the finale prints the characters one at a time
if (cl.intermission)
remaining = scr_printspeed.value * (cl.time - scr_centertime_start);
else
remaining = 9999;
scr_erase_center = 0;
start = scr_centerstring;
if (scr_center_lines <= 4)
y = 200*0.35; //johnfitz -- 320x200 coordinate system
else
y = 48;
if (crosshair.value)
y -= 8;
do
{
// scan the width of the line
for (l=0 ; l<40 ; l++)
if (start[l] == '\n' || !start[l])
break;
x = (320 - l*8)/2; //johnfitz -- 320x200 coordinate system
for (j=0 ; j<l ; j++, x+=8)
{
Draw_Character (x, y, start[j]); //johnfitz -- stretch overlays
if (!remaining--)
return;
}
y += 8;
while (*start && *start != '\n')
start++;
if (!*start)
break;
start++; // skip the \n
} while (1);
}
void SCR_CheckDrawCenterString (void)
{
if (scr_center_lines > scr_erase_lines)
scr_erase_lines = scr_center_lines;
scr_centertime_off -= host_frametime;
if (scr_centertime_off <= 0 && !cl.intermission)
return;
if (key_dest != key_game)
return;
if (cl.paused) //johnfitz -- don't show centerprint during a pause
return;
SCR_DrawCenterString ();
}
//=============================================================================
/*
====================
AdaptFovx
Adapt a 4:3 horizontal FOV to the current screen size using the "Hor+" scaling:
2.0 * atan(width / height * 3.0 / 4.0 * tan(fov_x / 2.0))
====================
*/
float AdaptFovx (float fov_x, float width, float height)
{
float a, x;
if (fov_x < 1 || fov_x > 179)
Sys_Error ("Bad fov: %f", fov_x);
if (!scr_fov_adapt.value)
return fov_x;
if ((x = height / width) == 0.75)
return fov_x;
a = atan(0.75 / x * tan(fov_x / 360 * M_PI));
a = a * 360 / M_PI;
return a;
}
/*
====================
CalcFovy
====================
*/
float CalcFovy (float fov_x, float width, float height)
{
float a, x;
if (fov_x < 1 || fov_x > 179)
Sys_Error ("Bad fov: %f", fov_x);
x = width / tan(fov_x / 360 * M_PI);
a = atan(height / x);
a = a * 360 / M_PI;
return a;
}
/*
=================
SCR_CalcRefdef
Must be called whenever vid changes
Internal use only
=================
*/
static void SCR_CalcRefdef (void)
{
float size, scale; //johnfitz -- scale
// force the status bar to redraw
Sbar_Changed ();
scr_tileclear_updates = 0; //johnfitz
// bound viewsize
if (scr_viewsize.value < 30)
Cvar_SetQuick (&scr_viewsize, "30");
if (scr_viewsize.value > 120)
Cvar_SetQuick (&scr_viewsize, "120");
// bound fov
if (scr_fov.value < 10)
Cvar_SetQuick (&scr_fov, "10");
if (scr_fov.value > 170)
Cvar_SetQuick (&scr_fov, "170");
vid.recalc_refdef = 0;
//johnfitz -- rewrote this section
size = scr_viewsize.value;
scale = CLAMP (1.0, scr_sbarscale.value, (float)glwidth / 320.0);
if (size >= 120 || cl.intermission || scr_sbaralpha.value < 1) //johnfitz -- scr_sbaralpha.value
sb_lines = 0;
else if (size >= 110)
sb_lines = 24 * scale;
else
sb_lines = 48 * scale;
size = q_min(scr_viewsize.value, 100) / 100;
//johnfitz
//johnfitz -- rewrote this section
r_refdef.vrect.width = q_max(glwidth * size, 96); //no smaller than 96, for icons
r_refdef.vrect.height = q_min(glheight * size, glheight - sb_lines); //make room for sbar
r_refdef.vrect.x = (glwidth - r_refdef.vrect.width)/2;
r_refdef.vrect.y = (glheight - sb_lines - r_refdef.vrect.height)/2;
//johnfitz
r_refdef.fov_x = AdaptFovx(scr_fov.value, vid.width, vid.height);
r_refdef.fov_y = CalcFovy (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
scr_vrect = r_refdef.vrect;
}
/*
=================
SCR_SizeUp_f
Keybinding command
=================
*/
void SCR_SizeUp_f (void)
{
Cvar_SetValueQuick (&scr_viewsize, scr_viewsize.value+10);
}
/*
=================
SCR_SizeDown_f
Keybinding command
=================
*/
void SCR_SizeDown_f (void)
{
Cvar_SetValueQuick (&scr_viewsize, scr_viewsize.value-10);
}
static void SCR_Callback_refdef (cvar_t *var)
{
vid.recalc_refdef = 1;
}
/*
==================
SCR_Conwidth_f -- johnfitz -- called when scr_conwidth or scr_conscale changes
==================
*/
void SCR_Conwidth_f (cvar_t *var)
{
vid.recalc_refdef = 1;
vid.conwidth = (scr_conwidth.value > 0) ? (int)scr_conwidth.value : (scr_conscale.value > 0) ? (int)(vid.width/scr_conscale.value) : vid.width;
vid.conwidth = CLAMP (320, vid.conwidth, vid.width);
vid.conwidth &= 0xFFFFFFF8;
vid.conheight = vid.conwidth * vid.height / vid.width;
}
//============================================================================
/*
==================
SCR_LoadPics -- johnfitz
==================
*/
void SCR_LoadPics (void)
{
scr_ram = Draw_PicFromWad ("ram");
scr_net = Draw_PicFromWad ("net");
scr_turtle = Draw_PicFromWad ("turtle");
}
/*
==================
SCR_Init
==================
*/
void SCR_Init (void)
{
//johnfitz -- new cvars
Cvar_RegisterVariable (&scr_menuscale);
Cvar_RegisterVariable (&scr_sbarscale);
Cvar_SetCallback (&scr_sbaralpha, SCR_Callback_refdef);
Cvar_RegisterVariable (&scr_sbaralpha);
Cvar_SetCallback (&scr_conwidth, &SCR_Conwidth_f);
Cvar_SetCallback (&scr_conscale, &SCR_Conwidth_f);
Cvar_RegisterVariable (&scr_conwidth);
Cvar_RegisterVariable (&scr_conscale);
Cvar_RegisterVariable (&scr_crosshairscale);
Cvar_RegisterVariable (&scr_showfps);
Cvar_RegisterVariable (&scr_clock);
//johnfitz
Cvar_SetCallback (&scr_fov, SCR_Callback_refdef);
Cvar_SetCallback (&scr_fov_adapt, SCR_Callback_refdef);
Cvar_SetCallback (&scr_viewsize, SCR_Callback_refdef);
Cvar_RegisterVariable (&scr_fov);
Cvar_RegisterVariable (&scr_fov_adapt);
Cvar_RegisterVariable (&scr_viewsize);
Cvar_RegisterVariable (&scr_conspeed);
Cvar_RegisterVariable (&scr_showram);
Cvar_RegisterVariable (&scr_showturtle);
Cvar_RegisterVariable (&scr_showpause);
Cvar_RegisterVariable (&scr_centertime);
Cvar_RegisterVariable (&scr_printspeed);
Cvar_RegisterVariable (&gl_triplebuffer);
Cmd_AddCommand ("screenshot",SCR_ScreenShot_f);
Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
Cmd_AddCommand ("sizedown",SCR_SizeDown_f);
SCR_LoadPics (); //johnfitz
scr_initialized = true;
}
//============================================================================
/*
==============
SCR_DrawFPS -- johnfitz
==============
*/
void SCR_DrawFPS (void)
{
static double oldtime = 0;
static double lastfps = 0;
static int oldframecount = 0;
double elapsed_time;
int frames;
elapsed_time = realtime - oldtime;
frames = r_framecount - oldframecount;
if (elapsed_time < 0 || frames < 0)
{
oldtime = realtime;
oldframecount = r_framecount;
return;
}
// update value every 3/4 second
if (elapsed_time > 0.75)
{
lastfps = frames / elapsed_time;
oldtime = realtime;
oldframecount = r_framecount;
}
if (scr_showfps.value)
{
char st[16];
int x, y;
sprintf (st, "%4.0f fps", lastfps);
x = 320 - (strlen(st)<<3);
y = 200 - 8;
if (scr_clock.value) y -= 8; //make room for clock
GL_SetCanvas (CANVAS_BOTTOMRIGHT);
Draw_String (x, y, st);
scr_tileclear_updates = 0;
}
}
/*
==============
SCR_DrawClock -- johnfitz
==============
*/
void SCR_DrawClock (void)
{
char str[12];
if (scr_clock.value == 1)
{
int minutes, seconds;
minutes = cl.time / 60;
seconds = ((int)cl.time)%60;
sprintf (str,"%i:%i%i", minutes, seconds/10, seconds%10);
}
else
return;
//draw it
GL_SetCanvas (CANVAS_BOTTOMRIGHT);
Draw_String (320 - (strlen(str)<<3), 200 - 8, str);
scr_tileclear_updates = 0;
}
/*
==============
SCR_DrawDevStats
==============
*/
void SCR_DrawDevStats (void)
{
char str[40];
int y = 25-9; //9=number of lines to print
int x = 0; //margin
if (!devstats.value)
return;
GL_SetCanvas (CANVAS_BOTTOMLEFT);
Draw_Fill (x, y*8, 19*8, 9*8, 0, 0.5); //dark rectangle
sprintf (str, "devstats |Curr Peak");
Draw_String (x, (y++)*8-x, str);
sprintf (str, "---------+---------");
Draw_String (x, (y++)*8-x, str);
sprintf (str, "Edicts |%4i %4i", dev_stats.edicts, dev_peakstats.edicts);
Draw_String (x, (y++)*8-x, str);
sprintf (str, "Packet |%4i %4i", dev_stats.packetsize, dev_peakstats.packetsize);
Draw_String (x, (y++)*8-x, str);
sprintf (str, "Visedicts|%4i %4i", dev_stats.visedicts, dev_peakstats.visedicts);
Draw_String (x, (y++)*8-x, str);
sprintf (str, "Efrags |%4i %4i", dev_stats.efrags, dev_peakstats.efrags);
Draw_String (x, (y++)*8-x, str);
sprintf (str, "Dlights |%4i %4i", dev_stats.dlights, dev_peakstats.dlights);
Draw_String (x, (y++)*8-x, str);
sprintf (str, "Beams |%4i %4i", dev_stats.beams, dev_peakstats.beams);
Draw_String (x, (y++)*8-x, str);
sprintf (str, "Tempents |%4i %4i", dev_stats.tempents, dev_peakstats.tempents);
Draw_String (x, (y++)*8-x, str);
}
/*
==============
SCR_DrawRam
==============
*/
void SCR_DrawRam (void)
{
if (!scr_showram.value)
return;
if (!r_cache_thrash)
return;
GL_SetCanvas (CANVAS_DEFAULT); //johnfitz
Draw_Pic (scr_vrect.x+32, scr_vrect.y, scr_ram);
}
/*
==============
SCR_DrawTurtle
==============
*/
void SCR_DrawTurtle (void)
{
static int count;
if (!scr_showturtle.value)
return;
if (host_frametime < 0.1)
{
count = 0;
return;
}
count++;
if (count < 3)
return;
GL_SetCanvas (CANVAS_DEFAULT); //johnfitz
Draw_Pic (scr_vrect.x, scr_vrect.y, scr_turtle);
}
/*
==============
SCR_DrawNet
==============
*/
void SCR_DrawNet (void)
{
if (realtime - cl.last_received_message < 0.3)
return;
if (cls.demoplayback)
return;
GL_SetCanvas (CANVAS_DEFAULT); //johnfitz
Draw_Pic (scr_vrect.x+64, scr_vrect.y, scr_net);
}
/*
==============
DrawPause
==============
*/
void SCR_DrawPause (void)
{
qpic_t *pic;
if (!cl.paused)
return;
if (!scr_showpause.value) // turn off for screenshots
return;
GL_SetCanvas (CANVAS_MENU); //johnfitz
pic = Draw_CachePic ("gfx/pause.lmp");
Draw_Pic ( (320 - pic->width)/2, (240 - 48 - pic->height)/2, pic); //johnfitz -- stretched menus
scr_tileclear_updates = 0; //johnfitz
}
/*
==============
SCR_DrawLoading
==============
*/
void SCR_DrawLoading (void)
{
qpic_t *pic;
if (!scr_drawloading)
return;
GL_SetCanvas (CANVAS_MENU); //johnfitz
pic = Draw_CachePic ("gfx/loading.lmp");
Draw_Pic ( (320 - pic->width)/2, (240 - 48 - pic->height)/2, pic); //johnfitz -- stretched menus
scr_tileclear_updates = 0; //johnfitz
}
/*
==============
SCR_DrawCrosshair -- johnfitz
==============
*/
void SCR_DrawCrosshair (void)
{
if (!crosshair.value)
return;
GL_SetCanvas (CANVAS_CROSSHAIR);
Draw_Character (-4, -4, '+'); //0,0 is center of viewport
}
//=============================================================================
/*
==================
SCR_SetUpToDrawConsole
==================
*/
void SCR_SetUpToDrawConsole (void)
{
//johnfitz -- let's hack away the problem of slow console when host_timescale is <0
extern cvar_t host_timescale;
float timescale;
//johnfitz
Con_CheckResize ();
if (scr_drawloading)
return; // never a console with loading plaque
// decide on the height of the console
con_forcedup = !cl.worldmodel || cls.signon != SIGNONS;
if (con_forcedup)
{
scr_conlines = glheight; //full screen //johnfitz -- glheight instead of vid.height
scr_con_current = scr_conlines;
}
else if (key_dest == key_console)
scr_conlines = glheight/2; //half screen //johnfitz -- glheight instead of vid.height
else
scr_conlines = 0; //none visible
timescale = (host_timescale.value > 0) ? host_timescale.value : 1; //johnfitz -- timescale
if (scr_conlines < scr_con_current)
{
// ericw -- (glheight/600.0) factor makes conspeed resolution independent, using 800x600 as a baseline
scr_con_current -= scr_conspeed.value*(glheight/600.0)*host_frametime/timescale; //johnfitz -- timescale
if (scr_conlines > scr_con_current)
scr_con_current = scr_conlines;
}
else if (scr_conlines > scr_con_current)
{
// ericw -- (glheight/600.0)
scr_con_current += scr_conspeed.value*(glheight/600.0)*host_frametime/timescale; //johnfitz -- timescale
if (scr_conlines < scr_con_current)
scr_con_current = scr_conlines;
}
if (clearconsole++ < vid.numpages)
Sbar_Changed ();
if (!con_forcedup && scr_con_current)
scr_tileclear_updates = 0; //johnfitz
}
/*
==================
SCR_DrawConsole
==================
*/
void SCR_DrawConsole (void)
{
if (scr_con_current)
{
Con_DrawConsole (scr_con_current, true);
clearconsole = 0;
}
else
{
if (key_dest == key_game || key_dest == key_message)
Con_DrawNotify (); // only draw notify in game
}
}
/*
==============================================================================
SCREEN SHOTS
==============================================================================
*/
static void SCR_ScreenShot_Usage (void)
{
Con_Printf ("usage: screenshot <format> <quality>\n");
Con_Printf (" format must be \"png\" or \"tga\" or \"jpg\"\n");
Con_Printf (" quality must be 1-100\n");
return;
}
/*
==================
SCR_ScreenShot_f -- johnfitz -- rewritten to use Image_WriteTGA
==================
*/
void SCR_ScreenShot_f (void)
{
byte *buffer;
char ext[4];
char imagename[16]; //johnfitz -- was [80]
char checkname[MAX_OSPATH];
int i, quality;
qboolean ok;
Q_strncpy (ext, "png", sizeof(ext));
if (Cmd_Argc () >= 2)
{
const char *requested_ext = Cmd_Argv (1);
if (!q_strcasecmp ("png", requested_ext)
|| !q_strcasecmp ("tga", requested_ext)
|| !q_strcasecmp ("jpg", requested_ext))
Q_strncpy (ext, requested_ext, sizeof(ext));
else
{
SCR_ScreenShot_Usage ();
return;
}
}
// read quality as the 3rd param (only used for JPG)
quality = 90;
if (Cmd_Argc () >= 3)
quality = Q_atoi (Cmd_Argv(2));
if (quality < 1 || quality > 100)
{
SCR_ScreenShot_Usage ();
return;
}
// find a file name to save it to
for (i=0; i<10000; i++)
{
q_snprintf (imagename, sizeof(imagename), "spasm%04i.%s", i, ext); // "fitz%04i.tga"
q_snprintf (checkname, sizeof(checkname), "%s/%s", com_gamedir, imagename);
if (Sys_FileTime(checkname) == -1)
break; // file doesn't exist
}
if (i == 10000)
{
Con_Printf ("SCR_ScreenShot_f: Couldn't find an unused filename\n");
return;
}
//get data
if (!(buffer = (byte *) malloc(glwidth*glheight*3)))
{
Con_Printf ("SCR_ScreenShot_f: Couldn't allocate memory\n");
return;
}
glPixelStorei (GL_PACK_ALIGNMENT, 1);/* for widths that aren't a multiple of 4 */
glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer);
// now write the file
if (!q_strncasecmp (ext, "png", sizeof(ext)))
ok = Image_WritePNG (imagename, buffer, glwidth, glheight, 24, false);
else if (!q_strncasecmp (ext, "tga", sizeof(ext)))
ok = Image_WriteTGA (imagename, buffer, glwidth, glheight, 24, false);
else if (!q_strncasecmp (ext, "jpg", sizeof(ext)))
ok = Image_WriteJPG (imagename, buffer, glwidth, glheight, 24, quality, false);
else
ok = false;
if (ok)
Con_Printf ("Wrote %s\n", imagename);
else
Con_Printf ("SCR_ScreenShot_f: Couldn't create %s\n", imagename);
free (buffer);
}
//=============================================================================
/*
===============
SCR_BeginLoadingPlaque
================
*/
void SCR_BeginLoadingPlaque (void)
{
S_StopAllSounds (true);
if (cls.state != ca_connected)
return;
if (cls.signon != SIGNONS)
return;
// redraw with no console and the loading plaque
Con_ClearNotify ();
scr_centertime_off = 0;
scr_con_current = 0;
scr_drawloading = true;
Sbar_Changed ();
SCR_UpdateScreen ();
scr_drawloading = false;
scr_disabled_for_loading = true;
scr_disabled_time = realtime;
}
/*
===============
SCR_EndLoadingPlaque
================
*/
void SCR_EndLoadingPlaque (void)
{
scr_disabled_for_loading = false;
Con_ClearNotify ();
}
//=============================================================================
const char *scr_notifystring;
qboolean scr_drawdialog;
void SCR_DrawNotifyString (void)
{
const char *start;
int l;
int j;
int x, y;
GL_SetCanvas (CANVAS_MENU); //johnfitz
start = scr_notifystring;
y = 200 * 0.35; //johnfitz -- stretched overlays
do
{
// scan the width of the line
for (l=0 ; l<40 ; l++)
if (start[l] == '\n' || !start[l])
break;
x = (320 - l*8)/2; //johnfitz -- stretched overlays
for (j=0 ; j<l ; j++, x+=8)
Draw_Character (x, y, start[j]);
y += 8;
while (*start && *start != '\n')
start++;
if (!*start)
break;
start++; // skip the \n
} while (1);
}
/*
==================
SCR_ModalMessage
Displays a text string in the center of the screen and waits for a Y or N
keypress.
==================
*/
int SCR_ModalMessage (const char *text, float timeout) //johnfitz -- timeout
{
double time1, time2; //johnfitz -- timeout
int lastkey, lastchar;
if (cls.state == ca_dedicated)
return true;
scr_notifystring = text;
// draw a fresh screen
scr_drawdialog = true;
SCR_UpdateScreen ();
scr_drawdialog = false;
S_ClearBuffer (); // so dma doesn't loop current sound
time1 = Sys_DoubleTime () + timeout; //johnfitz -- timeout
time2 = 0.0f; //johnfitz -- timeout
Key_BeginInputGrab ();
do
{
Sys_SendKeyEvents ();
Key_GetGrabbedInput (&lastkey, &lastchar);
Sys_Sleep (16);
if (timeout) time2 = Sys_DoubleTime (); //johnfitz -- zero timeout means wait forever.
} while (lastchar != 'y' && lastchar != 'Y' &&
lastchar != 'n' && lastchar != 'N' &&
lastkey != K_ESCAPE &&
lastkey != K_ABUTTON &&
lastkey != K_BBUTTON &&
time2 <= time1);
Key_EndInputGrab ();
// SCR_UpdateScreen (); //johnfitz -- commented out
//johnfitz -- timeout
if (time2 > time1)
return false;
//johnfitz
return (lastchar == 'y' || lastchar == 'Y' || lastkey == K_ABUTTON);
}
//=============================================================================
//johnfitz -- deleted SCR_BringDownConsole
/*
==================
SCR_TileClear
johnfitz -- modified to use glwidth/glheight instead of vid.width/vid.height
also fixed the dimentions of right and top panels
also added scr_tileclear_updates
==================
*/
void SCR_TileClear (void)
{
//ericw -- added check for glsl gamma. TODO: remove this ugly optimization?
if (scr_tileclear_updates >= vid.numpages && !gl_clear.value && !(gl_glsl_gamma_able && vid_gamma.value != 1))
return;
scr_tileclear_updates++;
if (r_refdef.vrect.x > 0)
{
// left
Draw_TileClear (0,
0,
r_refdef.vrect.x,
glheight - sb_lines);
// right
Draw_TileClear (r_refdef.vrect.x + r_refdef.vrect.width,
0,
glwidth - r_refdef.vrect.x - r_refdef.vrect.width,
glheight - sb_lines);
}
if (r_refdef.vrect.y > 0)
{
// top
Draw_TileClear (r_refdef.vrect.x,
0,
r_refdef.vrect.width,
r_refdef.vrect.y);
// bottom
Draw_TileClear (r_refdef.vrect.x,
r_refdef.vrect.y + r_refdef.vrect.height,
r_refdef.vrect.width,
glheight - r_refdef.vrect.y - r_refdef.vrect.height - sb_lines);
}
}
/*
==================
SCR_UpdateScreen
This is called every frame, and can also be called explicitly to flush
text to the screen.
WARNING: be very careful calling this from elsewhere, because the refresh
needs almost the entire 256k of stack space!
==================
*/
void SCR_UpdateScreen (void)
{
vid.numpages = (gl_triplebuffer.value) ? 3 : 2;
if (scr_disabled_for_loading)
{
if (realtime - scr_disabled_time > 60)
{
scr_disabled_for_loading = false;
Con_Printf ("load failed.\n");
}
else
return;
}
if (!scr_initialized || !con_initialized)
return; // not initialized yet
GL_BeginRendering (&glx, &gly, &glwidth, &glheight);
//
// determine size of refresh window
//
if (vid.recalc_refdef)
SCR_CalcRefdef ();
//
// do 3D refresh drawing, and then update the screen
//
SCR_SetUpToDrawConsole ();
V_RenderView ();
GL_Set2D ();
//FIXME: only call this when needed
SCR_TileClear ();
if (scr_drawdialog) //new game confirm
{
if (con_forcedup)
Draw_ConsoleBackground ();
else
Sbar_Draw ();
Draw_FadeScreen ();
SCR_DrawNotifyString ();
}
else if (scr_drawloading) //loading
{
SCR_DrawLoading ();
Sbar_Draw ();
}
else if (cl.intermission == 1 && key_dest == key_game) //end of level
{
Sbar_IntermissionOverlay ();
}
else if (cl.intermission == 2 && key_dest == key_game) //end of episode
{
Sbar_FinaleOverlay ();
SCR_CheckDrawCenterString ();
}
else
{
SCR_DrawCrosshair (); //johnfitz
SCR_DrawRam ();
SCR_DrawNet ();
SCR_DrawTurtle ();
SCR_DrawPause ();
SCR_CheckDrawCenterString ();
Sbar_Draw ();
SCR_DrawDevStats (); //johnfitz
SCR_DrawFPS (); //johnfitz
SCR_DrawClock (); //johnfitz
SCR_DrawConsole ();
M_Draw ();
}
V_UpdateBlend (); //johnfitz -- V_UpdatePalette cleaned up and renamed
GLSLGamma_GammaCorrect ();
GL_EndRendering ();
}
|