(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(particles-snow
(layer -200)
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(top_color 0.0 0.0 0.0)
(bottom_color 0.0 0.0 0.4)
)
- (leveltime
- (time 300)
- )
(particles-snow
(layer -200)
)
(top_color 0.0 0.0 0.0)
(bottom_color 0.0 0.0 0.4)
)
- (leveltime
- (time 300)
- )
(particles-snow
(layer -200)
)
(top_color 0.4 0.6 1.0)
(bottom_color 1.0 1.0 1.0)
)
- (leveltime
- (time 200)
- )
(particles-clouds
(layer -200)
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/cave2.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/cave2.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/cave2.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/cave2.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/cave2.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/cave2.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/arctis.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(image "images/background/ocean.jpg")
(speed 0.500000)
)
- (leveltime
- (time 300.000000)
- )
(spawnpoint (name "main") (x 96) (y 160))
(firefly (x 6860) (y 222))
(mriceblock (x 757) (y 221))
(image "images/background/ocean.jpg")
(speed 0.5)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
(top_color 0.0 0.0 0.0)
(bottom_color 0.6 0.0 0.0)
)
- (leveltime
- (time 300)
- )
(camera
(mode "normal")
)
)
(spawnpoint (name "main") (x 480) (y 448))
(init-script "
-DisplayEffect.fade_in(2.5);
+Effect.fade_in(1);
")
(yeti
(x 2)
Text.set_font(\"big\");
Text.fade_in(1.5);
wait(6);
-DisplayEffect.fade_out(1.5);
+Effect.fade_out(1.5);
wait(1.5);
-
-
-
-Level.finish();
+Level.finish(true);
")
)
(particles-snow
+++ /dev/null
-;; Generated by Flexlay Editor
-(supertux-level
- (version 2)
- (name (_ "Yeti Test"))
- (author "Team")
- (sector
- (name "main")
- (music "music/bossattack.ogg")
- (gravity 10.000000)
- (tilemap
- (layer "background")
- (solid #f)
- (speed 1.000000)
- (width 25)
- (height 20)
- (tiles
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 8 8 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 8 8
- 14 14 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 14 14
- 11 11 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 11 11
- 11 11 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 11 11
- 11 11 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 11 11
- 11 11 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 11 11
- 11 11 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 11 11
- 11 11 21 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 22 11 11
- 11 11 20 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 23 11 11
- ))
- (tilemap
- (layer "foreground")
- (solid #f)
- (speed 1.000000)
- (width 25)
- (height 20)
- (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0 0 0 0 0 0 0 0 0 0
- ))
- (camera
- (mode "normal")
- )
-
- (background
- (image "images/background/semi_arctic.jpg")
- (speed 0.500000)
- )
- (spawnpoint (name "main") (x 480) (y 448))
- (init-script "
-DisplayEffect.fade_in(2.5);
-")
- (yeti
- (x 2)
- (y 177)
- (dead-script "
-Sound.play(\"sounds/invincible.wav\");
-Text.set_text(\"You Made It BIG TIME!\");
-Text.set_font(\"big\");
-Text.fade_in(1.5);
-wait(6);
-DisplayEffect.fade_out(1.5);
-wait(1.5);
-
-
-
-Level.finish();
-")
- )
- (particles-snow
- )
- (yeti_stalactite (x 97) (y 32))
- (yeti_stalactite (x 128) (y 32))
- (yeti_stalactite (x 161) (y 32))
- (yeti_stalactite (x 191) (y 32))
- (yeti_stalactite (x 223) (y 32))
- (yeti_stalactite (x 255) (y 32))
- (yeti_stalactite (x 288) (y 32))
- (yeti_stalactite (x 321) (y 32))
- (yeti_stalactite (x 352) (y 32))
- (yeti_stalactite (x 384) (y 32))
- (yeti_stalactite (x 417) (y 32))
- (yeti_stalactite (x 576) (y 32))
- (yeti_stalactite (x 545) (y 32))
- (yeti_stalactite (x 512) (y 32))
- (yeti_stalactite (x 479) (y 32))
- (yeti_stalactite (x 448) (y 32))
- (yeti_stalactite (x 607) (y 32))
- (yeti_stalactite (x 639) (y 32))
- (yeti_stalactite (x 671) (y 32))
- )
- )
-
-;; EOF ;;
#include "main.hpp"
#include "resources.hpp"
-namespace {
- int ticks; // TODO: use a clock?
-}
+/// speed (pixels/s) the console closes
+static const float CLOSE_SPEED = 50;
Console::Console()
+ : backgroundOffset(0), height(0), offset(0), focused(false), stayOpen(0)
{
- background = new Surface("images/engine/console.png");
- background2 = new Surface("images/engine/console2.png");
+ background.reset(new Surface("images/engine/console.png"));
+ background2.reset(new Surface("images/engine/console2.png"));
}
Console::~Console()
{
- delete background;
- delete background2;
}
void
if (height < 4+9) height=4+9;
height+=9;
}
- ticks=60;
+
+ if(stayOpen < 5)
+ stayOpen += 0.7;
}
void
{
focused = false;
height = 0;
+ stayOpen = 0;
// clear input buffer
inputBuffer.str(std::string());
}
}
+void
+Console::update(float elapsed_time)
+{
+ if(stayOpen > 0) {
+ stayOpen -= elapsed_time;
+ if(stayOpen < 0)
+ stayOpen = 0;
+ } else if(!focused && height > 0) {
+ height -= elapsed_time * CLOSE_SPEED;
+ if(height < 0)
+ height = 0;
+ }
+}
+
void
Console::draw(DrawingContext& context)
{
- if (height == 0) return;
- if (!focused) {
- if (ticks-- < 0) {
- height-=10;
- ticks=0;
- if (height < 0) height=0;
- }
- if (height == 0) return;
- }
+ if (height == 0)
+ return;
- context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), LAYER_FOREGROUND1+1);
- context.draw_surface(background2, Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), LAYER_FOREGROUND1+1);
- context.draw_surface(background, Vector(SCREEN_WIDTH/2 - background->get_width()/2, height - background->get_height()), LAYER_FOREGROUND1+1);
+ context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 - background->get_width() + backgroundOffset, height - background->get_height()), LAYER_FOREGROUND1+1);
+ context.draw_surface(background2.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 + backgroundOffset, height - background->get_height()), LAYER_FOREGROUND1+1);
+ context.draw_surface(background.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2, height - background->get_height()), LAYER_FOREGROUND1+1);
backgroundOffset+=10;
if (backgroundOffset > (int)background->get_width()) backgroundOffset -= (int)background->get_width();
}
}
-int Console::height = 0;
-bool Console::focused = false;
-std::list<std::string> Console::lines;
-std::map<std::string, std::list<ConsoleCommandReceiver*> > Console::commands;
+Console* Console::instance = NULL;
ConsoleStreamBuffer Console::inputBuffer;
ConsoleStreamBuffer Console::outputBuffer;
std::ostream Console::input(&Console::inputBuffer);
std::ostream Console::output(&Console::outputBuffer);
-int Console::offset = 0;
-int Console::backgroundOffset = 0;
class Console
{
- public:
- Console();
- ~Console();
-
- static std::ostream input; /**< stream of keyboard input to send to the console. Do not forget to send std::endl or to flush the stream. */
- static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */
-
- static void backspace(); /**< delete last character sent to the input stream */
- static void scroll(int offset); /**< scroll console text up or down by @c offset lines */
- static void autocomplete(); /**< autocomplete current command */
-
- void draw(DrawingContext& context); /**< draw the console in a DrawingContext */
- static void show(); /**< display the console */
- static void hide(); /**< hide the console */
- static void toggle(); /**< display the console if hidden, hide otherwise */
-
- static bool hasFocus(); /**< true if characters should be sent to the console instead of their normal target */
- static void registerCommand(std::string command, ConsoleCommandReceiver* ccr); /**< associate command with the given CCR */
- static void unregisterCommand(std::string command, ConsoleCommandReceiver* ccr); /**< dissociate command and CCR */
- static void unregisterCommands(ConsoleCommandReceiver* ccr); /**< dissociate all commands of given CCR */
-
- template<typename T> static bool string_is(std::string s) {
- std::istringstream iss(s);
- T i;
- if ((iss >> i) && iss.eof()) {
- return true;
- } else {
- return false;
- }
+public:
+ Console();
+ ~Console();
+
+ static Console* instance;
+
+ static std::ostream input; /**< stream of keyboard input to send to the console. Do not forget to send std::endl or to flush the stream. */
+ static std::ostream output; /**< stream of characters to output to the console. Do not forget to send std::endl or to flush the stream. */
+
+ void backspace(); /**< delete last character sent to the input stream */
+ void scroll(int offset); /**< scroll console text up or down by @c offset lines */
+ void autocomplete(); /**< autocomplete current command */
+
+ void draw(DrawingContext& context); /**< draw the console in a DrawingContext */
+ void update(float elapsed_time);
+
+ void show(); /**< display the console */
+ void hide(); /**< hide the console */
+ void toggle(); /**< display the console if hidden, hide otherwise */
+
+ bool hasFocus(); /**< true if characters should be sent to the console instead of their normal target */
+ void registerCommand(std::string command, ConsoleCommandReceiver* ccr); /**< associate command with the given CCR */
+ void unregisterCommand(std::string command, ConsoleCommandReceiver* ccr); /**< dissociate command and CCR */
+ void unregisterCommands(ConsoleCommandReceiver* ccr); /**< dissociate all commands of given CCR */
+
+ template<typename T> static bool string_is(std::string s) {
+ std::istringstream iss(s);
+ T i;
+ if ((iss >> i) && iss.eof()) {
+ return true;
+ } else {
+ return false;
}
+ }
- template<typename T> static T string_to(std::string s) {
- std::istringstream iss(s);
- T i;
- if ((iss >> i) && iss.eof()) {
- return i;
- } else {
- return T();
- }
+ template<typename T> static T string_to(std::string s) {
+ std::istringstream iss(s);
+ T i;
+ if ((iss >> i) && iss.eof()) {
+ return i;
+ } else {
+ return T();
}
+ }
- protected:
- static std::list<std::string> lines; /**< backbuffer of lines sent to the console */
- static std::map<std::string, std::list<ConsoleCommandReceiver*> > commands; /**< map of console commands and a list of associated ConsoleCommandReceivers */
- Surface* background; /**< console background image */
- Surface* background2; /**< second, moving console background image */
- static int backgroundOffset; /**< current offset of scrolling background image */
- static int height; /**< height of the console in px */
- static int offset; /**< decrease to scroll text up */
- static bool focused; /**< true if console has input focus */
-
- static ConsoleStreamBuffer inputBuffer; /**< stream buffer used by input stream */
- static ConsoleStreamBuffer outputBuffer; /**< stream buffer used by output stream */
-
- static void addLine(std::string s); /**< display a line in the console */
- static void parse(std::string s); /**< react to a given command */
+private:
+ std::list<std::string> lines; /**< backbuffer of lines sent to the console */
+ std::map<std::string, std::list<ConsoleCommandReceiver*> > commands; /**< map of console commands and a list of associated ConsoleCommandReceivers */
+
+ std::auto_ptr<Surface> background; /**< console background image */
+ std::auto_ptr<Surface> background2; /**< second, moving console background image */
+
+ int backgroundOffset; /**< current offset of scrolling background image */
+ float height; /**< height of the console in px */
+ int offset; /**< decrease to scroll text up */
+ bool focused; /**< true if console has input focus */
+
+ float stayOpen;
+
+ static ConsoleStreamBuffer inputBuffer; /**< stream buffer used by input stream */
+ static ConsoleStreamBuffer outputBuffer; /**< stream buffer used by output stream */
+
+ void addLine(std::string s); /**< display a line in the console */
+ void parse(std::string s); /**< react to a given command */
- /** execute squirrel script and output result */
- static void execute_script(const std::string& s);
+ /** execute squirrel script and output result */
+ void execute_script(const std::string& s);
- static bool consoleCommand(std::string command, std::vector<std::string> arguments); /**< process internal command; return false if command was unknown, true otherwise */
+ bool consoleCommand(std::string command, std::vector<std::string> arguments); /**< process internal command; return false if command was unknown, true otherwise */
- friend class ConsoleStreamBuffer;
- static void flush(ConsoleStreamBuffer* buffer); /**< act upon changes in a ConsoleStreamBuffer */
+ friend class ConsoleStreamBuffer;
+ void flush(ConsoleStreamBuffer* buffer); /**< act upon changes in a ConsoleStreamBuffer */
};
class ConsoleStreamBuffer : public std::stringbuf
int sync()
{
int result = std::stringbuf::sync();
- Console::flush(this);
+ if(Console::instance != NULL)
+ Console::instance->flush(this);
return result;
}
};
public:
virtual ~ConsoleCommandReceiver()
{
- Console::unregisterCommands(this);
+ Console::instance->unregisterCommands(this);
}
/**
// if console key was pressed: toggle console
if ((key_mapping != keymap.end()) && (key_mapping->second == CONSOLE)) {
if (event.type != SDL_KEYDOWN) return;
- Console::toggle();
+ Console::instance->toggle();
return;
}
// if console is open: send key there
- if (Console::hasFocus()) {
+ if (Console::instance->hasFocus()) {
process_console_key_event(event);
return;
}
switch (event.key.keysym.sym) {
case SDLK_RETURN:
- Console::input << std::endl;
+ Console::instance->input << std::endl;
break;
case SDLK_BACKSPACE:
- Console::backspace();
+ Console::instance->backspace();
break;
case SDLK_TAB:
- Console::autocomplete();
+ Console::instance->autocomplete();
break;
case SDLK_PAGEUP:
- Console::scroll(-1);
+ Console::instance->scroll(-1);
break;
case SDLK_PAGEDOWN:
- Console::scroll(+1);
+ Console::instance->scroll(+1);
break;
case SDLK_END:
- Console::scroll(+65535);
+ Console::instance->scroll(+65535);
break;
default:
int c = event.key.keysym.unicode;
if ((c >= 32) && (c <= 126)) {
- Console::input << (char)c;
+ Console::instance->input << (char)c;
}
break;
}
fps_fps = 0;
for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) {
- Console::registerCommand(consoleCommands[i], this);
+ Console::instance->registerCommand(consoleCommands[i], this);
}
- statistics_backdrop = new Surface("images/engine/menu/score-backdrop.png");
+ statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png"));
restart_level(true);
}
main_controller->reset();
- delete level;
currentsector = 0;
- level = new Level;
+ level.reset(new Level);
level->load(levelfile);
global_stats.reset();
delete demo_controller;
delete end_sequence_controller;
- delete level;
-
- delete statistics_backdrop;
current_ = NULL;
}
// draw level stats while end_sequence is running
if (end_sequence) {
- global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop);
+ global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop.get());
}
}
{ return currentsector; }
Level* get_current_level()
- { return level; }
+ { return level.get(); }
void start_sequence(const std::string& sequencename);
void process_menu();
Timer endsequence_timer;
- Level* level;
- Surface* statistics_backdrop; // FIXME: where to put this?
+ std::auto_ptr<Level> level;
+ std::auto_ptr<Surface> statistics_backdrop;
Sector* currentsector;
std::string capture_file;
std::istream* playback_demo_stream;
CodeController* demo_controller;
- Console* console;
};
#endif /*SUPERTUX_GAMELOOP_H*/
msg << "Couldn't initialize SDL: " << SDL_GetError();
throw std::runtime_error(msg.str());
}
+ // just to be sure
+ atexit(SDL_Quit);
SDL_EnableUNICODE(1);
int main(int argc, char** argv)
{
+ int result = 0;
+
try {
srand(time(0));
init_physfs(argv[0]);
init_audio();
timelog("video");
init_video();
+ Console::instance = new Console();
timelog("scripting");
init_scripting();
}
main_loop->run();
-
- delete main_loop;
- main_loop = NULL;
} catch(std::exception& e) {
msg_fatal << "Unexpected exception: " << e.what() << std::endl;
- return 1;
+ result = 1;
} catch(...) {
msg_fatal << "Unexpected exception" << std::endl;
- return 1;
+ result = 1;
}
+ delete main_loop;
+ main_loop = NULL;
+
free_menu();
delete ScriptManager::instance;
ScriptManager::instance = NULL;
config = NULL;
delete main_controller;
main_controller = NULL;
+ delete Console::instance;
+ Console::instance = NULL;
delete texture_manager;
texture_manager = NULL;
SDL_Quit();
PHYSFS_deinit();
- return 0;
+ return result;
}
MainLoop::MainLoop()
: speed(1.0)
{
- console.reset(new Console());
}
MainLoop::~MainLoop()
current_screen->draw(context);
if(Menu::current() != NULL)
Menu::current()->draw(context);
- console->draw(context);
+ Console::instance->draw(context);
context.do_drawing();
game_time += elapsed_time;
ScriptManager::instance->update();
current_screen->update(elapsed_time);
+ Console::instance->update(elapsed_time);
main_controller->update();
SDL_Event event;
tux_life.reset(sprite_manager->create("images/creatures/tux_small/tux-life.sprite"));
- Console::registerCommand("coins", this);
+ Console::instance->registerCommand("coins", this);
}
PlayerStatus::~PlayerStatus()
player->move(player_pos);
camera->reset(player->get_pos());
+ update_game_objects();
// Run init script
if(init_script != "") {
ScriptInterface* interface = dynamic_cast<ScriptInterface*> (object);
if(interface != NULL) {
HSQUIRRELVM vm = script_manager->get_vm();
+ int oldtop = sq_gettop(vm);
sq_pushobject(vm, sector_table);
- interface->unexpose(vm, -1);
- sq_pop(vm, 1);
+ try {
+ interface->unexpose(vm, -1);
+ } catch(std::exception& e) {
+ msg_warning << "Couldn't unregister object: " << e.what() << std::endl;
+ }
+ sq_settop(vm, oldtop);
}
}
stream << "save/" << worlddirname << "_" << slot << ".stsg";
std::string slotfile = stream.str();
- sound_manager->stop_music();
fadeout(256);
- current_world->set_savegame_filename(slotfile);
- current_world->run();
+ try {
+ current_world->set_savegame_filename(slotfile);
+ current_world->run();
+ } catch(std::exception& e) {
+ msg_fatal << "Couldn't start world: " << e.what() << std::endl;
+ }
return true;
}
World::set_savegame_filename(const std::string& filename)
{
this->savegame_filename = filename;
+ // make sure the savegame directory exists
+ std::string dirname = FileSystem::dirname(filename);
+ if(!PHYSFS_exists(dirname.c_str())) {
+ if(PHYSFS_mkdir(dirname.c_str())) {
+ std::ostringstream msg;
+ msg << "Couldn't create directory for savegames '"
+ << dirname << "': " <<PHYSFS_getLastError();
+ throw std::runtime_error(msg.str());
+ }
+ }
+
+ if(!PHYSFS_isDirectory(dirname.c_str())) {
+ std::ostringstream msg;
+ msg << "Savegame path '" << dirname << "' is not a directory";
+ throw std::runtime_error(msg.str());
+ }
}
void