]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/serverlist.c
Revert "another superslow loop. FIXME added." as this is just once per
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / serverlist.c
index 4e1feee64de285d84b59da6a22a05a3967fc7dc5..24694d5f48fe5cd6eea23046ffef8a11b0b3b352 100644 (file)
@@ -64,7 +64,7 @@ entity makeXonoticServerList();
 var float autocvar_menu_slist_categories = TRUE;
 var float autocvar_menu_slist_categories_onlyifmultiple = TRUE; 
 var float autocvar_menu_slist_purethreshold = 10;
-var string autocvar_menu_slist_recommended = "76.124.107.5:26004";
+//var string autocvar_menu_slist_recommended = "76.124.107.5:26004";
 
 // server cache fields
 #define SLIST_FIELDS \
@@ -89,27 +89,21 @@ var string autocvar_menu_slist_recommended = "76.124.107.5:26004";
 SLIST_FIELDS
 #undef SLIST_FIELD
 
-// sort flags
-const float SLSF_DESCENDING = 1;
-const float SLSF_FAVORITES = 2;
-const float SLSF_CATEGORIES = 4;
-
 const float REFRESHSERVERLIST_RESORT = 0;    // sort the server list again to update for changes to e.g. favorite status, categories
 const float REFRESHSERVERLIST_REFILTER = 1;  // ..., also update filter and sort criteria
 const float REFRESHSERVERLIST_ASK = 2;       // ..., also suggest querying servers now
 const float REFRESHSERVERLIST_RESET = 3;     // ..., also clear the list first
 
 // function declarations
-float Get_Cat_Num_FromString(string input);
-entity Get_Cat_Ent(float catnum);
+entity RetrieveCategoryEnt(float catnum);
 
 float IsServerInList(string list, string srv);
 #define IsFavorite(srv) IsServerInList(cvar_string("net_slist_favorites"), srv)
-#define IsRecommended(srv) IsServerInList(cvar_string("menu_slist_recommended"), srv) // todo: use update notification instead of cvar
+#define IsRecommended(srv) IsServerInList(_Nex_ExtResponseSystem_RecommendedServers, srv)
 
 float CheckCategoryOverride(float cat);
 float CheckCategoryForEntry(float entry); 
-float m_getserverlistentrycategory(float entry) { return CheckCategoryOverride(CheckCategoryForEntry(entry)); }
+float m_gethostcachecategory(float entry) { return CheckCategoryOverride(CheckCategoryForEntry(entry)); }
 
 void RegisterSLCategories();
 
@@ -140,15 +134,15 @@ float category_item[MAX_CATEGORIES];
 float category_draw_count;
 
 #define SLIST_CATEGORIES \
-       SLIST_CATEGORY(CAT_FAVORITED,    "",            "",             _("Favorites")) \
-       SLIST_CATEGORY(CAT_RECOMMENDED,  "",            "CAT_SERVERS",  _("Recommended")) \
-       SLIST_CATEGORY(CAT_NORMAL,       "",            "CAT_SERVERS",  _("Normal Servers")) \
-       SLIST_CATEGORY(CAT_SERVERS,      "CAT_NORMAL",  "CAT_SERVERS",  _("Servers")) \
-       SLIST_CATEGORY(CAT_XPM,          "CAT_NORMAL",  "CAT_SERVERS",  _("Competitive Mode")) \
-       SLIST_CATEGORY(CAT_MODIFIED,     "",            "CAT_SERVERS",  _("Modified Servers")) \
-       SLIST_CATEGORY(CAT_OVERKILL,     "",            "CAT_SERVERS",  _("Overkill Mode")) \
-       SLIST_CATEGORY(CAT_MINSTAGIB,    "",            "CAT_SERVERS",  _("MinstaGib Mode")) \
-       SLIST_CATEGORY(CAT_DEFRAG,       "",            "CAT_SERVERS",  _("Defrag Mode"))
+       SLIST_CATEGORY(CAT_FAVORITED,    "",            "",             ZCTX(_("SLCAT^Favorites"))) \
+       SLIST_CATEGORY(CAT_RECOMMENDED,  "",            "CAT_SERVERS",  ZCTX(_("SLCAT^Recommended"))) \
+       SLIST_CATEGORY(CAT_NORMAL,       "",            "CAT_SERVERS",  ZCTX(_("SLCAT^Normal Servers"))) \
+       SLIST_CATEGORY(CAT_SERVERS,      "CAT_NORMAL",  "CAT_SERVERS",  ZCTX(_("SLCAT^Servers"))) \
+       SLIST_CATEGORY(CAT_XPM,          "CAT_NORMAL",  "CAT_SERVERS",  ZCTX(_("SLCAT^Competitive Mode"))) \
+       SLIST_CATEGORY(CAT_MODIFIED,     "",            "CAT_SERVERS",  ZCTX(_("SLCAT^Modified Servers"))) \
+       SLIST_CATEGORY(CAT_OVERKILL,     "",            "CAT_SERVERS",  ZCTX(_("SLCAT^Overkill Mode"))) \
+       SLIST_CATEGORY(CAT_MINSTAGIB,    "",            "CAT_SERVERS",  ZCTX(_("SLCAT^MinstaGib Mode"))) \
+       SLIST_CATEGORY(CAT_DEFRAG,       "",            "CAT_SERVERS",  ZCTX(_("SLCAT^Defrag Mode")))
 
 #define SLIST_CATEGORY_AUTOCVAR(name) autocvar_menu_slist_categories_##name##_override
 #define SLIST_CATEGORY(name,enoverride,dioverride,str) \
@@ -177,7 +171,7 @@ void RegisterSLCategories()
        SLIST_CATEGORIES
        #undef SLIST_CATEGORY
 
