Pass the interpolation blend factor differently
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 11 Feb 2011 17:05:35 +0000 (17:05 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 11 Feb 2011 17:05:35 +0000 (17:05 +0000)
Rather than pass it to the draw function, make it a member of the lerp
structure and set it through a function call.  Doing it this way
eliminates a few ill defined cases: 1) transitions between screens
that use different blend factors; 2) screens that render game state
from either a replay or a simulation.

git-svn-id: https://s.snth.net/svn/neverball/trunk@3490 78b8d119-cf0a-0410-b17c-f493084dd1d7

12 files changed:
ball/game_client.c
ball/game_client.h
ball/game_draw.c
ball/game_draw.h
ball/set.c
ball/st_ball.c
ball/st_demo.c
ball/st_help.c
ball/st_level.c
ball/st_name.c
ball/st_play.c
ball/st_shared.c

index e857b31..9a9a5ad 100644 (file)
@@ -105,7 +105,7 @@ static void game_run_cmd(const union cmd *cmd)
             {
                 game_lerp_copy(&gl);
                 /* Hack to sync state before the next update. */
-                game_lerp_apply(&gl, &gd, 1.0f);
+                game_lerp_apply(&gl, &gd);
                 first_update = 0;
                 break;
             }
@@ -444,9 +444,14 @@ void game_client_free(void)
 
 /*---------------------------------------------------------------------------*/
 
-void game_client_draw(int pose, float t, float a)
+void game_client_blend(float a)
 {
-    game_lerp_apply(&gl, &gd, a);
+    gl.alpha = a;
+}
+
+void game_client_draw(int pose, float t)
+{
+    game_lerp_apply(&gl, &gd);
     game_draw(&gd, pose, t);
 }
 
index d3bca90..dea27af 100644 (file)
@@ -15,7 +15,8 @@ enum
 int   game_client_init(const char *);
 void  game_client_free(void);
 void  game_client_sync(fs_file);
-void  game_client_draw(int, float, float);
+void  game_client_draw(int, float);
+void  game_client_blend(float);
 
 int   curr_clock(void);
 int   curr_coins(void);
index f735cdf..157f698 100644 (file)
@@ -609,6 +609,8 @@ void game_draw(const struct game_draw *gd, int pose, float t)
 
 void game_lerp_init(struct game_lerp *gl, struct game_draw *gd)
 {
+    gl->alpha = 1.0f;
+
     sol_load_lerp(&gl->lerp, &gd->file.vary);
 
     gl->tilt[PREV] = gl->tilt[CURR] = gd->tilt;
@@ -634,8 +636,10 @@ void game_lerp_copy(struct game_lerp *gl)
     gl->jump_dt[PREV] = gl->jump_dt[CURR];
 }
 
-void game_lerp_apply(struct game_lerp *gl, struct game_draw *gd, float a)
+void game_lerp_apply(struct game_lerp *gl, struct game_draw *gd)
 {
+    float a = gl->alpha;
+
     /* Solid. */
 
     sol_lerp_apply(&gl->lerp, a);
index 5fcb4c6..397f23b 100644 (file)
@@ -36,6 +36,8 @@ void game_draw(const struct game_draw *, int, float);
 
 struct game_lerp
 {
+    float alpha;                        /* Interpolation factor              */
+
     struct s_lerp lerp;
 
     struct game_tilt tilt[2];
@@ -48,7 +50,7 @@ struct game_lerp
 void game_lerp_init(struct game_lerp *, struct game_draw *);
 void game_lerp_free(struct game_lerp *);
 void game_lerp_copy(struct game_lerp *);
-void game_lerp_apply(struct game_lerp *, struct game_draw *, float);
+void game_lerp_apply(struct game_lerp *, struct game_draw *);
 
 /*---------------------------------------------------------------------------*/
 
index f812d27..f641724 100644 (file)
@@ -503,7 +503,7 @@ void level_snap(int i, const char *path)
         video_clear();
         game_client_fly(1.0f);
         game_kill_fade();
-        game_client_draw(POSE_LEVEL, 0, 1.0f);
+        game_client_draw(POSE_LEVEL, 0);
         SDL_GL_SwapBuffers();
 
         image_snap(filename);
index 8691ba3..7daf590 100644 (file)
@@ -228,7 +228,7 @@ static void ball_paint(int id, float t)
     }
     video_pop_matrix();
 
-    game_client_draw(POSE_BALL, t, demo_play_blend());
+    game_client_draw(POSE_BALL, t);
     gui_paint(id);
 }
 
