Example #1
0
AColMap* a_colmap_new(int Width, int Height, int MaxObjectDim)
{
    AColMap* const m = a_mem_malloc(sizeof(AColMap));

    #define nextpow(value)           \
    ({                               \
        int p = 0;                   \
        while((1 << p) < value) p++; \
        p;                           \
    })

    m->bitShift = nextpow(MaxObjectDim);
    m->w = 1 << a_math_max(0, nextpow(Width) - m->bitShift);
    m->h = 1 << a_math_max(0, nextpow(Height) - m->bitShift);

    m->submaps = a_mem_malloc(m->h * sizeof(AList**));

    for(int i = m->h; i--; ) {
        m->submaps[i] = a_mem_malloc(m->w * sizeof(AList*));

        for(int j = m->w; j--; ) {
            m->submaps[i][j] = a_list_new();
        }
    }

    return m;
}
Example #2
0
File: gui.c Project: alxm/inimaker
static void drawMenu(Menu* const m)
{
    a_pixel_setClip(false);

    const int h = a_sprite_h(sprites.menu[0]) + 2;
    int y = 4 + a_sprite_h(sprites.large) + 4;

    A_MENU_ITERATE(m, Item, item) {
        if(a_menu_isSelected(m, item)) {
            item->alpha = a_math_min(item->alpha + 32, 255);
        } else {
            item->alpha = a_math_max(item->alpha - 32, 0);
        }

        a_pixel_setBlend(A_PIXEL_PLAIN);
        a_blit(sprites.menu[0], 4, y);

        a_pixel_setBlend(A_PIXEL_RGBA);
        a_pixel_setAlpha(item->alpha);
        a_blit(sprites.menu[1], 4, y);

        a_pixel_setBlend(A_PIXEL_PLAIN);
        a_font_text(A_LEFT, 12, y + 5, fonts.whiteBold, item->text);

        y += h;
    }
}
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));
    }
}
void a_platform_api__drawVLine(int X, int Y1, int Y2)
{
    if(!a_screen_boxOnClip(X, Y1, 1, Y2 - Y1 + 1)) {
        return;
    }

    Y1 = a_math_max(Y1, a__screen.clipY);
    Y2 = a_math_min(Y2, a__screen.clipY2 - 1);

    g_draw_vline(X, Y1, Y2);
}
void a_platform_api__drawHLine(int X1, int X2, int Y)
{
    if(!a_screen_boxOnClip(X1, Y, X2 - X1 + 1, 1)) {
        return;
    }

    X1 = a_math_max(X1, a__screen.clipX);
    X2 = a_math_min(X2, a__screen.clipX2 - 1);

    g_draw_hline(X1, X2, Y);
}
static void drawRectangle(int X, int Y, int Width, int Height)
{
    if(a_screen_boxInsideClip(X, Y, Width, Height)) {
        g_draw_rectangle(X, Y, Width, Height);
        return;
    }

    if(!a_screen_boxOnClip(X, Y, Width, Height)) {
        return;
    }

    const int x2 = a_math_min(X + Width, a__screen.clipX2);
    const int y2 = a_math_min(Y + Height, a__screen.clipY2);

    X = a_math_max(X, a__screen.clipX);
    Y = a_math_max(Y, a__screen.clipY);
    Width = a_math_min(Width, x2 - X);
    Height = a_math_min(Height, y2 - Y);

    g_draw_rectangle(X, Y, Width, Height);
}