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