C:/Users/Mike/Documents/Visual Studio Projects/GameEngine/include/EventManager.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 Copyright (C) 2006 Michael Harnetty
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 -----------------------------------------------------------------------------
00019 */
00020 
00021 #ifndef EVENTMANAGER_H
00022 #define EVENTMANAGER_H
00023 
00024 #include "GameEnginePrerequisites.h"
00025 
00026 #include "Process.h"
00027 #include "IEventListener.h"
00028 #include "Singleton.h"
00029 
00030 namespace GameEngine{
00031         
00032         const int NUM_QUEUES = 2;
00033 
00039         class ENGINE_DECL EventManager : public GameEngine::Singleton<EventManager>{
00040         public:
00043                 EventManager();
00044                 
00047                 ~EventManager();
00048 
00049                 
00055                 bool addListener(const EventListenerPtr& listener, const EventType& eventType);
00056                 
00062                 bool delListener(const EventListenerPtr& listener, const EventType& eventType);
00063 
00064                 
00065                 
00070                 bool sendEvent(const Event& event) const;
00071                 
00076                 bool queueEvent(const EventPtr& event); // Add event to queue of events waiting to be processed
00077 
00078                 
00079                 
00085                 bool tick(const double maxTime);
00086                 
00087                 
00088                 
00094                 bool validateType(const EventType& type) const;
00095                 
00096                         
00097         private:
00098                 // Some typedefs to save typing later
00099                 typedef std::set< EventType >                                                   EventTypeSet;
00100                 typedef std::pair< EventTypeSet::iterator, bool>                EventTypeSetIRes;
00101                 typedef std::list< EventListenerPtr >                                   EventListenerTable;
00102                 typedef std::map< unsigned int, EventListenerTable >    EventListenerMap;
00103                 typedef std::pair< unsigned int, EventListenerTable >   EventListenerMapEnt;
00104                 typedef std::pair< EventListenerMap::iterator, bool >   EventListenerMapIRes;
00105                 typedef std::list< EventPtr >                                                   EventQueue;
00106 
00107 
00108                 EventTypeSet mTypeList; // List of all registered event types
00109                 EventListenerMap mRegistry; // Mapping beetween event types and listeners
00110 
00111                 EventQueue mQueues[NUM_QUEUES]; // Event queues
00112                 int mActiveQueue; // index number of the queue which is currently active
00113 
00114         };
00115 
00116 }
00117 
00118 #endif

Generated on Thu Apr 19 09:47:02 2007 for GameEngine by  doxygen 1.5.2