make it possible to start supertux from top soruce directory
[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 <config.h>
22
23 #include "../app/globals.h"
24
25 namespace SuperTux {
26
27 /** The datadir prefix prepended when loading game data file */
28 std::string datadir;
29 std::string package_symbol_name;
30 std::string package_name;
31 std::string package_version;
32   
33 JoystickKeymap::JoystickKeymap()
34 {
35   a_button     = 0;
36   b_button     = 1;
37   start_button = 2;
38   
39   x_axis = 0;
40   y_axis = 1;
41     
42   dead_zone = 4096;
43 }
44
45 JoystickKeymap joystick_keymap;
46
47 SDL_Surface * screen;
48 MouseCursor * mouse_cursor;
49
50 bool use_gl;
51 bool use_joystick;
52 bool use_fullscreen;
53 bool debug_mode;
54 bool show_fps;
55
56 int joystick_num = 0;
57 char* level_startup_file = 0;
58 bool launch_leveleditor_mode = false;
59 bool launch_worldmap_mode = false;
60 bool flip_levels_mode = false;
61
62 /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
63 std::string st_dir, st_save_dir;
64
65 SDL_Joystick * js;
66
67 /* Returns 1 for every button event, 2 for a quit event and 0 for no event. */
68 int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_delay, bool empty_events)
69 {
70   int i;
71   Timer maxdelay;
72   Timer mindelay;
73   
74   maxdelay.init(false);
75   mindelay.init(false);
76
77   if(max_delay < min_delay)
78     max_delay = min_delay;
79
80   maxdelay.start(max_delay);
81   mindelay.start(min_delay);
82
83   if(empty_events)
84     while (SDL_PollEvent(&event))
85     {}
86
87   /* Handle events: */
88
89   for(i = 0; maxdelay.check() || !i; ++i)
90     {
91       while (SDL_PollEvent(&event))
92         {
93           if(!mindelay.check())
94             {
95               if (event.type == SDL_QUIT)
96                 {
97                   /* Quit event - quit: */
98                   return 2;
99                 }
100               else if (event.type == SDL_KEYDOWN)
101                 {
102                   /* Keypress - skip intro: */
103
104                   return 1;
105                 }
106               else if (event.type == SDL_JOYBUTTONDOWN)
107                 {
108                   /* Fire button - skip intro: */
109
110                   return 1;
111                 }
112               else if (event.type == SDL_MOUSEBUTTONDOWN)
113                 {
114                   /* Mouse button - skip intro: */
115                   return 1;
116                 }
117             }
118         }
119       SDL_Delay(10);
120     }
121
122   return 0;
123 }
124
125 } //namespace SuperTux