- turned joystick defines into variables
[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 int JOY_A = 0;
27 int JOY_B = 1;
28 int JOY_START = 9;
29
30 int JOY_X = 0;
31 int JOY_Y = 1;
32
33 SDL_Surface * screen;
34 Text* black_text;
35 Text* gold_text;
36 Text* blue_text;
37 Text* red_text;
38 Text* yellow_nums;
39 Text* white_text;
40 Text* white_small_text;
41 Text* white_big_text;
42
43 MouseCursor * mouse_cursor;
44
45 bool use_gl;
46 bool use_joystick;
47 bool use_fullscreen;
48 bool debug_mode;
49 bool show_fps;
50 float game_speed = 1.0f;
51
52 int joystick_num = 0;
53 char* level_startup_file = 0;
54 bool launch_worldmap_mode = false;
55
56 /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
57 char *st_dir, *st_save_dir;
58
59 SDL_Joystick * js;
60
61 /* Returns 1 for every button event, 2 for a quit event and 0 for no event. */
62 int wait_for_event(SDL_Event& event,unsigned int min_delay, unsigned int max_delay, bool empty_events)
63 {
64   int i;
65   Timer maxdelay;
66   Timer mindelay;
67   
68   maxdelay.init(false);
69   mindelay.init(false);
70
71   if(max_delay < min_delay)
72     max_delay = min_delay;
73
74   maxdelay.start(max_delay);
75   mindelay.start(min_delay);
76
77   if(empty_events)
78     while (SDL_PollEvent(&event))
79     {}
80
81   /* Handle events: */
82
83   for(i = 0; maxdelay.check() || !i; ++i)
84     {
85       while (SDL_PollEvent(&event))
86         {
87           if(!mindelay.check())
88             {
89               if (event.type == SDL_QUIT)
90                 {
91                   /* Quit event - quit: */
92                   return 2;
93                 }
94               else if (event.type == SDL_KEYDOWN)
95                 {
96                   /* Keypress - skip intro: */
97
98                   return 1;
99                 }
100               else if (event.type == SDL_JOYBUTTONDOWN)
101                 {
102                   /* Fire button - skip intro: */
103
104                   return 1;
105                 }
106               else if (event.type == SDL_MOUSEBUTTONDOWN)
107                 {
108                   /* Mouse button - skip intro: */
109                   return 1;
110                 }
111             }
112         }
113       SDL_Delay(10);
114     }
115
116   return 0;
117 }