Minor simplification of code in date_to_str().
[neverball] / ball / st_demo.c
index d50324b..fe49041 100644 (file)
@@ -62,7 +62,7 @@ static int demo_action(int i)
         break;
 
     default:
-        if (level_replay(get_demo(i)->filename))
+        if (level_replay(demo_get(i)->filename))
             demo_play_goto(0);
             return goto_state(&st_demo_play);
     }
@@ -80,10 +80,10 @@ static void demo_replay(int id, int i)
     if ((jd = gui_vstack(id)))
     {
         gui_space(jd);
+        gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
 
-        gui_image(jd, get_demo(i)->shot, w / 6, h / 6);
         nam[MAXNAM - 1] = '\0';
-        strncpy(nam, get_demo(i)->name, MAXNAM);
+        strncpy(nam, demo_get(i)->name, MAXNAM);
         if (nam[MAXNAM - 1] != '\0')
         {
             nam[MAXNAM - 2] = '.';
@@ -208,7 +208,7 @@ static int gui_demo_status(int id, const struct demo *d)
 
 static void gui_demo_update_status(int i)
 {
-    const struct demo *d = get_demo(i);
+    const struct demo *d = demo_get(i);
 
     gui_set_label(name_id,   d->name);
     gui_set_label(date_id,   date_to_str(d->date));
@@ -284,6 +284,7 @@ static void demo_stick(int id, int a, int v)
 {
     int jd = shared_stick_basic(id, a, v);
     int i  = gui_token(jd);
+
     if (jd && i >= 0)
         gui_demo_update_status(i);
 }
@@ -302,7 +303,7 @@ static int demo_buttn(int b, int d)
 
 /*---------------------------------------------------------------------------*/
 
-static int simple_play;
+static int simple_play; /* play demo from command line */
 
 void demo_play_goto(int simple)
 {
@@ -443,12 +444,33 @@ static int demo_end_enter(void)
 
 static void demo_end_timer(int id, float dt)
 {
+    float t;
     float gg[3] = { 0.0f,  9.8f, 0.0f };
     float gf[3] = { 0.0f, -9.8f, 0.0f };
     int state = curr_demo_replay()->state;
 
-    if (time_state() < 2.f && state != GAME_NONE)
-        game_step((state == GAME_GOAL || state == GAME_SPEC) ? gg : gf, dt, NULL);
+    if (time_state() < 2.f)
+    {
+        /* Continue demo in background for 2 seconds */
+        if (replay_time < global_time)
+        {
+            /* The demo is finished, let the ball go */
+            if (state != GAME_NONE)
+                game_step((state == GAME_GOAL || state == GAME_SPEC) ? gg : gf,
+                          dt, NULL);
+        }
+        else
+        {
+            /* The demo is not finished, play it */
+            global_time += dt;
+
+            while (replay_time < global_time)
+                if (demo_replay_step(&t))
+                    replay_time += t;
+                else
+                    break;
+        }
+    }
 
     gui_timer(id, dt);
     audio_timer(dt);