minimize some #includes and replace with forward decls
[supertux.git] / src / game_session.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #ifndef SUPERTUX_GAMELOOP_H
20 #define SUPERTUX_GAMELOOP_H
21
22 #include <string>
23 #include <SDL.h>
24 #include <squirrel.h>
25 #include "screen.hpp"
26 #include "math/vector.hpp"
27 #include "video/surface.hpp"
28 #include "object/endsequence.hpp"
29
30 class Level;
31 class Sector;
32 class Statistics;
33 class DrawingContext;
34 class CodeController;
35 class Menu;
36
37 /**
38  * The GameSession class controlls the controll flow of the Game (the part
39  * where you actually play a level)
40  */
41 class GameSession : public Screen
42 {
43 public:
44   GameSession(const std::string& levelfile, Statistics* statistics = NULL);
45   ~GameSession();
46
47   void record_demo(const std::string& filename);
48   int get_demo_random_seed(const std::string& filename);
49   void play_demo(const std::string& filename);
50
51   void draw(DrawingContext& context);
52   void update(float frame_ratio);
53   void setup();
54
55   void set_current()
56   { current_ = this; }
57   static GameSession* current()
58   { return current_; }
59
60   /// ends the current level
61   void finish(bool win = true);
62   void respawn(const std::string& sectorname, const std::string& spawnpointname);
63   void set_reset_point(const std::string& sectorname, const Vector& pos);
64   std::string get_reset_point_sectorname()
65   { return reset_sector; }
66
67   Vector get_reset_point_pos()
68   { return reset_pos; }
69
70   void display_info_box(const std::string& text);
71
72   Sector* get_current_sector()
73   { return currentsector; }
74
75   Level* get_current_level()
76   { return level.get(); }
77
78   void start_sequence(const std::string& sequencename);
79
80   /**
81    * returns the "working directory" usually this is the directory where the
82    * currently played level resides. This is used when locating additional
83    * resources for the current level/world
84    */
85   std::string get_working_directory();
86   void restart_level();
87
88   void toggle_pause();
89
90 private:
91   void check_end_conditions();
92   void process_events();
93   void capture_demo_step();
94
95   void levelintro();
96   void drawstatus(DrawingContext& context);
97   void draw_pause(DrawingContext& context);
98
99   HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
100   void on_escape_press();
101   void process_menu();
102
103   std::auto_ptr<Level> level;
104   std::auto_ptr<Surface> statistics_backdrop;
105
106   // scripts
107   typedef std::vector<HSQOBJECT> ScriptList;
108   ScriptList scripts;
109
110   Sector* currentsector;
111
112   int levelnb;
113   int pause_menu_frame;
114
115   EndSequence* end_sequence;
116
117   bool game_pause;
118
119   std::string levelfile;
120
121   // reset point (the point where tux respawns if he dies)
122   std::string reset_sector;
123   Vector reset_pos;
124
125   // the sector and spawnpoint we should spawn after this frame
126   std::string newsector;
127   std::string newspawnpoint;
128
129   static GameSession* current_;
130
131   Statistics* best_level_statistics;
132
133   std::ostream* capture_demo_stream;
134   std::string capture_file;
135   std::istream* playback_demo_stream;
136   CodeController* demo_controller;
137
138   std::auto_ptr<Menu> game_menu;
139
140   float play_time; /**< total time in seconds that this session ran interactively */
141 };
142
143 #endif /*SUPERTUX_GAMELOOP_H*/