/
game.h
276 lines (213 loc) · 8.23 KB
/
game.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/**
* @file game.h
*
* @ingroup core
*
* @author Copyright © 2003-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright © 2005-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef LIBDENG_GAME_H
#define LIBDENG_GAME_H
#include "dd_plugin.h"
#include <de/ddstring.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup printGameFlags Print Game Flags.
*/
///@{
#define PGF_BANNER 0x1
#define PGF_STATUS 0x2
#define PGF_LIST_STARTUP_RESOURCES 0x4
#define PGF_LIST_OTHER_RESOURCES 0x8
#define PGF_EVERYTHING (PGF_BANNER|PGF_STATUS|PGF_LIST_STARTUP_RESOURCES|PGF_LIST_OTHER_RESOURCES)
///@}
struct AbstractResource_s;
struct gamedef_s;
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
namespace de {
class GameCollection;
/**
* Game. Used to record top-level game configurations registered by
* the loaded game plugin(s).
*
* @ingroup core
*/
class Game
{
public:
/**
* @param identityKey Unique game mode key/identifier, 16 chars max (e.g., "doom1-ultimate").
* @param dataPath The base directory for all data-class resources.
* @param defsPath The base directory for all defs-class resources.
* @param configDir Name of the config directory.
* @param title Default game title.
* @param author Default game author.
*/
Game(char const* identityKey, ddstring_t const* dataPath, ddstring_t const* defsPath,
char const* configDir, char const* title = "Unnamed", char const* author = "Unknown");
virtual ~Game();
/// @return Collection in which this game exists.
GameCollection& collection() const;
/// @return Unique plugin identifier attributed to that which registered this.
pluginid_t pluginId() const;
/// @return String containing the identity key.
ddstring_t const& identityKey() const;
/// @return String containing the default title.
ddstring_t const& title() const;
/// @return String containing the default author.
ddstring_t const& author() const;
/// @return String containing the name of the main config file.
ddstring_t const& mainConfig() const;
/// @return String containing the name of the binding config file.
ddstring_t const& bindingConfig() const;
/**
* @note Unless caller is the resource locator then you probably shouldn't be calling.
* This is the absolute data path and shouldn't be used directly for resource location.
*
* @return String containing the base data-class resource directory.
*/
ddstring_t const& dataPath() const;
/**
* @note Unless caller is the resource locator then you probably shouldn't be calling.
* This is the absolute defs path and shouldn't be used directly for resource location.
*
* @return String containing the base defs-class resource directory.
*/
ddstring_t const& defsPath() const;
/**
* Change the identfier of the plugin associated with this.
* @param newId New identifier.
*/
Game& setPluginId(pluginid_t newId);
/**
* Add a new resource to the list of resources.
*
* @note Resource registration order defines the order in which resources of each
* type are loaded.
*
* @param rclass Class of resource being added.
*/
Game& addResource(resourceclass_t rclass, struct AbstractResource_s& record);
bool allStartupResourcesFound() const;
/**
* Retrieve a subset of the resource collection associated with this.
*
* @param rclass Class of resource to collect.
* @return Vector of selected resource records.
*/
struct AbstractResource_s* const* resources(resourceclass_t rclass, int* count) const;
// Static members ------------------------------------------------------------------
/**
* Construct a new Game instance from the specified definition @a def.
*
* @note May fail if the definition is incomplete or invalid (@c NULL is returned).
*/
static Game* fromDef(GameDef const& def);
/**
* Print a game mode banner with rulers.
*
* @todo This has been moved here so that strings like the game title and author
* can be overridden (e.g., via DEHACKED). Make it so!
*/
static void printBanner(Game const& game);
/**
* Print the list of resources for @a Game.
*
* @param game Game to list resources of.
* @param printStatus @c true= Include the current availability/load status
* of each resource.
* @param rflags Only consider resources whose @ref resourceFlags match
* this value. If @c <0 the flags are ignored.
*/
static void printResources(Game const& game, bool printStatus, int rflags);
/**
* Print extended information about game @a info.
*
* @param info Game record to be printed.
* @param flags &ref printGameFlags
*/
static void print(Game const& game, int flags);
private:
struct Instance;
Instance* d;
};
/**
* The special "null" Game object.
*/
class NullGame : public Game
{
public:
/// General exception for invalid action on a NULL object. @ingroup errors
DENG2_ERROR(NullObjectError);
public:
NullGame(ddstring_t const* dataPath, ddstring_t const* defsPath);
Game& addResource(resourceclass_t /*rclass*/, struct AbstractResource_s& /*record*/) {
throw NullObjectError("NullGame::addResource", "Invalid action on null-object");
}
bool isRequiredResource(char const* /*absolutePath*/) {
return false; // Never.
}
bool allStartupResourcesFound() const {
return true; // Always.
}
struct AbstractResource_s* const* resources(resourceclass_t /*rclass*/, int* /*count*/) const {
return 0;
}
static Game* fromDef(GameDef const& /*def*/) {
throw NullObjectError("NullGame::fromDef", "Not valid for null-object");
}
};
/// @return @c true= @a game is a "null-game" object (not a real playable game).
inline bool isNullGame(Game const& game) {
return !!dynamic_cast<NullGame const*>(&game);
}
} // namespace de
extern "C" {
#endif // __cplusplus
/**
* C wrapper API:
*/
struct game_s; // The game instance (opaque).
typedef struct game_s Game;
Game* Game_New(char const* identityKey, ddstring_t const* dataPath, ddstring_t const* defsPath, char const* configDir, char const* title, char const* author);
void Game_Delete(Game* game);
boolean Game_IsNullObject(Game const* game);
struct game_s* Game_AddResource(Game* game, resourceclass_t rclass, struct AbstractResource_s* record);
boolean Game_AllStartupResourcesFound(Game const* game);
Game* Game_SetPluginId(Game* game, pluginid_t pluginId);
pluginid_t Game_PluginId(Game const* game);
ddstring_t const* Game_IdentityKey(Game const* game);
ddstring_t const* Game_Title(Game const* game);
ddstring_t const* Game_Author(Game const* game);
ddstring_t const* Game_MainConfig(Game const* game);
ddstring_t const* Game_BindingConfig(Game const* game);
struct AbstractResource_s* const* Game_Resources(Game const* game, resourceclass_t rclass, int* count);
ddstring_t const* Game_DataPath(Game const* game);
ddstring_t const* Game_DefsPath(Game const* game);
Game* Game_FromDef(GameDef const* def);
void Game_PrintBanner(Game const* game);
void Game_PrintResources(Game const* game, boolean printStatus, int rflags);
void Game_Print(Game const* game, int flags);
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* LIBDENG_GAME_H */