supertux
screen_manager.hpp
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 <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 
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  const std::vector<std::unique_ptr<Screen>>& get_screen_stack() { return m_screen_stack; }
63 
64 private:
65  struct FPS_Stats;
66  void draw_fps(DrawingContext& context, FPS_Stats& fps_statistics);
67  void draw_player_pos(DrawingContext& context);
68  void draw(Compositor& compositor, FPS_Stats& fps_statistics);
69  void update_gamelogic(float dt_sec);
70  void process_events();
71  void handle_screen_switch();
72 
73 private:
74  VideoSystem& m_video_system;
75  InputManager& m_input_manager;
76  std::unique_ptr<MenuStorage> m_menu_storage;
77  std::unique_ptr<MenuManager> m_menu_manager;
78  std::unique_ptr<ControllerHUD> m_controller_hud;
79  MobileController m_mobile_controller;
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 
94  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 */
Definition: menu_storage.hpp:24
Manages, updates and draws all Screens, Controllers, Menus and the Console.
Definition: screen_manager.hpp:43
Definition: screen_manager.cpp:56
Definition: input_manager.hpp:39
Definition: menu_manager.hpp:37
A &#39;Currenton&#39; allows access to the currently active instance of a class via the static current() func...
Definition: currenton.hpp:30
Definition: compositor.hpp:29
Definition: video_system.hpp:37
Definition: controller_hud.hpp:27
Definition: mobile_controller.hpp:33
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
Screen to be displayed simultaneously with another Screen.
Definition: screen_fade.hpp:27