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_drawloading = false;
25 static qbyte menuplyr_pixels[4096];
27 void DrawCrosshair(int num);
28 void V_CalcRefdef (void);
29 static void SCR_ScreenShot_f (void);
30 static void R_Envmap_f (void);
33 void R_ClearScreen(void);
36 ===============================================================================
40 ===============================================================================
43 char scr_centerstring[1024];
44 float scr_centertime_start; // for slow victory printing
45 float scr_centertime_off;
54 Called for important messages that should stay in the center of the screen
58 void SCR_CenterPrint (char *str)
60 strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1);
61 scr_centertime_off = scr_centertime.value;
62 scr_centertime_start = cl.time;
64 // count the number of lines for centering
75 void SCR_DrawCenterString (void)
82 // the finale prints the characters one at a time
84 remaining = scr_printspeed.value * (cl.time - scr_centertime_start);
89 start = scr_centerstring;
91 if (scr_center_lines <= 4)
92 y = vid.conheight*0.35;
98 // scan the width of the line
99 for (l=0 ; l<40 ; l++)
100 if (start[l] == '\n' || !start[l])
102 x = (vid.conwidth - l*8)/2;
107 DrawQ_String(x, y, start, l, 8, 8, 1, 1, 1, 1, 0);
115 while (*start && *start != '\n')
120 start++; // skip the \n
124 void SCR_CheckDrawCenterString (void)
126 if (scr_center_lines > scr_erase_lines)
127 scr_erase_lines = scr_center_lines;
129 scr_centertime_off -= host_frametime;
131 // don't draw if this is a normal stats-screen intermission,
132 // only if it is not an intermission, or a finale intermission
133 if (cl.intermission == 1)
135 if (scr_centertime_off <= 0 && !cl.intermission)
137 if (key_dest != key_game)
140 SCR_DrawCenterString ();
148 void SCR_DrawTurtle (void)
152 if (cls.state != ca_connected)
155 if (!scr_showturtle.integer)
158 if (host_frametime < 0.1)
168 DrawQ_Pic (0, 0, "turtle", 0, 0, 1, 1, 1, 1, 0);
176 void SCR_DrawNet (void)
178 if (cls.state != ca_connected)
180 if (realtime - cl.last_received_message < 0.3)
182 if (cls.demoplayback)
185 DrawQ_Pic (64, 0, "net", 0, 0, 1, 1, 1, 1, 0);
193 void SCR_DrawPause (void)
197 if (cls.state != ca_connected)
200 if (!scr_showpause.integer) // turn off for screenshots
206 pic = Draw_CachePic ("gfx/pause.lmp");
207 DrawQ_Pic ((vid.conwidth - pic->width)/2, (vid.conheight - pic->height)/2, "gfx/pause.lmp", 0, 0, 1, 1, 1, 1, 0);
217 void SCR_DrawLoading (void)
221 pic = Draw_CachePic ("gfx/loading.lmp");
222 DrawQ_Pic ((vid.conwidth - pic->width)/2, (vid.conheight - pic->height)/2, "gfx/loading.lmp", 0, 0, 1, 1, 1, 1, 0);
227 //=============================================================================
232 SCR_SetUpToDrawConsole
235 void SCR_SetUpToDrawConsole (void)
239 // decide on the height of the console
240 con_forcedup = !cl.worldmodel || cls.signon != SIGNONS;
244 scr_conlines = vid.conheight; // full screen
245 scr_con_current = scr_conlines;
247 else if (key_dest == key_console)
248 scr_conlines = vid.conheight/2; // half screen
250 scr_conlines = 0; // none visible
252 if (scr_conlines < scr_con_current)
254 scr_con_current -= scr_conspeed.value*host_realframetime;
255 if (scr_conlines > scr_con_current)
256 scr_con_current = scr_conlines;
259 else if (scr_conlines > scr_con_current)
261 scr_con_current += scr_conspeed.value*host_realframetime;
262 if (scr_conlines < scr_con_current)
263 scr_con_current = scr_conlines;
272 void SCR_DrawConsole (void)
276 Con_DrawConsole (scr_con_current);
281 if (key_dest == key_game || key_dest == key_message)
282 Con_DrawNotify (); // only draw notify in game
288 SCR_BeginLoadingPlaque
292 void SCR_BeginLoadingPlaque (void)
297 S_StopAllSounds (true);
299 scr_drawloading = true;
301 scr_drawloading = true;
305 //=============================================================================
307 char r_speeds_string[1024];
308 int speedstringcount, r_timereport_active;
309 double r_timereport_temp = 0, r_timereport_current = 0, r_timereport_start = 0;
311 void R_TimeReport(char *desc)
317 if (!r_timereport_active)
320 r_timereport_temp = r_timereport_current;
321 r_timereport_current = Sys_DoubleTime();
322 t = (int) ((r_timereport_current - r_timereport_temp) * 1000000.0);
324 sprintf(tempbuf, "%8i %s", t, desc);
325 length = strlen(tempbuf);
327 tempbuf[length++] = ' ';
329 if (speedstringcount + length > (vid.conwidth / 8))
331 strcat(r_speeds_string, "\n");
332 speedstringcount = 0;
334 // skip the space at the beginning if it's the first on the line
335 if (speedstringcount == 0)
337 strcat(r_speeds_string, tempbuf + 1);
338 speedstringcount = length - 1;
342 strcat(r_speeds_string, tempbuf);
343 speedstringcount += length;
347 void R_TimeReport_Start(void)
349 r_timereport_active = r_speeds.integer && cl.worldmodel && cls.state == ca_connected;
350 r_speeds_string[0] = 0;
351 if (r_timereport_active)
353 speedstringcount = 0;
354 AngleVectors (r_refdef.viewangles, vpn, NULL, NULL);
355 sprintf(r_speeds_string,
356 "org:'%+8.2f %+8.2f %+8.2f' ang:'%+4.0f %+4.0f %+4.0f' dir:'%+2.3f %+2.3f %+2.3f'\n"
357 "world:%6i faces%6i nodes%6i leafs%6i walls%6i dlitwalls\n"
358 "%5i models%5i bmodels%5i sprites%6i particles%4i dlights\n"
359 "%6i modeltris%6i transmeshs%6i transtris%6i meshs%6i meshtris\n",
360 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],
361 c_faces, c_nodes, c_leafs, c_brush_polys, c_light_polys,
362 c_models, c_bmodels, c_sprites, c_particles, c_dlights,
363 c_alias_polys, c_transmeshs, c_transtris, c_meshs, c_meshtris);
376 r_timereport_start = Sys_DoubleTime();
380 void R_TimeReport_End(void)
382 r_timereport_current = r_timereport_start;
383 R_TimeReport("total");
385 if (r_timereport_active)
389 for (i = 0;r_speeds_string[i];i++)
390 if (r_speeds_string[i] == '\n')
392 y = vid.conheight - sb_lines - lines * 8;
394 DrawQ_Fill(0, y, vid.conwidth, lines * 8, 0, 0, 0, 0.5, 0);
395 while (r_speeds_string[i])
398 while (r_speeds_string[i] && r_speeds_string[i] != '\n')
401 DrawQ_String(0, y, r_speeds_string + j, i - j, 8, 8, 1, 1, 1, 1, 0);
402 if (r_speeds_string[i] == '\n')
416 void SCR_SizeUp_f (void)
418 Cvar_SetValue ("viewsize",scr_viewsize.value+10);
429 void SCR_SizeDown_f (void)
431 Cvar_SetValue ("viewsize",scr_viewsize.value-10);
434 void CL_Screen_Init(void)
438 Cvar_RegisterVariable (&scr_fov);
439 Cvar_RegisterVariable (&scr_viewsize);
440 Cvar_RegisterVariable (&scr_conspeed);
441 Cvar_RegisterVariable (&scr_showram);
442 Cvar_RegisterVariable (&scr_showturtle);
443 Cvar_RegisterVariable (&scr_showpause);
444 Cvar_RegisterVariable (&scr_centertime);
445 Cvar_RegisterVariable (&scr_printspeed);
446 Cvar_RegisterVariable (&scr_2dresolution);
447 Cvar_RegisterVariable (&cl_avidemo);
449 Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
450 Cmd_AddCommand ("sizedown",SCR_SizeDown_f);
451 Cmd_AddCommand ("screenshot",SCR_ScreenShot_f);
452 Cmd_AddCommand ("envmap", R_Envmap_f);
454 scr_initialized = true;
457 // load the image data for the player image in the config menu
458 dat = (qpic_t *)COM_LoadFile ("gfx/menuplyr.lmp", false);
460 Sys_Error("unable to load gfx/menuplyr.lmp");
463 if (dat->width*dat->height <= 4096)
464 memcpy (menuplyr_pixels, dat->data, dat->width * dat->height);
466 Con_Printf("gfx/menuplyr.lmp larger than 4k buffer");
470 void DrawQ_Clear(void)
472 r_refdef.drawqueuesize = 0;
475 void DrawQ_Pic(float x, float y, char *picname, float width, float height, float red, float green, float blue, float alpha, int flags)
479 if (alpha < (1.0f / 255.0f))
481 size = sizeof(*dq) + ((strlen(picname) + 1 + 3) & ~3);
482 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
484 red = bound(0, red, 1);
485 green = bound(0, green, 1);
486 blue = bound(0, blue, 1);
487 alpha = bound(0, alpha, 1);
488 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
490 dq->command = DRAWQUEUE_PIC;
492 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));
495 // if these are not zero, they override the pic's size
498 strcpy((char *)(dq + 1), picname);
499 r_refdef.drawqueuesize += dq->size;
502 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)
507 if (alpha < (1.0f / 255.0f))
510 len = strlen(string);
512 for (len = 0;len < maxlen && string[len];len++);
513 for (;len > 0 && string[0] == ' ';string++, x += scalex, len--);
514 for (;len > 0 && string[len - 1] == ' ';len--);
517 if (x >= vid.conwidth || y >= vid.conheight || x < (-scalex * maxlen) || y < (-scaley))
519 size = sizeof(*dq) + ((len + 1 + 3) & ~3);
520 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
522 red = bound(0, red, 1);
523 green = bound(0, green, 1);
524 blue = bound(0, blue, 1);
525 alpha = bound(0, alpha, 1);
526 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
528 dq->command = DRAWQUEUE_STRING;
530 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));
535 out = (char *)(dq + 1);
536 memcpy(out, string, len);
538 r_refdef.drawqueuesize += dq->size;
541 void DrawQ_Fill (float x, float y, float w, float h, float red, float green, float blue, float alpha, int flags)
545 if (alpha < (1.0f / 255.0f))
547 size = sizeof(*dq) + 4;
548 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
550 red = bound(0, red, 1);
551 green = bound(0, green, 1);
552 blue = bound(0, blue, 1);
553 alpha = bound(0, alpha, 1);
554 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
556 dq->command = DRAWQUEUE_PIC;
558 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));
564 *((char *)(dq + 1)) = 0;
565 r_refdef.drawqueuesize += dq->size;
568 //only used for the player color selection menu
569 void DrawQ_PicTranslate (int x, int y, char *picname, qbyte *translation)
572 unsigned int trans[4096];
575 pic = Draw_CachePic(picname);
579 c = pic->width * pic->height;
582 Con_Printf("DrawQ_PicTranslate: image larger than 4k buffer\n");
586 for (i = 0;i < c;i++)
587 trans[i] = d_8to24table[translation[menuplyr_pixels[i]]];
589 // FIXME: this is renderer stuff?
590 R_UpdateTexture (pic->tex, (qbyte *)trans);
592 DrawQ_Pic(x, y, picname, 0, 0, 1, 1, 1, 1, 0);
601 float CalcFov (float fov_x, float width, float height)
603 // calculate vision size and alter by aspect, then convert back to angle
604 return atan (height / (width / tan(fov_x/360*M_PI))) * 360 / M_PI;
611 Must be called whenever vid changes
615 static void SCR_CalcRefdef (void)
620 //========================================
623 if (scr_viewsize.value < 30)
624 Cvar_Set ("viewsize","30");
625 if (scr_viewsize.value > 120)
626 Cvar_Set ("viewsize","120");
628 // bound field of view
629 if (scr_fov.value < 10)
630 Cvar_Set ("fov","10");
631 if (scr_fov.value > 170)
632 Cvar_Set ("fov","170");
634 // intermission is always full screen
642 if (scr_viewsize.value >= 120)
643 sb_lines = 0; // no status bar at all
644 else if (scr_viewsize.value >= 110)
645 sb_lines = 24; // no inventory
648 size = scr_viewsize.value * (1.0 / 100.0);
653 r_refdef.width = vid.realwidth;
654 r_refdef.height = vid.realheight;
660 r_refdef.width = vid.realwidth * size;
661 r_refdef.height = vid.realheight * size;
662 r_refdef.x = (vid.realwidth - r_refdef.width)/2;
663 r_refdef.y = (vid.realheight - r_refdef.height)/2;
666 r_refdef.width = bound(0, r_refdef.width, vid.realwidth);
667 r_refdef.height = bound(0, r_refdef.height, vid.realheight);
668 r_refdef.x = bound(0, r_refdef.x, vid.realwidth - r_refdef.width) + vid.realx;
669 r_refdef.y = bound(0, r_refdef.y, vid.realheight - r_refdef.height) + vid.realy;
671 // LordHavoc: viewzoom (zoom in for sniper rifles, etc)
672 r_refdef.fov_x = scr_fov.value * cl.viewzoom;
673 r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.width, r_refdef.height);
677 Mod_CheckLoaded(cl.worldmodel);
678 contents = Mod_PointInLeaf(r_refdef.vieworg, cl.worldmodel)->contents;
679 if (contents != CONTENTS_EMPTY && contents != CONTENTS_SOLID)
681 r_refdef.fov_x *= (sin(cl.time * 4.7) * 0.015 + 0.985);
682 r_refdef.fov_y *= (sin(cl.time * 3.0) * 0.015 + 0.985);
692 void SCR_ScreenShot_f (void)
696 char checkname[MAX_OSPATH];
698 // find a file name to save it to
700 for (; i<=9999 ; i++)
702 sprintf (filename, "dp%04i.tga", i);
703 sprintf (checkname, "%s/%s", com_gamedir, filename);
704 if (Sys_FileTime(checkname) == -1)
705 break; // file doesn't exist
709 Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
713 if (SCR_ScreenShot(filename, vid.realx, vid.realy, vid.realwidth, vid.realheight))
714 Con_Printf ("Wrote %s\n", filename);
716 Con_Printf ("unable to write %s\n", filename);
719 static int cl_avidemo_frame = 0;
721 void SCR_CaptureAVIDemo(void)
724 sprintf(filename, "dpavi%06d.tga", cl_avidemo_frame);
725 if (SCR_ScreenShot(filename, vid.realx, vid.realy, vid.realwidth, vid.realheight))
729 Cvar_SetValueQuick(&cl_avidemo, 0);
730 Con_Printf("avi saving failed on frame %i, out of disk space? stopping avi demo catpure.\n", cl_avidemo_frame);
731 cl_avidemo_frame = 0;
739 Grab six views for environment mapping tests
751 {{ 0, 180, 0}, "bk"},
752 {{ 0, 270, 0}, "lf"},
753 {{-90, 90, 0}, "up"},
757 static void R_Envmap_f (void)
760 char filename[256], basename[256];
764 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");
768 strcpy(basename, Cmd_Argv(1));
769 size = atoi(Cmd_Argv(2));
770 if (size != 128 && size != 256 && size != 512 && size != 1024)
772 Con_Printf("envmap: size must be one of 128, 256, 512, or 1024\n");
775 if (size > vid.realwidth || size > vid.realheight)
777 Con_Printf("envmap: your resolution is not big enough to render that size\n");
785 r_refdef.width = size;
786 r_refdef.height = size;
791 for (j = 0;j < 6;j++)
793 sprintf(filename, "env/%s%s.tga", basename, envmapinfo[j].name);
794 VectorCopy(envmapinfo[j].angles, r_refdef.viewangles);
797 SCR_ScreenShot(filename, vid.realx, vid.realy, size, size);
803 //=============================================================================
805 // LordHavoc: SHOWLMP stuff
806 #define SHOWLMP_MAXLABELS 256
807 typedef struct showlmp_s
817 showlmp_t showlmp[SHOWLMP_MAXLABELS];
819 void SHOWLMP_decodehide(void)
823 lmplabel = MSG_ReadString();
824 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
825 if (showlmp[i].isactive && strcmp(showlmp[i].label, lmplabel) == 0)
827 showlmp[i].isactive = false;
832 void SHOWLMP_decodeshow(void)
835 qbyte lmplabel[256], picname[256];
837 strcpy(lmplabel,MSG_ReadString());
838 strcpy(picname, MSG_ReadString());
839 if (gamemode == GAME_NEHAHRA) // LordHavoc: nasty old legacy junk
850 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
851 if (showlmp[i].isactive)
853 if (strcmp(showlmp[i].label, lmplabel) == 0)
856 break; // drop out to replace it
859 else if (k < 0) // find first empty one to replace
862 return; // none found to replace
863 // change existing one
864 showlmp[k].isactive = true;
865 strcpy(showlmp[k].label, lmplabel);
866 strcpy(showlmp[k].pic, picname);
871 void SHOWLMP_drawall(void)
875 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
876 if (showlmp[i].isactive)
877 DrawQ_Pic(showlmp[i].x, showlmp[i].y, showlmp[i].pic, 0, 0, 1, 1, 1, 1, 0);
880 void SHOWLMP_clear(void)
883 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
884 showlmp[i].isactive = false;
887 void CL_SetupScreenSize(void)
889 static float old2dresolution = -1;
891 VID_GetWindowSize (&vid.realx, &vid.realy, &vid.realwidth, &vid.realheight);
893 VID_UpdateGamma(false);
895 if (scr_2dresolution.value != old2dresolution)
897 Cvar_SetValue("scr_2dresolution", bound(0.0f, scr_2dresolution.value, 1.0f));
898 old2dresolution = scr_2dresolution.value;
901 if (vid.realwidth > 320)
903 vid.conwidth = (vid.realwidth - 320) * scr_2dresolution.value + 320;
904 vid.conwidth = bound(320, vid.conwidth, vid.realwidth);
909 if (vid.realheight > 240)
911 vid.conheight = (vid.realheight - 240) * scr_2dresolution.value + 240;
912 vid.conheight = bound(240, vid.conheight, vid.realheight);
917 SCR_SetUpToDrawConsole();
919 // determine size of refresh window
923 void CL_UpdateScreen(void)
925 if (!scr_initialized || !con_initialized)
926 return; // not initialized yet
928 if (cl_avidemo.integer)
929 SCR_CaptureAVIDemo();
931 cl_avidemo_frame = 0;
933 R_TimeReport("other");
935 CL_SetupScreenSize();
942 R_TimeReport("setup");
950 SCR_CheckDrawCenterString();
959 scr_drawloading = false;
965 // add r_speeds text to queue
968 // start a new timing run
969 R_TimeReport_Start();
971 // make menu fade everything else on the screen
977 void CL_Screen_NewMap(void)