From c50081f72ca9f264eb5c0f31e70a33b04574325c Mon Sep 17 00:00:00 2001 From: zicodxx <> Date: Fri, 30 Jul 2010 17:59:21 +0000 Subject: [PATCH] Added event_flush to take place in game_flush_inputs which will clean SDL events which may be buffered while event_process was suspended; suspend Game_Wind while loading restoring save state while playing a level to properly flush controls and reset timer; when toggeling cursor, also directly modify the mouse to wanted behaviour instead of waiting for mouse_update_cursor_and_grab --- CHANGELOG.txt | 1 + arch/include/event.h | 1 + arch/sdl/event.c | 7 +++++++ arch/sdl/mouse.c | 17 ++++++++++++++--- main/game.c | 4 ++-- main/state.c | 9 +++++++-- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ac25e70d9..e68bdf9aa 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ D2X-Rebirth Changelog -------- main/game.c: Removed leftover of mouse grabbing from set_screen_mode - forgot to do this in rev1192 SConstruct: restricted parsing of sdl-config to *NIX and Mac builds as it's static on Win32 anyways; added verbosebuild as SCons option to print out all compiler/linker messages +main/state.c, main/game.c, arch/sdl/event.c, arch/sdl/mouse.c, arch/include/event.h: Added event_flush to take place in game_flush_inputs which will clean SDL events which may be buffered while event_process was suspended; suspend Game_Wind while loading restoring save state while playing a level to properly flush controls and reset timer; when toggeling cursor, also directly modify the mouse to wanted behaviour instead of waiting for mouse_update_cursor_and_grab 20100729 -------- diff --git a/arch/include/event.h b/arch/include/event.h index 58cc2092c..fa603c035 100644 --- a/arch/include/event.h +++ b/arch/include/event.h @@ -50,6 +50,7 @@ int event_init(); // Sends input events to event handlers void event_poll(); +void event_flush(); // Set and call the default event handler void set_default_handler(int (*handler)(d_event *event)); diff --git a/arch/sdl/event.c b/arch/sdl/event.c index e783fff84..0c5a4358d 100644 --- a/arch/sdl/event.c +++ b/arch/sdl/event.c @@ -73,6 +73,13 @@ void event_poll() mouse_update_cursor_and_grab(time); } +void event_flush() +{ + SDL_Event event; + + while (SDL_PollEvent(&event)); +} + int event_init() { // We should now be active and responding to events. diff --git a/arch/sdl/mouse.c b/arch/sdl/mouse.c index d955bfa11..9b66cb0ae 100644 --- a/arch/sdl/mouse.c +++ b/arch/sdl/mouse.c @@ -241,13 +241,24 @@ int mouse_button_state(int button) void mouse_toggle_cursor(int activate) { Mouse.cursor_enabled = (activate && !GameArg.CtlNoMouse); + if (Mouse.cursor_enabled) + { + SDL_ShowCursor(SDL_ENABLE); + if (GameArg.CtlGrabMouse) + SDL_WM_GrabInput(SDL_GRAB_OFF); + } + else + { + SDL_ShowCursor(SDL_DISABLE); + if (GameArg.CtlGrabMouse) + SDL_WM_GrabInput(SDL_GRAB_ON); + } } /* * Here we check what to do with our mouse: * If we want to display/hide cursor, do so if not already and also hide it automatically after some time. * If we want to grab/release cursor, do so if not already. - * If app looses focus, automatically show and release cursor. */ void mouse_update_cursor_and_grab(fix time) { @@ -260,14 +271,14 @@ void mouse_update_cursor_and_grab(fix time) else if ( (Mouse.cursor_time + (F1_0*2)) < time && show) SDL_ShowCursor(SDL_DISABLE); - if (!grab) + if (grab) SDL_WM_GrabInput(SDL_GRAB_OFF); } else { if (show) SDL_ShowCursor(SDL_DISABLE); - if (grab && GameArg.CtlGrabMouse) + if (!grab && GameArg.CtlGrabMouse) SDL_WM_GrabInput(SDL_GRAB_ON); } } diff --git a/main/game.c b/main/game.c index 7eafe0791..0fd3f8acf 100644 --- a/main/game.c +++ b/main/game.c @@ -422,6 +422,7 @@ void start_time() void game_flush_inputs() { int dx,dy,dz; + event_flush(); key_flush(); joy_flush(); mouse_flush(); @@ -1173,9 +1174,8 @@ int game_handler(window *wind, d_event *event, void *data) case EVENT_WINDOW_ACTIVATED: set_screen_mode(SCREEN_GAME); - game_flush_inputs(); - mouse_toggle_cursor(0); + game_flush_inputs(); if (time_paused) start_time(); diff --git a/main/state.c b/main/state.c index 3dd4f5577..945b7df76 100644 --- a/main/state.c +++ b/main/state.c @@ -839,6 +839,9 @@ int state_restore_all_sub(char *filename, int secret_restore) init_player_stats_game(); //clear all stats } + if (Game_wind) + window_set_visible(Game_wind, 0); + //Read player info { @@ -1109,8 +1112,10 @@ int state_restore_all_sub(char *filename, int secret_restore) PHYSFS_close(fp); -// Load in bitmaps, etc.. -//!! piggy_load_level_data(); //already done by StartNewLevelSub() + if (Game_wind) + if (!window_is_visible(Game_wind)) + window_set_visible(Game_wind, 1); + reset_time(); return 1; }