]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_draw.c
sv_ccmds: Remove some more client-specific forward-to-server code
[xonotic/darkplaces.git] / gl_draw.c
index 18e38754dc97b7072a98a723e41802eee8fc9102..fd4eef5d74953df1388f2181c71829b929b7213e 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -94,7 +94,9 @@ cachepic_t *Draw_CachePic_Flags(const char *path, unsigned int cachepicflags)
                texflags |= TEXF_MIPMAP;
        if (!(cachepicflags & CACHEPICFLAG_NOCOMPRESSION) && gl_texturecompression_2d.integer && gl_texturecompression.integer)
                texflags |= TEXF_COMPRESS;
-       if ((cachepicflags & CACHEPICFLAG_NEAREST) || r_nearest_2d.integer)
+       if (cachepicflags & CACHEPICFLAG_LINEAR)
+               texflags |= TEXF_FORCELINEAR;
+       else if ((cachepicflags & CACHEPICFLAG_NEAREST) || r_nearest_2d.integer)
                texflags |= TEXF_FORCENEAREST;
 
        // check whether the picture has already been cached
@@ -235,9 +237,9 @@ void Draw_Frame(void)
        int i;
        cachepic_t *pic;
        static double nextpurgetime;
-       if (nextpurgetime > realtime)
+       if (nextpurgetime > host.realtime)
                return;
-       nextpurgetime = realtime + 0.05;
+       nextpurgetime = host.realtime + 0.05;
        for (i = 0, pic = cachepics;i < numcachepics;i++, pic++)
        {
                if (pic->autoload && pic->skinframe && pic->skinframe->base && pic->lastusedframe < draw_frame - 3)
@@ -670,7 +672,7 @@ static void LoadFont_f(cmd_state_t *cmd)
 
                                if (sizes == MAX_FONT_SIZES)
                                {
-                                       Con_Warnf("Warning: specified more than %i different font sizes, exceding ones are ignored\n", MAX_FONT_SIZES);
+                                       Con_Printf(CON_WARN "Warning: specified more than %i different font sizes, exceding ones are ignored\n", MAX_FONT_SIZES);
                                        sizes = -1;
                                        continue;
                                }
@@ -703,9 +705,6 @@ static void gl_draw_start(void)
        for(i = 0; i < dp_fonts.maxsize; ++i)
                if (dp_fonts.f[i].title[0])
                        LoadFont(false, va(vabuf, sizeof(vabuf), "gfx/font_%s", dp_fonts.f[i].title), &dp_fonts.f[i], 1, 0);
-
-       // draw the loading screen so people have something to see in the newly opened window
-       SCR_UpdateLoadingScreen(true, true);
 }
 
 static void gl_draw_shutdown(void)
@@ -769,7 +768,7 @@ void GL_Draw_Init (void)
                if(!FONT_USER(i)->title[0])
                        dpsnprintf(FONT_USER(i)->title, sizeof(FONT_USER(i)->title), "user%d", j++);
 
-       Cmd_AddCommand(&cmd_client, "loadfont", LoadFont_f, "loadfont function tganame loads a font; example: loadfont console gfx/veramono; loadfont without arguments lists the available functions");
+       Cmd_AddCommand(CMD_CLIENT, "loadfont", LoadFont_f, "loadfont function tganame loads a font; example: loadfont console gfx/veramono; loadfont without arguments lists the available functions");
        R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap, NULL, NULL);
 }
 
@@ -887,16 +886,38 @@ static void DrawQ_GetTextColor(float color[4], int colorindex, float r, float g,
        }
 }
 
