Index: apps/plugins/lib/highscore.c =================================================================== --- apps/plugins/lib/highscore.c (revision 21349) +++ apps/plugins/lib/highscore.c (working copy) @@ -34,8 +34,8 @@ for(i = 0;i < num_scores;i++) { - rb->snprintf(buf, sizeof(buf)-1, "%s:%d:%d\n", - scores[i].name, scores[i].score, scores[i].level); + rb->snprintf(buf, sizeof(buf), "%d:%d:%s\n", + scores[i].score, scores[i].level, scores[i].name); rc = rb->write(fd, buf, rb->strlen(buf)); if(rc < 0) { @@ -52,72 +52,52 @@ int i; int fd; char buf[80]; - char *name, *score, *level; - char *ptr; + char *score, *level, *name; fd = rb->open(filename, O_RDONLY); - rb->memset(scores, 0, sizeof(struct highscore)*(num_scores+1)); + rb->memset(scores, 0, sizeof(struct highscore)*num_scores); if(fd < 0) return -1; - i = -1; - while(rb->read_line(fd, buf, sizeof(buf)-1) && i < num_scores) + i = 0; + while(rb->read_line(fd, buf, sizeof(buf)) && i < num_scores) { - i++; - DEBUGF("%s\n", buf); - name = buf; - ptr = rb->strchr(buf, ':'); - if ( !ptr ) + + if ( !rb->settings_parseline(buf, &score, &level) ) continue; - *ptr = 0; - ptr++; - - rb->strncpy(scores[i].name, name, sizeof(scores[i].name)); - - DEBUGF("%s\n", scores[i].name); - score = ptr; - - ptr = rb->strchr(ptr, ':'); - if ( !ptr ) + if ( !rb->settings_parseline(level, &level, &name) ) continue; - *ptr = 0; - ptr++; - + scores[i].score = rb->atoi(score); - - level = ptr; scores[i].level = rb->atoi(level); - } + rb->strncpy(scores[i].name, name, sizeof(scores[i].name)-1); + i++; + } + rb->close(fd); return 0; } -int highscore_update(int score, int level, struct highscore *scores, int num_scores) +int highscore_update(int score, int level, + struct highscore *scores, int num_scores) { - int i, j; - int new = 0; - - /* look through the scores and see if this one is in the top ones */ - for(i = num_scores-1;i >= 0; i--) + int pos = num_scores-1; + + if (score <= scores[pos].score) + return 0; + + /* look through the scores and see if this one is in the top ones */ + while (--pos >= 0 && score > scores[pos].score) { - if ((score > scores[i].score)) - { - /* Move the rest down one... */ - if (i > 0) - { - for (j=1; j<=i; j++) - { - rb->memcpy((void *)&scores[j-1], (void *)&scores[j], sizeof(struct highscore)); - } - } - scores[i].score = score; - scores[i].level = level; - /* Need to sort out entering a name... maybe old three letter arcade style */ - new = 1; - break; - } - } - return new; + /* Move down one... */ + rb->memcpy((void *)&scores[pos+1], (void *)&scores[pos], + sizeof(struct highscore)); + } + scores[pos+1].score = score; + scores[pos+1].level = level; + /* Need to sort out entering a name... + * maybe old three letter arcade style */ + return pos+2; } Index: apps/plugins/lib/highscore.h =================================================================== --- apps/plugins/lib/highscore.h (revision 21349) +++ apps/plugins/lib/highscore.h (working copy) @@ -30,6 +30,7 @@ int highscore_save(char *filename, struct highscore *scores, int num_scores); int highscore_load(char *filename, struct highscore *scores, int num_scores); -int highscore_update(int score, int level, struct highscore *scores, int num_scores); +int highscore_update(int score, int level, + struct highscore *scores, int num_scores); #endif Index: apps/plugins/rockblox.c =================================================================== --- apps/plugins/rockblox.c (revision 21349) +++ apps/plugins/rockblox.c (working copy) @@ -723,7 +723,7 @@ #define MAX_HIGH_SCORES 5 /* Default High Scores... */ -struct highscore Highest[MAX_HIGH_SCORES]; +struct highscore highest[MAX_HIGH_SCORES]; /* get random number from (0) to (range-1) */ static int t_rand (int range) @@ -776,10 +776,11 @@ int i; char str[25]; /* for strings */ - for (i = MAX_HIGH_SCORES-1; i>=0; i--) + for (i = 0; isnprintf (str, sizeof (str), "%06d" _SPACE "L%1d",Highest[i].score, Highest[i].level); - rb->lcd_putsxy (HIGH_LABEL_X, HIGH_SCORE_Y + (10 * ((MAX_HIGH_SCORES-1) - i)), str); + rb->snprintf (str, sizeof (str), "%06d" _SPACE "L%1d", + highest[i].score, highest[i].level); + rb->lcd_putsxy (HIGH_LABEL_X, HIGH_SCORE_Y + (10 * i), str); } } #endif @@ -831,8 +832,8 @@ } static void init_rockblox (bool resume) { - highscore_update(rockblox_status.score, rockblox_status.level, Highest, - MAX_HIGH_SCORES); + highscore_update(rockblox_status.score, rockblox_status.level, + highest, MAX_HIGH_SCORES); #ifdef HAVE_LCD_BITMAP rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT); #else /* HAVE_LCD_CHARCELLS */ @@ -1332,7 +1333,7 @@ rb->srand (*rb->current_tick); /* Load HighScore if any */ - highscore_load(HIGH_SCORE,Highest,MAX_HIGH_SCORES); + highscore_load(HIGH_SCORE, highest, MAX_HIGH_SCORES); #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); @@ -1357,7 +1358,7 @@ pgfx_release(); #endif /* Save user's HighScore */ - highscore_save(HIGH_SCORE,Highest,MAX_HIGH_SCORES); + highscore_save(HIGH_SCORE, highest, MAX_HIGH_SCORES); backlight_use_settings(); /* backlight control in lib/helper.c */ dump_resume();