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
27 #include "statistics.h"
28 #include "math/vector.h"
31 enum GameSessionMode {
35 ST_GL_LOAD_LEVEL_FILE,
44 extern int game_started;
52 /** The GameSession class controlls the controll flow of a World, ie.
53 present the menu on specifc keypresses, render and update it while
54 keeping the speed and framerate sane, etc. */
58 enum ExitStatus { ES_NONE, ES_LEVEL_FINISHED, ES_GAME_OVER, ES_LEVEL_ABORT };
61 DrawingContext* context;
64 GameSession(const std::string& levelfile, GameSessionMode mode,
65 Statistics* statistics=0);
68 /** Enter the busy loop */
71 void record_demo(const std::string& filename);
72 void play_demo(const std::string& filename);
74 void action(float frame_ratio);
78 static GameSession* current() { return current_; }
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);
85 Sector* get_current_sector()
86 { return currentsector; }
88 void start_sequence(const std::string& sequencename);
89 /// called by JoystickKeyboardController after an ascii key has been pressed
95 void check_end_conditions();
97 void process_events();
98 void capture_demo_step();
101 void drawstatus(DrawingContext& context);
102 void drawendscreen();
103 void drawresultscreen();
106 void on_escape_press();
109 Timer endsequence_timer;
111 Sector* currentsector;
113 GameSessionMode mode;
116 int pause_menu_frame;
118 /** If true the end_sequence will be played, user input will be
119 ignored while doing that */
120 enum EndSequenceState {
122 ENDSEQUENCE_RUNNING, // tux is running right
123 ENDSEQUENCE_WAITING // waiting for the end of the music
125 EndSequenceState end_sequence;
127 CodeController* end_sequence_controller;
131 std::string levelfile;
133 // reset point (the point where tux respawns if he dies)
134 std::string reset_sector;
137 // the sector and spawnpoint we should spawn after this frame
138 std::string newsector;
139 std::string newspawnpoint;
141 static GameSession* current_;
143 Statistics* best_level_statistics;
144 ExitStatus exit_status;
146 std::ostream* capture_demo_stream;
147 std::string capture_file;
148 std::istream* playback_demo_stream;
149 CodeController* demo_controller;
152 std::string slotinfo(int slot);
154 /** Return true if the gameloop() was entered, false otherwise */
155 bool process_load_game_menu();
157 #endif /*SUPERTUX_GAMELOOP_H*/