Example #1
0
void prf_opensample(const char* name, const char* file, uint line)
{
    if (g_prf.samples_back == NULL)
        return;

    struct prf_samples* s = (struct prf_samples*)g_prf.samples_back;
    struct prf_node* n = prf_create_node(name, file, line, s->node_cur);

    /* save time */
    n->start_tick = timer_querytick();
    n->start_tm = timer_calctm(eng_get_framestats()->start_tick, n->start_tick)*1000.0;

    s->node_cur = n;
}
Example #2
0
void prf_closesample()
{
    if (g_prf.samples_back == NULL)
        return;

    struct prf_samples* s = (struct prf_samples*)g_prf.samples_back;
    struct prf_node* n = s->node_cur;
    ASSERT(n != NULL);

    /* calculate time elapsed since start_tick */
    n->tm = timer_calctm(n->start_tick, timer_querytick())*1000.0;

    /* go back to parent */
    s->node_cur = n->parent;
}
Example #3
0
void test_freelist()
{
    const uint item_cnt = 100000;
    const uint max_size = item_cnt * 1024;
    void** ptrs = (void**)ALLOC(item_cnt*sizeof(void*), 0);
    uint* h = (uint*)ALLOC(item_cnt*sizeof(uint), 0);
    size_t* sizes = (size_t*)ALLOC(item_cnt*sizeof(size_t), 0);

    uint free_cnt = 0;

    struct freelist_alloc freelist;
    struct allocator alloc;
    mem_freelist_create(mem_heap(), &freelist, max_size, 0);
    mem_freelist_bindalloc(&freelist, &alloc);

    uint64 t1 = timer_querytick();

    log_printf(LOG_TEXT, "allocating %d items from freelist (with hash validation)...", item_cnt);
    for (uint i = 0; i < item_cnt; i++)    {
        int s = rand_geti(8, 1024);
        ASSERT(s <= 1024);
        ptrs[i] = A_ALLOC(&alloc, s, 6);
        ASSERT(ptrs[i]);

        if (i > 0 && rand_flipcoin(50))  {
            uint idx_tofree = rand_geti(0, i-1);
            if (ptrs[idx_tofree] != NULL)   {
                A_FREE(&alloc, ptrs[idx_tofree]);
                ptrs[idx_tofree] = NULL;
            }
        }

        // random fill the buffer
        memset(ptrs[i], 0x00, s);

        h[i] = hash_murmur32(ptrs[i], s, 100);
        sizes[i] = s;
    }

    // check if the remaining buffers are untouched
    for (uint i = 0; i < item_cnt; i++)   {
        if (ptrs[i] != NULL)    {
#if defined(_DEBUG_)
            uint hh = hash_murmur32(ptrs[i], sizes[i], 100);
            ASSERT(h[i] == hh);
#endif
        }
    }

    for (uint i = 0; i < item_cnt; i++)   {
        //if (rand_flipcoin(50))  {
        if (ptrs[i] != NULL)    {
            A_FREE(&alloc, ptrs[i]);
            free_cnt ++;
            ptrs[i] = NULL;
        }
        //}
    }

    /* report leaks */
    uint leaks_cnt = mem_freelist_getleaks(&freelist, NULL);
    if (leaks_cnt > 0)
        log_printf(LOG_TEXT, "%d leaks found", leaks_cnt);

    mem_freelist_destroy(&freelist);
    log_print(LOG_TEXT, "done.");
    log_printf(LOG_TEXT, "took %f ms.",
        timer_calctm(t1, timer_querytick())*1000.0f);

    FREE(ptrs);
    FREE(h);
    FREE(sizes);
}
Example #4
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);
}