示例#1
0
文件: gui.c 项目: alxm/inimaker
void gui_consoleLine(const int font, const char* const text)
{
    printf("%s\n", text);

    Line* const line = malloc(sizeof(Line));

    line->font = font;
    line->text = a_str_dup(text);

    a_list_addLast(lines, line);

    if(a_list_size(lines) > CONSOLE_LINES) {
        free(a_list_pop(lines));
    }

    gui_draw(NULL);
    a_screen_show();
}
void a_fps_end(void)
{
    counter++;

    a_screen_show();

    const bool track = a2x_bool("trackFps");
    const bool done = a_timer_check(timer);

    if(track) {
        maxBuffer[BUFFER_SIZE - 1] = a_timer_diff(timer);
    } else {
        max = 1000 / a_math_max(1, a_timer_diff(timer));
    }

    if(!done) {
        while(!a_timer_check(timer)) {
            if(milisPerFrame - a_timer_diff(timer) >= 10) {
                a_time_waitMilis(10);
            }
        }
    }

    if(track) {
        uint32_t f = 0;
        uint32_t m = 0;

        for(int i = BUFFER_SIZE; i--; ) {
            f += fpsBuffer[i];
            m += maxBuffer[i];
        }

        fps = 1000 / ((float)f / BUFFER_SIZE);
        max = 1000 / ((float)m / BUFFER_SIZE);

        memmove(fpsBuffer, &fpsBuffer[1], (BUFFER_SIZE - 1) * sizeof(uint32_t));
        memmove(maxBuffer, &maxBuffer[1], (BUFFER_SIZE - 1) * sizeof(uint32_t));

        fpsBuffer[BUFFER_SIZE - 1] = a_timer_diff(timer);
    } else {
        fps = 1000 / a_math_max(1, a_timer_diff(timer));
    }
}
示例#3
0
void a_fps_frame(void)
{
    if(a_fps_notSkipped()) {
        a_screen_show();

        const bool done = a_timer_expired(g_timer);
        const uint32_t elapsedMs = a_timer_elapsed(g_timer);

        if(elapsedMs > 0) {
            g_maxFpsBufferSum -= g_maxFpsBuffer[g_bufferHead];
            g_maxFpsBuffer[g_bufferHead] = 1000 / elapsedMs;
            g_maxFpsBufferSum += g_maxFpsBuffer[g_bufferHead];
            g_maxFps = g_maxFpsBufferSum / g_bufferLen;
        }

        if(!done) {
            while(!a_timer_expired(g_timer)) {
                if(!g_canSleep) {
                    continue;
                }

                const uint32_t waitMs = g_msPerFrame - a_timer_elapsed(g_timer);

                #if A_PLATFORM_GP2X
                    // GP2X timer granularity is too coarse
                    if(waitMs >= 10) {
                        a_time_waitMs(10);
                    }
                #else
                    a_time_waitMs(waitMs);
                #endif
            }
        }

        g_fpsBufferSum -= g_fpsBuffer[g_bufferHead];
        g_fpsBuffer[g_bufferHead] = 1000 / a_timer_elapsed(g_timer);
        g_fpsBufferSum += g_fpsBuffer[g_bufferHead];
        g_fps = g_fpsBufferSum / g_bufferLen;

        g_bufferHead = (g_bufferHead + 1) % g_bufferLen;
    }

    a_input__get();
    g_frameCounter++;

    if(g_skipFrames) {
        if(a_fps_notSkipped() && a_timer_expired(g_skipAdjustTimer)) {
            int newFrameSkip = -1;

            if(g_maxFps <= g_fpsThresholdSlow && g_skipNum < g_skipMax) {
                newFrameSkip = g_skipNum + 1;
            } else if(g_maxFps >= g_fpsThresholdFast && g_skipNum > 0) {
                newFrameSkip = g_skipNum - 1;
            }

            if(newFrameSkip != -1) {
                if(newFrameSkip == 0) {
                    a_timer_start(g_noSleepTimer);
                } else {
                    a_timer_stop(g_noSleepTimer);
                }

                g_canSleep = false;
                a_fps__reset(newFrameSkip);
            } else if(!g_canSleep && a_timer_expired(g_noSleepTimer)) {
                g_canSleep = true;
            }
        }

        if(g_skipCounter++ == g_skipNum) {
            g_skipCounter = 0;
        }
    }
}