tried to do probability
authorTanya <tanya@bookdmitri.oblgaz>
Sun, 11 Apr 2010 22:15:53 +0000 (01:15 +0300)
committerTanya <tanya@bookdmitri.oblgaz>
Sun, 11 Apr 2010 22:15:53 +0000 (01:15 +0300)
applet/src/livewp-home-widget.c

index 9cc7e06..8448c7e 100644 (file)
@@ -27,6 +27,7 @@
 #include <gconf/gconf-client.h>
 #include "livewp-rules.h"
 #include <sys/time.h>
+#include <stdlib.h>
 
 #define PLUGIN_NAME "livewp-home-widget.desktop-0"
 #define GCONF_KEY_POSITION "/apps/osso/hildon-desktop/applets/%s/position"
@@ -223,6 +224,31 @@ init_object(AWallpaperPlugin *desktop_plugin,
   return actor;
 }
 
+gint 
+rnd(gint max)
+{
+    srand(time(NULL));
+    return rand() % max;
+}
+gint seed = 0;
+gint fast_rnd(gint max)
+{
+    gint offset = 12923;
+    gint multiplier = 4079;
+    
+    seed = seed * multiplier + offset;
+    return (gint)(seed % max);
+}
+
+
+gint 
+probability_plane()
+{
+    gint t = (fast_rnd(10) + 1) * 60;
+    fprintf(stderr, "probability_plane %d\n", t);
+    return t;
+}
+
 void 
 change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
@@ -371,7 +397,7 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
         /* stop animation */
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + 5*60;
+        actor->time_start_animation = sec + probability_plane();
     }
 
 }
@@ -418,7 +444,7 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
         /* stop animation */
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + 5*60;
+        actor->time_start_animation = sec + probability_plane();
     }
 
 }
@@ -623,6 +649,8 @@ probability_sun(Actor *actor)
     actor->time_start_animation += 20 * 1;
     actor->duration_animation = G_MAXINT;
 }
+
+
 /* Init Modern Scene */
 static void
 init_scene(AWallpaperPlugin *desktop_plugin)
@@ -691,6 +719,9 @@ static void
 init_scene1(AWallpaperPlugin *desktop_plugin)
 {
   Actor *actor;
+  gint now = time(NULL);
+  
+  seed = time(NULL)%10;
 
   scene.daytime = get_daytime();
   scene.actors = NULL;
@@ -728,19 +759,19 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   
   actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
                       FALSE, 100, 255, (gpointer)&change_plane2, NULL);
-  actor->time_start_animation = time(NULL) + 5;
+  actor->time_start_animation = now + probability_plane();
   actor->duration_animation = 60;
   scene.actors = g_slist_append(scene.actors, actor);
   
   actor = init_object(desktop_plugin, "plane1", "tu154_small.png", 620, 233, 9, 300, 116, 
                       FALSE, 100, 255, (gpointer)&change_plane1, NULL);
-  actor->time_start_animation = time(NULL) + 60;
+  actor->time_start_animation = now + probability_plane();
   actor->duration_animation = 30;
   scene.actors = g_slist_append(scene.actors, actor);
 
   actor = init_object(desktop_plugin, "cloud1", "cloud2.png", 0, 50, 7, 188, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = time(NULL) + 5;
+  actor->time_start_animation = now + 5;
   actor->duration_animation = 5*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
@@ -956,7 +987,7 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
     priv->short_timer = 0;
     /* TODO Move scene to priv */
     scene.timer_type = LONG_TIMER_TYPE;
-
+    
     //sleep(2);
 }