fixed some problem with change daytime, plane don't fly in night
authorTanya <tanya@bookdmitri.oblgaz>
Mon, 12 Apr 2010 21:23:10 +0000 (00:23 +0300)
committerTanya <tanya@bookdmitri.oblgaz>
Mon, 12 Apr 2010 21:23:10 +0000 (00:23 +0300)
applet/src/livewp-home-widget.c
applet/src/livewp-home-widget.h

index 01daa18..4b7b887 100644 (file)
@@ -44,7 +44,6 @@ HD_DEFINE_PLUGIN_MODULE (AWallpaperPlugin, animation_wallpaper_plugin, HD_TYPE_H
 #define Ystartposition 425 
 
 gint xapplet = 0, yapplet = 0;
-GSList * objects_list = NULL;
 Scene scene;
 
 static void
@@ -171,7 +170,7 @@ path_line(gint x0, gint x1, double t)
 void
 destroy_hildon_actor(Actor *actor)
 {
-    fprintf(stderr, "estroy_hildon_actor %p\n",actor->widget);
+    fprintf(stderr, "destroy_hildon_actor %s\n",actor->name);
     gtk_widget_destroy(actor->widget);
     actor->widget = NULL;
 }
@@ -230,14 +229,13 @@ rnd(gint max)
     srand(time(NULL));
     return rand() % max;
 }
-guint seed;
 gint fast_rnd(gint max)
 {
     guint offset = 12923;
     guint multiplier = 4079;
     
-    seed = seed * multiplier + offset;
-    return (gint)(seed % max);
+    scene.seed = scene.seed * multiplier + offset;
+    return (gint)(scene.seed % max);
 }
 
 gint 
@@ -261,7 +259,7 @@ change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
     char *newfile;
 
     if (actor){
-        if (get_daytime() == TIME_NIGHT){
+        if (scene.daytime == TIME_NIGHT){
             if (!actor->visible){
                 actor->visible = TRUE;
                 phase = get_moon_phase();
@@ -378,17 +376,14 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
     sec = tvb.tv_sec;
 //    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
    
+    if (scene.daytime != TIME_NIGHT){
+        if (actor->time_start_animation == 0){
+            actor->time_start_animation = sec + probability_plane();
+            return;
+        }
+    }
     if (!actor->visible){
         actor->visible = TRUE;
-        if (scene.daytime == TIME_NIGHT){
-            if (actor->filename)
-                g_free(actor->filename);
-            actor->filename = g_strdup("tu154.png");
-        }else{
-            if (actor->filename)
-                g_free(actor->filename);
-            actor->filename = g_strdup("tu154.png");
-        }
         create_hildon_actor(actor, desktop_plugin);
     }
     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
@@ -402,7 +397,10 @@ change_plane1(Actor *actor, AWallpaperPlugin *desktop_plugin)
         /* stop animation */
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + probability_plane();
+        if (scene.daytime == TIME_NIGHT) 
+            actor->time_start_animation = 0;
+        else 
+            actor->time_start_animation = sec + probability_plane();
     }
 
 }
@@ -423,21 +421,17 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
     ms = tvb.tv_usec;
     sec = tvb.tv_sec;
 //    fprintf(stderr, "1 %f - %d\n", sec+(double)ms/100000, now);
-   
+    if (scene.daytime != TIME_NIGHT){
+        if (actor->time_start_animation == 0){
+            actor->time_start_animation = sec + probability_plane();
+            return;
+        }
+    }
     if (!actor->visible){
         actor->visible = TRUE;
-        if (scene.daytime == TIME_NIGHT){
-            if (actor->filename)
-                g_free(actor->filename);
-        if (scene.daytime == TIME_NIGHT)
-            actor->filename = g_strdup("plane3.png");
-        }else{
-            if (actor->filename)
-                g_free(actor->filename);
-            actor->filename = g_strdup("plane3.png");
-        }
         create_hildon_actor(actor, desktop_plugin);
     }
+
     t = (double)((double)sec+(double)ms/1000000 - actor->time_start_animation) / actor->duration_animation;
     x = path_line(x0, x1, t);
     y = path_line(y0, y1, t);
@@ -449,7 +443,10 @@ change_plane2(Actor *actor, AWallpaperPlugin *desktop_plugin)
         /* stop animation */
         actor->visible = FALSE;
         destroy_hildon_actor(actor);
-        actor->time_start_animation = sec + probability_plane();
+        if (scene.daytime == TIME_NIGHT) 
+            actor->time_start_animation = 0;
+        else 
+            actor->time_start_animation = sec + probability_plane();
     }
 
 }
@@ -510,9 +507,10 @@ change_cloud(Actor *actor, AWallpaperPlugin *desktop_plugin)
 void
 change_wind(Actor *actor, AWallpaperPlugin *desktop_plugin)
 {
-    scene.wind_orientation = fast_rnd(2) - 1;
-    scene.wind_angle = (double)(fast_rnd(400) - 200) / 100;
-    actor->time_start_animation = time(NULL) + (fast_rnd(20) + 10) * 60;
+    scene.wind_orientation = fast_rnd(2);
+    if (scene.wind_orientation == 0) scene.wind_orientation = -1;
+    scene.wind_angle = (double)(fast_rnd(200) - 100) / 100;
+    actor->time_start_animation = time(NULL) + (fast_rnd(10) + 10) * 60;
     fprintf(stderr, "change wind orient = %d angle = %f after = %d\n", scene.wind_orientation, scene.wind_angle, actor->time_start_animation-time(NULL));
 }
 
