// $Id$
-//
+//
// SuperTux
-// Copyright (C) 2004 Bill Kendrick <bill@newbreedsoftware.com>
-// Tobias Glaesser <tobi.web@gmx.de>
-// Ingo Ruhnke <grumbel@gmx.de>
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <string>
#include <SDL.h>
-#include "timer.hpp"
-#include "statistics.hpp"
+#include <squirrel.h>
+#include "screen.hpp"
#include "math/vector.hpp"
-#include "console.hpp"
-
-/* GameLoop modes */
-enum GameSessionMode {
- ST_GL_PLAY,
- ST_GL_TEST,
- ST_GL_LOAD_GAME,
- ST_GL_LOAD_LEVEL_FILE,
- ST_GL_DEMO_GAME
-};
-
-enum GameMenuIDs {
- MNID_CONTINUE,
- MNID_ABORTLEVEL
-};
-
-extern int game_started;
+#include "video/surface.hpp"
+#include "object/endsequence.hpp"
class Level;
class Sector;
class Statistics;
class DrawingContext;
class CodeController;
+class Menu;
-/** The GameSession class controlls the controll flow of a World, ie.
- present the menu on specifc keypresses, render and update it while
- keeping the speed and framerate sane, etc. */
-class GameSession : public ConsoleCommandReceiver
+/**
+ * Screen that runs a Level, where Players run and jump through Sectors.
+ */
+class GameSession : public Screen
{
public:
- enum ExitStatus { ES_NONE, ES_LEVEL_FINISHED, ES_GAME_OVER, ES_LEVEL_ABORT };
-
-public:
- DrawingContext* context;
-
- GameSession(const std::string& levelfile, GameSessionMode mode,
- Statistics* statistics=0);
+ GameSession(const std::string& levelfile, Statistics* statistics = NULL);
~GameSession();
- /** Enter the busy loop */
- ExitStatus run();
-
void record_demo(const std::string& filename);
+ int get_demo_random_seed(const std::string& filename);
void play_demo(const std::string& filename);
- void draw();
+
+ void draw(DrawingContext& context);
void update(float frame_ratio);
+ void setup();
void set_current()
{ current_ = this; }
- static GameSession* current() { return current_; }
+ static GameSession* current()
+ { return current_; }
/// ends the current level
void finish(bool win = true);
- void respawn(const std::string& sectorname,
- const std::string& spawnpointname);
- void set_reset_point(const std::string& sectorname,
- const Vector& pos);
- void display_info_box(const std::string& text);
+ void respawn(const std::string& sectorname, const std::string& spawnpointname);
+ void set_reset_point(const std::string& sectorname, const Vector& pos);
+ std::string get_reset_point_sectorname()
+ { return reset_sector; }
+
+ Vector get_reset_point_pos()
+ { return reset_pos; }
+
Sector* get_current_sector()
{ return currentsector; }
Level* get_current_level()
- { return level; }
+ { return level.get(); }
void start_sequence(const std::string& sequencename);
- /** returns the "working directory" usually this is the directory where the
+ /**
+ * returns the "working directory" usually this is the directory where the
* currently played level resides. This is used when locating additional
* resources for the current level/world
*/
std::string get_working_directory();
- bool consoleCommand(std::string command); /**< callback from Console; return false if command was unknown, true otherwise */
-
-private:
void restart_level();
+ void toggle_pause();
+
+ /**
+ * Enters or leaves level editor mode
+ */
+ void set_editmode(bool edit_mode = true);
+
+ /**
+ * Forces all Players to enter ghost mode
+ */
+ void force_ghost_mode();
+
+private:
void check_end_conditions();
void process_events();
void capture_demo_step();
void levelintro();
void drawstatus(DrawingContext& context);
- void drawendscreen();
- void drawresultscreen();
- void draw_pause();
+ void draw_pause(DrawingContext& context);
+ HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
void on_escape_press();
void process_menu();
- Timer endsequence_timer;
- Level* level;
+ std::auto_ptr<Level> level;
+ std::auto_ptr<Surface> statistics_backdrop;
+
+ // scripts
+ typedef std::vector<HSQOBJECT> ScriptList;
+ ScriptList scripts;
+
Sector* currentsector;
- GameSessionMode mode;
int levelnb;
- float fps_fps;
int pause_menu_frame;
- /** If true the end_sequence will be played, user input will be
- ignored while doing that */
- enum EndSequenceState {
- NO_ENDSEQUENCE,
- ENDSEQUENCE_RUNNING, // tux is running right
- ENDSEQUENCE_WAITING // waiting for the end of the music
- };
- EndSequenceState end_sequence;
- float last_x_pos;
- CodeController* end_sequence_controller;
+ EndSequence* end_sequence;
- bool game_pause;
+ bool game_pause;
+ float speed_before_pause;
std::string levelfile;
static GameSession* current_;
Statistics* best_level_statistics;
- ExitStatus exit_status;
std::ostream* capture_demo_stream;
std::string capture_file;
std::istream* playback_demo_stream;
CodeController* demo_controller;
- Console* console;
-};
-std::string slotinfo(int slot);
+ std::auto_ptr<Menu> game_menu;
-/** Return true if the gameloop() was entered, false otherwise */
-bool process_load_game_menu();
+ float play_time; /**< total time in seconds that this session ran interactively */
-#endif /*SUPERTUX_GAMELOOP_H*/
+ bool edit_mode; /**< true if GameSession runs in level editor mode */
+};
+#endif /*SUPERTUX_GAMELOOP_H*/