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 "math/vector.hpp"
27 #include "video/surface.hpp"
28 #include "object/endsequence.hpp"
38 * Screen that runs a Level, where Players run and jump through Sectors.
40 class GameSession : public Screen
43 GameSession(const std::string& levelfile, Statistics* statistics = NULL);
46 void record_demo(const std::string& filename);
47 int get_demo_random_seed(const std::string& filename);
48 void play_demo(const std::string& filename);
50 void draw(DrawingContext& context);
51 void update(float frame_ratio);
56 static GameSession* current()
59 /// ends the current level
60 void finish(bool win = true);
61 void respawn(const std::string& sectorname, const std::string& spawnpointname);
62 void set_reset_point(const std::string& sectorname, const Vector& pos);
63 std::string get_reset_point_sectorname()
64 { return reset_sector; }
66 Vector get_reset_point_pos()
69 Sector* get_current_sector()
70 { return currentsector; }
72 Level* get_current_level()
73 { return level.get(); }
75 void start_sequence(const std::string& sequencename);
78 * returns the "working directory" usually this is the directory where the
79 * currently played level resides. This is used when locating additional
80 * resources for the current level/world
82 std::string get_working_directory();
88 void check_end_conditions();
89 void process_events();
90 void capture_demo_step();
93 void drawstatus(DrawingContext& context);
94 void draw_pause(DrawingContext& context);
96 HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
97 void on_escape_press();
100 std::auto_ptr<Level> level;
101 std::auto_ptr<Surface> statistics_backdrop;
104 typedef std::vector<HSQOBJECT> ScriptList;
107 Sector* currentsector;
110 int pause_menu_frame;
112 EndSequence* end_sequence;
115 float speed_before_pause;
117 std::string levelfile;
119 // reset point (the point where tux respawns if he dies)
120 std::string reset_sector;
123 // the sector and spawnpoint we should spawn after this frame
124 std::string newsector;
125 std::string newspawnpoint;
127 static GameSession* current_;
129 Statistics* best_level_statistics;
131 std::ostream* capture_demo_stream;
132 std::string capture_file;
133 std::istream* playback_demo_stream;
134 CodeController* demo_controller;
136 std::auto_ptr<Menu> game_menu;
138 float play_time; /**< total time in seconds that this session ran interactively */
141 #endif /*SUPERTUX_GAMELOOP_H*/