40 #ifndef _eventmanager_cpp
41 #define _eventmanager_cpp
49 #include "eventmanager.h"
50 #include "eventbase.h"
51 #include "eventgamewindow.h"
52 #include "eventquit.h"
53 #include "eventuserinput.h"
54 #include "Input/metacode.h"
55 #include "Input/inputmanager.h"
75 TargetManager(Target) { }
86 Log <<
"Getting Events from OS." << std::endl;
107 int MezzSDLFilter(
void *userdata, SDL_Event *event )
110 static Boole DroppedQuit=
false;
114 if ( event->type == SDL_QUIT )
144 PollingKeyPress = Polling|Keypress
166 ManualCheckIterator Which = ManualCheck.find(OneCode);
167 if(ManualCheck.end() == Which )
169 ManualCheck[OneCode] = _PollingCheck;
171 Which->second = (
PollingType)(Which->second | _PollingCheck);
182 static_cast<Mezzanine::Input::InputCode>(OneCode),
183 static_cast<Mezzanine::Internal::EventManagerInternalData::PollingType>(_PollingCheck)
200 for ( std::vector<Input::MetaCode>::const_iterator Iter=Transport.begin(); Iter!=Transport.end(); ++Iter)
213 if( ManualCheck.end() != Reduce )
215 if(Reduce->second == _PollingCheck)
216 { ManualCheck.erase(Reduce); }
218 { Reduce->second = (
PollingType)(Reduce->second & (~_PollingCheck)); }
228 ManualCheckIterator Which = ManualCheck.find(OneCode);
245 for ( std::vector<Input::MetaCode>::iterator Iter=Transport.begin(); Iter!=Transport.end(); ++Iter)
253 for (ManualCheckIterator Which = ManualCheck.begin(); Which!=ManualCheck.end(); ++Which)
260 : EventPumpWork(NULL)
278 UInt32 InitSDLSystems = SDL_WasInit(0);
279 if( (SDL_INIT_JOYSTICK & InitSDLSystems) == 0 )
281 if( SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0 )
284 if( !(SDL_INIT_GAMECONTROLLER | InitSDLSystems) )
286 if( SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_NOPARACHUTE) < 0 )
295 UInt32 InitSDLSystems = SDL_WasInit(0);
296 if( (SDL_INIT_JOYSTICK & InitSDLSystems) == 0 )
298 if( SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE) < 0 )
301 if( !(SDL_INIT_GAMECONTROLLER | InitSDLSystems) )
303 if( SDL_Init(SDL_INIT_GAMECONTROLLER | SDL_INIT_NOPARACHUTE) < 0 )
325 UInt32 InitSDLSystems = SDL_WasInit(0);
326 if( SDL_INIT_JOYSTICK | InitSDLSystems )
328 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
330 if( SDL_INIT_GAMECONTROLLER | InitSDLSystems )
332 SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
339 if(SDL_FALSE == SDL_GetEventFilter(0, 0))
341 SDL_SetEventFilter( Internal::MezzSDLFilter, 0);
343 if(4==Internal::MezzSDLFilter(0,0))
383 for( std::list<EventBase*>::iterator EvIt =
_Data->
EventQ.begin() ; EvIt !=
_Data->
EventQ.end() ; ++EvIt )
385 if(EventToRemove == (*EvIt))
405 if(Internal::EventManagerInternalData::Keypress & Iter->second)
456 while(SDL_PollEvent(&FromSDLRaw))
458 switch(FromSDLRaw.type)
461 case SDL_MOUSEBUTTONUP:
case SDL_KEYUP:
case SDL_JOYBUTTONUP:
462 case SDL_KEYDOWN:
case SDL_MOUSEBUTTONDOWN:
case SDL_JOYBUTTONDOWN:
463 case SDL_JOYAXISMOTION:
case SDL_JOYHATMOTION:
case SDL_JOYBALLMOTION:
464 case SDL_MOUSEMOTION:
case SDL_TEXTINPUT:
468 case SDL_WINDOWEVENT: {
569 if((*Iter)->GetType()==SpecificType)
583 if((*Iter)->GetType()==SpecificType)
597 if((*Iter)->GetType()==SpecificType)
607 std::list<EventBase*>* TempList =
new std::list<EventBase*>;
611 if((*Iter)->GetType()==SpecificType)
613 TempList->push_back(*Iter);
623 if((*Iter)->GetType()==SpecificType)
625 std::list<EventBase*>::iterator prev = Iter++;
715 {
delete ToBeDestroyed; }
723 stream <<
"<EventManager Version=\"1\">";
724 for(std::list<Mezzanine::EventBase*>::iterator Iter = Mgr.
_Data->
EventQ.begin(); Iter!=Mgr.
_Data->
EventQ.end(); ++Iter)
725 { stream << **Iter; }
727 { stream <<
"<ManualCheck Version=\"1\" PollingType=\"" << Iter->second <<
"\" InputCode=\"" << Iter->first <<
"\" />"; }
728 stream <<
"</EventManager>";
753 if(TagName.length()>6)
String GetOneTag(std::istream &stream)
Gets the first tag out of the Stream and returns it as a String.
std::ostream & operator<<(std::ostream &stream, const Mezzanine::LinearInterpolator< T > &Lint)
Used to Serialize an Mezzanine::LinearInterpolator to a human readable stream.
void AddMetaCodesToManualCheck(std::vector< Input::MetaCode > Transport, PollingType _PollingCheck)
Used to insert Codes into the list of items to be manually checked.
std::list< EventUserInput * > * GetAllUserInputEvents()
This returns a complete list of all the User Input events.
EventPumpWorkUnit * EventPumpWork
This is the workunit that does the work each frame.
std::list< EventQuit * > * GetAllQuitEvents()
This returns a complete list of all the quit events.
virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type &CurrentThreadStorage)
This does the actual work of the getting the data form the OS.
static EventManager * SingletonPtr
The one and only pointer to the single object.
void UpdateEvents()
Pulls Events from the all the subsystems for use in the EventManager.
void RemoveMetaCodesToManualCheck(const Input::MetaCode &OneCode, PollingType _PollingCheck)
Removes one type of polling check.
std::list< EventGameWindow * > * GetAllGameWindowEvents()
This returns a complete list of all the Render Time events.
Thrown when an unknown internal error occurred.
std::stringstream Logger
In case we ever replace the stringstream with another class, this will allow us to swap it out...
bool Boole
Generally acts a single bit, true or false.
EventGameWindow * PopNextGameWindowEvent()
Returns a pointer to the Next GameWindow event and removes it from the Que.
EventUserInput * PopNextUserInputEvent()
Returns a pointer to the Next User Input event and removes it from the Que.
virtual void AddWorkUnitMain(iWorkUnit *MoreWork, const String &WorkUnitName)
Add a normal Mezzanine::Threading::iWorkUnit to this For fcheduling.
Used to increase encapsulation, just a bit.
void AddInputCodeToManualCheck(Input::InputCode OneCode, PollingType _PollingCheck)
Adds one type of polling check.
EventPumpWorkUnit & operator=(const EventPumpWorkUnit &Other)
Protected assignment operator. THIS IS NOT ALLOWED.
ManagerType
A listing of Manager Types.
EventBase * GetNextSpecificEvent(EventBase::EventType SpecificType)
Returns a pointer to the Next kind event of the Specified type.
std::list< EventBase * > EventQ
The Queue that all the events get stored in.
Document * PreParseClassFromSingleTag(const String &NameSpace, const String &ClassName, const String &OneTag)
Perform a basic series of checks for extracting meaning from a single xml tag.
EventPumpWorkUnit(const EventPumpWorkUnit &Other)
Protected copy constructor. THIS IS NOT ALLOWED.
virtual void RemoveWorkUnitMain(iWorkUnit *LessWork)
Remove a WorkUnit from the main pool of WorkUnits (and not from the groups of Affinity or MonpolyWork...
Node GetFirstChild() const
Get the first child Node of this Node.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
DefaultEventManagerFactory()
Class constructor.
A simple reference counting pointer.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
void RemovePollingCheck(const Input::MetaCode &InputToStopPolling)
Removes Events from the list(s) of what needs to be polled.
virtual void Initialize()
Configures this manager for use prior to entering the main loop.
Threading::FrameScheduler & GetScheduler()
Gets the core structure responsible for scheduling work in the Entresol main loop.
EventUserInput * GetNextUserInputEvent()
Returns a pointer to the Next User Input event.
std::map< Input::InputCode, PollingType > ManualCheck
A unified polling and event repeater the Inputcode is the kind of event to check for each frame...
Every frame the OS must be queried for changes to the state, this does that querying on behalf of an ...
EventBase * PopNextSpecificEvent(EventBase::EventType SpecificType)
Returns a pointer to the Next kind event of the Specified type, and removes it from the Que...
EventPumpWorkUnit * GetEventPumpWork()
Gets the work unit responsible for pumping events from the OS.
SDL_Event RawEvent
This is an internal datatype use to communicate with the User input Subsystem.
static const String ImplementationName
A String containing the name of this manager implementation.
EventQuit * GetNextQuitEvent()
Returns a pointer to the Next EventQuit.
Internal::EventManagerInternalData * _Data
All the internal data for this EventManager.
EventBase * PopNextEvent()
Return a pointer to the Next event, and removes the Event from storage.
Node GetNextSibling() const
Attempt to retrieve the next sibling of this Node.
EventManager()
Default constructor.
void DropAllKeyPresses()
Drops all keypresses from the list of items to be perpetuated each frame.
EventManagerInternalData()
Constructor, it only inits pointers to 0.
A thread specific collection of double-buffered and algorithm specific resources. ...
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
static Boole SingletonValid()
Checks to see if the singleton pointer is valid.
void AddInputCodesToManualCheck(int OneCode, int _PollingCheck)
Adds one type of polling check where the data is only available as Ints.
virtual String GetImplementationTypeName() const
This Allows any manager name to be sent to a stream. Primarily used for logging.
EventType
A listing of values that can be used to identify Events.
static InputManager * GetSingletonPtr()
Fetches a pointer to the singleton.
std::list< EventBase * > * GetAllSpecificEvents(EventBase::EventType SpecificType)
This returns a complete list of all the specified events.
This is the base class for all managers that do no describe properties of a single world...
void RemoveNextUserInputEvent()
Removes the First User Input Event From the que without looking at it.
EventGameWindow * GetNextGameWindowEvent()
Returns a pointer to the Next GameWindow event.
The base class for all events.
A light-weight handle for manipulating nodes in DOM tree.
void AddPollingCheck(const Input::MetaCode &InputToTryPolling)
Generates extra events each iteration of the main loop, based on user input polling.
void RemoveNextGameWindowEvent()
Removes the First GameWindow Event From the que without looking at it.
void RemoveMetaCodesToManualCheck(std::vector< Input::MetaCode > Transport, PollingType _PollingCheck)
Remove Items form the internal manual check list.
virtual ~EventPumpWorkUnit()
Virtual Deconstructor.
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
uint32_t UInt32
An 32-bit unsigned integer.
void RemoveAllSpecificEvents(EventBase::EventType SpecificType)
This removes all the events of the specified type.
void AddEvent(EventBase *EventToAdd)
Adds an event of any kind to the end of the Event Queue.
void RemoveEvent(EventBase *EventToRemove)
Removes an event of any kind from the Event Queue.
void RemoveNextQuitEvent()
Removes the First EventQuit From the que without looking at it.
Entresol * TheEntresol
The actual pointer to the Entresol core class.
This is intended to convey the message that quitting needs to happen.
PollingType
The kinds of data that can be stored in Manual Check.
Logger & GetUsableLogger()
Get the usable logger for this thread specific resource.
size_t GetRemainingEventCount()
Gets a count of events.
String GetManagerImplName() const
Gets the name of the manager that is created by this factory.
std::list< NameValuePair > NameValuePairList
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
void DestroyManager(EntresolManager *ToBeDestroyed)
Destroys a Manager created by this factory.
virtual ~DefaultEventManagerFactory()
Class destructor.
void RemoveInputCodeToManualCheck(const Input::InputCode &OneCode, PollingType _PollingCheck)
Removes one type of polling check.
Thrown when parameters are checked at runtime and found invalid.
virtual ManagerType GetInterfaceType() const
This returns the type of this manager.
void RemovePollingCheck(ManualCheckIterator Reduce, PollingType _PollingCheck)
Remove a kind polling check from an item or remove item if that is the last check.
void RemoveNextSpecificEvent(EventBase::EventType SpecificType)
Returns a pointer to the Next kind event of the Specified type, and removes it from the Que...
EventQuit * PopNextQuitEvent()
Returns a pointer to the Next EventQuit and removes it from the Que.
void AddMetaCodesToManualCheck(const Input::MetaCode &OneCode, PollingType _PollingCheck)
Adds one type of polling check where the data is only available as Ints.
The bulk of the engine components go in this namspace.
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
Convey the message that Something happened to a game window.
EntresolManager * CreateManager(const NameValuePairList &Params)
Creates a manager of the type represented by this factory.
const Char8 * Name() const
ptrdiff_tGet the name of this Node.
void UpdateQuitEvents()
Checks for quit messages and adds them to the queue.
std::map< Input::InputCode, PollingType >::iterator ManualCheckIterator
an Iterator suitable for use with internal structures that correlate polling type and metacodes ...
ManagerBase::ManagerType GetManagerType() const
Gets the type of manager that is created by this factory.
EventManager * TargetManager
The Manager this does the work for.
virtual void Deinitialize()
Removes this manager from any necessary configuration so it can be safely disposed of...
void RemoveNextEvent()
Removes an Event From the que without looking at it.
This is a container for Events and facilitates the transfer of data.
std::string String
A datatype used to a series of characters.
EventBase * GetNextEvent()
Return a pointer to the Next event.
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
virtual ~EventManager()
Default Deconstructor.
Boole Initialized
Simple Boole indicating whether or not this manager has been initialized.