@@ -241,6 +241,8 @@ static void ball_timer(int id, float dt)
         demo_replay_stop(0);
         load_ball_demo();
     }
+
+    game_client_blend(demo_play_blend());
 }
 
 static int ball_buttn(int b, int d)
index 7e388dc..51a62df 100644 (file)
@@ -443,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, demo_play_blend());
+    game_client_draw(0, t);
 
     if (show_hud)
         hud_paint();
@@ -469,7 +469,10 @@ static void demo_play_timer(int id, float dt)
         goto_state(&st_demo_end);
     }
     else
+    {
         progress_step();
+        game_client_blend(demo_play_blend());
+    }
 }
 
 static void set_speed(int d)
@@ -621,7 +624,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, demo_play_blend());
+    game_client_draw(0, t);
     gui_paint(id);
 
     if (demo_paused)
index 14d1f65..39abc4e 100644 (file)
@@ -385,7 +385,7 @@ static void help_demo_leave(struct state *st, struct state *next, int id)
 
 static void help_demo_paint(int id, float t)
 {
-    game_client_draw(0, t, demo_play_blend());
+    game_client_draw(0, t);
 }
 
 static void help_demo_timer(int id, float dt)
@@ -394,6 +394,8 @@ static void help_demo_timer(int id, float dt)
 
     if (!demo_replay_step(dt))
         goto_state(&st_help);
+
+    game_client_blend(demo_play_blend());
 }
 
 static int help_demo_buttn(int b, int d)
index 64fc1b4..a83c6a4 100644 (file)
@@ -136,7 +136,7 @@ static int level_buttn(int b, int d)
 
 static void poser_paint(int id, float t)
 {
-    game_client_draw(POSE_LEVEL, t, 1.0f);
+    game_client_draw(POSE_LEVEL, t);
 }
 
 static int poser_buttn(int c, int d)
index 2e5ba1b..e71dc21 100644 (file)
@@ -157,7 +157,7 @@ static void name_paint(int id, float t)
         video_pop_matrix();
     }
     else
-        game_client_draw(0, t, 1.0f);
+        game_client_draw(0, t);
 
     gui_paint(id);
 }
index 3c180a4..6fe1a5d 100644 (file)
@@ -134,7 +134,7 @@ static int play_ready_enter(struct state *st, struct state *prev)
 
 static void play_ready_paint(int id, float t)
 {
-    game_client_draw(0, t, 1.0f);
+    game_client_draw(0, t);
     hud_view_paint();
     gui_paint(id);
 }
@@ -215,7 +215,7 @@ static int play_set_enter(struct state *st, struct state *prev)
 
 static void play_set_paint(int id, float t)
 {
-    game_client_draw(0, t, 1.0f);
+    game_client_draw(0, t);
     hud_view_paint();
     gui_paint(id);
 }
@@ -333,7 +333,7 @@ static int play_loop_enter(struct state *st, struct state *prev)
 
 static void play_loop_paint(int id, float t)
 {
-    game_client_draw(0, t, game_server_blend());
+    game_client_draw(0, t);
 
     if (show_hud)
         hud_paint();
@@ -359,6 +359,7 @@ static void play_loop_timer(int id, float dt)
 
     game_server_step(dt);
     game_client_sync(demo_fp);
+    game_client_blend(game_server_blend());
 
     switch (curr_status())
     {
@@ -518,7 +519,7 @@ static void look_leave(struct state *st, struct state *next, int id)
 
 static void look_paint(int id, float t)
 {
-    game_client_draw(0, t, 1.0f);
+    game_client_draw(0, t);
 }
 
 static void look_point(int id, int x, int y, int dx, int dy)
index b21478e..c6fa4ca 100644 (file)
@@ -30,7 +30,7 @@ void shared_leave(struct state *st, struct state *next, int id)
 
 void shared_paint(int id, float t)
 {
-    game_client_draw(0, t, 1.0f);
+    game_client_draw(0, t);
     gui_paint(id);
 }