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