void fadeout_screen(float seconds)
{
- g_screen_manager->set_screen_fade(new FadeOut(seconds));
+ g_screen_manager->set_screen_fade(std::unique_ptr<ScreenFade>(new FadeOut(seconds)));
}
void shrink_screen(float dest_x, float dest_y, float seconds)
{
- g_screen_manager->set_screen_fade(new ShrinkFade(Vector(dest_x, dest_y), seconds));
+ g_screen_manager->set_screen_fade(std::unique_ptr<ScreenFade>(new ShrinkFade(Vector(dest_x, dest_y), seconds)));
}
void abort_screenfade()
{
- g_screen_manager->set_screen_fade(NULL);
+ g_screen_manager->set_screen_fade(std::unique_ptr<ScreenFade>());
}
std::string translate(const std::string& text)
void display_text_file(const std::string& filename)
{
- g_screen_manager->push_screen(new TextScroller(filename));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new TextScroller(filename)));
}
void load_worldmap(const std::string& filename)
if(World::current() == NULL)
throw std::runtime_error("Can't start WorldMap without active world.");
- g_screen_manager->push_screen(new WorldMap(filename, World::current()->get_player_status()));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new WorldMap(filename, World::current()->get_player_status())));
}
void load_level(const std::string& filename)
if(GameSession::current() == NULL)
throw std::runtime_error("Can't start level without active level.");
- g_screen_manager->push_screen(new GameSession(filename, GameSession::current()->get_player_status()));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new GameSession(filename, GameSession::current()->get_player_status())));
}
void import(HSQUIRRELVM vm, const std::string& filename)
#include "object/player.hpp"
#include "scripting/squirrel_util.hpp"
#include "supertux/gameconfig.hpp"
-#include "supertux/levelintro.hpp"
#include "supertux/globals.hpp"
-#include "supertux/player_status.hpp"
-#include "supertux/screen_manager.hpp"
-#include "supertux/menu/menu_storage.hpp"
+#include "supertux/levelintro.hpp"
#include "supertux/menu/game_menu.hpp"
+#include "supertux/menu/menu_storage.hpp"
#include "supertux/menu/options_menu.hpp"
+#include "supertux/player_status.hpp"
+#include "supertux/screen_fade.hpp"
+#include "supertux/screen_manager.hpp"
#include "supertux/sector.hpp"
#include "util/file_system.hpp"
#include "util/gettext.hpp"
int total_stats_to_be_collected = level->stats.total_coins + level->stats.total_badguys + level->stats.total_secrets;
if ((!levelintro_shown) && (total_stats_to_be_collected > 0)) {
levelintro_shown = true;
- g_screen_manager->push_screen(new LevelIntro(level.get(), best_level_statistics));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new LevelIntro(level.get(), best_level_statistics)));
}
}
|| controller->pressed(Controller::ACTION)
|| controller->pressed(Controller::MENU_SELECT)
|| controller->pressed(Controller::PAUSE_MENU)) {
- g_screen_manager->exit_screen(new FadeOut(0.1));
+ g_screen_manager->exit_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.1)));
}
player_sprite_py += player_sprite_vy * elapsed_time;
#include "control/input_manager.hpp"
#include "math/random_generator.hpp"
#include "physfs/ifile_stream.hpp"
-#include "physfs/physfs_sdl.hpp"
#include "physfs/physfs_file_system.hpp"
+#include "physfs/physfs_sdl.hpp"
#include "scripting/squirrel_util.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
#include "supertux/player_status.hpp"
-#include "supertux/screen_manager.hpp"
#include "supertux/resources.hpp"
+#include "supertux/screen_fade.hpp"
+#include "supertux/screen_manager.hpp"
#include "supertux/title_screen.hpp"
#include "util/file_system.hpp"
#include "util/gettext.hpp"
if(g_config->start_level.size() > 4 &&
g_config->start_level.compare(g_config->start_level.size() - 5, 5, ".stwm") == 0) {
- g_screen_manager->push_screen(new worldmap::WorldMap(
- FileSystem::basename(g_config->start_level), default_playerstatus.get()));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(
+ new worldmap::WorldMap(
+ FileSystem::basename(g_config->start_level), default_playerstatus.get())));
} else {
std::unique_ptr<GameSession> session (
new GameSession(FileSystem::basename(g_config->start_level), default_playerstatus.get()));
if(g_config->record_demo != "")
session->record_demo(g_config->record_demo);
- g_screen_manager->push_screen(session.release());
+ g_screen_manager->push_screen(std::move(session));
}
} else {
- g_screen_manager->push_screen(new TitleScreen(default_playerstatus.get()));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new TitleScreen(default_playerstatus.get())));
}
g_screen_manager->run(context);
#include "audio/sound_manager.hpp"
#include "gui/menu_item.hpp"
#include "supertux/globals.hpp"
+#include "supertux/screen_fade.hpp"
#include "supertux/screen_manager.hpp"
#include "supertux/title_screen.hpp"
#include "supertux/world.hpp"
if (get_item_by_id(index).kind == MN_ACTION)
{
sound_manager->stop_music();
- GameSession* session = new GameSession(m_current_world.get_level_filename(index), m_current_world.get_player_status());
- g_screen_manager->push_screen(session);
+ g_screen_manager->push_screen(
+ std::unique_ptr<Screen>(
+ new GameSession(m_current_world.get_level_filename(index), m_current_world.get_player_status())));
}
}
}
#include "supertux/menu/addon_menu.hpp"
#include "supertux/menu/options_menu.hpp"
#include "supertux/menu/contrib_menu.hpp"
+#include "supertux/screen_fade.hpp"
#include "supertux/screen_manager.hpp"
#include "supertux/textscroller.hpp"
#include "supertux/title_screen.hpp"
case MNID_CREDITS:
MenuManager::instance().set_current(NULL);
- g_screen_manager->push_screen(new TextScroller("credits.txt"),
- new FadeOut(0.5));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new TextScroller("credits.txt")),
+ std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
break;
case MNID_QUITMAINMENU:
- g_screen_manager->quit(new FadeOut(0.25));
+ g_screen_manager->quit(std::unique_ptr<ScreenFade>(new FadeOut(0.25)));
sound_manager->stop_music(0.25);
break;
}
#include "gui/menu_manager.hpp"
#include "supertux/menu/menu_storage.hpp"
#include "supertux/menu/options_menu.hpp"
+#include "supertux/screen_fade.hpp"
#include "supertux/screen_manager.hpp"
#include "util/gettext.hpp"
using namespace scripting;
delete TimeScheduler::instance;
TimeScheduler::instance = NULL;
-
- for(std::vector<Screen*>::iterator i = screen_stack.begin();
- i != screen_stack.end(); ++i) {
- delete *i;
- }
}
void
-ScreenManager::push_screen(Screen* screen, ScreenFade* screen_fade)
+ScreenManager::push_screen(std::unique_ptr<Screen> screen, std::unique_ptr<ScreenFade> screen_fade)
{
- this->next_screen.reset(screen);
- this->screen_fade.reset(screen_fade);
+ assert(!this->next_screen);
+ this->next_screen = std::move(screen);
+ this->screen_fade = std::move(screen_fade);
nextpush = !nextpop;
nextpop = false;
speed = 1.0f;
}
void
-ScreenManager::exit_screen(ScreenFade* screen_fade)
+ScreenManager::exit_screen(std::unique_ptr<ScreenFade> screen_fade)
{
- next_screen.reset(NULL);
- this->screen_fade.reset(screen_fade);
+ next_screen.reset();
+ this->screen_fade = std::move(screen_fade);
nextpop = true;
nextpush = false;
}
void
-ScreenManager::set_screen_fade(ScreenFade* screen_fade)
+ScreenManager::set_screen_fade(std::unique_ptr<ScreenFade> screen_fade)
{
- this->screen_fade.reset(screen_fade);
+ this->screen_fade = std::move(screen_fade);
}
void
-ScreenManager::quit(ScreenFade* screen_fade)
+ScreenManager::quit(std::unique_ptr<ScreenFade> screen_fade)
{
- for(std::vector<Screen*>::iterator i = screen_stack.begin();
- i != screen_stack.end(); ++i)
- delete *i;
screen_stack.clear();
-
- exit_screen(screen_fade);
+ exit_screen(std::move(screen_fade));
}
void
void
ScreenManager::handle_screen_switch()
{
- while( (next_screen.get() != NULL || nextpop) &&
- has_no_pending_fadeout()) {
- if(current_screen.get() != NULL) {
+ while((next_screen || nextpop) &&
+ has_no_pending_fadeout())
+ {
+ if(current_screen) {
current_screen->leave();
}
running = false;
break;
}
- next_screen.reset(screen_stack.back());
+ next_screen = std::move(screen_stack.back());
screen_stack.pop_back();
}
- if(nextpush && current_screen.get() != NULL) {
- screen_stack.push_back(current_screen.release());
+ if(nextpush && current_screen) {
+ screen_stack.push_back(std::move(current_screen));
}
nextpush = false;
nextpop = false;
speed = 1.0;
- Screen* next_screen_ptr = next_screen.release();
- next_screen.reset(0);
- if(next_screen_ptr)
- next_screen_ptr->setup();
- current_screen.reset(next_screen_ptr);
- screen_fade.reset(NULL);
+ current_screen = std::move(next_screen);
+ if(current_screen)
+ current_screen->setup();
+ screen_fade.reset();
waiting_threads.wakeup();
}
while(running) {
handle_screen_switch();
- if(!running || current_screen.get() == NULL)
+ if(!running || !current_screen)
break;
Uint32 ticks = SDL_GetTicks();
~ScreenManager();
void run(DrawingContext &context);
- void exit_screen(ScreenFade* fade = NULL);
- void quit(ScreenFade* fade = NULL);
+ void exit_screen(std::unique_ptr<ScreenFade> fade = {});
+ void quit(std::unique_ptr<ScreenFade> fade = {});
void set_speed(float speed);
float get_speed() const;
bool has_no_pending_fadeout() const;
void take_screenshot();
// push new screen on screen_stack
- void push_screen(Screen* screen, ScreenFade* fade = NULL);
- void set_screen_fade(ScreenFade* fade);
+ void push_screen(std::unique_ptr<Screen> screen, std::unique_ptr<ScreenFade> fade = {});
+ void set_screen_fade(std::unique_ptr<ScreenFade> fade);
/// threads that wait for a screenswitch
scripting::ThreadQueue waiting_threads;
std::unique_ptr<Screen> current_screen;
std::unique_ptr<Console> console;
std::unique_ptr<ScreenFade> screen_fade;
- std::vector<Screen*> screen_stack;
+ std::vector<std::unique_ptr<Screen> > screen_stack;
bool screenshot_requested; /**< true if a screenshot should be taken after the next frame has been rendered */
};
)&& !(controller->pressed(Controller::UP))) // prevent skipping if jump with up is enabled
scroll += SCROLL;
if(controller->pressed(Controller::PAUSE_MENU)) {
- g_screen_manager->exit_screen(new FadeOut(0.5));
+ g_screen_manager->exit_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
}
scroll += speed * elapsed_time;
if(y < 0 && !fading ) {
fading = true;
- g_screen_manager->exit_screen(new FadeOut(0.5));
+ g_screen_manager->exit_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
}
}
#include "scripting/serialize.hpp"
#include "scripting/squirrel_util.hpp"
#include "supertux/globals.hpp"
+#include "supertux/screen_fade.hpp"
#include "supertux/screen_manager.hpp"
#include "supertux/player_status.hpp"
#include "supertux/world.hpp"
} catch(std::exception& ) {
// fallback: try to load worldmap worldmap.stwm
using namespace worldmap;
- g_screen_manager->push_screen(new WorldMap(basedir + "worldmap.stwm", get_player_status()));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new WorldMap(basedir + "worldmap.stwm", get_player_status())));
}
}
WorldMap::change(const std::string& filename, const std::string& force_spawnpoint)
{
g_screen_manager->exit_screen();
- g_screen_manager->push_screen(new WorldMap(filename, player_status, force_spawnpoint));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new WorldMap(filename, player_status, force_spawnpoint)));
}
void
// update state and savegame
save_state();
- g_screen_manager->push_screen(new GameSession(levelfile, player_status, &level->statistics),
- new ShrinkFade(shrinkpos, 1.0f));
+ g_screen_manager->push_screen(std::unique_ptr<Screen>(new GameSession(levelfile, player_status, &level->statistics)),
+ std::unique_ptr<ScreenFade>(new ShrinkFade(shrinkpos, 1.0f)));
in_level = true;
} catch(std::exception& e) {
log_fatal << "Couldn't load level: " << e.what() << std::endl;