Implemented SDL_EventState() and SDL_WaitEvent(), other minor cleanups.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 12 Apr 2013 22:57:06 -0400
changeset 274b3e208d2c10
parent 26 34c2ae82780a
child 28 7507f323a8a7
Implemented SDL_EventState() and SDL_WaitEvent(), other minor cleanups.
src/SDL12_compat.c
     1.1 --- a/src/SDL12_compat.c	Thu Apr 11 21:27:04 2013 -0400
     1.2 +++ b/src/SDL12_compat.c	Fri Apr 12 22:57:06 2013 -0400
     1.3 @@ -36,7 +36,6 @@
     1.4  //#include "render/SDL_yuv_sw_c.h"
     1.5  
     1.6  // !!! IMPLEMENT_ME SDL_ConvertSurface
     1.7 -// !!! IMPLEMENT_ME SDL_EventState
     1.8  // !!! IMPLEMENT_ME SDL_GL_GetAttribute
     1.9  // !!! IMPLEMENT_ME SDL_GL_Lock
    1.10  // !!! IMPLEMENT_ME SDL_GL_SetAttribute
    1.11 @@ -54,7 +53,6 @@
    1.12  // !!! IMPLEMENT_ME SDL_SoftStretch
    1.13  // !!! IMPLEMENT_ME SDL_UnlockSurface
    1.14  // !!! IMPLEMENT_ME SDL_UpperBlit
    1.15 -// !!! IMPLEMENT_ME SDL_WaitEvent
    1.16  // !!! IMPLEMENT_ME X11_KeyToUnicode
    1.17  
    1.18  
    1.19 @@ -336,6 +334,7 @@
    1.20  static int CDRomInit = 0;
    1.21  static SDL12_EventFilter EventFilter12 = NULL;
    1.22  static SDL12_Cursor *CurrentCursor = NULL;
    1.23 +static Uint8 EventStates[SDL12_NUMEVENTS];
    1.24  
    1.25  
    1.26  // !!! FIXME: need a mutex for the event queue.
    1.27 @@ -467,7 +466,8 @@
    1.28          EventQueuePool[SDL12_MAXEVENTS-1].next = NULL;
    1.29          EventQueueHead = EventQueueTail = NULL;
    1.30          EventQueueAvailable = EventQueuePool;
    1.31 -
    1.32 +        SDL_memset(EventStates, SDL_ENABLE, sizeof (EventStates)); /* on by default */
    1.33 +        EventStates[SDL12_SYSWMEVENT] = SDL_IGNORE;  /* off by default. */
    1.34          SDL20_SetEventFilter(EventFilter20to12, NULL);
    1.35          VideoDisplayIndex = GetVideoDisplay();
    1.36      }
    1.37 @@ -790,12 +790,28 @@
    1.38              return 0;  /* drop everything else. */
    1.39      }
    1.40  
    1.41 -    if ((!EventFilter12) || (EventFilter12(&event12)))
    1.42 -        SDL_PushEvent(&event12);
    1.43 +    if (EventStates[event12->type] != SDL_IGNORE)
    1.44 +    {
    1.45 +        if ((!EventFilter12) || (EventFilter12(&event12)))
    1.46 +            SDL_PushEvent(event12);
    1.47 +    }
    1.48  
    1.49      return 0;  /* always drop it from the 2.0 event queue. */
    1.50  }
    1.51  
    1.52 +Uint8
    1.53 +SDL_EventState(Uint8 type, int state)
    1.54 +{
    1.55 +    /* the values of "state" match between 1.2 and 2.0 */
    1.56 +    const Uint8 retval = EventStates[type];
    1.57 +    SDL12_Event e;
    1.58 +
    1.59 +    if (state != SDL_QUERY)
    1.60 +        EventStates[type] = state;
    1.61 +    if (state == SDL_IGNORE)  /* drop existing events of this type. */
    1.62 +        while (SDL_PeepEvents(&e, 1, SDL_GETEVENT, (1<<type))) {}
    1.63 +}
    1.64 +
    1.65  int
    1.66  SDL_PollEvent(SDL12_Event *event12)
    1.67  {
    1.68 @@ -835,10 +851,9 @@
    1.69  int
    1.70  SDL_PeepEvents(SDL12_Event *events12, int numevents, SDL_eventaction action, Uint32 mask)
    1.71  {
    1.72 -    int i;
    1.73 -
    1.74      if (action == SDL_ADDEVENT)
    1.75      {
    1.76 +        int i;
    1.77          for (i = 0; i < numevents; i++)
    1.78          {
    1.79              if (SDL_PushEvent(&events12[i]) == -1)
    1.80 @@ -889,6 +904,16 @@
    1.81      return 0;
    1.82  }
    1.83  
    1.84 +int
    1.85 +SDL_WaitEvent(SDL12_Event *event12)
    1.86 +{
    1.87 +    /* In 1.2, this only fails (-1) if you haven't SDL_Init()'d. */
    1.88 +    while (!SDL_PollEvent(event12))
    1.89 +        SDL_Delay(10);
    1.90 +    return 1;
    1.91 +}
    1.92 +
    1.93 +
    1.94  void
    1.95  SDL_SetEventFilter(SDL12_EventFilter filter12)
    1.96  {