GameSession Class Reference

Screen that runs a Level, where Players run and jump through Sectors. More...

#include <game_session.hpp>

Inherits Screen, and Currenton< GameSession >.

List of all members.

Public Member Functions

 GameSession (const std::string &levelfile, PlayerStatus *player_status, Statistics *statistics=NULL)
 ~GameSession ()
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 (DrawingContext &context)
 gets called once per frame.
void update (float frame_ratio)
 gets called for once (per logical) frame.
void setup ()
 gets called before this screen gets activated (which is at least once before the first draw or update call
void finish (bool win=true)
 ends the current level
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 ()
Vector get_reset_point_pos ()
Sectorget_current_sector ()
Levelget_current_level ()
PlayerStatusget_player_status ()
void start_sequence (const std::string &sequencename)
std::string get_working_directory ()
 returns the "working directory" usually this is the directory where the currently played level resides.
int restart_level ()
void toggle_pause ()
void set_editmode (bool edit_mode=true)
 Enters or leaves level editor mode.
void force_ghost_mode ()
 Forces all Players to enter ghost mode.

Private Types

typedef std::vector< HSQOBJECT > ScriptList

Private Member Functions

void check_end_conditions ()
void process_events ()
void capture_demo_step ()
void drawstatus (DrawingContext &context)
void draw_pause (DrawingContext &context)
HSQUIRRELVM run_script (std::istream &in, const std::string &sourcename)
void on_escape_press ()
void process_menu ()
 GameSession (const GameSession &)
GameSessionoperator= (const GameSession &)

Private Attributes

std::auto_ptr< Levellevel
SurfacePtr statistics_backdrop
ScriptList scripts
Sectorcurrentsector
int levelnb
int pause_menu_frame
EndSequenceend_sequence
bool game_pause
float speed_before_pause
std::string levelfile
std::string reset_sector
Vector reset_pos
std::string newsector
std::string newspawnpoint
Statisticsbest_level_statistics
PlayerStatusplayer_status
std::ostream * capture_demo_stream
std::string capture_file
std::istream * playback_demo_stream
CodeControllerdemo_controller
std::auto_ptr< Menugame_menu
float play_time
 total time in seconds that this session ran interactively
bool edit_mode
 true if GameSession runs in level editor mode
bool levelintro_shown
 true if the LevelIntro screen was already shown


Detailed Description

Screen that runs a Level, where Players run and jump through Sectors.

Definition at line 40 of file game_session.hpp.


Member Typedef Documentation

typedef std::vector<HSQOBJECT> GameSession::ScriptList [private]

Definition at line 112 of file game_session.hpp.


Constructor & Destructor Documentation

GameSession::GameSession ( const std::string &  levelfile,
PlayerStatus player_status,
Statistics statistics = NULL 
)

Definition at line 46 of file game_session.cpp.

References Surface::create(), currentsector, g_screen_manager, game_menu, game_pause, ScreenManager::get_speed(), level, restart_level(), speed_before_pause, and statistics_backdrop.

00046                                                                                                          :
00047   level(0), 
00048   statistics_backdrop(),
00049   scripts(),
00050   currentsector(0),
00051   levelnb(),
00052   pause_menu_frame(),
00053   end_sequence(0),
00054   game_pause(),
00055   speed_before_pause(),
00056   levelfile(levelfile_), 
00057   reset_sector(),
00058   reset_pos(),
00059   newsector(),
00060   newspawnpoint(),
00061   best_level_statistics(statistics),
00062   player_status(player_status),
00063   capture_demo_stream(0), 
00064   capture_file(),
00065   playback_demo_stream(0), 
00066   demo_controller(0),
00067   game_menu(),
00068   play_time(0), 
00069   edit_mode(false), 
00070   levelintro_shown(false)
00071 {
00072   currentsector = NULL;
00073 
00074   game_pause = false;
00075   speed_before_pause = g_screen_manager->get_speed();
00076 
00077   statistics_backdrop = Surface::create("images/engine/menu/score-backdrop.png");
00078 
00079   if (restart_level() != 0)
00080     throw std::runtime_error ("Initializing the level failed.");
00081 
00082   game_menu.reset(new GameMenu(*level));
00083 }

GameSession::~GameSession (  ) 

Definition at line 146 of file game_session.cpp.

References capture_demo_stream, demo_controller, and playback_demo_stream.

00147 {
00148   delete capture_demo_stream;
00149   delete playback_demo_stream;
00150   delete demo_controller;
00151 }

GameSession::GameSession ( const GameSession  )  [private]


Member Function Documentation

void GameSession::record_demo ( const std::string &  filename  ) 

Definition at line 154 of file game_session.cpp.

References capture_demo_stream, capture_file, g_config, and Config::random_seed.

Referenced by scripting::record_demo(), and restart_level().

00155 {
00156   delete capture_demo_stream;
00157 
00158   capture_demo_stream = new std::ofstream(filename.c_str());
00159   if(!capture_demo_stream->good()) {
00160     std::stringstream msg;
00161     msg << "Couldn't open demo file '" << filename << "' for writing.";
00162     throw std::runtime_error(msg.str());
00163   }
00164   capture_file = filename;
00165 
00166   char buf[30];                            // save the seed in the demo file
00167   snprintf(buf, sizeof(buf), "random_seed=%10d", g_config->random_seed);
00168   for (int i=0; i==0 || buf[i-1]; i++)
00169     capture_demo_stream->put(buf[i]);
00170 }

int GameSession::get_demo_random_seed ( const std::string &  filename  ) 

Definition at line 173 of file game_session.cpp.

References log_info.

Referenced by scripting::play_demo().

00174 {
00175   std::istream* test_stream = new std::ifstream(filename.c_str());
00176   if(test_stream->good()) {
00177     char buf[30];                     // recall the seed from the demo file
00178     int seed;
00179     for (int i=0; i<30 && (i==0 || buf[i-1]); i++)
00180       test_stream->get(buf[i]);
00181     if (sscanf(buf, "random_seed=%10d", &seed) == 1) {
00182       log_info << "Random seed " << seed << " from demo file" << std::endl;
00183       return seed;
00184     }
00185     else
00186       log_info << "Demo file contains no random number" << std::endl;
00187   }
00188   return 0;
00189 }

void GameSession::play_demo ( const std::string &  filename  ) 

Definition at line 192 of file game_session.cpp.

References currentsector, demo_controller, playback_demo_stream, and Sector::player.

Referenced by scripting::play_demo().

00193 {
00194   delete playback_demo_stream;
00195   delete demo_controller;
00196 
00197   playback_demo_stream = new std::ifstream(filename.c_str());
00198   if(!playback_demo_stream->good()) {
00199     std::stringstream msg;
00200     msg << "Couldn't open demo file '" << filename << "' for reading.";
00201     throw std::runtime_error(msg.str());
00202   }
00203 
00204   Player& tux = *currentsector->player;
00205   demo_controller = new CodeController();
00206   tux.set_controller(demo_controller);
00207 
00208   // skip over random seed, if it exists in the file
00209   char buf[30];                            // ascii decimal seed
00210   int seed;
00211   for (int i=0; i<30 && (i==0 || buf[i-1]); i++)
00212     playback_demo_stream->get(buf[i]);
00213   if (sscanf(buf, "random_seed=%010d", &seed) != 1)
00214     playback_demo_stream->seekg(0);     // old style w/o seed, restart at beg
00215 }

void GameSession::draw ( DrawingContext context  )  [virtual]

gets called once per frame.

The screen should draw itself in this function. State changes should not be done in this function, but rather in update

Implements Screen.

Definition at line 371 of file game_session.cpp.

References currentsector, Sector::draw(), draw_pause(), drawstatus(), and game_pause.

00372 {
00373   currentsector->draw(context);
00374   drawstatus(context);
00375 
00376   if(game_pause)
00377     draw_pause(context);
00378 }

void GameSession::update ( float  frame_ratio  )  [virtual]

gets called for once (per logical) frame.

Screens should do their state updates and logic here

Implements Screen.

Definition at line 431 of file game_session.cpp.

References Sector::activate(), Sector::camera, check_end_conditions(), MenuManager::current(), currentsector, edit_mode, end_sequence, g_jk_controller, g_screen_manager, game_pause, Camera::get_center(), JoystickKeyboardController::get_main_controller(), Sector::get_music_type(), Sector::get_players(), Timer::get_timeleft(), HERRING_MUSIC, HERRING_WARNING_MUSIC, Player::invincible_timer, EndSequence::is_tux_stopped(), level, LEVEL_MUSIC, log_warning, newsector, newspawnpoint, on_escape_press(), Controller::PAUSE_MENU, Sector::play_music(), play_time, Sector::player, Controller::pressed(), process_events(), process_menu(), SoundManager::set_listener_position(), ScreenManager::set_speed(), sound_manager, speed_before_pause, Timer::started(), TUX_INVINCIBLE_TIME_WARNING, EndSequence::update(), and Sector::update().

00432 {
00433   // handle controller
00434   if(g_jk_controller->get_main_controller()->pressed(Controller::PAUSE_MENU))
00435     on_escape_press();
00436 
00437   process_events();
00438   process_menu();
00439 
00440   // Unpause the game if the menu has been closed
00441   if (game_pause && !MenuManager::current()) {
00442     g_screen_manager->set_speed(speed_before_pause);
00443     game_pause = false;
00444   }
00445 
00446   check_end_conditions();
00447 
00448   // respawning in new sector?
00449   if(newsector != "" && newspawnpoint != "") {
00450     Sector* sector = level->get_sector(newsector);
00451     if(sector == 0) {
00452       log_warning << "Sector '" << newsector << "' not found" << std::endl;
00453       sector = level->get_sector("main");
00454     }
00455     sector->activate(newspawnpoint);
00456     sector->play_music(LEVEL_MUSIC);
00457     currentsector = sector;
00458     //Keep persistent across sectors
00459     if(edit_mode)
00460       currentsector->get_players()[0]->set_edit_mode(edit_mode);
00461     newsector = "";
00462     newspawnpoint = "";
00463   }
00464 
00465   // Update the world state and all objects in the world
00466   if(!game_pause) {
00467     // Update the world
00468     if (!end_sequence) {
00469       play_time += elapsed_time; //TODO: make sure we don't count cutscene time
00470       level->stats.time = play_time;
00471       currentsector->update(elapsed_time);
00472     } else {
00473       if (!end_sequence->is_tux_stopped()) {
00474         currentsector->update(elapsed_time);
00475       } else {
00476         end_sequence->update(elapsed_time);
00477       }
00478     }
00479   }
00480 
00481   // update sounds
00482   if (currentsector && currentsector->camera) sound_manager->set_listener_position(currentsector->camera->get_center());
00483 
00484   /* Handle music: */
00485   if (end_sequence)
00486     return;
00487 
00488   if(currentsector->player->invincible_timer.started()) {
00489     if(currentsector->player->invincible_timer.get_timeleft() <=
00490        TUX_INVINCIBLE_TIME_WARNING) {
00491       currentsector->play_music(HERRING_WARNING_MUSIC);
00492     } else {
00493       currentsector->play_music(HERRING_MUSIC);
00494     }
00495   } else if(currentsector->get_music_type() != LEVEL_MUSIC) {
00496     currentsector->play_music(LEVEL_MUSIC);
00497   }
00498 }

void GameSession::setup (  )  [virtual]

gets called before this screen gets activated (which is at least once before the first draw or update call

Reimplemented from Screen.

Definition at line 409 of file game_session.cpp.

References Sector::activate(), best_level_statistics, Sector::current(), currentsector, g_screen_manager, MovingObject::get_pos(), level, LEVEL_MUSIC, levelintro_shown, Sector::play_music(), Sector::player, and ScreenManager::push_screen().

00410 {
00411   if (currentsector == NULL)
00412     return;
00413 
00414   if(currentsector != Sector::current()) {
00415     currentsector->activate(currentsector->player->get_pos());
00416   }
00417   currentsector->play_music(LEVEL_MUSIC);
00418 
00419   // Eat unneeded events
00420   SDL_Event event;
00421   while(SDL_PollEvent(&event))
00422   {}
00423 
00424   if (!levelintro_shown) {
00425     levelintro_shown = true;
00426     g_screen_manager->push_screen(new LevelIntro(level.get(), best_level_statistics));
00427   }
00428 }

void GameSession::finish ( bool  win = true  ) 

ends the current level

Definition at line 501 of file game_session.cpp.

References edit_mode, ScreenManager::exit_screen(), force_ghost_mode(), g_screen_manager, and level.

Referenced by check_end_conditions(), and scripting::Level_finish().

00502 {
00503   using namespace worldmap;
00504 
00505   if (edit_mode) {
00506     force_ghost_mode();
00507     return;
00508   }
00509 
00510   if(win) {
00511     if(WorldMap::current())
00512       WorldMap::current()->finished_level(level.get());
00513   }
00514 
00515   g_screen_manager->exit_screen();
00516 }

void GameSession::respawn ( const std::string &  sectorname,
const std::string &  spawnpointname 
)

Definition at line 519 of file game_session.cpp.

References newsector, and newspawnpoint.

Referenced by Door::collision(), WillOWisp::collision_player(), and scripting::Level_spawn().

00520 {
00521   newsector = sector;
00522   newspawnpoint = spawnpoint;
00523 }

void GameSession::set_reset_point ( const std::string &  sectorname,
const Vector pos 
)

Definition at line 526 of file game_session.cpp.

References reset_pos, and reset_sector.

Referenced by Firefly::collision().

00527 {
00528   reset_sector = sector;
00529   reset_pos = pos;
00530 }

std::string GameSession::get_reset_point_sectorname (  )  [inline]

Definition at line 59 of file game_session.hpp.

References reset_sector.

00060   { return reset_sector; }

Vector GameSession::get_reset_point_pos (  )  [inline]

Definition at line 62 of file game_session.hpp.

References reset_pos.

00063   { return reset_pos; }

Sector* GameSession::get_current_sector (  )  [inline]

Definition at line 65 of file game_session.hpp.

References currentsector.

00066   { return currentsector; }

Level* GameSession::get_current_level (  )  [inline]

Definition at line 68 of file game_session.hpp.

References level.

00069   { return level.get(); }

PlayerStatus* GameSession::get_player_status (  )  [inline]

Definition at line 71 of file game_session.hpp.

References player_status.

00072   { return player_status; }

void GameSession::start_sequence ( const std::string &  sequencename  ) 

Definition at line 539 of file game_session.cpp.

References Sector::add_object(), currentsector, edit_mode, end_sequence, force_ghost_mode(), g_screen_manager, Sector::gameobjects, Sector::get_players(), log_warning, SoundManager::play_music(), Sector::player, ScreenManager::set_speed(), Player::set_winning(), sound_manager, EndSequence::start(), LevelTime::stop(), and EndSequence::stop_tux().

Referenced by Player::trigger_sequence().

00540 {
00541   // do not play sequences when in edit mode
00542   if (edit_mode) {
00543     force_ghost_mode();
00544     return;
00545   }
00546 
00547   // handle special "stoptux" sequence
00548   if (sequencename == "stoptux") {
00549     if (!end_sequence) {
00550       log_warning << "Final target reached without an active end sequence" << std::endl;
00551       this->start_sequence("endsequence");
00552     }
00553     if (end_sequence) end_sequence->stop_tux();
00554     return;
00555   }
00556 
00557   // abort if a sequence is already playing
00558   if (end_sequence)
00559     return;
00560 
00561   if (sequencename == "endsequence") {
00562     if (currentsector->get_players()[0]->get_physic().get_velocity_x() < 0) {
00563       end_sequence = new EndSequenceWalkLeft();
00564     } else {
00565       end_sequence = new EndSequenceWalkRight();
00566     }
00567   } else if (sequencename == "fireworks") {
00568     end_sequence = new EndSequenceFireworks();
00569   } else {
00570     log_warning << "Unknown sequence '" << sequencename << "'. Ignoring." << std::endl;
00571     return;
00572   }
00573 
00574   /* slow down the game for end-sequence */
00575   g_screen_manager->set_speed(0.5f);
00576 
00577   currentsector->add_object(end_sequence);
00578   end_sequence->start();
00579 
00580   sound_manager->play_music("music/leveldone.ogg", false);
00581   currentsector->player->set_winning();
00582 
00583   // Stop all clocks.
00584   for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();
00585       i != currentsector->gameobjects.end(); ++i)
00586   {
00587     GameObject* obj = *i;
00588 
00589     LevelTime* lt = dynamic_cast<LevelTime*> (obj);
00590     if(lt)
00591       lt->stop();
00592   }
00593 }

std::string GameSession::get_working_directory (  ) 

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

Definition at line 533 of file game_session.cpp.

References FileSystem::dirname(), and levelfile.

00534 {
00535   return FileSystem::dirname(levelfile);
00536 }

int GameSession::restart_level (  ) 

Definition at line 86 of file game_session.cpp.

References Sector::activate(), capture_file, currentsector, edit_mode, end_sequence, ScreenManager::exit_screen(), force_ghost_mode(), g_config, g_jk_controller, g_screen_manager, game_pause, gameRandom, level, LEVEL_MUSIC, levelfile, log_fatal, log_info, Sector::play_music(), play_time, RandomGenerator::rand(), Config::random_seed, record_demo(), JoystickKeyboardController::reset(), reset_pos, reset_sector, sound_manager, RandomGenerator::srand(), and SoundManager::stop_music().

Referenced by check_end_conditions(), GameSession(), scripting::play_demo(), scripting::record_demo(), scripting::restart(), and set_editmode().

00087 {
00088 
00089   if (edit_mode) {
00090     force_ghost_mode();
00091     return (-1);
00092   }
00093 
00094   game_pause   = false;
00095   end_sequence = 0;
00096 
00097   g_jk_controller->reset();
00098 
00099   currentsector = 0;
00100 
00101   level.reset(new Level);
00102   try {
00103     level->load(levelfile);
00104     level->stats.total_coins = level->get_total_coins();
00105     level->stats.total_badguys = level->get_total_badguys();
00106     level->stats.total_secrets = level->get_total_secrets();
00107     level->stats.reset();
00108 
00109     if(reset_sector != "") {
00110       currentsector = level->get_sector(reset_sector);
00111       if(!currentsector) {
00112         std::stringstream msg;
00113         msg << "Couldn't find sector '" << reset_sector << "' for resetting tux.";
00114         throw std::runtime_error(msg.str());
00115       }
00116       level->stats.declare_invalid();
00117       currentsector->activate(reset_pos);
00118     } else {
00119       currentsector = level->get_sector("main");
00120       if(!currentsector)
00121         throw std::runtime_error("Couldn't find main sector");
00122       play_time = 0;
00123       currentsector->activate("main");
00124     }
00125   } catch(std::exception& e) {
00126     log_fatal << "Couldn't start level: " << e.what() << std::endl;
00127     g_screen_manager->exit_screen();
00128     return (-1);
00129   }
00130 
00131   sound_manager->stop_music();
00132   currentsector->play_music(LEVEL_MUSIC);
00133 
00134   if(capture_file != "") {
00135     int newSeed=0;               // next run uses a new seed
00136     while (newSeed == 0)            // which is the next non-zero random num.
00137       newSeed = gameRandom.rand();
00138     g_config->random_seed = gameRandom.srand(newSeed);
00139     log_info << "Next run uses random seed " << g_config->random_seed <<std::endl;
00140     record_demo(capture_file);
00141   }
00142 
00143   return (0);
00144 }

void GameSession::toggle_pause (  ) 

Definition at line 239 of file game_session.cpp.

References g_screen_manager, game_menu, game_pause, ScreenManager::get_speed(), MNID_CONTINUE, MenuManager::set_current(), ScreenManager::set_speed(), and speed_before_pause.

Referenced by scripting::Level_toggle_pause(), on_escape_press(), and process_menu().

00240 {
00241   // pause
00242   if(!game_pause) {
00243     speed_before_pause = g_screen_manager->get_speed();
00244     g_screen_manager->set_speed(0);
00245     MenuManager::set_current(game_menu.get());
00246     game_menu->set_active_item(MNID_CONTINUE);
00247     game_pause = true;
00248   }
00249 
00250   // unpause is done in update() after the menu is processed
00251 }

void GameSession::set_editmode ( bool  edit_mode = true  ) 

Enters or leaves level editor mode.

Definition at line 254 of file game_session.cpp.

References currentsector, Sector::get_players(), and restart_level().

Referenced by scripting::Level_edit().

00255 {
00256   if (this->edit_mode == edit_mode) return;
00257   this->edit_mode = edit_mode;
00258 
00259   currentsector->get_players()[0]->set_edit_mode(edit_mode);
00260 
00261   if (edit_mode) {
00262 
00263     // entering edit mode
00264 
00265   } else {
00266 
00267     // leaving edit mode
00268     restart_level();
00269 
00270   }
00271 }

void GameSession::force_ghost_mode (  ) 

Forces all Players to enter ghost mode.

Definition at line 274 of file game_session.cpp.

References currentsector, and Sector::get_players().

Referenced by finish(), restart_level(), and start_sequence().

00275 {
00276   currentsector->get_players()[0]->set_ghost_mode(true);
00277 }

void GameSession::check_end_conditions (  )  [private]

Definition at line 358 of file game_session.cpp.

References currentsector, end_sequence, finish(), Player::is_dead(), EndSequence::is_done(), Sector::player, and restart_level().

Referenced by update().

00359 {
00360   Player* tux = currentsector->player;
00361 
00362   /* End of level? */
00363   if(end_sequence && end_sequence->is_done()) {
00364     finish(true);
00365   } else if (!end_sequence && tux->is_dead()) {
00366     restart_level();
00367   }
00368 }

void GameSession::process_events (  )  [private]

Definition at line 310 of file game_session.cpp.

References Controller::ACTION, capture_demo_stream, demo_controller, Controller::DOWN, g_jk_controller, JoystickKeyboardController::get_main_controller(), Controller::hold(), Controller::JUMP, Controller::LEFT, playback_demo_stream, CodeController::press(), Controller::RIGHT, Controller::UP, and CodeController::update().

Referenced by update().

00311 {
00312   // end of pause mode?
00313   // XXX this looks like a fail-safe to unpause the game if there's no menu
00314   // XXX having it enabled causes some unexpected problems
00315   // XXX hopefully disabling it won't...
00316   /*
00317     if(!Menu::current() && game_pause) {
00318     game_pause = false;
00319     }
00320   */
00321 
00322   // playback a demo?
00323   if(playback_demo_stream != 0) {
00324     demo_controller->update();
00325     char left = false;
00326     char right = false;
00327     char up = false;
00328     char down = false;
00329     char jump = false;
00330     char action = false;
00331     playback_demo_stream->get(left);
00332     playback_demo_stream->get(right);
00333     playback_demo_stream->get(up);
00334     playback_demo_stream->get(down);
00335     playback_demo_stream->get(jump);
00336     playback_demo_stream->get(action);
00337     demo_controller->press(Controller::LEFT, left);
00338     demo_controller->press(Controller::RIGHT, right);
00339     demo_controller->press(Controller::UP, up);
00340     demo_controller->press(Controller::DOWN, down);
00341     demo_controller->press(Controller::JUMP, jump);
00342     demo_controller->press(Controller::ACTION, action);
00343   }
00344 
00345   // save input for demo?
00346   if(capture_demo_stream != 0) {
00347     Controller *controller = g_jk_controller->get_main_controller();
00348     capture_demo_stream ->put(controller->hold(Controller::LEFT));
00349     capture_demo_stream ->put(controller->hold(Controller::RIGHT));
00350     capture_demo_stream ->put(controller->hold(Controller::UP));
00351     capture_demo_stream ->put(controller->hold(Controller::DOWN));
00352     capture_demo_stream ->put(controller->hold(Controller::JUMP));
00353     capture_demo_stream ->put(controller->hold(Controller::ACTION));
00354   }
00355 }

void GameSession::capture_demo_step (  )  [private]

void GameSession::drawstatus ( DrawingContext context  )  [private]

Definition at line 597 of file game_session.cpp.

References best_level_statistics, PlayerStatus::draw(), end_sequence, level, player_status, and statistics_backdrop.

Referenced by draw().

00598 {
00599   player_status->draw(context);
00600 
00601   // draw level stats while end_sequence is running
00602   if (end_sequence) {
00603     level->stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop);
00604   }
00605 }

