Fix for coverity #29409 - Use char 0 instead of NULL
[supertux.git] / src / 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_MAINLOOP_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_MAINLOOP_HPP
20
21 #include <memory>
22 #include <cstddef>
23
24 #include "scripting/thread_queue.hpp"
25 #include "supertux/screen.hpp"
26 #include "util/currenton.hpp"
27
28 class Console;
29 class DrawingContext;
30 class MenuManager;
31 class MenuStorage;
32 class Screen;
33 class ScreenFade;
34
35 /**
36  * Manages, updates and draws all Screens, Controllers, Menus and the Console.
37  */
38 class ScreenManager : public Currenton<ScreenManager>
39 {
40 public:
41   ScreenManager();
42   ~ScreenManager();
43
44   void run(DrawingContext &context);
45   void quit(std::unique_ptr<ScreenFade> fade = {});
46   void set_speed(float speed);
47   float get_speed() const;
48   bool has_pending_fadeout() const;
49
50   /**
51    * requests that a screenshot be taken after the next frame has been rendered
52    */
53   void take_screenshot();
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   /// threads that wait for a screenswitch
61   scripting::ThreadQueue m_waiting_threads;
62
63 private:
64   void draw_fps(DrawingContext& context, float fps);
65   void draw(DrawingContext& context);
66   void update_gamelogic(float elapsed_time);
67   void process_events();
68   void handle_screen_switch();
69
70 private:
71   std::unique_ptr<MenuStorage> m_menu_storage;
72   std::unique_ptr<MenuManager> m_menu_manager;
73
74   float m_speed;
75   struct Action
76   {
77     enum Type { PUSH_ACTION, POP_ACTION, QUIT_ACTION };
78     Type type;
79     std::unique_ptr<Screen> screen;
80
81     Action(Type type_,
82            std::unique_ptr<Screen> screen_ = {}) :
83       type(type_),
84       screen(std::move(screen_))
85     {}
86   };
87
88   std::vector<Action> m_actions;
89
90   /// measured fps
91   float m_fps;
92   std::unique_ptr<ScreenFade> m_screen_fade;
93   std::vector<std::unique_ptr<Screen> > m_screen_stack;
94   bool m_screenshot_requested; /**< true if a screenshot should be taken after the next frame has been rendered */
95 };
96
97 #endif
98
99 /* EOF */