Merge branch 'master' of https://vcs.maemo.org/git/livewp
authorVlad Vasiliev <vlad@toshiba2.oblgaz>
Mon, 12 Apr 2010 13:24:09 +0000 (16:24 +0300)
committerVlad Vasiliev <vlad@toshiba2.oblgaz>
Mon, 12 Apr 2010 13:24:09 +0000 (16:24 +0300)
applet/src/livewp-home-widget.c
applet/src/livewp-home-widget.h
applet/src/livewp-rules.c

index 84abca7..1874793 100644 (file)
@@ -230,23 +230,28 @@ rnd(gint max)
     srand(time(NULL));
     return rand() % max;
 }
-gint seed = 0;
+guint seed;
 gint fast_rnd(gint max)
 {
-    gint offset = 12923;
-    gint multiplier = 4079;
+    guint offset = 12923;
+    guint multiplier = 4079;
     
     seed = seed * multiplier + offset;
     return (gint)(seed % max);
 }
 
+gint 
+probability_sun()
+{
+    /* update sun position after ...  second */
+    return 60;
+}
+
 
 gint 
 probability_plane()
 {
-    gint t = (fast_rnd(10) + 1) * 60;
-    fprintf(stderr, "probability_plane %d\n", t);
-    return t;
+    return (fast_rnd(10) + 1) * 60;
 }
 
 void 
@@ -256,7 +261,7 @@ change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
     char *newfile;
 
     if (actor){
-        if (scene.daytime == TIME_NIGHT){
+        if (get_daytime() == TIME_NIGHT){
             if (!actor->visible){
                 actor->visible = TRUE;
                 phase = get_moon_phase();
@@ -277,7 +282,7 @@ change_moon(Actor * actor, AWallpaperPlugin *desktop_plugin)
             fprintf(stderr, "destroy moon \n");
             destroy_hildon_actor(actor);
             /* TO DO make moonrise*/
-            actor->time_start_animation = get_next_sunset();
+            actor->time_start_animation = 0;
         } 
     }
     
@@ -289,11 +294,11 @@ change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
     double alt, azm;
     gint x, y;
 
+    //fprintf(stderr, "change sun\n");
     if (actor){
         if (scene.daytime != TIME_NIGHT){
             if (!actor->visible){
                 actor->visible = TRUE;
-
                 create_hildon_actor(actor, desktop_plugin);
             }
             get_sun_pos(&alt, &azm);
@@ -301,11 +306,12 @@ change_sun(Actor * actor, AWallpaperPlugin *desktop_plugin)
             actor->x = x;
             actor->y = y;
             actor_set_position_full(actor->widget, x, y, actor->z);
-            probability_sun(actor);
+            //probability_sun(actor);
+            actor->time_start_animation = time(NULL) + probability_sun();
          }else if (actor->visible){
             actor->visible = FALSE;
             destroy_hildon_actor(actor);
-            actor->time_start_animation = get_next_sunrise();
+            actor->time_start_animation = 0;
         } 
     }
     
@@ -496,7 +502,7 @@ change_cloud(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 + (fast_rnd(5) + 1)*60;
     }
 
 }
@@ -650,13 +656,6 @@ reload_scene(AWallpaperPlugin *desktop_plugin)
         init_scene1(desktop_plugin);
 }
 
-void 
-probability_sun(Actor *actor)
-{
-    actor->time_start_animation += 20 * 1;
-    actor->duration_animation = G_MAXINT;
-}
-
 
 /* Init Modern Scene */
 static void
@@ -728,7 +727,6 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   Actor *actor;
   gint now = time(NULL);
   
-  seed = time(NULL)%10;
 
   scene.daytime = get_daytime();
   scene.actors = NULL;
@@ -754,16 +752,17 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   scene.actors = g_slist_append(scene.actors, actor);
 
 
-  actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
-                      TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
-  change_static_actor(actor, desktop_plugin);
-  scene.actors = g_slist_append(scene.actors, actor);
-
   actor = init_object(desktop_plugin, "moon", "moon1.png", 400, 15, 6, 60, 60, 
                       FALSE, 100, 255, (gpointer)&change_moon, NULL);
   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), 11, 188, 75, 
+                      FALSE, 100, 255, (gpointer)&change_cloud, NULL);
+  actor->time_start_animation = now + fast_rnd(3) * 60;
+  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();
@@ -776,12 +775,12 @@ init_scene1(AWallpaperPlugin *desktop_plugin)
   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 = now + 5;
