4 cvar_t scr_viewsize = {CVAR_SAVE, "viewsize","100"};
5 cvar_t scr_fov = {CVAR_SAVE, "fov","90"}; // 10 - 170
6 cvar_t scr_conspeed = {CVAR_SAVE, "scr_conspeed","900"}; // LordHavoc: quake used 300
7 cvar_t scr_centertime = {0, "scr_centertime","2"};
8 cvar_t scr_showram = {CVAR_SAVE, "showram","1"};
9 cvar_t scr_showturtle = {CVAR_SAVE, "showturtle","0"};
10 cvar_t scr_showpause = {CVAR_SAVE, "showpause","1"};
11 cvar_t scr_printspeed = {0, "scr_printspeed","8"};
12 cvar_t scr_2dresolution = {CVAR_SAVE, "scr_2dresolution", "1"};
13 cvar_t cl_avidemo = {0, "cl_avidemo", "0"};
15 qboolean scr_initialized; // ready to draw
17 float scr_con_current;
18 float scr_conlines; // lines of console to display
23 //qboolean scr_disabled_for_loading;
24 qboolean scr_drawloading = false;
25 //float scr_disabled_time;
27 static qbyte menuplyr_pixels[4096];
29 void DrawCrosshair(int num);
30 void V_CalcRefdef (void);
31 static void SCR_ScreenShot_f (void);
32 static void R_Envmap_f (void);
35 void R_ClearScreen(void);
38 ===============================================================================
42 ===============================================================================
45 char scr_centerstring[1024];
46 float scr_centertime_start; // for slow victory printing
47 float scr_centertime_off;
56 Called for important messages that should stay in the center of the screen
60 void SCR_CenterPrint (char *str)
62 strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1);
63 scr_centertime_off = scr_centertime.value;
64 scr_centertime_start = cl.time;
66 // count the number of lines for centering
77 void SCR_DrawCenterString (void)
84 // the finale prints the characters one at a time
86 remaining = scr_printspeed.value * (cl.time - scr_centertime_start);
91 start = scr_centerstring;
93 if (scr_center_lines <= 4)
94 y = vid.conheight*0.35;
100 // scan the width of the line
101 for (l=0 ; l<40 ; l++)
102 if (start[l] == '\n' || !start[l])
104 x = (vid.conwidth - l*8)/2;
109 DrawQ_String(x, y, start, l, 8, 8, 1, 1, 1, 1, 0);
117 while (*start && *start != '\n')
122 start++; // skip the \n
126 void SCR_CheckDrawCenterString (void)
128 if (scr_center_lines > scr_erase_lines)
129 scr_erase_lines = scr_center_lines;
131 scr_centertime_off -= host_frametime;
133 // don't draw if this is a normal stats-screen intermission,
134 // only if it is not an intermission, or a finale intermission
135 if (cl.intermission == 1)
137 if (scr_centertime_off <= 0 && !cl.intermission)
139 if (key_dest != key_game)
142 SCR_DrawCenterString ();
150 void SCR_DrawRam (void)
152 // if (!scr_showram.integer)
154 // DrawQ_Pic (32, 0, "ram", 0, 0, 1, 1, 1, 1, 0);
162 void SCR_DrawTurtle (void)
166 if (cls.state != ca_connected)
169 if (!scr_showturtle.integer)
172 if (host_frametime < 0.1)
182 DrawQ_Pic (0, 0, "turtle", 0, 0, 1, 1, 1, 1, 0);
190 void SCR_DrawNet (void)
192 if (cls.state != ca_connected)
194 if (realtime - cl.last_received_message < 0.3)
196 if (cls.demoplayback)
199 DrawQ_Pic (64, 0, "net", 0, 0, 1, 1, 1, 1, 0);
207 void SCR_DrawPause (void)
211 if (cls.state != ca_connected)
214 if (!scr_showpause.integer) // turn off for screenshots
220 pic = Draw_CachePic ("gfx/pause.lmp");
221 DrawQ_Pic ((vid.conwidth - pic->width)/2, (vid.conheight - pic->height)/2, "gfx/pause.lmp", 0, 0, 1, 1, 1, 1, 0);
231 void SCR_DrawLoading (void)
235 //if (!scr_drawloading)
238 pic = Draw_CachePic ("gfx/loading.lmp");
239 DrawQ_Pic ((vid.conwidth - pic->width)/2, (vid.conheight - pic->height)/2, "gfx/loading.lmp", 0, 0, 1, 1, 1, 1, 0);
244 //=============================================================================
249 SCR_SetUpToDrawConsole
252 void SCR_SetUpToDrawConsole (void)
256 // decide on the height of the console
257 con_forcedup = !cl.worldmodel || cls.signon != SIGNONS;
261 scr_conlines = vid.conheight; // full screen
262 scr_con_current = scr_conlines;
264 else if (key_dest == key_console)
265 scr_conlines = vid.conheight/2; // half screen
267 scr_conlines = 0; // none visible
269 if (scr_conlines < scr_con_current)
271 scr_con_current -= scr_conspeed.value*host_realframetime;
272 if (scr_conlines > scr_con_current)
273 scr_con_current = scr_conlines;
276 else if (scr_conlines > scr_con_current)
278 scr_con_current += scr_conspeed.value*host_realframetime;
279 if (scr_conlines < scr_con_current)
280 scr_con_current = scr_conlines;
289 void SCR_DrawConsole (void)
293 Con_DrawConsole (scr_con_current);
298 if (key_dest == key_game || key_dest == key_message)
299 Con_DrawNotify (); // only draw notify in game
305 SCR_BeginLoadingPlaque
309 void SCR_BeginLoadingPlaque (void)
314 S_StopAllSounds (true);
316 // if (cls.state != ca_connected)
318 // if (cls.signon != SIGNONS)
321 // redraw with no console and the loading plaque
322 // Con_ClearNotify ();
323 // scr_centertime_off = 0;
324 // scr_con_current = 0;
326 scr_drawloading = true;
328 scr_drawloading = true;
330 //scr_drawloading = false;
332 // scr_disabled_for_loading = true;
333 // scr_disabled_time = realtime;
342 void SCR_EndLoadingPlaque (void)
345 if (!scr_drawloading)
348 // scr_disabled_for_loading = false;
349 scr_drawloading = false;
354 //=============================================================================
356 char r_speeds_string[1024];
357 int speedstringcount, r_timereport_active;
358 double r_timereport_temp = 0, r_timereport_current = 0, r_timereport_start = 0;
360 void R_TimeReport(char *desc)
366 if (!r_timereport_active)
369 r_timereport_temp = r_timereport_current;
370 r_timereport_current = Sys_DoubleTime();
371 t = (int) ((r_timereport_current - r_timereport_temp) * 1000000.0);
373 sprintf(tempbuf, "%8i %s", t, desc);
374 length = strlen(tempbuf);
376 tempbuf[length++] = ' ';
378 if (speedstringcount + length > (vid.conwidth / 8))
380 strcat(r_speeds_string, "\n");
381 speedstringcount = 0;
383 // skip the space at the beginning if it's the first on the line
384 if (speedstringcount == 0)
386 strcat(r_speeds_string, tempbuf + 1);
387 speedstringcount = length - 1;
391 strcat(r_speeds_string, tempbuf);
392 speedstringcount += length;
396 void R_TimeReport_Start(void)
398 r_timereport_active = r_speeds.integer && cl.worldmodel && cls.state == ca_connected;
399 r_speeds_string[0] = 0;
400 if (r_timereport_active)
402 speedstringcount = 0;
403 AngleVectors (r_refdef.viewangles, vpn, NULL, NULL);
404 //sprintf(r_speeds_string, "org:'%c%6.2f %c%6.2f %c%6.2f' ang:'%c%3.0f %c%3.0f %c%3.0f' dir:'%c%2.3f %c%2.3f %c%2.3f'\n%6i walls %6i dlitwalls %7i modeltris %7i meshtris\nBSP: %6i faces %6i nodes %6i leafs\n%4i models %4i bmodels %4i sprites %5i particles %3i dlights\n",
405 // r_refdef.vieworg[0] < 0 ? '-' : ' ', fabs(r_refdef.vieworg[0]), r_refdef.vieworg[1] < 0 ? '-' : ' ', fabs(r_refdef.vieworg[1]), r_refdef.vieworg[2] < 0 ? '-' : ' ', fabs(r_refdef.vieworg[2]),
406 // r_refdef.viewangles[0] < 0 ? '-' : ' ', fabs(r_refdef.viewangles[0]), r_refdef.viewangles[1] < 0 ? '-' : ' ', fabs(r_refdef.viewangles[1]), r_refdef.viewangles[2] < 0 ? '-' : ' ', fabs(r_refdef.viewangles[2]),
407 // vpn[0] < 0 ? '-' : ' ', fabs(vpn[0]), vpn[1] < 0 ? '-' : ' ', fabs(vpn[1]), vpn[2] < 0 ? '-' : ' ', fabs(vpn[2]),
408 sprintf(r_speeds_string,
409 "org:'%+8.2f %+8.2f %+8.2f' ang:'%+4.0f %+4.0f %+4.0f' dir:'%+2.3f %+2.3f %+2.3f'\n"
410 "world:%6i faces%6i nodes%6i leafs%6i walls%6i dlitwalls\n"
411 "%5i models%5i bmodels%5i sprites%6i particles%4i dlights\n"
412 "%6i modeltris%6i transmeshs%6i transtris%6i meshs%6i meshtris\n",
413 r_refdef.vieworg[0], r_refdef.vieworg[1], r_refdef.vieworg[2], r_refdef.viewangles[0], r_refdef.viewangles[1], r_refdef.viewangles[2], vpn[0], vpn[1], vpn[2],
414 c_faces, c_nodes, c_leafs, c_brush_polys, c_light_polys,
415 c_models, c_bmodels, c_sprites, c_particles, c_dlights,
416 c_alias_polys, c_transmeshs, c_transtris, c_meshs, c_meshtris);
430 r_timereport_start = Sys_DoubleTime();
434 void R_TimeReport_End(void)
436 r_timereport_current = r_timereport_start;
437 R_TimeReport("total");
439 if (r_timereport_active)
443 for (i = 0;r_speeds_string[i];i++)
444 if (r_speeds_string[i] == '\n')
446 y = vid.conheight - sb_lines - lines * 8/* - 8*/;
448 DrawQ_Fill(0, y, vid.conwidth, lines * 8, 0, 0, 0, 0.5, 0);
449 while (r_speeds_string[i])
452 while (r_speeds_string[i] && r_speeds_string[i] != '\n')
455 DrawQ_String(0, y, r_speeds_string + j, i - j, 8, 8, 1, 1, 1, 1, 0);
456 if (r_speeds_string[i] == '\n')
470 void SCR_SizeUp_f (void)
472 Cvar_SetValue ("viewsize",scr_viewsize.value+10);
483 void SCR_SizeDown_f (void)
485 Cvar_SetValue ("viewsize",scr_viewsize.value-10);
488 void CL_Screen_Init(void)
492 Cvar_RegisterVariable (&scr_fov);
493 Cvar_RegisterVariable (&scr_viewsize);
494 Cvar_RegisterVariable (&scr_conspeed);
495 Cvar_RegisterVariable (&scr_showram);
496 Cvar_RegisterVariable (&scr_showturtle);
497 Cvar_RegisterVariable (&scr_showpause);
498 Cvar_RegisterVariable (&scr_centertime);
499 Cvar_RegisterVariable (&scr_printspeed);
500 Cvar_RegisterVariable (&scr_2dresolution);
501 Cvar_RegisterVariable (&cl_avidemo);
503 Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
504 Cmd_AddCommand ("sizedown",SCR_SizeDown_f);
505 Cmd_AddCommand ("screenshot",SCR_ScreenShot_f);
506 Cmd_AddCommand ("envmap", R_Envmap_f);
508 scr_initialized = true;
511 // load the image data for the player image in the config menu
512 dat = (qpic_t *)COM_LoadFile ("gfx/menuplyr.lmp", false);
514 Sys_Error("unable to load gfx/menuplyr.lmp");
517 if (dat->width*dat->height <= 4096)
518 memcpy (menuplyr_pixels, dat->data, dat->width * dat->height);
520 Con_Printf("gfx/menuplyr.lmp larger than 4k buffer");
524 void DrawQ_Clear(void)
526 r_refdef.drawqueuesize = 0;
529 void DrawQ_Pic(float x, float y, char *picname, float width, float height, float red, float green, float blue, float alpha, int flags)
533 if (alpha < (1.0f / 255.0f))
535 size = sizeof(*dq) + ((strlen(picname) + 1 + 3) & ~3);
536 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
538 red = bound(0, red, 1);
539 green = bound(0, green, 1);
540 blue = bound(0, blue, 1);
541 alpha = bound(0, alpha, 1);
542 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
544 dq->command = DRAWQUEUE_PIC;
546 dq->color = ((unsigned int) (red * 255.0f) << 24) | ((unsigned int) (green * 255.0f) << 16) | ((unsigned int) (blue * 255.0f) << 8) | ((unsigned int) (alpha * 255.0f));
549 // if these are not zero, they override the pic's size
552 strcpy((char *)(dq + 1), picname);
553 r_refdef.drawqueuesize += dq->size;
556 void DrawQ_String(float x, float y, char *string, int maxlen, float scalex, float scaley, float red, float green, float blue, float alpha, int flags)
561 if (alpha < (1.0f / 255.0f))
564 len = strlen(string);
566 for (len = 0;len < maxlen && string[len];len++);
567 for (;len > 0 && string[0] == ' ';string++, x += scalex, len--);
568 for (;len > 0 && string[len - 1] == ' ';len--);
571 if (x >= vid.conwidth || y >= vid.conheight || x < (-scalex * maxlen) || y < (-scaley))
573 size = sizeof(*dq) + ((len + 1 + 3) & ~3);
574 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
576 red = bound(0, red, 1);
577 green = bound(0, green, 1);
578 blue = bound(0, blue, 1);
579 alpha = bound(0, alpha, 1);
580 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
582 dq->command = DRAWQUEUE_STRING;
584 dq->color = ((unsigned int) (red * 255.0f) << 24) | ((unsigned int) (green * 255.0f) << 16) | ((unsigned int) (blue * 255.0f) << 8) | ((unsigned int) (alpha * 255.0f));
589 out = (char *)(dq + 1);
590 memcpy(out, string, len);
592 r_refdef.drawqueuesize += dq->size;
595 void DrawQ_Fill (float x, float y, float w, float h, float red, float green, float blue, float alpha, int flags)
599 if (alpha < (1.0f / 255.0f))
601 size = sizeof(*dq) + 4;
602 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
604 red = bound(0, red, 1);
605 green = bound(0, green, 1);
606 blue = bound(0, blue, 1);
607 alpha = bound(0, alpha, 1);
608 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
610 dq->command = DRAWQUEUE_PIC;
612 dq->color = ((unsigned int) (red * 255.0f) << 24) | ((unsigned int) (green * 255.0f) << 16) | ((unsigned int) (blue * 255.0f) << 8) | ((unsigned int) (alpha * 255.0f));
618 *((char *)(dq + 1)) = 0;
619 r_refdef.drawqueuesize += dq->size;
622 //only used for the player color selection menu
623 void DrawQ_PicTranslate (int x, int y, char *picname, qbyte *translation)
626 unsigned int trans[4096];
629 pic = Draw_CachePic(picname);
633 c = pic->width * pic->height;
636 Con_Printf("DrawQ_PicTranslate: image larger than 4k buffer\n");
640 for (i = 0;i < c;i++)
641 trans[i] = d_8to24table[translation[menuplyr_pixels[i]]];
643 // FIXME: this is renderer stuff?
644 R_UpdateTexture (pic->tex, (qbyte *)trans);
646 DrawQ_Pic(x, y, picname, 0, 0, 1, 1, 1, 1, 0);
655 float CalcFov (float fov_x, float width, float height)
657 // calculate vision size and alter by aspect, then convert back to angle
658 return atan (height / (width / tan(fov_x/360*M_PI))) * 360 / M_PI;
665 Must be called whenever vid changes
669 static void SCR_CalcRefdef (void)
674 //========================================
677 if (scr_viewsize.value < 30)
678 Cvar_Set ("viewsize","30");
679 if (scr_viewsize.value > 120)
680 Cvar_Set ("viewsize","120");
682 // bound field of view
683 if (scr_fov.value < 10)
684 Cvar_Set ("fov","10");
685 if (scr_fov.value > 170)
686 Cvar_Set ("fov","170");
688 // intermission is always full screen
696 if (scr_viewsize.value >= 120)
697 sb_lines = 0; // no status bar at all
698 else if (scr_viewsize.value >= 110)
699 sb_lines = 24; // no inventory
702 size = scr_viewsize.value * (1.0 / 100.0);
707 r_refdef.width = vid.realwidth;
708 r_refdef.height = vid.realheight;
714 r_refdef.width = vid.realwidth * size;
715 r_refdef.height = vid.realheight * size;
716 r_refdef.x = (vid.realwidth - r_refdef.width)/2;
717 r_refdef.y = (vid.realheight - r_refdef.height)/2;
720 r_refdef.width = bound(0, r_refdef.width, vid.realwidth);
721 r_refdef.height = bound(0, r_refdef.height, vid.realheight);
722 r_refdef.x = bound(0, r_refdef.x, vid.realwidth - r_refdef.width) + vid.realx;
723 r_refdef.y = bound(0, r_refdef.y, vid.realheight - r_refdef.height) + vid.realy;
725 // LordHavoc: viewzoom (zoom in for sniper rifles, etc)
726 r_refdef.fov_x = scr_fov.value * cl.viewzoom;
727 r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.width, r_refdef.height);
731 Mod_CheckLoaded(cl.worldmodel);
732 contents = Mod_PointInLeaf(r_refdef.vieworg, cl.worldmodel)->contents;
733 if (contents != CONTENTS_EMPTY && contents != CONTENTS_SOLID)
735 r_refdef.fov_x *= (sin(cl.time * 4.7) * 0.015 + 0.985);
736 r_refdef.fov_y *= (sin(cl.time * 3.0) * 0.015 + 0.985);
746 void SCR_ScreenShot_f (void)
750 char checkname[MAX_OSPATH];
752 // find a file name to save it to
754 strcpy(filename, "dp0000.tga");
756 for (i=0 ; i<=9999 ; i++)
758 filename[2] = (i/1000)%10 + '0';
759 filename[3] = (i/ 100)%10 + '0';
760 filename[4] = (i/ 10)%10 + '0';
761 filename[5] = (i/ 1)%10 + '0';
762 sprintf (checkname, "%s/%s", com_gamedir, filename);
763 if (Sys_FileTime(checkname) == -1)
764 break; // file doesn't exist
768 Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
772 if (SCR_ScreenShot(filename, vid.realx, vid.realy, vid.realwidth, vid.realheight))
773 Con_Printf ("Wrote %s\n", filename);
775 Con_Printf ("unable to write %s\n", filename);
778 static int cl_avidemo_frame = 0;
780 void SCR_CaptureAVIDemo(void)
783 sprintf(filename, "dpavi%06d.tga", cl_avidemo_frame);
784 if (SCR_ScreenShot(filename, vid.realx, vid.realy, vid.realwidth, vid.realheight))
788 Cvar_SetValueQuick(&cl_avidemo, 0);
789 Con_Printf("avi saving failed on frame %i, out of disk space? stopping avi demo catpure.\n", cl_avidemo_frame);
790 cl_avidemo_frame = 0;
798 Grab six views for environment mapping tests
810 {{ 0, 180, 0}, "bk"},
811 {{ 0, 270, 0}, "lf"},
812 {{-90, 90, 0}, "up"},
816 static void R_Envmap_f (void)
819 char filename[256], basename[256];
823 Con_Printf ("envmap <basename> <size>: save out 6 cubic environment map images, usable with loadsky, note that size must one of 128, 256, 512, or 1024 and can't be bigger than your current resolution\n");
827 strcpy(basename, Cmd_Argv(1));
828 size = atoi(Cmd_Argv(2));
829 if (size != 128 && size != 256 && size != 512 && size != 1024)
831 Con_Printf("envmap: size must be one of 128, 256, 512, or 1024\n");
834 if (size > vid.realwidth || size > vid.realheight)
836 Con_Printf("envmap: your resolution is not big enough to render that size\n");
844 r_refdef.width = size;
845 r_refdef.height = size;
850 for (j = 0;j < 6;j++)
852 sprintf(filename, "env/%s%s.tga", basename, envmapinfo[j].name);
853 VectorCopy(envmapinfo[j].angles, r_refdef.viewangles);
856 SCR_ScreenShot(filename, vid.realx, vid.realy, size, size);
862 //=============================================================================
864 // LordHavoc: SHOWLMP stuff
865 #define SHOWLMP_MAXLABELS 256
866 typedef struct showlmp_s
876 showlmp_t showlmp[SHOWLMP_MAXLABELS];
878 void SHOWLMP_decodehide(void)
882 lmplabel = MSG_ReadString();
883 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
884 if (showlmp[i].isactive && strcmp(showlmp[i].label, lmplabel) == 0)
886 showlmp[i].isactive = false;
891 void SHOWLMP_decodeshow(void)
894 qbyte lmplabel[256], picname[256];
896 strcpy(lmplabel,MSG_ReadString());
897 strcpy(picname, MSG_ReadString());
898 if (gamemode == GAME_NEHAHRA) // LordHavoc: nasty old legacy junk
909 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
910 if (showlmp[i].isactive)
912 if (strcmp(showlmp[i].label, lmplabel) == 0)
915 break; // drop out to replace it
918 else if (k < 0) // find first empty one to replace
921 return; // none found to replace
922 // change existing one
923 showlmp[k].isactive = true;
924 strcpy(showlmp[k].label, lmplabel);
925 strcpy(showlmp[k].pic, picname);
930 void SHOWLMP_drawall(void)
934 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
935 if (showlmp[i].isactive)
936 DrawQ_Pic(showlmp[i].x, showlmp[i].y, showlmp[i].pic, 0, 0, 1, 1, 1, 1, 0);
939 void SHOWLMP_clear(void)
942 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
943 showlmp[i].isactive = false;
946 void CL_SetupScreenSize(void)
948 static float old2dresolution = -1;
950 VID_GetWindowSize (&vid.realx, &vid.realy, &vid.realwidth, &vid.realheight);
952 VID_UpdateGamma(false);
954 if (scr_2dresolution.value != old2dresolution)
956 Cvar_SetValue("scr_2dresolution", bound(0.0f, scr_2dresolution.value, 1.0f));
957 old2dresolution = scr_2dresolution.value;
960 if (vid.realwidth > 320)
962 vid.conwidth = (vid.realwidth - 320) * scr_2dresolution.value + 320;
963 vid.conwidth = bound(320, vid.conwidth, vid.realwidth);
968 if (vid.realheight > 240)
970 vid.conheight = (vid.realheight - 240) * scr_2dresolution.value + 240;
971 vid.conheight = bound(240, vid.conheight, vid.realheight);
976 SCR_SetUpToDrawConsole();
978 // determine size of refresh window
982 void CL_UpdateScreen(void)
984 if (!scr_initialized || !con_initialized)
985 return; // not initialized yet
987 if (cl_avidemo.integer)
988 SCR_CaptureAVIDemo();
990 cl_avidemo_frame = 0;
992 R_TimeReport("other");
994 CL_SetupScreenSize();
1001 R_TimeReport("setup");
1010 SCR_CheckDrawCenterString();
1017 if (scr_drawloading)
1019 scr_drawloading = false;
1025 // add r_speeds text to queue
1028 // start a new timing run
1029 R_TimeReport_Start();
1031 // make menu fade everything else on the screen
1037 void CL_Screen_NewMap(void)