4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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
26 #include "statistics.hpp"
27 #include "math/vector.hpp"
28 #include "console.hpp"
29 #include "video/surface.hpp"
39 * The GameSession class controlls the controll flow of the Game (the part
40 * where you actually play a level)
42 class GameSession : public Screen
45 GameSession(const std::string& levelfile, Statistics* statistics = NULL);
48 void record_demo(const std::string& filename);
49 int get_demo_random_seed(const std::string& filename);
50 void play_demo(const std::string& filename);
52 void draw(DrawingContext& context);
53 void update(float frame_ratio);
58 static GameSession* current()
61 /// ends the current level
62 void finish(bool win = true);
63 void respawn(const std::string& sectorname, const std::string& spawnpointname);
64 void set_reset_point(const std::string& sectorname, const Vector& pos);
65 std::string get_reset_point_sectorname()
66 { return reset_sector; }
68 Vector get_reset_point_pos()
71 void display_info_box(const std::string& text);
73 Sector* get_current_sector()
74 { return currentsector; }
76 Level* get_current_level()
77 { return level.get(); }
79 void start_sequence(const std::string& sequencename);
82 * returns the "working directory" usually this is the directory where the
83 * currently played level resides. This is used when locating additional
84 * resources for the current level/world
86 std::string get_working_directory();
87 void restart_level(bool fromBeginning = true);
92 void check_end_conditions();
93 void process_events();
94 void capture_demo_step();
97 void drawstatus(DrawingContext& context);
98 void draw_pause(DrawingContext& context);
100 HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
101 void on_escape_press();
104 Timer endsequence_timer;
105 std::auto_ptr<Level> level;
106 std::auto_ptr<Surface> statistics_backdrop;
109 typedef std::vector<HSQOBJECT> ScriptList;
112 Sector* currentsector;
115 int pause_menu_frame;
117 /** If true the end_sequence will be played, user input will be
118 ignored while doing that */
119 enum EndSequenceState {
121 ENDSEQUENCE_RUNNING, // tux is running right
122 ENDSEQUENCE_WAITING // waiting for the end of the music
124 EndSequenceState end_sequence;
126 CodeController* end_sequence_controller;
130 std::string levelfile;
132 // reset point (the point where tux respawns if he dies)
133 std::string reset_sector;
136 // the sector and spawnpoint we should spawn after this frame
137 std::string newsector;
138 std::string newspawnpoint;
140 static GameSession* current_;
142 Statistics* best_level_statistics;
144 std::ostream* capture_demo_stream;
145 std::string capture_file;
146 std::istream* playback_demo_stream;
147 CodeController* demo_controller;
149 std::auto_ptr<Menu> game_menu;
151 float play_time; /**< total time in seconds that this session ran interactively */
154 #endif /*SUPERTUX_GAMELOOP_H*/