Rewrote logic of ScreenManager to handle ScreenManager::quit() better and not have...
[supertux.git] / src / supertux / screen_manager.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_SUPERTUX_MAINLOOP_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_MAINLOOP_HPP
19
20 #include <memory>
21 #include <cstddef>
22
23 #include "scripting/thread_queue.hpp"
24
25 class Console;
26 class DrawingContext;
27 class MenuManager;
28 class MenuStorage;
29 class Screen;
30 class ScreenFade;
31
32 /**
33  * Manages, updates and draws all Screens, Controllers, Menus and the Console.
34  */
35 class ScreenManager
36 {
37 public:
38   ScreenManager();
39   ~ScreenManager();
40
41   void run(DrawingContext &context);
42   void quit(std::unique_ptr<ScreenFade> fade = {});
43   void set_speed(float speed);
44   float get_speed() const;
45   bool has_pending_fadeout() const;
46
47   /**
48    * requests that a screenshot be taken after the next frame has been rendered
49    */
50   void take_screenshot();
51
52   // push new screen on screen_stack
53   void push_screen(std::unique_ptr<Screen> screen, std::unique_ptr<ScreenFade> fade = {});
54   void pop_screen(std::unique_ptr<ScreenFade> fade = {});
55   void set_screen_fade(std::unique_ptr<ScreenFade> fade);
56
57   /// threads that wait for a screenswitch
58   scripting::ThreadQueue m_waiting_threads;
59
60 private:
61   void draw_fps(DrawingContext& context, float fps);
62   void draw(DrawingContext& context);
63   void update_gamelogic(float elapsed_time);
64   void process_events();
65   void handle_screen_switch();
66
67 private:
68   std::unique_ptr<MenuStorage> m_menu_storage;
69   std::unique_ptr<MenuManager> m_menu_manager;
70
71   float m_speed;
72   enum Action { NO_ACTION, PUSH_ACTION, POP_ACTION, REPLACE_ACTION, QUIT_ACTION };
73   Action m_action;
74   /// measured fps
75   float m_fps;
76   std::unique_ptr<Screen> m_next_screen;
77   std::unique_ptr<ScreenFade> m_screen_fade;
78   std::vector<std::unique_ptr<Screen> > m_screen_stack;
79   bool m_screenshot_requested; /**< true if a screenshot should be taken after the next frame has been rendered */
80 };
81
82 #endif
83
84 /* EOF */