changed event hooking, event thread now safe
This commit is contained in:
parent
6bec0bc602
commit
9f0b7ec75e
@ -13,7 +13,7 @@
|
|||||||
\brief Definition file for core ZEngine class.
|
\brief Definition file for core ZEngine class.
|
||||||
|
|
||||||
ZEngine Game Engine core Engine definition.
|
ZEngine Game Engine core Engine definition.
|
||||||
<br>$Id: ZE_ZEngine.h,v 1.37 2003/06/07 00:34:43 cozman Exp $<br>
|
<br>$Id: ZE_ZEngine.h,v 1.38 2003/06/09 02:46:22 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -107,6 +107,8 @@ class ZEngine
|
|||||||
bool mLogAllErrors;
|
bool mLogAllErrors;
|
||||||
//! C-style FILE* for error logging.
|
//! C-style FILE* for error logging.
|
||||||
FILE *mErrlog;
|
FILE *mErrlog;
|
||||||
|
//! Event filter, for users who need to process their own events.
|
||||||
|
SDL_EventFilter mEventFilter;
|
||||||
|
|
||||||
#ifdef USE_SDL_MIXER
|
#ifdef USE_SDL_MIXER
|
||||||
//! Sound Bitrate
|
//! Sound Bitrate
|
||||||
@ -477,9 +479,11 @@ class ZEngine
|
|||||||
/*!
|
/*!
|
||||||
\brief Add a SDL Event Filter for user processing of events.
|
\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,
|
This is only needed when you need tight control with ZEngine. The parameter processed as if it were passed to
|
||||||
generally only those with a good amount of SDL experience should use this function or ZEngine's internal message
|
SDL_SetEventFilter, generally only those with a good amount of SDL experience should use this function or
|
||||||
state could be corrupted. For more information on SDL_SetEventFilter see http://sdldoc.csn.ul.ie/sdlseteventfilter.php.
|
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
|
\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
|
\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.)
|
the event queue and 1 otherwise.)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Central source file for ZEngine.
|
\brief Central source file for ZEngine.
|
||||||
|
|
||||||
Actual implementation of ZEngine singleton class, the core of ZEngine.
|
Actual implementation of ZEngine singleton class, the core of ZEngine.
|
||||||
<br>$Id: ZE_ZEngine.cpp,v 1.42 2003/06/06 18:55:57 cozman Exp $<br>
|
<br>$Id: ZE_ZEngine.cpp,v 1.43 2003/06/09 02:46:22 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ ZEngine::ZEngine()
|
|||||||
|
|
||||||
mScreen = NULL;
|
mScreen = NULL;
|
||||||
|
|
||||||
|
mEventFilter = NULL;
|
||||||
mActive = mQuit = false;
|
mActive = mQuit = false;
|
||||||
mKeyIsPressed = NULL;
|
mKeyIsPressed = NULL;
|
||||||
mMouseX = mMouseY = 0;
|
mMouseX = mMouseY = 0;
|
||||||
@ -500,44 +501,47 @@ void ZEngine::CheckEvents()
|
|||||||
|
|
||||||
while(SDL_PollEvent(&event))
|
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:
|
switch(event.type)
|
||||||
case SDL_ACTIVEEVENT:
|
{
|
||||||
if(event.active.state & SDL_APPACTIVE || event.active.state & SDL_APPINPUTFOCUS)
|
case SDL_VIDEOEXPOSE:
|
||||||
{
|
case SDL_ACTIVEEVENT:
|
||||||
if( (event.type == SDL_ACTIVEEVENT && event.active.gain == 1) || event.type == SDL_VIDEOEXPOSE)
|
if(event.active.state & SDL_APPACTIVE || event.active.state & SDL_APPINPUTFOCUS)
|
||||||
{
|
{
|
||||||
mActive = true;
|
if( (event.type == SDL_ACTIVEEVENT && event.active.gain == 1) || event.type == SDL_VIDEOEXPOSE)
|
||||||
if(mUnpauseOnActive)
|
|
||||||
UnpauseTimer();
|
|
||||||
if(mFullscreen)
|
|
||||||
mNeedReload = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mActive = mUnpauseOnActive = false;
|
|
||||||
if(!mPaused)
|
|
||||||
{
|
{
|
||||||
mUnpauseOnActive = true;
|
mActive = true;
|
||||||
PauseTimer();
|
if(mUnpauseOnActive)
|
||||||
|
UnpauseTimer();
|
||||||
|
if(mFullscreen)
|
||||||
|
mNeedReload = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mUnpauseOnActive = false;
|
{
|
||||||
|
mActive = mUnpauseOnActive = false;
|
||||||
|
if(!mPaused)
|
||||||
|
{
|
||||||
|
mUnpauseOnActive = true;
|
||||||
|
PauseTimer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mUnpauseOnActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case SDL_KEYDOWN:
|
||||||
case SDL_KEYDOWN:
|
mKeyPress[event.key.keysym.sym] = true;
|
||||||
mKeyPress[event.key.keysym.sym] = true;
|
break;
|
||||||
break;
|
case SDL_KEYUP:
|
||||||
case SDL_KEYUP:
|
mKeyPress[event.key.keysym.sym] = false;
|
||||||
mKeyPress[event.key.keysym.sym] = false;
|
break;
|
||||||
break;
|
case SDL_QUIT:
|
||||||
case SDL_QUIT:
|
mQuit = true;
|
||||||
mQuit = true;
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,7 +557,7 @@ void ZEngine::CheckEvents()
|
|||||||
|
|
||||||
void ZEngine::SetEventFilter(SDL_EventFilter filter)
|
void ZEngine::SetEventFilter(SDL_EventFilter filter)
|
||||||
{
|
{
|
||||||
SDL_SetEventFilter(filter);
|
mEventFilter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_PHYSFS
|
#ifdef USE_PHYSFS
|
||||||
|
Loading…
Reference in New Issue
Block a user