update build script
[carveJwlIkooP6JGAAIwe30JlM.git] / highscores.c
index 77ffc412de82d4a32c9246d304a89cf692b02ad5..c72b9876d7f13bbd13259bf692ade95cbb282c10 100644 (file)
@@ -3,13 +3,13 @@
 
 #include "highscores.h"
 
-VG_STATIC int highscore_cmp_points( void *a, void *b )
+static int highscore_cmp_points( void *a, void *b )
 {
    highscore_record *pa = a, *pb = b;
    return (int)pa->points - (int)pb->points;
 }
 
-VG_STATIC int highscore_cmp_datetime( void *a, void *b )
+static int highscore_cmp_datetime( void *a, void *b )
 {
    highscore_record *pa = a, *pb = b;
    
@@ -17,27 +17,27 @@ VG_STATIC int highscore_cmp_datetime( void *a, void *b )
    return pa->datetime < pb->datetime? 1: -1;
 }
 
-VG_STATIC int highscore_cmp_time( void *a, void *b )
+static int highscore_cmp_time( void *a, void *b )
 {
    highscore_record *pa = a, *pb = b;
    return (int)pb->time - (int)pa->time;
 }
 
-VG_STATIC int highscore_cmp_playerid( void *a, void *b )
+static int highscore_cmp_playerid( void *a, void *b )
 {
    highscore_record *pa = a, *pb = b;
    if( pa->playerid == pb->playerid ) return 0;
    return pa->playerid < pb->playerid? -1: 1;
 }
 
-VG_STATIC int highscore_cmp_playerinfo_playerid( void *a, void *b )
+static int highscore_cmp_playerinfo_playerid( void *a, void *b )
 {
    highscore_playerinfo *pa = a, *pb = b;
    if( pa->playerid == pb->playerid ) return 0;
    return pa->playerid < pb->playerid? -1: 1;
 }
 
-VG_STATIC void highscores_create_db(void)
+static void highscores_create_db(void)
 {
    struct highscore_system *sys = &highscore_system;
 
@@ -64,11 +64,13 @@ VG_STATIC void highscores_create_db(void)
    sys->dbheader.playerinfo_root = AATREE_PTR_NIL;
 }
 
