Random cleanup
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Thu, 17 Feb 2011 10:43:11 +0000 (10:43 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Thu, 17 Feb 2011 10:43:11 +0000 (10:43 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@3499 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/game_server.c
ball/game_server.h

index 0516f3f..9e5cc65 100644 (file)
@@ -37,7 +37,7 @@
 static int server_state = 0;
 
 static struct s_base base;
-static struct s_vary file;
+static struct s_vary vary;
 
 static float timer      = 0.f;          /* Clock time                        */
 static int   timer_down = 1;            /* Timer go up or down?              */
@@ -185,17 +185,17 @@ static void game_cmd_goalopen(void)
 static void game_cmd_updball(void)
 {
     cmd.type = CMD_BALL_POSITION;
-    v_cpy(cmd.ballpos.p, file.uv[0].p);
+    v_cpy(cmd.ballpos.p, vary.uv[0].p);
     game_proxy_enq(&cmd);
 
     cmd.type = CMD_BALL_BASIS;
-    v_cpy(cmd.ballbasis.e[0], file.uv[0].e[0]);
-    v_cpy(cmd.ballbasis.e[1], file.uv[0].e[1]);
+    v_cpy(cmd.ballbasis.e[0], vary.uv[0].e[0]);
+    v_cpy(cmd.ballbasis.e[1], vary.uv[0].e[1]);
     game_proxy_enq(&cmd);
 
     cmd.type = CMD_BALL_PEND_BASIS;
-    v_cpy(cmd.ballpendbasis.E[0], file.uv[0].E[0]);
-    v_cpy(cmd.ballpendbasis.E[1], file.uv[0].E[1]);
+    v_cpy(cmd.ballpendbasis.E[0], vary.uv[0].E[0]);
+    v_cpy(cmd.ballpendbasis.E[1], vary.uv[0].E[1]);
     game_proxy_enq(&cmd);
 }
 
@@ -218,7 +218,7 @@ static void game_cmd_updview(void)
 static void game_cmd_ballradius(void)
 {
     cmd.type         = CMD_BALL_RADIUS;
-    cmd.ballradius.r = file.uv[0].r;
+    cmd.ballradius.r = vary.uv[0].r;
     game_proxy_enq(&cmd);
 }
 
@@ -241,14 +241,14 @@ static void game_cmd_init_items(void)
     cmd.type = CMD_CLEAR_ITEMS;
     game_proxy_enq(&cmd);
 
-    for (i = 0; i < file.hc; i++)
+    for (i = 0; i < vary.hc; i++)
     {
         cmd.type = CMD_MAKE_ITEM;
 
-        v_cpy(cmd.mkitem.p, file.hv[i].p);
+        v_cpy(cmd.mkitem.p, vary.hv[i].p);
 
-        cmd.mkitem.t = file.hv[i].t;
-        cmd.mkitem.n = file.hv[i].n;
+        cmd.mkitem.t = vary.hv[i].t;
+        cmd.mkitem.n = vary.hv[i].n;
 
         game_proxy_enq(&cmd);
     }
@@ -421,11 +421,7 @@ static struct lockstep server_step;
 
 int game_server_init(const char *file_name, int t, int e)
 {
-    struct
-    {
-        int x, y;
-    } version;
-
+    struct { int x, y; } version;
     int i;
 
     timer      = (float) t / 100.f;
@@ -436,21 +432,28 @@ int game_server_init(const char *file_name, int t, int e)
     if (server_state)
         game_server_free();
 
+    /* Load SOL data. */
+
     if (!sol_load_base(&base, file_name))
         return (server_state = 0);
 
-    if (!sol_load_vary(&file, &base))
+    if (!sol_load_vary(&vary, &base))
+    {
+        sol_free_base(&base);
         return (server_state = 0);
+    }
 
     server_state = 1;
 
+    /* Get SOL version. */
+
     version.x = 0;
     version.y = 0;
 
-    for (i = 0; i < file.base->dc; i++)
+    for (i = 0; i < base.dc; i++)
     {
-        char *k = file.base->av + file.base->dv[i].ai;
-        char *v = file.base->av + file.base->dv[i].aj;
+        char *k = base.av + base.dv[i].ai;
+        char *v = base.av + base.dv[i].aj;
 
         if (strcmp(k, "version") == 0)
             sscanf(v, "%d.%d", &version.x, &version.y);
@@ -468,40 +471,34 @@ int game_server_init(const char *file_name, int t, int e)
     goal_e = e ? 1    : 0;
     goal_k = e ? 1.0f : 0.0f;
 
-    /* Initialize the view. */
-
-    game_view_init(&view);
+    /* Initialize the view (and put it at the ball). */
 
+    game_view_fly(&view, &vary, 0.0f);
     view_k = 1.0f;
 
-    /* Initialize ball size tracking... */
+    /* Initialize ball size tracking. */
 
     got_orig = 0;
     grow = 0;
 
     /* Initialize simulation. */
 
-    sol_init_sim(&file);
-
+    sol_init_sim(&vary);
     sol_cmd_enq_func(game_proxy_enq);
 
-    /* Queue client commands. */
+    /* Send initial update. */
 
     game_cmd_map(file_name, version.x, version.y);
     game_cmd_ups();
     game_cmd_timer();
 
-    if (goal_e) game_cmd_goalopen();
+    if (goal_e)
+        game_cmd_goalopen();
 
     game_cmd_init_balls();
     game_cmd_init_items();
 
-    /* Store the initial view. */
-
-    game_server_fly(0.0f);
-
-    /* End first update. */
-
+    game_cmd_updview();
     game_cmd_eou();
 
     /* Reset lockstep state. */
@@ -516,8 +513,10 @@ void game_server_free(void)
     if (server_state)
     {
         sol_quit_sim();
-        sol_free_vary(&file);
+
+        sol_free_vary(&vary);
         sol_free_base(&base);
+
         server_state = 0;
     }
 }
@@ -535,11 +534,11 @@ static void game_update_view(float dt)
 
     /* Center the view about the ball. */
 
-    v_cpy(view.c, file.uv->p);
+    v_cpy(view.c, vary.uv->p);
 
-    view_v[0] = -file.uv->v[0];
+    view_v[0] = -vary.uv->v[0];
     view_v[1] =  0.0f;
-    view_v[2] = -file.uv->v[2];
+    view_v[2] = -vary.uv->v[2];
 
     switch (input_get_c())
     {
@@ -589,11 +588,11 @@ static void game_update_view(float dt)
 
     v_scl(v,    view.e[1], view.dp * view_k);
     v_mad(v, v, view.e[2], view.dz * view_k);
-    v_add(view.p, v, file.uv->p);
+    v_add(view.p, v, vary.uv->p);
 
     /* Compute the new view center. */
 
-    v_cpy(view.c, file.uv->p);
+    v_cpy(view.c, vary.uv->p);
     v_mad(view.c, view.c, view.e[1], dc);
 
     /* Note the current view angle. */
@@ -627,7 +626,6 @@ static void game_update_time(float dt, int b)
 
 static int game_update_state(int bt)
 {
-    struct s_vary *vary = &file;
     struct b_goal *zp;
     int hi;
 
@@ -635,13 +633,13 @@ static int game_update_state(int bt)
 
     /* Test for an item. */
 
-    if (bt && (hi = sol_item_test(vary, p, ITEM_RADIUS)) != -1)
+    if (bt && (hi = sol_item_test(&vary, p, ITEM_RADIUS)) != -1)
     {
-        struct v_item *hp = file.hv + hi;
+        struct v_item *hp = vary.hv + hi;
 
         game_cmd_pkitem(hi);
 
-        grow_init(vary, hp->t);
+        grow_init(&vary, hp->t);
 
         if (hp->t == ITEM_COIN)
         {
@@ -658,26 +656,26 @@ static int game_update_state(int bt)
 
     /* Test for a switch. */
 
-    if (sol_swch_test(vary, 0) == SWCH_TRIGGER)
+    if (sol_swch_test(&vary, 0) == SWCH_TRIGGER)
         audio_play(AUD_SWITCH, 1.f);
 
     /* Test for a jump. */
 
-    if (jump_e == 1 && jump_b == 0 && (sol_jump_test(vary, jump_p, 0) ==
+    if (jump_e == 1 && jump_b == 0 && (sol_jump_test(&vary, jump_p, 0) ==
                                        JUMP_TRIGGER))
     {
         jump_b  = 1;
         jump_e  = 0;
         jump_dt = 0.f;
 
-        v_sub(jump_w, jump_p, vary->uv->p);
+        v_sub(jump_w, jump_p, vary.uv->p);
         v_add(jump_w, view.p, jump_w);
 
         audio_play(AUD_JUMP, 1.f);
 
         game_cmd_jump(1);
     }
-    if (jump_e == 0 && jump_b == 0 && (sol_jump_test(vary, jump_p, 0) ==
+    if (jump_e == 0 && jump_b == 0 && (sol_jump_test(&vary, jump_p, 0) ==
                                        JUMP_OUTSIDE))
     {
         jump_e = 1;
@@ -686,7 +684,7 @@ static int game_update_state(int bt)
 
     /* Test for a goal. */
 
-    if (bt && goal_e && (zp = sol_goal_test(vary, p, 0)))
+    if (bt && goal_e && (zp = sol_goal_test(&vary, p, 0)))
     {
         audio_play(AUD_GOAL, 1.0f);
         return GAME_GOAL;
@@ -702,7 +700,7 @@ static int game_update_state(int bt)
 
     /* Test for fall-out. */
 
-    if (bt && vary->uv[0].p[1] < vary->base->vv[0].p[1])
+    if (bt && vary.uv[0].p[1] < base.vv[0].p[1])
     {
         audio_play(AUD_FALL, 1.0f);
         return GAME_FALL;
@@ -715,8 +713,6 @@ static int game_step(const float g[3], float dt, int bt)
 {
     if (server_state)
     {
-        struct s_vary *vary = &file;
-
         float h[3];
 
         /* Smooth jittery or discontinuous input. */
@@ -729,7 +725,7 @@ static int game_step(const float g[3], float dt, int bt)
         game_cmd_tiltaxes();
         game_cmd_tiltangles();
 
-        grow_step(vary, dt);
+        grow_step(&vary, dt);
 
         game_tilt_grav(h, g, &tilt);
 
@@ -741,7 +737,7 @@ static int game_step(const float g[3], float dt, int bt)
 
             if (0.5f < jump_dt)
             {
-                v_cpy(vary->uv->p, jump_p);
+                v_cpy(vary.uv->p, jump_p);
                 v_cpy(view.p,      jump_w);
             }
             if (1.0f < jump_dt)
@@ -751,7 +747,7 @@ static int game_step(const float g[3], float dt, int bt)
         {
             /* Run the sim. */
 
-            float b = sol_step(vary, h, dt, 0, NULL);
+            float b = sol_step(&vary, h, dt, 0, NULL);
 
             /* Mix the sound of a ball bounce. */
 
@@ -761,9 +757,9 @@ static int game_step(const float g[3], float dt, int bt)
 
                 if (got_orig)
                 {
-                    if      (vary->uv->r > grow_orig) audio_play(AUD_BUMPL, k);
-                    else if (vary->uv->r < grow_orig) audio_play(AUD_BUMPS, k);
-                    else                              audio_play(AUD_BUMPM, k);
+                    if      (vary.uv->r > grow_orig) audio_play(AUD_BUMPL, k);
+                    else if (vary.uv->r < grow_orig) audio_play(AUD_BUMPS, k);
+                    else                             audio_play(AUD_BUMPM, k);
                 }
                 else audio_play(AUD_BUMPM, k);
             }
@@ -817,11 +813,6 @@ void game_set_goal(void)
     game_cmd_goalopen();
 }
 
-void game_clr_goal(void)
-{
-    goal_e = 0;
-}
-
 /*---------------------------------------------------------------------------*/
 
 void game_set_x(float k)
@@ -858,10 +849,4 @@ void game_set_rot(float r)
     input_set_r(r);
 }
 
-void game_server_fly(float k)
-{
-    game_view_fly(&view, &file, k);
-    game_cmd_updview();
-}
-
 /*---------------------------------------------------------------------------*/
index 1621d36..01d5625 100644 (file)
@@ -15,7 +15,6 @@ void  game_server_step(float);
 float game_server_blend(void);
 
 void  game_set_goal(void);
-void  game_clr_goal(void);
 
 void  game_set_ang(int, int);
 void  game_set_pos(int, int);
@@ -24,8 +23,6 @@ void  game_set_z  (float);
 void  game_set_cam(int);
 void  game_set_rot(float);
 
-void game_server_fly(float);
-
 /*---------------------------------------------------------------------------*/
 
 #endif