X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=highscores.h;h=3a2071758a8c04f76c6ddd8d5a2a1ead67d1c62d;hb=badfa88dd109bbae5628f58504402f4707569f73;hp=f19f93a2fd2494ef4b6635a7d0a512d712e76365;hpb=d5405f24a854aff8b76bb126492f2c18bc874270;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/highscores.h b/highscores.h index f19f93a..3a20717 100644 --- a/highscores.h +++ b/highscores.h @@ -80,7 +80,7 @@ struct highscore_database #pragma pack(pop) -static struct highscore_system +VG_STATIC struct highscore_system { highscore_database dbheader; aatree aainfo, @@ -91,19 +91,20 @@ static struct highscore_system aainfo_playerinfo_playerid, aainfo_playerinfo; - void *data, *playerinfo_data; + void *data, + *playerinfo_data; u32 pool_size, playerinfo_pool_size; } highscore_system; -static int highscore_cmp_points( void *a, void *b ) +VG_STATIC int highscore_cmp_points( void *a, void *b ) { highscore_record *pa = a, *pb = b; return (int)pa->points - (int)pb->points; } -static int highscore_cmp_datetime( void *a, void *b ) +VG_STATIC int highscore_cmp_datetime( void *a, void *b ) { highscore_record *pa = a, *pb = b; @@ -111,52 +112,27 @@ static int highscore_cmp_datetime( void *a, void *b ) return pa->datetime < pb->datetime? 1: -1; } -static int highscore_cmp_time( void *a, void *b ) +VG_STATIC int highscore_cmp_time( void *a, void *b ) { highscore_record *pa = a, *pb = b; return (int)pb->time - (int)pa->time; } -static int highscore_cmp_playerid( void *a, void *b ) +VG_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; } -static int highscore_cmp_playerinfo_playerid( void *a, void *b ) +VG_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; } -static void *highscore_malloc( u32 count, u32 size ) -{ - size_t requested_mem = size * count; - void *data = vg_alloc( requested_mem ); - - requested_mem /= 1024; - requested_mem /= 1024; - - if( !data ) - { - vg_error( "Could not allocated %dmb of memory\n", requested_mem ); - return NULL; - } - else - vg_success( "Allocated %dmb for %u records\n", requested_mem, count ); - - return data; -} - -static void highscores_free(void) -{ - vg_free( highscore_system.data ); - vg_free( highscore_system.playerinfo_data ); -} - -static void highscores_create_db(void) +VG_STATIC void highscores_create_db(void) { struct highscore_system *sys = &highscore_system; @@ -183,7 +159,7 @@ static void highscores_create_db(void) sys->dbheader.playerinfo_root = AATREE_PTR_NIL; } -static int highscores_read(void) +VG_STATIC int highscores_read(void) { struct highscore_system *sys = &highscore_system; @@ -200,7 +176,9 @@ static int highscores_read(void) return 0; } - count = fread( sys->data, sizeof(highscore_record), sys->pool_size, fp ); + count = fread( sys->data, sizeof(highscore_record), + sys->pool_size, fp ); + if( count != sys->pool_size ) { vg_error( "Unexpected EOF reading database contents;" @@ -229,13 +207,21 @@ static int highscores_read(void) } } -static void highscores_init( u32 pool_size, u32 playerinfo_pool_size ) +VG_STATIC void highscores_init( u32 pool_size, u32 playerinfo_pool_size ) { struct highscore_system *sys = &highscore_system; - sys->data = highscore_malloc( pool_size, sizeof(highscore_record) ); - sys->playerinfo_data = highscore_malloc( playerinfo_pool_size, - sizeof(highscore_playerinfo)); + sys->data = vg_linear_alloc( vg_mem.rtmemory, + pool_size*sizeof(highscore_record) ); + + sys->playerinfo_data = + vg_linear_alloc( vg_mem.rtmemory, + playerinfo_pool_size * sizeof(highscore_playerinfo) ); + + memset( sys->data, 0, pool_size*sizeof(highscore_record) ); + memset( sys->playerinfo_data, 0, + playerinfo_pool_size*sizeof(highscore_playerinfo) ); + /* This is ugly.. too bad! */ sys->aainfo.base = highscore_system.data; @@ -278,7 +264,7 @@ static void highscores_init( u32 pool_size, u32 playerinfo_pool_size ) sys->pool_size = pool_size; } -static int highscores_serialize_all(void) +VG_STATIC int highscores_serialize_all(void) { struct highscore_system *sys = &highscore_system; vg_info( "Serializing database\n" ); @@ -301,7 +287,7 @@ static int highscores_serialize_all(void) return 1; } -static highscore_record *highscore_find_user_record( u64 playerid, u32 trackid ) +VG_STATIC highscore_record *highscore_find_user_record( u64 playerid, u32 trackid ) { struct highscore_system *sys = &highscore_system; @@ -318,7 +304,7 @@ static highscore_record *highscore_find_user_record( u64 playerid, u32 trackid ) return aatree_get_data( &sys->aainfo_playerid, find ); } -static aatree_ptr highscores_push_record( highscore_record *record ) +VG_STATIC aatree_ptr highscores_push_record( highscore_record *record ) { struct highscore_system *sys = &highscore_system; @@ -389,7 +375,7 @@ static aatree_ptr highscores_push_record( highscore_record *record ) return index; } -static aatree_ptr highscore_set_user_nickname( u64 steamid, char nick[16] ) +VG_STATIC aatree_ptr highscore_set_user_nickname( u64 steamid, char nick[16] ) { char name[17]; for( int i=0; i<16; i++ ) @@ -429,8 +415,7 @@ static aatree_ptr highscore_set_user_nickname( u64 steamid, char nick[16] ) info->playerid = steamid; sys->dbheader.playerinfo_root = aatree_insert( &sys->aainfo_playerinfo_playerid, - sys->dbheader.playerinfo_root, - record ); + sys->dbheader.playerinfo_root, record ); } for( int i=0; i<16; i++ ) @@ -440,7 +425,7 @@ 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 */ -static int highscore_strlen( const char *str, int len ) +VG_STATIC int highscore_strlen( const char *str, int len ) { int str_length; for( str_length=0; str_length=len ) - return; + return i; buf[ len-1 - (i ++) ] = '0' + (value % 10); value /= 10; @@ -508,16 +493,18 @@ static void highscore_intr( char *buf, int value, int len, char alt ) for( ;i=len ) break; @@ -529,13 +516,13 @@ static void highscore_intl( char *buf, int value, int len ) i = len; for( int j=0; jaainfo_playerinfo_playerid, info_ptr ); highscore_strl( line+3, inf->nickname, 16 ); + + /* yep, this is fucking awesome! */ + if( inf->playerid == 0x8297744501001001 || + inf->playerid == 0x1ec4620101001001 || + inf->playerid == 0x0110000145749782 || + inf->playerid == 0x011000010162c41e ) + { + i --; + /* FIXME: Clear line, or yknow, do it properly */ + } } u16 centiseconds = record->time, @@ -629,7 +626,7 @@ 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 */ -static void highscores_board_printf( FILE *fp, const char *buf, u32 count ) +VG_STATIC void highscores_board_printf( FILE *fp, const char *buf, u32 count ) { int w=27;