- bullet tweaks
[supertux.git] / src / 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 "globals.h"
22
23 /** The datadir prefix prepended when loading game data file */
24 std::string datadir;
25
26 JoystickKeymap::JoystickKeymap()
27 {
28   a_button     = 0;
29   b_button     = 1;
30   start_button = 2;
31   
32   x_axis = 0;
33   y_axis = 1;
34     
35   dead_zone = 4096;
36 }
37
38 JoystickKeymap joystick_keymap;
39
40 SDL_Surface * screen;
41 Text* black_text;
42 Text* gold_text;
43 Text* blue_text;
44 Text* red_text;
45 Text* yellow_nums;
46 Text* white_text;
47 Text* white_small_text;
48 Text* white_big_text;
49
50 MouseCursor * mouse_cursor;
51
52 bool use_gl;
53 bool use_joystick;
54 bool use_fullscreen;
55 bool debug_mode;
56 bool show_fps;
57 float game_speed = 1.0f;
58
59 int joystick_num = 0;
60 char* level_startup_file = 0;
61 bool launch_worldmap_mode = false;
62
63 /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
64 char *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 }