void GameSession::draw_pause ( DrawingContext context  )  [private]

Definition at line 381 of file game_session.cpp.

References DrawingContext::draw_filled_rect(), LAYER_FOREGROUND1, SCREEN_HEIGHT, and SCREEN_WIDTH.

Referenced by draw().

00382 {
00383   context.draw_filled_rect(
00384     Vector(0,0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
00385     Color(0.0f, 0.0f, 0.0f, .25f), LAYER_FOREGROUND1);
00386 }

HSQUIRRELVM GameSession::run_script ( std::istream &  in,
const std::string &  sourcename 
) [private]

Definition at line 280 of file game_session.cpp.

References scripting::compile_and_run(), scripting::create_thread(), scripting::global_vm, scripting::object_to_vm(), and scripts.

Referenced by on_escape_press().

00281 {
00282   using namespace scripting;
00283 
00284   // garbage collect thread list
00285   for(ScriptList::iterator i = scripts.begin();
00286       i != scripts.end(); ) {
00287     HSQOBJECT& object = *i;
00288     HSQUIRRELVM vm = object_to_vm(object);
00289 
00290     if(sq_getvmstate(vm) != SQ_VMSTATE_SUSPENDED) {
00291       sq_release(global_vm, &object);
00292       i = scripts.erase(i);
00293       continue;
00294     }
00295 
00296     ++i;
00297   }
00298 
00299   HSQOBJECT object = create_thread(global_vm);
00300   scripts.push_back(object);
00301 
00302   HSQUIRRELVM vm = object_to_vm(object);
00303 
00304   compile_and_run(vm, in, sourcename);
00305 
00306   return vm;
00307 }

void GameSession::on_escape_press (  )  [private]

Definition at line 218 of file game_session.cpp.

References currentsector, Player::dying_timer, end_sequence, Player::is_dying(), level, Sector::player, run_script(), Timer::start(), and toggle_pause().

Referenced by update().

00219 {
00220   if(currentsector->player->is_dying() || end_sequence)
00221   {
00222     // Let the timers run out, we fast-forward them to force past a sequence
00223     if (end_sequence)
00224       end_sequence->stop();
00225 
00226     currentsector->player->dying_timer.start(FLT_EPSILON);
00227     return;   // don't let the player open the menu, when he is dying
00228   }
00229 
00230   if(level->on_menukey_script != "") {
00231     std::istringstream in(level->on_menukey_script);
00232     run_script(in, "OnMenuKeyScript");
00233   } else {
00234     toggle_pause();
00235   }
00236 }

void GameSession::process_menu (  )  [private]

Definition at line 389 of file game_session.cpp.

References MenuManager::current(), ScreenManager::exit_screen(), g_screen_manager, game_menu, MNID_ABORTLEVEL, MNID_CONTINUE, MenuManager::set_current(), and toggle_pause().

Referenced by update().

00390 {
00391   Menu* menu = MenuManager::current();
00392   if(menu) {
00393     if(menu == game_menu.get()) {
00394       switch (game_menu->check()) {
00395         case MNID_CONTINUE:
00396           MenuManager::set_current(0);
00397           toggle_pause();
00398           break;
00399         case MNID_ABORTLEVEL:
00400           MenuManager::set_current(0);
00401           g_screen_manager->exit_screen();
00402           break;
00403       }
00404     }
00405   }
00406 }

GameSession& GameSession::operator= ( const GameSession  )  [private]


Member Data Documentation

std::auto_ptr<Level> GameSession::level [private]

Definition at line 108 of file game_session.hpp.

Referenced by drawstatus(), finish(), GameSession(), get_current_level(), on_escape_press(), restart_level(), setup(), and update().

SurfacePtr GameSession::statistics_backdrop [private]

Definition at line 109 of file game_session.hpp.

Referenced by drawstatus(), and GameSession().

ScriptList GameSession::scripts [private]

Definition at line 113 of file game_session.hpp.

Referenced by run_script().

Sector* GameSession::currentsector [private]

Definition at line 115 of file game_session.hpp.

Referenced by check_end_conditions(), draw(), force_ghost_mode(), GameSession(), get_current_sector(), on_escape_press(), play_demo(), restart_level(), set_editmode(), setup(), start_sequence(), and update().

int GameSession::levelnb [private]

Definition at line 117 of file game_session.hpp.

int GameSession::pause_menu_frame [private]

Definition at line 118 of file game_session.hpp.

EndSequence* GameSession::end_sequence [private]

Definition at line 120 of file game_session.hpp.

Referenced by check_end_conditions(), drawstatus(), on_escape_press(), restart_level(), start_sequence(), and update().

bool GameSession::game_pause [private]

Definition at line 122 of file game_session.hpp.

Referenced by draw(), GameSession(), restart_level(), toggle_pause(), and update().

float GameSession::speed_before_pause [private]

Definition at line 123 of file game_session.hpp.

Referenced by GameSession(), toggle_pause(), and update().

std::string GameSession::levelfile [private]

Definition at line 125 of file game_session.hpp.

Referenced by get_working_directory(), and restart_level().

std::string GameSession::reset_sector [private]

Definition at line 128 of file game_session.hpp.

Referenced by get_reset_point_sectorname(), restart_level(), and set_reset_point().

Vector GameSession::reset_pos [private]

Definition at line 129 of file game_session.hpp.

Referenced by get_reset_point_pos(), restart_level(), and set_reset_point().

std::string GameSession::newsector [private]

Definition at line 132 of file game_session.hpp.

Referenced by respawn(), and update().

std::string GameSession::newspawnpoint [private]

Definition at line 133 of file game_session.hpp.

Referenced by respawn(), and update().

Statistics* GameSession::best_level_statistics [private]

Definition at line 135 of file game_session.hpp.

Referenced by drawstatus(), and setup().

PlayerStatus* GameSession::player_status [private]

Definition at line 136 of file game_session.hpp.

Referenced by drawstatus(), and get_player_status().

std::ostream* GameSession::capture_demo_stream [private]

Definition at line 138 of file game_session.hpp.

Referenced by process_events(), record_demo(), and ~GameSession().

std::string GameSession::capture_file [private]

Definition at line 139 of file game_session.hpp.

Referenced by record_demo(), and restart_level().

std::istream* GameSession::playback_demo_stream [private]

Definition at line 140 of file game_session.hpp.

Referenced by play_demo(), process_events(), and ~GameSession().

CodeController* GameSession::demo_controller [private]

Definition at line 141 of file game_session.hpp.

Referenced by play_demo(), process_events(), and ~GameSession().

std::auto_ptr<Menu> GameSession::game_menu [private]

Definition at line 143 of file game_session.hpp.

Referenced by GameSession(), process_menu(), and toggle_pause().

float GameSession::play_time [private]

total time in seconds that this session ran interactively

Definition at line 145 of file game_session.hpp.

Referenced by restart_level(), and update().

bool GameSession::edit_mode [private]

true if GameSession runs in level editor mode

Definition at line 147 of file game_session.hpp.

Referenced by finish(), restart_level(), start_sequence(), and update().

bool GameSession::levelintro_shown [private]

true if the LevelIntro screen was already shown

Definition at line 148 of file game_session.hpp.

Referenced by setup().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:30 2014 for SuperTux by  doxygen 1.5.1