X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=highscores.c;h=c72b9876d7f13bbd13259bf692ade95cbb282c10;hb=e311bbe2fa903a7e2a922f202f389b799193195d;hp=77ffc412de82d4a32c9246d304a89cf692b02ad5;hpb=d07048b61445be11605adba43667e19214358a24;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/highscores.c b/highscores.c index 77ffc41..c72b987 100644 --- a/highscores.c +++ b/highscores.c @@ -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 ) + 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