]> icculus.org git repositories - divverent/darkplaces.git/blob - r_crosshairs.c
timerefresh works more sanely again
[divverent/darkplaces.git] / r_crosshairs.c
1 #include "quakedef.h"
2
3 cvar_t crosshair_brightness = {CVAR_SAVE, "crosshair_brightness", "1"};
4 cvar_t crosshair_alpha = {CVAR_SAVE, "crosshair_alpha", "1"};
5 cvar_t crosshair_flashspeed = {CVAR_SAVE, "crosshair_flashspeed", "2"};
6 cvar_t crosshair_flashrange = {CVAR_SAVE, "crosshair_flashrange", "0.1"};
7 cvar_t crosshair_size = {CVAR_SAVE, "crosshair_size", "1"};
8
9 // must match NUMCROSSHAIRS in gl_draw.c
10 #define NUMCROSSHAIRS 5
11
12 void R_Crosshairs_Init(void)
13 {
14         Cvar_RegisterVariable(&crosshair_brightness);
15         Cvar_RegisterVariable(&crosshair_alpha);
16         Cvar_RegisterVariable(&crosshair_flashspeed);
17         Cvar_RegisterVariable(&crosshair_flashrange);
18         Cvar_RegisterVariable(&crosshair_size);
19 }
20
21 void DrawCrosshair(int num)
22 {
23         int i;
24         qbyte *color;
25         float scale, base;
26         char *picname;
27         cachepic_t *pic;
28         if (num < 0 || num >= NUMCROSSHAIRS)
29                 num = 0;
30         if (cl.viewentity >= 1 && cl.viewentity <= cl.maxclients)
31         {
32                 i = (cl.scores[cl.viewentity-1].colors & 0xF) << 4;
33                 if (i >= 208 && i < 224) // blue
34                         i += 8;
35                 else if (i < 128 || i >= 224) // 128-224 are backwards ranges (bright to dark, rather than dark to bright)
36                         i += 15;
37         }
38         else
39                 i = 15;
40         color = (qbyte *) &d_8to24table[i];
41         if (crosshair_flashspeed.value >= 0.01f)
42                 base = (sin(realtime * crosshair_flashspeed.value * (M_PI*2.0f)) * crosshair_flashrange.value);
43         else
44                 base = 0.0f;
45         scale = crosshair_brightness.value * (1.0f / 255.0f);
46         picname = va("gfx/crosshair%i.tga", num + 1);
47         pic = Draw_CachePic(picname);
48         if (pic)
49                 DrawQ_Pic((vid.conwidth - pic->width * crosshair_size.value) * 0.5f, (vid.conheight - pic->height * crosshair_size.value) * 0.5f, picname, pic->width * crosshair_size.value, pic->height * crosshair_size.value, color[0] * scale + base, color[1] * scale + base, color[2] * scale + base, crosshair_alpha.value, 0);
50 }
51