summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-12-29 22:53:37 +0000
committerAndy Williams <andy@andywilliams.me>2017-12-29 22:53:37 +0000
commit0800497ab2df8c6e7d353cbdf3686cefab912352 (patch)
tree88fe0d7496c7317ca42d8558f19a4e30806efe07
parent462243c4dfb86b7ed67a0df6ddc19552cf3d2ff9 (diff)
Speed up, remove a lot of calculations
Remove a lot of the CPU overhead for dense snowfall
-rw-r--r--src/e_mod_main.c39
-rw-r--r--src/e_mod_main.h1
2 files changed, 25 insertions, 15 deletions
diff --git a/src/e_mod_main.c b/src/e_mod_main.c
index 4c525fd..5b7557a 100644
--- a/src/e_mod_main.c
+++ b/src/e_mod_main.c
@@ -3,6 +3,10 @@
3#include "e_mod_main.h" 3#include "e_mod_main.h"
4#include "e_mod_config.h" 4#include "e_mod_config.h"
5 5
6#define SPEED_SLOW 6
7#define SPEED_MED 4
8#define SPEED_FAST 2
9static int MAX_FRAMES = SPEED_SLOW * SPEED_MED * SPEED_FAST;
6/* module private routines */ 10/* module private routines */
7static Snow *_snow_init(E_Module *m); 11static Snow *_snow_init(E_Module *m);
8static void _snow_shutdown(Snow *snow); 12static void _snow_shutdown(Snow *snow);
@@ -270,13 +274,13 @@ _snow_flakes_load(char type, Snow *snow)
270 switch (type) 274 switch (type)
271 { 275 {
272 case 's': 276 case 's':
273 flake->speed = 1; 277 flake->speed = SPEED_SLOW;
274 break; 278 break;
275 case 'm': 279 case 'm':
276 flake->speed = 2; 280 flake->speed = SPEED_MED;
277 break; 281 break;
278 case 'l': 282 case 'l':
279 flake->speed = 3; 283 flake->speed = SPEED_FAST;
280 break; 284 break;
281 } 285 }
282 snow->flakes = eina_list_append(snow->flakes, flake); 286 snow->flakes = eina_list_append(snow->flakes, flake);
@@ -290,10 +294,11 @@ _snow_cb_animator(void *data)
290 Snow *snow; 294 Snow *snow;
291 Eina_List *next; 295 Eina_List *next;
292 Evas_Coord ww; 296 Evas_Coord ww;
293 double d; 297 double time;
294 298
295 snow = data; 299 snow = data;
296 evas_output_viewport_get(snow->canvas, NULL, NULL, &ww, NULL); 300 evas_output_viewport_get(snow->canvas, NULL, NULL, &ww, NULL);
301 time = ecore_time_get();
297 302
298 next = snow->flakes; 303 next = snow->flakes;
299 while (next) 304 while (next)
@@ -303,29 +308,33 @@ _snow_cb_animator(void *data)
303 int drift; 308 int drift;
304 309
305 flake = next->data; 310 flake = next->data;
306 d = ecore_time_get() - flake->start_time; 311 next = eina_list_next(next);
307 y = 30 * d * flake->speed; 312 if (snow->frame % flake->speed != 0)
308 switch (rand() % 22) 313 continue;
314
315 switch (rand() % 50)
309 { 316 {
310 case 19: 317 case 0:
311 drift = -1; 318 drift = -1;
312 break; 319 break;
313 case 20: 320 case 1:
314 case 21: 321 case 2:
315 drift = 1; 322 drift = 1;
316 break; 323 break;
317 default: 324 default:
318 drift = 0; 325 drift = 0;
319 } 326 }
320 evas_object_geometry_get(flake->flake, &x, NULL, NULL, NULL); 327 evas_object_geometry_get(flake->flake, &x, &y, NULL, NULL);
321 if (y > snow->height) 328 if (++y > snow->height)
322 flake->start_time = ecore_time_get() + (double)(random() % 100) / (double)100; 329 y = -1 * rand() % 100;
323 if (x + drift >= ww) 330 if (x + drift >= ww)
324 x = 0; 331 x = 0;
325 evas_object_move(flake->flake, x + drift, y); 332 evas_object_move(flake->flake, x + drift, y);
326
327 next = eina_list_next(next);
328 } 333 }
334
335 snow->frame++;
336 if (snow->frame > MAX_FRAMES)
337 snow->frame = 0;
329 return EINA_TRUE; 338 return EINA_TRUE;
330} 339}
331 340
diff --git a/src/e_mod_main.h b/src/e_mod_main.h
index 84ec72d..fb80b66 100644
--- a/src/e_mod_main.h
+++ b/src/e_mod_main.h
@@ -27,6 +27,7 @@ struct _Snow
27 Eina_List *cons; 27 Eina_List *cons;
28 Evas *canvas; 28 Evas *canvas;
29 Ecore_Animator *animator; 29 Ecore_Animator *animator;
30 int frame;
30 Eina_List *trees; 31 Eina_List *trees;
31 Eina_List *flakes; 32 Eina_List *flakes;
32 33