-VG_STATIC int highscores_read(void)
-{
+static int highscores_read( const char *path ){
    struct highscore_system *sys = &highscore_system;
 
-   FILE *fp = fopen( ".aadb", "rb" );
+   if( path == NULL )
+      path = ".aadb";
+
+   FILE *fp = fopen( path, "rb" );
    if( fp ){
       vg_info( "Loading existing database\n" );
       
@@ -106,12 +108,12 @@ VG_STATIC int highscores_read(void)
    }
    else
    {
-      vg_low( "No existing database found (.aadb)\n" );
+      vg_low( "No existing database found (%s)\n", path );
       return 0;
    }
 }
 
-VG_STATIC void highscores_init( u32 pool_size, u32 playerinfo_pool_size )
+static void highscores_init( u32 pool_size, u32 playerinfo_pool_size )
 {
    struct highscore_system *sys = &highscore_system;
 
@@ -159,6 +161,7 @@ VG_STATIC void highscores_init( u32 pool_size, u32 playerinfo_pool_size )
       offsetof(highscore_playerinfo,aa_playerid);
    sys->aainfo_playerinfo_playerid.p_cmp = highscore_cmp_playerinfo_playerid;
 
+   /* TODO: Is this even useable? */
    sys->aainfo_playerinfo.base = highscore_system.playerinfo_data;
    sys->aainfo_playerinfo.stride = sizeof(highscore_playerinfo);
    sys->aainfo_playerinfo.offset = offsetof(highscore_playerinfo,aapn);
@@ -168,7 +171,7 @@ VG_STATIC void highscores_init( u32 pool_size, u32 playerinfo_pool_size )
    sys->pool_size = pool_size;
 }
 
-VG_STATIC int highscores_serialize_all(void)
+static int highscores_serialize_all(void)
 {
    struct highscore_system *sys = &highscore_system;
    vg_info( "Serializing database\n" );
@@ -191,7 +194,7 @@ VG_STATIC int highscores_serialize_all(void)
    return 1;
 }
 
-VG_STATIC highscore_record *highscore_find_user_record( u64 playerid, 
+static highscore_record *highscore_find_user_record( u64 playerid, 
                                                         u32 trackid )
 {
    struct highscore_system *sys = &highscore_system;
@@ -209,7 +212,7 @@ VG_STATIC highscore_record *highscore_find_user_record( u64 playerid,
    return aatree_get_data( &sys->aainfo_playerid, find );
 }
 
-VG_STATIC aatree_ptr highscores_push_record( highscore_record *record )
+static aatree_ptr highscores_push_record( highscore_record *record )
 {
    struct highscore_system *sys = &highscore_system;
 
@@ -278,7 +281,7 @@ VG_STATIC aatree_ptr highscores_push_record( highscore_record *record )
    return index;
 }
 
-VG_STATIC aatree_ptr highscore_set_user_nickname( u64 steamid, char nick[16] )
+static aatree_ptr highscore_set_user_nickname( u64 steamid, char nick[16] )
 {
    char name[17];
    for( int i=0; i<16; i++ )
@@ -328,7 +331,7 @@ VG_STATIC aatree_ptr highscore_set_user_nickname( u64 steamid, char nick[16] )
 }
 
 /* Get the length of a string, bounded by '\0' or len, whichever is first */
-VG_STATIC int highscore_strlen( const char *str, int len )
+static int highscore_strlen( const char *str, int len )
 {
    int str_length;
    for( str_length=0; str_length<len; str_length++ )
@@ -339,7 +342,7 @@ VG_STATIC int highscore_strlen( const char *str, int len )
 }
 
 /* Print the string(max length:len) centered into buf (has width:width) */
-VG_STATIC void highscore_strc( char *buf, const char *str, int len, int width )
+static void highscore_strc( char *buf, const char *str, int len, int width )
 {
    int str_length = highscore_strlen( str, len ),
        offs = (width-str_length)/2;
@@ -356,7 +359,7 @@ VG_STATIC void highscore_strc( char *buf, const char *str, int len, int width )
 }
 
 /* Print the string(max length:len) left aligned into buf */
-VG_STATIC void highscore_strl( char *buf, const char *str, int len )
+static void highscore_strl( char *buf, const char *str, int len )
 {
    for( int i=0; i<len; i++ )
    {
@@ -368,7 +371,7 @@ VG_STATIC void highscore_strl( char *buf, const char *str, int len )
 }
 
 /* Print the string (max length:len) right aligned into buf (has width:width) */
-VG_STATIC void highscore_strr( char *buf, const char *str, int len, int width )
+static void highscore_strr( char *buf, const char *str, int len, int width )
 {
    int str_length = highscore_strlen( str, len );
    
@@ -383,7 +386,7 @@ VG_STATIC void highscore_strr( char *buf, const char *str, int len, int width )
 
 /* Print integer (padded with: alt), right aligned into buf(width: len)
  * returns number of digits (not including alt), that were written to buf */
-VG_STATIC int highscore_intr( char *buf, int value, int len, char alt )
+static int highscore_intr( char *buf, int value, int len, char alt )
 {
    int i=0;
    while(value){
@@ -402,30 +405,34 @@ VG_STATIC int highscore_intr( char *buf, int value, int len, char alt )
 
 /* Print integer into buffer with max length len 
  * retuns the number of digits written to buf */
-VG_STATIC int highscore_intl( char *buf, int value, int len )
-{
-   char temp[32];
+static int highscore_intl( char *buf, int value, int len ){
+   if( value ){
+      char temp[32];
+      int i=0;
+      while(value){
+         if( i>=len ) 
+            break;
+
+         temp[ i ++ ] = '0' + (value % 10);
+         value /= 10;
+      }
 
-   int i=0;
-   while(value){
-      if( i>=len ) 
-         break;
+      if( i>len )
+         i = len;
 
-      temp[ i ++ ] = '0' + (value % 10);
-      value /= 10;
-   }
-   
-   if( i>len )
-      i = len;
+      for( int j=0; j<i; j ++ )
+         buf[j] = temp[ i-1-j ];
 
-   for( int j=0; j<i; j ++ )
-      buf[j] = temp[ i-1-j ];
-
-   return i;
+      return i;
+   }
+   else{
+      buf[ 0 ] = '0';
+      return 1;
+   }
 }
 
 /* Clear buffer with length using clr character */
-VG_STATIC void highscore_clear( char *buf, char clr, int length )
+static void highscore_clear( char *buf, char clr, int length )
 {
    for( int i=0; i<length; i++ )
       buf[i] = clr;
@@ -449,7 +456,7 @@ VG_STATIC void highscore_clear( char *buf, char clr, int length )
 
 /* Generate a highscores board in text form, the width is always 27. Buffer 
  * must be (count+3)*27 in size. */
-VG_STATIC void highscores_board_generate( char *buf, u32 id, u32 count )
+static void highscores_board_generate( char *buf, u32 id, u32 count )
 {
    int w=27;
    highscore_clear( buf, ' ', (count+3)*w );
@@ -529,7 +536,7 @@ VG_STATIC void highscores_board_generate( char *buf, u32 id, u32 count )
 
 /* Print string out to file using newlines. Count is number of records 
  * ( this requires a buffer of (count+3)*27 size */
-VG_STATIC void highscores_board_printf( FILE *fp, const char *buf, u32 count )
+static void highscores_board_printf( FILE *fp, const char *buf, u32 count )
 {
    int w=27;