Exemple #1
0
int game_step(const float g[3], float dt)
{
    struct s_file *fp = &file;

    static float s = 0.f;
    static float t = 0.f;

    float d = 0.f;
    float b = 0.f;
    float st = 0.f;
    int i, n = 1, m = 0;

    s = (7.f * s + dt) / 8.f;
    t = s;

    if (jump_b)
    {
        jump_dt += dt;

        /* Handle a jump. */

        if (0.5 < jump_dt)
        {
            fp->uv[ball].p[0] = jump_p[0];
            fp->uv[ball].p[1] = jump_p[1];
            fp->uv[ball].p[2] = jump_p[2];
        }
        if (1.f < jump_dt)
            jump_b = 0;
    }
    else
    {
        /* Run the sim. */

        while (t > MAX_DT && n < MAX_DN)
        {
            t /= 2;
            n *= 2;
        }

        for (i = 0; i < n; i++)
        {
            d = sol_step(fp, g, t, ball, &m);

            if (b < d)
                b = d;
            if (m)
                st += t;
        }

        /* Mix the sound of a ball bounce. */

        if (b > 0.5)
            audio_play(AUD_BUMP, (float) (b - 0.5) * 2.0f);
    }

    game_update_view(dt);
    return game_update_state(st);
}
Exemple #2
0
static int game_step(const float g[3], float dt, int bt)
{
    if (server_state)
    {
        float h[3];

        /* Smooth jittery or discontinuous input. */

        tilt.rx += (input_get_x() - tilt.rx) * dt / input_get_s();
        tilt.rz += (input_get_z() - tilt.rz) * dt / input_get_s();

        game_tilt_axes(&tilt, view.e);

        game_cmd_tiltaxes();
        game_cmd_tiltangles();

        grow_step(&vary, dt);

        game_tilt_grav(h, g, &tilt);

        if (jump_b > 0)
        {
            jump_dt += dt;

            /* Handle a jump. */

            if (jump_dt >= 0.5f)
            {
                /* Translate view at the exact instant of the jump. */

                if (jump_b == 1)
                {
                    float dp[3];

                    v_sub(dp,     jump_p, vary.uv->p);
                    v_add(view.p, view.p, dp);

                    jump_b = 2;
                }

                /* Translate ball and hold it at the destination. */

                v_cpy(vary.uv->p, jump_p);
            }

            if (jump_dt >= 1.0f)
                jump_b = 0;
        }
        else
        {
            /* Run the sim. */

            float b = sol_step(&vary, h, dt, 0, NULL);

            /* Mix the sound of a ball bounce. */

            if (b > 0.5f)
            {
                float k = (b - 0.5f) * 2.0f;

                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);
                }
                else audio_play(AUD_BUMPM, k);
            }
        }

        game_cmd_updball();

        game_update_view(dt);
        game_update_time(dt, bt);

        return game_update_state(bt);
    }
    return GAME_NONE;
}
int game_step(const float g[3], float dt, int bt)
{
    struct s_file *fp = &file;

    float h[3];
    float d = 0.f;
    float b = 0.f;
    float t;
    int i, n = 1;

#ifdef REDUCE_PHYSICS
    static unsigned tn=0;
    tn++;
    sol_test_inc=((tn&1))+1;
    sol_test_inc2=((~tn&1))+1;
//    if ((tn&1))
//	sol_test_max=0.2333333f;
//    else
//	sol_test_max=0.3333333f;
#endif
    if (game_state)
    {
        t = dt;

        /* Smooth jittery or discontinuous input. */

        if (t < RESPONSE)
        {
            game_rx += (game_ix - game_rx) * t / RESPONSE;
            game_rz += (game_iz - game_rz) * t / RESPONSE;
        }
        else
        {
            game_rx = game_ix;
            game_rz = game_iz;
        }

        game_update_grav(h, g);
        part_step(h, t);

        if (jump_b)
        {
            jump_dt += t;

            /* Handle a jump. */

            if (0.5 < jump_dt)
            {
                fp->uv[0].p[0] = jump_p[0];
                fp->uv[0].p[1] = jump_p[1];
                fp->uv[0].p[2] = jump_p[2];
            }
            if (1.f < jump_dt)
                jump_b = 0;
        }
        else
        {
            /* Run the sim. */

            while (t > MAX_DT && n < MAX_DN)
            {
                t /= 2;
                n *= 2;
            }

            for (i = 0; i < n; i++)
                if (b < (d = sol_step(fp, h, t, 0, NULL)))
                    b = d;

            /* Mix the sound of a ball bounce. */

            if (b > 0.5)
                audio_play(AUD_BUMP, (b - 0.5f) * 2.0f);
        }

        game_step_fade(dt);
        game_update_view(dt);
        game_update_time(dt, bt);

        return game_update_state();
    }
    return GAME_NONE;
}