author | Medo <smaxein@googlemail.com> |
Wed, 27 Jun 2012 22:52:19 +0200 | |
changeset 7314 | 6171f0bad318 |
parent 7275 | 15f722e0b96f |
permissions | -rw-r--r-- |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
1 |
/* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
4 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
9 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
13 |
* GNU General Public License for more details. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
14 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
18 |
*/ |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
19 |
|
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
/** |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
* Data structures for game scheme information. |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
*/ |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
|
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
#ifndef CFG_H_ |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
#define CFG_H_ |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
|
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
#include <stdbool.h> |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
28 |
|
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
29 |
// TODO: cfg/config -> scheme |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
30 |
|
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
typedef struct { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
32 |
char *name; |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
char *engineCommand; |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
34 |
bool maxMeansInfinity; |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
bool times1000; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
int min; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
int max; |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
38 |
int def; |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
} flib_cfg_setting_meta; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
|
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
typedef struct { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
42 |
char *name; |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
int bitmaskIndex; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
} flib_cfg_mod_meta; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
46 |
/** |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
47 |
* The order of the meta information in the arrays is the same as the order |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
48 |
* of the mod/setting information in the net protocol messages. |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
49 |
*/ |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
typedef struct { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
51 |
int _referenceCount; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
52 |
int settingCount; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
53 |
int modCount; |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
flib_cfg_setting_meta *settings; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
flib_cfg_mod_meta *mods; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
} flib_cfg_meta; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
57 |
|
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
58 |
typedef struct { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
59 |
int _referenceCount; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
60 |
flib_cfg_meta *meta; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
61 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
62 |
char *name; |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
int *settings; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
bool *mods; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
} flib_cfg; |
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
67 |
/** |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
68 |
* Read the meta-configuration from a .ini file (e.g. which settings exist, |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
69 |
* what are their defaults etc.) |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
70 |
* |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
71 |
* Returns the meta-configuration or NULL. |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
72 |
*/ |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
73 |
flib_cfg_meta *flib_cfg_meta_from_ini(const char *filename); |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
74 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
75 |
/** |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
76 |
* Increase the reference count of the object. Call this if you store a pointer to it somewhere. |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
77 |
* Returns the parameter. |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
78 |
*/ |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
79 |
flib_cfg_meta *flib_cfg_meta_retain(flib_cfg_meta *metainfo); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
80 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
81 |
/** |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
82 |
* Decrease the reference count of the object and free it if this was the last reference. |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
83 |
*/ |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
84 |
void flib_cfg_meta_release(flib_cfg_meta *metainfo); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
85 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
86 |
/** |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
87 |
* Create a new configuration with everything set to default or false |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
88 |
* Returns NULL on error. |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
89 |
*/ |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
90 |
flib_cfg *flib_cfg_create(flib_cfg_meta *meta, const char *schemeName); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
91 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
92 |
/** |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
93 |
* Create a copy of the scheme. Returns NULL on error or if NULL was passed. |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
94 |
*/ |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
95 |
flib_cfg *flib_cfg_copy(const flib_cfg *cfg); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
96 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
97 |
/** |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
98 |
* Increase the reference count of the object. Call this if you store a pointer to it somewhere. |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
99 |
* Returns the parameter. |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
100 |
*/ |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
101 |
flib_cfg *flib_cfg_retain(flib_cfg *cfg); |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
102 |
|
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
103 |
/** |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
104 |
* Decrease the reference count of the object and free it if this was the last reference. |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7175
diff
changeset
|
105 |
*/ |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
106 |
void flib_cfg_release(flib_cfg* cfg); |
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
107 |
|
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
108 |
/** |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
109 |
* Retrieve a mod setting by its name. If the mod is not found, logs an error and returns false. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
110 |
*/ |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
111 |
bool flib_cfg_get_mod(flib_cfg *cfg, const char *name); |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
112 |
|
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
113 |
/** |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
114 |
* Retrieve a game setting by its name. If the setting is not found, logs an error and returns def. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
115 |
*/ |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
116 |
int flib_cfg_get_setting(flib_cfg *cfg, const char *name, int def); |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
117 |
|
7175
038e3415100a
Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
118 |
#endif /* CFG_H_ */ |