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
This commit is contained in:
parent
8c93390f4b
commit
842af496ca
|
@ -3,6 +3,8 @@ D1X-Rebirth Changelog
|
|||
20100730
|
||||
--------
|
||||
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
|
||||
--------
|
||||
|
|
|
@ -34,6 +34,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));
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -391,6 +391,7 @@ void start_time()
|
|||
void game_flush_inputs()
|
||||
{
|
||||
int dx,dy,dz;
|
||||
event_flush();
|
||||
key_flush();
|
||||
joy_flush();
|
||||
mouse_flush();
|
||||
|
@ -1004,9 +1005,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();
|
||||
|
|
|
@ -712,6 +712,9 @@ int state_restore_all_sub(char *filename)
|
|||
InitPlayerObject(); //make sure player's object set up
|
||||
init_player_stats_game(); //clear all stats
|
||||
|
||||
if (Game_wind)
|
||||
window_set_visible(Game_wind, 0);
|
||||
|
||||
//Read player info
|
||||
|
||||
if ( between_levels ) {
|
||||
|
@ -890,8 +893,10 @@ RetryObjectLoading:
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue