home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quakeworld_src / client / screen.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  23.3 KB  |  1,177 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // screen.c -- master for refresh, status bar, console, chat, notify, etc
  21.  
  22. #include "quakedef.h"
  23. #include "r_local.h"
  24.  
  25. #include <time.h>
  26.  
  27. /*
  28.  
  29. background clear
  30. rendering
  31. turtle/net/ram icons
  32. sbar
  33. centerprint / slow centerprint
  34. notify lines
  35. intermission / finale overlay
  36. loading plaque
  37. console
  38. menu
  39.  
  40. required background clears
  41. required update regions
  42.  
  43.  
  44. syncronous draw mode or async
  45. One off screen buffer, with updates either copied or xblited
  46. Need to double buffer?
  47.  
  48.  
  49. async draw will require the refresh area to be cleared, because it will be
  50. xblited, but sync draw can just ignore it.
  51.  
  52. sync
  53. draw
  54.  
  55. CenterPrint ()
  56. SlowPrint ()
  57. Screen_Update ();
  58. Con_Printf ();
  59.  
  60. net 
  61. turn off messages option
  62.  
  63. the refresh is allways rendered, unless the console is full screen
  64.  
  65.  
  66. console is:
  67.   notify lines
  68.   half
  69.   full
  70.   
  71.  
  72. */
  73.  
  74.  
  75. // only the refresh window will be updated unless these variables are flagged 
  76. int     scr_copytop;
  77. int     scr_copyeverything;
  78.  
  79. float   scr_con_current;
  80. float   scr_conlines;   // lines of console to display
  81.  
  82. float   oldscreensize, oldfov;
  83. float   oldsbar;
  84. cvar_t    scr_viewsize = {"viewsize","100", true};
  85. cvar_t    scr_fov = {"fov","90"}; // 10 - 170
  86. cvar_t    scr_conspeed = {"scr_conspeed","300"};
  87. cvar_t    scr_centertime = {"scr_centertime","2"};
  88. cvar_t    scr_showram = {"showram","1"};
  89. cvar_t    scr_showturtle = {"showturtle","0"};
  90. cvar_t    scr_showpause = {"showpause","1"};
  91. cvar_t    scr_printspeed = {"scr_printspeed","8"};
  92. cvar_t    scr_allowsnap = {"scr_allowsnap", "1"};
  93.  
  94. qboolean  scr_initialized;    // ready to draw
  95.  
  96. qpic_t    *scr_ram;
  97. qpic_t    *scr_net;
  98. qpic_t    *scr_turtle;
  99.  
  100. int     scr_fullupdate;
  101.  
  102. int     clearconsole;
  103. int     clearnotify;
  104.  
  105. /*int     sb_lines; @@@ already defined in sbar.c */
  106.  
  107. /* viddef_t  vid; @@@ defined in video driver! */ // global video state
  108.  
  109. vrect_t   *pconupdate;
  110. vrect_t   scr_vrect;
  111.  
  112. qboolean  scr_disabled_for_loading;
  113.  
  114. qboolean  scr_skipupdate;
  115.  
  116. qboolean  block_drawing;
  117.  
  118. void SCR_ScreenShot_f (void);
  119. void SCR_RSShot_f (void);
  120.  
  121. /*
  122. ===============================================================================
  123.  
  124. CENTER PRINTING
  125.  
  126. ===============================================================================
  127. */
  128.  
  129. char    scr_centerstring[1024];
  130. float   scr_centertime_start; // for slow victory printing
  131. float   scr_centertime_off;
  132. int     scr_center_lines;
  133. int     scr_erase_lines;
  134. int     scr_erase_center;
  135.  
  136. /*
  137. ==============
  138. SCR_CenterPrint
  139.  
  140. Called for important messages that should stay in the center of the screen
  141. for a few moments
  142. ==============
  143. */
  144. void SCR_CenterPrint (char *str)
  145. {
  146.   strncpy (scr_centerstring, str, sizeof(scr_centerstring)-1);
  147.   scr_centertime_off = scr_centertime.value;
  148.   scr_centertime_start = cl.time;
  149.  
  150. // count the number of lines for centering
  151.   scr_center_lines = 1;
  152.   while (*str)
  153.   {
  154.     if (*str == '\n')
  155.       scr_center_lines++;
  156.     str++;
  157.   }
  158. }
  159.  
  160. void SCR_EraseCenterString (void)
  161. {
  162.   int   y;
  163.  
  164.   if (scr_erase_center++ > vid.numpages)
  165.   {
  166.     scr_erase_lines = 0;
  167.     return;
  168.   }
  169.  
  170.   if (scr_center_lines <= 4)
  171.     y = vid.height*0.35;
  172.   else
  173.     y = 48;
  174.  
  175.   scr_copytop = 1;
  176.   Draw_TileClear (0, y, vid.width, min(8*scr_erase_lines, vid.height - y - 1));
  177. }
  178.  
  179. void SCR_DrawCenterString (void)
  180. {
  181.   char  *start;
  182.   int   l;
  183.   int   j;
  184.   int   x, y;
  185.   int   remaining;
  186.  
  187. // the finale prints the characters one at a time
  188.   if (cl.intermission)
  189.     remaining = scr_printspeed.value * (cl.time - scr_centertime_start);
  190.   else
  191.     remaining = 9999;
  192.  
  193.   scr_erase_center = 0;
  194.   start = scr_centerstring;
  195.  
  196.   if (scr_center_lines <= 4)
  197.     y = vid.height*0.35;
  198.   else
  199.     y = 48;
  200.  
  201.   do  
  202.   {
  203.   // scan the width of the line
  204.     for (l=0 ; l<40 ; l++)
  205.       if (start[l] == '\n' || !start[l])
  206.         break;
  207.     x = (vid.width - l*8)/2;
  208.     for (j=0 ; j<l ; j++, x+=8)
  209.     {
  210.       Draw_Character (x, y, start[j]);  
  211.       if (!remaining--)
  212.         return;
  213.     }
  214.       
  215.     y += 8;
  216.  
  217.     while (*start && *start != '\n')
  218.       start++;
  219.  
  220.     if (!*start)
  221.       break;
  222.     start++;    // skip the \n
  223.   } while (1);
  224. }
  225.  
  226. void SCR_CheckDrawCenterString (void)
  227. {
  228.   scr_copytop = 1;
  229.   if (scr_center_lines > scr_erase_lines)
  230.     scr_erase_lines = scr_center_lines;
  231.  
  232.   scr_centertime_off -= host_frametime;
  233.   
  234.   if (scr_centertime_off <= 0 && !cl.intermission)
  235.     return;
  236.   if (key_dest != key_game)
  237.     return;
  238.  
  239.   SCR_DrawCenterString ();
  240. }
  241.  
  242. //=============================================================================
  243.  
  244. /*
  245. ====================
  246. CalcFov
  247. ====================
  248. */
  249. float CalcFov (float fov_x, float width, float height)
  250. {
  251.         float   a;
  252.         float   x;
  253.  
  254.         if (fov_x < 1 || fov_x > 179)
  255.                 Sys_Error ("Bad fov: %f", fov_x);
  256.  
  257.         x = width/tan(fov_x/360*M_PI);
  258.  
  259.         a = atan (height/x);
  260.  
  261.         a = a*360/M_PI;
  262.  
  263.         return a;
  264. }
  265.  
  266. /*
  267. =================
  268. SCR_CalcRefdef
  269.  
  270. Must be called whenever vid changes
  271. Internal use only
  272. =================
  273. */
  274. static void SCR_CalcRefdef (void)
  275. {
  276.   vrect_t   vrect;
  277.   float   size;
  278.  
  279.   scr_fullupdate = 0;   // force a background redraw
  280.   vid.recalc_refdef = 0;
  281.  
  282. // force the status bar to redraw
  283.   Sbar_Changed ();
  284.  
  285. //========================================
  286.   
  287. // bound viewsize
  288.   if (scr_viewsize.value < 30)
  289.     Cvar_Set ("viewsize","30");
  290.   if (scr_viewsize.value > 120)
  291.     Cvar_Set ("viewsize","120");
  292.  
  293. // bound field of view
  294.   if (scr_fov.value < 10)
  295.     Cvar_Set ("fov","10");
  296.   if (scr_fov.value > 170)
  297.     Cvar_Set ("fov","170");
  298.  
  299.   r_refdef.fov_x = scr_fov.value;
  300.   r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
  301.  
  302. // intermission is always full screen 
  303.   if (cl.intermission)
  304.     size = 120;
  305.   else
  306.     size = scr_viewsize.value;
  307.  
  308.   if (size >= 120)
  309.     sb_lines = 0;   // no status bar at all
  310.   else if (size >= 110)
  311.     sb_lines = 24;    // no inventory
  312.   else
  313.     sb_lines = 24+16+8;
  314.  
  315. // these calculations mirror those in R_Init() for r_refdef, but take no
  316. // account of water warping
  317.   vrect.x = 0;
  318.   vrect.y = 0;
  319.   vrect.width = vid.width;
  320.   vrect.height = vid.height;
  321.  
  322.   R_SetVrect (&vrect, &scr_vrect, sb_lines);
  323.  
  324. // guard against going from one mode to another that's less than half the
  325. // vertical resolution
  326.   if (scr_con_current > vid.height)
  327.     scr_con_current = vid.height;
  328.  
  329. // notify the refresh of the change
  330.   R_ViewChanged (&vrect, sb_lines, vid.aspect);
  331. }
  332.  
  333.  
  334. /*
  335. =================
  336. SCR_SizeUp_f
  337.  
  338. Keybinding command
  339. =================
  340. */
  341. void SCR_SizeUp_f (void)
  342. {
  343.   if (scr_viewsize.value < 120) {
  344.   Cvar_SetValue ("viewsize",scr_viewsize.value+10);
  345.   vid.recalc_refdef = 1;
  346.   }
  347. }
  348.  
  349.  
  350. /*
  351. =================
  352. SCR_SizeDown_f
  353.  
  354. Keybinding command
  355. =================
  356. */
  357. void SCR_SizeDown_f (void)
  358. {
  359.   Cvar_SetValue ("viewsize",scr_viewsize.value-10);
  360.   vid.recalc_refdef = 1;
  361. }
  362.  
  363. //============================================================================
  364.  
  365. /*
  366. ==================
  367. SCR_Init
  368. ==================
  369. */
  370. void SCR_Init (void)
  371. {
  372.   Cvar_RegisterVariable (&scr_fov);
  373.   Cvar_RegisterVariable (&scr_viewsize);
  374.   Cvar_RegisterVariable (&scr_conspeed);
  375.   Cvar_RegisterVariable (&scr_showram);
  376.   Cvar_RegisterVariable (&scr_showturtle);
  377.   Cvar_RegisterVariable (&scr_showpause);
  378.   Cvar_RegisterVariable (&scr_centertime);
  379.   Cvar_RegisterVariable (&scr_printspeed);
  380.   Cvar_RegisterVariable (&scr_allowsnap);
  381.  
  382. //
  383. // register our commands
  384. //
  385.   Cmd_AddCommand ("screenshot",SCR_ScreenShot_f);
  386.   Cmd_AddCommand ("snap",SCR_RSShot_f);
  387.   Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
  388.   Cmd_AddCommand ("sizedown",SCR_SizeDown_f);
  389.  
  390.   scr_ram = W_GetLumpName ("ram");
  391.   scr_net = W_GetLumpName ("net");
  392.   scr_turtle = W_GetLumpName ("turtle");
  393.  
  394.   scr_initialized = true;
  395. }
  396.  
  397.  
  398.  
  399. /*
  400. ==============
  401. SCR_DrawRam
  402. ==============
  403. */
  404. void SCR_DrawRam (void)
  405. {
  406.   if (!scr_showram.value)
  407.     return;
  408.  
  409.   if (!r_cache_thrash)
  410.     return;
  411.  
  412.   Draw_Pic (scr_vrect.x+32, scr_vrect.y, scr_ram);
  413. }
  414.  
  415. /*
  416. ==============
  417. SCR_DrawTurtle
  418. ==============
  419. */
  420. void SCR_DrawTurtle (void)
  421. {
  422.   static int  count;
  423.   
  424.   if (!scr_showturtle.value)
  425.     return;
  426.  
  427.   if (host_frametime < 0.1)
  428.   {
  429.     count = 0;
  430.     return;
  431.   }
  432.  
  433.   count++;
  434.   if (count < 3)
  435.     return;
  436.  
  437.   Draw_Pic (scr_vrect.x, scr_vrect.y, scr_turtle);
  438. }
  439.  
  440. /*
  441. ==============
  442. SCR_DrawNet
  443. ==============
  444. */
  445. void SCR_DrawNet (void)
  446. {
  447.   if (cls.netchan.outgoing_sequence - cls.netchan.incoming_acknowledged < UPDATE_BACKUP-1)
  448.     return;
  449.   if (cls.demoplayback)
  450.     return;
  451.  
  452.   Draw_Pic (scr_vrect.x+64, scr_vrect.y, scr_net);
  453. }
  454.  
  455. void SCR_DrawFPS (void)
  456. {
  457.   extern cvar_t show_fps;
  458.   static double lastframetime;
  459.   double t;
  460.   extern int fps_count;
  461.   static lastfps;
  462.   int x, y;
  463.   char st[80];
  464.  
  465.   if (!show_fps.value)
  466.     return;
  467.  
  468.   t = Sys_DoubleTime();
  469.   if ((t - lastframetime) >= 1.0) {
  470.     lastfps = fps_count;
  471.     fps_count = 0;
  472.     lastframetime = t;
  473.   }
  474.  
  475.   sprintf(st, "%3d FPS", lastfps);
  476.   x = vid.width - strlen(st) * 8 - 8;
  477.   y = vid.height - sb_lines - 8;
  478. //  Draw_TileClear(x, y, strlen(st) * 8, 8);
  479.   Draw_String(x, y, st);
  480. }
  481.  
  482. /*
  483. ==============
  484. DrawPause
  485. ==============
  486. */
  487. void SCR_DrawPause (void)
  488. {
  489.   qpic_t  *pic;
  490.  
  491.   if (!scr_showpause.value)   // turn off for screenshots
  492.     return;
  493.  
  494.   if (!cl.paused)
  495.     return;
  496.  
  497.   pic = Draw_CachePic ("gfx/pause.lmp");
  498.   Draw_Pic ( (vid.width - pic->width)/2, 
  499.     (vid.height - 48 - pic->height)/2, pic);
  500. }
  501.  
  502.  
  503. //=============================================================================
  504.  
  505.  
  506. /*
  507. ==================
  508. SCR_SetUpToDrawConsole
  509. ==================
  510. */
  511. void SCR_SetUpToDrawConsole (void)
  512. {
  513.   Con_CheckResize ();
  514.   
  515. // decide on the height of the console
  516.   if (cls.state != ca_active)
  517.   {
  518.     scr_conlines = vid.height;    // full screen
  519.     scr_con_current = scr_conlines;
  520.   }
  521.   else if (key_dest == key_console)
  522.     scr_conlines = vid.height/2;  // half screen
  523.   else
  524.     scr_conlines = 0;       // none visible
  525.   
  526.   if (scr_conlines < scr_con_current)
  527.   {
  528.     scr_con_current -= scr_conspeed.value*host_frametime;
  529.     if (scr_conlines > scr_con_current)
  530.       scr_con_current = scr_conlines;
  531.  
  532.   }
  533.   else if (scr_conlines > scr_con_current)
  534.   {
  535.     scr_con_current += scr_conspeed.value*host_frametime;
  536.     if (scr_conlines < scr_con_current)
  537.       scr_con_current = scr_conlines;
  538.   }
  539.  
  540.   if (clearconsole++ < vid.numpages)
  541.   {
  542.     scr_copytop = 1;
  543.     Draw_TileClear (0,(int)scr_con_current,vid.width, vid.height - (int)scr_con_current);
  544.     Sbar_Changed ();
  545.   }
  546.   else if (clearnotify++ < vid.numpages)
  547.   {
  548.     scr_copytop = 1;
  549.     Draw_TileClear (0,0,vid.width, con_notifylines);
  550.   }
  551.   else
  552.     con_notifylines = 0;
  553. }
  554.   
  555. /*
  556. ==================
  557. SCR_DrawConsole
  558. ==================
  559. */
  560. void SCR_DrawConsole (void)
  561. {
  562.   if (scr_con_current)
  563.   {
  564.     scr_copyeverything = 1;
  565.     Con_DrawConsole (scr_con_current);
  566.     clearconsole = 0;
  567.   }
  568.   else
  569.   {
  570.     if (key_dest == key_game || key_dest == key_message)
  571.       Con_DrawNotify ();  // only draw notify in game
  572.   }
  573. }
  574.  
  575.  
  576. /* 
  577. ============================================================================== 
  578.  
  579.             SCREEN SHOTS 
  580.  
  581. ============================================================================== 
  582. */ 
  583.  
  584.  
  585. /* 
  586. ============== 
  587. WritePCXfile 
  588. ============== 
  589. */ 
  590. void WritePCXfile (char *filename, byte *data, int width, int height,
  591.   int rowbytes, byte *palette, qboolean upload) 
  592. {
  593.   int   i, j, length;
  594.   pcx_t *pcx;
  595.   byte    *pack;
  596.     
  597.   pcx = Hunk_TempAlloc (width*height*2+1000);
  598.   if (pcx == NULL)
  599.   {
  600.     Con_Printf("SCR_ScreenShot_f: not enough memory\n");
  601.     return;
  602.   } 
  603.  
  604.   pcx->manufacturer = 0x0a; // PCX id
  605.   pcx->version = 5;     // 256 color
  606.   pcx->encoding = 1;    // uncompressed
  607.   pcx->bits_per_pixel = 8;    // 256 color
  608.   pcx->xmin = 0;
  609.   pcx->ymin = 0;
  610.   pcx->xmax = LittleShort((short)(width-1));
  611.   pcx->ymax = LittleShort((short)(height-1));
  612.   pcx->hres = LittleShort((short)width);
  613.   pcx->vres = LittleShort((short)height);
  614.   Q_memset (pcx->palette,0,sizeof(pcx->palette));
  615.   pcx->color_planes = 1;    // chunky image
  616.   pcx->bytes_per_line = LittleShort((short)width);
  617.   pcx->palette_type = LittleShort(2);   // not a grey scale
  618.   Q_memset (pcx->filler,0,sizeof(pcx->filler));
  619.  
  620. // pack the image
  621.   pack = &pcx->data;
  622.   
  623.   for (i=0 ; i<height ; i++)
  624.   {
  625.     for (j=0 ; j<width ; j++)
  626.     {
  627.       if ( (*data & 0xc0) != 0xc0)
  628.         *pack++ = *data++;
  629.       else
  630.       {
  631.         *pack++ = 0xc1;
  632.         *pack++ = *data++;
  633.       }
  634.     }
  635.  
  636.     data += rowbytes - width;
  637.   }
  638.       
  639. // write the palette
  640.   *pack++ = 0x0c; // palette ID byte
  641.   for (i=0 ; i<768 ; i++)
  642.     *pack++ = *palette++;
  643.     
  644. // write output file 
  645.   length = pack - (byte *)pcx;
  646.   if (upload)
  647.     CL_StartUpload((void *)pcx, length);
  648.   else
  649.     COM_WriteFile (filename, pcx, length);
  650.  
  651.  
  652.  
  653. /* 
  654. ================== 
  655. SCR_ScreenShot_f
  656. ================== 
  657. */  
  658. void SCR_ScreenShot_f (void) 
  659.   int     i; 
  660.   char    pcxname[80]; 
  661.   char    checkname[MAX_OSPATH];
  662.  
  663. // 
  664. // find a file name to save it to 
  665. // 
  666.   strcpy(pcxname,"quake00.pcx");
  667.     
  668.   for (i=0 ; i<=99 ; i++) 
  669.   { 
  670.     pcxname[5] = i/10 + '0'; 
  671.     pcxname[6] = i%10 + '0'; 
  672.     sprintf (checkname, "%s/%s", com_gamedir, pcxname);
  673.     if (Sys_FileTime(checkname) == -1)
  674.       break;  // file doesn't exist
  675.   } 
  676.   if (i==100) 
  677.   {
  678.     Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX"); 
  679.     return;
  680.   }
  681.  
  682. // 
  683. // save the pcx file 
  684. // 
  685.   D_EnableBackBufferAccess ();  // enable direct drawing of console to back
  686.                   //  buffer
  687.  
  688.   WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
  689.           host_basepal, false);
  690.  
  691.   D_DisableBackBufferAccess (); // for adapters that can't stay mapped in
  692.                   //  for linear writes all the time
  693.  
  694.   Con_Printf ("Wrote %s\n", pcxname);
  695.  
  696. /*
  697. Find closest color in the palette for named color
  698. */
  699. int MipColor(int r, int g, int b)
  700. {
  701.   int i;
  702.   float dist;
  703.   int best;
  704.   float bestdist;
  705.   int r1, g1, b1;
  706.   static int lr = -1, lg = -1, lb = -1;
  707.   static int lastbest;
  708.  
  709.   if (r == lr && g == lg && b == lb)
  710.     return lastbest;
  711.  
  712.   bestdist = 256*256*3;
  713.  
  714.   for (i = 0; i < 256; i++) {
  715.     r1 = host_basepal[i*3] - r;
  716.     g1 = host_basepal[i*3+1] - g;
  717.     b1 = host_basepal[i*3+2] - b;
  718.     dist = r1*r1 + g1*g1 + b1*b1;
  719.     if (dist < bestdist) {
  720.       bestdist = dist;
  721.       best = i;
  722.     }
  723.   }
  724.   lr = r; lg = g; lb = b;
  725.   lastbest = best;
  726.   return best;
  727. }
  728.  
  729. // in draw.c
  730. extern byte   *draw_chars;        // 8*8 graphic characters
  731.  
  732. void SCR_DrawCharToSnap (int num, byte *dest, int width)
  733. {
  734.   int   row, col;
  735.   byte  *source;
  736.   int   drawline;
  737.   int   x;
  738.  
  739.   row = num>>4;
  740.   col = num&15;
  741.   source = draw_chars + (row<<10) + (col<<3);
  742.  
  743.   drawline = 8;
  744.  
  745.   while (drawline--)
  746.   {
  747.     for (x=0 ; x<8 ; x++)
  748.       if (source[x])
  749.         dest[x] = source[x];
  750.       else
  751.         dest[x] = 98;
  752.     source += 128;
  753.     dest += width;
  754.   }
  755.  
  756. }
  757.  
  758. void SCR_DrawStringToSnap (const char *s, byte *buf, int x, int y, int width)
  759. {
  760.   byte *dest;
  761.   const unsigned char *p;
  762.  
  763.   dest = buf + ((y * width) + x);
  764.  
  765.   p = (const unsigned char *)s;
  766.   while (*p) {
  767.     SCR_DrawCharToSnap(*p++, dest, width);
  768.     dest += 8;
  769.   }
  770. }
  771.  
  772.  
  773. /* 
  774. ================== 
  775. SCR_RSShot_f
  776. ================== 
  777. */  
  778. void SCR_RSShot_f (void) 
  779.   int     i, x, y;
  780.   unsigned char   *src, *dest;
  781.   char    pcxname[80]; 
  782.   char    checkname[MAX_OSPATH];
  783.   unsigned char   *newbuf, *srcbuf;
  784.   int srcrowbytes;
  785.   int w, h;
  786.   int dx, dy, dex, dey, nx;
  787.   int r, b, g;
  788.   int count;
  789.   float fracw, frach;
  790.   char st[80];
  791.   time_t now;
  792.  
  793.   if (CL_IsUploading())
  794.     return; // already one pending
  795.  
  796.   if (cls.state < ca_onserver)
  797.     return; // gotta be connected
  798.  
  799.   if (!scr_allowsnap.value) {
  800.     MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
  801.     SZ_Print (&cls.netchan.message, "snap\n");
  802.     Con_Printf("Refusing remote screen shot request.\n");
  803.     return;
  804.   }
  805.  
  806.   Con_Printf("Remote screen shot requested.\n");
  807.  
  808. #if 0
  809. // 
  810. // find a file name to save it to 
  811. // 
  812.   strcpy(pcxname,"mquake00.pcx");
  813.     
  814.   for (i=0 ; i<=99 ; i++) 
  815.   { 
  816.     pcxname[6] = i/10 + '0'; 
  817.     pcxname[7] = i%10 + '0'; 
  818.     sprintf (checkname, "%s/%s", com_gamedir, pcxname);
  819.     if (Sys_FileTime(checkname) == -1)
  820.       break;  // file doesn't exist
  821.   } 
  822.   if (i==100) 
  823.   {
  824.     Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX"); 
  825.     return;
  826.   }
  827. #endif
  828.  
  829. // 
  830. // save the pcx file 
  831. // 
  832.   D_EnableBackBufferAccess ();  // enable direct drawing of console to back
  833.                   //  buffer
  834.  
  835.   w = (vid.width < RSSHOT_WIDTH) ? vid.width : RSSHOT_WIDTH;
  836.   h = (vid.height < RSSHOT_HEIGHT) ? vid.height : RSSHOT_HEIGHT;
  837.  
  838.   fracw = (float)vid.width / (float)w;
  839.   frach = (float)vid.height / (float)h;
  840.  
  841.   newbuf = malloc(w*h);
  842.  
  843.   for (y = 0; y < h; y++) {
  844.     dest = newbuf + (w * y);
  845.  
  846.     for (x = 0; x < w; x++) {
  847.       r = g = b = 0;
  848.  
  849.       dx = x * fracw;
  850.       dex = (x + 1) * fracw;
  851.       if (dex == dx) dex++; // at least one
  852.       dy = y * frach;
  853.       dey = (y + 1) * frach;
  854.       if (dey == dy) dey++; // at least one
  855.  
  856.       count = 0;
  857.       for (/* */; dy < dey; dy++) {
  858.         src = vid.buffer + (vid.rowbytes * dy) + dx;
  859.         for (nx = dx; nx < dex; nx++) {
  860.           r += host_basepal[*src * 3];
  861.           g += host_basepal[*src * 3+1];
  862.           b += host_basepal[*src * 3+2];
  863.           src++;
  864.           count++;
  865.         }
  866.       }
  867.       r /= count;
  868.       g /= count;
  869.       b /= count;
  870.       *dest++ = MipColor(r, g, b);
  871.     }
  872.   }
  873.  
  874.   time(&now);
  875.   strcpy(st, ctime(&now));
  876.   st[strlen(st) - 1] = 0;
  877.   SCR_DrawStringToSnap (st, newbuf, w - strlen(st)*8, 0, w);
  878.  
  879.   strncpy(st, cls.servername, sizeof(st));
  880.   st[sizeof(st) - 1] = 0;
  881.   SCR_DrawStringToSnap (st, newbuf, w - strlen(st)*8, 10, w);
  882.  
  883.   strncpy(st, name.string, sizeof(st));
  884.   st[sizeof(st) - 1] = 0;
  885.   SCR_DrawStringToSnap (st, newbuf, w - strlen(st)*8, 20, w);
  886.  
  887.   WritePCXfile (pcxname, newbuf, w, h, w, host_basepal, true);
  888.  
  889.   free(newbuf);
  890.  
  891.   D_DisableBackBufferAccess (); // for adapters that can't stay mapped in
  892.                   //  for linear writes all the time
  893.  
  894. //  Con_Printf ("Wrote %s\n", pcxname);
  895.   Con_Printf ("Sending shot to server...\n");
  896.  
  897.  
  898. //=============================================================================
  899.  
  900. char  *scr_notifystring;
  901. qboolean  scr_drawdialog;
  902.  
  903. void SCR_DrawNotifyString (void)
  904. {
  905.   char  *start;
  906.   int   l;
  907.   int   j;
  908.   int   x, y;
  909.  
  910.   start = scr_notifystring;
  911.  
  912.   y = vid.height*0.35;
  913.  
  914.   do  
  915.   {
  916.   // scan the width of the line
  917.     for (l=0 ; l<40 ; l++)
  918.       if (start[l] == '\n' || !start[l])
  919.         break;
  920.     x = (vid.width - l*8)/2;
  921.     for (j=0 ; j<l ; j++, x+=8)
  922.       Draw_Character (x, y, start[j]);  
  923.       
  924.     y += 8;
  925.  
  926.     while (*start && *start != '\n')
  927.       start++;
  928.  
  929.     if (!*start)
  930.       break;
  931.     start++;    // skip the \n
  932.   } while (1);
  933. }
  934.  
  935. /*
  936. ==================
  937. SCR_ModalMessage
  938.  
  939. Displays a text string in the center of the screen and waits for a Y or N
  940. keypress.  
  941. ==================
  942. */
  943. int SCR_ModalMessage (char *text)
  944. {
  945.   scr_notifystring = text;
  946.  
  947. // draw a fresh screen
  948.   scr_fullupdate = 0;
  949.   scr_drawdialog = true;
  950.   SCR_UpdateScreen ();
  951.   scr_drawdialog = false;
  952.   
  953.   S_ClearBuffer ();   // so dma doesn't loop current sound
  954.  
  955.   do
  956.   {
  957.     key_count = -1;   // wait for a key down and up
  958.     Sys_SendKeyEvents ();
  959.   } while (key_lastpress != 'y' && key_lastpress != 'n' && key_lastpress != K_ESCAPE);
  960.  
  961.   scr_fullupdate = 0;
  962.   SCR_UpdateScreen ();
  963.  
  964.   return key_lastpress == 'y';
  965. }
  966.  
  967.  
  968. //=============================================================================
  969.  
  970. /*
  971. ===============
  972. SCR_BringDownConsole
  973.  
  974. Brings the console down and fades the palettes back to normal
  975. ================
  976. */
  977. void SCR_BringDownConsole (void)
  978. {
  979.   int   i;
  980.   
  981.   scr_centertime_off = 0;
  982.   
  983.   for (i=0 ; i<20 && scr_conlines != scr_con_current ; i++)
  984.     SCR_UpdateScreen ();
  985.  
  986.   cl.cshifts[0].percent = 0;    // no area contents palette on next frame
  987.   VID_SetPalette (host_basepal);
  988. }
  989.  
  990.  
  991. /*
  992. ==================
  993. SCR_UpdateScreen
  994.  
  995. This is called every frame, and can also be called explicitly to flush
  996. text to the screen.
  997.  
  998. WARNING: be very careful calling this from elsewhere, because the refresh
  999. needs almost the entire 256k of stack space!
  1000. ==================
  1001. */
  1002. void SCR_UpdateScreen (void)
  1003. {
  1004.   static float  oldscr_viewsize;
  1005.   vrect_t   vrect;
  1006.  
  1007.   if (scr_skipupdate || block_drawing)
  1008.     return;
  1009.  
  1010.   if (scr_disabled_for_loading)
  1011.     return;
  1012.  
  1013. #ifdef _WIN32
  1014.   { // don't suck up any cpu if minimized
  1015.     extern int Minimized;
  1016.  
  1017.     if (Minimized)
  1018.       return;
  1019.   }
  1020. #endif
  1021.  
  1022.   scr_copytop = 0;
  1023.   scr_copyeverything = 0;
  1024.  
  1025.   if (!scr_initialized || !con_initialized)
  1026.     return;       // not initialized yet
  1027.  
  1028.   if (scr_viewsize.value != oldscr_viewsize)
  1029.   {
  1030.     oldscr_viewsize = scr_viewsize.value;
  1031.     vid.recalc_refdef = 1;
  1032.   }
  1033.   
  1034. //
  1035. // check for vid changes
  1036. //
  1037.   if (oldfov != scr_fov.value)
  1038.   {
  1039.     oldfov = scr_fov.value;
  1040.     vid.recalc_refdef = true;
  1041.   }
  1042.   
  1043.   if (oldscreensize != scr_viewsize.value)
  1044.   {
  1045.     oldscreensize = scr_viewsize.value;
  1046.     vid.recalc_refdef = true;
  1047.   }
  1048.  
  1049.   if (oldsbar != cl_sbar.value)
  1050.   {
  1051.     oldsbar = cl_sbar.value;
  1052.     vid.recalc_refdef = true;
  1053.   }
  1054.   
  1055.   if (vid.recalc_refdef)
  1056.   {
  1057.     // something changed, so reorder the screen
  1058.     SCR_CalcRefdef ();
  1059.   }
  1060.  
  1061. //
  1062. // do 3D refresh drawing, and then update the screen
  1063. //
  1064.   D_EnableBackBufferAccess ();  // of all overlay stuff if drawing directly
  1065.  
  1066.   if (scr_fullupdate++ < vid.numpages)
  1067.   { // clear the entire screen
  1068.     scr_copyeverything = 1;
  1069.     Draw_TileClear (0,0,vid.width,vid.height);
  1070.     Sbar_Changed ();
  1071.   }
  1072.  
  1073.   pconupdate = NULL;
  1074.  
  1075.  
  1076.   SCR_SetUpToDrawConsole ();
  1077.   SCR_EraseCenterString ();
  1078.   
  1079.   D_DisableBackBufferAccess (); // for adapters that can't stay mapped in
  1080.                   //  for linear writes all the time
  1081.  
  1082.   VID_LockBuffer ();
  1083.   V_RenderView ();
  1084.   VID_UnlockBuffer ();
  1085.  
  1086.   D_EnableBackBufferAccess ();  // of all overlay stuff if drawing directly
  1087.  
  1088.   if (scr_drawdialog)
  1089.   {
  1090.     Sbar_Draw ();
  1091.     Draw_FadeScreen ();
  1092.     SCR_DrawNotifyString ();
  1093.     scr_copyeverything = true;
  1094.   }
  1095.   else if (cl.intermission == 1 && key_dest == key_game)
  1096.   {
  1097.     Sbar_IntermissionOverlay ();
  1098.   }
  1099.   else if (cl.intermission == 2 && key_dest == key_game)
  1100.   {
  1101.     Sbar_FinaleOverlay ();
  1102.     SCR_CheckDrawCenterString ();
  1103.   }
  1104.   else
  1105.   {
  1106.     SCR_DrawRam ();
  1107.     SCR_DrawNet ();
  1108.     SCR_DrawTurtle ();
  1109.     SCR_DrawPause ();
  1110.     SCR_DrawFPS ();
  1111.     SCR_CheckDrawCenterString ();
  1112.     Sbar_Draw ();
  1113.     SCR_DrawConsole (); 
  1114.     M_Draw ();
  1115.   }
  1116.  
  1117.  
  1118.   D_DisableBackBufferAccess (); // for adapters that can't stay mapped in
  1119.                   //  for linear writes all the time
  1120.   if (pconupdate)
  1121.   {
  1122.     D_UpdateRects (pconupdate);
  1123.   }
  1124.  
  1125.   V_UpdatePalette ();
  1126.  
  1127. //
  1128. // update one of three areas
  1129. //
  1130.   if (scr_copyeverything)
  1131.   {
  1132.     vrect.x = 0;
  1133.     vrect.y = 0;
  1134.     vrect.width = vid.width;
  1135.     vrect.height = vid.height;
  1136.     vrect.pnext = 0;
  1137.   
  1138.     VID_Update (&vrect);
  1139.   }
  1140.   else if (scr_copytop)
  1141.   {
  1142.     vrect.x = 0;
  1143.     vrect.y = 0;
  1144.     vrect.width = vid.width;
  1145.     vrect.height = vid.height - sb_lines;
  1146.     vrect.pnext = 0;
  1147.   
  1148.     VID_Update (&vrect);
  1149.   } 
  1150.   else
  1151.   {
  1152.     vrect.x = scr_vrect.x;
  1153.     vrect.y = scr_vrect.y;
  1154.     vrect.width = scr_vrect.width;
  1155.     vrect.height = scr_vrect.height;
  1156.     vrect.pnext = 0;
  1157.   
  1158.     VID_Update (&vrect);
  1159.   } 
  1160. }
  1161.  
  1162. /*
  1163. ==================
  1164. SCR_UpdateWholeScreen
  1165. ==================
  1166. */
  1167. void SCR_UpdateWholeScreen (void)
  1168. {
  1169.   scr_fullupdate = 0;
  1170.   SCR_UpdateScreen ();
  1171. }
  1172.