Sion Tower (demo técnica) 0.1
|
00001 /* 00002 * This file is part of SionTower. 00003 * 00004 * 00005 * David Saltares Marquez (C) 2011 00006 * <david.saltares@gmail.com> 00007 * 00008 * 00009 * SionTower examples are free software: you can redistribute it and/or 00010 * modify it under the terms of the GNU General Public License ad 00011 * published by the Free Software Foundation, either version 3 of the 00012 * License, or (at your option) ant later version. 00013 * 00014 * SionTower examples are distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with SionTower examples. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 00023 #ifndef SIONTOWER_TRUNK_SRC_INCLUDE_STATEMANAGER_H_ 00024 #define SIONTOWER_TRUNK_SRC_INCLUDE_STATEMANAGER_H_ 00025 00026 #include <vector> 00027 #include <queue> 00028 00029 #include <OGRE/Ogre.h> 00030 #include <OIS/OIS.h> 00031 00032 class State; 00033 class Game; 00034 00036 00054 class StateManager: public Ogre::FrameListener, 00055 public Ogre::WindowEventListener, 00056 public OIS::KeyListener, 00057 public OIS::MouseListener { 00058 public: 00071 StateManager(Game* game, OIS::InputManager* inputManager); 00072 00078 ~StateManager(); 00079 00083 void start(); 00084 00088 void exitGame(); 00089 00097 void changeState(State* state); 00098 00113 void changeState(const Ogre::String& stateName); 00114 00120 void popState(); 00121 00127 void pushState(State* state); 00128 00132 void popAllStates(); 00133 00140 OIS::Mouse* getMouse(); 00141 00148 OIS::Keyboard* getKeyboard(); 00149 00156 bool keyPressed(const OIS::KeyEvent &arg); 00157 00164 bool keyReleased(const OIS::KeyEvent &arg); 00165 00172 bool mouseMoved(const OIS::MouseEvent &arg); 00173 00181 bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id); 00182 00190 bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id); 00191 00199 bool frameStarted(const Ogre::FrameEvent& event); 00200 00209 bool frameEnded(const Ogre::FrameEvent& event); 00210 00219 bool frameRenderingQueued(const Ogre::FrameEvent& event); 00220 00226 void windowClosed(Ogre::RenderWindow* window) {}; 00227 00233 void windowResized(Ogre::RenderWindow* window) {}; 00234 00242 bool windowClosing(Ogre::RenderWindow* window); 00243 00244 private: 00245 // Juego 00246 Game* _game; 00247 00248 // Objetos Ogre 00249 Ogre::Log* _log; 00250 Ogre::RenderWindow* _window; 00251 00252 // Managers de entrada OIS 00253 OIS::InputManager* _inputManager; 00254 OIS::Keyboard* _keyboard; 00255 OIS::Mouse* _mouse; 00256 00257 // Fichero de recursos 00258 Ogre::String _resourcesCfg; 00259 00260 // Métodos auxiliares 00261 void prepareResources(); 00262 void configureOIS(); 00263 00264 // Vector de estados 00265 std::vector<State*> _states; 00266 00267 // Iterador inverso 00268 std::vector<State*>::const_reverse_iterator rev_it; 00269 00270 // Número de estados (temporal) 00271 int _numStates; 00272 00273 // Tipo de operación (push o pop) 00274 enum tOperation {opPush, opPop}; 00275 00276 // Operación de pop o push sobre un estado que se ejecutará 00277 // al comienzo de update 00278 struct StateOperation { 00279 tOperation _type; 00280 State* _state; 00281 00282 StateOperation(tOperation type, State* state = 0): _type(type), _state(state) {}; 00283 }; 00284 00285 // Cola de operaciones por realizar 00286 std::queue<StateOperation> _pendingOperations; 00287 00288 // Controlamos la salida 00289 bool _exit; 00290 00291 // Realiza las operaciones pendientes 00292 void performOperations(); 00293 }; 00294 00295 inline OIS::Mouse* StateManager::getMouse() {return _mouse;} 00296 inline OIS::Keyboard* StateManager::getKeyboard() {return _keyboard;} 00297 00298 #endif // SIONTOWER_TRUNK_SRC_INCLUDE_STATEMANAGER_H_