#include "mainloop.hpp"
#include "title.hpp"
#include "game_session.hpp"
+#include "script_manager.hpp"
+#include "scripting/sound.hpp"
+#include "scripting/level.hpp"
+#include "scripting/wrapper_util.hpp"
#include "file_system.hpp"
#include "physfs/physfs_sdl.hpp"
-#include "exceptions.hpp"
SDL_Surface* screen = 0;
JoystickKeyboardController* main_controller = 0;
try {
config->load();
} catch(std::exception& e) {
- msg_info("Couldn't load config file: " << e.what() << ", using default settings");
+ msg_info << "Couldn't load config file: " << e.what() << ", using default settings" << std::endl;
}
}
if(f) {
fclose(f);
if(!PHYSFS_addToSearchPath(dir.c_str(), 1)) {
- msg_warning("Couldn't add '" << dir
- << "' to physfs searchpath: " << PHYSFS_getLastError());
+ msg_warning << "Couldn't add '" << dir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
} else {
sourcedir = true;
}
datadir = APPDATADIR;
#endif
if(!PHYSFS_addToSearchPath(datadir.c_str(), 1)) {
- msg_warning("Couldn't add '" << datadir
- << "' to physfs searchpath: " << PHYSFS_getLastError());
+ msg_warning << "Couldn't add '" << datadir << "' to physfs searchpath: " << PHYSFS_getLastError() << std::endl;
}
#endif
}
//show search Path
for(char** i = PHYSFS_getSearchPath(); *i != NULL; i++)
- msg_info("[" << *i << "] is in the search path");
+ msg_info << "[" << *i << "] is in the search path" << std::endl;
}
static void print_usage(const char* argv0)
"\n"));
}
-static void parse_commandline(int argc, char** argv)
+static bool parse_commandline(int argc, char** argv)
{
for(int i = 1; i < argc; ++i) {
std::string arg = argv[i];
config->record_demo = argv[++i];
} else if(arg == "--help") {
print_usage(argv[0]);
- throw graceful_shutdown();
+ return true;
} else if(arg == "--version") {
- msg_info(PACKAGE_NAME << " " << PACKAGE_VERSION);
- throw graceful_shutdown();
+ msg_info << PACKAGE_NAME << " " << PACKAGE_VERSION << std::endl;
+ return true;
} else if(arg[0] != '-') {
config->start_level = arg;
} else {
- msg_warning("Unknown option '" << arg << "'. Use --help to see a list of options");
+ msg_warning << "Unknown option '" << arg << "'. Use --help to see a list of options" << std::endl;
}
}
- // TODO joystick switchyes...
+ return false;
}
static void init_sdl()
}
#ifdef DEBUG
else {
- msg_warning("Couldn't find icon 'images/engine/icons/supertux.xpm'");
+ msg_warning << "Couldn't find icon 'images/engine/icons/supertux.xpm'" << std::endl;
}
#endif
sound_manager->enable_music(config->music_enabled);
}
+static void init_scripting()
+{
+ ScriptManager::instance = new ScriptManager();
+
+ HSQUIRRELVM vm = ScriptManager::instance->get_vm();
+ sq_pushroottable(vm);
+ expose_object(vm, -1, new Scripting::Sound(), "Sound", true);
+ expose_object(vm, -1, new Scripting::Level(), "Level", true);
+ sq_pop(vm, 1);
+}
+
static void quit_audio()
{
- if(sound_manager) {
+ if(sound_manager != NULL) {
delete sound_manager;
- sound_manager = 0;
+ sound_manager = NULL;
}
}
sound_manager->update();
}
- // clear even queue
+ // clear event queue
SDL_Event event;
while (SDL_PollEvent(&event))
{}
while(SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_QUIT:
- throw graceful_shutdown();
+ main_loop->quit();
+ break;
case SDL_KEYDOWN:
case SDL_JOYBUTTONDOWN:
case SDL_MOUSEBUTTONDOWN:
Uint32 current_ticks = SDL_GetTicks();
if(last_timelog_component != 0) {
- msg_info("Component '" << last_timelog_component << "' finished after " << (current_ticks - last_timelog_ticks) / 1000.0 << " seconds");
+ msg_info << "Component '" << last_timelog_component << "' finished after " << (current_ticks - last_timelog_ticks) / 1000.0 << " seconds" << std::endl;
}
last_timelog_ticks = current_ticks;
timelog("tinygettext");
init_tinygettext();
timelog("commandline");
- parse_commandline(argc, argv);
+ if(parse_commandline(argc, argv))
+ return 0;
timelog("audio");
init_audio();
timelog("video");
init_video();
+ timelog("scripting");
+ init_scripting();
timelog("menu");
setup_menu();
delete main_loop;
main_loop = NULL;
- } catch(graceful_shutdown& e) {
} catch(std::exception& e) {
- msg_fatal("Unexpected exception: " << e.what());
+ msg_fatal << "Unexpected exception: " << e.what() << std::endl;
return 1;
} catch(...) {
- msg_fatal("Unexpected exception");
+ msg_fatal << "Unexpected exception" << std::endl;
return 1;
}
free_menu();
+ delete ScriptManager::instance;
+ ScriptManager::instance = NULL;
unload_shared();
quit_audio();
if(config)
config->save();
delete config;
+ config = NULL;
delete main_controller;
+ main_controller = NULL;
delete texture_manager;
+ texture_manager = NULL;
SDL_Quit();
PHYSFS_deinit();