Пример #1
0
bool pump::process() {
    SDL_Event event;
    while(!killed_ && SDL_PollEvent(&event)) {
        bool claimed = false;

        switch(event.type) {
        case SDL_QUIT:
            killed_ = true;
            claimed = true;
            SDL_PushEvent(&event);
            break;

#if defined(__ANDROID__) && !SDL_VERSION_ATLEAST(2, 0, 0)
        case SDL_VIDEORESIZE:
            // Allow restore from app going to the background on android, while a modal dialog is up.
            video_resize( event );
            break;
#endif

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE || (defined(__ANDROID__) && SDL_VERSION_ATLEAST(2, 0, 0))
        case SDL_WINDOWEVENT:
            if (event.window.event == SDL_WINDOWEVENT_MINIMIZED)
            {
                SDL_Event e;
                while (SDL_WaitEvent(&e))
                {
                    if (e.type == SDL_WINDOWEVENT && e.window.event == SDL_WINDOWEVENT_RESTORED)
                        break;
                }
            }
            break;
#endif
        case SDL_USEREVENT:
            if(event.user.code == ST_EVENT_NESTED_DEATH) {
                reset();
                continue;
            }
            break;
        default:
            break;
        }
        claimed = process_event(event, claimed);
    }

    return !killed_;
}
Пример #2
0
int main(int argc, char *argv[])
{
    SDL_Event event;

    atexit(main_exit);

    process_configfile();
    process_options(argc, argv);

    // use g_nports if specified, otherwise use the number of port arguments.
    // if neither is given, create just one port
    int nportargs = argc - optind;
    g_nports = max(1, g_nports ? : nportargs);

    // now that we know the actual number of ports, repeat the last color/scale/height value
    // as often as necessary
    if (g_colors) {
        g_colors = (Uint32*)realloc(g_colors, g_nports * sizeof(Uint32));
        for (int n = ncolors; n < g_nports; ++n) {
            g_colors[n] = g_colors[ncolors - 1];
        }
    }

    if (g_scales) {
        g_scales = (float*)realloc(g_scales, g_nports * sizeof(float));
        for (int n = nscales; n < g_nports; ++n) {
            g_scales[n] = g_scales[nscales - 1];
        }
    }

    if (g_heights) {
        g_heights = (int*)realloc(g_heights, g_nports * sizeof(int));
        for (int n = nheights; n < g_nports; ++n) {
            g_heights[n] = g_heights[nheights - 1];
        }
        // g_heights overrides g_height
        g_height = 0;
        for (int n = 0; n < g_nports; ++n) {
            g_height += g_heights[n];
        }
        g_total_height = g_height;
    }


    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "can't init SDL: %s\n", SDL_GetError());
        exit(EXIT_FAILURE);
    }
    atexit(SDL_Quit);

    audio_init(g_client_name, (const char * const *)&argv[optind]);

    video_init();
    SDL_WM_SetCaption(audio_get_client_name(), NULL);

    waves_init();

    g_run = true;

    while (g_run)
    {
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_VIDEORESIZE:
                    video_resize(event.resize.w, event.resize.h);
                    audio_adjust();
                    waves_adjust();
                    break;
                case SDL_QUIT:
                    g_run = false;
                    break;
            }
        }

        waves_draw();
        video_flip();
    }

    return 0;
}