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"};
14 qboolean scr_initialized; // ready to draw
16 float scr_con_current;
17 float scr_conlines; // lines of console to display
22 //qboolean scr_disabled_for_loading;
23 qboolean scr_drawloading = false;
24 //float scr_disabled_time;
26 static qbyte menuplyr_pixels[4096];
28 void DrawCrosshair(int num);
29 void V_CalcRefdef (void);
30 static void SCR_ScreenShot_f (void);
31 static void R_Envmap_f (void);
34 void R_ClearScreen(void);
37 ===============================================================================
41 ===============================================================================
44 char scr_centerstring[1024];
45 float scr_centertime_start; // for slow victory printing
46 float scr_centertime_off;
55 Called for important messages that should stay in the center of the screen
59 void SCR_CenterPrint (char *str)
61 strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1);
62 scr_centertime_off = scr_centertime.value;
63 scr_centertime_start = cl.time;
65 // count the number of lines for centering
76 void SCR_DrawCenterString (void)
83 // the finale prints the characters one at a time
85 remaining = scr_printspeed.value * (cl.time - scr_centertime_start);
90 start = scr_centerstring;
92 if (scr_center_lines <= 4)
93 y = vid.conheight*0.35;
99 // scan the width of the line
100 for (l=0 ; l<40 ; l++)
101 if (start[l] == '\n' || !start[l])
103 x = (vid.conwidth - l*8)/2;
108 DrawQ_String(x, y, start, l, 8, 8, 1, 1, 1, 1, 0);
116 while (*start && *start != '\n')
121 start++; // skip the \n
125 void SCR_CheckDrawCenterString (void)
127 if (scr_center_lines > scr_erase_lines)
128 scr_erase_lines = scr_center_lines;
130 scr_centertime_off -= host_frametime;
132 if (scr_centertime_off <= 0 && !cl.intermission)
134 if (key_dest != key_game)
137 SCR_DrawCenterString ();
145 void SCR_DrawRam (void)
147 // if (!scr_showram.integer)
149 // DrawQ_Pic (32, 0, "ram", 0, 0, 1, 1, 1, 1, 0);
157 void SCR_DrawTurtle (void)
161 if (cls.state != ca_connected)
164 if (!scr_showturtle.integer)
167 if (host_frametime < 0.1)
177 DrawQ_Pic (0, 0, "turtle", 0, 0, 1, 1, 1, 1, 0);
185 void SCR_DrawNet (void)
187 if (cls.state != ca_connected)
189 if (realtime - cl.last_received_message < 0.3)
191 if (cls.demoplayback)
194 DrawQ_Pic (64, 0, "net", 0, 0, 1, 1, 1, 1, 0);
202 void SCR_DrawPause (void)
206 if (cls.state != ca_connected)
209 if (!scr_showpause.integer) // turn off for screenshots
215 pic = Draw_CachePic ("gfx/pause.lmp");
216 DrawQ_Pic ((vid.conwidth - pic->width)/2, (vid.conheight - pic->height)/2, "gfx/pause.lmp", 0, 0, 1, 1, 1, 1, 0);
226 void SCR_DrawLoading (void)
230 //if (!scr_drawloading)
233 pic = Draw_CachePic ("gfx/loading.lmp");
234 DrawQ_Pic ((vid.conwidth - pic->width)/2, (vid.conheight - pic->height)/2, "gfx/loading.lmp", 0, 0, 1, 1, 1, 1, 0);
239 //=============================================================================
244 SCR_SetUpToDrawConsole
247 void SCR_SetUpToDrawConsole (void)
251 // decide on the height of the console
252 con_forcedup = !cl.worldmodel || cls.signon != SIGNONS;
256 scr_conlines = vid.conheight; // full screen
257 scr_con_current = scr_conlines;
259 else if (key_dest == key_console)
260 scr_conlines = vid.conheight/2; // half screen
262 scr_conlines = 0; // none visible
264 if (scr_conlines < scr_con_current)
266 scr_con_current -= scr_conspeed.value*host_realframetime;
267 if (scr_conlines > scr_con_current)
268 scr_con_current = scr_conlines;
271 else if (scr_conlines > scr_con_current)
273 scr_con_current += scr_conspeed.value*host_realframetime;
274 if (scr_conlines < scr_con_current)
275 scr_con_current = scr_conlines;
284 void SCR_DrawConsole (void)
288 Con_DrawConsole (scr_con_current);
293 if (key_dest == key_game || key_dest == key_message)
294 Con_DrawNotify (); // only draw notify in game
300 SCR_BeginLoadingPlaque
304 void SCR_BeginLoadingPlaque (void)
309 S_StopAllSounds (true);
311 // if (cls.state != ca_connected)
313 // if (cls.signon != SIGNONS)
316 // redraw with no console and the loading plaque
317 // Con_ClearNotify ();
318 // scr_centertime_off = 0;
319 // scr_con_current = 0;
321 scr_drawloading = true;
323 scr_drawloading = true;
325 //scr_drawloading = false;
327 // scr_disabled_for_loading = true;
328 // scr_disabled_time = realtime;
337 void SCR_EndLoadingPlaque (void)
340 if (!scr_drawloading)
343 // scr_disabled_for_loading = false;
344 scr_drawloading = false;
349 //=============================================================================
351 char *scr_notifystring;
353 void SCR_DrawNotifyString (void)
359 start = scr_notifystring;
361 y = vid.conheight*0.35;
365 // scan the width of the line
366 for (l=0 ; l<40 ; l++)
367 if (start[l] == '\n' || !start[l])
369 x = (vid.conwidth - l*8)/2;
370 DrawQ_String (x, y, start, l, 8, 8, 1, 1, 1, 1, 0);
374 while (*start && *start != '\n')
379 start++; // skip the \n
384 char r_speeds_string[1024];
385 int speedstringcount, r_timereport_active;
386 double r_timereport_temp = 0, r_timereport_current = 0, r_timereport_start = 0;
388 void R_TimeReport(char *desc)
394 if (!r_timereport_active)
397 r_timereport_temp = r_timereport_current;
398 r_timereport_current = Sys_DoubleTime();
399 t = (int) ((r_timereport_current - r_timereport_temp) * 1000000.0);
401 sprintf(tempbuf, "%8i %s", t, desc);
402 length = strlen(tempbuf);
404 tempbuf[length++] = ' ';
406 if (speedstringcount + length > (vid.conwidth / 8))
408 strcat(r_speeds_string, "\n");
409 speedstringcount = 0;
411 // skip the space at the beginning if it's the first on the line
412 if (speedstringcount == 0)
414 strcat(r_speeds_string, tempbuf + 1);
415 speedstringcount = length - 1;
419 strcat(r_speeds_string, tempbuf);
420 speedstringcount += length;
424 void R_TimeReport_Start(void)
426 r_timereport_active = r_speeds.integer && cl.worldmodel && cls.state == ca_connected;
427 r_speeds_string[0] = 0;
428 if (r_timereport_active)
430 speedstringcount = 0;
431 AngleVectors (r_refdef.viewangles, vpn, NULL, NULL);
432 //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",
433 // 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]),
434 // 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]),
435 // vpn[0] < 0 ? '-' : ' ', fabs(vpn[0]), vpn[1] < 0 ? '-' : ' ', fabs(vpn[1]), vpn[2] < 0 ? '-' : ' ', fabs(vpn[2]),
436 sprintf(r_speeds_string,
437 "org:'%+8.2f %+8.2f %+8.2f' ang:'%+4.0f %+4.0f %+4.0f' dir:'%+2.3f %+2.3f %+2.3f'\n"
438 "world:%6i faces%6i nodes%6i leafs%6i walls%6i dlitwalls\n"
439 "%5i models%5i bmodels%5i sprites%6i particles%4i dlights\n"
440 "%6i modeltris%6i transmeshs%6i transtris%6i meshs%6i meshtris\n",
441 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],
442 c_faces, c_nodes, c_leafs, c_brush_polys, c_light_polys,
443 c_models, c_bmodels, c_sprites, c_particles, c_dlights,
444 c_alias_polys, c_transmeshs, c_transtris, c_meshs, c_meshtris);
458 r_timereport_start = Sys_DoubleTime();
462 void R_TimeReport_End(void)
464 r_timereport_current = r_timereport_start;
465 R_TimeReport("total");
467 if (r_timereport_active)
471 for (i = 0;r_speeds_string[i];i++)
472 if (r_speeds_string[i] == '\n')
474 y = vid.conheight - sb_lines - lines * 8/* - 8*/;
476 DrawQ_Fill(0, y, vid.conwidth, lines * 8, 0, 0, 0, 0.5, 0);
477 while (r_speeds_string[i])
480 while (r_speeds_string[i] && r_speeds_string[i] != '\n')
483 DrawQ_String(0, y, r_speeds_string + j, i - j, 8, 8, 1, 1, 1, 1, 0);
484 if (r_speeds_string[i] == '\n')
498 void SCR_SizeUp_f (void)
500 Cvar_SetValue ("viewsize",scr_viewsize.value+10);
511 void SCR_SizeDown_f (void)
513 Cvar_SetValue ("viewsize",scr_viewsize.value-10);
516 void CL_Screen_Init(void)
520 Cvar_RegisterVariable (&scr_fov);
521 Cvar_RegisterVariable (&scr_viewsize);
522 Cvar_RegisterVariable (&scr_conspeed);
523 Cvar_RegisterVariable (&scr_showram);
524 Cvar_RegisterVariable (&scr_showturtle);
525 Cvar_RegisterVariable (&scr_showpause);
526 Cvar_RegisterVariable (&scr_centertime);
527 Cvar_RegisterVariable (&scr_printspeed);
528 Cvar_RegisterVariable(&scr_2dresolution);
530 Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
531 Cmd_AddCommand ("sizedown",SCR_SizeDown_f);
532 Cmd_AddCommand ("screenshot",SCR_ScreenShot_f);
533 Cmd_AddCommand ("envmap", R_Envmap_f);
535 scr_initialized = true;
538 // load the image data for the player image in the config menu
539 dat = (qpic_t *)COM_LoadFile ("gfx/menuplyr.lmp", false);
541 Sys_Error("unable to load gfx/menuplyr.lmp");
544 if (dat->width*dat->height <= 4096)
545 memcpy (menuplyr_pixels, dat->data, dat->width * dat->height);
547 Con_Printf("gfx/menuplyr.lmp larger than 4k buffer");
551 void DrawQ_Clear(void)
553 r_refdef.drawqueuesize = 0;
556 void DrawQ_Pic(float x, float y, char *picname, float width, float height, float red, float green, float blue, float alpha, int flags)
560 if (alpha < (1.0f / 255.0f))
562 size = sizeof(*dq) + ((strlen(picname) + 1 + 3) & ~3);
563 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
565 red = bound(0, red, 1);
566 green = bound(0, green, 1);
567 blue = bound(0, blue, 1);
568 alpha = bound(0, alpha, 1);
569 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
571 dq->command = DRAWQUEUE_PIC;
573 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));
576 // if these are not zero, they override the pic's size
579 strcpy((char *)(dq + 1), picname);
580 r_refdef.drawqueuesize += dq->size;
583 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)
588 if (alpha < (1.0f / 255.0f))
591 len = strlen(string);
593 for (len = 0;len < maxlen && string[len];len++);
594 for (;len > 0 && string[0] == ' ';string++, x += scalex, len--);
595 for (;len > 0 && string[len - 1] == ' ';len--);
598 if (x >= vid.conwidth || y >= vid.conheight || x < (-scalex * maxlen) || y < (-scaley))
600 size = sizeof(*dq) + ((len + 1 + 3) & ~3);
601 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
603 red = bound(0, red, 1);
604 green = bound(0, green, 1);
605 blue = bound(0, blue, 1);
606 alpha = bound(0, alpha, 1);
607 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
609 dq->command = DRAWQUEUE_STRING;
611 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));
616 out = (char *)(dq + 1);
617 memcpy(out, string, len);
619 r_refdef.drawqueuesize += dq->size;
622 void DrawQ_Fill (float x, float y, float w, float h, float red, float green, float blue, float alpha, int flags)
626 if (alpha < (1.0f / 255.0f))
628 size = sizeof(*dq) + 4;
629 if (r_refdef.drawqueuesize + size > MAX_DRAWQUEUE)
631 red = bound(0, red, 1);
632 green = bound(0, green, 1);
633 blue = bound(0, blue, 1);
634 alpha = bound(0, alpha, 1);
635 dq = (void *)(r_refdef.drawqueue + r_refdef.drawqueuesize);
637 dq->command = DRAWQUEUE_PIC;
639 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));
645 *((char *)(dq + 1)) = 0;
646 r_refdef.drawqueuesize += dq->size;
649 //only used for the player color selection menu
650 void DrawQ_PicTranslate (int x, int y, char *picname, qbyte *translation)
653 unsigned int trans[4096];
656 pic = Draw_CachePic(picname);
660 c = pic->width * pic->height;
663 Con_Printf("DrawQ_PicTranslate: image larger than 4k buffer\n");
667 for (i = 0;i < c;i++)
668 trans[i] = d_8to24table[translation[menuplyr_pixels[i]]];
670 // FIXME: this is renderer stuff?
671 R_UpdateTexture (pic->tex, (qbyte *)trans);
673 DrawQ_Pic(x, y, picname, 0, 0, 1, 1, 1, 1, 0);
682 float CalcFov (float fov_x, float width, float height)
684 // calculate vision size and alter by aspect, then convert back to angle
685 return atan (height / (width / tan(fov_x/360*M_PI))) * 360 / M_PI;
692 Must be called whenever vid changes
696 static void SCR_CalcRefdef (void)
701 //========================================
704 if (scr_viewsize.value < 30)
705 Cvar_Set ("viewsize","30");
706 if (scr_viewsize.value > 120)
707 Cvar_Set ("viewsize","120");
709 // bound field of view
710 if (scr_fov.value < 10)
711 Cvar_Set ("fov","10");
712 if (scr_fov.value > 170)
713 Cvar_Set ("fov","170");
715 // intermission is always full screen
723 if (scr_viewsize.value >= 120)
724 sb_lines = 0; // no status bar at all
725 else if (scr_viewsize.value >= 110)
726 sb_lines = 24; // no inventory
729 size = scr_viewsize.value * (1.0 / 100.0);
734 r_refdef.width = vid.realwidth;
735 r_refdef.height = vid.realheight;
741 r_refdef.width = vid.realwidth * size;
742 r_refdef.height = vid.realheight * size;
743 r_refdef.x = (vid.realwidth - r_refdef.width)/2;
744 r_refdef.y = (vid.realheight - r_refdef.height)/2;
747 r_refdef.width = bound(0, r_refdef.width, vid.realwidth);
748 r_refdef.height = bound(0, r_refdef.height, vid.realheight);
749 r_refdef.x = bound(0, r_refdef.x, vid.realwidth - r_refdef.width) + vid.realx;
750 r_refdef.y = bound(0, r_refdef.y, vid.realheight - r_refdef.height) + vid.realy;
752 // LordHavoc: viewzoom (zoom in for sniper rifles, etc)
753 r_refdef.fov_x = scr_fov.value * cl.viewzoom;
754 r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.width, r_refdef.height);
758 Mod_CheckLoaded(cl.worldmodel);
759 contents = Mod_PointInLeaf(r_refdef.vieworg, cl.worldmodel)->contents;
760 if (contents != CONTENTS_EMPTY && contents != CONTENTS_SOLID)
762 r_refdef.fov_x *= (sin(cl.time * 4.7) * 0.015 + 0.985);
763 r_refdef.fov_y *= (sin(cl.time * 3.0) * 0.015 + 0.985);
773 void SCR_ScreenShot_f (void)
777 char checkname[MAX_OSPATH];
779 // find a file name to save it to
781 strcpy(filename, "dp0000.tga");
783 for (i=0 ; i<=9999 ; i++)
785 filename[2] = (i/1000)%10 + '0';
786 filename[3] = (i/ 100)%10 + '0';
787 filename[4] = (i/ 10)%10 + '0';
788 filename[5] = (i/ 1)%10 + '0';
789 sprintf (checkname, "%s/%s", com_gamedir, filename);
790 if (Sys_FileTime(checkname) == -1)
791 break; // file doesn't exist
795 Con_Printf ("SCR_ScreenShot_f: Couldn't create a TGA file\n");
799 SCR_ScreenShot(filename, vid.realx, vid.realy, vid.realwidth, vid.realheight);
800 Con_Printf ("Wrote %s\n", filename);
807 Grab six views for environment mapping tests
819 {{ 0, 180, 0}, "bk"},
820 {{ 0, 270, 0}, "lf"},
821 {{-90, 90, 0}, "up"},
825 static void R_Envmap_f (void)
828 char filename[256], basename[256];
832 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");
836 strcpy(basename, Cmd_Argv(1));
837 size = atoi(Cmd_Argv(2));
838 if (size != 128 && size != 256 && size != 512 && size != 1024)
840 Con_Printf("envmap: size must be one of 128, 256, 512, or 1024\n");
843 if (size > vid.realwidth || size > vid.realheight)
845 Con_Printf("envmap: your resolution is not big enough to render that size\n");
853 r_refdef.width = size;
854 r_refdef.height = size;
859 for (j = 0;j < 6;j++)
861 sprintf(filename, "env/%s%s.tga", basename, envmapinfo[j].name);
862 VectorCopy(envmapinfo[j].angles, r_refdef.viewangles);
865 SCR_ScreenShot(filename, vid.realx, vid.realy, size, size);
871 //=============================================================================
873 // LordHavoc: SHOWLMP stuff
874 #define SHOWLMP_MAXLABELS 256
875 typedef struct showlmp_s
885 showlmp_t showlmp[SHOWLMP_MAXLABELS];
887 void SHOWLMP_decodehide(void)
891 lmplabel = MSG_ReadString();
892 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
893 if (showlmp[i].isactive && strcmp(showlmp[i].label, lmplabel) == 0)
895 showlmp[i].isactive = false;
900 void SHOWLMP_decodeshow(void)
903 qbyte lmplabel[256], picname[256];
905 strcpy(lmplabel,MSG_ReadString());
906 strcpy(picname, MSG_ReadString());
907 if (gamemode == GAME_NEHAHRA) // LordHavoc: nasty old legacy junk
918 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
919 if (showlmp[i].isactive)
921 if (strcmp(showlmp[i].label, lmplabel) == 0)
924 break; // drop out to replace it
927 else if (k < 0) // find first empty one to replace
930 return; // none found to replace
931 // change existing one
932 showlmp[k].isactive = true;
933 strcpy(showlmp[k].label, lmplabel);
934 strcpy(showlmp[k].pic, picname);
939 void SHOWLMP_drawall(void)
943 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
944 if (showlmp[i].isactive)
945 DrawQ_Pic(showlmp[i].x, showlmp[i].y, showlmp[i].pic, 0, 0, 1, 1, 1, 1, 0);
948 void SHOWLMP_clear(void)
951 for (i = 0;i < SHOWLMP_MAXLABELS;i++)
952 showlmp[i].isactive = false;
955 void CL_SetupScreenSize(void)
957 static float old2dresolution = -1;
959 VID_GetWindowSize (&vid.realx, &vid.realy, &vid.realwidth, &vid.realheight);
961 VID_UpdateGamma(false);
963 if (scr_2dresolution.value != old2dresolution)
965 Cvar_SetValue("scr_2dresolution", bound(0.0f, scr_2dresolution.value, 1.0f));
966 old2dresolution = scr_2dresolution.value;
969 if (vid.realwidth > 320)
971 vid.conwidth = (vid.realwidth - 320) * scr_2dresolution.value + 320;
972 vid.conwidth = bound(320, vid.conwidth, vid.realwidth);
977 if (vid.realheight > 240)
979 vid.conheight = (vid.realheight - 240) * scr_2dresolution.value + 240;
980 vid.conheight = bound(240, vid.conheight, vid.realheight);
985 SCR_SetUpToDrawConsole();
987 // determine size of refresh window
991 void CL_UpdateScreen(void)
993 if (!scr_initialized || !con_initialized)
994 return; // not initialized yet
997 R_TimeReport("other");
999 CL_SetupScreenSize();
1006 R_TimeReport("setup");
1012 SCR_CheckDrawCenterString();
1020 if (scr_drawloading)
1022 scr_drawloading = false;
1028 // add r_speeds text to queue
1031 // start a new timing run
1032 R_TimeReport_Start();
1034 // make menu fade everything else on the screen
1040 void CL_Screen_NewMap(void)