diff options
-rw-r--r-- | engines/sci/gfx/operations.cpp | 64 | ||||
-rw-r--r-- | engines/sci/gfx/operations.h | 9 | ||||
-rw-r--r-- | engines/sci/include/uinput.h | 2 |
3 files changed, 35 insertions, 40 deletions
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp index 80bf9b6c60..4e62bfc846 100644 --- a/engines/sci/gfx/operations.cpp +++ b/engines/sci/gfx/operations.cpp @@ -551,7 +551,7 @@ static int _gfxop_init_common(gfx_state_t *state, gfx_options_t *options, void * state->options = options; state->mouse_pointer_in_hw = 0; state->disable_dirty = 0; - state->events = NULL; + state->events.clear(); state->pic = state->pic_unscaled = NULL; @@ -1368,15 +1368,18 @@ int gfxop_sleep(gfx_state_t *state, uint32 msecs) { const uint32 wakeup_time = g_system->getMillis() + msecs; while (true) { - GFXOP_FULL_POINTER_REFRESH; + // let backend process events and update the screen + gfxop_get_event(state, SCI_EVT_PEEK); + g_system->updateScreen(); time = g_system->getMillis(); - if (time >= wakeup_time) + if (time + 10 < wakeup_time) { + g_system->delayMillis(10); + } else { + if (time < wakeup_time) + g_system->delayMillis(wakeup_time - time); break; - // FIXME: Busy waiting like this is usually not a good idea if it is for - // more than a few milliseconds. One should invoke OSystem::pollEvent during longer - // waits, else the mouse cursor might not be updated properly, and the system - // will seem sluggish to the user. - g_system->delayMillis(wakeup_time - time); + } + } return GFX_OK; @@ -1616,37 +1619,32 @@ static int _gfxop_numlockify(int c) { sci_event_t gfxop_get_event(gfx_state_t *state, unsigned int mask) { sci_event_t error_event = { SCI_EVT_ERROR, 0, 0, 0 }; - sci_event_t event = { 0, 0, 0, 0 };; - gfx_input_event_t **seekerp = &(state->events); + sci_event_t event = { 0, 0, 0, 0 }; BASIC_CHECKS(error_event); if (_gfxop_remove_pointer(state)) { GFXERROR("Failed to remove pointer before processing event!\n"); } - while (*seekerp && !((*seekerp)->event.type & mask)) - seekerp = &((*seekerp)->next); - - if (*seekerp) { - gfx_input_event_t *goner = *seekerp; - event = goner->event; - *seekerp = goner->next; - free(goner); - } else { - event.type = 0; - - if (!(mask & SCI_EVT_NONBLOCK)) { - do { - if (event.type) { - *seekerp = (gfx_input_event_t *)sci_malloc(sizeof(gfx_input_event_t)); - (*seekerp)->next = NULL; - - (*seekerp)->event = event; - seekerp = &((*seekerp)->next); - } - event = state->driver->get_event(state->driver); - - } while (event.type && !(event.type & mask)); + // Get all queued events from graphics driver + do { + event = state->driver->get_event(state->driver); + if (event.type) + state->events.push_back(event); + } while (event.type); + + // Search for matching event in queue + Common::List<sci_event_t>::iterator iter = state->events.begin(); + while (iter != state->events.end() && !((*iter).type & mask)) + ++iter; + + if (iter != state->events.end()) { + // Event found + event = *iter; + + // If not peeking at the queue, remove the event + if (!(mask & SCI_EVT_PEEK)) { + state->events.erase(iter); } } diff --git a/engines/sci/gfx/operations.h b/engines/sci/gfx/operations.h index 5eee47e79c..e909a78ea0 100644 --- a/engines/sci/gfx/operations.h +++ b/engines/sci/gfx/operations.h @@ -34,6 +34,8 @@ #include "sci/gfx/gfx_system.h" #include "sci/include/uinput.h" +#include "common/list.h" + namespace Sci { #define GFXOP_NO_POINTER -1 @@ -87,11 +89,6 @@ struct gfx_dirty_rect_t { }; -struct gfx_input_event_t { - sci_event_t event; - gfx_input_event_t *next; -}; - struct gfx_state_t { int version; /* Interpreter version */ @@ -135,7 +132,7 @@ struct gfx_state_t { int pic_nr; /* Number of the current pic */ int palette_nr; /* Palette number of the current pic */ - gfx_input_event_t *events; + Common::List<sci_event_t> events; gfx_pixmap_t *fullscreen_override; /* An optional override picture which must have unscaled ** full-screen size, which overrides all other visibility, and diff --git a/engines/sci/include/uinput.h b/engines/sci/include/uinput.h index eb9a5a6439..dbf8cc424f 100644 --- a/engines/sci/include/uinput.h +++ b/engines/sci/include/uinput.h @@ -61,7 +61,7 @@ struct sci_event_t { /*Fake values for other events*/ #define SCI_EVT_ERROR (1<<10) #define SCI_EVT_QUIT (1<<11) -#define SCI_EVT_NONBLOCK (1<<15) +#define SCI_EVT_PEEK (1<<15) /* The QUIT event may be used to signal an external 'quit' command being ** issued to the gfx driver. */ #define SCI_EVT_ANY 0x7fff |