rewrote memory system entirely (hunk, cache, and zone are gone, memory pools replaced...
[xonotic/darkplaces.git] / r_crosshairs.c
index e2be867..a628b71 100644 (file)
@@ -1,15 +1,35 @@
 #include "quakedef.h"
 
-cvar_t crosshair_brightness = {"crosshair_brightness", "1.0", true};
-cvar_t crosshair_alpha = {"crosshair_alpha", "1.0", true};
-cvar_t crosshair_flashspeed = {"crosshair_flashspeed", "2", true};
-cvar_t crosshair_flashrange = {"crosshair_flashrange", "0.1", true};
+cvar_t crosshair_brightness = {CVAR_SAVE, "crosshair_brightness", "1.0"};
+cvar_t crosshair_alpha = {CVAR_SAVE, "crosshair_alpha", "1.0"};
+cvar_t crosshair_flashspeed = {CVAR_SAVE, "crosshair_flashspeed", "2"};
+cvar_t crosshair_flashrange = {CVAR_SAVE, "crosshair_flashrange", "0.1"};
 
-#define NUMCROSSHAIRS 1
+#define NUMCROSSHAIRS 5
 
-int crosshairtex[NUMCROSSHAIRS];
+static rtexturepool_t *crosshairtexturepool;
 
-char crosshairtex1[16*16] =
+static rtexture_t *crosshairtex[NUMCROSSHAIRS];
+
+static byte *crosshairtexdata[NUMCROSSHAIRS] =
+{
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0003300000033000"
+       "0003550000553000"
+       "0000577007750000"
+       "0000077007700000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000077007700000"
+       "0000577007750000"
+       "0003550000553000"
+       "0003300000033000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       ,
        "0000000000000000"
        "0000000000000000"
        "0000000000000000"
@@ -26,38 +46,102 @@ char crosshairtex1[16*16] =
        "0000000000000000"
        "0000000000000000"
        "0000000000000000"
-;
+       ,
+       "0000000000000000"
+       "0000000770000000"
+       "0000000770000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000440000000"
+       "0000000440000000"
+       "0770044004400770"
+       "0770044004400770"
+       "0000000440000000"
+       "0000000440000000"
+       "0000000000000000"
+       "0000000770000000"
+       "0000000770000000"
+       "0000000000000000"
+       "0000000000000000"
+       ,
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000077777770"
+       "0000000075200000"
+       "0000000072000000"
+       "0000000070000000"
+       "0000000070000000"
+       "0000000070000000"
+       "0000000000000000"
+       "0000000000000000"
+       ,
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000070000000"
+       "0000000000000000"
+       "0000000040000000"
+       "0000070404070000"
+       "0000000040000000"
+       "0000000000000000"
+       "0000000070000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+       "0000000000000000"
+};
 
-void r_crosshairs_start()
+static void crosshairload(int num, byte *in)
 {
        int i;
-       byte data[64*64][4];
+       byte data[16*16][4];
        for (i = 0;i < 16*16;i++)
        {
                data[i][0] = data[i][1] = data[i][2] = 255;
-               data[i][3] = (crosshairtex1[i] - '0') * 255 / 7;
+               data[i][3] = (in[i] - '0') * 255 / 7;
        }
-       crosshairtex[0] = GL_LoadTexture("crosshair0", 16, 16, &data[0][0], false, true, 4);
+       crosshairtex[num] = R_LoadTexture(crosshairtexturepool, va("crosshair%02d", num), 16, 16, &data[0][0], TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
+}
+
+static void r_crosshairs_start(void)
+{
+       int i;
+       crosshairtexturepool = R_AllocTexturePool();
+       for (i = 0;i < NUMCROSSHAIRS;i++)
+               crosshairload(i, crosshairtexdata[i]);
+//     crosshairtex[1] = crosshairload(crosshairtex2);
+}
+
+static void r_crosshairs_shutdown(void)
+{
+       R_FreeTexturePool(&crosshairtexturepool);
 }
 
-void r_crosshairs_shutdown()
+static void r_crosshairs_newmap(void)
 {
 }
 
-void R_Crosshairs_Init()
+void R_Crosshairs_Init(void)
 {
        Cvar_RegisterVariable(&crosshair_brightness);
        Cvar_RegisterVariable(&crosshair_alpha);
        Cvar_RegisterVariable(&crosshair_flashspeed);
        Cvar_RegisterVariable(&crosshair_flashrange);
-       R_RegisterModule("R_Crosshairs", r_crosshairs_start, r_crosshairs_shutdown);
+       R_RegisterModule("R_Crosshairs", r_crosshairs_start, r_crosshairs_shutdown, r_crosshairs_newmap);
 }
 
 void DrawCrosshair(int num)
 {
        byte *color;
        float scale, base;
-//     Draw_Character (r_refdef.vrect.x + r_refdef.vrect.width/2, r_refdef.vrect.y + r_refdef.vrect.height/2, '+');
        if (num < 0 || num >= NUMCROSSHAIRS)
                num = 0;
        if (cl.viewentity)
@@ -77,6 +161,6 @@ void DrawCrosshair(int num)
        else
                base = 0.0f;
        scale = crosshair_brightness.value / 255.0f;
-       Draw_GenericPic(crosshairtex[num], color[0] * scale + base, color[1] * scale + base, color[2] * scale + base, crosshair_alpha.value, r_refdef.vrect.x + r_refdef.vrect.width * 0.5f - 8.0f, r_refdef.vrect.y + r_refdef.vrect.height * 0.5f - 8.0f, 16.0f, 16.0f);
+       Draw_GenericPic(crosshairtex[num], color[0] * scale + base, color[1] * scale + base, color[2] * scale + base, crosshair_alpha.value, vid.conwidth * 0.5f - 8.0f, vid.conheight * 0.5f - 8.0f, 16.0f, 16.0f);
 }