-  actor->duration_animation = 5*60;
+  actor = init_object(desktop_plugin, "town", "town.png", 0, 0, 10, 800, 480, 
+                      TRUE, 100, 255, (gpointer)&change_static_actor, NULL);
+  change_static_actor(actor, desktop_plugin);
   scene.actors = g_slist_append(scene.actors, actor);
 
+
 }
 
 
@@ -880,6 +879,7 @@ short_timeout (AWallpaperPlugin *desktop_plugin)
         return TRUE;
 
     now = time(NULL);
+    //scene.daytime = daytime;
     /* fprintf(stderr, "Short timer %d\n", now); */
     tmp = scene.actors;
     while (tmp != NULL){
@@ -895,7 +895,6 @@ short_timeout (AWallpaperPlugin *desktop_plugin)
             }
             tmp = g_slist_next(tmp);
     }
-    scene.daytime = daytime;
     if (stop_flag){
          desktop_plugin->priv->short_timer = 0;
          return FALSE;
@@ -907,46 +906,46 @@ short_timeout (AWallpaperPlugin *desktop_plugin)
 static gboolean
 long_timeout (AWallpaperPlugin *desktop_plugin)
 {
-      gint daytime = get_daytime();
-      GSList * tmp;
-      void (*pfunc)(gpointer, gpointer);
-      time_t now;
-      Actor *actor;
+    gint daytime = get_daytime();
+    GSList * tmp;
+    void (*pfunc)(gpointer, gpointer);
+    time_t now;
+    Actor *actor;
 
     /* TODO  remove timeout */
     if (!desktop_plugin->priv->visible)
         return TRUE;
-  //fprintf(stderr, "timer daytime=%d\n", daytime);
-  if (scene.daytime != daytime){
-      tmp = scene.actors;
-      while (tmp != NULL){
-          //change_actor(tmp->data);
-          pfunc =((Actor*)tmp->data)->func_change;
-          if (pfunc){
-              (*pfunc)(tmp->data, desktop_plugin);
-          }
-          tmp = g_slist_next(tmp);
-      }
-   }
+    //fprintf(stderr, "timer daytime=%d\n", daytime);
+    if (scene.daytime != daytime){
+        tmp = scene.actors;
+        while (tmp != NULL){
+            //change_actor(tmp->data);
+            pfunc =((Actor*)tmp->data)->func_change;
+            if (pfunc){
+                (*pfunc)(tmp->data, desktop_plugin);
+            }
+            tmp = g_slist_next(tmp);
+        }
+    }
    
-   now = time(NULL);
-//fprintf(stderr, "Now  %d\n", now);
-   tmp = scene.actors;
-   while (tmp != NULL){
-       actor = tmp->data;
-       if (now >= actor->time_start_animation  
-           && actor->time_start_animation > 0
-           && desktop_plugin->priv->short_timer == 0){
+    now = time(NULL);
+    //fprintf(stderr, "Now  %d\n", now);
+    tmp = scene.actors;
+    while (tmp != NULL){
+        actor = tmp->data;
+        if (now >= actor->time_start_animation  
+            && actor->time_start_animation > 0
+            && desktop_plugin->priv->short_timer == 0){
             actor->time_start_animation = now;
             /* fprintf(stderr, "start short timer act = %s %d\n", actor->name, now); */
             desktop_plugin->priv->short_timer = g_timeout_add(SHORT_TIMER, (GtkFunction)short_timeout, desktop_plugin);
         }
         tmp = g_slist_next(tmp);
-   }
+    }
    
- scene.daytime = daytime;
+    scene.daytime = daytime;
 
- return TRUE; /* keep running this event */
+    return TRUE; /* keep running this event */
 }
 
 static void
@@ -1002,6 +1001,10 @@ 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 0de61a3..2f83a9d 100644 (file)
@@ -77,6 +77,5 @@ static void init_scene(AWallpaperPlugin *desktop_plugin);
 static void init_scene1(AWallpaperPlugin *desktop_plugin);
 void create_hildon_actor(Actor *actor, AWallpaperPlugin *desktop_plugin);
 void get_sun_screen_pos(double alt, double azm, gint * x, gint * y);
-void probability_sun(Actor *actor);
 
 #endif
index daa6056..a8eeed2 100644 (file)
@@ -49,8 +49,15 @@ void get_localtime(int * year, int * month, int * day, int * hour, int * min, in
 
 void get_coord(double * lat, double * lon)
 {
-    *lat = 59.883333;
-    *lon = 30.25;
+    /* coordinates St.-Petersburg */
+    //*lat = 59.883333;
+    //*lon = 30.25;
+
+    /* coordinates Vitebsk */
+    *lat = 55.166666;
+    *lon = 30.133333;
+
+
 }
 
 double