diff --git a/include/ZE_ZEngine.h b/include/ZE_ZEngine.h index a1d13e2..621242a 100644 --- a/include/ZE_ZEngine.h +++ b/include/ZE_ZEngine.h @@ -13,7 +13,7 @@ \brief Definition file for core ZEngine class. ZEngine Game Engine core Engine definition. -
$Id: ZE_ZEngine.h,v 1.37 2003/06/07 00:34:43 cozman Exp $
+
$Id: ZE_ZEngine.h,v 1.38 2003/06/09 02:46:22 cozman Exp $
\author James Turk **/ @@ -107,6 +107,8 @@ class ZEngine bool mLogAllErrors; //! C-style FILE* for error logging. FILE *mErrlog; + //! Event filter, for users who need to process their own events. + SDL_EventFilter mEventFilter; #ifdef USE_SDL_MIXER //! Sound Bitrate @@ -477,9 +479,11 @@ class ZEngine /*! \brief Add a SDL Event Filter for user processing of events. - This is only needed when you need tight control with ZEngine. The parameter is simply passed to SDL_SetEventFilter, - generally only those with a good amount of SDL experience should use this function or ZEngine's internal message - state could be corrupted. For more information on SDL_SetEventFilter see http://sdldoc.csn.ul.ie/sdlseteventfilter.php. + This is only needed when you need tight control with ZEngine. The parameter processed as if it were passed to + SDL_SetEventFilter, generally only those with a good amount of SDL experience should use this function or + ZEngine's internal message state could be corrupted. For more information on SDL_SetEventFilter see + http://sdldoc.csn.ul.ie/sdlseteventfilter.php. (FYI: The parameter is now actually processed in check events, + not passed to the SDL function, this is done because of problems with singletons and event threading.) \since 0.8.2 \param filter An SDL_EventFilter (A function that takes a const SDL_Event* and returns 0 if the event should be removed from the event queue and 1 otherwise.) diff --git a/src/ZE_ZEngine.cpp b/src/ZE_ZEngine.cpp index 6a6ad60..8acfde2 100644 --- a/src/ZE_ZEngine.cpp +++ b/src/ZE_ZEngine.cpp @@ -13,7 +13,7 @@ \brief Central source file for ZEngine. Actual implementation of ZEngine singleton class, the core of ZEngine. -
$Id: ZE_ZEngine.cpp,v 1.42 2003/06/06 18:55:57 cozman Exp $
+
$Id: ZE_ZEngine.cpp,v 1.43 2003/06/09 02:46:22 cozman Exp $
\author James Turk **/ @@ -41,6 +41,7 @@ ZEngine::ZEngine() mScreen = NULL; + mEventFilter = NULL; mActive = mQuit = false; mKeyIsPressed = NULL; mMouseX = mMouseY = 0; @@ -500,44 +501,47 @@ void ZEngine::CheckEvents() while(SDL_PollEvent(&event)) { - switch(event.type) + if(!mEventFilter || mEventFilter(&event)) //if the filter returns 0 it is removing the event, it will not be processed { - case SDL_VIDEOEXPOSE: - case SDL_ACTIVEEVENT: - if(event.active.state & SDL_APPACTIVE || event.active.state & SDL_APPINPUTFOCUS) - { - if( (event.type == SDL_ACTIVEEVENT && event.active.gain == 1) || event.type == SDL_VIDEOEXPOSE) + switch(event.type) + { + case SDL_VIDEOEXPOSE: + case SDL_ACTIVEEVENT: + if(event.active.state & SDL_APPACTIVE || event.active.state & SDL_APPINPUTFOCUS) { - mActive = true; - if(mUnpauseOnActive) - UnpauseTimer(); - if(mFullscreen) - mNeedReload = true; - } - else - { - mActive = mUnpauseOnActive = false; - if(!mPaused) + if( (event.type == SDL_ACTIVEEVENT && event.active.gain == 1) || event.type == SDL_VIDEOEXPOSE) { - mUnpauseOnActive = true; - PauseTimer(); + mActive = true; + if(mUnpauseOnActive) + UnpauseTimer(); + if(mFullscreen) + mNeedReload = true; } else - mUnpauseOnActive = false; + { + mActive = mUnpauseOnActive = false; + if(!mPaused) + { + mUnpauseOnActive = true; + PauseTimer(); + } + else + mUnpauseOnActive = false; + } } - } - break; - case SDL_KEYDOWN: - mKeyPress[event.key.keysym.sym] = true; - break; - case SDL_KEYUP: - mKeyPress[event.key.keysym.sym] = false; - break; - case SDL_QUIT: - mQuit = true; - break; - default: - break; + break; + case SDL_KEYDOWN: + mKeyPress[event.key.keysym.sym] = true; + break; + case SDL_KEYUP: + mKeyPress[event.key.keysym.sym] = false; + break; + case SDL_QUIT: + mQuit = true; + break; + default: + break; + } } } @@ -553,7 +557,7 @@ void ZEngine::CheckEvents() void ZEngine::SetEventFilter(SDL_EventFilter filter) { - SDL_SetEventFilter(filter); + mEventFilter = filter; } #ifdef USE_PHYSFS