Replaced std::auto_ptr<> with std::unique_ptr<>
[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 Screen;
26 class Console;
27 class ScreenFade;
28 class DrawingContext;
29
30 /**
31  * Manages, updates and draws all Screens, Controllers, Menus and the Console.
32  */
33 class ScreenManager
34 {
35 public:
36   ScreenManager();
37   ~ScreenManager();
38
39   void run(DrawingContext &context);
40   void exit_screen(ScreenFade* fade = NULL);
41   void quit(ScreenFade* fade = NULL);
42   void set_speed(float speed);
43   float get_speed() const;
44   bool has_no_pending_fadeout() const;
45
46   /**
47    * requests that a screenshot be taken after the next frame has been rendered
48    */
49   void take_screenshot();
50
51   // push new screen on screen_stack
52   void push_screen(Screen* screen, ScreenFade* fade = NULL);
53   void set_screen_fade(ScreenFade* fade);
54
55   /// threads that wait for a screenswitch
56   scripting::ThreadQueue waiting_threads;
57
58 private:
59   void draw_fps(DrawingContext& context, float fps);
60   void draw(DrawingContext& context);
61   void update_gamelogic(float elapsed_time);
62   void process_events();
63   void handle_screen_switch();
64
65 private:
66   bool running;
67   float speed;
68   bool nextpop;
69   bool nextpush;
70   /// measured fps
71   float fps;
72   std::unique_ptr<Screen> next_screen;
73   std::unique_ptr<Screen> current_screen;
74   std::unique_ptr<Console> console;
75   std::unique_ptr<ScreenFade> screen_fade;
76   std::vector<Screen*> screen_stack;
77   bool screenshot_requested; /**< true if a screenshot should be taken after the next frame has been rendered */
78 };
79
80 #endif
81
82 /* EOF */