Fixed trailing whitespaces in all(?) source files of supertux, also fixed some svn...
[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 "screen.hpp"
25 #include "timer.hpp"
26 #include "statistics.hpp"
27 #include "math/vector.hpp"
28 #include "console.hpp"
29 #include "video/surface.hpp"
30 #include "object/endsequence.hpp"
31
32 class Level;
33 class Sector;
34 class Statistics;
35 class DrawingContext;
36 class CodeController;
37 class Menu;
38
39 /**
40  * The GameSession class controlls the controll flow of the Game (the part
41  * where you actually play a level)
42  */
43 class GameSession : public Screen
44 {
45 public:
46   GameSession(const std::string& levelfile, Statistics* statistics = NULL);
47   ~GameSession();
48
49   void record_demo(const std::string& filename);
50   int get_demo_random_seed(const std::string& filename);
51   void play_demo(const std::string& filename);
52
53   void draw(DrawingContext& context);
54   void update(float frame_ratio);
55   void setup();
56
57   void set_current()
58   { current_ = this; }
59   static GameSession* current()
60   { return current_; }
61
62   /// ends the current level
63   void finish(bool win = true);
64   void respawn(const std::string& sectorname, const std::string& spawnpointname);
65   void set_reset_point(const std::string& sectorname, const Vector& pos);
66   std::string get_reset_point_sectorname()
67   { return reset_sector; }
68
69   Vector get_reset_point_pos()
70   { return reset_pos; }
71
72   void display_info_box(const std::string& text);
73
74   Sector* get_current_sector()
75   { return currentsector; }
76
77   Level* get_current_level()
78   { return level.get(); }
79
80   void start_sequence(const std::string& sequencename);
81
82   /**
83    * returns the "working directory" usually this is the directory where the
84    * currently played level resides. This is used when locating additional
85    * resources for the current level/world
86    */
87   std::string get_working_directory();
88   void restart_level(bool fromBeginning = true);
89
90   void toggle_pause();
91
92 private:
93   void check_end_conditions();
94   void process_events();
95   void capture_demo_step();
96
97   void levelintro();
98   void drawstatus(DrawingContext& context);
99   void draw_pause(DrawingContext& context);
100
101   HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
102   void on_escape_press();
103   void process_menu();
104
105   std::auto_ptr<Level> level;
106   std::auto_ptr<Surface> statistics_backdrop;
107
108   // scripts
109   typedef std::vector<HSQOBJECT> ScriptList;
110   ScriptList scripts;
111
112   Sector* currentsector;
113
114   int levelnb;
115   int pause_menu_frame;
116
117   EndSequence* end_sequence;
118
119   bool game_pause;
120
121   std::string levelfile;
122
123   // reset point (the point where tux respawns if he dies)
124   std::string reset_sector;
125   Vector reset_pos;
126
127   // the sector and spawnpoint we should spawn after this frame
128   std::string newsector;
129   std::string newspawnpoint;
130
131   static GameSession* current_;
132
133   Statistics* best_level_statistics;
134
135   std::ostream* capture_demo_stream;
136   std::string capture_file;
137   std::istream* playback_demo_stream;
138   CodeController* demo_controller;
139
140   std::auto_ptr<Menu> game_menu;
141
142   float play_time; /**< total time in seconds that this session ran interactively */
143 };
144
145 #endif /*SUPERTUX_GAMELOOP_H*/