35ae5d0e4c274cdcaa94ee15d6a384e4053c649a
[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 int screen_width  = SCREEN_WIDTH;
38 int screen_height = SCREEN_HEIGHT;
39
40 JoystickKeymap::JoystickKeymap()
41 {
42   a_button     = 0;
43   b_button     = 1;
44   start_button = 2;
45   
46   x_axis = 0;
47   y_axis = 1;
48     
49   dead_zone = 4096;
50 }
51
52 JoystickKeymap joystick_keymap;
53
54 SDL_Surface * screen;
55 MouseCursor * mouse_cursor;
56
57 bool use_gl;
58 bool use_joystick;
59 bool use_fullscreen;
60 bool debug_mode;
61 bool show_fps;
62 bool debug_grid = false;
63
64 int joystick_num = 0;
65 char* level_startup_file = 0;
66 bool launch_leveleditor_mode = false;
67 bool launch_worldmap_mode = false;
68 bool flip_levels_mode = false;
69
70 /* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
71 std::string st_dir, st_save_dir;
72
73 SDL_Joystick * js;
74
75 /* Returns 1 for every button event, 2 for a quit event and 0 for no event. */
76 int wait_for_event(SDL_Event& event, unsigned int min_delay,
77     unsigned int max_delay, bool empty_events)
78 {
79   int i;
80   Timer maxdelay;
81   Timer mindelay;
82   
83   maxdelay.init(false);
84   mindelay.init(false);
85
86   if(max_delay < min_delay)
87     max_delay = min_delay;
88
89   maxdelay.start(max_delay);
90   mindelay.start(min_delay);
91
92   if(empty_events)
93     while (SDL_PollEvent(&event))
94     {}
95
96   /* Handle events: */
97
98   for(i = 0; maxdelay.check() || !i; ++i)
99     {
100       while (SDL_PollEvent(&event))
101         {
102           if(!mindelay.check())
103             {
104               if (event.type == SDL_QUIT)
105                 {
106                   /* Quit event - quit: */
107                   return 2;
108                 }
109               else if (event.type == SDL_KEYDOWN)
110                 {
111                   /* Keypress - skip intro: */
112
113                   return 1;
114                 }
115               else if (event.type == SDL_JOYBUTTONDOWN)
116                 {
117                   /* Fire button - skip intro: */
118
119                   return 1;
120                 }
121               else if (event.type == SDL_MOUSEBUTTONDOWN)
122                 {
123                   /* Mouse button - skip intro: */
124                   return 1;
125                 }
126             }
127         }
128       SDL_Delay(10);
129     }
130
131   return 0;
132 }
133
134 } //namespace SuperTux