summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2004-06-16 20:51:05 +0000
committerJens Arnold <amiconn@rockbox.org>2004-06-16 20:51:05 +0000
commit58f17cd082d813dafe5839dc00f80d18649cf654 (patch)
treed664f0ac07758f9a671e6e07af326d0b2eaf8249
parentc05b7d722ad15fe3720f86b21af05e9a9cd18b8f (diff)
Mandelbrot didn't yield() at all, leading to playback problems when heavily calculating mandelbrots
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4759 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/mandelbrot.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/apps/plugins/mandelbrot.c b/apps/plugins/mandelbrot.c
index 450a4ebfee..786e31dc40 100644
--- a/apps/plugins/mandelbrot.c
+++ b/apps/plugins/mandelbrot.c
@@ -48,14 +48,14 @@ void init_mandelbrot_set(void){
void calc_mandelbrot_set(void){
- unsigned int start_tick;
+ unsigned int start_tick, last_yield;
int n_iter;
int x_pixel, y_pixel;
int x, x2, y, y2, a, b;
int x_fact, y_fact;
int brightness;
- start_tick = *rb->current_tick;
+ start_tick = last_yield = *rb->current_tick;
gray_clear_display();
@@ -63,9 +63,9 @@ void calc_mandelbrot_set(void){
y_fact = (y_max - y_min) / LCD_HEIGHT;
for (x_pixel = 0; x_pixel<LCD_WIDTH; x_pixel++){
- a = (x_pixel * x_fact) + x_min;
- for(y_pixel = LCD_HEIGHT-1; y_pixel>=0; y_pixel--){
- b = (y_pixel * y_fact) + y_min;
+ a = (x_pixel * x_fact) + x_min;
+ for(y_pixel = LCD_HEIGHT-1; y_pixel>=0; y_pixel--){
+ b = (y_pixel * y_fact) + y_min;
x = 0;
y = 0;
n_iter = 0;
@@ -89,9 +89,15 @@ void calc_mandelbrot_set(void){
} else {
brightness = 255 - (31 * (n_iter & 7));
}
- graybuffer[y_pixel]=brightness;
+ graybuffer[y_pixel]=brightness;
+ /* be nice to other threads:
+ * if at least one tick has passed, yield */
+ if (*rb->current_tick > last_yield){
+ rb->yield();
+ last_yield = *rb->current_tick;
+ }
}
- gray_drawgraymap(graybuffer, x_pixel, 0, 1, LCD_HEIGHT, 1);
+ gray_drawgraymap(graybuffer, x_pixel, 0, 1, LCD_HEIGHT, 1);
}
}