// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
-
#include <config.h>
+#include <assert.h>
#include "main.h"
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
+#include <assert.h>
#ifndef WIN32
#include <libgen.h>
#endif
#include <SDL.h>
#include <SDL_mixer.h>
#include <SDL_image.h>
+#include <SDL_opengl.h>
#include "gameconfig.h"
#include "resources.h"
-#include "app/globals.h"
-#include "app/setup.h"
-#include "app/gettext.h"
+#include "gettext.h"
#include "audio/sound_manager.h"
+#include "video/surface.h"
#include "control/joystickkeyboardcontroller.h"
#include "misc.h"
+#include "title.h"
#include "game_session.h"
+#include "file_system.h"
SDL_Surface* screen = 0;
JoystickKeyboardController* main_controller = 0;
+TinyGetText::DictionaryManager dictionary_manager;
static void init_config()
{
user_dir = home;
user_dir += "/.supertux";
- // Remove .supertux config file from old versions
- if(FileSystem::faccessible(user_dir)) {
- std::cerr << "Removing old config file " << user_dir << "\n";
- remove(user_dir.c_str());
- }
-
// create directories
std::string savedir = user_dir + "/save";
mkdir(user_dir.c_str(), 0755);
}
} else if(arg == "--show-fps") {
config->show_fps = true;
+ } else if(arg == "--play-demo") {
+ if(i+1 >= argc) {
+ print_usage(argv[0]);
+ throw std::runtime_error("Need to specify a demo filename");
+ }
+ config->start_demo = argv[++i];
+ } else if(arg == "--record-demo") {
+ if(i+1 >= argc) {
+ print_usage(argv[0]);
+ throw std::runtime_error("Need to specify a demo filename");
+ }
+ config->record_demo = argv[++i];
} else if(arg == "--help") {
print_usage(argv[0]);
throw std::runtime_error("");
}
SDL_EnableUNICODE(1);
+
+ // wait 100ms and clear SDL event queue because sometimes we have random
+ // joystick events in the queue on startup...
+ SDL_Delay(100);
+ SDL_Event dummy;
+ while(SDL_PollEvent(&dummy))
+ ;
}
static void check_gl_error()
}
}
+void wait_for_event(float min_delay, float max_delay)
+{
+ assert(min_delay <= max_delay);
+
+ Uint32 min = (Uint32) (min_delay * 1000);
+ Uint32 max = (Uint32) (max_delay * 1000);
+
+ SDL_Delay(min);
+
+ // clear even queue
+ SDL_Event event;
+ while (SDL_PollEvent(&event))
+ {}
+
+ /* Handle events: */
+ bool running = false;
+ Uint32 ticks = SDL_GetTicks();
+ while(running) {
+ while(SDL_PollEvent(&event)) {
+ switch(event.type) {
+ case SDL_QUIT:
+ throw std::runtime_error("received window close");
+ case SDL_KEYDOWN:
+ case SDL_JOYBUTTONDOWN:
+ case SDL_MOUSEBUTTONDOWN:
+ running = false;
+ }
+ }
+ if(SDL_GetTicks() - ticks >= (max - min))
+ running = false;
+ SDL_Delay(10);
+ }
+}
+
int main(int argc, char** argv)
{
#ifndef DEBUG // we want backtraces in debug mode so don't catch exceptions
load_shared();
if(config->start_level != "") {
GameSession session(config->start_level, ST_GL_LOAD_LEVEL_FILE);
+ if(config->start_demo != "")
+ session.play_demo(config->start_demo);
+ if(config->record_demo != "")
+ session.record_demo(config->record_demo);
session.run();
} else {
// normal game