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