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 "lib/helper.h"
23 #include "lib/playback_control.h"
28 * FIREWORKS.C by ZAKK ROBERTS
29 * Rockbox plugin simulating a fireworks display.
30 * Supports all bitmap LCDs, fully scalable.
31 * Currently disabled for Archos Recorder - runs too slow.
34 /* All sorts of keymappings.. */
35 #if (CONFIG_KEYPAD == IRIVER_H300_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD)
36 #define BTN_MENU BUTTON_OFF
37 #define BTN_FIRE BUTTON_SELECT
39 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
40 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
41 #define BTN_MENU BUTTON_MENU
42 #define BTN_FIRE BUTTON_SELECT
44 #elif (CONFIG_KEYPAD == RECORDER_PAD)
45 #define BTN_MENU BUTTON_OFF
46 #define BTN_FIRE BUTTON_PLAY
48 #elif (CONFIG_KEYPAD == ARCHOS_AV300_PAD)
49 #define BTN_MENU BUTTON_OFF
50 #define BTN_FIRE BUTTON_SELECT
52 #elif (CONFIG_KEYPAD == ONDIO_PAD)
53 #define BTN_MENU BUTTON_MENU
54 #define BTN_FIRE BUTTON_UP
56 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
57 #define BTN_MENU BUTTON_POWER
58 #define BTN_FIRE BUTTON_SELECT
60 #elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD)
61 #define BTN_MENU BUTTON_MODE
62 #define BTN_FIRE BUTTON_SELECT
64 #elif (CONFIG_KEYPAD == GIGABEAT_PAD) || \
65 (CONFIG_KEYPAD == GIGABEAT_S_PAD) || \
66 (CONFIG_KEYPAD == MROBE100_PAD)
67 #define BTN_MENU BUTTON_MENU
68 #define BTN_FIRE BUTTON_SELECT
70 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
71 (CONFIG_KEYPAD == SANSA_C200_PAD)
72 #define BTN_MENU BUTTON_POWER
73 #define BTN_FIRE BUTTON_SELECT
75 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
76 #define BTN_MENU (BUTTON_HOME|BUTTON_REPEAT)
77 #define BTN_FIRE BUTTON_SELECT
79 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
80 #define BTN_MENU BUTTON_POWER
81 #define BTN_FIRE BUTTON_PLAY
83 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
84 #define BTN_MENU BUTTON_RC_REC
85 #define BTN_FIRE BUTTON_RC_PLAY
87 #elif (CONFIG_KEYPAD == COWON_D2_PAD)
88 #define BTN_MENU (BUTTON_MENU|BUTTON_REL)
90 #elif CONFIG_KEYPAD == IAUDIO67_PAD
91 #define BTN_MENU BUTTON_MENU
92 #define BTN_FIRE BUTTON_PLAY
94 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
95 #define BTN_MENU BUTTON_MENU
96 #define BTN_FIRE BUTTON_SELECT
98 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
99 #define BTN_MENU BUTTON_MENU
100 #define BTN_FIRE BUTTON_SELECT
102 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
103 #define BTN_MENU BUTTON_MENU
104 #define BTN_FIRE BUTTON_PLAY
106 #elif (CONFIG_KEYPAD == ONDAVX747_PAD)
107 #define BTN_MENU (BUTTON_MENU|BUTTON_REL)
109 #elif (CONFIG_KEYPAD == SAMSUNG_YH_PAD)
110 #define BTN_MENU BUTTON_LEFT
111 #define BTN_FIRE BUTTON_PLAY
113 #elif (CONFIG_KEYPAD == PBELL_VIBE500_PAD)
114 #define BTN_MENU BUTTON_MENU
115 #define BTN_FIRE BUTTON_OK
117 #elif defined(HAVE_TOUCHSCREEN)
118 /* This is a touchscreen target */
120 #error No keymap defined!
123 #ifdef HAVE_TOUCHSCREEN
125 #define BTN_MENU (BUTTON_TOPLEFT|BUTTON_REL)
128 #define BTN_FIRE BUTTON_CENTER
132 /* The lowdown on source terminology:
133 * a ROCKET is launched from the LCD bottom.
134 * FIREWORKs are ejected from the rocket when it explodes. */
136 #define MAX_ROCKETS 40
137 #define ROCKET_LIFE (LCD_HEIGHT/2)
138 #define ROCKET_LIFE_VAR (LCD_HEIGHT/4)
139 #define ROCKET_SIZE 2
140 #define ROCKET_MOVEMENT_RANGE 4
141 #define ROCKET_TRAIL_PARTICLES 50
143 #define MAX_FIREWORKS 40
144 #define FIREWORK_MOVEMENT_RANGE 6
145 #define FIREWORK_SIZE 2
147 /* position, speed, "phase" (age), color of all fireworks */
148 int firework_xpoints
[MAX_ROCKETS
][MAX_FIREWORKS
];
149 int firework_ypoints
[MAX_ROCKETS
][MAX_FIREWORKS
];
150 int firework_xspeed
[MAX_ROCKETS
][MAX_FIREWORKS
];
151 int firework_yspeed
[MAX_ROCKETS
][MAX_FIREWORKS
];
152 int firework_phase
[MAX_ROCKETS
];
153 #ifdef HAVE_LCD_COLOR
154 int firework_color
[MAX_ROCKETS
][MAX_FIREWORKS
];
157 /* position, speed, "phase" (age) of all rockets */
158 int rocket_xpos
[MAX_ROCKETS
];
159 int rocket_ypos
[MAX_ROCKETS
];
160 int rocket_xspeed
[MAX_ROCKETS
];
161 int rocket_yspeed
[MAX_ROCKETS
];
162 int rocket_phase
[MAX_ROCKETS
];
163 int rocket_targetphase
[MAX_ROCKETS
];
165 /* settings values. these should eventually be saved to
166 * disk. maybe a preset loading/saving system? */
167 int autofire_delay
= 0;
168 int particles_per_firework
= 2;
169 int particle_life
= 1;
171 int show_rockets
= 1;
172 int frames_per_second
= 4;
173 bool quit_plugin
= false;
176 * firework_colors = brightest firework color, used most of the time.
177 * DARK colors = fireworks are nearly burnt out.
178 * DARKER colors = fireworks are several frames away from burning out.
179 * DARKEST colors = fireworks are a couple frames from burning out. */
180 #ifdef HAVE_LCD_COLOR
181 static const unsigned firework_colors
[] = {
182 LCD_RGBPACK(0,255,64), LCD_RGBPACK(61,255,249), LCD_RGBPACK(255,200,61),
183 LCD_RGBPACK(217,22,217), LCD_RGBPACK(22,217,132), LCD_RGBPACK(67,95,254),
184 LCD_RGBPACK(151,84,213) };
186 static const unsigned firework_dark_colors
[] = {
187 LCD_RGBPACK(0,128,32), LCD_RGBPACK(30,128,128), LCD_RGBPACK(128,100,30),
188 LCD_RGBPACK(109,11,109), LCD_RGBPACK(11,109,66), LCD_RGBPACK(33,47,128),
189 LCD_RGBPACK(75,42,105) };
191 static const unsigned firework_darker_colors
[] = {
192 LCD_RGBPACK(0,64,16), LCD_RGBPACK(15,64,64), LCD_RGBPACK(64,50,15),
193 LCD_RGBPACK(55,5,55), LCD_RGBPACK(5,55,33), LCD_RGBPACK(16,24,64),
194 LCD_RGBPACK(38,21,52) };
196 static const unsigned firework_darkest_colors
[] = {
197 LCD_RGBPACK(0,32,8), LCD_RGBPACK(7,32,32), LCD_RGBPACK(32,25,7),
198 LCD_RGBPACK(27,2,27), LCD_RGBPACK(2,27,16), LCD_RGBPACK(8,12,32),
199 LCD_RGBPACK(19,10,26) };
201 #define EXPLOSION_COLOR LCD_RGBPACK(255,240,0)
205 static const struct opt_items autofire_delay_settings
[15] = {
223 int autofire_delay_values
[15] = {
224 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400 };
226 static const struct opt_items particle_settings
[8] = {
237 int particle_values
[8] = {
238 5, 10, 15, 20, 25, 30, 35, 40 };
240 static const struct opt_items particle_life_settings
[9] = {
252 int particle_life_values
[9] = {
253 20, 30, 40, 50, 60, 70, 80, 90, 100 };
255 static const struct opt_items gravity_settings
[4] = {
262 int gravity_values
[4] = {
265 #ifdef HAVE_LCD_COLOR
267 static const struct opt_items rocket_settings
[3] = {
269 { "Yes (no trails)", -1 },
270 { "Yes (with trails)", -1 },
272 int rocket_values
[4] = {
277 static const struct opt_items rocket_settings
[2] = {
281 int rocket_values
[4] = {
286 static const struct opt_items fps_settings
[9] = {
298 int fps_values
[9] = {
299 20, 25, 30, 35, 40, 45, 50, 55, 60 };
301 MENUITEM_STRINGLIST(menu
, "Fireworks Menu", NULL
,
302 "Start Demo", "Auto-Fire", "Particles Per Firework",
303 "Particle Life", "Gravity", "Show Rockets",
304 "FPS (Speed)", "Playback Control", "Quit");
306 /* called on startup. initializes all variables, etc */
311 for(j
=0; j
<MAX_ROCKETS
; j
++)
313 rocket_phase
[j
] = -1;
314 firework_phase
[j
] = -1;
318 /* called when a rocket hits its destination height.
319 * prepares all associated fireworks to be expelled. */
320 void init_explode(int x
, int y
, int firework
, int points
)
324 for(i
=0; i
<points
; i
++)
326 rb
->srand(*rb
->current_tick
* i
);
328 firework_xpoints
[firework
][i
] = x
;
329 firework_ypoints
[firework
][i
] = y
;
331 firework_xspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
)
332 - FIREWORK_MOVEMENT_RANGE
/2;
333 firework_yspeed
[firework
][i
] = (rb
->rand() % FIREWORK_MOVEMENT_RANGE
)
334 - FIREWORK_MOVEMENT_RANGE
/2;
336 #ifdef HAVE_LCD_COLOR
337 firework_color
[firework
][i
] = rb
->rand() % 7;
342 /* called when a rocket is launched.
343 * prepares said rocket to start moving towards its destination. */
344 void init_rocket(int rocket
)
346 rb
->srand(*rb
->current_tick
);
348 rocket_xpos
[rocket
] = rb
->rand() % LCD_WIDTH
;
349 rocket_ypos
[rocket
] = LCD_HEIGHT
;
351 rocket_xspeed
[rocket
] = (rb
->rand() % ROCKET_MOVEMENT_RANGE
)
352 - ROCKET_MOVEMENT_RANGE
/2;
353 rocket_yspeed
[rocket
] = 3;
355 rocket_phase
[rocket
] = 0;
356 rocket_targetphase
[rocket
] = (ROCKET_LIFE
+ (rb
->rand() % ROCKET_LIFE_VAR
))
357 / rocket_yspeed
[rocket
];
360 /* startup/configuration menu. */
361 void fireworks_menu(void)
363 int selected
= 0, result
;
364 bool menu_quit
= false;
366 rb
->lcd_setfont(FONT_UI
);
367 #ifdef HAVE_LCD_COLOR
368 rb
->lcd_set_background(LCD_BLACK
);
369 rb
->lcd_set_foreground(LCD_WHITE
);
371 rb
->lcd_clear_display();
374 rb
->button_clear_queue();
378 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
383 rb
->lcd_setfont(FONT_SYSFIXED
);
385 #ifdef HAVE_LCD_COLOR
386 rb
->lcd_set_background(LCD_BLACK
);
387 rb
->lcd_set_foreground(LCD_WHITE
);
390 rb
->lcd_clear_display();
398 rb
->set_option("Auto-Fire", &autofire_delay
, INT
,
399 autofire_delay_settings
, 15, NULL
);
403 rb
->set_option("Particles Per Firework", &particles_per_firework
,
404 INT
, particle_settings
, 8, NULL
);
408 rb
->set_option("Particle Life", &particle_life
, INT
,
409 particle_life_settings
, 9, NULL
);
413 rb
->set_option("Gravity", &gravity
, INT
,
414 gravity_settings
, 4, NULL
);
418 rb
->set_option("Show Rockets", &show_rockets
, INT
,
419 rocket_settings
, 3, NULL
);
423 rb
->set_option("FPS (Speed)", &frames_per_second
, INT
,
424 fps_settings
, 9, NULL
);
428 playback_control(NULL
);
439 /* this is the plugin entry point */
440 enum plugin_status
plugin_start(const void* parameter
)
446 int start_tick
, elapsed_tick
;
449 /* set everything up.. no BL timeout, no backdrop,
450 white-text-on-black-background. */
451 backlight_force_on(); /* backlight control in lib/helper.c */
453 rb
->lcd_set_backdrop(NULL
);
454 rb
->lcd_set_background(LCD_BLACK
);
455 rb
->lcd_set_foreground(LCD_WHITE
);
458 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
464 start_tick
= *rb
->current_tick
;
468 rb
->lcd_clear_display();
470 /* loop through every possible rocket */
471 for(j
=0; j
<MAX_ROCKETS
; j
++)
473 /* if the current rocket is actually moving/"alive" then go on and
474 * move/update/explode it */
475 if(rocket_phase
[j
] > -1)
477 #ifdef HAVE_LCD_COLOR /* draw trail, if requested */
480 rb
->lcd_set_foreground(LCD_RGBPACK(128,128,128));
481 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
482 ROCKET_SIZE
, ROCKET_SIZE
);
483 rb
->lcd_set_foreground(LCD_RGBPACK(64,64,64));
484 rb
->lcd_fillrect(rocket_xpos
[j
]-rocket_xspeed
[j
],
485 rocket_ypos
[j
]+rocket_yspeed
[j
],
486 ROCKET_SIZE
, ROCKET_SIZE
);
491 rocket_xpos
[j
] += rocket_xspeed
[j
];
492 rocket_ypos
[j
] -= rocket_yspeed
[j
];
494 #ifdef HAVE_LCD_COLOR
495 rb
->lcd_set_foreground(LCD_WHITE
);
497 if(show_rockets
==2 || show_rockets
==1)
498 rb
->lcd_fillrect(rocket_xpos
[j
], rocket_ypos
[j
],
499 ROCKET_SIZE
, ROCKET_SIZE
);
501 /* if(rocket isn't "there" yet) keep moving
502 * if(rocket IS there) explode it. */
503 if(rocket_phase
[j
] < rocket_targetphase
[j
])
507 rocket_phase
[j
] = -1;
509 firework_phase
[j
] = 0;
510 init_explode(rocket_xpos
[j
], rocket_ypos
[j
], j
,
511 particle_values
[particles_per_firework
]);
515 /* and now onto the fireworks for this particular rocket... */
516 if(firework_phase
[j
] > -1)
518 for(i
=0; i
<particle_values
[particles_per_firework
]; i
++)
520 firework_xpoints
[j
][i
] += firework_xspeed
[j
][i
];
521 firework_ypoints
[j
][i
] += firework_yspeed
[j
][i
];
524 firework_ypoints
[j
][i
] += firework_phase
[j
]
525 /gravity_values
[gravity
];
527 #ifdef HAVE_LCD_COLOR
528 rb
->lcd_set_foreground(
529 firework_darkest_colors
[firework_color
[j
][i
]]);
530 rb
->lcd_fillrect(firework_xpoints
[j
][i
]-1,
531 firework_ypoints
[j
][i
]-1,
532 FIREWORK_SIZE
+2, FIREWORK_SIZE
+2);
534 int phase_left
= particle_life_values
[particle_life
]
537 rb
->lcd_set_foreground(
538 firework_colors
[firework_color
[j
][i
]]);
539 else if(phase_left
> 7)
540 rb
->lcd_set_foreground(
541 firework_dark_colors
[firework_color
[j
][i
]]);
542 else if(phase_left
> 3)
543 rb
->lcd_set_foreground(
544 firework_darker_colors
[firework_color
[j
][i
]]);
546 rb
->lcd_set_foreground(
547 firework_darkest_colors
[firework_color
[j
][i
]]);
549 rb
->lcd_fillrect(firework_xpoints
[j
][i
],
550 firework_ypoints
[j
][i
],
551 FIREWORK_SIZE
, FIREWORK_SIZE
);
552 /* WIP - currently ugly explosion effect
553 #ifdef HAVE_LCD_COLOR
554 if(firework_phase[j] < 10)
556 rb->lcd_set_foreground(EXPLOSION_COLOR);
557 rb->lcd_fillrect(rocket_xpos[j]-firework_phase[j],
558 rocket_ypos[j]-firework_phase[j],
559 firework_phase[j]*2, firework_phase[j]*2);
564 #ifdef HAVE_LCD_COLOR
565 rb
->lcd_set_foreground(LCD_WHITE
);
568 /* firework at its destination age?
569 * no = keep aging; yes = delete it. */
570 if(firework_phase
[j
] < particle_life_values
[particle_life
])
573 firework_phase
[j
] = -1;
577 /* is autofire on? */
578 if(autofire_delay
!= 0)
580 elapsed_tick
= *rb
->current_tick
- start_tick
;
582 if(elapsed_tick
> autofire_delay_values
[autofire_delay
])
584 init_rocket(thisrocket
);
585 if(++thisrocket
== MAX_ROCKETS
)
588 start_tick
= *rb
->current_tick
;
594 button
= rb
->button_get_w_tmo(HZ
/fps_values
[frames_per_second
]);
597 case BTN_MENU
: /* back to config menu */
601 case BTN_FIRE
: /* fire off rockets manually */
602 case BTN_FIRE
|BUTTON_REPEAT
:
603 init_rocket(thisrocket
);
604 if(++thisrocket
== MAX_ROCKETS
)
609 /* Turn on backlight timeout (revert to settings) */
610 backlight_use_settings(); /* backlight control in lib/helper.c */
612 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
613 rb
->cpu_boost(false);