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