コード例 #1
0
ファイル: event.c プロジェクト: paud/d2x-xl
void event_poll(Uint32 mask)
{
	SDL_Event event;
#if TO_EVENT_POLL
	time_t t0 = SDL_GetTicks ();
	time_t _t = t0;
#endif

/*
	if (!mask)
		mask = SDL_ALLEVENTS;
	else
		mask |= SDL_ACTIVEEVENTMASK | SDL_QUITMASK | SDL_SYSWMEVENTMASK;
	while (PollEvent(&event, mask)) {
*/
	while (SDL_PollEvent (&event)) {
#if TO_EVENT_POLL
		if (!gameOpts->legacy.bInput)
			_t = SDL_GetTicks ();
#endif
		switch(event.type) {
			case SDL_KEYDOWN:
				key_handler((SDL_KeyboardEvent *)&event);
				break;
			case SDL_KEYUP:
				key_handler((SDL_KeyboardEvent *)&event);
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				mouse_button_handler((SDL_MouseButtonEvent *)&event);
				break;
			case SDL_MOUSEMOTION:
				mouse_motion_handler((SDL_MouseMotionEvent *)&event);
				break;
#ifndef USE_LINUX_JOY       // stpohle - so we can choose at compile time..
			case SDL_JOYBUTTONDOWN:
			case SDL_JOYBUTTONUP:
				joy_button_handler((SDL_JoyButtonEvent *)&event);
				break;
			case SDL_JOYAXISMOTION:
				joy_axis_handler((SDL_JoyAxisEvent *)&event);
				break;
			case SDL_JOYHATMOTION:
				joy_hat_handler((SDL_JoyHatEvent *)&event);
				break;
			case SDL_JOYBALLMOTION:
				break;
#endif
			case SDL_QUIT: {
				quit_request();
			} break;
		}
#if TO_EVENT_POLL
	if (!gameOpts->legacy.bInput && (_t - t0 >= TO_EVENT_POLL))
		break;
#endif
	}
}
コード例 #2
0
ファイル: event.c プロジェクト: gameplayer22/DXX-Retro
void event_poll()
{
    SDL_Event event;
    int clean_uniframe=1;
    window *wind = window_get_front();
    int idle = 1;

    // If the front window changes, exit this loop, otherwise unintended behavior can occur
    // like pressing 'Return' really fast at 'Difficulty Level' causing multiple games to be started
    while ((wind == window_get_front()) && SDL_PollEvent(&event))
    {
        switch(event.type) {
        case SDL_KEYDOWN:
        case SDL_KEYUP:
            if (clean_uniframe)
                memset(unicode_frame_buffer,'\0',sizeof(unsigned char)*KEY_BUFFER_SIZE);
            clean_uniframe=0;
            key_handler((SDL_KeyboardEvent *)&event);
            idle = 0;
            break;
        case SDL_MOUSEBUTTONDOWN:
        case SDL_MOUSEBUTTONUP:
            mouse_button_handler((SDL_MouseButtonEvent *)&event);
            idle = 0;
            break;
        case SDL_MOUSEMOTION:
            mouse_motion_handler((SDL_MouseMotionEvent *)&event);
            idle = 0;
            break;
        case SDL_JOYBUTTONDOWN:
        case SDL_JOYBUTTONUP:
            joy_button_handler((SDL_JoyButtonEvent *)&event);
            idle = 0;
            break;
        case SDL_JOYAXISMOTION:
            if (joy_axis_handler((SDL_JoyAxisEvent *)&event))
                idle = 0;
            break;
        case SDL_JOYHATMOTION:
            joy_hat_handler((SDL_JoyHatEvent *)&event);
            idle = 0;
            break;
        case SDL_JOYBALLMOTION:
            break;
        case SDL_QUIT: {
            d_event qevent = { EVENT_QUIT };
            call_default_handler(&qevent);
            idle = 0;
        }
        break;
        }
    }

    // Send the idle event if there were no other events
    if (idle)
    {
        d_event ievent;

        ievent.type = EVENT_IDLE;
        event_send(&ievent);
    }
    else
        event_reset_idle_seconds();

    mouse_cursor_autohide();
}