Implement game state interpolation (WIP)
[neverball] / ball / st_demo.c
index 045c104..7e388dc 100644 (file)
 #include "demo.h"
 #include "progress.h"
 #include "audio.h"
-#include "solid.h"
 #include "config.h"
-#include "st_shared.h"
 #include "util.h"
 #include "common.h"
 #include "demo_dir.h"
+#include "speed.h"
 
 #include "game_common.h"
 #include "game_server.h"
@@ -33,6 +32,7 @@
 
 #include "st_demo.h"
 #include "st_title.h"
+#include "st_shared.h"
 
 /*---------------------------------------------------------------------------*/
 
@@ -357,9 +357,9 @@ static void demo_point(int id, int x, int y, int dx, int dy)
         gui_demo_update_status(i);
 }
 
-static void demo_stick(int id, int a, float v)
+static void demo_stick(int id, int a, float v, int bump)
 {
-    int jd = shared_stick_basic(id, a, v);
+    int jd = shared_stick_basic(id, a, v, bump);
     int i  = gui_token(jd);
 
     if (jd && i >= 0 && !GUI_ISMSK(i))
@@ -384,6 +384,7 @@ static int standalone;
 static int demo_paused;
 static int show_hud;
 static int check_compat;
+static int speed;
 
 static float prelude;
 
@@ -431,6 +432,9 @@ static int demo_play_enter(struct state *st, struct state *prev)
 
     prelude = 1.0f;
 
+    speed = SPEED_NORMAL;
+    demo_speed_set(speed);
+
     show_hud = 1;
     hud_update(0);
 
@@ -439,7 +443,7 @@ static int demo_play_enter(struct state *st, struct state *prev)
 
 static void demo_play_paint(int id, float t)
 {
-    game_client_draw(0, t);
+    game_client_draw(0, t, demo_play_blend());
 
     if (show_hud)
         hud_paint();
@@ -468,6 +472,38 @@ static void demo_play_timer(int id, float dt)
         progress_step();
 }
 
+static void set_speed(int d)
+{
+    if (d > 0) speed = SPEED_UP(speed);
+    if (d < 0) speed = SPEED_DN(speed);
+
+    demo_speed_set(speed);
+    hud_speed_pulse(speed);
+}
+
+static void demo_play_stick(int id, int a, float v, int bump)
+{
+    if (!bump)
+        return;
+
+    if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
+    {
+        if (v < 0) set_speed(+1);
+        if (v > 0) set_speed(-1);
+    }
+}
+
+static int demo_play_click(int b, int d)
+{
+    if (d)
+    {
+        if (b == SDL_BUTTON_WHEELUP)   set_speed(+1);
+        if (b == SDL_BUTTON_WHEELDOWN) set_speed(-1);
+    }
+
+    return 1;
+}
+
 static int demo_play_keybd(int c, int d)
 {
     if (d)
@@ -585,7 +621,7 @@ static int demo_end_enter(struct state *st, struct state *prev)
 
 static void demo_end_paint(int id, float t)
 {
-    game_client_draw(0, t);
+    game_client_draw(0, t, demo_play_blend());
     gui_paint(id);
 
     if (demo_paused)
@@ -727,8 +763,7 @@ struct state st_demo = {
     shared_angle,
     shared_click,
     NULL,
-    demo_buttn,
-    1, 0
+    demo_buttn
 };
 
 struct state st_demo_play = {
@@ -737,12 +772,11 @@ struct state st_demo_play = {
     demo_play_paint,
     demo_play_timer,
     NULL,
+    demo_play_stick,
     NULL,
-    NULL,
-    NULL,
+    demo_play_click,
     demo_play_keybd,
-    demo_play_buttn,
-    1, 0
+    demo_play_buttn
 };
 
 struct state st_demo_end = {
@@ -755,8 +789,7 @@ struct state st_demo_end = {
     shared_angle,
     shared_click,
     demo_end_keybd,
-    demo_end_buttn,
-    1, 0
+    demo_end_buttn
 };
 
 struct state st_demo_del = {
@@ -769,8 +802,7 @@ struct state st_demo_del = {
     shared_angle,
     shared_click,
     NULL,
-    demo_del_buttn,
-    1, 0
+    demo_del_buttn
 };
 
 struct state st_demo_compat = {
@@ -783,6 +815,5 @@ struct state st_demo_compat = {
     shared_angle,
     shared_click,
     NULL,
-    demo_compat_buttn,
-    1, 0
+    demo_compat_buttn
 };