]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
-Fixed the binary insert in the hostcache.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 22 Dec 2004 15:43:39 +0000 (15:43 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 22 Dec 2004 15:43:39 +0000 (15:43 +0000)
-Fixed a bug in the old menu's serverlist.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4881 d7cf8633-e32d-0410-b094-e92efae38249

menu.c
netconn.c

diff --git a/menu.c b/menu.c
index bfdcce896803bc724d93d4ecf2091c8a11ef8841..9111bd36c385ef64ab854297e08ec1e8ce3b845d 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -3830,7 +3830,7 @@ void M_ServerList_Draw (void)
        if (*m_return_reason)
                M_Print(16, menu_height - 8, m_return_reason);
        y = 48;
-       visible = (menu_height - 16 - y) / 8;
+       visible = (menu_height - 16 - y) / 8 / 2;
        start = bound(0, slist_cursor - (visible >> 1), hostcache_viewcount - visible);
        end = min(start + visible, hostcache_viewcount);
 
index 2ded74db9aeadfc26587ce230281b1d6fc18e290..09c69084cc0bcf206fb99ae2afb19de3f164678c 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -101,6 +101,21 @@ hostcache_t hostcache_cache[HOSTCACHE_TOTALSIZE];
 
 qboolean       hostcache_consoleoutput;
 
+#if 0
+static void _HostCache_PingTest(void)
+{
+       int i;
+       for( i = 0 ; i < 50 ; i++ ) {
+               memset( &hostcache_cache[hostcache_cachecount], 0, sizeof( hostcache_t ) );
+               hostcache_cache[hostcache_cachecount].info.ping = rand() % 450;
+               hostcache_cache[hostcache_cachecount].finished = true;
+               sprintf( hostcache_cache[hostcache_cachecount].line1, "%i", hostcache_cache[hostcache_cachecount].info.ping );
+               _HostCache_Insert( &hostcache_cache[hostcache_cachecount] );
+               hostcache_cachecount++;
+       }
+}
+#endif
+
 // helper function to insert a value into the viewset
 // spare entries will be removed
 static void _HostCache_ViewSet_InsertBefore( int index, hostcache_t *entry )
@@ -144,9 +159,9 @@ static qboolean _HostCache_SortTest( hostcache_t *A, hostcache_t *B )
        else if( hostcache_sortbyfield == HCIF_NAME )
                result = strcmp( B->info.name, A->info.name );
        
-       if( result > 0 && hostcache_sortdescending)
-               return true;
-       return false;
+       if( hostcache_sortdescending )
+               return result > 0;
+       return result < 0;
 }
 
 static qboolean _hc_testint( int A, hostcache_infofield_t op, int B )
@@ -230,18 +245,18 @@ static void _HostCache_Insert( hostcache_t *entry )
                _HostCache_ViewSet_InsertBefore( hostcache_viewcount, entry );
                return;
        }
-       start = 1;
+       start = 0;
        end = hostcache_viewcount - 1;
-       while( end > start )
+       while( end > start + 1 )
        {
                mid = (start + end) / 2;
                // test the item that lies in the middle between start and end
                if( _HostCache_SortTest( entry, hostcache_viewset[mid] ) )
                        // the item has to be in the upper half
-                       end = mid - 1;
+                       end = mid;
                else 
                        // the item has to be in the lower half
-                       start = mid + 1;
+                       start = mid;
        }
        _HostCache_ViewSet_InsertBefore( start + 1, entry );
 }