Had to change the #includes of dependend headers from "dir/header.h" to "../dir...
[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 "../app/globals.h"
22
23 namespace SuperTux {
24
25 /** The datadir prefix prepended when loading game data file */
26 std::string datadir;
27
28 JoystickKeymap::JoystickKeymap()
29 {
30   a_button     = 0;
31   b_button     = 1;
32   start_button = 2;
33   
34   x_axis = 0;
35   y_axis = 1;
36     
37   dead_zone = 4096;
38 }
39
40 JoystickKeymap joystick_keymap;
41
42 SDL_Surface * screen;
43 Font* gold_text;
44 Font* blue_text;
45 Font* gray_text;
46 Font* yellow_nums;
47 Font* white_text;
48 Font* white_small_text;
49 Font* white_big_text;
50
51 MouseCursor * mouse_cursor;
52
53 bool use_gl;
54 bool use_joystick;
55 bool use_fullscreen;
56 bool debug_mode;
57 bool show_fps;
58 float game_speed = 1.0f;
59
60 int joystick_num = 0;
61 char* level_startup_file = 0;
62 bool launch_leveleditor_mode = false;
63 bool launch_worldmap_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 }
127
128 } //namespace SuperTux