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"
32 enum GameSessionMode {
36 ST_GL_LOAD_LEVEL_FILE,
45 extern int game_started;
54 * The GameSession class controlls the controll flow of the Game (the part
55 * where you actually play a level)
57 class GameSession : public Screen
60 GameSession(const std::string& levelfile, GameSessionMode mode,
61 Statistics* statistics = NULL);
64 void record_demo(const std::string& filename);
65 void play_demo(const std::string& filename);
67 void draw(DrawingContext& context);
68 void update(float frame_ratio);
73 static GameSession* current()
76 /// ends the current level
77 void finish(bool win = true);
78 void respawn(const std::string& sectorname,
79 const std::string& spawnpointname);
80 void set_reset_point(const std::string& sectorname,
82 void display_info_box(const std::string& text);
84 Sector* get_current_sector()
85 { return currentsector; }
87 Level* get_current_level()
88 { return level.get(); }
90 void start_sequence(const std::string& sequencename);
92 /** returns the "working directory" usually this is the directory where the
93 * currently played level resides. This is used when locating additional
94 * resources for the current level/world
96 std::string get_working_directory();
97 void restart_level(bool fromBeginning = true);
100 void check_end_conditions();
101 void process_events();
102 void capture_demo_step();
105 void drawstatus(DrawingContext& context);
106 void draw_pause(DrawingContext& context);
108 void on_escape_press();
111 Timer endsequence_timer;
112 std::auto_ptr<Level> level;
113 std::auto_ptr<Surface> statistics_backdrop;
115 Sector* currentsector;
117 GameSessionMode mode;
120 int pause_menu_frame;
122 /** If true the end_sequence will be played, user input will be
123 ignored while doing that */
124 enum EndSequenceState {
126 ENDSEQUENCE_RUNNING, // tux is running right
127 ENDSEQUENCE_WAITING // waiting for the end of the music
129 EndSequenceState end_sequence;
131 CodeController* end_sequence_controller;
135 std::string levelfile;
137 // reset point (the point where tux respawns if he dies)
138 std::string reset_sector;
141 // the sector and spawnpoint we should spawn after this frame
142 std::string newsector;
143 std::string newspawnpoint;
145 static GameSession* current_;
147 Statistics* best_level_statistics;
149 std::ostream* capture_demo_stream;
150 std::string capture_file;
151 std::istream* playback_demo_stream;
152 CodeController* demo_controller;
155 #endif /*SUPERTUX_GAMELOOP_H*/