1 // SuperTux 2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 3 // 2014 Ingo Ruhnke <grumbel@gmail.com> 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 #ifndef HEADER_SUPERTUX_SUPERTUX_SCREEN_MANAGER_HPP 19 #define HEADER_SUPERTUX_SUPERTUX_SCREEN_MANAGER_HPP 20 21 #include <memory> 22 #include <SDL2/SDL.h> 23 24 #include "config.h" 25 26 #include "control/mobile_controller.hpp" 27 #include "squirrel/squirrel_thread_queue.hpp" 28 #include "supertux/screen.hpp" 29 #include "util/currenton.hpp" 30 31 class Compositor; 32 class ControllerHUD; 33 class DrawingContext; 34 class InputManager; 35 class MenuManager; 36 class MenuStorage; 37 class ScreenFade; 38 class VideoSystem; 39 40 /** 41 * Manages, updates and draws all Screens, Controllers, Menus and the Console. 42 */ 43 class ScreenManager final : public Currenton<ScreenManager> 44 { 45 public: 46 ScreenManager(VideoSystem& video_system, InputManager& input_manager); 47 ~ScreenManager() override; 48 49 void run(); 50 void quit(std::unique_ptr<ScreenFade> fade = {}); 51 void set_speed(float speed); 52 float get_speed() const; 53 bool has_pending_fadeout() const; 54 55 // push new screen on screen_stack 56 void push_screen(std::unique_ptr<Screen> screen, std::unique_ptr<ScreenFade> fade = {}); 57 void pop_screen(std::unique_ptr<ScreenFade> fade = {}); 58 void set_screen_fade(std::unique_ptr<ScreenFade> fade); 59 60 void loop_iter(); 61 62 private: 63 struct FPS_Stats; 64 void draw_fps(DrawingContext& context, FPS_Stats& fps_statistics); 65 void draw_player_pos(DrawingContext& context); 66 void draw(Compositor& compositor, FPS_Stats& fps_statistics); 67 void update_gamelogic(float dt_sec); 68 void process_events(); 69 void handle_screen_switch(); 70 71 private: 72 VideoSystem& m_video_system; 73 InputManager& m_input_manager; 74 std::unique_ptr<MenuStorage> m_menu_storage; 75 std::unique_ptr<MenuManager> m_menu_manager; 76 std::unique_ptr<ControllerHUD> m_controller_hud; 77 #ifdef ENABLE_TOUCHSCREEN_SUPPORT 78 MobileController m_mobile_controller; 79 #endif 80 81 Uint32 last_ticks; 82 Uint32 elapsed_ticks; 83 const Uint32 ms_per_step; 84 const float seconds_per_step; 85 std::unique_ptr<FPS_Stats> m_fps_statistics; 86 87 float m_speed; 88 struct Action 89 { 90 enum Type { PUSH_ACTION, POP_ACTION, QUIT_ACTION }; 91 Type type; 92 std::unique_ptr<Screen> screen; 93 ActionScreenManager::Action94 Action(Type type_, 95 std::unique_ptr<Screen> screen_ = {}) : 96 type(type_), 97 screen(std::move(screen_)) 98 {} 99 }; 100 101 std::vector<Action> m_actions; 102 103 std::unique_ptr<ScreenFade> m_screen_fade; 104 std::vector<std::unique_ptr<Screen> > m_screen_stack; 105 }; 106 107 #endif 108 109 /* EOF */ 110