4 // Copyright (C) 2004 Bill Kendrick <bill@newbreedsoftware.com>
5 // Tobias Glaesser <tobi.web@gmx.de>
6 // Ingo Ruhnke <grumbel@gmx.de>
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #ifndef SUPERTUX_GAMELOOP_H
22 #define SUPERTUX_GAMELOOP_H
28 #include "statistics.hpp"
29 #include "math/vector.hpp"
30 #include "console.hpp"
31 #include "video/surface.hpp"
34 enum GameSessionMode {
38 ST_GL_LOAD_LEVEL_FILE,
47 extern int game_started;
56 * The GameSession class controlls the controll flow of the Game (the part
57 * where you actually play a level)
59 class GameSession : public Screen, public ConsoleCommandReceiver
62 GameSession(const std::string& levelfile, GameSessionMode mode,
63 Statistics* statistics = NULL);
66 void record_demo(const std::string& filename);
67 void play_demo(const std::string& filename);
69 void draw(DrawingContext& context);
70 void update(float frame_ratio);
75 static GameSession* current()
78 /// ends the current level
79 void finish(bool win = true);
80 void respawn(const std::string& sectorname,
81 const std::string& spawnpointname);
82 void set_reset_point(const std::string& sectorname,
84 void display_info_box(const std::string& text);
86 Sector* get_current_sector()
87 { return currentsector; }
89 Level* get_current_level()
90 { return level.get(); }
92 void start_sequence(const std::string& sequencename);
94 /** returns the "working directory" usually this is the directory where the
95 * currently played level resides. This is used when locating additional
96 * resources for the current level/world
98 std::string get_working_directory();
99 bool consoleCommand(std::string command, std::vector<std::string> arguments); /**< callback from Console; return false if command was unknown, true otherwise */
102 void restart_level(bool fromBeginning = true);
104 void check_end_conditions();
105 void process_events();
106 void capture_demo_step();
109 void drawstatus(DrawingContext& context);
110 void draw_pause(DrawingContext& context);
112 void on_escape_press();
115 Timer endsequence_timer;
116 std::auto_ptr<Level> level;
117 std::auto_ptr<Surface> statistics_backdrop;
119 Sector* currentsector;
121 GameSessionMode mode;
124 int pause_menu_frame;
126 /** If true the end_sequence will be played, user input will be
127 ignored while doing that */
128 enum EndSequenceState {
130 ENDSEQUENCE_RUNNING, // tux is running right
131 ENDSEQUENCE_WAITING // waiting for the end of the music
133 EndSequenceState end_sequence;
135 CodeController* end_sequence_controller;
139 std::string levelfile;
141 // reset point (the point where tux respawns if he dies)
142 std::string reset_sector;
145 // the sector and spawnpoint we should spawn after this frame
146 std::string newsector;
147 std::string newspawnpoint;
149 static GameSession* current_;
151 Statistics* best_level_statistics;
153 std::ostream* capture_demo_stream;
154 std::string capture_file;
155 std::istream* playback_demo_stream;
156 CodeController* demo_controller;
159 #endif /*SUPERTUX_GAMELOOP_H*/