Index: apps/plugins/clix.c =================================================================== --- apps/plugins/clix.c (revision 21947) +++ apps/plugins/clix.c (working copy) @@ -238,56 +238,6 @@ CC_DARK_GREEN }; -/* display the highscore list and highlight the last one */ -static void clix_show_highscores(int position) -{ - int i, w, h; - char str[30]; - -#ifdef HAVE_LCD_COLOR - rb->lcd_set_background(LCD_BLACK); - rb->lcd_set_foreground(LCD_WHITE); -#endif - rb->button_clear_queue(); - rb->lcd_clear_display(); - - rb->lcd_setfont(FONT_UI); - rb->lcd_getstringsize("High Scores", &w, &h); - /* check wether it fits on screen */ - if ((4*h + h*(NUM_SCORES-1) + MARGIN) > LCD_HEIGHT) { - rb->lcd_setfont(FONT_SYSFIXED); - rb->lcd_getstringsize("High Scores", &w, &h); - } - rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); - rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); - rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); - - for (i = 0; ilcd_set_foreground(LCD_RGBPACK(245,0,0)); - } -#endif - rb->snprintf (str, sizeof (str), "%d)", i+1); - rb->lcd_putsxy (MARGIN,3*h + h*i, str); - rb->snprintf (str, sizeof (str), "%d", highest[i].score); - rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); - rb->snprintf (str, sizeof (str), "%d", highest[i].level); - rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); - if(i == position) { -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_WHITE); -#else - rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)); -#endif - } - } - rb->lcd_update(); - rb->button_get(true); - rb->lcd_setfont(FONT_SYSFIXED); -} - /* recursive function to check if a neighbour cell is of the same color if so call the function with the neighbours position */ @@ -667,7 +617,7 @@ return 1; break; case 3: - clix_show_highscores(NUM_SCORES); + highscore_show(NUM_SCORES, highest, NUM_SCORES); break; case 4: playback_control(NULL); @@ -812,16 +762,14 @@ clix_draw( state); rb->splash(HZ*2, "Game Over!"); rb->lcd_clear_display(); - if (highscore_would_update(state->score, - highest, NUM_SCORES)) { - position=highscore_update(state->score, - state->level, "", - highest,NUM_SCORES); - if (position == 0) { - rb->splash(HZ*2, "New High Score"); - } - clix_show_highscores(position); - } + position=highscore_update(state->score, + state->level, "", + highest,NUM_SCORES); + if (position == 0) + rb->splash(HZ*2, "New High Score"); + if (position != -1) + highscore_show(position, highest, + NUM_SCORES); if (clix_menu(state, 0)) return 1; break; Index: apps/plugins/lib/highscore.c =================================================================== --- apps/plugins/lib/highscore.c (revision 21947) +++ apps/plugins/lib/highscore.c (working copy) @@ -21,6 +21,8 @@ #include "plugin.h" #include "highscore.h" +static bool highscore_updated = false; + int highscore_save(char *filename, struct highscore *scores, int num_scores) { int i; @@ -28,6 +30,9 @@ int rc; char buf[80]; + if(!highscore_updated) + return 1; + fd = rb->open(filename, O_WRONLY|O_CREAT); if(fd < 0) return -1; @@ -44,6 +49,7 @@ } } rb->close(fd); + highscore_updated = false; return 0; } @@ -76,6 +82,7 @@ i++; } rb->close(fd); + highscore_updated = false; return 0; } @@ -102,6 +109,7 @@ entry->level = level; rb->strlcpy(entry->name, name, sizeof(entry->name)); + highscore_updated = true; return pos; } @@ -110,3 +118,54 @@ { return (num_scores > 0) && (score > scores[num_scores-1].score); } + +#ifdef HAVE_LCD_BITMAP +void highscore_show(int position, struct highscore *scores, int num_scores) +{ + int i, w, h; + char str[30]; +#define MARGIN 5 +#ifdef HAVE_LCD_COLOR + rb->lcd_set_background(LCD_BLACK); + rb->lcd_set_foreground(LCD_WHITE); +#endif + rb->button_clear_queue(); + rb->lcd_clear_display(); + + rb->lcd_setfont(FONT_UI); + rb->lcd_getstringsize("High Scores", &w, &h); + /* check wether it fits on screen */ + if ((4*h + h*(num_scores-1) + MARGIN) > LCD_HEIGHT) { + rb->lcd_setfont(FONT_SYSFIXED); + rb->lcd_getstringsize("High Scores", &w, &h); + } + rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); + rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); + rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); + + for (i = 0; ilcd_set_foreground(LCD_RGBPACK(245,0,0)); + } +#endif + rb->snprintf (str, sizeof (str), "%d)", i+1); + rb->lcd_putsxy (MARGIN,3*h + h*i, str); + rb->snprintf (str, sizeof (str), "%d", scores[i].score); + rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); + rb->snprintf (str, sizeof (str), "%d", scores[i].level); + rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); + if(i == position) { +#ifdef HAVE_LCD_COLOR + rb->lcd_set_foreground(LCD_WHITE); +#else + rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)); +#endif + } + } + rb->lcd_update(); + rb->button_get(true); + rb->lcd_setfont(FONT_SYSFIXED); +} +#endif /* HAVE_LCD_BITMAP */ Index: apps/plugins/lib/highscore.h =================================================================== --- apps/plugins/lib/highscore.h (revision 21947) +++ apps/plugins/lib/highscore.h (working copy) @@ -82,4 +82,15 @@ bool highscore_would_update(int score, struct highscore *scores, int num_scores); +#ifdef HAVE_LCD_BITMAP +/* Displays a nice highscore table. In general the font is FONT_UI, but if + * the highscore table doesn't fit on the the display size it uses + * FONT_SYSFIXED. + * + * - position : highlight position line + * - scores : the array of existing scores + * - num_scores: number of elements in 'scores' + */ +void highscore_show(int position, struct highscore *scores, int num_scores); #endif +#endif Index: apps/plugins/jewels.c =================================================================== --- apps/plugins/jewels.c (revision 21947) +++ apps/plugins/jewels.c (working copy) @@ -415,7 +415,6 @@ #define HIGH_SCORE PLUGIN_GAMES_DIR "/jewels.score" struct highscore highest[NUM_SCORES]; -bool highest_updated = false; /***************************************************************************** @@ -1256,55 +1255,6 @@ bj->score += points; } -static void jewels_show_highscores(int position) -{ - int i, w, h; - char str[30]; - -#ifdef HAVE_LCD_COLOR - rb->lcd_set_background(LCD_BLACK); - rb->lcd_set_foreground(LCD_WHITE); -#endif - rb->button_clear_queue(); - rb->lcd_clear_display(); - - rb->lcd_setfont(FONT_UI); - rb->lcd_getstringsize("High Scores", &w, &h); - /* check wether it fits on screen */ - if ((4*h + h*(NUM_SCORES-1) + MARGIN) > LCD_HEIGHT) { - rb->lcd_setfont(FONT_SYSFIXED); - rb->lcd_getstringsize("High Scores", &w, &h); - } - rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); - rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); - rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); - - for (i = 0; ilcd_set_foreground(LCD_RGBPACK(245,0,0)); - } -#endif - rb->snprintf (str, sizeof (str), "%d)", i+1); - rb->lcd_putsxy (MARGIN,3*h + h*i, str); - rb->snprintf (str, sizeof (str), "%d", highest[i].score); - rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); - rb->snprintf (str, sizeof (str), "%d", highest[i].level); - rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); - if(i == position) { -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_WHITE); -#else - rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)); -#endif - } - } - rb->lcd_update(); - rb->button_get(true); - rb->lcd_setfont(FONT_SYSFIXED); -} - static bool jewels_help(void) { rb->lcd_setfont(FONT_UI); @@ -1402,7 +1352,7 @@ return 1; break; case 4: - jewels_show_highscores(NUM_SCORES); + highscore_show(NUM_SCORES, highest, NUM_SCORES); break; case 5: playback_control(NULL); @@ -1567,17 +1517,12 @@ rb->splash(HZ*2, "Game Over!"); rb->lcd_clear_display(); bj->score += (bj->level-1)*LEVEL_PTS; - if (highscore_would_update(bj->score, highest, - NUM_SCORES)) { - position=highscore_update(bj->score, - bj->level, "", - highest,NUM_SCORES); - highest_updated = true; - if (position == 0) { - rb->splash(HZ*2, "New High Score"); - } - jewels_show_highscores(position); - } + position=highscore_update(bj->score, bj->level, "", + highest, NUM_SCORES); + if (position == 0) + rb->splash(HZ*2, "New High Score"); + if (position != -1) + highscore_show(position, highest, NUM_SCORES); break; case GAME_TYPE_PUZZLE: rb->splash(2*HZ, "Game Over"); @@ -1597,7 +1542,6 @@ /* load high scores */ highscore_load(HIGH_SCORE,highest,NUM_SCORES); - highest_updated = false; rb->lcd_setfont(FONT_SYSFIXED); #if LCD_DEPTH > 1 @@ -1607,8 +1551,7 @@ struct game_context bj; bj.tmp_type = GAME_TYPE_NORMAL; jewels_main(&bj); - if(highest_updated) - highscore_save(HIGH_SCORE,highest,NUM_SCORES); + highscore_save(HIGH_SCORE,highest,NUM_SCORES); rb->lcd_setfont(FONT_UI); return PLUGIN_OK; Index: apps/plugins/bubbles.c =================================================================== --- apps/plugins/bubbles.c (revision 21947) +++ apps/plugins/bubbles.c (working copy) @@ -1235,7 +1235,6 @@ * elapsedshot is the shot elapsed time in 1/100s of seconds * startedshot is when the current shot began * resume denotes whether to resume the currently loaded game - * dirty denotes whether the high scores are out of sync with the saved file * playboard is the game playing board */ struct game_context { @@ -1254,7 +1253,6 @@ long elapsedshot; long startedshot; bool resume; - bool dirty; struct tile playboard[BB_HEIGHT][BB_WIDTH]; }; @@ -1272,7 +1270,6 @@ static int bubbles_fall(struct game_context* bb); static int bubbles_checklevel(struct game_context* bb); static void bubbles_recordscore(struct game_context* bb); -static void bubbles_displayscores(struct game_context* bb, int position); static void bubbles_savescores(struct game_context* bb); static bool bubbles_loadgame(struct game_context* bb); static void bubbles_savegame(struct game_context* bb); @@ -1286,6 +1283,7 @@ * bubbles_init() initializes bubbles data structures. ******************************************************************************/ static void bubbles_init(struct game_context* bb) { + bubbles_setcolors(); /* seed the rand generator */ rb->srand(*rb->current_tick); @@ -2113,15 +2111,12 @@ int position; - if (highscore_would_update(bb->score, bb->highscores, NUM_SCORES)) { - bb->dirty = true; - position = highscore_update(bb->score, bb->level, "", - bb->highscores, NUM_SCORES); - if (position==0) { - rb->splash(HZ*2, "New High Score"); - } - bubbles_displayscores(bb, position); - } + position = highscore_update(bb->score, bb->level, "", + bb->highscores, NUM_SCORES); + if (position==0) + rb->splash(HZ*2, "New High Score"); + if (position != -1) + highscore_show(position, bb->highscores, NUM_SCORES); } /***************************************************************************** @@ -2129,8 +2124,6 @@ ******************************************************************************/ static void bubbles_loadscores(struct game_context* bb) { - bb->dirty = false; - /* highlevel and highscores */ highscore_load(SCORE_FILE, &bb->highlevel, NUM_SCORES+1); @@ -2145,63 +2138,9 @@ /* highlevel and highscores */ highscore_save(SCORE_FILE, &bb->highlevel, NUM_SCORES+1); - bb->dirty = false; } /***************************************************************************** -* bubbles_displayscores() displays the high scores -******************************************************************************/ -#define MARGIN 5 -static void bubbles_displayscores(struct game_context* bb, int position) { - int i, w, h; - char str[30]; - -#ifdef HAVE_LCD_COLOR - rb->lcd_set_background(LCD_BLACK); - rb->lcd_set_foreground(LCD_WHITE); -#endif - rb->button_clear_queue(); - rb->lcd_clear_display(); - - rb->lcd_setfont(FONT_UI); - rb->lcd_getstringsize("High Scores", &w, &h); - /* check wether it fits on screen */ - if ((4*h + h*(NUM_SCORES-1) + MARGIN) > LCD_HEIGHT) { - rb->lcd_setfont(FONT_SYSFIXED); - rb->lcd_getstringsize("High Scores", &w, &h); - } - rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); - rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); - rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); - - for (i = 0; ilcd_set_foreground(LCD_RGBPACK(245,0,0)); - } -#endif - rb->snprintf (str, sizeof (str), "%d)", i+1); - rb->lcd_putsxy (MARGIN,3*h + h*i, str); - rb->snprintf (str, sizeof (str), "%d", bb->highscores[i].score); - rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); - rb->snprintf (str, sizeof (str), "%d", bb->highscores[i].level); - rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); - if(i == position) { -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_WHITE); -#else - rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)-1); -#endif - } - } - rb->lcd_update(); - rb->button_get(true); - rb->lcd_setfont(FONT_SYSFIXED); - bubbles_setcolors(); -} - -/***************************************************************************** * bubbles_loadgame() loads the saved game and returns load success. ******************************************************************************/ static bool bubbles_loadgame(struct game_context* bb) { @@ -2277,10 +2216,7 @@ ******************************************************************************/ static void bubbles_callback(void* param) { struct game_context* bb = (struct game_context*) param; - if(bb->dirty) { - rb->splash(HZ/2, "Saving high scores..."); - bubbles_savescores(bb); - } + bubbles_savescores(bb); } /***************************************************************************** @@ -2376,8 +2312,6 @@ bool startgame = false; long timeout; - bubbles_setcolors(); - /* don't resume by default */ bb->resume = false; @@ -2409,7 +2343,7 @@ startlevel--; break; case 3: /* High scores */ - bubbles_displayscores(bb, 0); + highscore_show(NUM_SCORES, bb->highscores, NUM_SCORES); break; case 4: /* Playback Control */ playback_control(NULL); @@ -2494,7 +2428,6 @@ /* record high level */ if( NUM_LEVELS-1 > bb.highlevel.level) { bb.highlevel.level = NUM_LEVELS-1; - bb.dirty = true; } /* record high score */ bubbles_recordscore(&bb); @@ -2508,8 +2441,8 @@ if(!bb.resume) { /* record high level */ if((int)bb.level-1 > bb.highlevel.level) { - bb.highlevel.level = bb.level-1; - bb.dirty = true; + bb.highlevel.score = -1; + highscore_update(0, bb.level-1, "", &bb.highlevel, 1); } /* record high score */ bubbles_recordscore(&bb); @@ -2521,10 +2454,7 @@ return PLUGIN_USB_CONNECTED; case BB_QUIT: - if(bb.dirty) { - rb->splash(HZ/2, "Saving high scores..."); - bubbles_savescores(&bb); - } + bubbles_savescores(&bb); exit = true; break; Index: apps/plugins/invadrox.c =================================================================== --- apps/plugins/invadrox.c (revision 21947) +++ apps/plugins/invadrox.c (working copy) @@ -1723,8 +1723,7 @@ rb->splash(HZ * 2, "Game Over"); if (score > hiscore.score) { /* Save new hiscore */ - hiscore.score = score; - hiscore.level = level; + highscore_update(score, level, "Invader", &hiscore, 1); highscore_save(HISCOREFILE, &hiscore, 1); }