+// returns a colorindex (format 0x1RGBA) if str is a valid RGB string
+// returns 0 otherwise
+static int RGBstring_to_colorindex(const char *str)
+{
+       Uchar ch; 
+       int ind = 0x0001 << 4;
+       do {
+               if (*str <= '9' && *str >= '0')
+                       ind |= (*str - '0');
+               else
+               {
+                       ch = tolower(*str);
+                       if (ch >= 'a' && ch <= 'f')
+                               ind |= (ch - 87);
+                       else
+                               return 0;
+               }
+               ++str;
+               ind <<= 4;
+       } while(!(ind & 0x10000));
+       return ind | 0xf; // add costant alpha value
+}
+
 // NOTE: this function always draws exactly one character if maxwidth <= 0
 float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *maxlen, float w, float h, float sw, float sh, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth)
 {
        const char *text_start = text;
-       int colorindex = STRING_COLOR_DEFAULT;
+       int colorindex;
        size_t i;
        float x = 0;
        Uchar ch, mapch, nextch;
        Uchar prevch = 0; // used for kerning
-       int tempcolorindex;
        float kx;
        int map_index = 0;
        size_t bytes_left;
@@ -943,7 +964,7 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max
 
        // maxwidth /= fnt->scale; // w and h are multiplied by it already
        // ftbase_x = snap_to_pixel_x(0);
-       
+
        if(maxwidth <= 0)
        {
                least_one = true;
@@ -977,7 +998,6 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max
                        x += width_of[(int) ' '] * dw;
                        continue;
                }
-               // i points to the char after ^
                if (ch == STRING_COLOR_TAG && !ignorecolorcodes && i < *maxlen)
                {
                        ch = *text; // colors are ascii, so no u8_ needed
@@ -988,41 +1008,19 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max
                                ++i;
                                continue;
                        }
-                       // i points to the char after ^...
-                       // i+3 points to 3 in ^x123
-                       // i+3 == *maxlen would mean that char is missing
                        else if (ch == STRING_COLOR_RGB_TAG_CHAR && i + 3 < *maxlen ) // ^x found
                        {
-                               // building colorindex...
-                               ch = tolower(text[1]);
-                               tempcolorindex = 0x10000; // binary: 1,0000,0000,0000,0000
-                               if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 12;
-                               else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 12;
-                               else tempcolorindex = 0;
+                               const char *text_p = &text[1];
+                               int tempcolorindex = RGBstring_to_colorindex(text_p);
                                if (tempcolorindex)
                                {
-                                       ch = tolower(text[2]);
-                                       if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 8;
-                                       else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 8;
-                                       else tempcolorindex = 0;
-                                       if (tempcolorindex)
-                                       {
-                                               ch = tolower(text[3]);
-                                               if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 4;
-                                               else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 4;
-                                               else tempcolorindex = 0;
-                                               if (tempcolorindex)
-                                               {
-                                                       colorindex = tempcolorindex | 0xf;
-                                                       // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
-                                                       i+=4;
-                                                       text += 4;
-                                                       continue;
-                                               }
-                                       }
+                                       colorindex = tempcolorindex;
+                                       i+=4;
+                                       text += 4;
+                                       continue;
                                }
                        }
-                       else if (ch == STRING_COLOR_TAG) // ^^ found, ignore the first ^ and go to print the second
+                       else if (ch == STRING_COLOR_TAG) // ^^ found
                        {
                                i++;
                                text++;
@@ -1084,7 +1082,6 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
        float x = startx, y, s, t, u, v, thisw;
        Uchar ch, mapch, nextch;
        Uchar prevch = 0; // used for kerning
-       int tempcolorindex;
        int map_index = 0;
        //ft2_font_map_t *prevmap = NULL; // the previous map
        ft2_font_map_t *map = NULL;     // the currently used map
@@ -1198,35 +1195,15 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                }
                                else if (ch == STRING_COLOR_RGB_TAG_CHAR && i+3 < maxlen ) // ^x found
                                {
-                                       // building colorindex...
-                                       ch = tolower(text[1]);
-                                       tempcolorindex = 0x10000; // binary: 1,0000,0000,0000,0000
-                                       if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 12;
-                                       else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 12;
-                                       else tempcolorindex = 0;
-                                       if (tempcolorindex)
+                                       const char *text_p = &text[1];
+                                       int tempcolorindex = RGBstring_to_colorindex(text_p);
+                                       if(tempcolorindex)
                                        {
-                                               ch = tolower(text[2]);
-                                               if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 8;
-                                               else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 8;
-                                               else tempcolorindex = 0;
-                                               if (tempcolorindex)
-                                               {
-                                                       ch = tolower(text[3]);
-                                                       if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 4;
-                                                       else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 4;
-                                                       else tempcolorindex = 0;
-                                                       if (tempcolorindex)
-                                                       {
-                                                               colorindex = tempcolorindex | 0xf;
-                                                               // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
-                                                               //Con_Printf("^1colorindex:^7 %x\n", colorindex);
-                                                               DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
-                                                               i+=4;
-                                                               text+=4;
-                                                               continue;
-                                                       }
-                                               }
+                                               colorindex = tempcolorindex;
+                                               DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
+                                               i+=4;
+                                               text+=4;
+                                               continue;
                                        }
                                }
                                else if (ch == STRING_COLOR_TAG)
@@ -1340,7 +1317,7 @@ out:
 
        if (outcolor)
                *outcolor = colorindex;
-       
+
        // note: this relies on the proper text (not shadow) being drawn last
        return x;
 }
@@ -1506,7 +1483,7 @@ void DrawQ_FlushUI(void)
                return;
        }
 
-       // this is roughly equivalent to R_Q1BSP_Draw, so the UI can use full material feature set
+       // this is roughly equivalent to R_Mod_Draw, so the UI can use full material feature set
        r_refdef.view.colorscale = 1;
        r_textureframe++; // used only by R_GetCurrentTexture
        GL_DepthMask(false);