Debian Codegraph @

include/igame.h

raw
1 #pragma once
2
3 #include "xmlutil/Node.h"
4 #include "imodule.h"
5 #include <list>
6 #include <string>
7
8 // String identifier for the game manager module
9 const char* const MODULE_GAMEMANAGER("GameManager");
10
11 const char* const RKEY_GAME_TYPE = "user/game/type";
12 const char* const RKEY_FS_GAME = "user/game/fs_game";
13 const char* const RKEY_FS_GAME_BASE = "user/game/fs_game_base";
14 const char* const RKEY_ENGINE_PATH = "user/paths/enginePath";
15 const char* const RKEY_MOD_PATH = "user/paths/modPath";
16 const char* const RKEY_MOD_BASE_PATH = "user/paths/modBasePath";
17
18 namespace game
19 {
20
21 /// Interface for an object representing a single game type.
22 class IGame
23 {
24 public:
25 /// Destructor
26 virtual ~IGame() {}
27
28 /**
29 * \brief Get a string key value from the game file.
30 *
31 * The "key values" are the attributes on the top-level <game> node, for example "type",
32 * "name" and "index". Originally these were the only data items stored in the .game
33 * file, before it was expanded into a general XML tree.
34 *
35 * \param key
36 * Name of the key to retrieve. If this key does not exist, a warning is
37 * emitted and the empty string is returned.
38 */
39 virtual std::string getKeyValue(const std::string& key) const = 0;
40
41 /**
42 * @brief Test if this game has a specific optional feature.
43 *
44 * Games are allowed to specify certain features to expose in the UI, which might not be
45 * required in other games. Each feature is defined by a single text string which appears under
46 * the <features> node.
47 */
48 virtual bool hasFeature(const std::string& feature) const = 0;
49
50 /// Get the name of this game
51 virtual std::string getName() const = 0;
52
53 /**
54 * \brief
55 * Search an XPath relative to the this game node.
56 *
57 * \param xpath
58 * The <b>relative</b> XPath under the game node, including the initial
59 * forward-slash(es).
60 */
61 virtual xml::NodeList getLocalXPath(const std::string& path) const = 0;
62 };
63
64 typedef std::shared_ptr<IGame> IGamePtr;
65
66 /**
67 * Represents the game configuration as specified by the user
68 * in the Game Settings dialog, comprising Game name,
69 * engine path, mod path, etc.
70 */
71 struct GameConfiguration
72 {
73 // The name of the current game, e.g. "Doom 3"
74 std::string gameType;
75
76 // The engine path (pointing to the game executable)
77 std::string enginePath;
78
79 // The "userengine" path (where the fs_game is stored)
80 // this is ~/.doom3/<fs_game> in linux, and <enginepath>/<fs_game> in Win32
81 std::string modBasePath;
82
83 // The "mod mod" path (where the fs_game_base is stored)
84 // this is ~/.doom3/<fs_game_base> in linux, and <enginepath>/<fs_game_base> in Win32
85 std::string modPath;
86 };
87
88 /**
89 * \brief
90 * Interface for the game management module.
91 */
92 class IGameManager :
93 public RegisterableModule
94 {
95 public:
96 // Returns the user's local engine path, on POSIX systems this might
97 // point to the folder in the home directory, e.g. ~/.doom3/ if it exists.
98 // If no engine directory is found in the home directory, the regular
99 // engine path is returned, e.g. /usr/local/doom3 or c:\games\doom3
100 virtual std::string getUserEnginePath() = 0;
101
102 /**
103 * greebo: Gets the mod path (e.g. ~/.doom3/gathers/).
104 * Returns the mod base path if the mod path itself is empty.
105 */
106 virtual const std::string& getModPath() const = 0;
107
108 /**
109 * greebo: Returns the mod base path (e.g. ~/.doom3/darkmod/),
110 * can be an empty string if fs_game_base is not set.
111 */
112 virtual const std::string& getModBasePath() const = 0;
113
114 /** greebo: Returns the current Game (shared_ptr).
115 */
116 virtual IGamePtr currentGame() = 0;
117
118 // A sorted list of engine paths (queried by the VFS)
119 typedef std::list<std::string> PathList;
120
121 // Returns the list of ordered engine paths, which should
122 // be initialised by the Virtual Filesystem (in this exact order)
123 virtual const PathList& getVFSSearchPaths() const = 0;
124
125 typedef std::vector<IGamePtr> GameList;
126 virtual const GameList& getSortedGameList() = 0;
127
128 // Returns the absolute path where maps are going to be saved to
129 virtual const std::string& getMapPath() = 0;
130
131 // Returns the absolute path where prefabs are going to be saved to
132 virtual const std::string& getPrefabPath() = 0;
133
134 // Returns the active game configuration
135 virtual const GameConfiguration& getConfig() const = 0;
136
137 // Activates the given mod configuration
138 // Stores the given config, initialises VFS and constructs a few secondary paths
139 virtual void applyConfig(const GameConfiguration& config) = 0;
140 };
141 typedef std::shared_ptr<IGameManager> IGameManagerPtr;
142
143 } // namespace game
144
145 // This is the accessor for the game manager
146 inline game::IGameManager& GlobalGameManager()
147 {
148 static module::InstanceReference<game::IGameManager> _reference(MODULE_GAMEMANAGER);
149 return _reference;
150 }