Beispiel #1
0
void gfx_step(void)
{
	int i;
	static int toogle=0;
	ALLEGRO_EVENT ev;

	for (i = 0; i < MOVE_FRAMES; i++) {
		do {
			al_wait_for_event(G.ev, &ev);
			switch (ev.type) {
			case ALLEGRO_EVENT_KEY_DOWN:
				if (toogle ^= 1) al_stop_timer(G.tick);
				else al_start_timer(G.tick);
				break;
			default:
				break;
			}
		} while (ev.type != ALLEGRO_EVENT_TIMER);
		gfx_render(i);
	}
}
Beispiel #2
0
void eng_update()
{
    /* variables for fps calculation */
    static float elapsed_tm = 0.0f;
    static uint frame_cnt = 0;
    static int simulated = FALSE;

    /* reset frame stack on start of each frame */
    struct allocator* tmp_alloc = tsk_get_tmpalloc(0);
    A_SAVE(tmp_alloc);

    uint64 start_tick = timer_querytick();
    g_eng->frame_stats.start_tick = start_tick;

    /* check for file changes (dev-mode) */
    if (BIT_CHECK(g_eng->params.flags, ENG_FLAG_DEV))
        fio_mon_update();

    /* update all timers */
    timer_update(start_tick);

    /* do all the work ... */
    float dt = g_eng->timer->dt;

    /* resource manager */
    rs_update();

    /* physics */
    if (!BIT_CHECK(g_eng->params.flags, ENG_FLAG_DISABLEPHX)) {
        if (simulated)
            phx_wait();
        phx_update_xforms(simulated);   /* gather results */
    }

    /* update scripting */
    sct_update();

    /* physics: run simulation */
    if (!BIT_CHECK(g_eng->params.flags, ENG_FLAG_DISABLEPHX))
        simulated = phx_update_sim(dt);

    /* update component system stages */
    PRF_OPENSAMPLE("Component (pre-render)");
    cmp_update(dt, CMP_UPDATE_STAGE1);
    cmp_update(dt, CMP_UPDATE_STAGE2);
    cmp_update(dt, CMP_UPDATE_STAGE3);
    cmp_update(dt, CMP_UPDATE_STAGE4);
    PRF_CLOSESAMPLE();

    /* cull and render active scene */
    PRF_OPENSAMPLE("Render");
    gfx_render();
    PRF_CLOSESAMPLE();

    PRF_OPENSAMPLE("Component (post-render)");
    cmp_update(dt, CMP_UPDATE_STAGE5);
    PRF_CLOSESAMPLE();

    /* clear update list of components */
    cmp_clear_updates();

    /* final frame stats calculation */
    fl64 ft = timer_calctm(start_tick, timer_querytick());
    if (g_eng->fps_lock > 0)  {
        fl64 target_ft = 1.0 / (fl64)g_eng->fps_lock;
        while (ft < target_ft)  {
            ft = timer_calctm(start_tick, timer_querytick());
        }
    }

#if defined(_PROFILE_)
    /* present samples in _PROFILE_ mode */
    prf_presentsamples(ft);
#endif

    g_eng->frame_stats.ft = (float)ft;
    g_eng->frame_stats.frame ++;
    frame_cnt ++;
    elapsed_tm += (float)ft;
    if (elapsed_tm > 1.0f)  {
        g_eng->frame_stats.fps = frame_cnt;
        frame_cnt = 0;
        elapsed_tm = 0.0f;
    }

    A_LOAD(tmp_alloc);
}