Improved frozen behavior.
[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* silver_text;
44 Text* blue_text;
45 Text* red_text;
46 Text* green_text;
47 Text* yellow_nums;
48 Text* white_text;
49 Text* white_small_text;
50 Text* white_big_text;
51
52 MouseCursor * mouse_cursor;
53
54 bool use_gl;
55 bool use_joystick;
56 bool use_fullscreen;
57 bool debug_mode;
58 bool show_fps;
59 float game_speed = 1.0f;
60
61 int joystick_num = 0;
62 char* level_startup_file = 0;
63 bool launch_leveleditor_mode = false;
64
65 /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
66 char *st_dir, *st_save_dir;
67
68 SDL_Joystick * js;
69
70 /* Returns 1 for every button event, 2 for a quit event and 0 for no event. */
71 int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_delay, bool empty_events)
72 {
73   int i;
74   Timer maxdelay;
75   Timer mindelay;
76   
77   maxdelay.init(false);
78   mindelay.init(false);
79
80   if(max_delay < min_delay)
81     max_delay = min_delay;
82
83   maxdelay.start(max_delay);
84   mindelay.start(min_delay);
85
86   if(empty_events)
87     while (SDL_PollEvent(&event))
88     {}
89
90   /* Handle events: */
91
92   for(i = 0; maxdelay.check() || !i; ++i)
93     {
94       while (SDL_PollEvent(&event))
95         {
96           if(!mindelay.check())
97             {
98               if (event.type == SDL_QUIT)
99                 {
100                   /* Quit event - quit: */
101                   return 2;
102                 }
103               else if (event.type == SDL_KEYDOWN)
104                 {
105                   /* Keypress - skip intro: */
106
107                   return 1;
108                 }
109               else if (event.type == SDL_JOYBUTTONDOWN)
110                 {
111                   /* Fire button - skip intro: */
112
113                   return 1;
114                 }
115               else if (event.type == SDL_MOUSEBUTTONDOWN)
116                 {
117                   /* Mouse button - skip intro: */
118                   return 1;
119                 }
120             }
121         }
122       SDL_Delay(10);
123     }
124
125   return 0;
126 }