@@ -613,11 +611,8 @@ change_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin)
 void 
 change_static_actor(Actor * actor, AWallpaperPlugin *desktop_plugin)
 {
-    gint daytime;
     gchar *newfile;
-    if (!actor) return;
-    daytime = get_daytime();
-    newfile = g_strdup_printf("%s%d.png", actor->name, daytime); 
+    newfile = g_strdup_printf("%s%d.png", actor->name, scene.daytime); 
     if (actor->filename)
             g_free(actor->filename);
     actor->filename = newfile;
@@ -678,6 +673,9 @@ init_scene(AWallpaperPlugin *desktop_plugin)
   scene.actors = NULL;
   scene.wind_orientation = -1;
   scene.wind_angle = 0.3;
+  /* init value for random */
+  scene.seed = time(NULL);
+
   
 
   actor = init_object(desktop_plugin, "sky", "sky0.png", 0, 0, 5, 800, 480, 
@@ -766,6 +764,9 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   scene.actors = NULL;
   scene.wind_orientation = -1;
   scene.wind_angle = 0.3;
+  /* init value for random */
+  scene.seed = time(NULL);
+
   
   actor = init_object(desktop_plugin, "sky", "sky.png", 0, 0, 5, 800, 480, 
                       TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
@@ -791,12 +792,25 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   change_moon(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
   
-  actor = init_object(desktop_plugin, "cloud1", "cloud2.png", 0, fast_rnd(300), 7, 188, 75, 
+  actor = init_object(desktop_plugin, "cloud1", "cloud1.png", 0, fast_rnd(300)-97, 7, 150, 97, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 5*60;
+  scene.actors = g_slist_append(scene.actors, actor);
+  
+  actor = init_object(desktop_plugin, "cloud2", "cloud2.png", 0, fast_rnd(300)-75, 7, 188, 75, 
                       FALSE, 100, 255, (gpointer)&change_cloud, NULL);
-  actor->time_start_animation = now + fast_rnd(3) * 60;
+  actor->time_start_animation = now + fast_rnd(180);
+  actor->duration_animation = 5*60;
+  scene.actors = g_slist_append(scene.actors, actor);
+
+  actor = init_object(desktop_plugin, "cloud4", "cloud4.png", 0, fast_rnd(300)-75, 7, 150, 75, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(180);
   actor->duration_animation = 5*60;
   scene.actors = g_slist_append(scene.actors, actor);
 
   actor = init_object(desktop_plugin, "plane2", "plane3.png", 0, 45, 8, 160, 50, 
                       FALSE, 100, 255, (gpointer)&change_plane2, NULL);
   actor->time_start_animation = now + probability_plane();
@@ -814,6 +828,10 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   change_static_actor(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
 
+  actor = init_object(desktop_plugin, "wind", "", 0, 0, 5, 0, 0, 
+                      FALSE, 100, 255, (gpointer)&change_wind, NULL);
+  change_wind(actor, desktop_plugin);
+  scene.actors = g_slist_append(scene.actors, actor);
 
 }
 
@@ -902,12 +920,12 @@ change_actor(GtkWidget * actor)
 static gboolean
 short_timeout (AWallpaperPlugin *desktop_plugin)
 {
-      gint daytime = get_daytime();
-      GSList * tmp;
-      void (*pfunc)(gpointer, gpointer);
-      time_t now;
-      Actor *actor;
-      gboolean stop_flag = TRUE;
+    gint daytime = get_daytime();
+    GSList * tmp;
+    void (*pfunc)(gpointer, gpointer);
+    time_t now;
+    Actor *actor;
+    gboolean stop_flag = TRUE;
 
     if (!desktop_plugin->priv->visible || !desktop_plugin->priv->rich_animation){
         desktop_plugin->priv->short_timer = 0;
@@ -955,6 +973,7 @@ long_timeout (AWallpaperPlugin *desktop_plugin)
     }
     //fprintf(stderr, "timer daytime=%d\n", daytime);
     if (scene.daytime != daytime){
+        scene.daytime = daytime;
         tmp = scene.actors;
         while (tmp != NULL){
             //change_actor(tmp->data);
@@ -982,7 +1001,6 @@ long_timeout (AWallpaperPlugin *desktop_plugin)
         tmp = g_slist_next(tmp);
     }
    
-    scene.daytime = daytime;
 
     return TRUE; /* keep running this event */
 }
@@ -1042,9 +1060,7 @@ animation_wallpaper_plugin_init (AWallpaperPlugin *desktop_plugin)
     gtk_container_add (GTK_CONTAINER (desktop_plugin), rich_animation);
     init_applet_position();
 
-    /* start value for random */
-    seed = time(NULL);
-
+    
     fprintf(stderr, "!!!theme = %s\n", priv->theme);
     if (!strcmp(priv->theme,"Modern"))
         init_scene(desktop_plugin);
index 2f83a9d..fd3b159 100644 (file)
@@ -53,6 +53,7 @@ typedef struct {
     gint timer_type;
     gint wind_orientation; // +/- 1
     double wind_angle; // [-1 .. 1]
+    guint seed; /* init value for random  */
 } Scene;
 /*
 typedef struct {