rewrote memory system entirely (hunk, cache, and zone are gone, memory pools replaced...
[xonotic/darkplaces.git] / r_crosshairs.c
index c6a2b81..a628b71 100644 (file)
@@ -1,15 +1,17 @@
 #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 5
 
-rtexture_t *crosshairtex[NUMCROSSHAIRS];
+static rtexturepool_t *crosshairtexturepool;
 
-byte *crosshairtexdata[NUMCROSSHAIRS] =
+static rtexture_t *crosshairtex[NUMCROSSHAIRS];
+
+static byte *crosshairtexdata[NUMCROSSHAIRS] =
 {
        "0000000000000000"
        "0000000000000000"
@@ -97,7 +99,7 @@ byte *crosshairtexdata[NUMCROSSHAIRS] =
        "0000000000000000"
 };
 
-void crosshairload(int num, byte *in)
+static void crosshairload(int num, byte *in)
 {
        int i;
        byte data[16*16][4];
@@ -106,35 +108,40 @@ void crosshairload(int num, byte *in)
                data[i][0] = data[i][1] = data[i][2] = 255;
                data[i][3] = (in[i] - '0') * 255 / 7;
        }
-       crosshairtex[num] = R_LoadTexture(va("crosshair%02d", num), 16, 16, &data[0][0], TEXF_ALPHA | TEXF_RGBA | TEXF_PRECACHE);
+       crosshairtex[num] = R_LoadTexture(crosshairtexturepool, va("crosshair%02d", num), 16, 16, &data[0][0], TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
 }
 
-void r_crosshairs_start()
+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);
 }
 
-void r_crosshairs_shutdown()
+static void r_crosshairs_shutdown(void)
+{
+       R_FreeTexturePool(&crosshairtexturepool);
+}
+
+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)
@@ -154,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);
 }