Planeshift

econtrolmanager.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00003  *
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 (version 2 of the License)
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  * You should have received a copy of the GNU General Public License
00013  * along with this program; if not, write to the Free Software
00014  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00015  *
00016  */
00017 
00018 #ifndef ECONTROLMANAGER_H
00019 #define ECONTROLMANAGER_H
00020 
00021 #include <csutil/csstring.h>
00022 #include <iutil/event.h>
00023 #include <csutil/array.h>
00024 
00029 #define CMD_DECLARATION(func)   static void func(eControlManager *obj, bool down)
00030 
00031 struct iObjectRegistry;
00032 
00033 class eControlManager 
00034 {
00035 public:
00041     eControlManager(iObjectRegistry* object_reg);
00042     ~eControlManager();
00043 
00050     bool HandleEvent(iEvent &event);
00051 
00059     bool LoadKeyMap(const char* filename);
00060 
00063     void ClearKeyMap();
00064 
00065     // Actions
00066     CMD_DECLARATION( HandleForward      );
00067     CMD_DECLARATION( HandleBackward     );
00068     CMD_DECLARATION( HandleRotateLeft   );
00069     CMD_DECLARATION( HandleRotateRight  );
00070     CMD_DECLARATION( HandleLookUp       );
00071     CMD_DECLARATION( HandleLookDown     );
00072 
00073 private:
00079     void ExecuteKeyCommand(csKeyEventData &key);
00080 
00087     void Map(const char *action, csKeyEventData &data);
00088 
00095     size_t StringToAction(const char *name);
00096 
00100     struct ActionKeyMap
00101     {
00102         csString action;        
00103         csKeyEventData csKey;   
00104     };
00105 
00106     csArray<ActionKeyMap*>  keyMap; 
00107 
00108 
00109     iObjectRegistry*    object_reg;
00110 };
00111 
00114 #endif