Added a --flip-levels argument, I guess it doesn't need any description of what it...
[supertux.git] / lib / app / globals.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20
21 #include "../app/globals.h"
22
23 namespace SuperTux {
24
25 /** The datadir prefix prepended when loading game data file */
26 std::string datadir;
27 std::string package_symbol_name;
28 std::string package_name;
29 std::string package_version;
30   
31 JoystickKeymap::JoystickKeymap()
32 {
33   a_button     = 0;
34   b_button     = 1;
35   start_button = 2;
36   
37   x_axis = 0;
38   y_axis = 1;
39     
40   dead_zone = 4096;
41 }
42
43 JoystickKeymap joystick_keymap;
44
45 SDL_Surface * screen;
46 MouseCursor * mouse_cursor;
47
48 bool use_gl;
49 bool use_joystick;
50 bool use_fullscreen;
51 bool debug_mode;
52 bool show_fps;
53
54 int joystick_num = 0;
55 char* level_startup_file = 0;
56 bool launch_leveleditor_mode = false;
57 bool launch_worldmap_mode = false;
58 bool flip_levels_mode = false;
59
60 /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
61 char *st_dir, *st_save_dir;
62
63 SDL_Joystick * js;
64
65 /* Returns 1 for every button event, 2 for a quit event and 0 for no event. */
66 int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_delay, bool empty_events)
67 {
68   int i;
69   Timer maxdelay;
70   Timer mindelay;
71   
72   maxdelay.init(false);
73   mindelay.init(false);
74
75   if(max_delay < min_delay)
76     max_delay = min_delay;
77
78   maxdelay.start(max_delay);
79   mindelay.start(min_delay);
80
81   if(empty_events)
82     while (SDL_PollEvent(&event))
83     {}
84
85   /* Handle events: */
86
87   for(i = 0; maxdelay.check() || !i; ++i)
88     {
89       while (SDL_PollEvent(&event))
90         {
91           if(!mindelay.check())
92             {
93               if (event.type == SDL_QUIT)
94                 {
95                   /* Quit event - quit: */
96                   return 2;
97                 }
98               else if (event.type == SDL_KEYDOWN)
99                 {
100                   /* Keypress - skip intro: */
101
102                   return 1;
103                 }
104               else if (event.type == SDL_JOYBUTTONDOWN)
105                 {
106                   /* Fire button - skip intro: */
107
108                   return 1;
109                 }
110               else if (event.type == SDL_MOUSEBUTTONDOWN)
111                 {
112                   /* Mouse button - skip intro: */
113                   return 1;
114                 }
115             }
116         }
117       SDL_Delay(10);
118     }
119
120   return 0;
121 }
122
123 } //namespace SuperTux