-       float i, catnum;
+       float i, x, catnum;
        string s;
 
        #define PROCESS_OVERRIDE(override_string,override_field) \
@@ -186,13 +180,26 @@ void RegisterSLCategories()
                        s = categories[i].override_string; \
                        if((s != "") && (s != categories[i].cat_name)) \
                        { \
-                               catnum = Get_Cat_Num_FromString(s); \
+                               catnum = 0; \
+                               for(x = 0; x < category_ent_count; ++x) \
+                               { if(categories[x].cat_name == s) { \
+                                       catnum = (x+1); \
+                                       break; \
+                               } } \
                                if(catnum) \
                                { \
                                        strunzone(categories[i].override_string); \
                                        categories[i].override_field = catnum; \
                                        continue; \
                                } \
+                               else \
+                               { \
+                                       print(sprintf( \
+                                               "RegisterSLCategories(): Improper override '%s' for category '%s'!\n", \
+                                               s, \
+                                               categories[i].cat_name \
+                                       )); \
+                               } \
                        } \
                        strunzone(categories[i].override_string); \
                        categories[i].override_field = 0; \
@@ -203,14 +210,7 @@ void RegisterSLCategories()
 }
 
 // Supporting Functions
-float Get_Cat_Num_FromString(string input)
-{
-       float i;
-       for(i = 0; i < category_ent_count; ++i) { if(categories[i].cat_name == input) { return (i + 1); } }
-       print(sprintf("Get_Cat_Num_FromString('%s'): Improper category name!\n", input));
-       return 0;
-}
-entity Get_Cat_Ent(float catnum)
+entity RetrieveCategoryEnt(float catnum)
 {
        if((catnum > 0) && (catnum <= category_ent_count))
        {
@@ -218,12 +218,11 @@ entity Get_Cat_Ent(float catnum)
        }
        else
        {
-               error(sprintf("Get_Cat_Ent(%d): Improper category number!\n", catnum));
+               error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum));
                return world;
        }
 }
 
-
 float IsServerInList(string list, string srv)
 {
        string p;
@@ -254,7 +253,7 @@ float IsServerInList(string list, string srv)
 
 float CheckCategoryOverride(float cat)
 {
-       entity catent = Get_Cat_Ent(cat);
+       entity catent = RetrieveCategoryEnt(cat);
        if(catent)
        {
                float override = (autocvar_menu_slist_categories ? catent.cat_enoverride : catent.cat_dioverride); 
@@ -285,8 +284,6 @@ float CheckCategoryForEntry(float entry)
                else if(k == "M") { modtype = strtolower(v); }
        }
 
-       //print(sprintf("modtype = %s\n", modtype)); 
-
        if(impure > autocvar_menu_slist_purethreshold) { impure = TRUE; }
        else { impure = FALSE; }
 
@@ -302,15 +299,13 @@ float CheckCategoryForEntry(float entry)
                        case "xpm": { return CAT_XPM; } 
                        case "minstagib": { return CAT_MINSTAGIB; }
                        case "overkill": { return CAT_OVERKILL; }
+                       //case "nix": { return CAT_NIX; }
+                       //case "newtoys": { return CAT_NEWTOYS; }
 
                        // "cts" is allowed as compat, xdf is replacement
                        case "cts": 
                        case "xdf": { return CAT_DEFRAG; }
                        
-                       //if(modname != "CTS")
-                       //if(modname != "NIX")
-                       //if(modname != "NewToys")
-                       
                        default: { dprint(sprintf("Found strange mod type: %s\n", modtype)); return CAT_MODIFIED; }
                }
        }
@@ -587,6 +582,13 @@ void XonoticServerList_draw(entity me)
                _Nex_ExtResponseSystem_BannedServersNeedsRefresh = 0;
        }
 
+       if(_Nex_ExtResponseSystem_RecommendedServersNeedsRefresh)
+       {
+               if(!me.needsRefresh)
+                       me.needsRefresh = 3;
+               _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 0;
+       }
+
        if(me.currentSortField == -1)
        {
                me.setSortOrder(me, SLIST_FIELD_PING, +1);
@@ -601,6 +603,11 @@ void XonoticServerList_draw(entity me)
                me.needsRefresh = 0;
                me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
        }
+       else if(me.needsRefresh == 3)
+       {
+               me.needsRefresh = 0;
+               me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
+       }
 
        owned = ((me.selectedServer == me.ipAddressBox.text) && (me.ipAddressBox.text != ""));
 
@@ -617,7 +624,7 @@ void XonoticServerList_draw(entity me)
                // entire list, otherwise there is no way to know which item is first in its category.
 
                float cat, x;
-               for(i = 0; i < itemcount; ++i)
+               for(i = 0; i < itemcount; ++i) // FIXME this loop is TOTALLY unacceptable (O(servers)). Make it O(categories * log(servers)). Yes, that is possible.
                {
                        cat = gethostcachenumber(SLIST_FIELD_CATEGORY, i);
                        if(cat)
@@ -645,8 +652,8 @@ void XonoticServerList_draw(entity me)
                }
                if(autocvar_menu_slist_categories_onlyifmultiple && (category_draw_count == 1))
                {
-                       category_name[0] = category_name[1] = -1;
-                       category_item[0] = category_item[1] = -1;
+                       category_name[0] = -1;
+                       category_item[0] = -1;
                        category_draw_count = 0;
                        me.nItems = itemcount;
                }
@@ -941,7 +948,7 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float
        
        if(item < 0)
        {
-               entity catent = Get_Cat_Ent(-item);
+               entity catent = RetrieveCategoryEnt(-item);
                if(catent)
                {
                        draw_Text(