Add SDL 2.0 compatibility.

Remove the INPUT_MASK define. Its usage is replaced by the functions:
- is_input
- discard_input
This also removes most external users of the discard function, which is
also problematic due to the event mask.
This commit is contained in:
Mark de Wever 2013-03-02 21:17:25 +00:00
parent 074f6432a4
commit 9015bbcd37
3 changed files with 53 additions and 11 deletions

View file

@ -282,7 +282,7 @@ void pump()
++poll_count;
if(!begin_ignoring && temp_event.type == SDL_ACTIVEEVENT) {
begin_ignoring = poll_count;
} else if(begin_ignoring > 0 && SDL_EVENTMASK(temp_event.type)&INPUT_MASK) {
} else if(begin_ignoring > 0 && is_input(temp_event)) {
//ignore user input events that occurred after the window was activated
continue;
}
@ -290,7 +290,7 @@ void pump()
}
std::vector<SDL_Event>::iterator ev_it = events.begin();
for(int i=1; i < begin_ignoring; ++i){
if(SDL_EVENTMASK(ev_it->type)&INPUT_MASK) {
if(is_input(*ev_it)) {
//ignore user input events that occurred before the window was activated
ev_it = events.erase(ev_it);
} else {
@ -486,4 +486,41 @@ int pump_info::ticks(unsigned *refresh_counter, unsigned refresh_rate) {
return ticks_;
}
#if SDL_VERSION_ATLEAST(2,0,0)
/* The contanstants for the minimum and maximum are picked from the headers. */
#define INPUT_MIN 0x200
#define INPUT_MAX 0x8FF
bool is_input(const SDL_Event& event)
{
return event.type >= INPUT_MIN && event.type <= INPUT_MAX;
}
void discard_input()
{
SDL_FlushEvents(INPUT_MIN, INPUT_MAX);
}
#else
#define INPUT_MASK (SDL_EVENTMASK(SDL_KEYDOWN)|\
SDL_EVENTMASK(SDL_KEYUP)|\
SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|\
SDL_EVENTMASK(SDL_MOUSEBUTTONUP)|\
SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|\
SDL_EVENTMASK(SDL_JOYBUTTONUP))
bool is_input(const SDL_Event& event)
{
return SDL_EVENTMASK(event.type) & INPUT_MASK;
}
void discard_input()
{
discard(INPUT_MASK);
}
#endif
} //end events namespace

View file

@ -113,15 +113,20 @@ void raise_draw_event();
void raise_volatile_draw_event();
void raise_volatile_undraw_event();
void raise_help_string_event(int mousex, int mousey);
/**
* Is the event an input event?
*
* @returns Whether or not the event is an input event.
*/
bool is_input(const SDL_Event& event);
/** Discards all input events. */
void discard_input();
}
typedef std::vector<events::handler*> handler_vector;
#define INPUT_MASK (SDL_EVENTMASK(SDL_KEYDOWN)|\
SDL_EVENTMASK(SDL_KEYUP)|\
SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)|\
SDL_EVENTMASK(SDL_MOUSEBUTTONUP)|\
SDL_EVENTMASK(SDL_JOYBUTTONDOWN)|\
SDL_EVENTMASK(SDL_JOYBUTTONUP))
#endif

View file

@ -787,7 +787,7 @@ bool game_controller::play_multiplayer()
cache_.clear_defines();
game_config::scoped_preproc_define multiplayer(state_.classification().campaign_define);
load_game_cfg();
events::discard(INPUT_MASK); // prevent the "keylogger" effect
events::discard_input(); // prevent the "keylogger" effect
cursor::set(cursor::NORMAL);
// update binary paths
paths_manager_.set_paths(game_config());
@ -863,7 +863,7 @@ bool game_controller::play_multiplayer_commandline()
cache_.clear_defines();
game_config::scoped_preproc_define multiplayer(state_.classification().campaign_define);
load_game_cfg();
events::discard(INPUT_MASK); // prevent the "keylogger" effect
events::discard_input(); // prevent the "keylogger" effect
cursor::set(cursor::NORMAL);
// update binary paths
paths_manager_.set_paths(game_config());