1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Zakk Roberts
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "oldmenuapi.h"
27 static const struct plugin_api
* rb
;
30 * FIREWORKS.C by ZAKK ROBERTS
31 * Rockbox plugin simulating a fireworks display.
32 * Supports all bitmap LCDs, fully scalable.
33 * Currently disabled for Archos Recorder - runs too slow.
36 /* All sorts of keymappings.. */
37 #if (CONFIG_KEYPAD == IRIVER_H300_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD)
38 #define BTN_MENU BUTTON_OFF
39 #define BTN_FIRE BUTTON_SELECT
40 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
41 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
42 #define BTN_MENU BUTTON_MENU
43 #define BTN_FIRE BUTTON_SELECT
44 #elif (CONFIG_KEYPAD == RECORDER_PAD)
45 #define BTN_MENU BUTTON_OFF
46 #define BTN_FIRE BUTTON_PLAY
47 #elif (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
48 #define BTN_MENU BUTTON_OFF
49 #define BTN_FIRE BUTTON_SELECT
50 #elif (CONFIG_KEYPAD == ONDIO_PAD)
51 #define BTN_MENU BUTTON_MENU
52 #define BTN_FIRE BUTTON_UP
53 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
54 #define BTN_MENU BUTTON_POWER
55 #define BTN_FIRE BUTTON_SELECT
56 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD)
57 #define BTN_MENU BUTTON_MODE
58 #define BTN_FIRE BUTTON_SELECT
59 #elif (CONFIG_KEYPAD == GIGABEAT_PAD) || \
60 (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
61 (CONFIG_KEYPAD == MROBE100_PAD)
62 #define BTN_MENU BUTTON_MENU
63 #define BTN_FIRE BUTTON_SELECT
64 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
65 (CONFIG_KEYPAD == SANSA_C200_PAD)
66 #define BTN_MENU BUTTON_POWER
67 #define BTN_FIRE BUTTON_SELECT
68 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
69 #define BTN_MENU BUTTON_POWER
70 #define BTN_FIRE BUTTON_PLAY
71 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
72 #define BTN_MENU BUTTON_RC_REC
73 #define BTN_FIRE BUTTON_RC_PLAY
74 #elif (CONFIG_KEYPAD == COWOND2_PAD)
75 #define BTN_MENU (BUTTON_MENU|BUTTON_REL)
77 #error No keymap defined!
82 #define BTN_MENU (BUTTON_TOPLEFT|BUTTON_REL)
85 #define BTN_FIRE BUTTON_CENTER
89 /* The lowdown on source terminology:
90 * a ROCKET is launched from the LCD bottom.
91 * FIREWORKs are ejected from the rocket when it explodes. */
93 #define MAX_ROCKETS 40
94 #define ROCKET_LIFE (LCD_HEIGHT/2)
95 #define ROCKET_LIFE_VAR (LCD_HEIGHT/4)
97 #define ROCKET_MOVEMENT_RANGE 4
98 #define ROCKET_TRAIL_PARTICLES 50
100 #define MAX_FIREWORKS 40
101 #define FIREWORK_MOVEMENT_RANGE 6
102 #define FIREWORK_SIZE 2
104 /* position, speed, "phase" (age), color of all fireworks */
105 int firework_xpoints
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
106 int firework_ypoints
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
107 int firework_xspeed
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
108 int firework_yspeed
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
109 int firework_phase
[MAX_ROCKETS
+1];
110 #ifdef HAVE_LCD_COLOR
111 int firework_color
[MAX_ROCKETS
+1][MAX_FIREWORKS
];
114 /* position, speed, "phase" (age) of all rockets */
115 int rocket_xpos
[MAX_ROCKETS
+1];
116 int rocket_ypos
[MAX_ROCKETS
+1];
117 int rocket_xspeed
[MAX_ROCKETS
+1];
118 int rocket_yspeed
[MAX_ROCKETS
+1];
119 int rocket_phase
[MAX_ROCKETS
+1];
120 int rocket_targetphase
[MAX_ROCKETS
+1];
122 /* settings values. these should eventually be saved to
123 * disk. maybe a preset loading/saving system? */
124 int autofire_delay
= 0;
125 int particles_per_firework
= 2;
126 int particle_life
= 1;
128 int show_rockets
= 1;
129 int frames_per_second
= 4;
130 bool quit_plugin
= false;
133 * firework_colors = brightest firework color, used most of the time.
134 * DARK colors = fireworks are nearly burnt out.
135 * DARKER colors = fireworks are several frames away from burning out.
136 * DARKEST colors = fireworks are a couple frames from burning out. */
137 #ifdef HAVE_LCD_COLOR
138 static const unsigned firework_colors
[] = {
139 LCD_RGBPACK(0,255,64), LCD_RGBPACK(61,255,249), LCD_RGBPACK(255,200,61),
140 LCD_RGBPACK(217,22,217), LCD_RGBPACK(22,217,132), LCD_RGBPACK(67,95,254),
141 LCD_RGBPACK(151,84,213) };
143 static const unsigned firework_dark_colors
[] = {
144 LCD_RGBPACK(0,128,32), LCD_RGBPACK(30,128,128), LCD_RGBPACK(128,100,30),
145 LCD_RGBPACK(109,11,109), LCD_RGBPACK(11,109,66), LCD_RGBPACK(33,47,128),
146 LCD_RGBPACK(75,42,105) };
148 static const unsigned firework_darker_colors
[] = {
149 LCD_RGBPACK(0,64,16), LCD_RGBPACK(15,64,64), LCD_RGBPACK(64,50,15),
150 LCD_RGBPACK(55,5,55), LCD_RGBPACK(5,55,33), LCD_RGBPACK(16,24,64),
151 LCD_RGBPACK(38,21,52) };
153 static const unsigned firework_darkest_colors
[] = {
154 LCD_RGBPACK(0,32,8), LCD_RGBPACK(7,32,32), LCD_RGBPACK(32,25,7),
155 LCD_RGBPACK(27,2,27), LCD_RGBPACK(2,27,16), LCD_RGBPACK(8,12,32),
156 LCD_RGBPACK(19,10,26) };
158 #define EXPLOSION_COLOR LCD_RGBPACK(255,240,0)
162 static const struct opt_items autofire_delay_settings
[15] = {
180 int autofire_delay_values
[15] = {
181 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400 };
183 static const struct opt_items particle_settings
[8] = {
194 int particle_values
[8] = {
195 5, 10, 15, 20, 25, 30, 35, 40 };
197 static const struct opt_items particle_life_settings
[9] = {
209 int particle_life_values
[9] = {
210 20, 30, 40, 50, 60, 70, 80, 90, 100 };
212 static const struct opt_items gravity_settings
[4] = {
219 int gravity_values
[4] = {
222 #ifdef HAVE_LCD_COLOR
224 static const struct opt_items rocket_settings
[3] = {
226 { "Yes (no trails)", -1 },
227 { "Yes (with trails)", -1 },
229 int rocket_values
[4] = {
234 static const struct opt_items rocket_settings
[2] = {
238 int rocket_values
[4] = {
243 static const struct opt_items fps_settings
[9] = {
255 int fps_values
[9] = {
256 20, 25, 30, 35, 40, 45, 50, 55, 60 };
258 static const struct menu_item items
[] = {
259 { "Start Demo", NULL
},
260 { "Auto-Fire", NULL
},
261 { "Particles Per Firework", NULL
},
262 { "Particle Life", NULL
},
264 { "Show Rockets", NULL
},
265 { "FPS (Speed)", NULL
},
269 /* called on startup. initializes all variables, etc */
274 for(j
=0; j
<MAX_ROCKETS
; j
++)
275 firework_phase
[j
] = -1;
278 /* called when a rocket hits its destination height.
279 * prepares all associated fireworks to be expelled. */
280 void init_explode(int x
, int y
, int firework
, int points
)
284 for(i
=0; i
<points
; i
++)
286 rb
->srand(*rb
->current_tick
* i
);
288 firework_xpoints
[firework
][i
] = x
;
289 firework_ypoints
[firework
][i
] = y
;
291 firework_xspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
) - FIREWORK_MOVEMENT_RANGE
/2;
292 firework_yspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
) - FIREWORK_MOVEMENT_RANGE
/2;
294 #ifdef HAVE_LCD_COLOR
295 firework_color
[firework
][i
] = rb
->rand() % 7;
300 /* called when a rocket is launched.
301 * prepares said rocket to start moving towards its destination. */
302 void init_rocket(int rocket
)
304 rb
->srand(*rb
->current_tick
);
306 rocket_xpos
[rocket
] = rb
->rand() % LCD_WIDTH
;
307 rocket_ypos
[rocket
] = LCD_HEIGHT
;
309 rocket_xspeed
[rocket
] = (rb
->rand() % ROCKET_MOVEMENT_RANGE
) - ROCKET_MOVEMENT_RANGE
/2;
310 rocket_yspeed
[rocket
] = 3;
312 rocket_targetphase
[rocket
] = (ROCKET_LIFE
+ (rb
->rand() % ROCKET_LIFE_VAR
)) / rocket_yspeed
[rocket
];
315 /* startup/configuration menu. */
316 void fireworks_menu(void)
319 bool menu_quit
= false;
321 rb
->lcd_setfont(FONT_UI
);
322 #ifdef HAVE_LCD_COLOR
323 rb
->lcd_set_background(LCD_BLACK
);
324 rb
->lcd_set_foreground(LCD_WHITE
);
326 rb
->lcd_clear_display();
329 m
= menu_init(rb
, items
, sizeof(items
) / sizeof(*items
),
330 NULL
, NULL
, NULL
, NULL
);
332 rb
->button_clear_queue();
336 result
= menu_show(m
);
341 rb
->lcd_setfont(FONT_SYSFIXED
);
343 #ifdef HAVE_LCD_COLOR
344 rb
->lcd_set_background(LCD_BLACK
);
345 rb
->lcd_set_foreground(LCD_WHITE
);
348 rb
->lcd_clear_display();
356 rb
->set_option("Auto-Fire", &autofire_delay
, INT
, autofire_delay_settings
, 15, NULL
);
360 rb
->set_option("Particles Per Firework", &particles_per_firework
, INT
, particle_settings
, 8, NULL
);
364 rb
->set_option("Particle Life", &particle_life
, INT
, particle_life_settings
, 9, NULL
);
368 rb
->set_option("Gravity", &gravity
, INT
, gravity_settings
, 4, NULL
);
372 rb
->set_option("Show Rockets", &show_rockets
, INT
, rocket_settings
, 3, NULL
);
376 rb
->set_option("FPS (Speed)", &frames_per_second
, INT
, fps_settings
, 9, NULL
);
389 /* this is the plugin entry point */
390 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
)
396 int j
, i
, autofire
=0;
398 int start_tick
, elapsed_tick
;
401 /* set everything up.. no BL timeout, no backdrop,
402 white-text-on-black-background. */
403 backlight_force_on(rb
); /* backlight control in lib/helper.c */
405 rb
->lcd_set_backdrop(NULL
);
406 rb
->lcd_set_background(LCD_BLACK
);
407 rb
->lcd_set_foreground(LCD_WHITE
);
410 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
416 start_tick
= *rb
->current_tick
;
420 rb
->lcd_clear_display();
422 /* loop through every possible rocket */
423 for(j
=0; j
<MAX_ROCKETS
; j
++)
425 /* if the current rocket is actually moving/"alive" then go on and
426 * move/update/explode it */
427 if(rocket_phase
[j
] > -1)
429 #ifdef HAVE_LCD_COLOR /* draw trail, if requested */
432 rb
->lcd_set_foreground(LCD_RGBPACK(128,128,128));
433 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
434 ROCKET_SIZE
, ROCKET_SIZE
);
435 rb
->lcd_set_foreground(LCD_RGBPACK(64,64,64));
436 rb
->lcd_fillrect(rocket_xpos
[j
]-rocket_xspeed
[j
], rocket_ypos
[j
]+rocket_yspeed
[j
],
437 ROCKET_SIZE
, ROCKET_SIZE
);
442 rocket_xpos
[j
] += rocket_xspeed
[j
];
443 rocket_ypos
[j
] -= rocket_yspeed
[j
];
445 #ifdef HAVE_LCD_COLOR
446 rb
->lcd_set_foreground(LCD_WHITE
);
448 if(show_rockets
==2 || show_rockets
==1)
449 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
450 ROCKET_SIZE
, ROCKET_SIZE
);
452 /* if(rocket isn't "there" yet) keep moving
453 * if(rocket IS there) explode it. */
454 if(rocket_phase
[j
] < rocket_targetphase
[j
])
458 rocket_phase
[j
] = -1;
460 firework_phase
[j
] = 0;
461 init_explode(rocket_xpos
[j
], rocket_ypos
[j
], j
, particle_values
[particles_per_firework
]);
465 /* and now onto the fireworks for this particular rocket... */
466 if(firework_phase
[j
] > -1)
468 for(i
=0; i
<particle_values
[particles_per_firework
]; i
++)
470 firework_xpoints
[j
][i
] += firework_xspeed
[j
][i
];
471 firework_ypoints
[j
][i
] += firework_yspeed
[j
][i
];
474 firework_ypoints
[j
][i
] += firework_phase
[j
]/gravity_values
[gravity
];
476 #ifdef HAVE_LCD_COLOR
477 rb
->lcd_set_foreground(firework_darkest_colors
[firework_color
[j
][i
]]);
478 rb
->lcd_fillrect(firework_xpoints
[j
][i
]-1,
479 firework_ypoints
[j
][i
]-1,
480 FIREWORK_SIZE
+2, FIREWORK_SIZE
+2);
482 if(firework_phase
[j
] < particle_life_values
[particle_life
]-10)
483 rb
->lcd_set_foreground(firework_colors
[firework_color
[j
][i
]]);
484 else if(firework_phase
[j
] < particle_life_values
[particle_life
]-7)
485 rb
->lcd_set_foreground(firework_dark_colors
[firework_color
[j
][i
]]);
486 else if(firework_phase
[j
] < particle_life_values
[particle_life
]-3)
487 rb
->lcd_set_foreground(firework_darker_colors
[firework_color
[j
][i
]]);
489 rb
->lcd_set_foreground(firework_darkest_colors
[firework_color
[j
][i
]]);
491 rb
->lcd_fillrect(firework_xpoints
[j
][i
],
492 firework_ypoints
[j
][i
],
493 FIREWORK_SIZE
, FIREWORK_SIZE
);
494 /* WIP - currently ugly explosion effect
495 #ifdef HAVE_LCD_COLOR
496 if(firework_phase[j] < 10)
498 rb->lcd_set_foreground(EXPLOSION_COLOR);
499 rb->lcd_fillrect(rocket_xpos[j]-firework_phase[j],
500 rocket_ypos[j]-firework_phase[j],
501 firework_phase[j]*2, firework_phase[j]*2);
506 #ifdef HAVE_LCD_COLOR
507 rb
->lcd_set_foreground(LCD_WHITE
);
510 /* firework at its destination age?
511 * no = keep aging; yes = delete it. */
512 if(firework_phase
[j
] < particle_life_values
[particle_life
])
515 firework_phase
[j
] = -1;
519 /* is autofire on? */
520 if(autofire_delay
!= 0)
522 elapsed_tick
= *rb
->current_tick
- start_tick
;
524 if(elapsed_tick
> autofire_delay_values
[autofire_delay
])
526 rocket_phase
[autofire
] = 0;
527 init_rocket(autofire
);
529 start_tick
= *rb
->current_tick
;
531 if(autofire
< MAX_ROCKETS
)
540 button
= rb
->button_get_w_tmo(HZ
/fps_values
[frames_per_second
]);
543 case BTN_MENU
: /* back to config menu */
547 case BTN_FIRE
: /* fire off rockets manually */
548 case BTN_FIRE
|BUTTON_REPEAT
:
549 if(thisrocket
< MAX_ROCKETS
)
554 rocket_phase
[thisrocket
] = 0;
555 init_rocket(thisrocket
);
559 /* Turn on backlight timeout (revert to settings) */
560 backlight_use_settings(rb
); /* backlight control in lib/helper.c */
562 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
563 rb
->cpu_boost(false);