diff options
author | Johannes Schwarz <ubuntuxer@rockbox.org> | 2009-07-18 15:16:24 +0000 |
---|---|---|
committer | Johannes Schwarz <ubuntuxer@rockbox.org> | 2009-07-18 15:16:24 +0000 |
commit | 99f52999968eb56e8fc9cabbf2ab4f65943ce678 (patch) | |
tree | 0e87625df1579f27b3f43141d8a2d20f7b8df248 /apps/plugins/bubbles.c | |
parent | 03cb2b83ae17d9118ddee69908389fb4cd0484a6 (diff) | |
download | rockbox-99f52999968eb56e8fc9cabbf2ab4f65943ce678.tar.gz rockbox-99f52999968eb56e8fc9cabbf2ab4f65943ce678.zip |
Commit FS#10350, prevents to save an unchanged highscore and move the function show_highscore to the lib
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21960 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/bubbles.c')
-rw-r--r-- | apps/plugins/bubbles.c | 94 |
1 files changed, 12 insertions, 82 deletions
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c index 17848dbcf3..4ed15bd124 100644 --- a/apps/plugins/bubbles.c +++ b/apps/plugins/bubbles.c | |||
@@ -1235,7 +1235,6 @@ struct tile { | |||
1235 | * elapsedshot is the shot elapsed time in 1/100s of seconds | 1235 | * elapsedshot is the shot elapsed time in 1/100s of seconds |
1236 | * startedshot is when the current shot began | 1236 | * startedshot is when the current shot began |
1237 | * resume denotes whether to resume the currently loaded game | 1237 | * resume denotes whether to resume the currently loaded game |
1238 | * dirty denotes whether the high scores are out of sync with the saved file | ||
1239 | * playboard is the game playing board | 1238 | * playboard is the game playing board |
1240 | */ | 1239 | */ |
1241 | struct game_context { | 1240 | struct game_context { |
@@ -1254,7 +1253,6 @@ struct game_context { | |||
1254 | long elapsedshot; | 1253 | long elapsedshot; |
1255 | long startedshot; | 1254 | long startedshot; |
1256 | bool resume; | 1255 | bool resume; |
1257 | bool dirty; | ||
1258 | struct tile playboard[BB_HEIGHT][BB_WIDTH]; | 1256 | struct tile playboard[BB_HEIGHT][BB_WIDTH]; |
1259 | }; | 1257 | }; |
1260 | 1258 | ||
@@ -1272,7 +1270,6 @@ static void bubbles_anchored(struct game_context* bb, int row, int col); | |||
1272 | static int bubbles_fall(struct game_context* bb); | 1270 | static int bubbles_fall(struct game_context* bb); |
1273 | static int bubbles_checklevel(struct game_context* bb); | 1271 | static int bubbles_checklevel(struct game_context* bb); |
1274 | static void bubbles_recordscore(struct game_context* bb); | 1272 | static void bubbles_recordscore(struct game_context* bb); |
1275 | static void bubbles_displayscores(struct game_context* bb, int position); | ||
1276 | static void bubbles_savescores(struct game_context* bb); | 1273 | static void bubbles_savescores(struct game_context* bb); |
1277 | static bool bubbles_loadgame(struct game_context* bb); | 1274 | static bool bubbles_loadgame(struct game_context* bb); |
1278 | static void bubbles_savegame(struct game_context* bb); | 1275 | static void bubbles_savegame(struct game_context* bb); |
@@ -1286,6 +1283,7 @@ static int bubbles(struct game_context* bb); | |||
1286 | * bubbles_init() initializes bubbles data structures. | 1283 | * bubbles_init() initializes bubbles data structures. |
1287 | ******************************************************************************/ | 1284 | ******************************************************************************/ |
1288 | static void bubbles_init(struct game_context* bb) { | 1285 | static void bubbles_init(struct game_context* bb) { |
1286 | bubbles_setcolors(); | ||
1289 | /* seed the rand generator */ | 1287 | /* seed the rand generator */ |
1290 | rb->srand(*rb->current_tick); | 1288 | rb->srand(*rb->current_tick); |
1291 | 1289 | ||
@@ -2113,15 +2111,12 @@ static void bubbles_recordscore(struct game_context* bb) { | |||
2113 | 2111 | ||
2114 | int position; | 2112 | int position; |
2115 | 2113 | ||
2116 | if (highscore_would_update(bb->score, bb->highscores, NUM_SCORES)) { | 2114 | position = highscore_update(bb->score, bb->level, "", |
2117 | bb->dirty = true; | 2115 | bb->highscores, NUM_SCORES); |
2118 | position = highscore_update(bb->score, bb->level, "", | 2116 | if (position==0) |
2119 | bb->highscores, NUM_SCORES); | 2117 | rb->splash(HZ*2, "New High Score"); |
2120 | if (position==0) { | 2118 | if (position != -1) |
2121 | rb->splash(HZ*2, "New High Score"); | 2119 | highscore_show(position, bb->highscores, NUM_SCORES); |
2122 | } | ||
2123 | bubbles_displayscores(bb, position); | ||
2124 | } | ||
2125 | } | 2120 | } |
2126 | 2121 | ||
2127 | /***************************************************************************** | 2122 | /***************************************************************************** |
@@ -2129,8 +2124,6 @@ static void bubbles_recordscore(struct game_context* bb) { | |||
2129 | ******************************************************************************/ | 2124 | ******************************************************************************/ |
2130 | static void bubbles_loadscores(struct game_context* bb) { | 2125 | static void bubbles_loadscores(struct game_context* bb) { |
2131 | 2126 | ||
2132 | bb->dirty = false; | ||
2133 | |||
2134 | /* highlevel and highscores */ | 2127 | /* highlevel and highscores */ |
2135 | highscore_load(SCORE_FILE, &bb->highlevel, NUM_SCORES+1); | 2128 | highscore_load(SCORE_FILE, &bb->highlevel, NUM_SCORES+1); |
2136 | 2129 | ||
@@ -2145,60 +2138,6 @@ static void bubbles_savescores(struct game_context* bb) { | |||
2145 | 2138 | ||
2146 | /* highlevel and highscores */ | 2139 | /* highlevel and highscores */ |
2147 | highscore_save(SCORE_FILE, &bb->highlevel, NUM_SCORES+1); | 2140 | highscore_save(SCORE_FILE, &bb->highlevel, NUM_SCORES+1); |
2148 | bb->dirty = false; | ||
2149 | } | ||
2150 | |||
2151 | /***************************************************************************** | ||
2152 | * bubbles_displayscores() displays the high scores | ||
2153 | ******************************************************************************/ | ||
2154 | #define MARGIN 5 | ||
2155 | static void bubbles_displayscores(struct game_context* bb, int position) { | ||
2156 | int i, w, h; | ||
2157 | char str[30]; | ||
2158 | |||
2159 | #ifdef HAVE_LCD_COLOR | ||
2160 | rb->lcd_set_background(LCD_BLACK); | ||
2161 | rb->lcd_set_foreground(LCD_WHITE); | ||
2162 | #endif | ||
2163 | rb->button_clear_queue(); | ||
2164 | rb->lcd_clear_display(); | ||
2165 | |||
2166 | rb->lcd_setfont(FONT_UI); | ||
2167 | rb->lcd_getstringsize("High Scores", &w, &h); | ||
2168 | /* check wether it fits on screen */ | ||
2169 | if ((4*h + h*(NUM_SCORES-1) + MARGIN) > LCD_HEIGHT) { | ||
2170 | rb->lcd_setfont(FONT_SYSFIXED); | ||
2171 | rb->lcd_getstringsize("High Scores", &w, &h); | ||
2172 | } | ||
2173 | rb->lcd_putsxy(LCD_WIDTH/2-w/2, MARGIN, "High Scores"); | ||
2174 | rb->lcd_putsxy(LCD_WIDTH/4-w/4,2*h, "Score"); | ||
2175 | rb->lcd_putsxy(LCD_WIDTH*3/4-w/4,2*h, "Level"); | ||
2176 | |||
2177 | for (i = 0; i<NUM_SCORES; i++) | ||
2178 | { | ||
2179 | #ifdef HAVE_LCD_COLOR | ||
2180 | if(i == position) { | ||
2181 | rb->lcd_set_foreground(LCD_RGBPACK(245,0,0)); | ||
2182 | } | ||
2183 | #endif | ||
2184 | rb->snprintf (str, sizeof (str), "%d)", i+1); | ||
2185 | rb->lcd_putsxy (MARGIN,3*h + h*i, str); | ||
2186 | rb->snprintf (str, sizeof (str), "%d", bb->highscores[i].score); | ||
2187 | rb->lcd_putsxy (LCD_WIDTH/4-w/4,3*h + h*i, str); | ||
2188 | rb->snprintf (str, sizeof (str), "%d", bb->highscores[i].level); | ||
2189 | rb->lcd_putsxy (LCD_WIDTH*3/4-w/4,3*h + h*i, str); | ||
2190 | if(i == position) { | ||
2191 | #ifdef HAVE_LCD_COLOR | ||
2192 | rb->lcd_set_foreground(LCD_WHITE); | ||
2193 | #else | ||
2194 | rb->lcd_hline(MARGIN, LCD_WIDTH-MARGIN, 3*h + h*(i+1)-1); | ||
2195 | #endif | ||
2196 | } | ||
2197 | } | ||
2198 | rb->lcd_update(); | ||
2199 | rb->button_get(true); | ||
2200 | rb->lcd_setfont(FONT_SYSFIXED); | ||
2201 | bubbles_setcolors(); | ||
2202 | } | 2141 | } |
2203 | 2142 | ||
2204 | /***************************************************************************** | 2143 | /***************************************************************************** |
@@ -2277,10 +2216,7 @@ static inline void bubbles_setcolors(void) { | |||
2277 | ******************************************************************************/ | 2216 | ******************************************************************************/ |
2278 | static void bubbles_callback(void* param) { | 2217 | static void bubbles_callback(void* param) { |
2279 | struct game_context* bb = (struct game_context*) param; | 2218 | struct game_context* bb = (struct game_context*) param; |
2280 | if(bb->dirty) { | 2219 | bubbles_savescores(bb); |
2281 | rb->splash(HZ/2, "Saving high scores..."); | ||
2282 | bubbles_savescores(bb); | ||
2283 | } | ||
2284 | } | 2220 | } |
2285 | 2221 | ||
2286 | /***************************************************************************** | 2222 | /***************************************************************************** |
@@ -2376,8 +2312,6 @@ static int bubbles(struct game_context* bb) { | |||
2376 | bool startgame = false; | 2312 | bool startgame = false; |
2377 | long timeout; | 2313 | long timeout; |
2378 | 2314 | ||
2379 | bubbles_setcolors(); | ||
2380 | |||
2381 | /* don't resume by default */ | 2315 | /* don't resume by default */ |
2382 | bb->resume = false; | 2316 | bb->resume = false; |
2383 | 2317 | ||
@@ -2409,7 +2343,7 @@ static int bubbles(struct game_context* bb) { | |||
2409 | startlevel--; | 2343 | startlevel--; |
2410 | break; | 2344 | break; |
2411 | case 3: /* High scores */ | 2345 | case 3: /* High scores */ |
2412 | bubbles_displayscores(bb, 0); | 2346 | highscore_show(NUM_SCORES, bb->highscores, NUM_SCORES); |
2413 | break; | 2347 | break; |
2414 | case 4: /* Playback Control */ | 2348 | case 4: /* Playback Control */ |
2415 | playback_control(NULL); | 2349 | playback_control(NULL); |
@@ -2494,7 +2428,6 @@ enum plugin_status plugin_start(const void* parameter) { | |||
2494 | /* record high level */ | 2428 | /* record high level */ |
2495 | if( NUM_LEVELS-1 > bb.highlevel.level) { | 2429 | if( NUM_LEVELS-1 > bb.highlevel.level) { |
2496 | bb.highlevel.level = NUM_LEVELS-1; | 2430 | bb.highlevel.level = NUM_LEVELS-1; |
2497 | bb.dirty = true; | ||
2498 | } | 2431 | } |
2499 | /* record high score */ | 2432 | /* record high score */ |
2500 | bubbles_recordscore(&bb); | 2433 | bubbles_recordscore(&bb); |
@@ -2508,8 +2441,8 @@ enum plugin_status plugin_start(const void* parameter) { | |||
2508 | if(!bb.resume) { | 2441 | if(!bb.resume) { |
2509 | /* record high level */ | 2442 | /* record high level */ |
2510 | if((int)bb.level-1 > bb.highlevel.level) { | 2443 | if((int)bb.level-1 > bb.highlevel.level) { |
2511 | bb.highlevel.level = bb.level-1; | 2444 | bb.highlevel.score = -1; |
2512 | bb.dirty = true; | 2445 | highscore_update(0, bb.level-1, "", &bb.highlevel, 1); |
2513 | } | 2446 | } |
2514 | /* record high score */ | 2447 | /* record high score */ |
2515 | bubbles_recordscore(&bb); | 2448 | bubbles_recordscore(&bb); |
@@ -2521,10 +2454,7 @@ enum plugin_status plugin_start(const void* parameter) { | |||
2521 | return PLUGIN_USB_CONNECTED; | 2454 | return PLUGIN_USB_CONNECTED; |
2522 | 2455 | ||
2523 | case BB_QUIT: | 2456 | case BB_QUIT: |
2524 | if(bb.dirty) { | 2457 | bubbles_savescores(&bb); |
2525 | rb->splash(HZ/2, "Saving high scores..."); | ||
2526 | bubbles_savescores(&bb); | ||
2527 | } | ||
2528 | exit = true; | 2458 | exit = true; |
2529 | break; | 2459 | break; |
2530 | 2460 | ||