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? */
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);
}
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);
}
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);
}
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;
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);
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. */
if (server_state)
{
sol_quit_sim();
- sol_free_vary(&file);
+
+ sol_free_vary(&vary);
sol_free_base(&base);
+
server_state = 0;
}
}
/* 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())
{
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. */
static int game_update_state(int bt)
{
- struct s_vary *vary = &file;
struct b_goal *zp;
int hi;
/* 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)
{
/* 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;
/* 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;
/* 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;
{
if (server_state)
{
- struct s_vary *vary = &file;
-
float h[3];
/* Smooth jittery or discontinuous input. */
game_cmd_tiltaxes();
game_cmd_tiltangles();
- grow_step(vary, dt);
+ grow_step(&vary, dt);
game_tilt_grav(h, g, &tilt);
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)
{
/* 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. */
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);
}
game_cmd_goalopen();
}
-void game_clr_goal(void)
-{
- goal_e = 0;
-}
-
/*---------------------------------------------------------------------------*/
void game_set_x(float k)
input_set_r(r);
}
-void game_server_fly(float k)
-{
- game_view_fly(&view, &file, k);
- game_cmd_updview();
-}
-
/*---------------------------------------------------------------------------*/