summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/rockbox.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2019-05-15 18:17:28 -0400
committerFranklin Wei <git@fwei.tk>2019-05-15 18:18:17 -0400
commit75fe15a06c282b50a9b672c5420a2270e1bfe878 (patch)
treed8314a49db1add04945ff664d0ddf8cafc6df868 /apps/plugins/puzzles/rockbox.c
parentf940276fd9bc38ae34d4119fd1d983171a627400 (diff)
downloadrockbox-75fe15a06c282b50a9b672c5420a2270e1bfe878.tar.gz
rockbox-75fe15a06c282b50a9b672c5420a2270e1bfe878.zip
puzzles: refactor rockbox frontend
Cleaned up a bit of copy-pasted code and added some useful comments. Change-Id: I9a6f37acbeeda58b3ea8c65ee96230372400f323
Diffstat (limited to 'apps/plugins/puzzles/rockbox.c')
-rw-r--r--apps/plugins/puzzles/rockbox.c69
1 files changed, 37 insertions, 32 deletions
diff --git a/apps/plugins/puzzles/rockbox.c b/apps/plugins/puzzles/rockbox.c
index 8a25038255..ddcad4fa59 100644
--- a/apps/plugins/puzzles/rockbox.c
+++ b/apps/plugins/puzzles/rockbox.c
@@ -1915,7 +1915,7 @@ static void zoom(void)
1915 zoom_fb = smalloc(zoom_w * zoom_h * sizeof(fb_data)); 1915 zoom_fb = smalloc(zoom_w * zoom_h * sizeof(fb_data));
1916 if(!zoom_fb) 1916 if(!zoom_fb)
1917 { 1917 {
1918 rb->splash(HZ, "OOM"); 1918 rb->splash(HZ, "Out of memory. Cannot zoom in.");
1919 return; 1919 return;
1920 } 1920 }
1921 1921
@@ -2412,6 +2412,8 @@ static int do_preset_menu(struct preset_menu *menu, char *title, int selected)
2412 } 2412 }
2413} 2413}
2414 2414
2415/* Let user choose from game presets. Returns true if the user chooses
2416 * one (in which case the caller should start a new game. */
2415static bool presets_menu(void) 2417static bool presets_menu(void)
2416{ 2418{
2417 /* figure out the index of the current preset 2419 /* figure out the index of the current preset
@@ -2692,6 +2694,17 @@ static void reset_drawing(void)
2692 rb->lcd_set_background(BG_COLOR); 2694 rb->lcd_set_background(BG_COLOR);
2693} 2695}
2694 2696
2697/* Make a new game, but tell the user through a splash so they don't
2698 * think we're locked up. Also performs new-game initialization
2699 * specific to Rockbox. */
2700static void new_game_notify(void)
2701{
2702 rb->splash(0, "Please wait...");
2703 midend_new_game(me);
2704 fix_size();
2705 rb->lcd_update();
2706}
2707
2695static int pause_menu(void) 2708static int pause_menu(void)
2696{ 2709{
2697#define static auto 2710#define static auto
@@ -2733,8 +2746,7 @@ static int pause_menu(void)
2733 quit = true; 2746 quit = true;
2734 break; 2747 break;
2735 case 1: 2748 case 1:
2736 midend_new_game(me); 2749 new_game_notify();
2737 fix_size();
2738 quit = true; 2750 quit = true;
2739 break; 2751 break;
2740 case 2: 2752 case 2:
@@ -2779,8 +2791,7 @@ static int pause_menu(void)
2779 case 10: 2791 case 10:
2780 if(presets_menu()) 2792 if(presets_menu())
2781 { 2793 {
2782 midend_new_game(me); 2794 new_game_notify();
2783 fix_size();
2784 reset_drawing(); 2795 reset_drawing();
2785 clear_and_draw(); 2796 clear_and_draw();
2786 quit = true; 2797 quit = true;
@@ -2794,8 +2805,7 @@ static int pause_menu(void)
2794 case 12: 2805 case 12:
2795 if(config_menu()) 2806 if(config_menu())
2796 { 2807 {
2797 midend_new_game(me); 2808 new_game_notify();
2798 fix_size();
2799 reset_drawing(); 2809 reset_drawing();
2800 clear_and_draw(); 2810 clear_and_draw();
2801 quit = true; 2811 quit = true;
@@ -2948,12 +2958,14 @@ static void tune_input(const char *name)
2948 input_settings.numerical_chooser = string_in_list(name, number_chooser_games); 2958 input_settings.numerical_chooser = string_in_list(name, number_chooser_games);
2949} 2959}
2950 2960
2951static const char *init_for_game(const game *gm, int load_fd, bool draw) 2961static const char *init_for_game(const game *gm, int load_fd)
2952{ 2962{
2953 me = midend_new(NULL, gm, &rb_drawing, NULL); 2963 me = midend_new(NULL, gm, &rb_drawing, NULL);
2954 2964
2955 if(load_fd < 0) 2965 if(load_fd < 0)
2956 midend_new_game(me); 2966 {
2967 new_game_notify();
2968 }
2957 else 2969 else
2958 { 2970 {
2959 const char *ret = midend_deserialize(me, read_wrapper, (void*) load_fd); 2971 const char *ret = midend_deserialize(me, read_wrapper, (void*) load_fd);
@@ -2966,17 +2978,10 @@ static const char *init_for_game(const game *gm, int load_fd, bool draw)
2966 mouse_x = LCD_WIDTH / 2; 2978 mouse_x = LCD_WIDTH / 2;
2967 mouse_y = LCD_HEIGHT / 2; 2979 mouse_y = LCD_HEIGHT / 2;
2968 2980
2969 fix_size();
2970
2971 init_colors(); 2981 init_colors();
2972 2982
2973 reset_drawing(); 2983 reset_drawing();
2974 2984
2975 if(draw)
2976 {
2977 clear_and_draw();
2978 }
2979
2980 return NULL; 2985 return NULL;
2981} 2986}
2982 2987
@@ -3160,7 +3165,7 @@ static bool load_game(void)
3160 3165
3161 if(!strcmp(game, thegame.name)) 3166 if(!strcmp(game, thegame.name))
3162 { 3167 {
3163 ret = init_for_game(&thegame, fd, false); 3168 ret = init_for_game(&thegame, fd);
3164 if(ret) 3169 if(ret)
3165 { 3170 {
3166 rb->splash(HZ, ret); 3171 rb->splash(HZ, ret);
@@ -3254,7 +3259,7 @@ static void puzzles_main(void)
3254 if(!load_success) 3259 if(!load_success)
3255 { 3260 {
3256 /* our main menu expects a ready-to-use midend */ 3261 /* our main menu expects a ready-to-use midend */
3257 init_for_game(&thegame, -1, false); 3262 init_for_game(&thegame, -1);
3258 } 3263 }
3259 3264
3260#ifdef HAVE_ADJUSTABLE_CPU_FREQ 3265#ifdef HAVE_ADJUSTABLE_CPU_FREQ
@@ -3294,14 +3299,17 @@ static void puzzles_main(void)
3294 switch(rb->do_menu(&menu, &sel, NULL, false)) 3299 switch(rb->do_menu(&menu, &sel, NULL, false))
3295 { 3300 {
3296 case 0: 3301 case 0:
3297 clear_and_draw(); 3302 /* Loaded. Run the game! */
3298 goto game_loop; 3303 goto game_loop;
3299 case 1: 3304 case 1:
3300 if(!load_success) 3305 if(!load_success)
3301 { 3306 {
3302 clear_and_draw(); 3307 /* Failed to load (so midend is already initialized
3308 * with new game) */
3303 goto game_loop; 3309 goto game_loop;
3304 } 3310 }
3311
3312 /* Otherwise we need to generate a new game. */
3305 quit = true; 3313 quit = true;
3306 break; 3314 break;
3307 case 2: 3315 case 2:
@@ -3316,22 +3324,14 @@ static void puzzles_main(void)
3316 case 5: 3324 case 5:
3317 if(presets_menu()) 3325 if(presets_menu())
3318 { 3326 {
3319 midend_new_game(me); 3327 new_game_notify();
3320 fix_size();
3321 init_colors();
3322 reset_drawing();
3323 clear_and_draw();
3324 goto game_loop; 3328 goto game_loop;
3325 } 3329 }
3326 break; 3330 break;
3327 case 6: 3331 case 6:
3328 if(config_menu()) 3332 if(config_menu())
3329 { 3333 {
3330 midend_new_game(me); 3334 new_game_notify();
3331 fix_size();
3332 init_colors();
3333 reset_drawing();
3334 clear_and_draw();
3335 goto game_loop; 3335 goto game_loop;
3336 } 3336 }
3337 break; 3337 break;
@@ -3350,16 +3350,19 @@ static void puzzles_main(void)
3350 3350
3351 while(1) 3351 while(1)
3352 { 3352 {
3353 init_for_game(&thegame, -1, true); 3353 init_for_game(&thegame, -1);
3354 game_loop:
3355 reset_drawing();
3356 clear_and_draw();
3354 3357
3355 last_keystate = 0; 3358 last_keystate = 0;
3356 accept_input = true; 3359 accept_input = true;
3357 3360
3358 game_loop:
3359 while(1) 3361 while(1)
3360 { 3362 {
3361 int button = process_input(timer_on ? TIMER_INTERVAL : -1, true); 3363 int button = process_input(timer_on ? TIMER_INTERVAL : -1, true);
3362 3364
3365 /* special codes are < 0 */
3363 if(button < 0) 3366 if(button < 0)
3364 { 3367 {
3365 rb_unclip(NULL); 3368 rb_unclip(NULL);
@@ -3393,6 +3396,7 @@ static void puzzles_main(void)
3393 } 3396 }
3394 } 3397 }
3395 3398
3399 /* we have a game input */
3396 if(button) 3400 if(button)
3397 midend_process_key(me, 0, 0, button); 3401 midend_process_key(me, 0, 0, button);
3398 3402
@@ -3403,6 +3407,7 @@ static void puzzles_main(void)
3403 3407
3404 draw_title(true); /* will draw to fb */ 3408 draw_title(true); /* will draw to fb */
3405 3409
3410 /* Blit mouse but immediately clear it. */
3406 if(mouse_mode) 3411 if(mouse_mode)
3407 draw_mouse(); 3412 draw_mouse();
3408 3413