Adonthell  0.4
prefs.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000/2002/2004 Kai Sterker <kai.sterker@gmail.com>
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file prefs.h
21  *
22  * @author Kai Sterker
23  * @brief Adonthell's configuration
24  */
25 
26 #ifndef __PREFS_H__
27 #define __PREFS_H__
28 
29 #include <string>
30 #include <fstream>
31 #include "types.h"
32 
33 #ifndef SWIG
34 using namespace std;
35 
36 /**
37  * The config file opened by the lexical scanner
38  */
39 extern FILE* prefsin;
40 
41 /**
42  * Start the lexical scanner to parse the config file,
43  * usually fount at ~/.adonthell/adonthellrc
44  */
45 extern int parse_adonthellrc (int&, string&);
46 
47 /**
48  * Returncodes of the scanner for the different entries
49  * of the configuration file.
50  */
51 enum
52 {
53  PREFS_UNKNOWN = 0,
54  PREFS_SCREEN_MODE = 1,
55  PREFS_LANGUAGE = 2,
56  PREFS_FONT = 3,
57  PREFS_QUICK_LOAD = 4,
58  PREFS_AUDIO_CHANNELS = 5,
59  PREFS_AUDIO_RESOLUTION = 6,
60  PREFS_AUDIO_SAMPLE_RATE = 7,
61  PREFS_AUDIO_VOLUME = 8,
62  PREFS_VERSION = 9,
63  PREFS_NUM = 10,
64  PREFS_STR = 11,
65  PREFS_DISPLAY = 12,
66 };
67 
68 #endif
69 
70 /**
71  * This class contains the engine's configuration read either from the
72  * %config file or from the command line.
73  */
74 class config
75 {
76 public:
77  /**
78  * Constructor. Initializes all configuration options with default
79  * values.
80  * - Language: English
81  * - Screen mode: windowed
82  * - Quick load: enabled
83  * - Audio: High quality (44.1kHz, 16 bit, stereo)
84  * - Volume: 100%
85  * - Config file: $HOME/.adonthell/adonthellrc
86  */
87  config ();
88 
89  /**
90  * See whether any options have been specified on the command line.
91  * Possible command line options are
92  * - <b>\-h</b> Print help message
93  * - <b>\-d</b> Print the data directory
94  * - <b>\-v</b> Print the version number
95  * - <b>\-l</b> List games found in the gamedir
96  * - <b>\-g dir</b> Play %game contained in dir
97  * - <b>\-c</b> Byte-compile all Python scripts in the current directory
98  *
99  * @param argc argument count
100  * @param argv argument vector
101  */
102  void parse_arguments (int argc, char * argv[]);
103 
104  /**
105  * Writes a default configuration file with the values set in the
106  * constructor
107  * @sa config::config ()
108  */
109  void write_adonthellrc ();
110  /**
111  * Reads the configuration file. If it cannot find the file, it
112  * tries to write a default one.
113  * @return <b>true</b> on success, <b>false</b> otherwise.
114  */
115  bool read_adonthellrc ();
116  /**
117  * Returns the path to the user's private Adonthell directory.
118  * Usually this is $HOME/.adonthell/ and will contain his personal
119  * configuration as well as all saved games.
120  */
121  char *get_adonthellrc ();
122 
123  /**
124  * @name Configuration options
125  */
126  //@{
127  /**
128  * Language to use if NLS was compiled in.
129  */
130  string language;
131  string font;
132  /**
133  * Name of the %game that is running at present.
134  */
135  string game_name;
136  /**
137  * Path of the directory that contains the %game running at present.
138  */
139  string gamedir;
140  /**
141  * Whether the engine shall run in window (0) or fullscreen (1) mode.
142  */
144  /**
145  * Index of the display to use for fullscreen mode
146  */
148  /**
149  * Whether the quick-load feature is enabled (1) or not (0)
150  */
152  /**
153  * The number of channels: mono (0) or stereo (1).
154  */
156  /**
157  * The resolution: 8 bit (0) or 16 bit (1)
158  */
160  /**
161  * The sample rate: 11025 Hz (0), 22050 Hz (1) or 44100 Hz (2)
162  */
164  /**
165  * The volume: a value betwen 0 and 100. 0 means that audio
166  * is completely off.
167  */
169  //@}
170 
171 private:
172 #ifndef SWIG
173  config & operator = (const config*);
174 
175  string adonthellrc; // Path to the adonthellrc file: $HOME/.adonthell/
176 #endif
177 };
178 
179 #endif // __PREFS_H__
config::audio_channels
u_int8 audio_channels
The number of channels: mono (0) or stereo (1).
Definition: prefs.h:155
types.h
Declares some basic types.
config::display
u_int8 display
Index of the display to use for fullscreen mode.
Definition: prefs.h:147
config::game_name
string game_name
Name of the game that is running at present.
Definition: prefs.h:135
u_int8
#define u_int8
8 bits long unsigned integer
Definition: types.h:35
prefsin
FILE * prefsin
The config file opened by the lexical scanner.
config::language
string language
Language to use if NLS was compiled in.
Definition: prefs.h:130
config::audio_volume
u_int8 audio_volume
The volume: a value betwen 0 and 100.
Definition: prefs.h:168
parse_adonthellrc
int parse_adonthellrc(int &, string &)
Start the lexical scanner to parse the config file, usually fount at ~/.adonthell/adonthellrc.
config
This class contains the engine's configuration read either from the config file or from the command l...
Definition: prefs.h:74
config::screen_mode
u_int8 screen_mode
Whether the engine shall run in window (0) or fullscreen (1) mode.
Definition: prefs.h:143
config::gamedir
string gamedir
Path of the directory that contains the game running at present.
Definition: prefs.h:139
config::audio_resolution
u_int8 audio_resolution
The resolution: 8 bit (0) or 16 bit (1)
Definition: prefs.h:159
config::audio_sample_rate
u_int8 audio_sample_rate
The sample rate: 11025 Hz (0), 22050 Hz (1) or 44100 Hz (2)
Definition: prefs.h:163
config::quick_load
u_int8 quick_load
Whether the quick-load feature is enabled (1) or not (0)
Definition: prefs.h:151